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_child_runs_first",
270 .data = &sysctl_sched_child_runs_first,
271 .maxlen = sizeof(unsigned int),
273 .proc_handler = &proc_dointvec,
276 .ctl_name = CTL_UNNUMBERED,
277 .procname = "sched_features",
278 .data = &sysctl_sched_features,
279 .maxlen = sizeof(unsigned int),
281 .proc_handler = &proc_dointvec,
285 .ctl_name = CTL_UNNUMBERED,
286 .procname = "sched_compat_yield",
287 .data = &sysctl_sched_compat_yield,
288 .maxlen = sizeof(unsigned int),
290 .proc_handler = &proc_dointvec,
292 #ifdef CONFIG_PROVE_LOCKING
294 .ctl_name = CTL_UNNUMBERED,
295 .procname = "prove_locking",
296 .data = &prove_locking,
297 .maxlen = sizeof(int),
299 .proc_handler = &proc_dointvec,
302 #ifdef CONFIG_LOCK_STAT
304 .ctl_name = CTL_UNNUMBERED,
305 .procname = "lock_stat",
307 .maxlen = sizeof(int),
309 .proc_handler = &proc_dointvec,
313 .ctl_name = KERN_PANIC,
315 .data = &panic_timeout,
316 .maxlen = sizeof(int),
318 .proc_handler = &proc_dointvec,
321 .ctl_name = KERN_CORE_USES_PID,
322 .procname = "core_uses_pid",
323 .data = &core_uses_pid,
324 .maxlen = sizeof(int),
326 .proc_handler = &proc_dointvec,
328 #ifdef CONFIG_AUDITSYSCALL
330 .ctl_name = CTL_UNNUMBERED,
331 .procname = "audit_argv_kb",
332 .data = &audit_argv_kb,
333 .maxlen = sizeof(int),
335 .proc_handler = &proc_dointvec,
339 .ctl_name = KERN_CORE_PATTERN,
340 .procname = "core_pattern",
341 .data = core_pattern,
342 .maxlen = CORENAME_MAX_SIZE,
344 .proc_handler = &proc_dostring,
345 .strategy = &sysctl_string,
347 #ifdef CONFIG_PROC_SYSCTL
349 .ctl_name = KERN_TAINTED,
350 .procname = "tainted",
352 .maxlen = sizeof(int),
354 .proc_handler = &proc_dointvec_taint,
358 .ctl_name = KERN_CAP_BSET,
359 .procname = "cap-bound",
361 .maxlen = sizeof(kernel_cap_t),
363 .proc_handler = &proc_dointvec_bset,
365 #ifdef CONFIG_BLK_DEV_INITRD
367 .ctl_name = KERN_REALROOTDEV,
368 .procname = "real-root-dev",
369 .data = &real_root_dev,
370 .maxlen = sizeof(int),
372 .proc_handler = &proc_dointvec,
376 .ctl_name = CTL_UNNUMBERED,
377 .procname = "print-fatal-signals",
378 .data = &print_fatal_signals,
379 .maxlen = sizeof(int),
381 .proc_handler = &proc_dointvec,
385 .ctl_name = KERN_SPARC_REBOOT,
386 .procname = "reboot-cmd",
387 .data = reboot_command,
390 .proc_handler = &proc_dostring,
391 .strategy = &sysctl_string,
394 .ctl_name = KERN_SPARC_STOP_A,
395 .procname = "stop-a",
396 .data = &stop_a_enabled,
397 .maxlen = sizeof (int),
399 .proc_handler = &proc_dointvec,
402 .ctl_name = KERN_SPARC_SCONS_PWROFF,
403 .procname = "scons-poweroff",
404 .data = &scons_pwroff,
405 .maxlen = sizeof (int),
407 .proc_handler = &proc_dointvec,
412 .ctl_name = KERN_HPPA_PWRSW,
413 .procname = "soft-power",
414 .data = &pwrsw_enabled,
415 .maxlen = sizeof (int),
417 .proc_handler = &proc_dointvec,
420 .ctl_name = KERN_HPPA_UNALIGNED,
421 .procname = "unaligned-trap",
422 .data = &unaligned_enabled,
423 .maxlen = sizeof (int),
425 .proc_handler = &proc_dointvec,
429 .ctl_name = KERN_CTLALTDEL,
430 .procname = "ctrl-alt-del",
432 .maxlen = sizeof(int),
434 .proc_handler = &proc_dointvec,
437 .ctl_name = KERN_PRINTK,
438 .procname = "printk",
439 .data = &console_loglevel,
440 .maxlen = 4*sizeof(int),
442 .proc_handler = &proc_dointvec,
446 .ctl_name = KERN_MODPROBE,
447 .procname = "modprobe",
448 .data = &modprobe_path,
449 .maxlen = KMOD_PATH_LEN,
451 .proc_handler = &proc_dostring,
452 .strategy = &sysctl_string,
455 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
457 .ctl_name = KERN_HOTPLUG,
458 .procname = "hotplug",
459 .data = &uevent_helper,
460 .maxlen = UEVENT_HELPER_PATH_LEN,
462 .proc_handler = &proc_dostring,
463 .strategy = &sysctl_string,
466 #ifdef CONFIG_CHR_DEV_SG
468 .ctl_name = KERN_SG_BIG_BUFF,
469 .procname = "sg-big-buff",
470 .data = &sg_big_buff,
471 .maxlen = sizeof (int),
473 .proc_handler = &proc_dointvec,
476 #ifdef CONFIG_BSD_PROCESS_ACCT
478 .ctl_name = KERN_ACCT,
481 .maxlen = 3*sizeof(int),
483 .proc_handler = &proc_dointvec,
486 #ifdef CONFIG_MAGIC_SYSRQ
488 .ctl_name = KERN_SYSRQ,
490 .data = &__sysrq_enabled,
491 .maxlen = sizeof (int),
493 .proc_handler = &proc_dointvec,
496 #ifdef CONFIG_PROC_SYSCTL
498 .ctl_name = KERN_CADPID,
499 .procname = "cad_pid",
501 .maxlen = sizeof (int),
503 .proc_handler = &proc_do_cad_pid,
507 .ctl_name = KERN_MAX_THREADS,
508 .procname = "threads-max",
509 .data = &max_threads,
510 .maxlen = sizeof(int),
512 .proc_handler = &proc_dointvec,
515 .ctl_name = KERN_RANDOM,
516 .procname = "random",
518 .child = random_table,
520 #ifdef CONFIG_UNIX98_PTYS
522 .ctl_name = KERN_PTY,
529 .ctl_name = KERN_OVERFLOWUID,
530 .procname = "overflowuid",
531 .data = &overflowuid,
532 .maxlen = sizeof(int),
534 .proc_handler = &proc_dointvec_minmax,
535 .strategy = &sysctl_intvec,
536 .extra1 = &minolduid,
537 .extra2 = &maxolduid,
540 .ctl_name = KERN_OVERFLOWGID,
541 .procname = "overflowgid",
542 .data = &overflowgid,
543 .maxlen = sizeof(int),
545 .proc_handler = &proc_dointvec_minmax,
546 .strategy = &sysctl_intvec,
547 .extra1 = &minolduid,
548 .extra2 = &maxolduid,
551 #ifdef CONFIG_MATHEMU
553 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
554 .procname = "ieee_emulation_warnings",
555 .data = &sysctl_ieee_emulation_warnings,
556 .maxlen = sizeof(int),
558 .proc_handler = &proc_dointvec,
561 #ifdef CONFIG_NO_IDLE_HZ
563 .ctl_name = KERN_HZ_TIMER,
564 .procname = "hz_timer",
565 .data = &sysctl_hz_timer,
566 .maxlen = sizeof(int),
568 .proc_handler = &proc_dointvec,
572 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
573 .procname = "userprocess_debug",
574 .data = &sysctl_userprocess_debug,
575 .maxlen = sizeof(int),
577 .proc_handler = &proc_dointvec,
581 .ctl_name = KERN_PIDMAX,
582 .procname = "pid_max",
584 .maxlen = sizeof (int),
586 .proc_handler = &proc_dointvec_minmax,
587 .strategy = sysctl_intvec,
588 .extra1 = &pid_max_min,
589 .extra2 = &pid_max_max,
592 .ctl_name = KERN_PANIC_ON_OOPS,
593 .procname = "panic_on_oops",
594 .data = &panic_on_oops,
595 .maxlen = sizeof(int),
597 .proc_handler = &proc_dointvec,
600 .ctl_name = KERN_PRINTK_RATELIMIT,
601 .procname = "printk_ratelimit",
602 .data = &printk_ratelimit_jiffies,
603 .maxlen = sizeof(int),
605 .proc_handler = &proc_dointvec_jiffies,
606 .strategy = &sysctl_jiffies,
609 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
610 .procname = "printk_ratelimit_burst",
611 .data = &printk_ratelimit_burst,
612 .maxlen = sizeof(int),
614 .proc_handler = &proc_dointvec,
617 .ctl_name = KERN_NGROUPS_MAX,
618 .procname = "ngroups_max",
619 .data = &ngroups_max,
620 .maxlen = sizeof (int),
622 .proc_handler = &proc_dointvec,
624 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
626 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
627 .procname = "unknown_nmi_panic",
628 .data = &unknown_nmi_panic,
629 .maxlen = sizeof (int),
631 .proc_handler = &proc_dointvec,
634 .ctl_name = KERN_NMI_WATCHDOG,
635 .procname = "nmi_watchdog",
636 .data = &nmi_watchdog_enabled,
637 .maxlen = sizeof (int),
639 .proc_handler = &proc_nmi_enabled,
642 #if defined(CONFIG_X86)
644 .ctl_name = KERN_PANIC_ON_NMI,
645 .procname = "panic_on_unrecovered_nmi",
646 .data = &panic_on_unrecovered_nmi,
647 .maxlen = sizeof(int),
649 .proc_handler = &proc_dointvec,
652 .ctl_name = KERN_BOOTLOADER_TYPE,
653 .procname = "bootloader_type",
654 .data = &bootloader_type,
655 .maxlen = sizeof (int),
657 .proc_handler = &proc_dointvec,
660 .ctl_name = CTL_UNNUMBERED,
661 .procname = "kstack_depth_to_print",
662 .data = &kstack_depth_to_print,
663 .maxlen = sizeof(int),
665 .proc_handler = &proc_dointvec,
668 #if defined(CONFIG_MMU)
670 .ctl_name = KERN_RANDOMIZE,
671 .procname = "randomize_va_space",
672 .data = &randomize_va_space,
673 .maxlen = sizeof(int),
675 .proc_handler = &proc_dointvec,
678 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
680 .ctl_name = KERN_SPIN_RETRY,
681 .procname = "spin_retry",
683 .maxlen = sizeof (int),
685 .proc_handler = &proc_dointvec,
688 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
690 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
691 .procname = "acpi_video_flags",
692 .data = &acpi_realmode_flags,
693 .maxlen = sizeof (unsigned long),
695 .proc_handler = &proc_doulongvec_minmax,
700 .ctl_name = KERN_IA64_UNALIGNED,
701 .procname = "ignore-unaligned-usertrap",
702 .data = &no_unaligned_warning,
703 .maxlen = sizeof (int),
705 .proc_handler = &proc_dointvec,
710 .ctl_name = KERN_COMPAT_LOG,
711 .procname = "compat-log",
713 .maxlen = sizeof (int),
715 .proc_handler = &proc_dointvec,
718 #ifdef CONFIG_RT_MUTEXES
720 .ctl_name = KERN_MAX_LOCK_DEPTH,
721 .procname = "max_lock_depth",
722 .data = &max_lock_depth,
723 .maxlen = sizeof(int),
725 .proc_handler = &proc_dointvec,
728 #ifdef CONFIG_PROC_FS
730 .ctl_name = CTL_UNNUMBERED,
731 .procname = "maps_protect",
732 .data = &maps_protect,
733 .maxlen = sizeof(int),
735 .proc_handler = &proc_dointvec,
739 .ctl_name = CTL_UNNUMBERED,
740 .procname = "poweroff_cmd",
741 .data = &poweroff_cmd,
742 .maxlen = POWEROFF_CMD_PATH_LEN,
744 .proc_handler = &proc_dostring,
745 .strategy = &sysctl_string,
748 * NOTE: do not add new entries to this table unless you have read
749 * Documentation/sysctl/ctl_unnumbered.txt
754 /* Constants for minimum and maximum testing in vm_table.
755 We use these as one-element integer vectors. */
758 static int one_hundred = 100;
761 static ctl_table vm_table[] = {
763 .ctl_name = VM_OVERCOMMIT_MEMORY,
764 .procname = "overcommit_memory",
765 .data = &sysctl_overcommit_memory,
766 .maxlen = sizeof(sysctl_overcommit_memory),
768 .proc_handler = &proc_dointvec,
771 .ctl_name = VM_PANIC_ON_OOM,
772 .procname = "panic_on_oom",
773 .data = &sysctl_panic_on_oom,
774 .maxlen = sizeof(sysctl_panic_on_oom),
776 .proc_handler = &proc_dointvec,
779 .ctl_name = VM_OVERCOMMIT_RATIO,
780 .procname = "overcommit_ratio",
781 .data = &sysctl_overcommit_ratio,
782 .maxlen = sizeof(sysctl_overcommit_ratio),
784 .proc_handler = &proc_dointvec,
787 .ctl_name = VM_PAGE_CLUSTER,
788 .procname = "page-cluster",
789 .data = &page_cluster,
790 .maxlen = sizeof(int),
792 .proc_handler = &proc_dointvec,
795 .ctl_name = VM_DIRTY_BACKGROUND,
796 .procname = "dirty_background_ratio",
797 .data = &dirty_background_ratio,
798 .maxlen = sizeof(dirty_background_ratio),
800 .proc_handler = &proc_dointvec_minmax,
801 .strategy = &sysctl_intvec,
803 .extra2 = &one_hundred,
806 .ctl_name = VM_DIRTY_RATIO,
807 .procname = "dirty_ratio",
808 .data = &vm_dirty_ratio,
809 .maxlen = sizeof(vm_dirty_ratio),
811 .proc_handler = &proc_dointvec_minmax,
812 .strategy = &sysctl_intvec,
814 .extra2 = &one_hundred,
817 .ctl_name = VM_DIRTY_WB_CS,
818 .procname = "dirty_writeback_centisecs",
819 .data = &dirty_writeback_interval,
820 .maxlen = sizeof(dirty_writeback_interval),
822 .proc_handler = &dirty_writeback_centisecs_handler,
825 .ctl_name = VM_DIRTY_EXPIRE_CS,
826 .procname = "dirty_expire_centisecs",
827 .data = &dirty_expire_interval,
828 .maxlen = sizeof(dirty_expire_interval),
830 .proc_handler = &proc_dointvec_userhz_jiffies,
833 .ctl_name = VM_NR_PDFLUSH_THREADS,
834 .procname = "nr_pdflush_threads",
835 .data = &nr_pdflush_threads,
836 .maxlen = sizeof nr_pdflush_threads,
837 .mode = 0444 /* read-only*/,
838 .proc_handler = &proc_dointvec,
841 .ctl_name = VM_SWAPPINESS,
842 .procname = "swappiness",
843 .data = &vm_swappiness,
844 .maxlen = sizeof(vm_swappiness),
846 .proc_handler = &proc_dointvec_minmax,
847 .strategy = &sysctl_intvec,
849 .extra2 = &one_hundred,
851 #ifdef CONFIG_HUGETLB_PAGE
853 .ctl_name = VM_HUGETLB_PAGES,
854 .procname = "nr_hugepages",
855 .data = &max_huge_pages,
856 .maxlen = sizeof(unsigned long),
858 .proc_handler = &hugetlb_sysctl_handler,
859 .extra1 = (void *)&hugetlb_zero,
860 .extra2 = (void *)&hugetlb_infinity,
863 .ctl_name = VM_HUGETLB_GROUP,
864 .procname = "hugetlb_shm_group",
865 .data = &sysctl_hugetlb_shm_group,
866 .maxlen = sizeof(gid_t),
868 .proc_handler = &proc_dointvec,
871 .ctl_name = CTL_UNNUMBERED,
872 .procname = "hugepages_treat_as_movable",
873 .data = &hugepages_treat_as_movable,
874 .maxlen = sizeof(int),
876 .proc_handler = &hugetlb_treat_movable_handler,
880 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
881 .procname = "lowmem_reserve_ratio",
882 .data = &sysctl_lowmem_reserve_ratio,
883 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
885 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
886 .strategy = &sysctl_intvec,
889 .ctl_name = VM_DROP_PAGECACHE,
890 .procname = "drop_caches",
891 .data = &sysctl_drop_caches,
892 .maxlen = sizeof(int),
894 .proc_handler = drop_caches_sysctl_handler,
895 .strategy = &sysctl_intvec,
898 .ctl_name = VM_MIN_FREE_KBYTES,
899 .procname = "min_free_kbytes",
900 .data = &min_free_kbytes,
901 .maxlen = sizeof(min_free_kbytes),
903 .proc_handler = &min_free_kbytes_sysctl_handler,
904 .strategy = &sysctl_intvec,
908 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
909 .procname = "percpu_pagelist_fraction",
910 .data = &percpu_pagelist_fraction,
911 .maxlen = sizeof(percpu_pagelist_fraction),
913 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
914 .strategy = &sysctl_intvec,
915 .extra1 = &min_percpu_pagelist_fract,
919 .ctl_name = VM_MAX_MAP_COUNT,
920 .procname = "max_map_count",
921 .data = &sysctl_max_map_count,
922 .maxlen = sizeof(sysctl_max_map_count),
924 .proc_handler = &proc_dointvec
928 .ctl_name = VM_LAPTOP_MODE,
929 .procname = "laptop_mode",
930 .data = &laptop_mode,
931 .maxlen = sizeof(laptop_mode),
933 .proc_handler = &proc_dointvec_jiffies,
934 .strategy = &sysctl_jiffies,
937 .ctl_name = VM_BLOCK_DUMP,
938 .procname = "block_dump",
940 .maxlen = sizeof(block_dump),
942 .proc_handler = &proc_dointvec,
943 .strategy = &sysctl_intvec,
947 .ctl_name = VM_VFS_CACHE_PRESSURE,
948 .procname = "vfs_cache_pressure",
949 .data = &sysctl_vfs_cache_pressure,
950 .maxlen = sizeof(sysctl_vfs_cache_pressure),
952 .proc_handler = &proc_dointvec,
953 .strategy = &sysctl_intvec,
956 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
958 .ctl_name = VM_LEGACY_VA_LAYOUT,
959 .procname = "legacy_va_layout",
960 .data = &sysctl_legacy_va_layout,
961 .maxlen = sizeof(sysctl_legacy_va_layout),
963 .proc_handler = &proc_dointvec,
964 .strategy = &sysctl_intvec,
970 .ctl_name = VM_ZONE_RECLAIM_MODE,
971 .procname = "zone_reclaim_mode",
972 .data = &zone_reclaim_mode,
973 .maxlen = sizeof(zone_reclaim_mode),
975 .proc_handler = &proc_dointvec,
976 .strategy = &sysctl_intvec,
980 .ctl_name = VM_MIN_UNMAPPED,
981 .procname = "min_unmapped_ratio",
982 .data = &sysctl_min_unmapped_ratio,
983 .maxlen = sizeof(sysctl_min_unmapped_ratio),
985 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
986 .strategy = &sysctl_intvec,
988 .extra2 = &one_hundred,
991 .ctl_name = VM_MIN_SLAB,
992 .procname = "min_slab_ratio",
993 .data = &sysctl_min_slab_ratio,
994 .maxlen = sizeof(sysctl_min_slab_ratio),
996 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
997 .strategy = &sysctl_intvec,
999 .extra2 = &one_hundred,
1004 .ctl_name = CTL_UNNUMBERED,
1005 .procname = "stat_interval",
1006 .data = &sysctl_stat_interval,
1007 .maxlen = sizeof(sysctl_stat_interval),
1009 .proc_handler = &proc_dointvec_jiffies,
1010 .strategy = &sysctl_jiffies,
1013 #ifdef CONFIG_SECURITY
1015 .ctl_name = CTL_UNNUMBERED,
1016 .procname = "mmap_min_addr",
1017 .data = &mmap_min_addr,
1018 .maxlen = sizeof(unsigned long),
1020 .proc_handler = &proc_doulongvec_minmax,
1025 .ctl_name = CTL_UNNUMBERED,
1026 .procname = "numa_zonelist_order",
1027 .data = &numa_zonelist_order,
1028 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1030 .proc_handler = &numa_zonelist_order_handler,
1031 .strategy = &sysctl_string,
1034 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1035 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1037 .ctl_name = VM_VDSO_ENABLED,
1038 .procname = "vdso_enabled",
1039 .data = &vdso_enabled,
1040 .maxlen = sizeof(vdso_enabled),
1042 .proc_handler = &proc_dointvec,
1043 .strategy = &sysctl_intvec,
1048 * NOTE: do not add new entries to this table unless you have read
1049 * Documentation/sysctl/ctl_unnumbered.txt
1054 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1055 static ctl_table binfmt_misc_table[] = {
1060 static ctl_table fs_table[] = {
1062 .ctl_name = FS_NRINODE,
1063 .procname = "inode-nr",
1064 .data = &inodes_stat,
1065 .maxlen = 2*sizeof(int),
1067 .proc_handler = &proc_dointvec,
1070 .ctl_name = FS_STATINODE,
1071 .procname = "inode-state",
1072 .data = &inodes_stat,
1073 .maxlen = 7*sizeof(int),
1075 .proc_handler = &proc_dointvec,
1078 .ctl_name = FS_NRFILE,
1079 .procname = "file-nr",
1080 .data = &files_stat,
1081 .maxlen = 3*sizeof(int),
1083 .proc_handler = &proc_nr_files,
1086 .ctl_name = FS_MAXFILE,
1087 .procname = "file-max",
1088 .data = &files_stat.max_files,
1089 .maxlen = sizeof(int),
1091 .proc_handler = &proc_dointvec,
1094 .ctl_name = FS_DENTRY,
1095 .procname = "dentry-state",
1096 .data = &dentry_stat,
1097 .maxlen = 6*sizeof(int),
1099 .proc_handler = &proc_dointvec,
1102 .ctl_name = FS_OVERFLOWUID,
1103 .procname = "overflowuid",
1104 .data = &fs_overflowuid,
1105 .maxlen = sizeof(int),
1107 .proc_handler = &proc_dointvec_minmax,
1108 .strategy = &sysctl_intvec,
1109 .extra1 = &minolduid,
1110 .extra2 = &maxolduid,
1113 .ctl_name = FS_OVERFLOWGID,
1114 .procname = "overflowgid",
1115 .data = &fs_overflowgid,
1116 .maxlen = sizeof(int),
1118 .proc_handler = &proc_dointvec_minmax,
1119 .strategy = &sysctl_intvec,
1120 .extra1 = &minolduid,
1121 .extra2 = &maxolduid,
1124 .ctl_name = FS_LEASES,
1125 .procname = "leases-enable",
1126 .data = &leases_enable,
1127 .maxlen = sizeof(int),
1129 .proc_handler = &proc_dointvec,
1131 #ifdef CONFIG_DNOTIFY
1133 .ctl_name = FS_DIR_NOTIFY,
1134 .procname = "dir-notify-enable",
1135 .data = &dir_notify_enable,
1136 .maxlen = sizeof(int),
1138 .proc_handler = &proc_dointvec,
1143 .ctl_name = FS_LEASE_TIME,
1144 .procname = "lease-break-time",
1145 .data = &lease_break_time,
1146 .maxlen = sizeof(int),
1148 .proc_handler = &proc_dointvec_minmax,
1149 .strategy = &sysctl_intvec,
1154 .ctl_name = FS_AIO_NR,
1155 .procname = "aio-nr",
1157 .maxlen = sizeof(aio_nr),
1159 .proc_handler = &proc_doulongvec_minmax,
1162 .ctl_name = FS_AIO_MAX_NR,
1163 .procname = "aio-max-nr",
1164 .data = &aio_max_nr,
1165 .maxlen = sizeof(aio_max_nr),
1167 .proc_handler = &proc_doulongvec_minmax,
1169 #ifdef CONFIG_INOTIFY_USER
1171 .ctl_name = FS_INOTIFY,
1172 .procname = "inotify",
1174 .child = inotify_table,
1179 .ctl_name = KERN_SETUID_DUMPABLE,
1180 .procname = "suid_dumpable",
1181 .data = &suid_dumpable,
1182 .maxlen = sizeof(int),
1184 .proc_handler = &proc_dointvec,
1186 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1188 .ctl_name = CTL_UNNUMBERED,
1189 .procname = "binfmt_misc",
1191 .child = binfmt_misc_table,
1195 * NOTE: do not add new entries to this table unless you have read
1196 * Documentation/sysctl/ctl_unnumbered.txt
1201 static ctl_table debug_table[] = {
1202 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1204 .ctl_name = CTL_UNNUMBERED,
1205 .procname = "exception-trace",
1206 .data = &show_unhandled_signals,
1207 .maxlen = sizeof(int),
1209 .proc_handler = proc_dointvec
1215 static ctl_table dev_table[] = {
1219 static DEFINE_SPINLOCK(sysctl_lock);
1221 /* called under sysctl_lock */
1222 static int use_table(struct ctl_table_header *p)
1224 if (unlikely(p->unregistering))
1230 /* called under sysctl_lock */
1231 static void unuse_table(struct ctl_table_header *p)
1234 if (unlikely(p->unregistering))
1235 complete(p->unregistering);
1238 /* called under sysctl_lock, will reacquire if has to wait */
1239 static void start_unregistering(struct ctl_table_header *p)
1242 * if p->used is 0, nobody will ever touch that entry again;
1243 * we'll eliminate all paths to it before dropping sysctl_lock
1245 if (unlikely(p->used)) {
1246 struct completion wait;
1247 init_completion(&wait);
1248 p->unregistering = &wait;
1249 spin_unlock(&sysctl_lock);
1250 wait_for_completion(&wait);
1251 spin_lock(&sysctl_lock);
1254 * do not remove from the list until nobody holds it; walking the
1255 * list in do_sysctl() relies on that.
1257 list_del_init(&p->ctl_entry);
1260 void sysctl_head_finish(struct ctl_table_header *head)
1264 spin_lock(&sysctl_lock);
1266 spin_unlock(&sysctl_lock);
1269 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1271 struct ctl_table_header *head;
1272 struct list_head *tmp;
1273 spin_lock(&sysctl_lock);
1275 tmp = &prev->ctl_entry;
1279 tmp = &root_table_header.ctl_entry;
1281 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1283 if (!use_table(head))
1285 spin_unlock(&sysctl_lock);
1289 if (tmp == &root_table_header.ctl_entry)
1292 spin_unlock(&sysctl_lock);
1296 #ifdef CONFIG_SYSCTL_SYSCALL
1297 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1298 void __user *newval, size_t newlen)
1300 struct ctl_table_header *head;
1301 int error = -ENOTDIR;
1303 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1307 if (!oldlenp || get_user(old_len, oldlenp))
1311 for (head = sysctl_head_next(NULL); head;
1312 head = sysctl_head_next(head)) {
1313 error = parse_table(name, nlen, oldval, oldlenp,
1314 newval, newlen, head->ctl_table);
1315 if (error != -ENOTDIR) {
1316 sysctl_head_finish(head);
1323 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1325 struct __sysctl_args tmp;
1328 if (copy_from_user(&tmp, args, sizeof(tmp)))
1332 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1333 tmp.newval, tmp.newlen);
1337 #endif /* CONFIG_SYSCTL_SYSCALL */
1340 * sysctl_perm does NOT grant the superuser all rights automatically, because
1341 * some sysctl variables are readonly even to root.
1344 static int test_perm(int mode, int op)
1348 else if (in_egroup_p(0))
1350 if ((mode & op & 0007) == op)
1355 int sysctl_perm(ctl_table *table, int op)
1358 error = security_sysctl(table, op);
1361 return test_perm(table->mode, op);
1364 #ifdef CONFIG_SYSCTL_SYSCALL
1365 static int parse_table(int __user *name, int nlen,
1366 void __user *oldval, size_t __user *oldlenp,
1367 void __user *newval, size_t newlen,
1374 if (get_user(n, name))
1376 for ( ; table->ctl_name || table->procname; table++) {
1377 if (!table->ctl_name)
1379 if (n == table->ctl_name) {
1382 if (sysctl_perm(table, 001))
1386 table = table->child;
1389 error = do_sysctl_strategy(table, name, nlen,
1398 /* Perform the actual read/write of a sysctl table entry. */
1399 int do_sysctl_strategy (ctl_table *table,
1400 int __user *name, int nlen,
1401 void __user *oldval, size_t __user *oldlenp,
1402 void __user *newval, size_t newlen)
1411 if (sysctl_perm(table, op))
1414 if (table->strategy) {
1415 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1423 /* If there is no strategy routine, or if the strategy returns
1424 * zero, proceed with automatic r/w */
1425 if (table->data && table->maxlen) {
1426 if (oldval && oldlenp) {
1427 if (get_user(len, oldlenp))
1430 if (len > table->maxlen)
1431 len = table->maxlen;
1432 if(copy_to_user(oldval, table->data, len))
1434 if(put_user(len, oldlenp))
1438 if (newval && newlen) {
1440 if (len > table->maxlen)
1441 len = table->maxlen;
1442 if(copy_from_user(table->data, newval, len))
1448 #endif /* CONFIG_SYSCTL_SYSCALL */
1450 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1452 for (; table->ctl_name || table->procname; table++) {
1453 table->parent = parent;
1455 sysctl_set_parent(table, table->child);
1459 static __init int sysctl_init(void)
1461 sysctl_set_parent(NULL, root_table);
1465 core_initcall(sysctl_init);
1468 * register_sysctl_table - register a sysctl hierarchy
1469 * @table: the top-level table structure
1471 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1472 * array. An entry with a ctl_name of 0 terminates the table.
1474 * The members of the &ctl_table structure are used as follows:
1476 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1477 * must be unique within that level of sysctl
1479 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1480 * enter a sysctl file
1482 * data - a pointer to data for use by proc_handler
1484 * maxlen - the maximum size in bytes of the data
1486 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1488 * child - a pointer to the child sysctl table if this entry is a directory, or
1491 * proc_handler - the text handler routine (described below)
1493 * strategy - the strategy routine (described below)
1495 * de - for internal use by the sysctl routines
1497 * extra1, extra2 - extra pointers usable by the proc handler routines
1499 * Leaf nodes in the sysctl tree will be represented by a single file
1500 * under /proc; non-leaf nodes will be represented by directories.
1502 * sysctl(2) can automatically manage read and write requests through
1503 * the sysctl table. The data and maxlen fields of the ctl_table
1504 * struct enable minimal validation of the values being written to be
1505 * performed, and the mode field allows minimal authentication.
1507 * More sophisticated management can be enabled by the provision of a
1508 * strategy routine with the table entry. This will be called before
1509 * any automatic read or write of the data is performed.
1511 * The strategy routine may return
1513 * < 0 - Error occurred (error is passed to user process)
1515 * 0 - OK - proceed with automatic read or write.
1517 * > 0 - OK - read or write has been done by the strategy routine, so
1518 * return immediately.
1520 * There must be a proc_handler routine for any terminal nodes
1521 * mirrored under /proc/sys (non-terminals are handled by a built-in
1522 * directory handler). Several default handlers are available to
1523 * cover common cases -
1525 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1526 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1527 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1529 * It is the handler's job to read the input buffer from user memory
1530 * and process it. The handler should return 0 on success.
1532 * This routine returns %NULL on a failure to register, and a pointer
1533 * to the table header on success.
1535 struct ctl_table_header *register_sysctl_table(ctl_table * table)
1537 struct ctl_table_header *tmp;
1538 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1541 tmp->ctl_table = table;
1542 INIT_LIST_HEAD(&tmp->ctl_entry);
1544 tmp->unregistering = NULL;
1545 sysctl_set_parent(NULL, table);
1546 spin_lock(&sysctl_lock);
1547 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1548 spin_unlock(&sysctl_lock);
1553 * unregister_sysctl_table - unregister a sysctl table hierarchy
1554 * @header: the header returned from register_sysctl_table
1556 * Unregisters the sysctl table and all children. proc entries may not
1557 * actually be removed until they are no longer used by anyone.
1559 void unregister_sysctl_table(struct ctl_table_header * header)
1562 spin_lock(&sysctl_lock);
1563 start_unregistering(header);
1564 spin_unlock(&sysctl_lock);
1568 #else /* !CONFIG_SYSCTL */
1569 struct ctl_table_header *register_sysctl_table(ctl_table * table)
1574 void unregister_sysctl_table(struct ctl_table_header * table)
1578 #endif /* CONFIG_SYSCTL */
1584 #ifdef CONFIG_PROC_SYSCTL
1586 static int _proc_do_string(void* data, int maxlen, int write,
1587 struct file *filp, void __user *buffer,
1588 size_t *lenp, loff_t *ppos)
1594 if (!data || !maxlen || !*lenp) {
1602 while (len < *lenp) {
1603 if (get_user(c, p++))
1605 if (c == 0 || c == '\n')
1611 if(copy_from_user(data, buffer, len))
1613 ((char *) data)[len] = 0;
1631 if(copy_to_user(buffer, data, len))
1634 if(put_user('\n', ((char __user *) buffer) + len))
1645 * proc_dostring - read a string sysctl
1646 * @table: the sysctl table
1647 * @write: %TRUE if this is a write to the sysctl file
1648 * @filp: the file structure
1649 * @buffer: the user buffer
1650 * @lenp: the size of the user buffer
1651 * @ppos: file position
1653 * Reads/writes a string from/to the user buffer. If the kernel
1654 * buffer provided is not large enough to hold the string, the
1655 * string is truncated. The copied string is %NULL-terminated.
1656 * If the string is being read by the user process, it is copied
1657 * and a newline '\n' is added. It is truncated if the buffer is
1660 * Returns 0 on success.
1662 int proc_dostring(ctl_table *table, int write, struct file *filp,
1663 void __user *buffer, size_t *lenp, loff_t *ppos)
1665 return _proc_do_string(table->data, table->maxlen, write, filp,
1666 buffer, lenp, ppos);
1670 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1672 int write, void *data)
1675 *valp = *negp ? -*lvalp : *lvalp;
1680 *lvalp = (unsigned long)-val;
1683 *lvalp = (unsigned long)val;
1689 static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1690 int write, struct file *filp, void __user *buffer,
1691 size_t *lenp, loff_t *ppos,
1692 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1693 int write, void *data),
1696 #define TMPBUFLEN 21
1697 int *i, vleft, first=1, neg, val;
1701 char buf[TMPBUFLEN], *p;
1702 char __user *s = buffer;
1704 if (!tbl_data || !table->maxlen || !*lenp ||
1705 (*ppos && !write)) {
1710 i = (int *) tbl_data;
1711 vleft = table->maxlen / sizeof(*i);
1715 conv = do_proc_dointvec_conv;
1717 for (; left && vleft--; i++, first=0) {
1732 if (len > sizeof(buf) - 1)
1733 len = sizeof(buf) - 1;
1734 if (copy_from_user(buf, s, len))
1738 if (*p == '-' && left > 1) {
1742 if (*p < '0' || *p > '9')
1745 lval = simple_strtoul(p, &p, 0);
1748 if ((len < left) && *p && !isspace(*p))
1755 if (conv(&neg, &lval, i, 1, data))
1762 if (conv(&neg, &lval, i, 0, data))
1765 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1769 if(copy_to_user(s, buf, len))
1776 if (!write && !first && left) {
1777 if(put_user('\n', s))
1784 if (get_user(c, s++))
1799 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1800 void __user *buffer, size_t *lenp, loff_t *ppos,
1801 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1802 int write, void *data),
1805 return __do_proc_dointvec(table->data, table, write, filp,
1806 buffer, lenp, ppos, conv, data);
1810 * proc_dointvec - read a vector of integers
1811 * @table: the sysctl table
1812 * @write: %TRUE if this is a write to the sysctl file
1813 * @filp: the file structure
1814 * @buffer: the user buffer
1815 * @lenp: the size of the user buffer
1816 * @ppos: file position
1818 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1819 * values from/to the user buffer, treated as an ASCII string.
1821 * Returns 0 on success.
1823 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1824 void __user *buffer, size_t *lenp, loff_t *ppos)
1826 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1834 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1836 int write, void *data)
1838 int op = *(int *)data;
1840 int val = *negp ? -*lvalp : *lvalp;
1842 case OP_SET: *valp = val; break;
1843 case OP_AND: *valp &= val; break;
1844 case OP_OR: *valp |= val; break;
1850 *lvalp = (unsigned long)-val;
1853 *lvalp = (unsigned long)val;
1860 * init may raise the set.
1863 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1864 void __user *buffer, size_t *lenp, loff_t *ppos)
1868 if (write && !capable(CAP_SYS_MODULE)) {
1872 op = is_init(current) ? OP_SET : OP_AND;
1873 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1874 do_proc_dointvec_bset_conv,&op);
1878 * Taint values can only be increased
1880 static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
1881 void __user *buffer, size_t *lenp, loff_t *ppos)
1885 if (write && !capable(CAP_SYS_ADMIN))
1889 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1890 do_proc_dointvec_bset_conv,&op);
1893 struct do_proc_dointvec_minmax_conv_param {
1898 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1900 int write, void *data)
1902 struct do_proc_dointvec_minmax_conv_param *param = data;
1904 int val = *negp ? -*lvalp : *lvalp;
1905 if ((param->min && *param->min > val) ||
1906 (param->max && *param->max < val))
1913 *lvalp = (unsigned long)-val;
1916 *lvalp = (unsigned long)val;
1923 * proc_dointvec_minmax - read a vector of integers with min/max values
1924 * @table: the sysctl table
1925 * @write: %TRUE if this is a write to the sysctl file
1926 * @filp: the file structure
1927 * @buffer: the user buffer
1928 * @lenp: the size of the user buffer
1929 * @ppos: file position
1931 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1932 * values from/to the user buffer, treated as an ASCII string.
1934 * This routine will ensure the values are within the range specified by
1935 * table->extra1 (min) and table->extra2 (max).
1937 * Returns 0 on success.
1939 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1940 void __user *buffer, size_t *lenp, loff_t *ppos)
1942 struct do_proc_dointvec_minmax_conv_param param = {
1943 .min = (int *) table->extra1,
1944 .max = (int *) table->extra2,
1946 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1947 do_proc_dointvec_minmax_conv, ¶m);
1950 static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
1952 void __user *buffer,
1953 size_t *lenp, loff_t *ppos,
1954 unsigned long convmul,
1955 unsigned long convdiv)
1957 #define TMPBUFLEN 21
1958 unsigned long *i, *min, *max, val;
1959 int vleft, first=1, neg;
1961 char buf[TMPBUFLEN], *p;
1962 char __user *s = buffer;
1964 if (!data || !table->maxlen || !*lenp ||
1965 (*ppos && !write)) {
1970 i = (unsigned long *) data;
1971 min = (unsigned long *) table->extra1;
1972 max = (unsigned long *) table->extra2;
1973 vleft = table->maxlen / sizeof(unsigned long);
1976 for (; left && vleft--; i++, min++, max++, first=0) {
1991 if (len > TMPBUFLEN-1)
1993 if (copy_from_user(buf, s, len))
1997 if (*p == '-' && left > 1) {
2001 if (*p < '0' || *p > '9')
2003 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2005 if ((len < left) && *p && !isspace(*p))
2014 if ((min && val < *min) || (max && val > *max))
2021 sprintf(p, "%lu", convdiv * (*i) / convmul);
2025 if(copy_to_user(s, buf, len))
2032 if (!write && !first && left) {
2033 if(put_user('\n', s))
2040 if (get_user(c, s++))
2055 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2057 void __user *buffer,
2058 size_t *lenp, loff_t *ppos,
2059 unsigned long convmul,
2060 unsigned long convdiv)
2062 return __do_proc_doulongvec_minmax(table->data, table, write,
2063 filp, buffer, lenp, ppos, convmul, convdiv);
2067 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2068 * @table: the sysctl table
2069 * @write: %TRUE if this is a write to the sysctl file
2070 * @filp: the file structure
2071 * @buffer: the user buffer
2072 * @lenp: the size of the user buffer
2073 * @ppos: file position
2075 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2076 * values from/to the user buffer, treated as an ASCII string.
2078 * This routine will ensure the values are within the range specified by
2079 * table->extra1 (min) and table->extra2 (max).
2081 * Returns 0 on success.
2083 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2084 void __user *buffer, size_t *lenp, loff_t *ppos)
2086 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2090 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2091 * @table: the sysctl table
2092 * @write: %TRUE if this is a write to the sysctl file
2093 * @filp: the file structure
2094 * @buffer: the user buffer
2095 * @lenp: the size of the user buffer
2096 * @ppos: file position
2098 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2099 * values from/to the user buffer, treated as an ASCII string. The values
2100 * are treated as milliseconds, and converted to jiffies when they are stored.
2102 * This routine will ensure the values are within the range specified by
2103 * table->extra1 (min) and table->extra2 (max).
2105 * Returns 0 on success.
2107 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2109 void __user *buffer,
2110 size_t *lenp, loff_t *ppos)
2112 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2113 lenp, ppos, HZ, 1000l);
2117 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2119 int write, void *data)
2122 if (*lvalp > LONG_MAX / HZ)
2124 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2130 lval = (unsigned long)-val;
2133 lval = (unsigned long)val;
2140 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2142 int write, void *data)
2145 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2147 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2153 lval = (unsigned long)-val;
2156 lval = (unsigned long)val;
2158 *lvalp = jiffies_to_clock_t(lval);
2163 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2165 int write, void *data)
2168 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2174 lval = (unsigned long)-val;
2177 lval = (unsigned long)val;
2179 *lvalp = jiffies_to_msecs(lval);
2185 * proc_dointvec_jiffies - read a vector of integers as seconds
2186 * @table: the sysctl table
2187 * @write: %TRUE if this is a write to the sysctl file
2188 * @filp: the file structure
2189 * @buffer: the user buffer
2190 * @lenp: the size of the user buffer
2191 * @ppos: file position
2193 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2194 * values from/to the user buffer, treated as an ASCII string.
2195 * The values read are assumed to be in seconds, and are converted into
2198 * Returns 0 on success.
2200 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2201 void __user *buffer, size_t *lenp, loff_t *ppos)
2203 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2204 do_proc_dointvec_jiffies_conv,NULL);
2208 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2209 * @table: the sysctl table
2210 * @write: %TRUE if this is a write to the sysctl file
2211 * @filp: the file structure
2212 * @buffer: the user buffer
2213 * @lenp: the size of the user buffer
2214 * @ppos: pointer to the file position
2216 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2217 * values from/to the user buffer, treated as an ASCII string.
2218 * The values read are assumed to be in 1/USER_HZ seconds, and
2219 * are converted into jiffies.
2221 * Returns 0 on success.
2223 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2224 void __user *buffer, size_t *lenp, loff_t *ppos)
2226 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2227 do_proc_dointvec_userhz_jiffies_conv,NULL);
2231 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2232 * @table: the sysctl table
2233 * @write: %TRUE if this is a write to the sysctl file
2234 * @filp: the file structure
2235 * @buffer: the user buffer
2236 * @lenp: the size of the user buffer
2237 * @ppos: file position
2238 * @ppos: the current position in the file
2240 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2241 * values from/to the user buffer, treated as an ASCII string.
2242 * The values read are assumed to be in 1/1000 seconds, and
2243 * are converted into jiffies.
2245 * Returns 0 on success.
2247 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2248 void __user *buffer, size_t *lenp, loff_t *ppos)
2250 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2251 do_proc_dointvec_ms_jiffies_conv, NULL);
2254 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2255 void __user *buffer, size_t *lenp, loff_t *ppos)
2257 struct pid *new_pid;
2261 tmp = pid_nr(cad_pid);
2263 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2264 lenp, ppos, NULL, NULL);
2268 new_pid = find_get_pid(tmp);
2272 put_pid(xchg(&cad_pid, new_pid));
2276 #else /* CONFIG_PROC_FS */
2278 int proc_dostring(ctl_table *table, int write, struct file *filp,
2279 void __user *buffer, size_t *lenp, loff_t *ppos)
2284 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2285 void __user *buffer, size_t *lenp, loff_t *ppos)
2290 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2291 void __user *buffer, size_t *lenp, loff_t *ppos)
2296 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2297 void __user *buffer, size_t *lenp, loff_t *ppos)
2302 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2303 void __user *buffer, size_t *lenp, loff_t *ppos)
2308 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2309 void __user *buffer, size_t *lenp, loff_t *ppos)
2314 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2315 void __user *buffer, size_t *lenp, loff_t *ppos)
2320 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2321 void __user *buffer, size_t *lenp, loff_t *ppos)
2326 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2328 void __user *buffer,
2329 size_t *lenp, loff_t *ppos)
2335 #endif /* CONFIG_PROC_FS */
2338 #ifdef CONFIG_SYSCTL_SYSCALL
2340 * General sysctl support routines
2343 /* The generic string strategy routine: */
2344 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2345 void __user *oldval, size_t __user *oldlenp,
2346 void __user *newval, size_t newlen)
2348 if (!table->data || !table->maxlen)
2351 if (oldval && oldlenp) {
2353 if (get_user(bufsize, oldlenp))
2356 size_t len = strlen(table->data), copied;
2358 /* This shouldn't trigger for a well-formed sysctl */
2359 if (len > table->maxlen)
2360 len = table->maxlen;
2362 /* Copy up to a max of bufsize-1 bytes of the string */
2363 copied = (len >= bufsize) ? bufsize - 1 : len;
2365 if (copy_to_user(oldval, table->data, copied) ||
2366 put_user(0, (char __user *)(oldval + copied)))
2368 if (put_user(len, oldlenp))
2372 if (newval && newlen) {
2373 size_t len = newlen;
2374 if (len > table->maxlen)
2375 len = table->maxlen;
2376 if(copy_from_user(table->data, newval, len))
2378 if (len == table->maxlen)
2380 ((char *) table->data)[len] = 0;
2386 * This function makes sure that all of the integers in the vector
2387 * are between the minimum and maximum values given in the arrays
2388 * table->extra1 and table->extra2, respectively.
2390 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2391 void __user *oldval, size_t __user *oldlenp,
2392 void __user *newval, size_t newlen)
2395 if (newval && newlen) {
2396 int __user *vec = (int __user *) newval;
2397 int *min = (int *) table->extra1;
2398 int *max = (int *) table->extra2;
2402 if (newlen % sizeof(int) != 0)
2405 if (!table->extra1 && !table->extra2)
2408 if (newlen > table->maxlen)
2409 newlen = table->maxlen;
2410 length = newlen / sizeof(int);
2412 for (i = 0; i < length; i++) {
2414 if (get_user(value, vec + i))
2416 if (min && value < min[i])
2418 if (max && value > max[i])
2425 /* Strategy function to convert jiffies to seconds */
2426 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2427 void __user *oldval, size_t __user *oldlenp,
2428 void __user *newval, size_t newlen)
2430 if (oldval && oldlenp) {
2433 if (get_user(olen, oldlenp))
2438 if (olen < sizeof(int))
2441 val = *(int *)(table->data) / HZ;
2442 if (put_user(val, (int __user *)oldval))
2444 if (put_user(sizeof(int), oldlenp))
2448 if (newval && newlen) {
2450 if (newlen != sizeof(int))
2452 if (get_user(new, (int __user *)newval))
2454 *(int *)(table->data) = new*HZ;
2459 /* Strategy function to convert jiffies to seconds */
2460 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2461 void __user *oldval, size_t __user *oldlenp,
2462 void __user *newval, size_t newlen)
2464 if (oldval && oldlenp) {
2467 if (get_user(olen, oldlenp))
2472 if (olen < sizeof(int))
2475 val = jiffies_to_msecs(*(int *)(table->data));
2476 if (put_user(val, (int __user *)oldval))
2478 if (put_user(sizeof(int), oldlenp))
2482 if (newval && newlen) {
2484 if (newlen != sizeof(int))
2486 if (get_user(new, (int __user *)newval))
2488 *(int *)(table->data) = msecs_to_jiffies(new);
2495 #else /* CONFIG_SYSCTL_SYSCALL */
2498 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2500 static int msg_count;
2501 struct __sysctl_args tmp;
2502 int name[CTL_MAXNAME];
2505 /* Read in the sysctl name for better debug message logging */
2506 if (copy_from_user(&tmp, args, sizeof(tmp)))
2508 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2510 for (i = 0; i < tmp.nlen; i++)
2511 if (get_user(name[i], tmp.name + i))
2514 /* Ignore accesses to kernel.version */
2515 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2518 if (msg_count < 5) {
2521 "warning: process `%s' used the removed sysctl "
2522 "system call with ", current->comm);
2523 for (i = 0; i < tmp.nlen; i++)
2524 printk("%d.", name[i]);
2531 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2532 void __user *oldval, size_t __user *oldlenp,
2533 void __user *newval, size_t newlen)
2538 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2539 void __user *oldval, size_t __user *oldlenp,
2540 void __user *newval, size_t newlen)
2545 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2546 void __user *oldval, size_t __user *oldlenp,
2547 void __user *newval, size_t newlen)
2552 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2553 void __user *oldval, size_t __user *oldlenp,
2554 void __user *newval, size_t newlen)
2559 #endif /* CONFIG_SYSCTL_SYSCALL */
2562 * No sense putting this after each symbol definition, twice,
2563 * exception granted :-)
2565 EXPORT_SYMBOL(proc_dointvec);
2566 EXPORT_SYMBOL(proc_dointvec_jiffies);
2567 EXPORT_SYMBOL(proc_dointvec_minmax);
2568 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2569 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2570 EXPORT_SYMBOL(proc_dostring);
2571 EXPORT_SYMBOL(proc_doulongvec_minmax);
2572 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2573 EXPORT_SYMBOL(register_sysctl_table);
2574 EXPORT_SYMBOL(sysctl_intvec);
2575 EXPORT_SYMBOL(sysctl_jiffies);
2576 EXPORT_SYMBOL(sysctl_ms_jiffies);
2577 EXPORT_SYMBOL(sysctl_string);
2578 EXPORT_SYMBOL(unregister_sysctl_table);