Add linux-next specific files for 20110824
[linux-2.6/next.git] / kernel / sysctl.c
blobf31e7ec8ceaaa0f3f866bc6f9b6f5f10eef7a1f5
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/export.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>
59 #include <linux/kmod.h>
61 #include <asm/uaccess.h>
62 #include <asm/processor.h>
64 #ifdef CONFIG_X86
65 #include <asm/nmi.h>
66 #include <asm/stacktrace.h>
67 #include <asm/io.h>
68 #endif
69 #ifdef CONFIG_BSD_PROCESS_ACCT
70 #include <linux/acct.h>
71 #endif
72 #ifdef CONFIG_RT_MUTEXES
73 #include <linux/rtmutex.h>
74 #endif
75 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
76 #include <linux/lockdep.h>
77 #endif
78 #ifdef CONFIG_CHR_DEV_SG
79 #include <scsi/sg.h>
80 #endif
82 #ifdef CONFIG_LOCKUP_DETECTOR
83 #include <linux/nmi.h>
84 #endif
87 #if defined(CONFIG_SYSCTL)
89 /* External variables not in a header file. */
90 extern int sysctl_overcommit_memory;
91 extern int sysctl_overcommit_ratio;
92 extern int max_threads;
93 extern int core_uses_pid;
94 extern int suid_dumpable;
95 extern char core_pattern[];
96 extern unsigned int core_pipe_limit;
97 extern int pid_max;
98 extern int min_free_kbytes;
99 extern int pid_max_min, pid_max_max;
100 extern int sysctl_drop_caches;
101 extern int percpu_pagelist_fraction;
102 extern int compat_log;
103 extern int latencytop_enabled;
104 extern int sysctl_nr_open_min, sysctl_nr_open_max;
105 #ifndef CONFIG_MMU
106 extern int sysctl_nr_trim_pages;
107 #endif
108 #ifdef CONFIG_BLOCK
109 extern int blk_iopoll_enabled;
110 #endif
112 /* Constants used for minimum and maximum */
113 #ifdef CONFIG_LOCKUP_DETECTOR
114 static int sixty = 60;
115 static int neg_one = -1;
116 #endif
118 static int zero;
119 static int __maybe_unused one = 1;
120 static int __maybe_unused two = 2;
121 static int __maybe_unused three = 3;
122 static unsigned long one_ul = 1;
123 static int one_hundred = 100;
124 #ifdef CONFIG_PRINTK
125 static int ten_thousand = 10000;
126 #endif
128 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
129 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
131 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
132 static int maxolduid = 65535;
133 static int minolduid;
134 static int min_percpu_pagelist_fract = 8;
136 static int ngroups_max = NGROUPS_MAX;
138 #ifdef CONFIG_INOTIFY_USER
139 #include <linux/inotify.h>
140 #endif
141 #ifdef CONFIG_SPARC
142 #include <asm/system.h>
143 #endif
145 #ifdef CONFIG_SPARC64
146 extern int sysctl_tsb_ratio;
147 #endif
149 #ifdef __hppa__
150 extern int pwrsw_enabled;
151 extern int unaligned_enabled;
152 #endif
154 #ifdef CONFIG_S390
155 #ifdef CONFIG_MATHEMU
156 extern int sysctl_ieee_emulation_warnings;
157 #endif
158 extern int sysctl_userprocess_debug;
159 extern int spin_retry;
160 #endif
162 #ifdef CONFIG_IA64
163 extern int no_unaligned_warning;
164 extern int unaligned_dump_stack;
165 #endif
167 #ifdef CONFIG_PROC_SYSCTL
168 static int proc_do_cad_pid(struct ctl_table *table, int write,
169 void __user *buffer, size_t *lenp, loff_t *ppos);
170 static int proc_taint(struct ctl_table *table, int write,
171 void __user *buffer, size_t *lenp, loff_t *ppos);
172 #endif
174 #ifdef CONFIG_PRINTK
175 static int proc_dmesg_restrict(struct ctl_table *table, int write,
176 void __user *buffer, size_t *lenp, loff_t *ppos);
177 #endif
179 #ifdef CONFIG_MAGIC_SYSRQ
180 /* Note: sysrq code uses it's own private copy */
181 static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
183 static int sysrq_sysctl_handler(ctl_table *table, int write,
184 void __user *buffer, size_t *lenp,
185 loff_t *ppos)
187 int error;
189 error = proc_dointvec(table, write, buffer, lenp, ppos);
190 if (error)
191 return error;
193 if (write)
194 sysrq_toggle_support(__sysrq_enabled);
196 return 0;
199 #endif
201 static struct ctl_table root_table[];
202 static struct ctl_table_root sysctl_table_root;
203 static struct ctl_table_header root_table_header = {
204 {{.count = 1,
205 .ctl_table = root_table,
206 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),}},
207 .root = &sysctl_table_root,
208 .set = &sysctl_table_root.default_set,
210 static struct ctl_table_root sysctl_table_root = {
211 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
212 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
215 static struct ctl_table kern_table[];
216 static struct ctl_table vm_table[];
217 static struct ctl_table fs_table[];
218 static struct ctl_table debug_table[];
219 static struct ctl_table dev_table[];
220 extern struct ctl_table random_table[];
221 #ifdef CONFIG_EPOLL
222 extern struct ctl_table epoll_table[];
223 #endif
225 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
226 int sysctl_legacy_va_layout;
227 #endif
229 /* The default sysctl tables: */
231 static struct ctl_table root_table[] = {
233 .procname = "kernel",
234 .mode = 0555,
235 .child = kern_table,
238 .procname = "vm",
239 .mode = 0555,
240 .child = vm_table,
243 .procname = "fs",
244 .mode = 0555,
245 .child = fs_table,
248 .procname = "debug",
249 .mode = 0555,
250 .child = debug_table,
253 .procname = "dev",
254 .mode = 0555,
255 .child = dev_table,
260 #ifdef CONFIG_SCHED_DEBUG
261 static int min_sched_granularity_ns = 100000; /* 100 usecs */
262 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
263 static int min_wakeup_granularity_ns; /* 0 usecs */
264 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
265 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
266 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
267 #endif
269 #ifdef CONFIG_COMPACTION
270 static int min_extfrag_threshold;
271 static int max_extfrag_threshold = 1000;
272 #endif
274 static struct ctl_table kern_table[] = {
276 .procname = "sched_child_runs_first",
277 .data = &sysctl_sched_child_runs_first,
278 .maxlen = sizeof(unsigned int),
279 .mode = 0644,
280 .proc_handler = proc_dointvec,
282 #ifdef CONFIG_SCHED_DEBUG
284 .procname = "sched_min_granularity_ns",
285 .data = &sysctl_sched_min_granularity,
286 .maxlen = sizeof(unsigned int),
287 .mode = 0644,
288 .proc_handler = sched_proc_update_handler,
289 .extra1 = &min_sched_granularity_ns,
290 .extra2 = &max_sched_granularity_ns,
293 .procname = "sched_latency_ns",
294 .data = &sysctl_sched_latency,
295 .maxlen = sizeof(unsigned int),
296 .mode = 0644,
297 .proc_handler = sched_proc_update_handler,
298 .extra1 = &min_sched_granularity_ns,
299 .extra2 = &max_sched_granularity_ns,
302 .procname = "sched_wakeup_granularity_ns",
303 .data = &sysctl_sched_wakeup_granularity,
304 .maxlen = sizeof(unsigned int),
305 .mode = 0644,
306 .proc_handler = sched_proc_update_handler,
307 .extra1 = &min_wakeup_granularity_ns,
308 .extra2 = &max_wakeup_granularity_ns,
311 .procname = "sched_tunable_scaling",
312 .data = &sysctl_sched_tunable_scaling,
313 .maxlen = sizeof(enum sched_tunable_scaling),
314 .mode = 0644,
315 .proc_handler = sched_proc_update_handler,
316 .extra1 = &min_sched_tunable_scaling,
317 .extra2 = &max_sched_tunable_scaling,
320 .procname = "sched_migration_cost",
321 .data = &sysctl_sched_migration_cost,
322 .maxlen = sizeof(unsigned int),
323 .mode = 0644,
324 .proc_handler = proc_dointvec,
327 .procname = "sched_nr_migrate",
328 .data = &sysctl_sched_nr_migrate,
329 .maxlen = sizeof(unsigned int),
330 .mode = 0644,
331 .proc_handler = proc_dointvec,
334 .procname = "sched_time_avg",
335 .data = &sysctl_sched_time_avg,
336 .maxlen = sizeof(unsigned int),
337 .mode = 0644,
338 .proc_handler = proc_dointvec,
341 .procname = "sched_shares_window",
342 .data = &sysctl_sched_shares_window,
343 .maxlen = sizeof(unsigned int),
344 .mode = 0644,
345 .proc_handler = proc_dointvec,
348 .procname = "timer_migration",
349 .data = &sysctl_timer_migration,
350 .maxlen = sizeof(unsigned int),
351 .mode = 0644,
352 .proc_handler = proc_dointvec_bool,
354 #endif
356 .procname = "sched_rt_period_us",
357 .data = &sysctl_sched_rt_period,
358 .maxlen = sizeof(unsigned int),
359 .mode = 0644,
360 .proc_handler = sched_rt_handler,
363 .procname = "sched_rt_runtime_us",
364 .data = &sysctl_sched_rt_runtime,
365 .maxlen = sizeof(int),
366 .mode = 0644,
367 .proc_handler = sched_rt_handler,
369 #ifdef CONFIG_SCHED_AUTOGROUP
371 .procname = "sched_autogroup_enabled",
372 .data = &sysctl_sched_autogroup_enabled,
373 .maxlen = sizeof(unsigned int),
374 .mode = 0644,
375 .proc_handler = proc_dointvec_minmax,
376 .extra1 = &zero,
377 .extra2 = &one,
379 #endif
380 #ifdef CONFIG_PROVE_LOCKING
382 .procname = "prove_locking",
383 .data = &prove_locking,
384 .maxlen = sizeof(int),
385 .mode = 0644,
386 .proc_handler = proc_dointvec,
388 #endif
389 #ifdef CONFIG_LOCK_STAT
391 .procname = "lock_stat",
392 .data = &lock_stat,
393 .maxlen = sizeof(int),
394 .mode = 0644,
395 .proc_handler = proc_dointvec,
397 #endif
399 .procname = "panic",
400 .data = &panic_timeout,
401 .maxlen = sizeof(int),
402 .mode = 0644,
403 .proc_handler = proc_dointvec,
406 .procname = "core_uses_pid",
407 .data = &core_uses_pid,
408 .maxlen = sizeof(int),
409 .mode = 0644,
410 .proc_handler = proc_dointvec,
413 .procname = "core_pattern",
414 .data = core_pattern,
415 .maxlen = CORENAME_MAX_SIZE,
416 .mode = 0644,
417 .proc_handler = proc_dostring,
420 .procname = "core_pipe_limit",
421 .data = &core_pipe_limit,
422 .maxlen = sizeof(unsigned int),
423 .mode = 0644,
424 .proc_handler = proc_dointvec,
426 #ifdef CONFIG_PROC_SYSCTL
428 .procname = "tainted",
429 .maxlen = sizeof(long),
430 .mode = 0644,
431 .proc_handler = proc_taint,
433 #endif
434 #ifdef CONFIG_LATENCYTOP
436 .procname = "latencytop",
437 .data = &latencytop_enabled,
438 .maxlen = sizeof(int),
439 .mode = 0644,
440 .proc_handler = proc_dointvec,
442 #endif
443 #ifdef CONFIG_BLK_DEV_INITRD
445 .procname = "real-root-dev",
446 .data = &real_root_dev,
447 .maxlen = sizeof(int),
448 .mode = 0644,
449 .proc_handler = proc_dointvec,
451 #endif
453 .procname = "print-fatal-signals",
454 .data = &print_fatal_signals,
455 .maxlen = sizeof(int),
456 .mode = 0644,
457 .proc_handler = proc_dointvec,
459 #ifdef CONFIG_SPARC
461 .procname = "reboot-cmd",
462 .data = reboot_command,
463 .maxlen = 256,
464 .mode = 0644,
465 .proc_handler = proc_dostring,
468 .procname = "stop-a",
469 .data = &stop_a_enabled,
470 .maxlen = sizeof (int),
471 .mode = 0644,
472 .proc_handler = proc_dointvec,
475 .procname = "scons-poweroff",
476 .data = &scons_pwroff,
477 .maxlen = sizeof (int),
478 .mode = 0644,
479 .proc_handler = proc_dointvec,
481 #endif
482 #ifdef CONFIG_SPARC64
484 .procname = "tsb-ratio",
485 .data = &sysctl_tsb_ratio,
486 .maxlen = sizeof (int),
487 .mode = 0644,
488 .proc_handler = proc_dointvec,
490 #endif
491 #ifdef __hppa__
493 .procname = "soft-power",
494 .data = &pwrsw_enabled,
495 .maxlen = sizeof (int),
496 .mode = 0644,
497 .proc_handler = proc_dointvec,
500 .procname = "unaligned-trap",
501 .data = &unaligned_enabled,
502 .maxlen = sizeof (int),
503 .mode = 0644,
504 .proc_handler = proc_dointvec,
506 #endif
508 .procname = "ctrl-alt-del",
509 .data = &C_A_D,
510 .maxlen = sizeof(int),
511 .mode = 0644,
512 .proc_handler = proc_dointvec,
514 #ifdef CONFIG_FUNCTION_TRACER
516 .procname = "ftrace_enabled",
517 .data = &ftrace_enabled,
518 .maxlen = sizeof(int),
519 .mode = 0644,
520 .proc_handler = ftrace_enable_sysctl,
522 #endif
523 #ifdef CONFIG_STACK_TRACER
525 .procname = "stack_tracer_enabled",
526 .data = &stack_tracer_enabled,
527 .maxlen = sizeof(int),
528 .mode = 0644,
529 .proc_handler = stack_trace_sysctl,
531 #endif
532 #ifdef CONFIG_TRACING
534 .procname = "ftrace_dump_on_oops",
535 .data = &ftrace_dump_on_oops,
536 .maxlen = sizeof(int),
537 .mode = 0644,
538 .proc_handler = proc_dointvec,
540 #endif
541 #ifdef CONFIG_MODULES
543 .procname = "modprobe",
544 .data = &modprobe_path,
545 .maxlen = KMOD_PATH_LEN,
546 .mode = 0644,
547 .proc_handler = proc_dostring,
550 .procname = "modules_disabled",
551 .data = &modules_disabled,
552 .maxlen = sizeof(int),
553 .mode = 0644,
554 /* only handle a transition from default "0" to "1" */
555 .proc_handler = proc_dointvec_minmax,
556 .extra1 = &one,
557 .extra2 = &one,
559 #endif
560 #ifdef CONFIG_HOTPLUG
562 .procname = "hotplug",
563 .data = &uevent_helper,
564 .maxlen = UEVENT_HELPER_PATH_LEN,
565 .mode = 0644,
566 .proc_handler = proc_dostring,
568 #endif
569 #ifdef CONFIG_CHR_DEV_SG
571 .procname = "sg-big-buff",
572 .data = &sg_big_buff,
573 .maxlen = sizeof (int),
574 .mode = 0444,
575 .proc_handler = proc_dointvec,
577 #endif
578 #ifdef CONFIG_BSD_PROCESS_ACCT
580 .procname = "acct",
581 .data = &acct_parm,
582 .maxlen = 3*sizeof(int),
583 .mode = 0644,
584 .proc_handler = proc_dointvec,
586 #endif
587 #ifdef CONFIG_MAGIC_SYSRQ
589 .procname = "sysrq",
590 .data = &__sysrq_enabled,
591 .maxlen = sizeof (int),
592 .mode = 0644,
593 .proc_handler = sysrq_sysctl_handler,
595 #endif
596 #ifdef CONFIG_PROC_SYSCTL
598 .procname = "cad_pid",
599 .data = NULL,
600 .maxlen = sizeof (int),
601 .mode = 0600,
602 .proc_handler = proc_do_cad_pid,
604 #endif
606 .procname = "threads-max",
607 .data = &max_threads,
608 .maxlen = sizeof(int),
609 .mode = 0644,
610 .proc_handler = proc_dointvec,
613 .procname = "random",
614 .mode = 0555,
615 .child = random_table,
618 .procname = "usermodehelper",
619 .mode = 0555,
620 .child = usermodehelper_table,
623 .procname = "overflowuid",
624 .data = &overflowuid,
625 .maxlen = sizeof(int),
626 .mode = 0644,
627 .proc_handler = proc_dointvec_minmax,
628 .extra1 = &minolduid,
629 .extra2 = &maxolduid,
632 .procname = "overflowgid",
633 .data = &overflowgid,
634 .maxlen = sizeof(int),
635 .mode = 0644,
636 .proc_handler = proc_dointvec_minmax,
637 .extra1 = &minolduid,
638 .extra2 = &maxolduid,
640 #ifdef CONFIG_S390
641 #ifdef CONFIG_MATHEMU
643 .procname = "ieee_emulation_warnings",
644 .data = &sysctl_ieee_emulation_warnings,
645 .maxlen = sizeof(int),
646 .mode = 0644,
647 .proc_handler = proc_dointvec,
649 #endif
651 .procname = "userprocess_debug",
652 .data = &show_unhandled_signals,
653 .maxlen = sizeof(int),
654 .mode = 0644,
655 .proc_handler = proc_dointvec,
657 #endif
659 .procname = "pid_max",
660 .data = &pid_max,
661 .maxlen = sizeof (int),
662 .mode = 0644,
663 .proc_handler = proc_dointvec_minmax,
664 .extra1 = &pid_max_min,
665 .extra2 = &pid_max_max,
668 .procname = "panic_on_oops",
669 .data = &panic_on_oops,
670 .maxlen = sizeof(int),
671 .mode = 0644,
672 .proc_handler = proc_dointvec,
674 #if defined CONFIG_PRINTK
676 .procname = "printk",
677 .data = &console_loglevel,
678 .maxlen = 4*sizeof(int),
679 .mode = 0644,
680 .proc_handler = proc_dointvec,
683 .procname = "printk_ratelimit",
684 .data = &printk_ratelimit_state.interval,
685 .maxlen = sizeof(int),
686 .mode = 0644,
687 .proc_handler = proc_dointvec_jiffies,
690 .procname = "printk_ratelimit_burst",
691 .data = &printk_ratelimit_state.burst,
692 .maxlen = sizeof(int),
693 .mode = 0644,
694 .proc_handler = proc_dointvec,
697 .procname = "printk_delay",
698 .data = &printk_delay_msec,
699 .maxlen = sizeof(int),
700 .mode = 0644,
701 .proc_handler = proc_dointvec_minmax,
702 .extra1 = &zero,
703 .extra2 = &ten_thousand,
706 .procname = "dmesg_restrict",
707 .data = &dmesg_restrict,
708 .maxlen = sizeof(int),
709 .mode = 0644,
710 .proc_handler = proc_dointvec_bool,
713 .procname = "kptr_restrict",
714 .data = &kptr_restrict,
715 .maxlen = sizeof(int),
716 .mode = 0644,
717 .proc_handler = proc_dmesg_restrict,
718 .extra1 = &zero,
719 .extra2 = &two,
721 #endif
723 .procname = "ngroups_max",
724 .data = &ngroups_max,
725 .maxlen = sizeof (int),
726 .mode = 0444,
727 .proc_handler = proc_dointvec,
729 #if defined(CONFIG_LOCKUP_DETECTOR)
731 .procname = "watchdog",
732 .data = &watchdog_enabled,
733 .maxlen = sizeof (int),
734 .mode = 0644,
735 .proc_handler = proc_dowatchdog,
736 .extra1 = &zero,
737 .extra2 = &one,
740 .procname = "watchdog_thresh",
741 .data = &watchdog_thresh,
742 .maxlen = sizeof(int),
743 .mode = 0644,
744 .proc_handler = proc_dowatchdog,
745 .extra1 = &neg_one,
746 .extra2 = &sixty,
749 .procname = "softlockup_panic",
750 .data = &softlockup_panic,
751 .maxlen = sizeof(int),
752 .mode = 0644,
753 .proc_handler = proc_dointvec_bool,
756 .procname = "nmi_watchdog",
757 .data = &watchdog_enabled,
758 .maxlen = sizeof (int),
759 .mode = 0644,
760 .proc_handler = proc_dowatchdog,
761 .extra1 = &zero,
762 .extra2 = &one,
764 #endif
765 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
767 .procname = "unknown_nmi_panic",
768 .data = &unknown_nmi_panic,
769 .maxlen = sizeof (int),
770 .mode = 0644,
771 .proc_handler = proc_dointvec,
773 #endif
774 #if defined(CONFIG_X86)
776 .procname = "panic_on_unrecovered_nmi",
777 .data = &panic_on_unrecovered_nmi,
778 .maxlen = sizeof(int),
779 .mode = 0644,
780 .proc_handler = proc_dointvec,
783 .procname = "panic_on_io_nmi",
784 .data = &panic_on_io_nmi,
785 .maxlen = sizeof(int),
786 .mode = 0644,
787 .proc_handler = proc_dointvec,
790 .procname = "bootloader_type",
791 .data = &bootloader_type,
792 .maxlen = sizeof (int),
793 .mode = 0444,
794 .proc_handler = proc_dointvec,
797 .procname = "bootloader_version",
798 .data = &bootloader_version,
799 .maxlen = sizeof (int),
800 .mode = 0444,
801 .proc_handler = proc_dointvec,
804 .procname = "kstack_depth_to_print",
805 .data = &kstack_depth_to_print,
806 .maxlen = sizeof(int),
807 .mode = 0644,
808 .proc_handler = proc_dointvec,
811 .procname = "io_delay_type",
812 .data = &io_delay_type,
813 .maxlen = sizeof(int),
814 .mode = 0644,
815 .proc_handler = proc_dointvec,
817 #endif
818 #if defined(CONFIG_MMU)
820 .procname = "randomize_va_space",
821 .data = &randomize_va_space,
822 .maxlen = sizeof(int),
823 .mode = 0644,
824 .proc_handler = proc_dointvec,
826 #endif
827 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
829 .procname = "spin_retry",
830 .data = &spin_retry,
831 .maxlen = sizeof (int),
832 .mode = 0644,
833 .proc_handler = proc_dointvec,
835 #endif
836 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
838 .procname = "acpi_video_flags",
839 .data = &acpi_realmode_flags,
840 .maxlen = sizeof (unsigned long),
841 .mode = 0644,
842 .proc_handler = proc_doulongvec_minmax,
844 #endif
845 #ifdef CONFIG_IA64
847 .procname = "ignore-unaligned-usertrap",
848 .data = &no_unaligned_warning,
849 .maxlen = sizeof (int),
850 .mode = 0644,
851 .proc_handler = proc_dointvec,
854 .procname = "unaligned-dump-stack",
855 .data = &unaligned_dump_stack,
856 .maxlen = sizeof (int),
857 .mode = 0644,
858 .proc_handler = proc_dointvec,
860 #endif
861 #ifdef CONFIG_DETECT_HUNG_TASK
863 .procname = "hung_task_panic",
864 .data = &sysctl_hung_task_panic,
865 .maxlen = sizeof(int),
866 .mode = 0644,
867 .proc_handler = proc_dointvec_bool,
870 .procname = "hung_task_check_count",
871 .data = &sysctl_hung_task_check_count,
872 .maxlen = sizeof(unsigned long),
873 .mode = 0644,
874 .proc_handler = proc_doulongvec_minmax,
877 .procname = "hung_task_timeout_secs",
878 .data = &sysctl_hung_task_timeout_secs,
879 .maxlen = sizeof(unsigned long),
880 .mode = 0644,
881 .proc_handler = proc_dohung_task_timeout_secs,
884 .procname = "hung_task_warnings",
885 .data = &sysctl_hung_task_warnings,
886 .maxlen = sizeof(unsigned long),
887 .mode = 0644,
888 .proc_handler = proc_doulongvec_minmax,
890 #endif
891 #ifdef CONFIG_COMPAT
893 .procname = "compat-log",
894 .data = &compat_log,
895 .maxlen = sizeof (int),
896 .mode = 0644,
897 .proc_handler = proc_dointvec,
899 #endif
900 #ifdef CONFIG_RT_MUTEXES
902 .procname = "max_lock_depth",
903 .data = &max_lock_depth,
904 .maxlen = sizeof(int),
905 .mode = 0644,
906 .proc_handler = proc_dointvec,
908 #endif
910 .procname = "poweroff_cmd",
911 .data = &poweroff_cmd,
912 .maxlen = POWEROFF_CMD_PATH_LEN,
913 .mode = 0644,
914 .proc_handler = proc_dostring,
916 #ifdef CONFIG_KEYS
918 .procname = "keys",
919 .mode = 0555,
920 .child = key_sysctls,
922 #endif
923 #ifdef CONFIG_RCU_TORTURE_TEST
925 .procname = "rcutorture_runnable",
926 .data = &rcutorture_runnable,
927 .maxlen = sizeof(int),
928 .mode = 0644,
929 .proc_handler = proc_dointvec,
931 #endif
932 #ifdef CONFIG_PERF_EVENTS
934 * User-space scripts rely on the existence of this file
935 * as a feature check for perf_events being enabled.
937 * So it's an ABI, do not remove!
940 .procname = "perf_event_paranoid",
941 .data = &sysctl_perf_event_paranoid,
942 .maxlen = sizeof(sysctl_perf_event_paranoid),
943 .mode = 0644,
944 .proc_handler = proc_dointvec,
947 .procname = "perf_event_mlock_kb",
948 .data = &sysctl_perf_event_mlock,
949 .maxlen = sizeof(sysctl_perf_event_mlock),
950 .mode = 0644,
951 .proc_handler = proc_dointvec,
954 .procname = "perf_event_max_sample_rate",
955 .data = &sysctl_perf_event_sample_rate,
956 .maxlen = sizeof(sysctl_perf_event_sample_rate),
957 .mode = 0644,
958 .proc_handler = perf_proc_update_handler,
960 #endif
961 #ifdef CONFIG_KMEMCHECK
963 .procname = "kmemcheck",
964 .data = &kmemcheck_enabled,
965 .maxlen = sizeof(int),
966 .mode = 0644,
967 .proc_handler = proc_dointvec,
969 #endif
970 #ifdef CONFIG_BLOCK
972 .procname = "blk_iopoll",
973 .data = &blk_iopoll_enabled,
974 .maxlen = sizeof(int),
975 .mode = 0644,
976 .proc_handler = proc_dointvec,
978 #endif
982 static struct ctl_table vm_table[] = {
984 .procname = "overcommit_memory",
985 .data = &sysctl_overcommit_memory,
986 .maxlen = sizeof(sysctl_overcommit_memory),
987 .mode = 0644,
988 .proc_handler = proc_dointvec_minmax,
989 .extra1 = &zero,
990 .extra2 = &two,
993 .procname = "panic_on_oom",
994 .data = &sysctl_panic_on_oom,
995 .maxlen = sizeof(sysctl_panic_on_oom),
996 .mode = 0644,
997 .proc_handler = proc_dointvec_minmax,
998 .extra1 = &zero,
999 .extra2 = &two,
1002 .procname = "oom_kill_allocating_task",
1003 .data = &sysctl_oom_kill_allocating_task,
1004 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1005 .mode = 0644,
1006 .proc_handler = proc_dointvec,
1009 .procname = "oom_dump_tasks",
1010 .data = &sysctl_oom_dump_tasks,
1011 .maxlen = sizeof(sysctl_oom_dump_tasks),
1012 .mode = 0644,
1013 .proc_handler = proc_dointvec,
1016 .procname = "overcommit_ratio",
1017 .data = &sysctl_overcommit_ratio,
1018 .maxlen = sizeof(sysctl_overcommit_ratio),
1019 .mode = 0644,
1020 .proc_handler = proc_dointvec,
1023 .procname = "page-cluster",
1024 .data = &page_cluster,
1025 .maxlen = sizeof(int),
1026 .mode = 0644,
1027 .proc_handler = proc_dointvec_minmax,
1028 .extra1 = &zero,
1031 .procname = "dirty_background_ratio",
1032 .data = &dirty_background_ratio,
1033 .maxlen = sizeof(dirty_background_ratio),
1034 .mode = 0644,
1035 .proc_handler = dirty_background_ratio_handler,
1036 .extra1 = &zero,
1037 .extra2 = &one_hundred,
1040 .procname = "dirty_background_bytes",
1041 .data = &dirty_background_bytes,
1042 .maxlen = sizeof(dirty_background_bytes),
1043 .mode = 0644,
1044 .proc_handler = dirty_background_bytes_handler,
1045 .extra1 = &one_ul,
1048 .procname = "dirty_ratio",
1049 .data = &vm_dirty_ratio,
1050 .maxlen = sizeof(vm_dirty_ratio),
1051 .mode = 0644,
1052 .proc_handler = dirty_ratio_handler,
1053 .extra1 = &zero,
1054 .extra2 = &one_hundred,
1057 .procname = "dirty_bytes",
1058 .data = &vm_dirty_bytes,
1059 .maxlen = sizeof(vm_dirty_bytes),
1060 .mode = 0644,
1061 .proc_handler = dirty_bytes_handler,
1062 .extra1 = &dirty_bytes_min,
1065 .procname = "dirty_writeback_centisecs",
1066 .data = &dirty_writeback_interval,
1067 .maxlen = sizeof(dirty_writeback_interval),
1068 .mode = 0644,
1069 .proc_handler = dirty_writeback_centisecs_handler,
1072 .procname = "dirty_expire_centisecs",
1073 .data = &dirty_expire_interval,
1074 .maxlen = sizeof(dirty_expire_interval),
1075 .mode = 0644,
1076 .proc_handler = proc_dointvec_minmax,
1077 .extra1 = &zero,
1080 .procname = "nr_pdflush_threads",
1081 .data = &nr_pdflush_threads,
1082 .maxlen = sizeof nr_pdflush_threads,
1083 .mode = 0444 /* read-only*/,
1084 .proc_handler = proc_dointvec,
1087 .procname = "swappiness",
1088 .data = &vm_swappiness,
1089 .maxlen = sizeof(vm_swappiness),
1090 .mode = 0644,
1091 .proc_handler = proc_dointvec_minmax,
1092 .extra1 = &zero,
1093 .extra2 = &one_hundred,
1095 #ifdef CONFIG_HUGETLB_PAGE
1097 .procname = "nr_hugepages",
1098 .data = NULL,
1099 .maxlen = sizeof(unsigned long),
1100 .mode = 0644,
1101 .proc_handler = hugetlb_sysctl_handler,
1102 .extra1 = (void *)&hugetlb_zero,
1103 .extra2 = (void *)&hugetlb_infinity,
1105 #ifdef CONFIG_NUMA
1107 .procname = "nr_hugepages_mempolicy",
1108 .data = NULL,
1109 .maxlen = sizeof(unsigned long),
1110 .mode = 0644,
1111 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1112 .extra1 = (void *)&hugetlb_zero,
1113 .extra2 = (void *)&hugetlb_infinity,
1115 #endif
1117 .procname = "hugetlb_shm_group",
1118 .data = &sysctl_hugetlb_shm_group,
1119 .maxlen = sizeof(gid_t),
1120 .mode = 0644,
1121 .proc_handler = proc_dointvec,
1124 .procname = "hugepages_treat_as_movable",
1125 .data = &hugepages_treat_as_movable,
1126 .maxlen = sizeof(int),
1127 .mode = 0644,
1128 .proc_handler = hugetlb_treat_movable_handler,
1131 .procname = "nr_overcommit_hugepages",
1132 .data = NULL,
1133 .maxlen = sizeof(unsigned long),
1134 .mode = 0644,
1135 .proc_handler = hugetlb_overcommit_handler,
1136 .extra1 = (void *)&hugetlb_zero,
1137 .extra2 = (void *)&hugetlb_infinity,
1139 #endif
1141 .procname = "lowmem_reserve_ratio",
1142 .data = &sysctl_lowmem_reserve_ratio,
1143 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1144 .mode = 0644,
1145 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1148 .procname = "drop_caches",
1149 .data = &sysctl_drop_caches,
1150 .maxlen = sizeof(int),
1151 .mode = 0644,
1152 .proc_handler = drop_caches_sysctl_handler,
1153 .extra1 = &one,
1154 .extra2 = &three,
1156 #ifdef CONFIG_COMPACTION
1158 .procname = "compact_memory",
1159 .data = &sysctl_compact_memory,
1160 .maxlen = sizeof(int),
1161 .mode = 0200,
1162 .proc_handler = sysctl_compaction_handler,
1165 .procname = "extfrag_threshold",
1166 .data = &sysctl_extfrag_threshold,
1167 .maxlen = sizeof(int),
1168 .mode = 0644,
1169 .proc_handler = sysctl_extfrag_handler,
1170 .extra1 = &min_extfrag_threshold,
1171 .extra2 = &max_extfrag_threshold,
1174 #endif /* CONFIG_COMPACTION */
1176 .procname = "min_free_kbytes",
1177 .data = &min_free_kbytes,
1178 .maxlen = sizeof(min_free_kbytes),
1179 .mode = 0644,
1180 .proc_handler = min_free_kbytes_sysctl_handler,
1181 .extra1 = &zero,
1184 .procname = "percpu_pagelist_fraction",
1185 .data = &percpu_pagelist_fraction,
1186 .maxlen = sizeof(percpu_pagelist_fraction),
1187 .mode = 0644,
1188 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1189 .extra1 = &min_percpu_pagelist_fract,
1191 #ifdef CONFIG_MMU
1193 .procname = "max_map_count",
1194 .data = &sysctl_max_map_count,
1195 .maxlen = sizeof(sysctl_max_map_count),
1196 .mode = 0644,
1197 .proc_handler = proc_dointvec_unsigned,
1199 #else
1201 .procname = "nr_trim_pages",
1202 .data = &sysctl_nr_trim_pages,
1203 .maxlen = sizeof(sysctl_nr_trim_pages),
1204 .mode = 0644,
1205 .proc_handler = proc_dointvec_unsigned,
1207 #endif
1209 .procname = "laptop_mode",
1210 .data = &laptop_mode,
1211 .maxlen = sizeof(laptop_mode),
1212 .mode = 0644,
1213 .proc_handler = proc_dointvec_jiffies,
1216 .procname = "block_dump",
1217 .data = &block_dump,
1218 .maxlen = sizeof(block_dump),
1219 .mode = 0644,
1220 .proc_handler = proc_dointvec_unsigned,
1223 .procname = "vfs_cache_pressure",
1224 .data = &sysctl_vfs_cache_pressure,
1225 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1226 .mode = 0644,
1227 .proc_handler = proc_dointvec_unsigned,
1229 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1231 .procname = "legacy_va_layout",
1232 .data = &sysctl_legacy_va_layout,
1233 .maxlen = sizeof(sysctl_legacy_va_layout),
1234 .mode = 0644,
1235 .proc_handler = proc_dointvec_unsigned,
1237 #endif
1238 #ifdef CONFIG_NUMA
1240 .procname = "zone_reclaim_mode",
1241 .data = &zone_reclaim_mode,
1242 .maxlen = sizeof(zone_reclaim_mode),
1243 .mode = 0644,
1244 .proc_handler = proc_dointvec_unsigned,
1247 .procname = "min_unmapped_ratio",
1248 .data = &sysctl_min_unmapped_ratio,
1249 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1250 .mode = 0644,
1251 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1252 .extra1 = &zero,
1253 .extra2 = &one_hundred,
1256 .procname = "min_slab_ratio",
1257 .data = &sysctl_min_slab_ratio,
1258 .maxlen = sizeof(sysctl_min_slab_ratio),
1259 .mode = 0644,
1260 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1261 .extra1 = &zero,
1262 .extra2 = &one_hundred,
1264 #endif
1265 #ifdef CONFIG_SMP
1267 .procname = "stat_interval",
1268 .data = &sysctl_stat_interval,
1269 .maxlen = sizeof(sysctl_stat_interval),
1270 .mode = 0644,
1271 .proc_handler = proc_dointvec_jiffies,
1273 #endif
1274 #ifdef CONFIG_MMU
1276 .procname = "mmap_min_addr",
1277 .data = &dac_mmap_min_addr,
1278 .maxlen = sizeof(unsigned long),
1279 .mode = 0644,
1280 .proc_handler = mmap_min_addr_handler,
1282 #endif
1283 #ifdef CONFIG_NUMA
1285 .procname = "numa_zonelist_order",
1286 .data = &numa_zonelist_order,
1287 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1288 .mode = 0644,
1289 .proc_handler = numa_zonelist_order_handler,
1291 #endif
1292 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1293 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1295 .procname = "vdso_enabled",
1296 .data = &vdso_enabled,
1297 .maxlen = sizeof(vdso_enabled),
1298 .mode = 0644,
1299 .proc_handler = proc_dointvec_unsigned,
1301 #endif
1302 #ifdef CONFIG_HIGHMEM
1304 .procname = "highmem_is_dirtyable",
1305 .data = &vm_highmem_is_dirtyable,
1306 .maxlen = sizeof(vm_highmem_is_dirtyable),
1307 .mode = 0644,
1308 .proc_handler = proc_dointvec_bool,
1310 #endif
1312 .procname = "scan_unevictable_pages",
1313 .data = &scan_unevictable_pages,
1314 .maxlen = sizeof(scan_unevictable_pages),
1315 .mode = 0644,
1316 .proc_handler = scan_unevictable_handler,
1318 #ifdef CONFIG_MEMORY_FAILURE
1320 .procname = "memory_failure_early_kill",
1321 .data = &sysctl_memory_failure_early_kill,
1322 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1323 .mode = 0644,
1324 .proc_handler = proc_dointvec_bool,
1327 .procname = "memory_failure_recovery",
1328 .data = &sysctl_memory_failure_recovery,
1329 .maxlen = sizeof(sysctl_memory_failure_recovery),
1330 .mode = 0644,
1331 .proc_handler = proc_dointvec_bool,
1333 #endif
1337 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1338 static struct ctl_table binfmt_misc_table[] = {
1341 #endif
1343 static struct ctl_table fs_table[] = {
1345 .procname = "inode-nr",
1346 .data = &inodes_stat,
1347 .maxlen = 2*sizeof(int),
1348 .mode = 0444,
1349 .proc_handler = proc_nr_inodes,
1352 .procname = "inode-state",
1353 .data = &inodes_stat,
1354 .maxlen = 7*sizeof(int),
1355 .mode = 0444,
1356 .proc_handler = proc_nr_inodes,
1359 .procname = "file-nr",
1360 .data = &files_stat,
1361 .maxlen = sizeof(files_stat),
1362 .mode = 0444,
1363 .proc_handler = proc_nr_files,
1366 .procname = "file-max",
1367 .data = &files_stat.max_files,
1368 .maxlen = sizeof(files_stat.max_files),
1369 .mode = 0644,
1370 .proc_handler = proc_doulongvec_minmax,
1373 .procname = "nr_open",
1374 .data = &sysctl_nr_open,
1375 .maxlen = sizeof(int),
1376 .mode = 0644,
1377 .proc_handler = proc_dointvec_minmax,
1378 .extra1 = &sysctl_nr_open_min,
1379 .extra2 = &sysctl_nr_open_max,
1382 .procname = "dentry-state",
1383 .data = &dentry_stat,
1384 .maxlen = 6*sizeof(int),
1385 .mode = 0444,
1386 .proc_handler = proc_nr_dentry,
1389 .procname = "overflowuid",
1390 .data = &fs_overflowuid,
1391 .maxlen = sizeof(int),
1392 .mode = 0644,
1393 .proc_handler = proc_dointvec_minmax,
1394 .extra1 = &minolduid,
1395 .extra2 = &maxolduid,
1398 .procname = "overflowgid",
1399 .data = &fs_overflowgid,
1400 .maxlen = sizeof(int),
1401 .mode = 0644,
1402 .proc_handler = proc_dointvec_minmax,
1403 .extra1 = &minolduid,
1404 .extra2 = &maxolduid,
1406 #ifdef CONFIG_FILE_LOCKING
1408 .procname = "leases-enable",
1409 .data = &leases_enable,
1410 .maxlen = sizeof(int),
1411 .mode = 0644,
1412 .proc_handler = proc_dointvec,
1414 #endif
1415 #ifdef CONFIG_DNOTIFY
1417 .procname = "dir-notify-enable",
1418 .data = &dir_notify_enable,
1419 .maxlen = sizeof(int),
1420 .mode = 0644,
1421 .proc_handler = proc_dointvec,
1423 #endif
1424 #ifdef CONFIG_MMU
1425 #ifdef CONFIG_FILE_LOCKING
1427 .procname = "lease-break-time",
1428 .data = &lease_break_time,
1429 .maxlen = sizeof(int),
1430 .mode = 0644,
1431 .proc_handler = proc_dointvec,
1433 #endif
1434 #ifdef CONFIG_AIO
1436 .procname = "aio-nr",
1437 .data = &aio_nr,
1438 .maxlen = sizeof(aio_nr),
1439 .mode = 0444,
1440 .proc_handler = proc_doulongvec_minmax,
1443 .procname = "aio-max-nr",
1444 .data = &aio_max_nr,
1445 .maxlen = sizeof(aio_max_nr),
1446 .mode = 0644,
1447 .proc_handler = proc_doulongvec_minmax,
1449 #endif /* CONFIG_AIO */
1450 #ifdef CONFIG_INOTIFY_USER
1452 .procname = "inotify",
1453 .mode = 0555,
1454 .child = inotify_table,
1456 #endif
1457 #ifdef CONFIG_EPOLL
1459 .procname = "epoll",
1460 .mode = 0555,
1461 .child = epoll_table,
1463 #endif
1464 #endif
1466 .procname = "suid_dumpable",
1467 .data = &suid_dumpable,
1468 .maxlen = sizeof(int),
1469 .mode = 0644,
1470 .proc_handler = proc_dointvec_minmax,
1471 .extra1 = &zero,
1472 .extra2 = &two,
1474 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1476 .procname = "binfmt_misc",
1477 .mode = 0555,
1478 .child = binfmt_misc_table,
1480 #endif
1482 .procname = "pipe-max-size",
1483 .data = &pipe_max_size,
1484 .maxlen = sizeof(int),
1485 .mode = 0644,
1486 .proc_handler = &pipe_proc_fn,
1487 .extra1 = &pipe_min_size,
1492 static struct ctl_table debug_table[] = {
1493 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1494 defined(CONFIG_S390) || defined(CONFIG_TILE)
1496 .procname = "exception-trace",
1497 .data = &show_unhandled_signals,
1498 .maxlen = sizeof(int),
1499 .mode = 0644,
1500 .proc_handler = proc_dointvec
1502 #endif
1503 #if defined(CONFIG_OPTPROBES)
1505 .procname = "kprobes-optimization",
1506 .data = &sysctl_kprobes_optimization,
1507 .maxlen = sizeof(int),
1508 .mode = 0644,
1509 .proc_handler = proc_kprobes_optimization_handler,
1510 .extra1 = &zero,
1511 .extra2 = &one,
1513 #endif
1517 static struct ctl_table dev_table[] = {
1521 static DEFINE_SPINLOCK(sysctl_lock);
1523 /* called under sysctl_lock */
1524 static int use_table(struct ctl_table_header *p)
1526 if (unlikely(p->unregistering))
1527 return 0;
1528 p->used++;
1529 return 1;
1532 /* called under sysctl_lock */
1533 static void unuse_table(struct ctl_table_header *p)
1535 if (!--p->used)
1536 if (unlikely(p->unregistering))
1537 complete(p->unregistering);
1540 /* called under sysctl_lock, will reacquire if has to wait */
1541 static void start_unregistering(struct ctl_table_header *p)
1544 * if p->used is 0, nobody will ever touch that entry again;
1545 * we'll eliminate all paths to it before dropping sysctl_lock
1547 if (unlikely(p->used)) {
1548 struct completion wait;
1549 init_completion(&wait);
1550 p->unregistering = &wait;
1551 spin_unlock(&sysctl_lock);
1552 wait_for_completion(&wait);
1553 spin_lock(&sysctl_lock);
1554 } else {
1555 /* anything non-NULL; we'll never dereference it */
1556 p->unregistering = ERR_PTR(-EINVAL);
1559 * do not remove from the list until nobody holds it; walking the
1560 * list in do_sysctl() relies on that.
1562 list_del_init(&p->ctl_entry);
1565 void sysctl_head_get(struct ctl_table_header *head)
1567 spin_lock(&sysctl_lock);
1568 head->count++;
1569 spin_unlock(&sysctl_lock);
1572 void sysctl_head_put(struct ctl_table_header *head)
1574 spin_lock(&sysctl_lock);
1575 if (!--head->count)
1576 kfree_rcu(head, rcu);
1577 spin_unlock(&sysctl_lock);
1580 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1582 if (!head)
1583 BUG();
1584 spin_lock(&sysctl_lock);
1585 if (!use_table(head))
1586 head = ERR_PTR(-ENOENT);
1587 spin_unlock(&sysctl_lock);
1588 return head;
1591 void sysctl_head_finish(struct ctl_table_header *head)
1593 if (!head)
1594 return;
1595 spin_lock(&sysctl_lock);
1596 unuse_table(head);
1597 spin_unlock(&sysctl_lock);
1600 static struct ctl_table_set *
1601 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1603 struct ctl_table_set *set = &root->default_set;
1604 if (root->lookup)
1605 set = root->lookup(root, namespaces);
1606 return set;
1609 static struct list_head *
1610 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1612 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1613 return &set->list;
1616 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1617 struct ctl_table_header *prev)
1619 struct ctl_table_root *root;
1620 struct list_head *header_list;
1621 struct ctl_table_header *head;
1622 struct list_head *tmp;
1624 spin_lock(&sysctl_lock);
1625 if (prev) {
1626 head = prev;
1627 tmp = &prev->ctl_entry;
1628 unuse_table(prev);
1629 goto next;
1631 tmp = &root_table_header.ctl_entry;
1632 for (;;) {
1633 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1635 if (!use_table(head))
1636 goto next;
1637 spin_unlock(&sysctl_lock);
1638 return head;
1639 next:
1640 root = head->root;
1641 tmp = tmp->next;
1642 header_list = lookup_header_list(root, namespaces);
1643 if (tmp != header_list)
1644 continue;
1646 do {
1647 root = list_entry(root->root_list.next,
1648 struct ctl_table_root, root_list);
1649 if (root == &sysctl_table_root)
1650 goto out;
1651 header_list = lookup_header_list(root, namespaces);
1652 } while (list_empty(header_list));
1653 tmp = header_list->next;
1655 out:
1656 spin_unlock(&sysctl_lock);
1657 return NULL;
1660 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1662 return __sysctl_head_next(current->nsproxy, prev);
1665 void register_sysctl_root(struct ctl_table_root *root)
1667 spin_lock(&sysctl_lock);
1668 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1669 spin_unlock(&sysctl_lock);
1673 * sysctl_perm does NOT grant the superuser all rights automatically, because
1674 * some sysctl variables are readonly even to root.
1677 static int test_perm(int mode, int op)
1679 if (!current_euid())
1680 mode >>= 6;
1681 else if (in_egroup_p(0))
1682 mode >>= 3;
1683 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1684 return 0;
1685 return -EACCES;
1688 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1690 int mode;
1692 if (root->permissions)
1693 mode = root->permissions(root, current->nsproxy, table);
1694 else
1695 mode = table->mode;
1697 return test_perm(mode, op);
1700 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1702 for (; table->procname; table++) {
1703 table->parent = parent;
1704 if (table->child)
1705 sysctl_set_parent(table, table->child);
1709 static __init int sysctl_init(void)
1711 sysctl_set_parent(NULL, root_table);
1712 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1713 sysctl_check_table(current->nsproxy, root_table);
1714 #endif
1715 return 0;
1718 core_initcall(sysctl_init);
1720 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1721 struct ctl_table *table)
1723 struct ctl_table *p;
1724 const char *s = branch->procname;
1726 /* branch should have named subdirectory as its first element */
1727 if (!s || !branch->child)
1728 return NULL;
1730 /* ... and nothing else */
1731 if (branch[1].procname)
1732 return NULL;
1734 /* table should contain subdirectory with the same name */
1735 for (p = table; p->procname; p++) {
1736 if (!p->child)
1737 continue;
1738 if (p->procname && strcmp(p->procname, s) == 0)
1739 return p;
1741 return NULL;
1744 /* see if attaching q to p would be an improvement */
1745 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1747 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1748 struct ctl_table *next;
1749 int is_better = 0;
1750 int not_in_parent = !p->attached_by;
1752 while ((next = is_branch_in(by, to)) != NULL) {
1753 if (by == q->attached_by)
1754 is_better = 1;
1755 if (to == p->attached_by)
1756 not_in_parent = 1;
1757 by = by->child;
1758 to = next->child;
1761 if (is_better && not_in_parent) {
1762 q->attached_by = by;
1763 q->attached_to = to;
1764 q->parent = p;
1769 * __register_sysctl_paths - register a sysctl hierarchy
1770 * @root: List of sysctl headers to register on
1771 * @namespaces: Data to compute which lists of sysctl entries are visible
1772 * @path: The path to the directory the sysctl table is in.
1773 * @table: the top-level table structure
1775 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1776 * array. A completely 0 filled entry terminates the table.
1778 * The members of the &struct ctl_table structure are used as follows:
1780 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1781 * enter a sysctl file
1783 * data - a pointer to data for use by proc_handler
1785 * maxlen - the maximum size in bytes of the data
1787 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1789 * child - a pointer to the child sysctl table if this entry is a directory, or
1790 * %NULL.
1792 * proc_handler - the text handler routine (described below)
1794 * de - for internal use by the sysctl routines
1796 * extra1, extra2 - extra pointers usable by the proc handler routines
1798 * Leaf nodes in the sysctl tree will be represented by a single file
1799 * under /proc; non-leaf nodes will be represented by directories.
1801 * sysctl(2) can automatically manage read and write requests through
1802 * the sysctl table. The data and maxlen fields of the ctl_table
1803 * struct enable minimal validation of the values being written to be
1804 * performed, and the mode field allows minimal authentication.
1806 * There must be a proc_handler routine for any terminal nodes
1807 * mirrored under /proc/sys (non-terminals are handled by a built-in
1808 * directory handler). Several default handlers are available to
1809 * cover common cases -
1811 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1812 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1813 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1815 * It is the handler's job to read the input buffer from user memory
1816 * and process it. The handler should return 0 on success.
1818 * This routine returns %NULL on a failure to register, and a pointer
1819 * to the table header on success.
1821 struct ctl_table_header *__register_sysctl_paths(
1822 struct ctl_table_root *root,
1823 struct nsproxy *namespaces,
1824 const struct ctl_path *path, struct ctl_table *table)
1826 struct ctl_table_header *header;
1827 struct ctl_table *new, **prevp;
1828 unsigned int n, npath;
1829 struct ctl_table_set *set;
1831 /* Count the path components */
1832 for (npath = 0; path[npath].procname; ++npath)
1836 * For each path component, allocate a 2-element ctl_table array.
1837 * The first array element will be filled with the sysctl entry
1838 * for this, the second will be the sentinel (procname == 0).
1840 * We allocate everything in one go so that we don't have to
1841 * worry about freeing additional memory in unregister_sysctl_table.
1843 header = kzalloc(sizeof(struct ctl_table_header) +
1844 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1845 if (!header)
1846 return NULL;
1848 new = (struct ctl_table *) (header + 1);
1850 /* Now connect the dots */
1851 prevp = &header->ctl_table;
1852 for (n = 0; n < npath; ++n, ++path) {
1853 /* Copy the procname */
1854 new->procname = path->procname;
1855 new->mode = 0555;
1857 *prevp = new;
1858 prevp = &new->child;
1860 new += 2;
1862 *prevp = table;
1863 header->ctl_table_arg = table;
1865 INIT_LIST_HEAD(&header->ctl_entry);
1866 header->used = 0;
1867 header->unregistering = NULL;
1868 header->root = root;
1869 sysctl_set_parent(NULL, header->ctl_table);
1870 header->count = 1;
1871 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1872 if (sysctl_check_table(namespaces, header->ctl_table)) {
1873 kfree(header);
1874 return NULL;
1876 #endif
1877 spin_lock(&sysctl_lock);
1878 header->set = lookup_header_set(root, namespaces);
1879 header->attached_by = header->ctl_table;
1880 header->attached_to = root_table;
1881 header->parent = &root_table_header;
1882 for (set = header->set; set; set = set->parent) {
1883 struct ctl_table_header *p;
1884 list_for_each_entry(p, &set->list, ctl_entry) {
1885 if (p->unregistering)
1886 continue;
1887 try_attach(p, header);
1890 header->parent->count++;
1891 list_add_tail(&header->ctl_entry, &header->set->list);
1892 spin_unlock(&sysctl_lock);
1894 return header;
1898 * register_sysctl_table_path - register a sysctl table hierarchy
1899 * @path: The path to the directory the sysctl table is in.
1900 * @table: the top-level table structure
1902 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1903 * array. A completely 0 filled entry terminates the table.
1905 * See __register_sysctl_paths for more details.
1907 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1908 struct ctl_table *table)
1910 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1911 path, table);
1915 * register_sysctl_table - register a sysctl table hierarchy
1916 * @table: the top-level table structure
1918 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1919 * array. A completely 0 filled entry terminates the table.
1921 * See register_sysctl_paths for more details.
1923 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1925 static const struct ctl_path null_path[] = { {} };
1927 return register_sysctl_paths(null_path, table);
1931 * unregister_sysctl_table - unregister a sysctl table hierarchy
1932 * @header: the header returned from register_sysctl_table
1934 * Unregisters the sysctl table and all children. proc entries may not
1935 * actually be removed until they are no longer used by anyone.
1937 void unregister_sysctl_table(struct ctl_table_header * header)
1939 might_sleep();
1941 if (header == NULL)
1942 return;
1944 spin_lock(&sysctl_lock);
1945 start_unregistering(header);
1946 if (!--header->parent->count) {
1947 WARN_ON(1);
1948 kfree_rcu(header->parent, rcu);
1950 if (!--header->count)
1951 kfree_rcu(header, rcu);
1952 spin_unlock(&sysctl_lock);
1955 int sysctl_is_seen(struct ctl_table_header *p)
1957 struct ctl_table_set *set = p->set;
1958 int res;
1959 spin_lock(&sysctl_lock);
1960 if (p->unregistering)
1961 res = 0;
1962 else if (!set->is_seen)
1963 res = 1;
1964 else
1965 res = set->is_seen(set);
1966 spin_unlock(&sysctl_lock);
1967 return res;
1970 void setup_sysctl_set(struct ctl_table_set *p,
1971 struct ctl_table_set *parent,
1972 int (*is_seen)(struct ctl_table_set *))
1974 INIT_LIST_HEAD(&p->list);
1975 p->parent = parent ? parent : &sysctl_table_root.default_set;
1976 p->is_seen = is_seen;
1979 #else /* !CONFIG_SYSCTL */
1980 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1982 return NULL;
1985 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1986 struct ctl_table *table)
1988 return NULL;
1991 void unregister_sysctl_table(struct ctl_table_header * table)
1995 void setup_sysctl_set(struct ctl_table_set *p,
1996 struct ctl_table_set *parent,
1997 int (*is_seen)(struct ctl_table_set *))
2001 void sysctl_head_put(struct ctl_table_header *head)
2005 #endif /* CONFIG_SYSCTL */
2008 * /proc/sys support
2011 #ifdef CONFIG_PROC_SYSCTL
2013 static int _proc_do_string(void* data, int maxlen, int write,
2014 void __user *buffer,
2015 size_t *lenp, loff_t *ppos)
2017 size_t len;
2018 char __user *p;
2019 char c;
2021 if (!data || !maxlen || !*lenp) {
2022 *lenp = 0;
2023 return 0;
2026 if (write) {
2027 len = 0;
2028 p = buffer;
2029 while (len < *lenp) {
2030 if (get_user(c, p++))
2031 return -EFAULT;
2032 if (c == 0 || c == '\n')
2033 break;
2034 len++;
2036 if (len >= maxlen)
2037 len = maxlen-1;
2038 if(copy_from_user(data, buffer, len))
2039 return -EFAULT;
2040 ((char *) data)[len] = 0;
2041 *ppos += *lenp;
2042 } else {
2043 len = strlen(data);
2044 if (len > maxlen)
2045 len = maxlen;
2047 if (*ppos > len) {
2048 *lenp = 0;
2049 return 0;
2052 data += *ppos;
2053 len -= *ppos;
2055 if (len > *lenp)
2056 len = *lenp;
2057 if (len)
2058 if(copy_to_user(buffer, data, len))
2059 return -EFAULT;
2060 if (len < *lenp) {
2061 if(put_user('\n', ((char __user *) buffer) + len))
2062 return -EFAULT;
2063 len++;
2065 *lenp = len;
2066 *ppos += len;
2068 return 0;
2072 * proc_dostring - read a string sysctl
2073 * @table: the sysctl table
2074 * @write: %TRUE if this is a write to the sysctl file
2075 * @buffer: the user buffer
2076 * @lenp: the size of the user buffer
2077 * @ppos: file position
2079 * Reads/writes a string from/to the user buffer. If the kernel
2080 * buffer provided is not large enough to hold the string, the
2081 * string is truncated. The copied string is %NULL-terminated.
2082 * If the string is being read by the user process, it is copied
2083 * and a newline '\n' is added. It is truncated if the buffer is
2084 * not large enough.
2086 * Returns 0 on success.
2088 int proc_dostring(struct ctl_table *table, int write,
2089 void __user *buffer, size_t *lenp, loff_t *ppos)
2091 return _proc_do_string(table->data, table->maxlen, write,
2092 buffer, lenp, ppos);
2095 static size_t proc_skip_spaces(char **buf)
2097 size_t ret;
2098 char *tmp = skip_spaces(*buf);
2099 ret = tmp - *buf;
2100 *buf = tmp;
2101 return ret;
2104 static void proc_skip_char(char **buf, size_t *size, const char v)
2106 while (*size) {
2107 if (**buf != v)
2108 break;
2109 (*size)--;
2110 (*buf)++;
2114 #define TMPBUFLEN 22
2116 * proc_get_long - reads an ASCII formatted integer from a user buffer
2118 * @buf: a kernel buffer
2119 * @size: size of the kernel buffer
2120 * @val: this is where the number will be stored
2121 * @neg: set to %TRUE if number is negative
2122 * @perm_tr: a vector which contains the allowed trailers
2123 * @perm_tr_len: size of the perm_tr vector
2124 * @tr: pointer to store the trailer character
2126 * In case of success %0 is returned and @buf and @size are updated with
2127 * the amount of bytes read. If @tr is non-NULL and a trailing
2128 * character exists (size is non-zero after returning from this
2129 * function), @tr is updated with the trailing character.
2131 static int proc_get_long(char **buf, size_t *size,
2132 unsigned long *val, bool *neg,
2133 const char *perm_tr, unsigned perm_tr_len, char *tr)
2135 int len;
2136 char *p, tmp[TMPBUFLEN];
2138 if (!*size)
2139 return -EINVAL;
2141 len = *size;
2142 if (len > TMPBUFLEN - 1)
2143 len = TMPBUFLEN - 1;
2145 memcpy(tmp, *buf, len);
2147 tmp[len] = 0;
2148 p = tmp;
2149 if (*p == '-' && *size > 1) {
2150 *neg = true;
2151 p++;
2152 } else
2153 *neg = false;
2154 if (!isdigit(*p))
2155 return -EINVAL;
2157 *val = simple_strtoul(p, &p, 0);
2159 len = p - tmp;
2161 /* We don't know if the next char is whitespace thus we may accept
2162 * invalid integers (e.g. 1234...a) or two integers instead of one
2163 * (e.g. 123...1). So lets not allow such large numbers. */
2164 if (len == TMPBUFLEN - 1)
2165 return -EINVAL;
2167 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2168 return -EINVAL;
2170 if (tr && (len < *size))
2171 *tr = *p;
2173 *buf += len;
2174 *size -= len;
2176 return 0;
2180 * proc_put_long - converts an integer to a decimal ASCII formatted string
2182 * @buf: the user buffer
2183 * @size: the size of the user buffer
2184 * @val: the integer to be converted
2185 * @neg: sign of the number, %TRUE for negative
2187 * In case of success %0 is returned and @buf and @size are updated with
2188 * the amount of bytes written.
2190 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2191 bool neg)
2193 int len;
2194 char tmp[TMPBUFLEN], *p = tmp;
2196 sprintf(p, "%s%lu", neg ? "-" : "", val);
2197 len = strlen(tmp);
2198 if (len > *size)
2199 len = *size;
2200 if (copy_to_user(*buf, tmp, len))
2201 return -EFAULT;
2202 *size -= len;
2203 *buf += len;
2204 return 0;
2206 #undef TMPBUFLEN
2208 static int proc_put_char(void __user **buf, size_t *size, char c)
2210 if (*size) {
2211 char __user **buffer = (char __user **)buf;
2212 if (put_user(c, *buffer))
2213 return -EFAULT;
2214 (*size)--, (*buffer)++;
2215 *buf = *buffer;
2217 return 0;
2220 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2221 int *valp,
2222 int write, void *data)
2224 if (write) {
2225 *valp = *negp ? -*lvalp : *lvalp;
2226 } else {
2227 int val = *valp;
2228 if (val < 0) {
2229 *negp = true;
2230 *lvalp = (unsigned long)-val;
2231 } else {
2232 *negp = false;
2233 *lvalp = (unsigned long)val;
2236 return 0;
2239 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2241 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2242 int write, void __user *buffer,
2243 size_t *lenp, loff_t *ppos,
2244 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2245 int write, void *data),
2246 void *data)
2248 int *i, vleft, first = 1, err = 0;
2249 unsigned long page = 0;
2250 size_t left;
2251 char *kbuf;
2253 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2254 *lenp = 0;
2255 return 0;
2258 i = (int *) tbl_data;
2259 vleft = table->maxlen / sizeof(*i);
2260 left = *lenp;
2262 if (!conv)
2263 conv = do_proc_dointvec_conv;
2265 if (write) {
2266 if (left > PAGE_SIZE - 1)
2267 left = PAGE_SIZE - 1;
2268 page = __get_free_page(GFP_TEMPORARY);
2269 kbuf = (char *) page;
2270 if (!kbuf)
2271 return -ENOMEM;
2272 if (copy_from_user(kbuf, buffer, left)) {
2273 err = -EFAULT;
2274 goto free;
2276 kbuf[left] = 0;
2279 for (; left && vleft--; i++, first=0) {
2280 unsigned long lval;
2281 bool neg;
2283 if (write) {
2284 left -= proc_skip_spaces(&kbuf);
2286 if (!left)
2287 break;
2288 err = proc_get_long(&kbuf, &left, &lval, &neg,
2289 proc_wspace_sep,
2290 sizeof(proc_wspace_sep), NULL);
2291 if (err)
2292 break;
2293 if (conv(&neg, &lval, i, 1, data)) {
2294 err = -EINVAL;
2295 break;
2297 } else {
2298 if (conv(&neg, &lval, i, 0, data)) {
2299 err = -EINVAL;
2300 break;
2302 if (!first)
2303 err = proc_put_char(&buffer, &left, '\t');
2304 if (err)
2305 break;
2306 err = proc_put_long(&buffer, &left, lval, neg);
2307 if (err)
2308 break;
2312 if (!write && !first && left && !err)
2313 err = proc_put_char(&buffer, &left, '\n');
2314 if (write && !err && left)
2315 left -= proc_skip_spaces(&kbuf);
2316 free:
2317 if (write) {
2318 free_page(page);
2319 if (first)
2320 return err ? : -EINVAL;
2322 *lenp -= left;
2323 *ppos += *lenp;
2324 return err;
2327 static int do_proc_dointvec(struct ctl_table *table, int write,
2328 void __user *buffer, size_t *lenp, loff_t *ppos,
2329 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2330 int write, void *data),
2331 void *data)
2333 return __do_proc_dointvec(table->data, table, write,
2334 buffer, lenp, ppos, conv, data);
2338 * proc_dointvec - read a vector of integers
2339 * @table: the sysctl table
2340 * @write: %TRUE if this is a write to the sysctl file
2341 * @buffer: the user buffer
2342 * @lenp: the size of the user buffer
2343 * @ppos: file position
2345 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2346 * values from/to the user buffer, treated as an ASCII string.
2348 * Returns 0 on success.
2350 int proc_dointvec(struct ctl_table *table, int write,
2351 void __user *buffer, size_t *lenp, loff_t *ppos)
2353 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2354 NULL,NULL);
2358 * Taint values can only be increased
2359 * This means we can safely use a temporary.
2361 static int proc_taint(struct ctl_table *table, int write,
2362 void __user *buffer, size_t *lenp, loff_t *ppos)
2364 struct ctl_table t;
2365 unsigned long tmptaint = get_taint();
2366 int err;
2368 if (write && !capable(CAP_SYS_ADMIN))
2369 return -EPERM;
2371 t = *table;
2372 t.data = &tmptaint;
2373 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2374 if (err < 0)
2375 return err;
2377 if (write) {
2379 * Poor man's atomic or. Not worth adding a primitive
2380 * to everyone's atomic.h for this
2382 int i;
2383 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2384 if ((tmptaint >> i) & 1)
2385 add_taint(i);
2389 return err;
2392 #ifdef CONFIG_PRINTK
2393 static int proc_dmesg_restrict(struct ctl_table *table, int write,
2394 void __user *buffer, size_t *lenp, loff_t *ppos)
2396 if (write && !capable(CAP_SYS_ADMIN))
2397 return -EPERM;
2399 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2401 #endif
2403 struct do_proc_dointvec_minmax_conv_param {
2404 int *min;
2405 int *max;
2408 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2409 int *valp,
2410 int write, void *data)
2412 struct do_proc_dointvec_minmax_conv_param *param = data;
2413 if (write) {
2414 int val = *negp ? -*lvalp : *lvalp;
2415 if ((param->min && *param->min > val) ||
2416 (param->max && *param->max < val))
2417 return -EINVAL;
2418 *valp = val;
2419 } else {
2420 int val = *valp;
2421 if (val < 0) {
2422 *negp = true;
2423 *lvalp = (unsigned long)-val;
2424 } else {
2425 *negp = false;
2426 *lvalp = (unsigned long)val;
2429 return 0;
2433 * proc_dointvec_minmax - read a vector of integers with min/max values
2434 * @table: the sysctl table
2435 * @write: %TRUE if this is a write to the sysctl file
2436 * @buffer: the user buffer
2437 * @lenp: the size of the user buffer
2438 * @ppos: file position
2440 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2441 * values from/to the user buffer, treated as an ASCII string.
2443 * This routine will ensure the values are within the range specified by
2444 * table->extra1 (min) and table->extra2 (max).
2446 * Returns 0 on success.
2448 int proc_dointvec_minmax(struct ctl_table *table, int write,
2449 void __user *buffer, size_t *lenp, loff_t *ppos)
2451 struct do_proc_dointvec_minmax_conv_param param = {
2452 .min = (int *) table->extra1,
2453 .max = (int *) table->extra2,
2455 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2456 do_proc_dointvec_minmax_conv, &param);
2460 * proc_dointvec_bool - read a vector of integers with 0/1 values
2461 * @table: the sysctl table
2462 * @write: %TRUE if this is a write to the sysctl file
2463 * @buffer: the user buffer
2464 * @lenp: the size of the user buffer
2465 * @ppos: file position
2467 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2468 * values from/to the user buffer, treated as an ASCII string.
2470 * This routine will ensure the values are either 0 or 1.
2472 * Returns 0 on success.
2474 int proc_dointvec_bool(struct ctl_table *table, int write,
2475 void __user *buffer, size_t *lenp, loff_t *ppos)
2477 struct do_proc_dointvec_minmax_conv_param param = {
2478 .min = &zero,
2479 .max = &one,
2481 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2482 do_proc_dointvec_minmax_conv, &param);
2484 EXPORT_SYMBOL(proc_dointvec_bool);
2487 * proc_dointvec_unsigned - read a vector of integers with positive values
2488 * @table: the sysctl table
2489 * @write: %TRUE if this is a write to the sysctl file
2490 * @buffer: the user buffer
2491 * @lenp: the size of the user buffer
2492 * @ppos: file position
2494 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2495 * values from/to the user buffer, treated as an ASCII string.
2497 * This routine will ensure the values are positive.
2499 * Returns 0 on success.
2501 int proc_dointvec_unsigned(struct ctl_table *table, int write,
2502 void __user *buffer, size_t *lenp, loff_t *ppos)
2504 struct do_proc_dointvec_minmax_conv_param param = {
2505 .min = &zero,
2506 .max = (int *) table->extra2,
2508 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2509 do_proc_dointvec_minmax_conv, &param);
2511 EXPORT_SYMBOL(proc_dointvec_unsigned);
2513 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2514 void __user *buffer,
2515 size_t *lenp, loff_t *ppos,
2516 unsigned long convmul,
2517 unsigned long convdiv)
2519 unsigned long *i, *min, *max;
2520 int vleft, first = 1, err = 0;
2521 unsigned long page = 0;
2522 size_t left;
2523 char *kbuf;
2525 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2526 *lenp = 0;
2527 return 0;
2530 i = (unsigned long *) data;
2531 min = (unsigned long *) table->extra1;
2532 max = (unsigned long *) table->extra2;
2533 vleft = table->maxlen / sizeof(unsigned long);
2534 left = *lenp;
2536 if (write) {
2537 if (left > PAGE_SIZE - 1)
2538 left = PAGE_SIZE - 1;
2539 page = __get_free_page(GFP_TEMPORARY);
2540 kbuf = (char *) page;
2541 if (!kbuf)
2542 return -ENOMEM;
2543 if (copy_from_user(kbuf, buffer, left)) {
2544 err = -EFAULT;
2545 goto free;
2547 kbuf[left] = 0;
2550 for (; left && vleft--; i++, first = 0) {
2551 unsigned long val;
2553 if (write) {
2554 bool neg;
2556 left -= proc_skip_spaces(&kbuf);
2558 err = proc_get_long(&kbuf, &left, &val, &neg,
2559 proc_wspace_sep,
2560 sizeof(proc_wspace_sep), NULL);
2561 if (err)
2562 break;
2563 if (neg)
2564 continue;
2565 if ((min && val < *min) || (max && val > *max))
2566 continue;
2567 *i = val;
2568 } else {
2569 val = convdiv * (*i) / convmul;
2570 if (!first)
2571 err = proc_put_char(&buffer, &left, '\t');
2572 err = proc_put_long(&buffer, &left, val, false);
2573 if (err)
2574 break;
2578 if (!write && !first && left && !err)
2579 err = proc_put_char(&buffer, &left, '\n');
2580 if (write && !err)
2581 left -= proc_skip_spaces(&kbuf);
2582 free:
2583 if (write) {
2584 free_page(page);
2585 if (first)
2586 return err ? : -EINVAL;
2588 *lenp -= left;
2589 *ppos += *lenp;
2590 return err;
2593 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2594 void __user *buffer,
2595 size_t *lenp, loff_t *ppos,
2596 unsigned long convmul,
2597 unsigned long convdiv)
2599 return __do_proc_doulongvec_minmax(table->data, table, write,
2600 buffer, lenp, ppos, convmul, convdiv);
2604 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2605 * @table: the sysctl table
2606 * @write: %TRUE if this is a write to the sysctl file
2607 * @buffer: the user buffer
2608 * @lenp: the size of the user buffer
2609 * @ppos: file position
2611 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2612 * values from/to the user buffer, treated as an ASCII string.
2614 * This routine will ensure the values are within the range specified by
2615 * table->extra1 (min) and table->extra2 (max).
2617 * Returns 0 on success.
2619 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2620 void __user *buffer, size_t *lenp, loff_t *ppos)
2622 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2626 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2627 * @table: the sysctl table
2628 * @write: %TRUE if this is a write to the sysctl file
2629 * @buffer: the user buffer
2630 * @lenp: the size of the user buffer
2631 * @ppos: file position
2633 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2634 * values from/to the user buffer, treated as an ASCII string. The values
2635 * are treated as milliseconds, and converted to jiffies when they are stored.
2637 * This routine will ensure the values are within the range specified by
2638 * table->extra1 (min) and table->extra2 (max).
2640 * Returns 0 on success.
2642 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2643 void __user *buffer,
2644 size_t *lenp, loff_t *ppos)
2646 return do_proc_doulongvec_minmax(table, write, buffer,
2647 lenp, ppos, HZ, 1000l);
2651 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2652 int *valp,
2653 int write, void *data)
2655 if (write) {
2656 if (*lvalp > LONG_MAX / HZ)
2657 return 1;
2658 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
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 = lval / HZ;
2671 return 0;
2674 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2675 int *valp,
2676 int write, void *data)
2678 if (write) {
2679 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2680 return 1;
2681 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2682 } else {
2683 int val = *valp;
2684 unsigned long lval;
2685 if (val < 0) {
2686 *negp = true;
2687 lval = (unsigned long)-val;
2688 } else {
2689 *negp = false;
2690 lval = (unsigned long)val;
2692 *lvalp = jiffies_to_clock_t(lval);
2694 return 0;
2697 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2698 int *valp,
2699 int write, void *data)
2701 if (write) {
2702 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2703 } else {
2704 int val = *valp;
2705 unsigned long lval;
2706 if (val < 0) {
2707 *negp = true;
2708 lval = (unsigned long)-val;
2709 } else {
2710 *negp = false;
2711 lval = (unsigned long)val;
2713 *lvalp = jiffies_to_msecs(lval);
2715 return 0;
2719 * proc_dointvec_jiffies - read a vector of integers as seconds
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
2726 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2727 * values from/to the user buffer, treated as an ASCII string.
2728 * The values read are assumed to be in seconds, and are converted into
2729 * jiffies.
2731 * Returns 0 on success.
2733 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2734 void __user *buffer, size_t *lenp, loff_t *ppos)
2736 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2737 do_proc_dointvec_jiffies_conv,NULL);
2741 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2742 * @table: the sysctl table
2743 * @write: %TRUE if this is a write to the sysctl file
2744 * @buffer: the user buffer
2745 * @lenp: the size of the user buffer
2746 * @ppos: pointer to the file position
2748 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2749 * values from/to the user buffer, treated as an ASCII string.
2750 * The values read are assumed to be in 1/USER_HZ seconds, and
2751 * are converted into jiffies.
2753 * Returns 0 on success.
2755 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2756 void __user *buffer, size_t *lenp, loff_t *ppos)
2758 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2759 do_proc_dointvec_userhz_jiffies_conv,NULL);
2763 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2764 * @table: the sysctl table
2765 * @write: %TRUE if this is a write to the sysctl file
2766 * @buffer: the user buffer
2767 * @lenp: the size of the user buffer
2768 * @ppos: file position
2769 * @ppos: the current position in the file
2771 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2772 * values from/to the user buffer, treated as an ASCII string.
2773 * The values read are assumed to be in 1/1000 seconds, and
2774 * are converted into jiffies.
2776 * Returns 0 on success.
2778 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2779 void __user *buffer, size_t *lenp, loff_t *ppos)
2781 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2782 do_proc_dointvec_ms_jiffies_conv, NULL);
2785 static int proc_do_cad_pid(struct ctl_table *table, int write,
2786 void __user *buffer, size_t *lenp, loff_t *ppos)
2788 struct pid *new_pid;
2789 pid_t tmp;
2790 int r;
2792 tmp = pid_vnr(cad_pid);
2794 r = __do_proc_dointvec(&tmp, table, write, buffer,
2795 lenp, ppos, NULL, NULL);
2796 if (r || !write)
2797 return r;
2799 new_pid = find_get_pid(tmp);
2800 if (!new_pid)
2801 return -ESRCH;
2803 put_pid(xchg(&cad_pid, new_pid));
2804 return 0;
2808 * proc_do_large_bitmap - read/write from/to a large bitmap
2809 * @table: the sysctl table
2810 * @write: %TRUE if this is a write to the sysctl file
2811 * @buffer: the user buffer
2812 * @lenp: the size of the user buffer
2813 * @ppos: file position
2815 * The bitmap is stored at table->data and the bitmap length (in bits)
2816 * in table->maxlen.
2818 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2819 * large bitmaps may be represented in a compact manner. Writing into
2820 * the file will clear the bitmap then update it with the given input.
2822 * Returns 0 on success.
2824 int proc_do_large_bitmap(struct ctl_table *table, int write,
2825 void __user *buffer, size_t *lenp, loff_t *ppos)
2827 int err = 0;
2828 bool first = 1;
2829 size_t left = *lenp;
2830 unsigned long bitmap_len = table->maxlen;
2831 unsigned long *bitmap = (unsigned long *) table->data;
2832 unsigned long *tmp_bitmap = NULL;
2833 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2835 if (!bitmap_len || !left || (*ppos && !write)) {
2836 *lenp = 0;
2837 return 0;
2840 if (write) {
2841 unsigned long page = 0;
2842 char *kbuf;
2844 if (left > PAGE_SIZE - 1)
2845 left = PAGE_SIZE - 1;
2847 page = __get_free_page(GFP_TEMPORARY);
2848 kbuf = (char *) page;
2849 if (!kbuf)
2850 return -ENOMEM;
2851 if (copy_from_user(kbuf, buffer, left)) {
2852 free_page(page);
2853 return -EFAULT;
2855 kbuf[left] = 0;
2857 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2858 GFP_KERNEL);
2859 if (!tmp_bitmap) {
2860 free_page(page);
2861 return -ENOMEM;
2863 proc_skip_char(&kbuf, &left, '\n');
2864 while (!err && left) {
2865 unsigned long val_a, val_b;
2866 bool neg;
2868 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2869 sizeof(tr_a), &c);
2870 if (err)
2871 break;
2872 if (val_a >= bitmap_len || neg) {
2873 err = -EINVAL;
2874 break;
2877 val_b = val_a;
2878 if (left) {
2879 kbuf++;
2880 left--;
2883 if (c == '-') {
2884 err = proc_get_long(&kbuf, &left, &val_b,
2885 &neg, tr_b, sizeof(tr_b),
2886 &c);
2887 if (err)
2888 break;
2889 if (val_b >= bitmap_len || neg ||
2890 val_a > val_b) {
2891 err = -EINVAL;
2892 break;
2894 if (left) {
2895 kbuf++;
2896 left--;
2900 while (val_a <= val_b)
2901 set_bit(val_a++, tmp_bitmap);
2903 first = 0;
2904 proc_skip_char(&kbuf, &left, '\n');
2906 free_page(page);
2907 } else {
2908 unsigned long bit_a, bit_b = 0;
2910 while (left) {
2911 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2912 if (bit_a >= bitmap_len)
2913 break;
2914 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2915 bit_a + 1) - 1;
2917 if (!first) {
2918 err = proc_put_char(&buffer, &left, ',');
2919 if (err)
2920 break;
2922 err = proc_put_long(&buffer, &left, bit_a, false);
2923 if (err)
2924 break;
2925 if (bit_a != bit_b) {
2926 err = proc_put_char(&buffer, &left, '-');
2927 if (err)
2928 break;
2929 err = proc_put_long(&buffer, &left, bit_b, false);
2930 if (err)
2931 break;
2934 first = 0; bit_b++;
2936 if (!err)
2937 err = proc_put_char(&buffer, &left, '\n');
2940 if (!err) {
2941 if (write) {
2942 if (*ppos)
2943 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2944 else
2945 memcpy(bitmap, tmp_bitmap,
2946 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2948 kfree(tmp_bitmap);
2949 *lenp -= left;
2950 *ppos += *lenp;
2951 return 0;
2952 } else {
2953 kfree(tmp_bitmap);
2954 return err;
2958 #else /* CONFIG_PROC_SYSCTL */
2960 int proc_dostring(struct ctl_table *table, int write,
2961 void __user *buffer, size_t *lenp, loff_t *ppos)
2963 return -ENOSYS;
2966 int proc_dointvec(struct ctl_table *table, int write,
2967 void __user *buffer, size_t *lenp, loff_t *ppos)
2969 return -ENOSYS;
2972 int proc_dointvec_minmax(struct ctl_table *table, int write,
2973 void __user *buffer, size_t *lenp, loff_t *ppos)
2975 return -ENOSYS;
2978 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2979 void __user *buffer, size_t *lenp, loff_t *ppos)
2981 return -ENOSYS;
2984 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2985 void __user *buffer, size_t *lenp, loff_t *ppos)
2987 return -ENOSYS;
2990 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2991 void __user *buffer, size_t *lenp, loff_t *ppos)
2993 return -ENOSYS;
2996 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2997 void __user *buffer, size_t *lenp, loff_t *ppos)
2999 return -ENOSYS;
3002 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
3003 void __user *buffer,
3004 size_t *lenp, loff_t *ppos)
3006 return -ENOSYS;
3010 #endif /* CONFIG_PROC_SYSCTL */
3013 * No sense putting this after each symbol definition, twice,
3014 * exception granted :-)
3016 EXPORT_SYMBOL(proc_dointvec);
3017 EXPORT_SYMBOL(proc_dointvec_jiffies);
3018 EXPORT_SYMBOL(proc_dointvec_minmax);
3019 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3020 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3021 EXPORT_SYMBOL(proc_dostring);
3022 EXPORT_SYMBOL(proc_doulongvec_minmax);
3023 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3024 EXPORT_SYMBOL(register_sysctl_table);
3025 EXPORT_SYMBOL(register_sysctl_paths);
3026 EXPORT_SYMBOL(unregister_sysctl_table);