x86, binutils, xen: Fix another wrong size directive
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / kernel / sysctl.c
blob4e17828edb77a33e469d84a3f7ae192b9a74ea03
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/proc_fs.h>
28 #include <linux/security.h>
29 #include <linux/ctype.h>
30 #include <linux/kmemcheck.h>
31 #include <linux/fs.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/ratelimit.h>
40 #include <linux/compaction.h>
41 #include <linux/hugetlb.h>
42 #include <linux/initrd.h>
43 #include <linux/key.h>
44 #include <linux/times.h>
45 #include <linux/limits.h>
46 #include <linux/dcache.h>
47 #include <linux/dnotify.h>
48 #include <linux/syscalls.h>
49 #include <linux/vmstat.h>
50 #include <linux/nfs_fs.h>
51 #include <linux/acpi.h>
52 #include <linux/reboot.h>
53 #include <linux/ftrace.h>
54 #include <linux/perf_event.h>
55 #include <linux/kprobes.h>
56 #include <linux/pipe_fs_i.h>
57 #include <linux/oom.h>
59 #include <asm/uaccess.h>
60 #include <asm/processor.h>
62 #ifdef CONFIG_X86
63 #include <asm/nmi.h>
64 #include <asm/stacktrace.h>
65 #include <asm/io.h>
66 #endif
67 #ifdef CONFIG_BSD_PROCESS_ACCT
68 #include <linux/acct.h>
69 #endif
70 #ifdef CONFIG_RT_MUTEXES
71 #include <linux/rtmutex.h>
72 #endif
73 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
74 #include <linux/lockdep.h>
75 #endif
76 #ifdef CONFIG_CHR_DEV_SG
77 #include <scsi/sg.h>
78 #endif
80 #ifdef CONFIG_LOCKUP_DETECTOR
81 #include <linux/nmi.h>
82 #endif
85 #if defined(CONFIG_SYSCTL)
87 /* External variables not in a header file. */
88 extern int sysctl_overcommit_memory;
89 extern int sysctl_overcommit_ratio;
90 extern int max_threads;
91 extern int core_uses_pid;
92 extern int suid_dumpable;
93 extern char core_pattern[];
94 extern unsigned int core_pipe_limit;
95 extern int pid_max;
96 extern int min_free_kbytes;
97 extern int pid_max_min, pid_max_max;
98 extern int sysctl_drop_caches;
99 extern int percpu_pagelist_fraction;
100 extern int compat_log;
101 extern int latencytop_enabled;
102 extern int sysctl_nr_open_min, sysctl_nr_open_max;
103 #ifndef CONFIG_MMU
104 extern int sysctl_nr_trim_pages;
105 #endif
106 #ifdef CONFIG_BLOCK
107 extern int blk_iopoll_enabled;
108 #endif
110 /* Constants used for minimum and maximum */
111 #ifdef CONFIG_LOCKUP_DETECTOR
112 static int sixty = 60;
113 static int neg_one = -1;
114 #endif
116 static int zero;
117 static int __maybe_unused one = 1;
118 static int __maybe_unused two = 2;
119 static unsigned long one_ul = 1;
120 static int one_hundred = 100;
121 #ifdef CONFIG_PRINTK
122 static int ten_thousand = 10000;
123 #endif
125 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
126 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
128 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
129 static int maxolduid = 65535;
130 static int minolduid;
131 static int min_percpu_pagelist_fract = 8;
133 static int ngroups_max = NGROUPS_MAX;
135 #ifdef CONFIG_INOTIFY_USER
136 #include <linux/inotify.h>
137 #endif
138 #ifdef CONFIG_SPARC
139 #include <asm/system.h>
140 #endif
142 #ifdef CONFIG_SPARC64
143 extern int sysctl_tsb_ratio;
144 #endif
146 #ifdef __hppa__
147 extern int pwrsw_enabled;
148 extern int unaligned_enabled;
149 #endif
151 #ifdef CONFIG_S390
152 #ifdef CONFIG_MATHEMU
153 extern int sysctl_ieee_emulation_warnings;
154 #endif
155 extern int sysctl_userprocess_debug;
156 extern int spin_retry;
157 #endif
159 #ifdef CONFIG_IA64
160 extern int no_unaligned_warning;
161 extern int unaligned_dump_stack;
162 #endif
164 #ifdef CONFIG_PROC_SYSCTL
165 static int proc_do_cad_pid(struct ctl_table *table, int write,
166 void __user *buffer, size_t *lenp, loff_t *ppos);
167 static int proc_taint(struct ctl_table *table, int write,
168 void __user *buffer, size_t *lenp, loff_t *ppos);
169 #endif
171 #ifdef CONFIG_MAGIC_SYSRQ
172 /* Note: sysrq code uses it's own private copy */
173 static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
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,
250 * NOTE: do not add new entries to this table unless you have read
251 * Documentation/sysctl/ctl_unnumbered.txt
256 #ifdef CONFIG_SCHED_DEBUG
257 static int min_sched_granularity_ns = 100000; /* 100 usecs */
258 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
259 static int min_wakeup_granularity_ns; /* 0 usecs */
260 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
261 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
262 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
263 static int min_sched_shares_ratelimit = 100000; /* 100 usec */
264 static int max_sched_shares_ratelimit = NSEC_PER_SEC; /* 1 second */
265 #endif
267 #ifdef CONFIG_COMPACTION
268 static int min_extfrag_threshold;
269 static int max_extfrag_threshold = 1000;
270 #endif
272 static struct ctl_table kern_table[] = {
274 .procname = "sched_child_runs_first",
275 .data = &sysctl_sched_child_runs_first,
276 .maxlen = sizeof(unsigned int),
277 .mode = 0644,
278 .proc_handler = proc_dointvec,
280 #ifdef CONFIG_SCHED_DEBUG
282 .procname = "sched_min_granularity_ns",
283 .data = &sysctl_sched_min_granularity,
284 .maxlen = sizeof(unsigned int),
285 .mode = 0644,
286 .proc_handler = sched_proc_update_handler,
287 .extra1 = &min_sched_granularity_ns,
288 .extra2 = &max_sched_granularity_ns,
291 .procname = "sched_latency_ns",
292 .data = &sysctl_sched_latency,
293 .maxlen = sizeof(unsigned int),
294 .mode = 0644,
295 .proc_handler = sched_proc_update_handler,
296 .extra1 = &min_sched_granularity_ns,
297 .extra2 = &max_sched_granularity_ns,
300 .procname = "sched_wakeup_granularity_ns",
301 .data = &sysctl_sched_wakeup_granularity,
302 .maxlen = sizeof(unsigned int),
303 .mode = 0644,
304 .proc_handler = sched_proc_update_handler,
305 .extra1 = &min_wakeup_granularity_ns,
306 .extra2 = &max_wakeup_granularity_ns,
309 .procname = "sched_shares_ratelimit",
310 .data = &sysctl_sched_shares_ratelimit,
311 .maxlen = sizeof(unsigned int),
312 .mode = 0644,
313 .proc_handler = sched_proc_update_handler,
314 .extra1 = &min_sched_shares_ratelimit,
315 .extra2 = &max_sched_shares_ratelimit,
318 .procname = "sched_tunable_scaling",
319 .data = &sysctl_sched_tunable_scaling,
320 .maxlen = sizeof(enum sched_tunable_scaling),
321 .mode = 0644,
322 .proc_handler = sched_proc_update_handler,
323 .extra1 = &min_sched_tunable_scaling,
324 .extra2 = &max_sched_tunable_scaling,
327 .procname = "sched_shares_thresh",
328 .data = &sysctl_sched_shares_thresh,
329 .maxlen = sizeof(unsigned int),
330 .mode = 0644,
331 .proc_handler = proc_dointvec_minmax,
332 .extra1 = &zero,
335 .procname = "sched_migration_cost",
336 .data = &sysctl_sched_migration_cost,
337 .maxlen = sizeof(unsigned int),
338 .mode = 0644,
339 .proc_handler = proc_dointvec,
342 .procname = "sched_nr_migrate",
343 .data = &sysctl_sched_nr_migrate,
344 .maxlen = sizeof(unsigned int),
345 .mode = 0644,
346 .proc_handler = proc_dointvec,
349 .procname = "sched_time_avg",
350 .data = &sysctl_sched_time_avg,
351 .maxlen = sizeof(unsigned int),
352 .mode = 0644,
353 .proc_handler = proc_dointvec,
356 .procname = "timer_migration",
357 .data = &sysctl_timer_migration,
358 .maxlen = sizeof(unsigned int),
359 .mode = 0644,
360 .proc_handler = proc_dointvec_minmax,
361 .extra1 = &zero,
362 .extra2 = &one,
364 #endif
366 .procname = "sched_rt_period_us",
367 .data = &sysctl_sched_rt_period,
368 .maxlen = sizeof(unsigned int),
369 .mode = 0644,
370 .proc_handler = sched_rt_handler,
373 .procname = "sched_rt_runtime_us",
374 .data = &sysctl_sched_rt_runtime,
375 .maxlen = sizeof(int),
376 .mode = 0644,
377 .proc_handler = sched_rt_handler,
380 .procname = "sched_compat_yield",
381 .data = &sysctl_sched_compat_yield,
382 .maxlen = sizeof(unsigned int),
383 .mode = 0644,
384 .proc_handler = proc_dointvec,
386 #ifdef CONFIG_PROVE_LOCKING
388 .procname = "prove_locking",
389 .data = &prove_locking,
390 .maxlen = sizeof(int),
391 .mode = 0644,
392 .proc_handler = proc_dointvec,
394 #endif
395 #ifdef CONFIG_LOCK_STAT
397 .procname = "lock_stat",
398 .data = &lock_stat,
399 .maxlen = sizeof(int),
400 .mode = 0644,
401 .proc_handler = proc_dointvec,
403 #endif
405 .procname = "panic",
406 .data = &panic_timeout,
407 .maxlen = sizeof(int),
408 .mode = 0644,
409 .proc_handler = proc_dointvec,
412 .procname = "core_uses_pid",
413 .data = &core_uses_pid,
414 .maxlen = sizeof(int),
415 .mode = 0644,
416 .proc_handler = proc_dointvec,
419 .procname = "core_pattern",
420 .data = core_pattern,
421 .maxlen = CORENAME_MAX_SIZE,
422 .mode = 0644,
423 .proc_handler = proc_dostring,
426 .procname = "core_pipe_limit",
427 .data = &core_pipe_limit,
428 .maxlen = sizeof(unsigned int),
429 .mode = 0644,
430 .proc_handler = proc_dointvec,
432 #ifdef CONFIG_PROC_SYSCTL
434 .procname = "tainted",
435 .maxlen = sizeof(long),
436 .mode = 0644,
437 .proc_handler = proc_taint,
439 #endif
440 #ifdef CONFIG_LATENCYTOP
442 .procname = "latencytop",
443 .data = &latencytop_enabled,
444 .maxlen = sizeof(int),
445 .mode = 0644,
446 .proc_handler = proc_dointvec,
448 #endif
449 #ifdef CONFIG_BLK_DEV_INITRD
451 .procname = "real-root-dev",
452 .data = &real_root_dev,
453 .maxlen = sizeof(int),
454 .mode = 0644,
455 .proc_handler = proc_dointvec,
457 #endif
459 .procname = "print-fatal-signals",
460 .data = &print_fatal_signals,
461 .maxlen = sizeof(int),
462 .mode = 0644,
463 .proc_handler = proc_dointvec,
465 #ifdef CONFIG_SPARC
467 .procname = "reboot-cmd",
468 .data = reboot_command,
469 .maxlen = 256,
470 .mode = 0644,
471 .proc_handler = proc_dostring,
474 .procname = "stop-a",
475 .data = &stop_a_enabled,
476 .maxlen = sizeof (int),
477 .mode = 0644,
478 .proc_handler = proc_dointvec,
481 .procname = "scons-poweroff",
482 .data = &scons_pwroff,
483 .maxlen = sizeof (int),
484 .mode = 0644,
485 .proc_handler = proc_dointvec,
487 #endif
488 #ifdef CONFIG_SPARC64
490 .procname = "tsb-ratio",
491 .data = &sysctl_tsb_ratio,
492 .maxlen = sizeof (int),
493 .mode = 0644,
494 .proc_handler = proc_dointvec,
496 #endif
497 #ifdef __hppa__
499 .procname = "soft-power",
500 .data = &pwrsw_enabled,
501 .maxlen = sizeof (int),
502 .mode = 0644,
503 .proc_handler = proc_dointvec,
506 .procname = "unaligned-trap",
507 .data = &unaligned_enabled,
508 .maxlen = sizeof (int),
509 .mode = 0644,
510 .proc_handler = proc_dointvec,
512 #endif
514 .procname = "ctrl-alt-del",
515 .data = &C_A_D,
516 .maxlen = sizeof(int),
517 .mode = 0644,
518 .proc_handler = proc_dointvec,
520 #ifdef CONFIG_FUNCTION_TRACER
522 .procname = "ftrace_enabled",
523 .data = &ftrace_enabled,
524 .maxlen = sizeof(int),
525 .mode = 0644,
526 .proc_handler = ftrace_enable_sysctl,
528 #endif
529 #ifdef CONFIG_STACK_TRACER
531 .procname = "stack_tracer_enabled",
532 .data = &stack_tracer_enabled,
533 .maxlen = sizeof(int),
534 .mode = 0644,
535 .proc_handler = stack_trace_sysctl,
537 #endif
538 #ifdef CONFIG_TRACING
540 .procname = "ftrace_dump_on_oops",
541 .data = &ftrace_dump_on_oops,
542 .maxlen = sizeof(int),
543 .mode = 0644,
544 .proc_handler = proc_dointvec,
546 #endif
547 #ifdef CONFIG_MODULES
549 .procname = "modprobe",
550 .data = &modprobe_path,
551 .maxlen = KMOD_PATH_LEN,
552 .mode = 0644,
553 .proc_handler = proc_dostring,
556 .procname = "modules_disabled",
557 .data = &modules_disabled,
558 .maxlen = sizeof(int),
559 .mode = 0644,
560 /* only handle a transition from default "0" to "1" */
561 .proc_handler = proc_dointvec_minmax,
562 .extra1 = &one,
563 .extra2 = &one,
565 #endif
566 #ifdef CONFIG_HOTPLUG
568 .procname = "hotplug",
569 .data = &uevent_helper,
570 .maxlen = UEVENT_HELPER_PATH_LEN,
571 .mode = 0644,
572 .proc_handler = proc_dostring,
574 #endif
575 #ifdef CONFIG_CHR_DEV_SG
577 .procname = "sg-big-buff",
578 .data = &sg_big_buff,
579 .maxlen = sizeof (int),
580 .mode = 0444,
581 .proc_handler = proc_dointvec,
583 #endif
584 #ifdef CONFIG_BSD_PROCESS_ACCT
586 .procname = "acct",
587 .data = &acct_parm,
588 .maxlen = 3*sizeof(int),
589 .mode = 0644,
590 .proc_handler = proc_dointvec,
592 #endif
593 #ifdef CONFIG_MAGIC_SYSRQ
595 .procname = "sysrq",
596 .data = &__sysrq_enabled,
597 .maxlen = sizeof (int),
598 .mode = 0644,
599 .proc_handler = sysrq_sysctl_handler,
601 #endif
602 #ifdef CONFIG_PROC_SYSCTL
604 .procname = "cad_pid",
605 .data = NULL,
606 .maxlen = sizeof (int),
607 .mode = 0600,
608 .proc_handler = proc_do_cad_pid,
610 #endif
612 .procname = "threads-max",
613 .data = &max_threads,
614 .maxlen = sizeof(int),
615 .mode = 0644,
616 .proc_handler = proc_dointvec,
619 .procname = "random",
620 .mode = 0555,
621 .child = random_table,
624 .procname = "overflowuid",
625 .data = &overflowuid,
626 .maxlen = sizeof(int),
627 .mode = 0644,
628 .proc_handler = proc_dointvec_minmax,
629 .extra1 = &minolduid,
630 .extra2 = &maxolduid,
633 .procname = "overflowgid",
634 .data = &overflowgid,
635 .maxlen = sizeof(int),
636 .mode = 0644,
637 .proc_handler = proc_dointvec_minmax,
638 .extra1 = &minolduid,
639 .extra2 = &maxolduid,
641 #ifdef CONFIG_S390
642 #ifdef CONFIG_MATHEMU
644 .procname = "ieee_emulation_warnings",
645 .data = &sysctl_ieee_emulation_warnings,
646 .maxlen = sizeof(int),
647 .mode = 0644,
648 .proc_handler = proc_dointvec,
650 #endif
652 .procname = "userprocess_debug",
653 .data = &show_unhandled_signals,
654 .maxlen = sizeof(int),
655 .mode = 0644,
656 .proc_handler = proc_dointvec,
658 #endif
660 .procname = "pid_max",
661 .data = &pid_max,
662 .maxlen = sizeof (int),
663 .mode = 0644,
664 .proc_handler = proc_dointvec_minmax,
665 .extra1 = &pid_max_min,
666 .extra2 = &pid_max_max,
669 .procname = "panic_on_oops",
670 .data = &panic_on_oops,
671 .maxlen = sizeof(int),
672 .mode = 0644,
673 .proc_handler = proc_dointvec,
675 #if defined CONFIG_PRINTK
677 .procname = "printk",
678 .data = &console_loglevel,
679 .maxlen = 4*sizeof(int),
680 .mode = 0644,
681 .proc_handler = proc_dointvec,
684 .procname = "printk_ratelimit",
685 .data = &printk_ratelimit_state.interval,
686 .maxlen = sizeof(int),
687 .mode = 0644,
688 .proc_handler = proc_dointvec_jiffies,
691 .procname = "printk_ratelimit_burst",
692 .data = &printk_ratelimit_state.burst,
693 .maxlen = sizeof(int),
694 .mode = 0644,
695 .proc_handler = proc_dointvec,
698 .procname = "printk_delay",
699 .data = &printk_delay_msec,
700 .maxlen = sizeof(int),
701 .mode = 0644,
702 .proc_handler = proc_dointvec_minmax,
703 .extra1 = &zero,
704 .extra2 = &ten_thousand,
707 .procname = "dmesg_restrict",
708 .data = &dmesg_restrict,
709 .maxlen = sizeof(int),
710 .mode = 0644,
711 .proc_handler = proc_dointvec_minmax,
712 .extra1 = &zero,
713 .extra2 = &one,
715 #endif
717 .procname = "ngroups_max",
718 .data = &ngroups_max,
719 .maxlen = sizeof (int),
720 .mode = 0444,
721 .proc_handler = proc_dointvec,
723 #if defined(CONFIG_LOCKUP_DETECTOR)
725 .procname = "watchdog",
726 .data = &watchdog_enabled,
727 .maxlen = sizeof (int),
728 .mode = 0644,
729 .proc_handler = proc_dowatchdog_enabled,
732 .procname = "watchdog_thresh",
733 .data = &softlockup_thresh,
734 .maxlen = sizeof(int),
735 .mode = 0644,
736 .proc_handler = proc_dowatchdog_thresh,
737 .extra1 = &neg_one,
738 .extra2 = &sixty,
741 .procname = "softlockup_panic",
742 .data = &softlockup_panic,
743 .maxlen = sizeof(int),
744 .mode = 0644,
745 .proc_handler = proc_dointvec_minmax,
746 .extra1 = &zero,
747 .extra2 = &one,
749 #endif
750 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) && !defined(CONFIG_LOCKUP_DETECTOR)
752 .procname = "unknown_nmi_panic",
753 .data = &unknown_nmi_panic,
754 .maxlen = sizeof (int),
755 .mode = 0644,
756 .proc_handler = proc_dointvec,
759 .procname = "nmi_watchdog",
760 .data = &nmi_watchdog_enabled,
761 .maxlen = sizeof (int),
762 .mode = 0644,
763 .proc_handler = proc_nmi_enabled,
765 #endif
766 #if defined(CONFIG_X86)
768 .procname = "panic_on_unrecovered_nmi",
769 .data = &panic_on_unrecovered_nmi,
770 .maxlen = sizeof(int),
771 .mode = 0644,
772 .proc_handler = proc_dointvec,
775 .procname = "panic_on_io_nmi",
776 .data = &panic_on_io_nmi,
777 .maxlen = sizeof(int),
778 .mode = 0644,
779 .proc_handler = proc_dointvec,
782 .procname = "bootloader_type",
783 .data = &bootloader_type,
784 .maxlen = sizeof (int),
785 .mode = 0444,
786 .proc_handler = proc_dointvec,
789 .procname = "bootloader_version",
790 .data = &bootloader_version,
791 .maxlen = sizeof (int),
792 .mode = 0444,
793 .proc_handler = proc_dointvec,
796 .procname = "kstack_depth_to_print",
797 .data = &kstack_depth_to_print,
798 .maxlen = sizeof(int),
799 .mode = 0644,
800 .proc_handler = proc_dointvec,
803 .procname = "io_delay_type",
804 .data = &io_delay_type,
805 .maxlen = sizeof(int),
806 .mode = 0644,
807 .proc_handler = proc_dointvec,
809 #endif
810 #if defined(CONFIG_MMU)
812 .procname = "randomize_va_space",
813 .data = &randomize_va_space,
814 .maxlen = sizeof(int),
815 .mode = 0644,
816 .proc_handler = proc_dointvec,
818 #endif
819 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
821 .procname = "spin_retry",
822 .data = &spin_retry,
823 .maxlen = sizeof (int),
824 .mode = 0644,
825 .proc_handler = proc_dointvec,
827 #endif
828 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
830 .procname = "acpi_video_flags",
831 .data = &acpi_realmode_flags,
832 .maxlen = sizeof (unsigned long),
833 .mode = 0644,
834 .proc_handler = proc_doulongvec_minmax,
836 #endif
837 #ifdef CONFIG_IA64
839 .procname = "ignore-unaligned-usertrap",
840 .data = &no_unaligned_warning,
841 .maxlen = sizeof (int),
842 .mode = 0644,
843 .proc_handler = proc_dointvec,
846 .procname = "unaligned-dump-stack",
847 .data = &unaligned_dump_stack,
848 .maxlen = sizeof (int),
849 .mode = 0644,
850 .proc_handler = proc_dointvec,
852 #endif
853 #ifdef CONFIG_DETECT_HUNG_TASK
855 .procname = "hung_task_panic",
856 .data = &sysctl_hung_task_panic,
857 .maxlen = sizeof(int),
858 .mode = 0644,
859 .proc_handler = proc_dointvec_minmax,
860 .extra1 = &zero,
861 .extra2 = &one,
864 .procname = "hung_task_check_count",
865 .data = &sysctl_hung_task_check_count,
866 .maxlen = sizeof(unsigned long),
867 .mode = 0644,
868 .proc_handler = proc_doulongvec_minmax,
871 .procname = "hung_task_timeout_secs",
872 .data = &sysctl_hung_task_timeout_secs,
873 .maxlen = sizeof(unsigned long),
874 .mode = 0644,
875 .proc_handler = proc_dohung_task_timeout_secs,
878 .procname = "hung_task_warnings",
879 .data = &sysctl_hung_task_warnings,
880 .maxlen = sizeof(unsigned long),
881 .mode = 0644,
882 .proc_handler = proc_doulongvec_minmax,
884 #endif
885 #ifdef CONFIG_COMPAT
887 .procname = "compat-log",
888 .data = &compat_log,
889 .maxlen = sizeof (int),
890 .mode = 0644,
891 .proc_handler = proc_dointvec,
893 #endif
894 #ifdef CONFIG_RT_MUTEXES
896 .procname = "max_lock_depth",
897 .data = &max_lock_depth,
898 .maxlen = sizeof(int),
899 .mode = 0644,
900 .proc_handler = proc_dointvec,
902 #endif
904 .procname = "poweroff_cmd",
905 .data = &poweroff_cmd,
906 .maxlen = POWEROFF_CMD_PATH_LEN,
907 .mode = 0644,
908 .proc_handler = proc_dostring,
910 #ifdef CONFIG_KEYS
912 .procname = "keys",
913 .mode = 0555,
914 .child = key_sysctls,
916 #endif
917 #ifdef CONFIG_RCU_TORTURE_TEST
919 .procname = "rcutorture_runnable",
920 .data = &rcutorture_runnable,
921 .maxlen = sizeof(int),
922 .mode = 0644,
923 .proc_handler = proc_dointvec,
925 #endif
926 #ifdef CONFIG_PERF_EVENTS
928 .procname = "perf_event_paranoid",
929 .data = &sysctl_perf_event_paranoid,
930 .maxlen = sizeof(sysctl_perf_event_paranoid),
931 .mode = 0644,
932 .proc_handler = proc_dointvec,
935 .procname = "perf_event_mlock_kb",
936 .data = &sysctl_perf_event_mlock,
937 .maxlen = sizeof(sysctl_perf_event_mlock),
938 .mode = 0644,
939 .proc_handler = proc_dointvec,
942 .procname = "perf_event_max_sample_rate",
943 .data = &sysctl_perf_event_sample_rate,
944 .maxlen = sizeof(sysctl_perf_event_sample_rate),
945 .mode = 0644,
946 .proc_handler = proc_dointvec,
948 #endif
949 #ifdef CONFIG_KMEMCHECK
951 .procname = "kmemcheck",
952 .data = &kmemcheck_enabled,
953 .maxlen = sizeof(int),
954 .mode = 0644,
955 .proc_handler = proc_dointvec,
957 #endif
958 #ifdef CONFIG_BLOCK
960 .procname = "blk_iopoll",
961 .data = &blk_iopoll_enabled,
962 .maxlen = sizeof(int),
963 .mode = 0644,
964 .proc_handler = proc_dointvec,
966 #endif
968 * NOTE: do not add new entries to this table unless you have read
969 * Documentation/sysctl/ctl_unnumbered.txt
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
1333 * NOTE: do not add new entries to this table unless you have read
1334 * Documentation/sysctl/ctl_unnumbered.txt
1339 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1340 static struct ctl_table binfmt_misc_table[] = {
1343 #endif
1345 static struct ctl_table fs_table[] = {
1347 .procname = "inode-nr",
1348 .data = &inodes_stat,
1349 .maxlen = 2*sizeof(int),
1350 .mode = 0444,
1351 .proc_handler = proc_nr_inodes,
1354 .procname = "inode-state",
1355 .data = &inodes_stat,
1356 .maxlen = 7*sizeof(int),
1357 .mode = 0444,
1358 .proc_handler = proc_nr_inodes,
1361 .procname = "file-nr",
1362 .data = &files_stat,
1363 .maxlen = sizeof(files_stat),
1364 .mode = 0444,
1365 .proc_handler = proc_nr_files,
1368 .procname = "file-max",
1369 .data = &files_stat.max_files,
1370 .maxlen = sizeof(files_stat.max_files),
1371 .mode = 0644,
1372 .proc_handler = proc_doulongvec_minmax,
1375 .procname = "nr_open",
1376 .data = &sysctl_nr_open,
1377 .maxlen = sizeof(int),
1378 .mode = 0644,
1379 .proc_handler = proc_dointvec_minmax,
1380 .extra1 = &sysctl_nr_open_min,
1381 .extra2 = &sysctl_nr_open_max,
1384 .procname = "dentry-state",
1385 .data = &dentry_stat,
1386 .maxlen = 6*sizeof(int),
1387 .mode = 0444,
1388 .proc_handler = proc_nr_dentry,
1391 .procname = "overflowuid",
1392 .data = &fs_overflowuid,
1393 .maxlen = sizeof(int),
1394 .mode = 0644,
1395 .proc_handler = proc_dointvec_minmax,
1396 .extra1 = &minolduid,
1397 .extra2 = &maxolduid,
1400 .procname = "overflowgid",
1401 .data = &fs_overflowgid,
1402 .maxlen = sizeof(int),
1403 .mode = 0644,
1404 .proc_handler = proc_dointvec_minmax,
1405 .extra1 = &minolduid,
1406 .extra2 = &maxolduid,
1408 #ifdef CONFIG_FILE_LOCKING
1410 .procname = "leases-enable",
1411 .data = &leases_enable,
1412 .maxlen = sizeof(int),
1413 .mode = 0644,
1414 .proc_handler = proc_dointvec,
1416 #endif
1417 #ifdef CONFIG_DNOTIFY
1419 .procname = "dir-notify-enable",
1420 .data = &dir_notify_enable,
1421 .maxlen = sizeof(int),
1422 .mode = 0644,
1423 .proc_handler = proc_dointvec,
1425 #endif
1426 #ifdef CONFIG_MMU
1427 #ifdef CONFIG_FILE_LOCKING
1429 .procname = "lease-break-time",
1430 .data = &lease_break_time,
1431 .maxlen = sizeof(int),
1432 .mode = 0644,
1433 .proc_handler = proc_dointvec,
1435 #endif
1436 #ifdef CONFIG_AIO
1438 .procname = "aio-nr",
1439 .data = &aio_nr,
1440 .maxlen = sizeof(aio_nr),
1441 .mode = 0444,
1442 .proc_handler = proc_doulongvec_minmax,
1445 .procname = "aio-max-nr",
1446 .data = &aio_max_nr,
1447 .maxlen = sizeof(aio_max_nr),
1448 .mode = 0644,
1449 .proc_handler = proc_doulongvec_minmax,
1451 #endif /* CONFIG_AIO */
1452 #ifdef CONFIG_INOTIFY_USER
1454 .procname = "inotify",
1455 .mode = 0555,
1456 .child = inotify_table,
1458 #endif
1459 #ifdef CONFIG_EPOLL
1461 .procname = "epoll",
1462 .mode = 0555,
1463 .child = epoll_table,
1465 #endif
1466 #endif
1468 .procname = "suid_dumpable",
1469 .data = &suid_dumpable,
1470 .maxlen = sizeof(int),
1471 .mode = 0644,
1472 .proc_handler = proc_dointvec_minmax,
1473 .extra1 = &zero,
1474 .extra2 = &two,
1476 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1478 .procname = "binfmt_misc",
1479 .mode = 0555,
1480 .child = binfmt_misc_table,
1482 #endif
1484 .procname = "pipe-max-size",
1485 .data = &pipe_max_size,
1486 .maxlen = sizeof(int),
1487 .mode = 0644,
1488 .proc_handler = &pipe_proc_fn,
1489 .extra1 = &pipe_min_size,
1492 * NOTE: do not add new entries to this table unless you have read
1493 * Documentation/sysctl/ctl_unnumbered.txt
1498 static struct ctl_table debug_table[] = {
1499 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1500 defined(CONFIG_S390)
1502 .procname = "exception-trace",
1503 .data = &show_unhandled_signals,
1504 .maxlen = sizeof(int),
1505 .mode = 0644,
1506 .proc_handler = proc_dointvec
1508 #endif
1509 #if defined(CONFIG_OPTPROBES)
1511 .procname = "kprobes-optimization",
1512 .data = &sysctl_kprobes_optimization,
1513 .maxlen = sizeof(int),
1514 .mode = 0644,
1515 .proc_handler = proc_kprobes_optimization_handler,
1516 .extra1 = &zero,
1517 .extra2 = &one,
1519 #endif
1523 static struct ctl_table dev_table[] = {
1527 static DEFINE_SPINLOCK(sysctl_lock);
1529 /* called under sysctl_lock */
1530 static int use_table(struct ctl_table_header *p)
1532 if (unlikely(p->unregistering))
1533 return 0;
1534 p->used++;
1535 return 1;
1538 /* called under sysctl_lock */
1539 static void unuse_table(struct ctl_table_header *p)
1541 if (!--p->used)
1542 if (unlikely(p->unregistering))
1543 complete(p->unregistering);
1546 /* called under sysctl_lock, will reacquire if has to wait */
1547 static void start_unregistering(struct ctl_table_header *p)
1550 * if p->used is 0, nobody will ever touch that entry again;
1551 * we'll eliminate all paths to it before dropping sysctl_lock
1553 if (unlikely(p->used)) {
1554 struct completion wait;
1555 init_completion(&wait);
1556 p->unregistering = &wait;
1557 spin_unlock(&sysctl_lock);
1558 wait_for_completion(&wait);
1559 spin_lock(&sysctl_lock);
1560 } else {
1561 /* anything non-NULL; we'll never dereference it */
1562 p->unregistering = ERR_PTR(-EINVAL);
1565 * do not remove from the list until nobody holds it; walking the
1566 * list in do_sysctl() relies on that.
1568 list_del_init(&p->ctl_entry);
1571 void sysctl_head_get(struct ctl_table_header *head)
1573 spin_lock(&sysctl_lock);
1574 head->count++;
1575 spin_unlock(&sysctl_lock);
1578 void sysctl_head_put(struct ctl_table_header *head)
1580 spin_lock(&sysctl_lock);
1581 if (!--head->count)
1582 kfree(head);
1583 spin_unlock(&sysctl_lock);
1586 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1588 if (!head)
1589 BUG();
1590 spin_lock(&sysctl_lock);
1591 if (!use_table(head))
1592 head = ERR_PTR(-ENOENT);
1593 spin_unlock(&sysctl_lock);
1594 return head;
1597 void sysctl_head_finish(struct ctl_table_header *head)
1599 if (!head)
1600 return;
1601 spin_lock(&sysctl_lock);
1602 unuse_table(head);
1603 spin_unlock(&sysctl_lock);
1606 static struct ctl_table_set *
1607 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1609 struct ctl_table_set *set = &root->default_set;
1610 if (root->lookup)
1611 set = root->lookup(root, namespaces);
1612 return set;
1615 static struct list_head *
1616 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1618 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1619 return &set->list;
1622 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1623 struct ctl_table_header *prev)
1625 struct ctl_table_root *root;
1626 struct list_head *header_list;
1627 struct ctl_table_header *head;
1628 struct list_head *tmp;
1630 spin_lock(&sysctl_lock);
1631 if (prev) {
1632 head = prev;
1633 tmp = &prev->ctl_entry;
1634 unuse_table(prev);
1635 goto next;
1637 tmp = &root_table_header.ctl_entry;
1638 for (;;) {
1639 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1641 if (!use_table(head))
1642 goto next;
1643 spin_unlock(&sysctl_lock);
1644 return head;
1645 next:
1646 root = head->root;
1647 tmp = tmp->next;
1648 header_list = lookup_header_list(root, namespaces);
1649 if (tmp != header_list)
1650 continue;
1652 do {
1653 root = list_entry(root->root_list.next,
1654 struct ctl_table_root, root_list);
1655 if (root == &sysctl_table_root)
1656 goto out;
1657 header_list = lookup_header_list(root, namespaces);
1658 } while (list_empty(header_list));
1659 tmp = header_list->next;
1661 out:
1662 spin_unlock(&sysctl_lock);
1663 return NULL;
1666 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1668 return __sysctl_head_next(current->nsproxy, prev);
1671 void register_sysctl_root(struct ctl_table_root *root)
1673 spin_lock(&sysctl_lock);
1674 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1675 spin_unlock(&sysctl_lock);
1679 * sysctl_perm does NOT grant the superuser all rights automatically, because
1680 * some sysctl variables are readonly even to root.
1683 static int test_perm(int mode, int op)
1685 if (!current_euid())
1686 mode >>= 6;
1687 else if (in_egroup_p(0))
1688 mode >>= 3;
1689 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1690 return 0;
1691 return -EACCES;
1694 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1696 int error;
1697 int mode;
1699 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1700 if (error)
1701 return error;
1703 if (root->permissions)
1704 mode = root->permissions(root, current->nsproxy, table);
1705 else
1706 mode = table->mode;
1708 return test_perm(mode, op);
1711 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1713 for (; table->procname; table++) {
1714 table->parent = parent;
1715 if (table->child)
1716 sysctl_set_parent(table, table->child);
1720 static __init int sysctl_init(void)
1722 sysctl_set_parent(NULL, root_table);
1723 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1724 sysctl_check_table(current->nsproxy, root_table);
1725 #endif
1726 return 0;
1729 core_initcall(sysctl_init);
1731 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1732 struct ctl_table *table)
1734 struct ctl_table *p;
1735 const char *s = branch->procname;
1737 /* branch should have named subdirectory as its first element */
1738 if (!s || !branch->child)
1739 return NULL;
1741 /* ... and nothing else */
1742 if (branch[1].procname)
1743 return NULL;
1745 /* table should contain subdirectory with the same name */
1746 for (p = table; p->procname; p++) {
1747 if (!p->child)
1748 continue;
1749 if (p->procname && strcmp(p->procname, s) == 0)
1750 return p;
1752 return NULL;
1755 /* see if attaching q to p would be an improvement */
1756 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1758 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1759 struct ctl_table *next;
1760 int is_better = 0;
1761 int not_in_parent = !p->attached_by;
1763 while ((next = is_branch_in(by, to)) != NULL) {
1764 if (by == q->attached_by)
1765 is_better = 1;
1766 if (to == p->attached_by)
1767 not_in_parent = 1;
1768 by = by->child;
1769 to = next->child;
1772 if (is_better && not_in_parent) {
1773 q->attached_by = by;
1774 q->attached_to = to;
1775 q->parent = p;
1780 * __register_sysctl_paths - register a sysctl hierarchy
1781 * @root: List of sysctl headers to register on
1782 * @namespaces: Data to compute which lists of sysctl entries are visible
1783 * @path: The path to the directory the sysctl table is in.
1784 * @table: the top-level table structure
1786 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1787 * array. A completely 0 filled entry terminates the table.
1789 * The members of the &struct ctl_table structure are used as follows:
1791 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1792 * enter a sysctl file
1794 * data - a pointer to data for use by proc_handler
1796 * maxlen - the maximum size in bytes of the data
1798 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1800 * child - a pointer to the child sysctl table if this entry is a directory, or
1801 * %NULL.
1803 * proc_handler - the text handler routine (described below)
1805 * de - for internal use by the sysctl routines
1807 * extra1, extra2 - extra pointers usable by the proc handler routines
1809 * Leaf nodes in the sysctl tree will be represented by a single file
1810 * under /proc; non-leaf nodes will be represented by directories.
1812 * sysctl(2) can automatically manage read and write requests through
1813 * the sysctl table. The data and maxlen fields of the ctl_table
1814 * struct enable minimal validation of the values being written to be
1815 * performed, and the mode field allows minimal authentication.
1817 * There must be a proc_handler routine for any terminal nodes
1818 * mirrored under /proc/sys (non-terminals are handled by a built-in
1819 * directory handler). Several default handlers are available to
1820 * cover common cases -
1822 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1823 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1824 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1826 * It is the handler's job to read the input buffer from user memory
1827 * and process it. The handler should return 0 on success.
1829 * This routine returns %NULL on a failure to register, and a pointer
1830 * to the table header on success.
1832 struct ctl_table_header *__register_sysctl_paths(
1833 struct ctl_table_root *root,
1834 struct nsproxy *namespaces,
1835 const struct ctl_path *path, struct ctl_table *table)
1837 struct ctl_table_header *header;
1838 struct ctl_table *new, **prevp;
1839 unsigned int n, npath;
1840 struct ctl_table_set *set;
1842 /* Count the path components */
1843 for (npath = 0; path[npath].procname; ++npath)
1847 * For each path component, allocate a 2-element ctl_table array.
1848 * The first array element will be filled with the sysctl entry
1849 * for this, the second will be the sentinel (procname == 0).
1851 * We allocate everything in one go so that we don't have to
1852 * worry about freeing additional memory in unregister_sysctl_table.
1854 header = kzalloc(sizeof(struct ctl_table_header) +
1855 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1856 if (!header)
1857 return NULL;
1859 new = (struct ctl_table *) (header + 1);
1861 /* Now connect the dots */
1862 prevp = &header->ctl_table;
1863 for (n = 0; n < npath; ++n, ++path) {
1864 /* Copy the procname */
1865 new->procname = path->procname;
1866 new->mode = 0555;
1868 *prevp = new;
1869 prevp = &new->child;
1871 new += 2;
1873 *prevp = table;
1874 header->ctl_table_arg = table;
1876 INIT_LIST_HEAD(&header->ctl_entry);
1877 header->used = 0;
1878 header->unregistering = NULL;
1879 header->root = root;
1880 sysctl_set_parent(NULL, header->ctl_table);
1881 header->count = 1;
1882 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1883 if (sysctl_check_table(namespaces, header->ctl_table)) {
1884 kfree(header);
1885 return NULL;
1887 #endif
1888 spin_lock(&sysctl_lock);
1889 header->set = lookup_header_set(root, namespaces);
1890 header->attached_by = header->ctl_table;
1891 header->attached_to = root_table;
1892 header->parent = &root_table_header;
1893 for (set = header->set; set; set = set->parent) {
1894 struct ctl_table_header *p;
1895 list_for_each_entry(p, &set->list, ctl_entry) {
1896 if (p->unregistering)
1897 continue;
1898 try_attach(p, header);
1901 header->parent->count++;
1902 list_add_tail(&header->ctl_entry, &header->set->list);
1903 spin_unlock(&sysctl_lock);
1905 return header;
1909 * register_sysctl_table_path - register a sysctl table hierarchy
1910 * @path: The path to the directory the sysctl table is in.
1911 * @table: the top-level table structure
1913 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1914 * array. A completely 0 filled entry terminates the table.
1916 * See __register_sysctl_paths for more details.
1918 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1919 struct ctl_table *table)
1921 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1922 path, table);
1926 * register_sysctl_table - register a sysctl table hierarchy
1927 * @table: the top-level table structure
1929 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1930 * array. A completely 0 filled entry terminates the table.
1932 * See register_sysctl_paths for more details.
1934 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1936 static const struct ctl_path null_path[] = { {} };
1938 return register_sysctl_paths(null_path, table);
1942 * unregister_sysctl_table - unregister a sysctl table hierarchy
1943 * @header: the header returned from register_sysctl_table
1945 * Unregisters the sysctl table and all children. proc entries may not
1946 * actually be removed until they are no longer used by anyone.
1948 void unregister_sysctl_table(struct ctl_table_header * header)
1950 might_sleep();
1952 if (header == NULL)
1953 return;
1955 spin_lock(&sysctl_lock);
1956 start_unregistering(header);
1957 if (!--header->parent->count) {
1958 WARN_ON(1);
1959 kfree(header->parent);
1961 if (!--header->count)
1962 kfree(header);
1963 spin_unlock(&sysctl_lock);
1966 int sysctl_is_seen(struct ctl_table_header *p)
1968 struct ctl_table_set *set = p->set;
1969 int res;
1970 spin_lock(&sysctl_lock);
1971 if (p->unregistering)
1972 res = 0;
1973 else if (!set->is_seen)
1974 res = 1;
1975 else
1976 res = set->is_seen(set);
1977 spin_unlock(&sysctl_lock);
1978 return res;
1981 void setup_sysctl_set(struct ctl_table_set *p,
1982 struct ctl_table_set *parent,
1983 int (*is_seen)(struct ctl_table_set *))
1985 INIT_LIST_HEAD(&p->list);
1986 p->parent = parent ? parent : &sysctl_table_root.default_set;
1987 p->is_seen = is_seen;
1990 #else /* !CONFIG_SYSCTL */
1991 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1993 return NULL;
1996 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1997 struct ctl_table *table)
1999 return NULL;
2002 void unregister_sysctl_table(struct ctl_table_header * table)
2006 void setup_sysctl_set(struct ctl_table_set *p,
2007 struct ctl_table_set *parent,
2008 int (*is_seen)(struct ctl_table_set *))
2012 void sysctl_head_put(struct ctl_table_header *head)
2016 #endif /* CONFIG_SYSCTL */
2019 * /proc/sys support
2022 #ifdef CONFIG_PROC_SYSCTL
2024 static int _proc_do_string(void* data, int maxlen, int write,
2025 void __user *buffer,
2026 size_t *lenp, loff_t *ppos)
2028 size_t len;
2029 char __user *p;
2030 char c;
2032 if (!data || !maxlen || !*lenp) {
2033 *lenp = 0;
2034 return 0;
2037 if (write) {
2038 len = 0;
2039 p = buffer;
2040 while (len < *lenp) {
2041 if (get_user(c, p++))
2042 return -EFAULT;
2043 if (c == 0 || c == '\n')
2044 break;
2045 len++;
2047 if (len >= maxlen)
2048 len = maxlen-1;
2049 if(copy_from_user(data, buffer, len))
2050 return -EFAULT;
2051 ((char *) data)[len] = 0;
2052 *ppos += *lenp;
2053 } else {
2054 len = strlen(data);
2055 if (len > maxlen)
2056 len = maxlen;
2058 if (*ppos > len) {
2059 *lenp = 0;
2060 return 0;
2063 data += *ppos;
2064 len -= *ppos;
2066 if (len > *lenp)
2067 len = *lenp;
2068 if (len)
2069 if(copy_to_user(buffer, data, len))
2070 return -EFAULT;
2071 if (len < *lenp) {
2072 if(put_user('\n', ((char __user *) buffer) + len))
2073 return -EFAULT;
2074 len++;
2076 *lenp = len;
2077 *ppos += len;
2079 return 0;
2083 * proc_dostring - read a string sysctl
2084 * @table: the sysctl table
2085 * @write: %TRUE if this is a write to the sysctl file
2086 * @buffer: the user buffer
2087 * @lenp: the size of the user buffer
2088 * @ppos: file position
2090 * Reads/writes a string from/to the user buffer. If the kernel
2091 * buffer provided is not large enough to hold the string, the
2092 * string is truncated. The copied string is %NULL-terminated.
2093 * If the string is being read by the user process, it is copied
2094 * and a newline '\n' is added. It is truncated if the buffer is
2095 * not large enough.
2097 * Returns 0 on success.
2099 int proc_dostring(struct ctl_table *table, int write,
2100 void __user *buffer, size_t *lenp, loff_t *ppos)
2102 return _proc_do_string(table->data, table->maxlen, write,
2103 buffer, lenp, ppos);
2106 static size_t proc_skip_spaces(char **buf)
2108 size_t ret;
2109 char *tmp = skip_spaces(*buf);
2110 ret = tmp - *buf;
2111 *buf = tmp;
2112 return ret;
2115 static void proc_skip_char(char **buf, size_t *size, const char v)
2117 while (*size) {
2118 if (**buf != v)
2119 break;
2120 (*size)--;
2121 (*buf)++;
2125 #define TMPBUFLEN 22
2127 * proc_get_long - reads an ASCII formatted integer from a user buffer
2129 * @buf: a kernel buffer
2130 * @size: size of the kernel buffer
2131 * @val: this is where the number will be stored
2132 * @neg: set to %TRUE if number is negative
2133 * @perm_tr: a vector which contains the allowed trailers
2134 * @perm_tr_len: size of the perm_tr vector
2135 * @tr: pointer to store the trailer character
2137 * In case of success %0 is returned and @buf and @size are updated with
2138 * the amount of bytes read. If @tr is non-NULL and a trailing
2139 * character exists (size is non-zero after returning from this
2140 * function), @tr is updated with the trailing character.
2142 static int proc_get_long(char **buf, size_t *size,
2143 unsigned long *val, bool *neg,
2144 const char *perm_tr, unsigned perm_tr_len, char *tr)
2146 int len;
2147 char *p, tmp[TMPBUFLEN];
2149 if (!*size)
2150 return -EINVAL;
2152 len = *size;
2153 if (len > TMPBUFLEN - 1)
2154 len = TMPBUFLEN - 1;
2156 memcpy(tmp, *buf, len);
2158 tmp[len] = 0;
2159 p = tmp;
2160 if (*p == '-' && *size > 1) {
2161 *neg = true;
2162 p++;
2163 } else
2164 *neg = false;
2165 if (!isdigit(*p))
2166 return -EINVAL;
2168 *val = simple_strtoul(p, &p, 0);
2170 len = p - tmp;
2172 /* We don't know if the next char is whitespace thus we may accept
2173 * invalid integers (e.g. 1234...a) or two integers instead of one
2174 * (e.g. 123...1). So lets not allow such large numbers. */
2175 if (len == TMPBUFLEN - 1)
2176 return -EINVAL;
2178 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2179 return -EINVAL;
2181 if (tr && (len < *size))
2182 *tr = *p;
2184 *buf += len;
2185 *size -= len;
2187 return 0;
2191 * proc_put_long - converts an integer to a decimal ASCII formatted string
2193 * @buf: the user buffer
2194 * @size: the size of the user buffer
2195 * @val: the integer to be converted
2196 * @neg: sign of the number, %TRUE for negative
2198 * In case of success %0 is returned and @buf and @size are updated with
2199 * the amount of bytes written.
2201 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2202 bool neg)
2204 int len;
2205 char tmp[TMPBUFLEN], *p = tmp;
2207 sprintf(p, "%s%lu", neg ? "-" : "", val);
2208 len = strlen(tmp);
2209 if (len > *size)
2210 len = *size;
2211 if (copy_to_user(*buf, tmp, len))
2212 return -EFAULT;
2213 *size -= len;
2214 *buf += len;
2215 return 0;
2217 #undef TMPBUFLEN
2219 static int proc_put_char(void __user **buf, size_t *size, char c)
2221 if (*size) {
2222 char __user **buffer = (char __user **)buf;
2223 if (put_user(c, *buffer))
2224 return -EFAULT;
2225 (*size)--, (*buffer)++;
2226 *buf = *buffer;
2228 return 0;
2231 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2232 int *valp,
2233 int write, void *data)
2235 if (write) {
2236 *valp = *negp ? -*lvalp : *lvalp;
2237 } else {
2238 int val = *valp;
2239 if (val < 0) {
2240 *negp = true;
2241 *lvalp = (unsigned long)-val;
2242 } else {
2243 *negp = false;
2244 *lvalp = (unsigned long)val;
2247 return 0;
2250 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2252 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2253 int write, void __user *buffer,
2254 size_t *lenp, loff_t *ppos,
2255 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2256 int write, void *data),
2257 void *data)
2259 int *i, vleft, first = 1, err = 0;
2260 unsigned long page = 0;
2261 size_t left;
2262 char *kbuf;
2264 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2265 *lenp = 0;
2266 return 0;
2269 i = (int *) tbl_data;
2270 vleft = table->maxlen / sizeof(*i);
2271 left = *lenp;
2273 if (!conv)
2274 conv = do_proc_dointvec_conv;
2276 if (write) {
2277 if (left > PAGE_SIZE - 1)
2278 left = PAGE_SIZE - 1;
2279 page = __get_free_page(GFP_TEMPORARY);
2280 kbuf = (char *) page;
2281 if (!kbuf)
2282 return -ENOMEM;
2283 if (copy_from_user(kbuf, buffer, left)) {
2284 err = -EFAULT;
2285 goto free;
2287 kbuf[left] = 0;
2290 for (; left && vleft--; i++, first=0) {
2291 unsigned long lval;
2292 bool neg;
2294 if (write) {
2295 left -= proc_skip_spaces(&kbuf);
2297 if (!left)
2298 break;
2299 err = proc_get_long(&kbuf, &left, &lval, &neg,
2300 proc_wspace_sep,
2301 sizeof(proc_wspace_sep), NULL);
2302 if (err)
2303 break;
2304 if (conv(&neg, &lval, i, 1, data)) {
2305 err = -EINVAL;
2306 break;
2308 } else {
2309 if (conv(&neg, &lval, i, 0, data)) {
2310 err = -EINVAL;
2311 break;
2313 if (!first)
2314 err = proc_put_char(&buffer, &left, '\t');
2315 if (err)
2316 break;
2317 err = proc_put_long(&buffer, &left, lval, neg);
2318 if (err)
2319 break;
2323 if (!write && !first && left && !err)
2324 err = proc_put_char(&buffer, &left, '\n');
2325 if (write && !err && left)
2326 left -= proc_skip_spaces(&kbuf);
2327 free:
2328 if (write) {
2329 free_page(page);
2330 if (first)
2331 return err ? : -EINVAL;
2333 *lenp -= left;
2334 *ppos += *lenp;
2335 return err;
2338 static int do_proc_dointvec(struct ctl_table *table, int write,
2339 void __user *buffer, size_t *lenp, loff_t *ppos,
2340 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2341 int write, void *data),
2342 void *data)
2344 return __do_proc_dointvec(table->data, table, write,
2345 buffer, lenp, ppos, conv, data);
2349 * proc_dointvec - read a vector of integers
2350 * @table: the sysctl table
2351 * @write: %TRUE if this is a write to the sysctl file
2352 * @buffer: the user buffer
2353 * @lenp: the size of the user buffer
2354 * @ppos: file position
2356 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2357 * values from/to the user buffer, treated as an ASCII string.
2359 * Returns 0 on success.
2361 int proc_dointvec(struct ctl_table *table, int write,
2362 void __user *buffer, size_t *lenp, loff_t *ppos)
2364 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2365 NULL,NULL);
2369 * Taint values can only be increased
2370 * This means we can safely use a temporary.
2372 static int proc_taint(struct ctl_table *table, int write,
2373 void __user *buffer, size_t *lenp, loff_t *ppos)
2375 struct ctl_table t;
2376 unsigned long tmptaint = get_taint();
2377 int err;
2379 if (write && !capable(CAP_SYS_ADMIN))
2380 return -EPERM;
2382 t = *table;
2383 t.data = &tmptaint;
2384 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2385 if (err < 0)
2386 return err;
2388 if (write) {
2390 * Poor man's atomic or. Not worth adding a primitive
2391 * to everyone's atomic.h for this
2393 int i;
2394 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2395 if ((tmptaint >> i) & 1)
2396 add_taint(i);
2400 return err;
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);
2459 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2460 void __user *buffer,
2461 size_t *lenp, loff_t *ppos,
2462 unsigned long convmul,
2463 unsigned long convdiv)
2465 unsigned long *i, *min, *max;
2466 int vleft, first = 1, err = 0;
2467 unsigned long page = 0;
2468 size_t left;
2469 char *kbuf;
2471 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2472 *lenp = 0;
2473 return 0;
2476 i = (unsigned long *) data;
2477 min = (unsigned long *) table->extra1;
2478 max = (unsigned long *) table->extra2;
2479 vleft = table->maxlen / sizeof(unsigned long);
2480 left = *lenp;
2482 if (write) {
2483 if (left > PAGE_SIZE - 1)
2484 left = PAGE_SIZE - 1;
2485 page = __get_free_page(GFP_TEMPORARY);
2486 kbuf = (char *) page;
2487 if (!kbuf)
2488 return -ENOMEM;
2489 if (copy_from_user(kbuf, buffer, left)) {
2490 err = -EFAULT;
2491 goto free;
2493 kbuf[left] = 0;
2496 for (; left && vleft--; i++, first = 0) {
2497 unsigned long val;
2499 if (write) {
2500 bool neg;
2502 left -= proc_skip_spaces(&kbuf);
2504 err = proc_get_long(&kbuf, &left, &val, &neg,
2505 proc_wspace_sep,
2506 sizeof(proc_wspace_sep), NULL);
2507 if (err)
2508 break;
2509 if (neg)
2510 continue;
2511 if ((min && val < *min) || (max && val > *max))
2512 continue;
2513 *i = val;
2514 } else {
2515 val = convdiv * (*i) / convmul;
2516 if (!first)
2517 err = proc_put_char(&buffer, &left, '\t');
2518 err = proc_put_long(&buffer, &left, val, false);
2519 if (err)
2520 break;
2524 if (!write && !first && left && !err)
2525 err = proc_put_char(&buffer, &left, '\n');
2526 if (write && !err)
2527 left -= proc_skip_spaces(&kbuf);
2528 free:
2529 if (write) {
2530 free_page(page);
2531 if (first)
2532 return err ? : -EINVAL;
2534 *lenp -= left;
2535 *ppos += *lenp;
2536 return err;
2539 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2540 void __user *buffer,
2541 size_t *lenp, loff_t *ppos,
2542 unsigned long convmul,
2543 unsigned long convdiv)
2545 return __do_proc_doulongvec_minmax(table->data, table, write,
2546 buffer, lenp, ppos, convmul, convdiv);
2550 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2551 * @table: the sysctl table
2552 * @write: %TRUE if this is a write to the sysctl file
2553 * @buffer: the user buffer
2554 * @lenp: the size of the user buffer
2555 * @ppos: file position
2557 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2558 * values from/to the user buffer, treated as an ASCII string.
2560 * This routine will ensure the values are within the range specified by
2561 * table->extra1 (min) and table->extra2 (max).
2563 * Returns 0 on success.
2565 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2566 void __user *buffer, size_t *lenp, loff_t *ppos)
2568 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2572 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2573 * @table: the sysctl table
2574 * @write: %TRUE if this is a write to the sysctl file
2575 * @buffer: the user buffer
2576 * @lenp: the size of the user buffer
2577 * @ppos: file position
2579 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2580 * values from/to the user buffer, treated as an ASCII string. The values
2581 * are treated as milliseconds, and converted to jiffies when they are stored.
2583 * This routine will ensure the values are within the range specified by
2584 * table->extra1 (min) and table->extra2 (max).
2586 * Returns 0 on success.
2588 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2589 void __user *buffer,
2590 size_t *lenp, loff_t *ppos)
2592 return do_proc_doulongvec_minmax(table, write, buffer,
2593 lenp, ppos, HZ, 1000l);
2597 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2598 int *valp,
2599 int write, void *data)
2601 if (write) {
2602 if (*lvalp > LONG_MAX / HZ)
2603 return 1;
2604 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2605 } else {
2606 int val = *valp;
2607 unsigned long lval;
2608 if (val < 0) {
2609 *negp = true;
2610 lval = (unsigned long)-val;
2611 } else {
2612 *negp = false;
2613 lval = (unsigned long)val;
2615 *lvalp = lval / HZ;
2617 return 0;
2620 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2621 int *valp,
2622 int write, void *data)
2624 if (write) {
2625 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2626 return 1;
2627 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2628 } else {
2629 int val = *valp;
2630 unsigned long lval;
2631 if (val < 0) {
2632 *negp = true;
2633 lval = (unsigned long)-val;
2634 } else {
2635 *negp = false;
2636 lval = (unsigned long)val;
2638 *lvalp = jiffies_to_clock_t(lval);
2640 return 0;
2643 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2644 int *valp,
2645 int write, void *data)
2647 if (write) {
2648 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2649 } else {
2650 int val = *valp;
2651 unsigned long lval;
2652 if (val < 0) {
2653 *negp = true;
2654 lval = (unsigned long)-val;
2655 } else {
2656 *negp = false;
2657 lval = (unsigned long)val;
2659 *lvalp = jiffies_to_msecs(lval);
2661 return 0;
2665 * proc_dointvec_jiffies - read a vector of integers as seconds
2666 * @table: the sysctl table
2667 * @write: %TRUE if this is a write to the sysctl file
2668 * @buffer: the user buffer
2669 * @lenp: the size of the user buffer
2670 * @ppos: file position
2672 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2673 * values from/to the user buffer, treated as an ASCII string.
2674 * The values read are assumed to be in seconds, and are converted into
2675 * jiffies.
2677 * Returns 0 on success.
2679 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2680 void __user *buffer, size_t *lenp, loff_t *ppos)
2682 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2683 do_proc_dointvec_jiffies_conv,NULL);
2687 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2688 * @table: the sysctl table
2689 * @write: %TRUE if this is a write to the sysctl file
2690 * @buffer: the user buffer
2691 * @lenp: the size of the user buffer
2692 * @ppos: pointer to the file position
2694 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2695 * values from/to the user buffer, treated as an ASCII string.
2696 * The values read are assumed to be in 1/USER_HZ seconds, and
2697 * are converted into jiffies.
2699 * Returns 0 on success.
2701 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2702 void __user *buffer, size_t *lenp, loff_t *ppos)
2704 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2705 do_proc_dointvec_userhz_jiffies_conv,NULL);
2709 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2710 * @table: the sysctl table
2711 * @write: %TRUE if this is a write to the sysctl file
2712 * @buffer: the user buffer
2713 * @lenp: the size of the user buffer
2714 * @ppos: file position
2715 * @ppos: the current position in the file
2717 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2718 * values from/to the user buffer, treated as an ASCII string.
2719 * The values read are assumed to be in 1/1000 seconds, and
2720 * are converted into jiffies.
2722 * Returns 0 on success.
2724 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2725 void __user *buffer, size_t *lenp, loff_t *ppos)
2727 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2728 do_proc_dointvec_ms_jiffies_conv, NULL);
2731 static int proc_do_cad_pid(struct ctl_table *table, int write,
2732 void __user *buffer, size_t *lenp, loff_t *ppos)
2734 struct pid *new_pid;
2735 pid_t tmp;
2736 int r;
2738 tmp = pid_vnr(cad_pid);
2740 r = __do_proc_dointvec(&tmp, table, write, buffer,
2741 lenp, ppos, NULL, NULL);
2742 if (r || !write)
2743 return r;
2745 new_pid = find_get_pid(tmp);
2746 if (!new_pid)
2747 return -ESRCH;
2749 put_pid(xchg(&cad_pid, new_pid));
2750 return 0;
2754 * proc_do_large_bitmap - read/write from/to a large bitmap
2755 * @table: the sysctl table
2756 * @write: %TRUE if this is a write to the sysctl file
2757 * @buffer: the user buffer
2758 * @lenp: the size of the user buffer
2759 * @ppos: file position
2761 * The bitmap is stored at table->data and the bitmap length (in bits)
2762 * in table->maxlen.
2764 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2765 * large bitmaps may be represented in a compact manner. Writing into
2766 * the file will clear the bitmap then update it with the given input.
2768 * Returns 0 on success.
2770 int proc_do_large_bitmap(struct ctl_table *table, int write,
2771 void __user *buffer, size_t *lenp, loff_t *ppos)
2773 int err = 0;
2774 bool first = 1;
2775 size_t left = *lenp;
2776 unsigned long bitmap_len = table->maxlen;
2777 unsigned long *bitmap = (unsigned long *) table->data;
2778 unsigned long *tmp_bitmap = NULL;
2779 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2781 if (!bitmap_len || !left || (*ppos && !write)) {
2782 *lenp = 0;
2783 return 0;
2786 if (write) {
2787 unsigned long page = 0;
2788 char *kbuf;
2790 if (left > PAGE_SIZE - 1)
2791 left = PAGE_SIZE - 1;
2793 page = __get_free_page(GFP_TEMPORARY);
2794 kbuf = (char *) page;
2795 if (!kbuf)
2796 return -ENOMEM;
2797 if (copy_from_user(kbuf, buffer, left)) {
2798 free_page(page);
2799 return -EFAULT;
2801 kbuf[left] = 0;
2803 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2804 GFP_KERNEL);
2805 if (!tmp_bitmap) {
2806 free_page(page);
2807 return -ENOMEM;
2809 proc_skip_char(&kbuf, &left, '\n');
2810 while (!err && left) {
2811 unsigned long val_a, val_b;
2812 bool neg;
2814 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2815 sizeof(tr_a), &c);
2816 if (err)
2817 break;
2818 if (val_a >= bitmap_len || neg) {
2819 err = -EINVAL;
2820 break;
2823 val_b = val_a;
2824 if (left) {
2825 kbuf++;
2826 left--;
2829 if (c == '-') {
2830 err = proc_get_long(&kbuf, &left, &val_b,
2831 &neg, tr_b, sizeof(tr_b),
2832 &c);
2833 if (err)
2834 break;
2835 if (val_b >= bitmap_len || neg ||
2836 val_a > val_b) {
2837 err = -EINVAL;
2838 break;
2840 if (left) {
2841 kbuf++;
2842 left--;
2846 while (val_a <= val_b)
2847 set_bit(val_a++, tmp_bitmap);
2849 first = 0;
2850 proc_skip_char(&kbuf, &left, '\n');
2852 free_page(page);
2853 } else {
2854 unsigned long bit_a, bit_b = 0;
2856 while (left) {
2857 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2858 if (bit_a >= bitmap_len)
2859 break;
2860 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2861 bit_a + 1) - 1;
2863 if (!first) {
2864 err = proc_put_char(&buffer, &left, ',');
2865 if (err)
2866 break;
2868 err = proc_put_long(&buffer, &left, bit_a, false);
2869 if (err)
2870 break;
2871 if (bit_a != bit_b) {
2872 err = proc_put_char(&buffer, &left, '-');
2873 if (err)
2874 break;
2875 err = proc_put_long(&buffer, &left, bit_b, false);
2876 if (err)
2877 break;
2880 first = 0; bit_b++;
2882 if (!err)
2883 err = proc_put_char(&buffer, &left, '\n');
2886 if (!err) {
2887 if (write) {
2888 if (*ppos)
2889 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2890 else
2891 memcpy(bitmap, tmp_bitmap,
2892 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2894 kfree(tmp_bitmap);
2895 *lenp -= left;
2896 *ppos += *lenp;
2897 return 0;
2898 } else {
2899 kfree(tmp_bitmap);
2900 return err;
2904 #else /* CONFIG_PROC_FS */
2906 int proc_dostring(struct ctl_table *table, int write,
2907 void __user *buffer, size_t *lenp, loff_t *ppos)
2909 return -ENOSYS;
2912 int proc_dointvec(struct ctl_table *table, int write,
2913 void __user *buffer, size_t *lenp, loff_t *ppos)
2915 return -ENOSYS;
2918 int proc_dointvec_minmax(struct ctl_table *table, int write,
2919 void __user *buffer, size_t *lenp, loff_t *ppos)
2921 return -ENOSYS;
2924 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2925 void __user *buffer, size_t *lenp, loff_t *ppos)
2927 return -ENOSYS;
2930 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2931 void __user *buffer, size_t *lenp, loff_t *ppos)
2933 return -ENOSYS;
2936 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2937 void __user *buffer, size_t *lenp, loff_t *ppos)
2939 return -ENOSYS;
2942 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2943 void __user *buffer, size_t *lenp, loff_t *ppos)
2945 return -ENOSYS;
2948 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2949 void __user *buffer,
2950 size_t *lenp, loff_t *ppos)
2952 return -ENOSYS;
2956 #endif /* CONFIG_PROC_FS */
2959 * No sense putting this after each symbol definition, twice,
2960 * exception granted :-)
2962 EXPORT_SYMBOL(proc_dointvec);
2963 EXPORT_SYMBOL(proc_dointvec_jiffies);
2964 EXPORT_SYMBOL(proc_dointvec_minmax);
2965 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2966 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2967 EXPORT_SYMBOL(proc_dostring);
2968 EXPORT_SYMBOL(proc_doulongvec_minmax);
2969 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2970 EXPORT_SYMBOL(register_sysctl_table);
2971 EXPORT_SYMBOL(register_sysctl_paths);
2972 EXPORT_SYMBOL(unregister_sysctl_table);