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
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
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>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/proc_fs.h>
27 #include <linux/capability.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/smp_lock.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/hugetlb.h>
40 #include <linux/security.h>
41 #include <linux/initrd.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/nfs_fs.h>
47 #include <linux/acpi.h>
48 #include <linux/reboot.h>
50 #include <asm/uaccess.h>
51 #include <asm/processor.h>
55 #include <asm/stacktrace.h>
58 #if defined(CONFIG_SYSCTL)
60 /* External variables not in a header file. */
62 extern int print_fatal_signals;
63 extern int sysctl_overcommit_memory;
64 extern int sysctl_overcommit_ratio;
65 extern int sysctl_panic_on_oom;
66 extern int max_threads;
67 extern int core_uses_pid;
68 extern int suid_dumpable;
69 extern char core_pattern[];
71 extern int min_free_kbytes;
72 extern int printk_ratelimit_jiffies;
73 extern int printk_ratelimit_burst;
74 extern int pid_max_min, pid_max_max;
75 extern int sysctl_drop_caches;
76 extern int percpu_pagelist_fraction;
77 extern int compat_log;
78 extern int maps_protect;
79 extern int sysctl_stat_interval;
80 extern int audit_argv_kb;
82 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
83 static int maxolduid = 65535;
85 static int min_percpu_pagelist_fract = 8;
87 static int ngroups_max = NGROUPS_MAX;
90 extern char modprobe_path[];
92 #ifdef CONFIG_CHR_DEV_SG
93 extern int sg_big_buff;
97 extern char reboot_command [];
98 extern int stop_a_enabled;
99 extern int scons_pwroff;
103 extern int pwrsw_enabled;
104 extern int unaligned_enabled;
108 #ifdef CONFIG_MATHEMU
109 extern int sysctl_ieee_emulation_warnings;
111 extern int sysctl_userprocess_debug;
112 extern int spin_retry;
115 extern int sysctl_hz_timer;
117 #ifdef CONFIG_BSD_PROCESS_ACCT
118 extern int acct_parm[];
122 extern int no_unaligned_warning;
125 #ifdef CONFIG_RT_MUTEXES
126 extern int max_lock_depth;
129 #ifdef CONFIG_SYSCTL_SYSCALL
130 static int parse_table(int __user *, int, void __user *, size_t __user *,
131 void __user *, size_t, ctl_table *);
135 #ifdef CONFIG_PROC_SYSCTL
136 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
137 void __user *buffer, size_t *lenp, loff_t *ppos);
138 static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
139 void __user *buffer, size_t *lenp, loff_t *ppos);
142 static ctl_table root_table[];
143 static struct ctl_table_header root_table_header =
144 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
146 static ctl_table kern_table[];
147 static ctl_table vm_table[];
148 static ctl_table fs_table[];
149 static ctl_table debug_table[];
150 static ctl_table dev_table[];
151 extern ctl_table random_table[];
152 #ifdef CONFIG_UNIX98_PTYS
153 extern ctl_table pty_table[];
155 #ifdef CONFIG_INOTIFY_USER
156 extern ctl_table inotify_table[];
159 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
160 int sysctl_legacy_va_layout;
163 extern int prove_locking;
164 extern int lock_stat;
166 /* The default sysctl tables: */
168 static ctl_table root_table[] = {
170 .ctl_name = CTL_KERN,
171 .procname = "kernel",
196 .ctl_name = CTL_DEBUG,
199 .child = debug_table,
208 * NOTE: do not add new entries to this table unless you have read
209 * Documentation/sysctl/ctl_unnumbered.txt
214 #ifdef CONFIG_SCHED_DEBUG
215 static unsigned long min_sched_granularity_ns = 100000; /* 100 usecs */
216 static unsigned long max_sched_granularity_ns = 1000000000; /* 1 second */
217 static unsigned long min_wakeup_granularity_ns; /* 0 usecs */
218 static unsigned long max_wakeup_granularity_ns = 1000000000; /* 1 second */
221 static ctl_table kern_table[] = {
222 #ifdef CONFIG_SCHED_DEBUG
224 .ctl_name = CTL_UNNUMBERED,
225 .procname = "sched_min_granularity_ns",
226 .data = &sysctl_sched_min_granularity,
227 .maxlen = sizeof(unsigned int),
229 .proc_handler = &proc_dointvec_minmax,
230 .strategy = &sysctl_intvec,
231 .extra1 = &min_sched_granularity_ns,
232 .extra2 = &max_sched_granularity_ns,
235 .ctl_name = CTL_UNNUMBERED,
236 .procname = "sched_latency_ns",
237 .data = &sysctl_sched_latency,
238 .maxlen = sizeof(unsigned int),
240 .proc_handler = &proc_dointvec_minmax,
241 .strategy = &sysctl_intvec,
242 .extra1 = &min_sched_granularity_ns,
243 .extra2 = &max_sched_granularity_ns,
246 .ctl_name = CTL_UNNUMBERED,
247 .procname = "sched_wakeup_granularity_ns",
248 .data = &sysctl_sched_wakeup_granularity,
249 .maxlen = sizeof(unsigned int),
251 .proc_handler = &proc_dointvec_minmax,
252 .strategy = &sysctl_intvec,
253 .extra1 = &min_wakeup_granularity_ns,
254 .extra2 = &max_wakeup_granularity_ns,
257 .ctl_name = CTL_UNNUMBERED,
258 .procname = "sched_batch_wakeup_granularity_ns",
259 .data = &sysctl_sched_batch_wakeup_granularity,
260 .maxlen = sizeof(unsigned int),
262 .proc_handler = &proc_dointvec_minmax,
263 .strategy = &sysctl_intvec,
264 .extra1 = &min_wakeup_granularity_ns,
265 .extra2 = &max_wakeup_granularity_ns,
268 .ctl_name = CTL_UNNUMBERED,
269 .procname = "sched_runtime_limit_ns",
270 .data = &sysctl_sched_runtime_limit,
271 .maxlen = sizeof(unsigned int),
273 .proc_handler = &proc_dointvec_minmax,
274 .strategy = &sysctl_intvec,
275 .extra1 = &min_sched_granularity_ns,
276 .extra2 = &max_sched_granularity_ns,
279 .ctl_name = CTL_UNNUMBERED,
280 .procname = "sched_child_runs_first",
281 .data = &sysctl_sched_child_runs_first,
282 .maxlen = sizeof(unsigned int),
284 .proc_handler = &proc_dointvec,
287 .ctl_name = CTL_UNNUMBERED,
288 .procname = "sched_features",
289 .data = &sysctl_sched_features,
290 .maxlen = sizeof(unsigned int),
292 .proc_handler = &proc_dointvec,
296 .ctl_name = CTL_UNNUMBERED,
297 .procname = "sched_compat_yield",
298 .data = &sysctl_sched_compat_yield,
299 .maxlen = sizeof(unsigned int),
301 .proc_handler = &proc_dointvec,
303 #ifdef CONFIG_PROVE_LOCKING
305 .ctl_name = CTL_UNNUMBERED,
306 .procname = "prove_locking",
307 .data = &prove_locking,
308 .maxlen = sizeof(int),
310 .proc_handler = &proc_dointvec,
313 #ifdef CONFIG_LOCK_STAT
315 .ctl_name = CTL_UNNUMBERED,
316 .procname = "lock_stat",
318 .maxlen = sizeof(int),
320 .proc_handler = &proc_dointvec,
324 .ctl_name = KERN_PANIC,
326 .data = &panic_timeout,
327 .maxlen = sizeof(int),
329 .proc_handler = &proc_dointvec,
332 .ctl_name = KERN_CORE_USES_PID,
333 .procname = "core_uses_pid",
334 .data = &core_uses_pid,
335 .maxlen = sizeof(int),
337 .proc_handler = &proc_dointvec,
339 #ifdef CONFIG_AUDITSYSCALL
341 .ctl_name = CTL_UNNUMBERED,
342 .procname = "audit_argv_kb",
343 .data = &audit_argv_kb,
344 .maxlen = sizeof(int),
346 .proc_handler = &proc_dointvec,
350 .ctl_name = KERN_CORE_PATTERN,
351 .procname = "core_pattern",
352 .data = core_pattern,
353 .maxlen = CORENAME_MAX_SIZE,
355 .proc_handler = &proc_dostring,
356 .strategy = &sysctl_string,
358 #ifdef CONFIG_PROC_SYSCTL
360 .ctl_name = KERN_TAINTED,
361 .procname = "tainted",
363 .maxlen = sizeof(int),
365 .proc_handler = &proc_dointvec_taint,
369 .ctl_name = KERN_CAP_BSET,
370 .procname = "cap-bound",
372 .maxlen = sizeof(kernel_cap_t),
374 .proc_handler = &proc_dointvec_bset,
376 #ifdef CONFIG_BLK_DEV_INITRD
378 .ctl_name = KERN_REALROOTDEV,
379 .procname = "real-root-dev",
380 .data = &real_root_dev,
381 .maxlen = sizeof(int),
383 .proc_handler = &proc_dointvec,
387 .ctl_name = CTL_UNNUMBERED,
388 .procname = "print-fatal-signals",
389 .data = &print_fatal_signals,
390 .maxlen = sizeof(int),
392 .proc_handler = &proc_dointvec,
396 .ctl_name = KERN_SPARC_REBOOT,
397 .procname = "reboot-cmd",
398 .data = reboot_command,
401 .proc_handler = &proc_dostring,
402 .strategy = &sysctl_string,
405 .ctl_name = KERN_SPARC_STOP_A,
406 .procname = "stop-a",
407 .data = &stop_a_enabled,
408 .maxlen = sizeof (int),
410 .proc_handler = &proc_dointvec,
413 .ctl_name = KERN_SPARC_SCONS_PWROFF,
414 .procname = "scons-poweroff",
415 .data = &scons_pwroff,
416 .maxlen = sizeof (int),
418 .proc_handler = &proc_dointvec,
423 .ctl_name = KERN_HPPA_PWRSW,
424 .procname = "soft-power",
425 .data = &pwrsw_enabled,
426 .maxlen = sizeof (int),
428 .proc_handler = &proc_dointvec,
431 .ctl_name = KERN_HPPA_UNALIGNED,
432 .procname = "unaligned-trap",
433 .data = &unaligned_enabled,
434 .maxlen = sizeof (int),
436 .proc_handler = &proc_dointvec,
440 .ctl_name = KERN_CTLALTDEL,
441 .procname = "ctrl-alt-del",
443 .maxlen = sizeof(int),
445 .proc_handler = &proc_dointvec,
448 .ctl_name = KERN_PRINTK,
449 .procname = "printk",
450 .data = &console_loglevel,
451 .maxlen = 4*sizeof(int),
453 .proc_handler = &proc_dointvec,
457 .ctl_name = KERN_MODPROBE,
458 .procname = "modprobe",
459 .data = &modprobe_path,
460 .maxlen = KMOD_PATH_LEN,
462 .proc_handler = &proc_dostring,
463 .strategy = &sysctl_string,
466 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
468 .ctl_name = KERN_HOTPLUG,
469 .procname = "hotplug",
470 .data = &uevent_helper,
471 .maxlen = UEVENT_HELPER_PATH_LEN,
473 .proc_handler = &proc_dostring,
474 .strategy = &sysctl_string,
477 #ifdef CONFIG_CHR_DEV_SG
479 .ctl_name = KERN_SG_BIG_BUFF,
480 .procname = "sg-big-buff",
481 .data = &sg_big_buff,
482 .maxlen = sizeof (int),
484 .proc_handler = &proc_dointvec,
487 #ifdef CONFIG_BSD_PROCESS_ACCT
489 .ctl_name = KERN_ACCT,
492 .maxlen = 3*sizeof(int),
494 .proc_handler = &proc_dointvec,
497 #ifdef CONFIG_MAGIC_SYSRQ
499 .ctl_name = KERN_SYSRQ,
501 .data = &__sysrq_enabled,
502 .maxlen = sizeof (int),
504 .proc_handler = &proc_dointvec,
507 #ifdef CONFIG_PROC_SYSCTL
509 .ctl_name = KERN_CADPID,
510 .procname = "cad_pid",
512 .maxlen = sizeof (int),
514 .proc_handler = &proc_do_cad_pid,
518 .ctl_name = KERN_MAX_THREADS,
519 .procname = "threads-max",
520 .data = &max_threads,
521 .maxlen = sizeof(int),
523 .proc_handler = &proc_dointvec,
526 .ctl_name = KERN_RANDOM,
527 .procname = "random",
529 .child = random_table,
531 #ifdef CONFIG_UNIX98_PTYS
533 .ctl_name = KERN_PTY,
540 .ctl_name = KERN_OVERFLOWUID,
541 .procname = "overflowuid",
542 .data = &overflowuid,
543 .maxlen = sizeof(int),
545 .proc_handler = &proc_dointvec_minmax,
546 .strategy = &sysctl_intvec,
547 .extra1 = &minolduid,
548 .extra2 = &maxolduid,
551 .ctl_name = KERN_OVERFLOWGID,
552 .procname = "overflowgid",
553 .data = &overflowgid,
554 .maxlen = sizeof(int),
556 .proc_handler = &proc_dointvec_minmax,
557 .strategy = &sysctl_intvec,
558 .extra1 = &minolduid,
559 .extra2 = &maxolduid,
562 #ifdef CONFIG_MATHEMU
564 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
565 .procname = "ieee_emulation_warnings",
566 .data = &sysctl_ieee_emulation_warnings,
567 .maxlen = sizeof(int),
569 .proc_handler = &proc_dointvec,
572 #ifdef CONFIG_NO_IDLE_HZ
574 .ctl_name = KERN_HZ_TIMER,
575 .procname = "hz_timer",
576 .data = &sysctl_hz_timer,
577 .maxlen = sizeof(int),
579 .proc_handler = &proc_dointvec,
583 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
584 .procname = "userprocess_debug",
585 .data = &sysctl_userprocess_debug,
586 .maxlen = sizeof(int),
588 .proc_handler = &proc_dointvec,
592 .ctl_name = KERN_PIDMAX,
593 .procname = "pid_max",
595 .maxlen = sizeof (int),
597 .proc_handler = &proc_dointvec_minmax,
598 .strategy = sysctl_intvec,
599 .extra1 = &pid_max_min,
600 .extra2 = &pid_max_max,
603 .ctl_name = KERN_PANIC_ON_OOPS,
604 .procname = "panic_on_oops",
605 .data = &panic_on_oops,
606 .maxlen = sizeof(int),
608 .proc_handler = &proc_dointvec,
611 .ctl_name = KERN_PRINTK_RATELIMIT,
612 .procname = "printk_ratelimit",
613 .data = &printk_ratelimit_jiffies,
614 .maxlen = sizeof(int),
616 .proc_handler = &proc_dointvec_jiffies,
617 .strategy = &sysctl_jiffies,
620 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
621 .procname = "printk_ratelimit_burst",
622 .data = &printk_ratelimit_burst,
623 .maxlen = sizeof(int),
625 .proc_handler = &proc_dointvec,
628 .ctl_name = KERN_NGROUPS_MAX,
629 .procname = "ngroups_max",
630 .data = &ngroups_max,
631 .maxlen = sizeof (int),
633 .proc_handler = &proc_dointvec,
635 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
637 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
638 .procname = "unknown_nmi_panic",
639 .data = &unknown_nmi_panic,
640 .maxlen = sizeof (int),
642 .proc_handler = &proc_dointvec,
645 .ctl_name = KERN_NMI_WATCHDOG,
646 .procname = "nmi_watchdog",
647 .data = &nmi_watchdog_enabled,
648 .maxlen = sizeof (int),
650 .proc_handler = &proc_nmi_enabled,
653 #if defined(CONFIG_X86)
655 .ctl_name = KERN_PANIC_ON_NMI,
656 .procname = "panic_on_unrecovered_nmi",
657 .data = &panic_on_unrecovered_nmi,
658 .maxlen = sizeof(int),
660 .proc_handler = &proc_dointvec,
663 .ctl_name = KERN_BOOTLOADER_TYPE,
664 .procname = "bootloader_type",
665 .data = &bootloader_type,
666 .maxlen = sizeof (int),
668 .proc_handler = &proc_dointvec,
671 .ctl_name = CTL_UNNUMBERED,
672 .procname = "kstack_depth_to_print",
673 .data = &kstack_depth_to_print,
674 .maxlen = sizeof(int),
676 .proc_handler = &proc_dointvec,
679 #if defined(CONFIG_MMU)
681 .ctl_name = KERN_RANDOMIZE,
682 .procname = "randomize_va_space",
683 .data = &randomize_va_space,
684 .maxlen = sizeof(int),
686 .proc_handler = &proc_dointvec,
689 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
691 .ctl_name = KERN_SPIN_RETRY,
692 .procname = "spin_retry",
694 .maxlen = sizeof (int),
696 .proc_handler = &proc_dointvec,
699 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
701 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
702 .procname = "acpi_video_flags",
703 .data = &acpi_realmode_flags,
704 .maxlen = sizeof (unsigned long),
706 .proc_handler = &proc_doulongvec_minmax,
711 .ctl_name = KERN_IA64_UNALIGNED,
712 .procname = "ignore-unaligned-usertrap",
713 .data = &no_unaligned_warning,
714 .maxlen = sizeof (int),
716 .proc_handler = &proc_dointvec,
721 .ctl_name = KERN_COMPAT_LOG,
722 .procname = "compat-log",
724 .maxlen = sizeof (int),
726 .proc_handler = &proc_dointvec,
729 #ifdef CONFIG_RT_MUTEXES
731 .ctl_name = KERN_MAX_LOCK_DEPTH,
732 .procname = "max_lock_depth",
733 .data = &max_lock_depth,
734 .maxlen = sizeof(int),
736 .proc_handler = &proc_dointvec,
739 #ifdef CONFIG_PROC_FS
741 .ctl_name = CTL_UNNUMBERED,
742 .procname = "maps_protect",
743 .data = &maps_protect,
744 .maxlen = sizeof(int),
746 .proc_handler = &proc_dointvec,
750 .ctl_name = CTL_UNNUMBERED,
751 .procname = "poweroff_cmd",
752 .data = &poweroff_cmd,
753 .maxlen = POWEROFF_CMD_PATH_LEN,
755 .proc_handler = &proc_dostring,
756 .strategy = &sysctl_string,
759 * NOTE: do not add new entries to this table unless you have read
760 * Documentation/sysctl/ctl_unnumbered.txt
765 /* Constants for minimum and maximum testing in vm_table.
766 We use these as one-element integer vectors. */
769 static int one_hundred = 100;
772 static ctl_table vm_table[] = {
774 .ctl_name = VM_OVERCOMMIT_MEMORY,
775 .procname = "overcommit_memory",
776 .data = &sysctl_overcommit_memory,
777 .maxlen = sizeof(sysctl_overcommit_memory),
779 .proc_handler = &proc_dointvec,
782 .ctl_name = VM_PANIC_ON_OOM,
783 .procname = "panic_on_oom",
784 .data = &sysctl_panic_on_oom,
785 .maxlen = sizeof(sysctl_panic_on_oom),
787 .proc_handler = &proc_dointvec,
790 .ctl_name = VM_OVERCOMMIT_RATIO,
791 .procname = "overcommit_ratio",
792 .data = &sysctl_overcommit_ratio,
793 .maxlen = sizeof(sysctl_overcommit_ratio),
795 .proc_handler = &proc_dointvec,
798 .ctl_name = VM_PAGE_CLUSTER,
799 .procname = "page-cluster",
800 .data = &page_cluster,
801 .maxlen = sizeof(int),
803 .proc_handler = &proc_dointvec,
806 .ctl_name = VM_DIRTY_BACKGROUND,
807 .procname = "dirty_background_ratio",
808 .data = &dirty_background_ratio,
809 .maxlen = sizeof(dirty_background_ratio),
811 .proc_handler = &proc_dointvec_minmax,
812 .strategy = &sysctl_intvec,
814 .extra2 = &one_hundred,
817 .ctl_name = VM_DIRTY_RATIO,
818 .procname = "dirty_ratio",
819 .data = &vm_dirty_ratio,
820 .maxlen = sizeof(vm_dirty_ratio),
822 .proc_handler = &proc_dointvec_minmax,
823 .strategy = &sysctl_intvec,
825 .extra2 = &one_hundred,
828 .ctl_name = VM_DIRTY_WB_CS,
829 .procname = "dirty_writeback_centisecs",
830 .data = &dirty_writeback_interval,
831 .maxlen = sizeof(dirty_writeback_interval),
833 .proc_handler = &dirty_writeback_centisecs_handler,
836 .ctl_name = VM_DIRTY_EXPIRE_CS,
837 .procname = "dirty_expire_centisecs",
838 .data = &dirty_expire_interval,
839 .maxlen = sizeof(dirty_expire_interval),
841 .proc_handler = &proc_dointvec_userhz_jiffies,
844 .ctl_name = VM_NR_PDFLUSH_THREADS,
845 .procname = "nr_pdflush_threads",
846 .data = &nr_pdflush_threads,
847 .maxlen = sizeof nr_pdflush_threads,
848 .mode = 0444 /* read-only*/,
849 .proc_handler = &proc_dointvec,
852 .ctl_name = VM_SWAPPINESS,
853 .procname = "swappiness",
854 .data = &vm_swappiness,
855 .maxlen = sizeof(vm_swappiness),
857 .proc_handler = &proc_dointvec_minmax,
858 .strategy = &sysctl_intvec,
860 .extra2 = &one_hundred,
862 #ifdef CONFIG_HUGETLB_PAGE
864 .ctl_name = VM_HUGETLB_PAGES,
865 .procname = "nr_hugepages",
866 .data = &max_huge_pages,
867 .maxlen = sizeof(unsigned long),
869 .proc_handler = &hugetlb_sysctl_handler,
870 .extra1 = (void *)&hugetlb_zero,
871 .extra2 = (void *)&hugetlb_infinity,
874 .ctl_name = VM_HUGETLB_GROUP,
875 .procname = "hugetlb_shm_group",
876 .data = &sysctl_hugetlb_shm_group,
877 .maxlen = sizeof(gid_t),
879 .proc_handler = &proc_dointvec,
882 .ctl_name = CTL_UNNUMBERED,
883 .procname = "hugepages_treat_as_movable",
884 .data = &hugepages_treat_as_movable,
885 .maxlen = sizeof(int),
887 .proc_handler = &hugetlb_treat_movable_handler,
891 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
892 .procname = "lowmem_reserve_ratio",
893 .data = &sysctl_lowmem_reserve_ratio,
894 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
896 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
897 .strategy = &sysctl_intvec,
900 .ctl_name = VM_DROP_PAGECACHE,
901 .procname = "drop_caches",
902 .data = &sysctl_drop_caches,
903 .maxlen = sizeof(int),
905 .proc_handler = drop_caches_sysctl_handler,
906 .strategy = &sysctl_intvec,
909 .ctl_name = VM_MIN_FREE_KBYTES,
910 .procname = "min_free_kbytes",
911 .data = &min_free_kbytes,
912 .maxlen = sizeof(min_free_kbytes),
914 .proc_handler = &min_free_kbytes_sysctl_handler,
915 .strategy = &sysctl_intvec,
919 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
920 .procname = "percpu_pagelist_fraction",
921 .data = &percpu_pagelist_fraction,
922 .maxlen = sizeof(percpu_pagelist_fraction),
924 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
925 .strategy = &sysctl_intvec,
926 .extra1 = &min_percpu_pagelist_fract,
930 .ctl_name = VM_MAX_MAP_COUNT,
931 .procname = "max_map_count",
932 .data = &sysctl_max_map_count,
933 .maxlen = sizeof(sysctl_max_map_count),
935 .proc_handler = &proc_dointvec
939 .ctl_name = VM_LAPTOP_MODE,
940 .procname = "laptop_mode",
941 .data = &laptop_mode,
942 .maxlen = sizeof(laptop_mode),
944 .proc_handler = &proc_dointvec_jiffies,
945 .strategy = &sysctl_jiffies,
948 .ctl_name = VM_BLOCK_DUMP,
949 .procname = "block_dump",
951 .maxlen = sizeof(block_dump),
953 .proc_handler = &proc_dointvec,
954 .strategy = &sysctl_intvec,
958 .ctl_name = VM_VFS_CACHE_PRESSURE,
959 .procname = "vfs_cache_pressure",
960 .data = &sysctl_vfs_cache_pressure,
961 .maxlen = sizeof(sysctl_vfs_cache_pressure),
963 .proc_handler = &proc_dointvec,
964 .strategy = &sysctl_intvec,
967 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
969 .ctl_name = VM_LEGACY_VA_LAYOUT,
970 .procname = "legacy_va_layout",
971 .data = &sysctl_legacy_va_layout,
972 .maxlen = sizeof(sysctl_legacy_va_layout),
974 .proc_handler = &proc_dointvec,
975 .strategy = &sysctl_intvec,
981 .ctl_name = VM_ZONE_RECLAIM_MODE,
982 .procname = "zone_reclaim_mode",
983 .data = &zone_reclaim_mode,
984 .maxlen = sizeof(zone_reclaim_mode),
986 .proc_handler = &proc_dointvec,
987 .strategy = &sysctl_intvec,
991 .ctl_name = VM_MIN_UNMAPPED,
992 .procname = "min_unmapped_ratio",
993 .data = &sysctl_min_unmapped_ratio,
994 .maxlen = sizeof(sysctl_min_unmapped_ratio),
996 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
997 .strategy = &sysctl_intvec,
999 .extra2 = &one_hundred,
1002 .ctl_name = VM_MIN_SLAB,
1003 .procname = "min_slab_ratio",
1004 .data = &sysctl_min_slab_ratio,
1005 .maxlen = sizeof(sysctl_min_slab_ratio),
1007 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1008 .strategy = &sysctl_intvec,
1010 .extra2 = &one_hundred,
1015 .ctl_name = CTL_UNNUMBERED,
1016 .procname = "stat_interval",
1017 .data = &sysctl_stat_interval,
1018 .maxlen = sizeof(sysctl_stat_interval),
1020 .proc_handler = &proc_dointvec_jiffies,
1021 .strategy = &sysctl_jiffies,
1024 #ifdef CONFIG_SECURITY
1026 .ctl_name = CTL_UNNUMBERED,
1027 .procname = "mmap_min_addr",
1028 .data = &mmap_min_addr,
1029 .maxlen = sizeof(unsigned long),
1031 .proc_handler = &proc_doulongvec_minmax,
1036 .ctl_name = CTL_UNNUMBERED,
1037 .procname = "numa_zonelist_order",
1038 .data = &numa_zonelist_order,
1039 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1041 .proc_handler = &numa_zonelist_order_handler,
1042 .strategy = &sysctl_string,
1045 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1046 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1048 .ctl_name = VM_VDSO_ENABLED,
1049 .procname = "vdso_enabled",
1050 .data = &vdso_enabled,
1051 .maxlen = sizeof(vdso_enabled),
1053 .proc_handler = &proc_dointvec,
1054 .strategy = &sysctl_intvec,
1059 * NOTE: do not add new entries to this table unless you have read
1060 * Documentation/sysctl/ctl_unnumbered.txt
1065 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1066 static ctl_table binfmt_misc_table[] = {
1071 static ctl_table fs_table[] = {
1073 .ctl_name = FS_NRINODE,
1074 .procname = "inode-nr",
1075 .data = &inodes_stat,
1076 .maxlen = 2*sizeof(int),
1078 .proc_handler = &proc_dointvec,
1081 .ctl_name = FS_STATINODE,
1082 .procname = "inode-state",
1083 .data = &inodes_stat,
1084 .maxlen = 7*sizeof(int),
1086 .proc_handler = &proc_dointvec,
1089 .ctl_name = FS_NRFILE,
1090 .procname = "file-nr",
1091 .data = &files_stat,
1092 .maxlen = 3*sizeof(int),
1094 .proc_handler = &proc_nr_files,
1097 .ctl_name = FS_MAXFILE,
1098 .procname = "file-max",
1099 .data = &files_stat.max_files,
1100 .maxlen = sizeof(int),
1102 .proc_handler = &proc_dointvec,
1105 .ctl_name = FS_DENTRY,
1106 .procname = "dentry-state",
1107 .data = &dentry_stat,
1108 .maxlen = 6*sizeof(int),
1110 .proc_handler = &proc_dointvec,
1113 .ctl_name = FS_OVERFLOWUID,
1114 .procname = "overflowuid",
1115 .data = &fs_overflowuid,
1116 .maxlen = sizeof(int),
1118 .proc_handler = &proc_dointvec_minmax,
1119 .strategy = &sysctl_intvec,
1120 .extra1 = &minolduid,
1121 .extra2 = &maxolduid,
1124 .ctl_name = FS_OVERFLOWGID,
1125 .procname = "overflowgid",
1126 .data = &fs_overflowgid,
1127 .maxlen = sizeof(int),
1129 .proc_handler = &proc_dointvec_minmax,
1130 .strategy = &sysctl_intvec,
1131 .extra1 = &minolduid,
1132 .extra2 = &maxolduid,
1135 .ctl_name = FS_LEASES,
1136 .procname = "leases-enable",
1137 .data = &leases_enable,
1138 .maxlen = sizeof(int),
1140 .proc_handler = &proc_dointvec,
1142 #ifdef CONFIG_DNOTIFY
1144 .ctl_name = FS_DIR_NOTIFY,
1145 .procname = "dir-notify-enable",
1146 .data = &dir_notify_enable,
1147 .maxlen = sizeof(int),
1149 .proc_handler = &proc_dointvec,
1154 .ctl_name = FS_LEASE_TIME,
1155 .procname = "lease-break-time",
1156 .data = &lease_break_time,
1157 .maxlen = sizeof(int),
1159 .proc_handler = &proc_dointvec_minmax,
1160 .strategy = &sysctl_intvec,
1165 .ctl_name = FS_AIO_NR,
1166 .procname = "aio-nr",
1168 .maxlen = sizeof(aio_nr),
1170 .proc_handler = &proc_doulongvec_minmax,
1173 .ctl_name = FS_AIO_MAX_NR,
1174 .procname = "aio-max-nr",
1175 .data = &aio_max_nr,
1176 .maxlen = sizeof(aio_max_nr),
1178 .proc_handler = &proc_doulongvec_minmax,
1180 #ifdef CONFIG_INOTIFY_USER
1182 .ctl_name = FS_INOTIFY,
1183 .procname = "inotify",
1185 .child = inotify_table,
1190 .ctl_name = KERN_SETUID_DUMPABLE,
1191 .procname = "suid_dumpable",
1192 .data = &suid_dumpable,
1193 .maxlen = sizeof(int),
1195 .proc_handler = &proc_dointvec,
1197 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1199 .ctl_name = CTL_UNNUMBERED,
1200 .procname = "binfmt_misc",
1202 .child = binfmt_misc_table,
1206 * NOTE: do not add new entries to this table unless you have read
1207 * Documentation/sysctl/ctl_unnumbered.txt
1212 static ctl_table debug_table[] = {
1213 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1215 .ctl_name = CTL_UNNUMBERED,
1216 .procname = "exception-trace",
1217 .data = &show_unhandled_signals,
1218 .maxlen = sizeof(int),
1220 .proc_handler = proc_dointvec
1226 static ctl_table dev_table[] = {
1230 static DEFINE_SPINLOCK(sysctl_lock);
1232 /* called under sysctl_lock */
1233 static int use_table(struct ctl_table_header *p)
1235 if (unlikely(p->unregistering))
1241 /* called under sysctl_lock */
1242 static void unuse_table(struct ctl_table_header *p)
1245 if (unlikely(p->unregistering))
1246 complete(p->unregistering);
1249 /* called under sysctl_lock, will reacquire if has to wait */
1250 static void start_unregistering(struct ctl_table_header *p)
1253 * if p->used is 0, nobody will ever touch that entry again;
1254 * we'll eliminate all paths to it before dropping sysctl_lock
1256 if (unlikely(p->used)) {
1257 struct completion wait;
1258 init_completion(&wait);
1259 p->unregistering = &wait;
1260 spin_unlock(&sysctl_lock);
1261 wait_for_completion(&wait);
1262 spin_lock(&sysctl_lock);
1265 * do not remove from the list until nobody holds it; walking the
1266 * list in do_sysctl() relies on that.
1268 list_del_init(&p->ctl_entry);
1271 void sysctl_head_finish(struct ctl_table_header *head)
1275 spin_lock(&sysctl_lock);
1277 spin_unlock(&sysctl_lock);
1280 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1282 struct ctl_table_header *head;
1283 struct list_head *tmp;
1284 spin_lock(&sysctl_lock);
1286 tmp = &prev->ctl_entry;
1290 tmp = &root_table_header.ctl_entry;
1292 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1294 if (!use_table(head))
1296 spin_unlock(&sysctl_lock);
1300 if (tmp == &root_table_header.ctl_entry)
1303 spin_unlock(&sysctl_lock);
1307 #ifdef CONFIG_SYSCTL_SYSCALL
1308 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1309 void __user *newval, size_t newlen)
1311 struct ctl_table_header *head;
1312 int error = -ENOTDIR;
1314 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1318 if (!oldlenp || get_user(old_len, oldlenp))
1322 for (head = sysctl_head_next(NULL); head;
1323 head = sysctl_head_next(head)) {
1324 error = parse_table(name, nlen, oldval, oldlenp,
1325 newval, newlen, head->ctl_table);
1326 if (error != -ENOTDIR) {
1327 sysctl_head_finish(head);
1334 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1336 struct __sysctl_args tmp;
1339 if (copy_from_user(&tmp, args, sizeof(tmp)))
1343 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1344 tmp.newval, tmp.newlen);
1348 #endif /* CONFIG_SYSCTL_SYSCALL */
1351 * sysctl_perm does NOT grant the superuser all rights automatically, because
1352 * some sysctl variables are readonly even to root.
1355 static int test_perm(int mode, int op)
1359 else if (in_egroup_p(0))
1361 if ((mode & op & 0007) == op)
1366 int sysctl_perm(ctl_table *table, int op)
1369 error = security_sysctl(table, op);
1372 return test_perm(table->mode, op);
1375 #ifdef CONFIG_SYSCTL_SYSCALL
1376 static int parse_table(int __user *name, int nlen,
1377 void __user *oldval, size_t __user *oldlenp,
1378 void __user *newval, size_t newlen,
1385 if (get_user(n, name))
1387 for ( ; table->ctl_name || table->procname; table++) {
1388 if (!table->ctl_name)
1390 if (n == table->ctl_name) {
1393 if (sysctl_perm(table, 001))
1397 table = table->child;
1400 error = do_sysctl_strategy(table, name, nlen,
1409 /* Perform the actual read/write of a sysctl table entry. */
1410 int do_sysctl_strategy (ctl_table *table,
1411 int __user *name, int nlen,
1412 void __user *oldval, size_t __user *oldlenp,
1413 void __user *newval, size_t newlen)
1422 if (sysctl_perm(table, op))
1425 if (table->strategy) {
1426 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1434 /* If there is no strategy routine, or if the strategy returns
1435 * zero, proceed with automatic r/w */
1436 if (table->data && table->maxlen) {
1437 if (oldval && oldlenp) {
1438 if (get_user(len, oldlenp))
1441 if (len > table->maxlen)
1442 len = table->maxlen;
1443 if(copy_to_user(oldval, table->data, len))
1445 if(put_user(len, oldlenp))
1449 if (newval && newlen) {
1451 if (len > table->maxlen)
1452 len = table->maxlen;
1453 if(copy_from_user(table->data, newval, len))
1459 #endif /* CONFIG_SYSCTL_SYSCALL */
1461 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1463 for (; table->ctl_name || table->procname; table++) {
1464 table->parent = parent;
1466 sysctl_set_parent(table, table->child);
1470 static __init int sysctl_init(void)
1472 sysctl_set_parent(NULL, root_table);
1476 core_initcall(sysctl_init);
1479 * register_sysctl_table - register a sysctl hierarchy
1480 * @table: the top-level table structure
1482 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1483 * array. An entry with a ctl_name of 0 terminates the table.
1485 * The members of the &ctl_table structure are used as follows:
1487 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1488 * must be unique within that level of sysctl
1490 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1491 * enter a sysctl file
1493 * data - a pointer to data for use by proc_handler
1495 * maxlen - the maximum size in bytes of the data
1497 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1499 * child - a pointer to the child sysctl table if this entry is a directory, or
1502 * proc_handler - the text handler routine (described below)
1504 * strategy - the strategy routine (described below)
1506 * de - for internal use by the sysctl routines
1508 * extra1, extra2 - extra pointers usable by the proc handler routines
1510 * Leaf nodes in the sysctl tree will be represented by a single file
1511 * under /proc; non-leaf nodes will be represented by directories.
1513 * sysctl(2) can automatically manage read and write requests through
1514 * the sysctl table. The data and maxlen fields of the ctl_table
1515 * struct enable minimal validation of the values being written to be
1516 * performed, and the mode field allows minimal authentication.
1518 * More sophisticated management can be enabled by the provision of a
1519 * strategy routine with the table entry. This will be called before
1520 * any automatic read or write of the data is performed.
1522 * The strategy routine may return
1524 * < 0 - Error occurred (error is passed to user process)
1526 * 0 - OK - proceed with automatic read or write.
1528 * > 0 - OK - read or write has been done by the strategy routine, so
1529 * return immediately.
1531 * There must be a proc_handler routine for any terminal nodes
1532 * mirrored under /proc/sys (non-terminals are handled by a built-in
1533 * directory handler). Several default handlers are available to
1534 * cover common cases -
1536 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1537 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1538 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1540 * It is the handler's job to read the input buffer from user memory
1541 * and process it. The handler should return 0 on success.
1543 * This routine returns %NULL on a failure to register, and a pointer
1544 * to the table header on success.
1546 struct ctl_table_header *register_sysctl_table(ctl_table * table)
1548 struct ctl_table_header *tmp;
1549 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1552 tmp->ctl_table = table;
1553 INIT_LIST_HEAD(&tmp->ctl_entry);
1555 tmp->unregistering = NULL;
1556 sysctl_set_parent(NULL, table);
1557 spin_lock(&sysctl_lock);
1558 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1559 spin_unlock(&sysctl_lock);
1564 * unregister_sysctl_table - unregister a sysctl table hierarchy
1565 * @header: the header returned from register_sysctl_table
1567 * Unregisters the sysctl table and all children. proc entries may not
1568 * actually be removed until they are no longer used by anyone.
1570 void unregister_sysctl_table(struct ctl_table_header * header)
1573 spin_lock(&sysctl_lock);
1574 start_unregistering(header);
1575 spin_unlock(&sysctl_lock);
1579 #else /* !CONFIG_SYSCTL */
1580 struct ctl_table_header *register_sysctl_table(ctl_table * table)
1585 void unregister_sysctl_table(struct ctl_table_header * table)
1589 #endif /* CONFIG_SYSCTL */
1595 #ifdef CONFIG_PROC_SYSCTL
1597 static int _proc_do_string(void* data, int maxlen, int write,
1598 struct file *filp, void __user *buffer,
1599 size_t *lenp, loff_t *ppos)
1605 if (!data || !maxlen || !*lenp) {
1613 while (len < *lenp) {
1614 if (get_user(c, p++))
1616 if (c == 0 || c == '\n')
1622 if(copy_from_user(data, buffer, len))
1624 ((char *) data)[len] = 0;
1642 if(copy_to_user(buffer, data, len))
1645 if(put_user('\n', ((char __user *) buffer) + len))
1656 * proc_dostring - read a string sysctl
1657 * @table: the sysctl table
1658 * @write: %TRUE if this is a write to the sysctl file
1659 * @filp: the file structure
1660 * @buffer: the user buffer
1661 * @lenp: the size of the user buffer
1662 * @ppos: file position
1664 * Reads/writes a string from/to the user buffer. If the kernel
1665 * buffer provided is not large enough to hold the string, the
1666 * string is truncated. The copied string is %NULL-terminated.
1667 * If the string is being read by the user process, it is copied
1668 * and a newline '\n' is added. It is truncated if the buffer is
1671 * Returns 0 on success.
1673 int proc_dostring(ctl_table *table, int write, struct file *filp,
1674 void __user *buffer, size_t *lenp, loff_t *ppos)
1676 return _proc_do_string(table->data, table->maxlen, write, filp,
1677 buffer, lenp, ppos);
1681 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1683 int write, void *data)
1686 *valp = *negp ? -*lvalp : *lvalp;
1691 *lvalp = (unsigned long)-val;
1694 *lvalp = (unsigned long)val;
1700 static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1701 int write, struct file *filp, void __user *buffer,
1702 size_t *lenp, loff_t *ppos,
1703 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1704 int write, void *data),
1707 #define TMPBUFLEN 21
1708 int *i, vleft, first=1, neg, val;
1712 char buf[TMPBUFLEN], *p;
1713 char __user *s = buffer;
1715 if (!tbl_data || !table->maxlen || !*lenp ||
1716 (*ppos && !write)) {
1721 i = (int *) tbl_data;
1722 vleft = table->maxlen / sizeof(*i);
1726 conv = do_proc_dointvec_conv;
1728 for (; left && vleft--; i++, first=0) {
1743 if (len > sizeof(buf) - 1)
1744 len = sizeof(buf) - 1;
1745 if (copy_from_user(buf, s, len))
1749 if (*p == '-' && left > 1) {
1753 if (*p < '0' || *p > '9')
1756 lval = simple_strtoul(p, &p, 0);
1759 if ((len < left) && *p && !isspace(*p))
1766 if (conv(&neg, &lval, i, 1, data))
1773 if (conv(&neg, &lval, i, 0, data))
1776 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1780 if(copy_to_user(s, buf, len))
1787 if (!write && !first && left) {
1788 if(put_user('\n', s))
1795 if (get_user(c, s++))
1810 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1811 void __user *buffer, size_t *lenp, loff_t *ppos,
1812 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1813 int write, void *data),
1816 return __do_proc_dointvec(table->data, table, write, filp,
1817 buffer, lenp, ppos, conv, data);
1821 * proc_dointvec - read a vector of integers
1822 * @table: the sysctl table
1823 * @write: %TRUE if this is a write to the sysctl file
1824 * @filp: the file structure
1825 * @buffer: the user buffer
1826 * @lenp: the size of the user buffer
1827 * @ppos: file position
1829 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1830 * values from/to the user buffer, treated as an ASCII string.
1832 * Returns 0 on success.
1834 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1835 void __user *buffer, size_t *lenp, loff_t *ppos)
1837 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1845 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1847 int write, void *data)
1849 int op = *(int *)data;
1851 int val = *negp ? -*lvalp : *lvalp;
1853 case OP_SET: *valp = val; break;
1854 case OP_AND: *valp &= val; break;
1855 case OP_OR: *valp |= val; break;
1861 *lvalp = (unsigned long)-val;
1864 *lvalp = (unsigned long)val;
1871 * init may raise the set.
1874 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1875 void __user *buffer, size_t *lenp, loff_t *ppos)
1879 if (write && !capable(CAP_SYS_MODULE)) {
1883 op = is_init(current) ? OP_SET : OP_AND;
1884 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1885 do_proc_dointvec_bset_conv,&op);
1889 * Taint values can only be increased
1891 static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
1892 void __user *buffer, size_t *lenp, loff_t *ppos)
1896 if (write && !capable(CAP_SYS_ADMIN))
1900 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1901 do_proc_dointvec_bset_conv,&op);
1904 struct do_proc_dointvec_minmax_conv_param {
1909 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1911 int write, void *data)
1913 struct do_proc_dointvec_minmax_conv_param *param = data;
1915 int val = *negp ? -*lvalp : *lvalp;
1916 if ((param->min && *param->min > val) ||
1917 (param->max && *param->max < val))
1924 *lvalp = (unsigned long)-val;
1927 *lvalp = (unsigned long)val;
1934 * proc_dointvec_minmax - read a vector of integers with min/max values
1935 * @table: the sysctl table
1936 * @write: %TRUE if this is a write to the sysctl file
1937 * @filp: the file structure
1938 * @buffer: the user buffer
1939 * @lenp: the size of the user buffer
1940 * @ppos: file position
1942 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1943 * values from/to the user buffer, treated as an ASCII string.
1945 * This routine will ensure the values are within the range specified by
1946 * table->extra1 (min) and table->extra2 (max).
1948 * Returns 0 on success.
1950 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1951 void __user *buffer, size_t *lenp, loff_t *ppos)
1953 struct do_proc_dointvec_minmax_conv_param param = {
1954 .min = (int *) table->extra1,
1955 .max = (int *) table->extra2,
1957 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1958 do_proc_dointvec_minmax_conv, ¶m);
1961 static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
1963 void __user *buffer,
1964 size_t *lenp, loff_t *ppos,
1965 unsigned long convmul,
1966 unsigned long convdiv)
1968 #define TMPBUFLEN 21
1969 unsigned long *i, *min, *max, val;
1970 int vleft, first=1, neg;
1972 char buf[TMPBUFLEN], *p;
1973 char __user *s = buffer;
1975 if (!data || !table->maxlen || !*lenp ||
1976 (*ppos && !write)) {
1981 i = (unsigned long *) data;
1982 min = (unsigned long *) table->extra1;
1983 max = (unsigned long *) table->extra2;
1984 vleft = table->maxlen / sizeof(unsigned long);
1987 for (; left && vleft--; i++, min++, max++, first=0) {
2002 if (len > TMPBUFLEN-1)
2004 if (copy_from_user(buf, s, len))
2008 if (*p == '-' && left > 1) {
2012 if (*p < '0' || *p > '9')
2014 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2016 if ((len < left) && *p && !isspace(*p))
2025 if ((min && val < *min) || (max && val > *max))
2032 sprintf(p, "%lu", convdiv * (*i) / convmul);
2036 if(copy_to_user(s, buf, len))
2043 if (!write && !first && left) {
2044 if(put_user('\n', s))
2051 if (get_user(c, s++))
2066 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2068 void __user *buffer,
2069 size_t *lenp, loff_t *ppos,
2070 unsigned long convmul,
2071 unsigned long convdiv)
2073 return __do_proc_doulongvec_minmax(table->data, table, write,
2074 filp, buffer, lenp, ppos, convmul, convdiv);
2078 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2079 * @table: the sysctl table
2080 * @write: %TRUE if this is a write to the sysctl file
2081 * @filp: the file structure
2082 * @buffer: the user buffer
2083 * @lenp: the size of the user buffer
2084 * @ppos: file position
2086 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2087 * values from/to the user buffer, treated as an ASCII string.
2089 * This routine will ensure the values are within the range specified by
2090 * table->extra1 (min) and table->extra2 (max).
2092 * Returns 0 on success.
2094 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2095 void __user *buffer, size_t *lenp, loff_t *ppos)
2097 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2101 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2102 * @table: the sysctl table
2103 * @write: %TRUE if this is a write to the sysctl file
2104 * @filp: the file structure
2105 * @buffer: the user buffer
2106 * @lenp: the size of the user buffer
2107 * @ppos: file position
2109 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2110 * values from/to the user buffer, treated as an ASCII string. The values
2111 * are treated as milliseconds, and converted to jiffies when they are stored.
2113 * This routine will ensure the values are within the range specified by
2114 * table->extra1 (min) and table->extra2 (max).
2116 * Returns 0 on success.
2118 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2120 void __user *buffer,
2121 size_t *lenp, loff_t *ppos)
2123 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2124 lenp, ppos, HZ, 1000l);
2128 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2130 int write, void *data)
2133 if (*lvalp > LONG_MAX / HZ)
2135 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2141 lval = (unsigned long)-val;
2144 lval = (unsigned long)val;
2151 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2153 int write, void *data)
2156 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2158 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2164 lval = (unsigned long)-val;
2167 lval = (unsigned long)val;
2169 *lvalp = jiffies_to_clock_t(lval);
2174 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2176 int write, void *data)
2179 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2185 lval = (unsigned long)-val;
2188 lval = (unsigned long)val;
2190 *lvalp = jiffies_to_msecs(lval);
2196 * proc_dointvec_jiffies - read a vector of integers as seconds
2197 * @table: the sysctl table
2198 * @write: %TRUE if this is a write to the sysctl file
2199 * @filp: the file structure
2200 * @buffer: the user buffer
2201 * @lenp: the size of the user buffer
2202 * @ppos: file position
2204 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2205 * values from/to the user buffer, treated as an ASCII string.
2206 * The values read are assumed to be in seconds, and are converted into
2209 * Returns 0 on success.
2211 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2212 void __user *buffer, size_t *lenp, loff_t *ppos)
2214 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2215 do_proc_dointvec_jiffies_conv,NULL);
2219 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2220 * @table: the sysctl table
2221 * @write: %TRUE if this is a write to the sysctl file
2222 * @filp: the file structure
2223 * @buffer: the user buffer
2224 * @lenp: the size of the user buffer
2225 * @ppos: pointer to the file position
2227 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2228 * values from/to the user buffer, treated as an ASCII string.
2229 * The values read are assumed to be in 1/USER_HZ seconds, and
2230 * are converted into jiffies.
2232 * Returns 0 on success.
2234 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2235 void __user *buffer, size_t *lenp, loff_t *ppos)
2237 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2238 do_proc_dointvec_userhz_jiffies_conv,NULL);
2242 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2243 * @table: the sysctl table
2244 * @write: %TRUE if this is a write to the sysctl file
2245 * @filp: the file structure
2246 * @buffer: the user buffer
2247 * @lenp: the size of the user buffer
2248 * @ppos: file position
2249 * @ppos: the current position in the file
2251 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2252 * values from/to the user buffer, treated as an ASCII string.
2253 * The values read are assumed to be in 1/1000 seconds, and
2254 * are converted into jiffies.
2256 * Returns 0 on success.
2258 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2259 void __user *buffer, size_t *lenp, loff_t *ppos)
2261 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2262 do_proc_dointvec_ms_jiffies_conv, NULL);
2265 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2266 void __user *buffer, size_t *lenp, loff_t *ppos)
2268 struct pid *new_pid;
2272 tmp = pid_nr(cad_pid);
2274 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2275 lenp, ppos, NULL, NULL);
2279 new_pid = find_get_pid(tmp);
2283 put_pid(xchg(&cad_pid, new_pid));
2287 #else /* CONFIG_PROC_FS */
2289 int proc_dostring(ctl_table *table, int write, struct file *filp,
2290 void __user *buffer, size_t *lenp, loff_t *ppos)
2295 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2296 void __user *buffer, size_t *lenp, loff_t *ppos)
2301 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2302 void __user *buffer, size_t *lenp, loff_t *ppos)
2307 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2308 void __user *buffer, size_t *lenp, loff_t *ppos)
2313 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2314 void __user *buffer, size_t *lenp, loff_t *ppos)
2319 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2320 void __user *buffer, size_t *lenp, loff_t *ppos)
2325 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2326 void __user *buffer, size_t *lenp, loff_t *ppos)
2331 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2332 void __user *buffer, size_t *lenp, loff_t *ppos)
2337 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2339 void __user *buffer,
2340 size_t *lenp, loff_t *ppos)
2346 #endif /* CONFIG_PROC_FS */
2349 #ifdef CONFIG_SYSCTL_SYSCALL
2351 * General sysctl support routines
2354 /* The generic string strategy routine: */
2355 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2356 void __user *oldval, size_t __user *oldlenp,
2357 void __user *newval, size_t newlen)
2359 if (!table->data || !table->maxlen)
2362 if (oldval && oldlenp) {
2364 if (get_user(bufsize, oldlenp))
2367 size_t len = strlen(table->data), copied;
2369 /* This shouldn't trigger for a well-formed sysctl */
2370 if (len > table->maxlen)
2371 len = table->maxlen;
2373 /* Copy up to a max of bufsize-1 bytes of the string */
2374 copied = (len >= bufsize) ? bufsize - 1 : len;
2376 if (copy_to_user(oldval, table->data, copied) ||
2377 put_user(0, (char __user *)(oldval + copied)))
2379 if (put_user(len, oldlenp))
2383 if (newval && newlen) {
2384 size_t len = newlen;
2385 if (len > table->maxlen)
2386 len = table->maxlen;
2387 if(copy_from_user(table->data, newval, len))
2389 if (len == table->maxlen)
2391 ((char *) table->data)[len] = 0;
2397 * This function makes sure that all of the integers in the vector
2398 * are between the minimum and maximum values given in the arrays
2399 * table->extra1 and table->extra2, respectively.
2401 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2402 void __user *oldval, size_t __user *oldlenp,
2403 void __user *newval, size_t newlen)
2406 if (newval && newlen) {
2407 int __user *vec = (int __user *) newval;
2408 int *min = (int *) table->extra1;
2409 int *max = (int *) table->extra2;
2413 if (newlen % sizeof(int) != 0)
2416 if (!table->extra1 && !table->extra2)
2419 if (newlen > table->maxlen)
2420 newlen = table->maxlen;
2421 length = newlen / sizeof(int);
2423 for (i = 0; i < length; i++) {
2425 if (get_user(value, vec + i))
2427 if (min && value < min[i])
2429 if (max && value > max[i])
2436 /* Strategy function to convert jiffies to seconds */
2437 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2438 void __user *oldval, size_t __user *oldlenp,
2439 void __user *newval, size_t newlen)
2441 if (oldval && oldlenp) {
2444 if (get_user(olen, oldlenp))
2449 if (olen < sizeof(int))
2452 val = *(int *)(table->data) / HZ;
2453 if (put_user(val, (int __user *)oldval))
2455 if (put_user(sizeof(int), oldlenp))
2459 if (newval && newlen) {
2461 if (newlen != sizeof(int))
2463 if (get_user(new, (int __user *)newval))
2465 *(int *)(table->data) = new*HZ;
2470 /* Strategy function to convert jiffies to seconds */
2471 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2472 void __user *oldval, size_t __user *oldlenp,
2473 void __user *newval, size_t newlen)
2475 if (oldval && oldlenp) {
2478 if (get_user(olen, oldlenp))
2483 if (olen < sizeof(int))
2486 val = jiffies_to_msecs(*(int *)(table->data));
2487 if (put_user(val, (int __user *)oldval))
2489 if (put_user(sizeof(int), oldlenp))
2493 if (newval && newlen) {
2495 if (newlen != sizeof(int))
2497 if (get_user(new, (int __user *)newval))
2499 *(int *)(table->data) = msecs_to_jiffies(new);
2506 #else /* CONFIG_SYSCTL_SYSCALL */
2509 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2511 static int msg_count;
2512 struct __sysctl_args tmp;
2513 int name[CTL_MAXNAME];
2516 /* Read in the sysctl name for better debug message logging */
2517 if (copy_from_user(&tmp, args, sizeof(tmp)))
2519 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2521 for (i = 0; i < tmp.nlen; i++)
2522 if (get_user(name[i], tmp.name + i))
2525 /* Ignore accesses to kernel.version */
2526 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2529 if (msg_count < 5) {
2532 "warning: process `%s' used the removed sysctl "
2533 "system call with ", current->comm);
2534 for (i = 0; i < tmp.nlen; i++)
2535 printk("%d.", name[i]);
2542 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2543 void __user *oldval, size_t __user *oldlenp,
2544 void __user *newval, size_t newlen)
2549 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2550 void __user *oldval, size_t __user *oldlenp,
2551 void __user *newval, size_t newlen)
2556 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2557 void __user *oldval, size_t __user *oldlenp,
2558 void __user *newval, size_t newlen)
2563 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2564 void __user *oldval, size_t __user *oldlenp,
2565 void __user *newval, size_t newlen)
2570 #endif /* CONFIG_SYSCTL_SYSCALL */
2573 * No sense putting this after each symbol definition, twice,
2574 * exception granted :-)
2576 EXPORT_SYMBOL(proc_dointvec);
2577 EXPORT_SYMBOL(proc_dointvec_jiffies);
2578 EXPORT_SYMBOL(proc_dointvec_minmax);
2579 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2580 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2581 EXPORT_SYMBOL(proc_dostring);
2582 EXPORT_SYMBOL(proc_doulongvec_minmax);
2583 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2584 EXPORT_SYMBOL(register_sysctl_table);
2585 EXPORT_SYMBOL(sysctl_intvec);
2586 EXPORT_SYMBOL(sysctl_jiffies);
2587 EXPORT_SYMBOL(sysctl_ms_jiffies);
2588 EXPORT_SYMBOL(sysctl_string);
2589 EXPORT_SYMBOL(unregister_sysctl_table);