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/capability.h>
31 #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>
49 #include <asm/uaccess.h>
50 #include <asm/processor.h>
52 extern int proc_nr_files(ctl_table *table, int write, struct file *filp,
53 void __user *buffer, size_t *lenp, loff_t *ppos);
59 #if defined(CONFIG_SYSCTL)
61 /* External variables not in a header file. */
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 sysrq_enabled;
68 extern int core_uses_pid;
69 extern int suid_dumpable;
70 extern char core_pattern[];
72 extern int min_free_kbytes;
73 extern int printk_ratelimit_jiffies;
74 extern int printk_ratelimit_burst;
75 extern int pid_max_min, pid_max_max;
76 extern int sysctl_drop_caches;
77 extern int percpu_pagelist_fraction;
78 extern int compat_log;
80 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
81 static int maxolduid = 65535;
83 static int min_percpu_pagelist_fract = 8;
85 static int ngroups_max = NGROUPS_MAX;
88 extern char modprobe_path[];
90 #ifdef CONFIG_CHR_DEV_SG
91 extern int sg_big_buff;
94 static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
95 void __user *buffer, size_t *lenp, loff_t *ppos);
99 extern char reboot_command [];
100 extern int stop_a_enabled;
101 extern int scons_pwroff;
105 extern int pwrsw_enabled;
106 extern int unaligned_enabled;
110 #ifdef CONFIG_MATHEMU
111 extern int sysctl_ieee_emulation_warnings;
113 extern int sysctl_userprocess_debug;
114 extern int spin_retry;
117 extern int sysctl_hz_timer;
119 #ifdef CONFIG_BSD_PROCESS_ACCT
120 extern int acct_parm[];
124 extern int no_unaligned_warning;
127 #ifdef CONFIG_RT_MUTEXES
128 extern int max_lock_depth;
131 #ifdef CONFIG_SYSCTL_SYSCALL
132 static int parse_table(int __user *, int, void __user *, size_t __user *,
133 void __user *, size_t, ctl_table *, void **);
136 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
137 void __user *buffer, size_t *lenp, loff_t *ppos);
139 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
140 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 /* /proc declarations: */
165 #ifdef CONFIG_PROC_SYSCTL
167 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
168 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
169 static int proc_opensys(struct inode *, struct file *);
171 struct file_operations proc_sys_file_operations = {
172 .open = proc_opensys,
173 .read = proc_readsys,
174 .write = proc_writesys,
177 extern struct proc_dir_entry *proc_sys_root;
179 static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
180 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
183 /* The default sysctl tables: */
185 static ctl_table root_table[] = {
187 .ctl_name = CTL_KERN,
188 .procname = "kernel",
213 .ctl_name = CTL_DEBUG,
216 .child = debug_table,
228 static ctl_table kern_table[] = {
229 #ifndef CONFIG_UTS_NS
231 .ctl_name = KERN_OSTYPE,
232 .procname = "ostype",
233 .data = init_uts_ns.name.sysname,
234 .maxlen = sizeof(init_uts_ns.name.sysname),
236 .proc_handler = &proc_do_uts_string,
237 .strategy = &sysctl_string,
240 .ctl_name = KERN_OSRELEASE,
241 .procname = "osrelease",
242 .data = init_uts_ns.name.release,
243 .maxlen = sizeof(init_uts_ns.name.release),
245 .proc_handler = &proc_do_uts_string,
246 .strategy = &sysctl_string,
249 .ctl_name = KERN_VERSION,
250 .procname = "version",
251 .data = init_uts_ns.name.version,
252 .maxlen = sizeof(init_uts_ns.name.version),
254 .proc_handler = &proc_do_uts_string,
255 .strategy = &sysctl_string,
258 .ctl_name = KERN_NODENAME,
259 .procname = "hostname",
260 .data = init_uts_ns.name.nodename,
261 .maxlen = sizeof(init_uts_ns.name.nodename),
263 .proc_handler = &proc_do_uts_string,
264 .strategy = &sysctl_string,
267 .ctl_name = KERN_DOMAINNAME,
268 .procname = "domainname",
269 .data = init_uts_ns.name.domainname,
270 .maxlen = sizeof(init_uts_ns.name.domainname),
272 .proc_handler = &proc_do_uts_string,
273 .strategy = &sysctl_string,
275 #else /* !CONFIG_UTS_NS */
277 .ctl_name = KERN_OSTYPE,
278 .procname = "ostype",
280 /* could maybe use __NEW_UTS_LEN here? */
281 .maxlen = FIELD_SIZEOF(struct new_utsname, sysname),
283 .proc_handler = &proc_do_uts_string,
284 .strategy = &sysctl_string,
287 .ctl_name = KERN_OSRELEASE,
288 .procname = "osrelease",
290 .maxlen = FIELD_SIZEOF(struct new_utsname, release),
292 .proc_handler = &proc_do_uts_string,
293 .strategy = &sysctl_string,
296 .ctl_name = KERN_VERSION,
297 .procname = "version",
299 .maxlen = FIELD_SIZEOF(struct new_utsname, version),
301 .proc_handler = &proc_do_uts_string,
302 .strategy = &sysctl_string,
305 .ctl_name = KERN_NODENAME,
306 .procname = "hostname",
308 .maxlen = FIELD_SIZEOF(struct new_utsname, nodename),
310 .proc_handler = &proc_do_uts_string,
311 .strategy = &sysctl_string,
314 .ctl_name = KERN_DOMAINNAME,
315 .procname = "domainname",
317 .maxlen = FIELD_SIZEOF(struct new_utsname, domainname),
319 .proc_handler = &proc_do_uts_string,
320 .strategy = &sysctl_string,
322 #endif /* !CONFIG_UTS_NS */
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,
340 .ctl_name = KERN_CORE_PATTERN,
341 .procname = "core_pattern",
342 .data = core_pattern,
345 .proc_handler = &proc_dostring,
346 .strategy = &sysctl_string,
349 .ctl_name = KERN_TAINTED,
350 .procname = "tainted",
352 .maxlen = sizeof(int),
354 .proc_handler = &proc_dointvec,
357 .ctl_name = KERN_CAP_BSET,
358 .procname = "cap-bound",
360 .maxlen = sizeof(kernel_cap_t),
362 .proc_handler = &proc_dointvec_bset,
364 #ifdef CONFIG_BLK_DEV_INITRD
366 .ctl_name = KERN_REALROOTDEV,
367 .procname = "real-root-dev",
368 .data = &real_root_dev,
369 .maxlen = sizeof(int),
371 .proc_handler = &proc_dointvec,
376 .ctl_name = KERN_SPARC_REBOOT,
377 .procname = "reboot-cmd",
378 .data = reboot_command,
381 .proc_handler = &proc_dostring,
382 .strategy = &sysctl_string,
385 .ctl_name = KERN_SPARC_STOP_A,
386 .procname = "stop-a",
387 .data = &stop_a_enabled,
388 .maxlen = sizeof (int),
390 .proc_handler = &proc_dointvec,
393 .ctl_name = KERN_SPARC_SCONS_PWROFF,
394 .procname = "scons-poweroff",
395 .data = &scons_pwroff,
396 .maxlen = sizeof (int),
398 .proc_handler = &proc_dointvec,
403 .ctl_name = KERN_HPPA_PWRSW,
404 .procname = "soft-power",
405 .data = &pwrsw_enabled,
406 .maxlen = sizeof (int),
408 .proc_handler = &proc_dointvec,
411 .ctl_name = KERN_HPPA_UNALIGNED,
412 .procname = "unaligned-trap",
413 .data = &unaligned_enabled,
414 .maxlen = sizeof (int),
416 .proc_handler = &proc_dointvec,
420 .ctl_name = KERN_CTLALTDEL,
421 .procname = "ctrl-alt-del",
423 .maxlen = sizeof(int),
425 .proc_handler = &proc_dointvec,
428 .ctl_name = KERN_PRINTK,
429 .procname = "printk",
430 .data = &console_loglevel,
431 .maxlen = 4*sizeof(int),
433 .proc_handler = &proc_dointvec,
437 .ctl_name = KERN_MODPROBE,
438 .procname = "modprobe",
439 .data = &modprobe_path,
440 .maxlen = KMOD_PATH_LEN,
442 .proc_handler = &proc_dostring,
443 .strategy = &sysctl_string,
446 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
448 .ctl_name = KERN_HOTPLUG,
449 .procname = "hotplug",
450 .data = &uevent_helper,
451 .maxlen = UEVENT_HELPER_PATH_LEN,
453 .proc_handler = &proc_dostring,
454 .strategy = &sysctl_string,
457 #ifdef CONFIG_CHR_DEV_SG
459 .ctl_name = KERN_SG_BIG_BUFF,
460 .procname = "sg-big-buff",
461 .data = &sg_big_buff,
462 .maxlen = sizeof (int),
464 .proc_handler = &proc_dointvec,
467 #ifdef CONFIG_BSD_PROCESS_ACCT
469 .ctl_name = KERN_ACCT,
472 .maxlen = 3*sizeof(int),
474 .proc_handler = &proc_dointvec,
477 #ifdef CONFIG_SYSVIPC
479 .ctl_name = KERN_SHMMAX,
480 .procname = "shmmax",
482 .maxlen = sizeof (size_t),
484 .proc_handler = &proc_do_ipc_string,
487 .ctl_name = KERN_SHMALL,
488 .procname = "shmall",
490 .maxlen = sizeof (size_t),
492 .proc_handler = &proc_do_ipc_string,
495 .ctl_name = KERN_SHMMNI,
496 .procname = "shmmni",
498 .maxlen = sizeof (int),
500 .proc_handler = &proc_do_ipc_string,
503 .ctl_name = KERN_MSGMAX,
504 .procname = "msgmax",
506 .maxlen = sizeof (int),
508 .proc_handler = &proc_do_ipc_string,
511 .ctl_name = KERN_MSGMNI,
512 .procname = "msgmni",
514 .maxlen = sizeof (int),
516 .proc_handler = &proc_do_ipc_string,
519 .ctl_name = KERN_MSGMNB,
520 .procname = "msgmnb",
522 .maxlen = sizeof (int),
524 .proc_handler = &proc_do_ipc_string,
527 .ctl_name = KERN_SEM,
530 .maxlen = 4*sizeof (int),
532 .proc_handler = &proc_do_ipc_string,
535 #ifdef CONFIG_MAGIC_SYSRQ
537 .ctl_name = KERN_SYSRQ,
539 .data = &sysrq_enabled,
540 .maxlen = sizeof (int),
542 .proc_handler = &proc_dointvec,
546 .ctl_name = KERN_CADPID,
547 .procname = "cad_pid",
549 .maxlen = sizeof (int),
551 .proc_handler = &proc_do_cad_pid,
554 .ctl_name = KERN_MAX_THREADS,
555 .procname = "threads-max",
556 .data = &max_threads,
557 .maxlen = sizeof(int),
559 .proc_handler = &proc_dointvec,
562 .ctl_name = KERN_RANDOM,
563 .procname = "random",
565 .child = random_table,
567 #ifdef CONFIG_UNIX98_PTYS
569 .ctl_name = KERN_PTY,
576 .ctl_name = KERN_OVERFLOWUID,
577 .procname = "overflowuid",
578 .data = &overflowuid,
579 .maxlen = sizeof(int),
581 .proc_handler = &proc_dointvec_minmax,
582 .strategy = &sysctl_intvec,
583 .extra1 = &minolduid,
584 .extra2 = &maxolduid,
587 .ctl_name = KERN_OVERFLOWGID,
588 .procname = "overflowgid",
589 .data = &overflowgid,
590 .maxlen = sizeof(int),
592 .proc_handler = &proc_dointvec_minmax,
593 .strategy = &sysctl_intvec,
594 .extra1 = &minolduid,
595 .extra2 = &maxolduid,
598 #ifdef CONFIG_MATHEMU
600 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
601 .procname = "ieee_emulation_warnings",
602 .data = &sysctl_ieee_emulation_warnings,
603 .maxlen = sizeof(int),
605 .proc_handler = &proc_dointvec,
608 #ifdef CONFIG_NO_IDLE_HZ
610 .ctl_name = KERN_HZ_TIMER,
611 .procname = "hz_timer",
612 .data = &sysctl_hz_timer,
613 .maxlen = sizeof(int),
615 .proc_handler = &proc_dointvec,
619 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
620 .procname = "userprocess_debug",
621 .data = &sysctl_userprocess_debug,
622 .maxlen = sizeof(int),
624 .proc_handler = &proc_dointvec,
628 .ctl_name = KERN_PIDMAX,
629 .procname = "pid_max",
631 .maxlen = sizeof (int),
633 .proc_handler = &proc_dointvec_minmax,
634 .strategy = sysctl_intvec,
635 .extra1 = &pid_max_min,
636 .extra2 = &pid_max_max,
639 .ctl_name = KERN_PANIC_ON_OOPS,
640 .procname = "panic_on_oops",
641 .data = &panic_on_oops,
642 .maxlen = sizeof(int),
644 .proc_handler = &proc_dointvec,
647 .ctl_name = KERN_PRINTK_RATELIMIT,
648 .procname = "printk_ratelimit",
649 .data = &printk_ratelimit_jiffies,
650 .maxlen = sizeof(int),
652 .proc_handler = &proc_dointvec_jiffies,
653 .strategy = &sysctl_jiffies,
656 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
657 .procname = "printk_ratelimit_burst",
658 .data = &printk_ratelimit_burst,
659 .maxlen = sizeof(int),
661 .proc_handler = &proc_dointvec,
664 .ctl_name = KERN_NGROUPS_MAX,
665 .procname = "ngroups_max",
666 .data = &ngroups_max,
667 .maxlen = sizeof (int),
669 .proc_handler = &proc_dointvec,
671 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
673 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
674 .procname = "unknown_nmi_panic",
675 .data = &unknown_nmi_panic,
676 .maxlen = sizeof (int),
678 .proc_handler = &proc_dointvec,
681 .ctl_name = KERN_NMI_WATCHDOG,
682 .procname = "nmi_watchdog",
683 .data = &nmi_watchdog_enabled,
684 .maxlen = sizeof (int),
686 .proc_handler = &proc_nmi_enabled,
689 #if defined(CONFIG_X86)
691 .ctl_name = KERN_PANIC_ON_NMI,
692 .procname = "panic_on_unrecovered_nmi",
693 .data = &panic_on_unrecovered_nmi,
694 .maxlen = sizeof(int),
696 .proc_handler = &proc_dointvec,
699 .ctl_name = KERN_BOOTLOADER_TYPE,
700 .procname = "bootloader_type",
701 .data = &bootloader_type,
702 .maxlen = sizeof (int),
704 .proc_handler = &proc_dointvec,
707 #if defined(CONFIG_MMU)
709 .ctl_name = KERN_RANDOMIZE,
710 .procname = "randomize_va_space",
711 .data = &randomize_va_space,
712 .maxlen = sizeof(int),
714 .proc_handler = &proc_dointvec,
717 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
719 .ctl_name = KERN_SPIN_RETRY,
720 .procname = "spin_retry",
722 .maxlen = sizeof (int),
724 .proc_handler = &proc_dointvec,
727 #ifdef CONFIG_ACPI_SLEEP
729 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
730 .procname = "acpi_video_flags",
731 .data = &acpi_video_flags,
732 .maxlen = sizeof (unsigned long),
734 .proc_handler = &proc_doulongvec_minmax,
739 .ctl_name = KERN_IA64_UNALIGNED,
740 .procname = "ignore-unaligned-usertrap",
741 .data = &no_unaligned_warning,
742 .maxlen = sizeof (int),
744 .proc_handler = &proc_dointvec,
749 .ctl_name = KERN_COMPAT_LOG,
750 .procname = "compat-log",
752 .maxlen = sizeof (int),
754 .proc_handler = &proc_dointvec,
757 #ifdef CONFIG_RT_MUTEXES
759 .ctl_name = KERN_MAX_LOCK_DEPTH,
760 .procname = "max_lock_depth",
761 .data = &max_lock_depth,
762 .maxlen = sizeof(int),
764 .proc_handler = &proc_dointvec,
771 /* Constants for minimum and maximum testing in vm_table.
772 We use these as one-element integer vectors. */
774 static int one_hundred = 100;
777 static ctl_table vm_table[] = {
779 .ctl_name = VM_OVERCOMMIT_MEMORY,
780 .procname = "overcommit_memory",
781 .data = &sysctl_overcommit_memory,
782 .maxlen = sizeof(sysctl_overcommit_memory),
784 .proc_handler = &proc_dointvec,
787 .ctl_name = VM_PANIC_ON_OOM,
788 .procname = "panic_on_oom",
789 .data = &sysctl_panic_on_oom,
790 .maxlen = sizeof(sysctl_panic_on_oom),
792 .proc_handler = &proc_dointvec,
795 .ctl_name = VM_OVERCOMMIT_RATIO,
796 .procname = "overcommit_ratio",
797 .data = &sysctl_overcommit_ratio,
798 .maxlen = sizeof(sysctl_overcommit_ratio),
800 .proc_handler = &proc_dointvec,
803 .ctl_name = VM_PAGE_CLUSTER,
804 .procname = "page-cluster",
805 .data = &page_cluster,
806 .maxlen = sizeof(int),
808 .proc_handler = &proc_dointvec,
811 .ctl_name = VM_DIRTY_BACKGROUND,
812 .procname = "dirty_background_ratio",
813 .data = &dirty_background_ratio,
814 .maxlen = sizeof(dirty_background_ratio),
816 .proc_handler = &proc_dointvec_minmax,
817 .strategy = &sysctl_intvec,
819 .extra2 = &one_hundred,
822 .ctl_name = VM_DIRTY_RATIO,
823 .procname = "dirty_ratio",
824 .data = &vm_dirty_ratio,
825 .maxlen = sizeof(vm_dirty_ratio),
827 .proc_handler = &proc_dointvec_minmax,
828 .strategy = &sysctl_intvec,
830 .extra2 = &one_hundred,
833 .ctl_name = VM_DIRTY_WB_CS,
834 .procname = "dirty_writeback_centisecs",
835 .data = &dirty_writeback_interval,
836 .maxlen = sizeof(dirty_writeback_interval),
838 .proc_handler = &dirty_writeback_centisecs_handler,
841 .ctl_name = VM_DIRTY_EXPIRE_CS,
842 .procname = "dirty_expire_centisecs",
843 .data = &dirty_expire_interval,
844 .maxlen = sizeof(dirty_expire_interval),
846 .proc_handler = &proc_dointvec_userhz_jiffies,
849 .ctl_name = VM_NR_PDFLUSH_THREADS,
850 .procname = "nr_pdflush_threads",
851 .data = &nr_pdflush_threads,
852 .maxlen = sizeof nr_pdflush_threads,
853 .mode = 0444 /* read-only*/,
854 .proc_handler = &proc_dointvec,
857 .ctl_name = VM_SWAPPINESS,
858 .procname = "swappiness",
859 .data = &vm_swappiness,
860 .maxlen = sizeof(vm_swappiness),
862 .proc_handler = &proc_dointvec_minmax,
863 .strategy = &sysctl_intvec,
865 .extra2 = &one_hundred,
867 #ifdef CONFIG_HUGETLB_PAGE
869 .ctl_name = VM_HUGETLB_PAGES,
870 .procname = "nr_hugepages",
871 .data = &max_huge_pages,
872 .maxlen = sizeof(unsigned long),
874 .proc_handler = &hugetlb_sysctl_handler,
875 .extra1 = (void *)&hugetlb_zero,
876 .extra2 = (void *)&hugetlb_infinity,
879 .ctl_name = VM_HUGETLB_GROUP,
880 .procname = "hugetlb_shm_group",
881 .data = &sysctl_hugetlb_shm_group,
882 .maxlen = sizeof(gid_t),
884 .proc_handler = &proc_dointvec,
888 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
889 .procname = "lowmem_reserve_ratio",
890 .data = &sysctl_lowmem_reserve_ratio,
891 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
893 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
894 .strategy = &sysctl_intvec,
897 .ctl_name = VM_DROP_PAGECACHE,
898 .procname = "drop_caches",
899 .data = &sysctl_drop_caches,
900 .maxlen = sizeof(int),
902 .proc_handler = drop_caches_sysctl_handler,
903 .strategy = &sysctl_intvec,
906 .ctl_name = VM_MIN_FREE_KBYTES,
907 .procname = "min_free_kbytes",
908 .data = &min_free_kbytes,
909 .maxlen = sizeof(min_free_kbytes),
911 .proc_handler = &min_free_kbytes_sysctl_handler,
912 .strategy = &sysctl_intvec,
916 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
917 .procname = "percpu_pagelist_fraction",
918 .data = &percpu_pagelist_fraction,
919 .maxlen = sizeof(percpu_pagelist_fraction),
921 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
922 .strategy = &sysctl_intvec,
923 .extra1 = &min_percpu_pagelist_fract,
927 .ctl_name = VM_MAX_MAP_COUNT,
928 .procname = "max_map_count",
929 .data = &sysctl_max_map_count,
930 .maxlen = sizeof(sysctl_max_map_count),
932 .proc_handler = &proc_dointvec
936 .ctl_name = VM_LAPTOP_MODE,
937 .procname = "laptop_mode",
938 .data = &laptop_mode,
939 .maxlen = sizeof(laptop_mode),
941 .proc_handler = &proc_dointvec_jiffies,
942 .strategy = &sysctl_jiffies,
945 .ctl_name = VM_BLOCK_DUMP,
946 .procname = "block_dump",
948 .maxlen = sizeof(block_dump),
950 .proc_handler = &proc_dointvec,
951 .strategy = &sysctl_intvec,
955 .ctl_name = VM_VFS_CACHE_PRESSURE,
956 .procname = "vfs_cache_pressure",
957 .data = &sysctl_vfs_cache_pressure,
958 .maxlen = sizeof(sysctl_vfs_cache_pressure),
960 .proc_handler = &proc_dointvec,
961 .strategy = &sysctl_intvec,
964 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
966 .ctl_name = VM_LEGACY_VA_LAYOUT,
967 .procname = "legacy_va_layout",
968 .data = &sysctl_legacy_va_layout,
969 .maxlen = sizeof(sysctl_legacy_va_layout),
971 .proc_handler = &proc_dointvec,
972 .strategy = &sysctl_intvec,
978 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
979 .procname = "swap_token_timeout",
980 .data = &swap_token_default_timeout,
981 .maxlen = sizeof(swap_token_default_timeout),
983 .proc_handler = &proc_dointvec_jiffies,
984 .strategy = &sysctl_jiffies,
989 .ctl_name = VM_ZONE_RECLAIM_MODE,
990 .procname = "zone_reclaim_mode",
991 .data = &zone_reclaim_mode,
992 .maxlen = sizeof(zone_reclaim_mode),
994 .proc_handler = &proc_dointvec,
995 .strategy = &sysctl_intvec,
999 .ctl_name = VM_MIN_UNMAPPED,
1000 .procname = "min_unmapped_ratio",
1001 .data = &sysctl_min_unmapped_ratio,
1002 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1004 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1005 .strategy = &sysctl_intvec,
1007 .extra2 = &one_hundred,
1010 .ctl_name = VM_MIN_SLAB,
1011 .procname = "min_slab_ratio",
1012 .data = &sysctl_min_slab_ratio,
1013 .maxlen = sizeof(sysctl_min_slab_ratio),
1015 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1016 .strategy = &sysctl_intvec,
1018 .extra2 = &one_hundred,
1021 #ifdef CONFIG_X86_32
1023 .ctl_name = VM_VDSO_ENABLED,
1024 .procname = "vdso_enabled",
1025 .data = &vdso_enabled,
1026 .maxlen = sizeof(vdso_enabled),
1028 .proc_handler = &proc_dointvec,
1029 .strategy = &sysctl_intvec,
1036 static ctl_table fs_table[] = {
1038 .ctl_name = FS_NRINODE,
1039 .procname = "inode-nr",
1040 .data = &inodes_stat,
1041 .maxlen = 2*sizeof(int),
1043 .proc_handler = &proc_dointvec,
1046 .ctl_name = FS_STATINODE,
1047 .procname = "inode-state",
1048 .data = &inodes_stat,
1049 .maxlen = 7*sizeof(int),
1051 .proc_handler = &proc_dointvec,
1054 .ctl_name = FS_NRFILE,
1055 .procname = "file-nr",
1056 .data = &files_stat,
1057 .maxlen = 3*sizeof(int),
1059 .proc_handler = &proc_nr_files,
1062 .ctl_name = FS_MAXFILE,
1063 .procname = "file-max",
1064 .data = &files_stat.max_files,
1065 .maxlen = sizeof(int),
1067 .proc_handler = &proc_dointvec,
1070 .ctl_name = FS_DENTRY,
1071 .procname = "dentry-state",
1072 .data = &dentry_stat,
1073 .maxlen = 6*sizeof(int),
1075 .proc_handler = &proc_dointvec,
1078 .ctl_name = FS_OVERFLOWUID,
1079 .procname = "overflowuid",
1080 .data = &fs_overflowuid,
1081 .maxlen = sizeof(int),
1083 .proc_handler = &proc_dointvec_minmax,
1084 .strategy = &sysctl_intvec,
1085 .extra1 = &minolduid,
1086 .extra2 = &maxolduid,
1089 .ctl_name = FS_OVERFLOWGID,
1090 .procname = "overflowgid",
1091 .data = &fs_overflowgid,
1092 .maxlen = sizeof(int),
1094 .proc_handler = &proc_dointvec_minmax,
1095 .strategy = &sysctl_intvec,
1096 .extra1 = &minolduid,
1097 .extra2 = &maxolduid,
1100 .ctl_name = FS_LEASES,
1101 .procname = "leases-enable",
1102 .data = &leases_enable,
1103 .maxlen = sizeof(int),
1105 .proc_handler = &proc_dointvec,
1107 #ifdef CONFIG_DNOTIFY
1109 .ctl_name = FS_DIR_NOTIFY,
1110 .procname = "dir-notify-enable",
1111 .data = &dir_notify_enable,
1112 .maxlen = sizeof(int),
1114 .proc_handler = &proc_dointvec,
1119 .ctl_name = FS_LEASE_TIME,
1120 .procname = "lease-break-time",
1121 .data = &lease_break_time,
1122 .maxlen = sizeof(int),
1124 .proc_handler = &proc_dointvec,
1127 .ctl_name = FS_AIO_NR,
1128 .procname = "aio-nr",
1130 .maxlen = sizeof(aio_nr),
1132 .proc_handler = &proc_doulongvec_minmax,
1135 .ctl_name = FS_AIO_MAX_NR,
1136 .procname = "aio-max-nr",
1137 .data = &aio_max_nr,
1138 .maxlen = sizeof(aio_max_nr),
1140 .proc_handler = &proc_doulongvec_minmax,
1142 #ifdef CONFIG_INOTIFY_USER
1144 .ctl_name = FS_INOTIFY,
1145 .procname = "inotify",
1147 .child = inotify_table,
1152 .ctl_name = KERN_SETUID_DUMPABLE,
1153 .procname = "suid_dumpable",
1154 .data = &suid_dumpable,
1155 .maxlen = sizeof(int),
1157 .proc_handler = &proc_dointvec,
1162 static ctl_table debug_table[] = {
1166 static ctl_table dev_table[] = {
1170 extern void init_irq_proc (void);
1172 static DEFINE_SPINLOCK(sysctl_lock);
1174 /* called under sysctl_lock */
1175 static int use_table(struct ctl_table_header *p)
1177 if (unlikely(p->unregistering))
1183 /* called under sysctl_lock */
1184 static void unuse_table(struct ctl_table_header *p)
1187 if (unlikely(p->unregistering))
1188 complete(p->unregistering);
1191 /* called under sysctl_lock, will reacquire if has to wait */
1192 static void start_unregistering(struct ctl_table_header *p)
1195 * if p->used is 0, nobody will ever touch that entry again;
1196 * we'll eliminate all paths to it before dropping sysctl_lock
1198 if (unlikely(p->used)) {
1199 struct completion wait;
1200 init_completion(&wait);
1201 p->unregistering = &wait;
1202 spin_unlock(&sysctl_lock);
1203 wait_for_completion(&wait);
1204 spin_lock(&sysctl_lock);
1207 * do not remove from the list until nobody holds it; walking the
1208 * list in do_sysctl() relies on that.
1210 list_del_init(&p->ctl_entry);
1213 void __init sysctl_init(void)
1215 #ifdef CONFIG_PROC_SYSCTL
1216 register_proc_table(root_table, proc_sys_root, &root_table_header);
1221 #ifdef CONFIG_SYSCTL_SYSCALL
1222 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1223 void __user *newval, size_t newlen)
1225 struct list_head *tmp;
1226 int error = -ENOTDIR;
1228 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1232 if (!oldlenp || get_user(old_len, oldlenp))
1235 spin_lock(&sysctl_lock);
1236 tmp = &root_table_header.ctl_entry;
1238 struct ctl_table_header *head =
1239 list_entry(tmp, struct ctl_table_header, ctl_entry);
1240 void *context = NULL;
1242 if (!use_table(head))
1245 spin_unlock(&sysctl_lock);
1247 error = parse_table(name, nlen, oldval, oldlenp,
1248 newval, newlen, head->ctl_table,
1252 spin_lock(&sysctl_lock);
1254 if (error != -ENOTDIR)
1256 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1257 spin_unlock(&sysctl_lock);
1261 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1263 struct __sysctl_args tmp;
1266 if (copy_from_user(&tmp, args, sizeof(tmp)))
1270 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1271 tmp.newval, tmp.newlen);
1275 #endif /* CONFIG_SYSCTL_SYSCALL */
1278 * ctl_perm does NOT grant the superuser all rights automatically, because
1279 * some sysctl variables are readonly even to root.
1282 static int test_perm(int mode, int op)
1286 else if (in_egroup_p(0))
1288 if ((mode & op & 0007) == op)
1293 static inline int ctl_perm(ctl_table *table, int op)
1296 error = security_sysctl(table, op);
1299 return test_perm(table->mode, op);
1302 #ifdef CONFIG_SYSCTL_SYSCALL
1303 static int parse_table(int __user *name, int nlen,
1304 void __user *oldval, size_t __user *oldlenp,
1305 void __user *newval, size_t newlen,
1306 ctl_table *table, void **context)
1312 if (get_user(n, name))
1314 for ( ; table->ctl_name; table++) {
1315 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1318 if (ctl_perm(table, 001))
1320 if (table->strategy) {
1321 error = table->strategy(
1324 newval, newlen, context);
1330 table = table->child;
1333 error = do_sysctl_strategy(table, name, nlen,
1335 newval, newlen, context);
1342 /* Perform the actual read/write of a sysctl table entry. */
1343 int do_sysctl_strategy (ctl_table *table,
1344 int __user *name, int nlen,
1345 void __user *oldval, size_t __user *oldlenp,
1346 void __user *newval, size_t newlen, void **context)
1355 if (ctl_perm(table, op))
1358 if (table->strategy) {
1359 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1360 newval, newlen, context);
1367 /* If there is no strategy routine, or if the strategy returns
1368 * zero, proceed with automatic r/w */
1369 if (table->data && table->maxlen) {
1370 if (oldval && oldlenp) {
1371 if (get_user(len, oldlenp))
1374 if (len > table->maxlen)
1375 len = table->maxlen;
1376 if(copy_to_user(oldval, table->data, len))
1378 if(put_user(len, oldlenp))
1382 if (newval && newlen) {
1384 if (len > table->maxlen)
1385 len = table->maxlen;
1386 if(copy_from_user(table->data, newval, len))
1392 #endif /* CONFIG_SYSCTL_SYSCALL */
1395 * register_sysctl_table - register a sysctl hierarchy
1396 * @table: the top-level table structure
1397 * @insert_at_head: whether the entry should be inserted in front or at the end
1399 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1400 * array. An entry with a ctl_name of 0 terminates the table.
1402 * The members of the &ctl_table structure are used as follows:
1404 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1405 * must be unique within that level of sysctl
1407 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1408 * enter a sysctl file
1410 * data - a pointer to data for use by proc_handler
1412 * maxlen - the maximum size in bytes of the data
1414 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1416 * child - a pointer to the child sysctl table if this entry is a directory, or
1419 * proc_handler - the text handler routine (described below)
1421 * strategy - the strategy routine (described below)
1423 * de - for internal use by the sysctl routines
1425 * extra1, extra2 - extra pointers usable by the proc handler routines
1427 * Leaf nodes in the sysctl tree will be represented by a single file
1428 * under /proc; non-leaf nodes will be represented by directories.
1430 * sysctl(2) can automatically manage read and write requests through
1431 * the sysctl table. The data and maxlen fields of the ctl_table
1432 * struct enable minimal validation of the values being written to be
1433 * performed, and the mode field allows minimal authentication.
1435 * More sophisticated management can be enabled by the provision of a
1436 * strategy routine with the table entry. This will be called before
1437 * any automatic read or write of the data is performed.
1439 * The strategy routine may return
1441 * < 0 - Error occurred (error is passed to user process)
1443 * 0 - OK - proceed with automatic read or write.
1445 * > 0 - OK - read or write has been done by the strategy routine, so
1446 * return immediately.
1448 * There must be a proc_handler routine for any terminal nodes
1449 * mirrored under /proc/sys (non-terminals are handled by a built-in
1450 * directory handler). Several default handlers are available to
1451 * cover common cases -
1453 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1454 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1455 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1457 * It is the handler's job to read the input buffer from user memory
1458 * and process it. The handler should return 0 on success.
1460 * This routine returns %NULL on a failure to register, and a pointer
1461 * to the table header on success.
1463 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1466 struct ctl_table_header *tmp;
1467 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1470 tmp->ctl_table = table;
1471 INIT_LIST_HEAD(&tmp->ctl_entry);
1473 tmp->unregistering = NULL;
1474 spin_lock(&sysctl_lock);
1476 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1478 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1479 spin_unlock(&sysctl_lock);
1480 #ifdef CONFIG_PROC_SYSCTL
1481 register_proc_table(table, proc_sys_root, tmp);
1487 * unregister_sysctl_table - unregister a sysctl table hierarchy
1488 * @header: the header returned from register_sysctl_table
1490 * Unregisters the sysctl table and all children. proc entries may not
1491 * actually be removed until they are no longer used by anyone.
1493 void unregister_sysctl_table(struct ctl_table_header * header)
1496 spin_lock(&sysctl_lock);
1497 start_unregistering(header);
1498 #ifdef CONFIG_PROC_SYSCTL
1499 unregister_proc_table(header->ctl_table, proc_sys_root);
1501 spin_unlock(&sysctl_lock);
1505 #else /* !CONFIG_SYSCTL */
1506 struct ctl_table_header * register_sysctl_table(ctl_table * table,
1512 void unregister_sysctl_table(struct ctl_table_header * table)
1516 #endif /* CONFIG_SYSCTL */
1522 #ifdef CONFIG_PROC_SYSCTL
1524 /* Scan the sysctl entries in table and add them all into /proc */
1525 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1527 struct proc_dir_entry *de;
1531 for (; table->ctl_name; table++) {
1532 /* Can't do anything without a proc name. */
1533 if (!table->procname)
1535 /* Maybe we can't do anything with it... */
1536 if (!table->proc_handler && !table->child) {
1537 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1542 len = strlen(table->procname);
1546 if (table->proc_handler)
1550 for (de = root->subdir; de; de = de->next) {
1551 if (proc_match(len, table->procname, de))
1554 /* If the subdir exists already, de is non-NULL */
1558 de = create_proc_entry(table->procname, mode, root);
1562 de->data = (void *) table;
1563 if (table->proc_handler)
1564 de->proc_fops = &proc_sys_file_operations;
1567 if (de->mode & S_IFDIR)
1568 register_proc_table(table->child, de, set);
1573 * Unregister a /proc sysctl table and any subdirectories.
1575 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1577 struct proc_dir_entry *de;
1578 for (; table->ctl_name; table++) {
1579 if (!(de = table->de))
1581 if (de->mode & S_IFDIR) {
1582 if (!table->child) {
1583 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1586 unregister_proc_table(table->child, de);
1588 /* Don't unregister directories which still have entries.. */
1594 * In any case, mark the entry as goner; we'll keep it
1595 * around if it's busy, but we'll know to do nothing with
1596 * its fields. We are under sysctl_lock here.
1600 /* Don't unregister proc entries that are still being used.. */
1601 if (atomic_read(&de->count))
1605 remove_proc_entry(table->procname, root);
1609 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1610 size_t count, loff_t *ppos)
1613 struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
1614 struct ctl_table *table;
1616 ssize_t error = -ENOTDIR;
1618 spin_lock(&sysctl_lock);
1619 if (de && de->data && use_table(de->set)) {
1621 * at that point we know that sysctl was not unregistered
1622 * and won't be until we finish
1624 spin_unlock(&sysctl_lock);
1625 table = (struct ctl_table *) de->data;
1626 if (!table || !table->proc_handler)
1629 op = (write ? 002 : 004);
1630 if (ctl_perm(table, op))
1633 /* careful: calling conventions are nasty here */
1635 error = (*table->proc_handler)(table, write, file,
1640 spin_lock(&sysctl_lock);
1641 unuse_table(de->set);
1643 spin_unlock(&sysctl_lock);
1647 static int proc_opensys(struct inode *inode, struct file *file)
1649 if (file->f_mode & FMODE_WRITE) {
1651 * sysctl entries that are not writable,
1652 * are _NOT_ writable, capabilities or not.
1654 if (!(inode->i_mode & S_IWUSR))
1661 static ssize_t proc_readsys(struct file * file, char __user * buf,
1662 size_t count, loff_t *ppos)
1664 return do_rw_proc(0, file, buf, count, ppos);
1667 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1668 size_t count, loff_t *ppos)
1670 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1673 static int _proc_do_string(void* data, int maxlen, int write,
1674 struct file *filp, void __user *buffer,
1675 size_t *lenp, loff_t *ppos)
1681 if (!data || !maxlen || !*lenp ||
1682 (*ppos && !write)) {
1690 while (len < *lenp) {
1691 if (get_user(c, p++))
1693 if (c == 0 || c == '\n')
1699 if(copy_from_user(data, buffer, len))
1701 ((char *) data)[len] = 0;
1710 if(copy_to_user(buffer, data, len))
1713 if(put_user('\n', ((char __user *) buffer) + len))
1724 * proc_dostring - read a string sysctl
1725 * @table: the sysctl table
1726 * @write: %TRUE if this is a write to the sysctl file
1727 * @filp: the file structure
1728 * @buffer: the user buffer
1729 * @lenp: the size of the user buffer
1730 * @ppos: file position
1732 * Reads/writes a string from/to the user buffer. If the kernel
1733 * buffer provided is not large enough to hold the string, the
1734 * string is truncated. The copied string is %NULL-terminated.
1735 * If the string is being read by the user process, it is copied
1736 * and a newline '\n' is added. It is truncated if the buffer is
1739 * Returns 0 on success.
1741 int proc_dostring(ctl_table *table, int write, struct file *filp,
1742 void __user *buffer, size_t *lenp, loff_t *ppos)
1744 return _proc_do_string(table->data, table->maxlen, write, filp,
1745 buffer, lenp, ppos);
1749 * Special case of dostring for the UTS structure. This has locks
1750 * to observe. Should this be in kernel/sys.c ????
1753 #ifndef CONFIG_UTS_NS
1754 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
1755 void __user *buffer, size_t *lenp, loff_t *ppos)
1760 down_read(&uts_sem);
1761 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1764 down_write(&uts_sem);
1765 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1770 #else /* !CONFIG_UTS_NS */
1771 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
1772 void __user *buffer, size_t *lenp, loff_t *ppos)
1775 struct uts_namespace* uts_ns = current->nsproxy->uts_ns;
1778 switch (table->ctl_name) {
1780 which = uts_ns->name.sysname;
1783 which = uts_ns->name.nodename;
1785 case KERN_OSRELEASE:
1786 which = uts_ns->name.release;
1789 which = uts_ns->name.version;
1791 case KERN_DOMAINNAME:
1792 which = uts_ns->name.domainname;
1800 down_read(&uts_sem);
1801 r=_proc_do_string(which,table->maxlen,0,filp,buffer,lenp, ppos);
1804 down_write(&uts_sem);
1805 r=_proc_do_string(which,table->maxlen,1,filp,buffer,lenp, ppos);
1811 #endif /* !CONFIG_UTS_NS */
1813 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1815 int write, void *data)
1818 *valp = *negp ? -*lvalp : *lvalp;
1823 *lvalp = (unsigned long)-val;
1826 *lvalp = (unsigned long)val;
1832 static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1833 int write, struct file *filp, void __user *buffer,
1834 size_t *lenp, loff_t *ppos,
1835 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1836 int write, void *data),
1839 #define TMPBUFLEN 21
1840 int *i, vleft, first=1, neg, val;
1844 char buf[TMPBUFLEN], *p;
1845 char __user *s = buffer;
1847 if (!tbl_data || !table->maxlen || !*lenp ||
1848 (*ppos && !write)) {
1853 i = (int *) tbl_data;
1854 vleft = table->maxlen / sizeof(*i);
1858 conv = do_proc_dointvec_conv;
1860 for (; left && vleft--; i++, first=0) {
1875 if (len > sizeof(buf) - 1)
1876 len = sizeof(buf) - 1;
1877 if (copy_from_user(buf, s, len))
1881 if (*p == '-' && left > 1) {
1885 if (*p < '0' || *p > '9')
1888 lval = simple_strtoul(p, &p, 0);
1891 if ((len < left) && *p && !isspace(*p))
1898 if (conv(&neg, &lval, i, 1, data))
1905 if (conv(&neg, &lval, i, 0, data))
1908 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1912 if(copy_to_user(s, buf, len))
1919 if (!write && !first && left) {
1920 if(put_user('\n', s))
1927 if (get_user(c, s++))
1942 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1943 void __user *buffer, size_t *lenp, loff_t *ppos,
1944 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1945 int write, void *data),
1948 return __do_proc_dointvec(table->data, table, write, filp,
1949 buffer, lenp, ppos, conv, data);
1953 * proc_dointvec - read a vector of integers
1954 * @table: the sysctl table
1955 * @write: %TRUE if this is a write to the sysctl file
1956 * @filp: the file structure
1957 * @buffer: the user buffer
1958 * @lenp: the size of the user buffer
1959 * @ppos: file position
1961 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1962 * values from/to the user buffer, treated as an ASCII string.
1964 * Returns 0 on success.
1966 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1967 void __user *buffer, size_t *lenp, loff_t *ppos)
1969 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1979 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1981 int write, void *data)
1983 int op = *(int *)data;
1985 int val = *negp ? -*lvalp : *lvalp;
1987 case OP_SET: *valp = val; break;
1988 case OP_AND: *valp &= val; break;
1989 case OP_OR: *valp |= val; break;
1990 case OP_MAX: if(*valp < val)
1993 case OP_MIN: if(*valp > val)
2001 *lvalp = (unsigned long)-val;
2004 *lvalp = (unsigned long)val;
2011 * init may raise the set.
2014 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2015 void __user *buffer, size_t *lenp, loff_t *ppos)
2019 if (!capable(CAP_SYS_MODULE)) {
2023 op = is_init(current) ? OP_SET : OP_AND;
2024 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2025 do_proc_dointvec_bset_conv,&op);
2028 struct do_proc_dointvec_minmax_conv_param {
2033 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2035 int write, void *data)
2037 struct do_proc_dointvec_minmax_conv_param *param = data;
2039 int val = *negp ? -*lvalp : *lvalp;
2040 if ((param->min && *param->min > val) ||
2041 (param->max && *param->max < val))
2048 *lvalp = (unsigned long)-val;
2051 *lvalp = (unsigned long)val;
2058 * proc_dointvec_minmax - read a vector of integers with min/max values
2059 * @table: the sysctl table
2060 * @write: %TRUE if this is a write to the sysctl file
2061 * @filp: the file structure
2062 * @buffer: the user buffer
2063 * @lenp: the size of the user buffer
2064 * @ppos: file position
2066 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2067 * values from/to the user buffer, treated as an ASCII string.
2069 * This routine will ensure the values are within the range specified by
2070 * table->extra1 (min) and table->extra2 (max).
2072 * Returns 0 on success.
2074 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2075 void __user *buffer, size_t *lenp, loff_t *ppos)
2077 struct do_proc_dointvec_minmax_conv_param param = {
2078 .min = (int *) table->extra1,
2079 .max = (int *) table->extra2,
2081 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2082 do_proc_dointvec_minmax_conv, ¶m);
2085 static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
2087 void __user *buffer,
2088 size_t *lenp, loff_t *ppos,
2089 unsigned long convmul,
2090 unsigned long convdiv)
2092 #define TMPBUFLEN 21
2093 unsigned long *i, *min, *max, val;
2094 int vleft, first=1, neg;
2096 char buf[TMPBUFLEN], *p;
2097 char __user *s = buffer;
2099 if (!data || !table->maxlen || !*lenp ||
2100 (*ppos && !write)) {
2105 i = (unsigned long *) data;
2106 min = (unsigned long *) table->extra1;
2107 max = (unsigned long *) table->extra2;
2108 vleft = table->maxlen / sizeof(unsigned long);
2111 for (; left && vleft--; i++, min++, max++, first=0) {
2126 if (len > TMPBUFLEN-1)
2128 if (copy_from_user(buf, s, len))
2132 if (*p == '-' && left > 1) {
2136 if (*p < '0' || *p > '9')
2138 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2140 if ((len < left) && *p && !isspace(*p))
2149 if ((min && val < *min) || (max && val > *max))
2156 sprintf(p, "%lu", convdiv * (*i) / convmul);
2160 if(copy_to_user(s, buf, len))
2167 if (!write && !first && left) {
2168 if(put_user('\n', s))
2175 if (get_user(c, s++))
2190 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2192 void __user *buffer,
2193 size_t *lenp, loff_t *ppos,
2194 unsigned long convmul,
2195 unsigned long convdiv)
2197 return __do_proc_doulongvec_minmax(table->data, table, write,
2198 filp, buffer, lenp, ppos, convmul, convdiv);
2202 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2203 * @table: the sysctl table
2204 * @write: %TRUE if this is a write to the sysctl file
2205 * @filp: the file structure
2206 * @buffer: the user buffer
2207 * @lenp: the size of the user buffer
2208 * @ppos: file position
2210 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2211 * values from/to the user buffer, treated as an ASCII string.
2213 * This routine will ensure the values are within the range specified by
2214 * table->extra1 (min) and table->extra2 (max).
2216 * Returns 0 on success.
2218 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2219 void __user *buffer, size_t *lenp, loff_t *ppos)
2221 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2225 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2226 * @table: the sysctl table
2227 * @write: %TRUE if this is a write to the sysctl file
2228 * @filp: the file structure
2229 * @buffer: the user buffer
2230 * @lenp: the size of the user buffer
2231 * @ppos: file position
2233 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2234 * values from/to the user buffer, treated as an ASCII string. The values
2235 * are treated as milliseconds, and converted to jiffies when they are stored.
2237 * This routine will ensure the values are within the range specified by
2238 * table->extra1 (min) and table->extra2 (max).
2240 * Returns 0 on success.
2242 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2244 void __user *buffer,
2245 size_t *lenp, loff_t *ppos)
2247 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2248 lenp, ppos, HZ, 1000l);
2252 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2254 int write, void *data)
2257 if (*lvalp > LONG_MAX / HZ)
2259 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2265 lval = (unsigned long)-val;
2268 lval = (unsigned long)val;
2275 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2277 int write, void *data)
2280 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2282 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2288 lval = (unsigned long)-val;
2291 lval = (unsigned long)val;
2293 *lvalp = jiffies_to_clock_t(lval);
2298 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2300 int write, void *data)
2303 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2309 lval = (unsigned long)-val;
2312 lval = (unsigned long)val;
2314 *lvalp = jiffies_to_msecs(lval);
2320 * proc_dointvec_jiffies - read a vector of integers as seconds
2321 * @table: the sysctl table
2322 * @write: %TRUE if this is a write to the sysctl file
2323 * @filp: the file structure
2324 * @buffer: the user buffer
2325 * @lenp: the size of the user buffer
2326 * @ppos: file position
2328 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2329 * values from/to the user buffer, treated as an ASCII string.
2330 * The values read are assumed to be in seconds, and are converted into
2333 * Returns 0 on success.
2335 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2336 void __user *buffer, size_t *lenp, loff_t *ppos)
2338 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2339 do_proc_dointvec_jiffies_conv,NULL);
2343 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2344 * @table: the sysctl table
2345 * @write: %TRUE if this is a write to the sysctl file
2346 * @filp: the file structure
2347 * @buffer: the user buffer
2348 * @lenp: the size of the user buffer
2349 * @ppos: pointer to the file position
2351 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2352 * values from/to the user buffer, treated as an ASCII string.
2353 * The values read are assumed to be in 1/USER_HZ seconds, and
2354 * are converted into jiffies.
2356 * Returns 0 on success.
2358 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2359 void __user *buffer, size_t *lenp, loff_t *ppos)
2361 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2362 do_proc_dointvec_userhz_jiffies_conv,NULL);
2366 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2367 * @table: the sysctl table
2368 * @write: %TRUE if this is a write to the sysctl file
2369 * @filp: the file structure
2370 * @buffer: the user buffer
2371 * @lenp: the size of the user buffer
2372 * @ppos: file position
2373 * @ppos: the current position in the file
2375 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2376 * values from/to the user buffer, treated as an ASCII string.
2377 * The values read are assumed to be in 1/1000 seconds, and
2378 * are converted into jiffies.
2380 * Returns 0 on success.
2382 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2383 void __user *buffer, size_t *lenp, loff_t *ppos)
2385 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2386 do_proc_dointvec_ms_jiffies_conv, NULL);
2389 #ifdef CONFIG_SYSVIPC
2390 static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2391 void __user *buffer, size_t *lenp, loff_t *ppos)
2394 struct ipc_namespace *ns;
2396 ns = current->nsproxy->ipc_ns;
2398 switch (table->ctl_name) {
2400 data = &ns->shm_ctlmax;
2403 data = &ns->shm_ctlall;
2406 data = &ns->shm_ctlmni;
2409 data = &ns->msg_ctlmax;
2412 data = &ns->msg_ctlmni;
2415 data = &ns->msg_ctlmnb;
2418 data = &ns->sem_ctls;
2424 return __do_proc_dointvec(data, table, write, filp, buffer,
2425 lenp, ppos, NULL, NULL);
2427 return __do_proc_doulongvec_minmax(data, table, write, filp, buffer,
2428 lenp, ppos, 1l, 1l);
2432 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2433 void __user *buffer, size_t *lenp, loff_t *ppos)
2435 struct pid *new_pid;
2439 tmp = pid_nr(cad_pid);
2441 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2442 lenp, ppos, NULL, NULL);
2446 new_pid = find_get_pid(tmp);
2450 put_pid(xchg(&cad_pid, new_pid));
2454 #else /* CONFIG_PROC_FS */
2456 int proc_dostring(ctl_table *table, int write, struct file *filp,
2457 void __user *buffer, size_t *lenp, loff_t *ppos)
2462 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
2463 void __user *buffer, size_t *lenp, loff_t *ppos)
2468 #ifdef CONFIG_SYSVIPC
2469 static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2470 void __user *buffer, size_t *lenp, loff_t *ppos)
2476 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2477 void __user *buffer, size_t *lenp, loff_t *ppos)
2482 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2483 void __user *buffer, size_t *lenp, loff_t *ppos)
2488 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2489 void __user *buffer, size_t *lenp, loff_t *ppos)
2494 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2495 void __user *buffer, size_t *lenp, loff_t *ppos)
2500 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2501 void __user *buffer, size_t *lenp, loff_t *ppos)
2506 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2507 void __user *buffer, size_t *lenp, loff_t *ppos)
2512 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2513 void __user *buffer, size_t *lenp, loff_t *ppos)
2518 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2520 void __user *buffer,
2521 size_t *lenp, loff_t *ppos)
2527 #endif /* CONFIG_PROC_FS */
2530 #ifdef CONFIG_SYSCTL_SYSCALL
2532 * General sysctl support routines
2535 /* The generic string strategy routine: */
2536 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2537 void __user *oldval, size_t __user *oldlenp,
2538 void __user *newval, size_t newlen, void **context)
2540 if (!table->data || !table->maxlen)
2543 if (oldval && oldlenp) {
2545 if (get_user(bufsize, oldlenp))
2548 size_t len = strlen(table->data), copied;
2550 /* This shouldn't trigger for a well-formed sysctl */
2551 if (len > table->maxlen)
2552 len = table->maxlen;
2554 /* Copy up to a max of bufsize-1 bytes of the string */
2555 copied = (len >= bufsize) ? bufsize - 1 : len;
2557 if (copy_to_user(oldval, table->data, copied) ||
2558 put_user(0, (char __user *)(oldval + copied)))
2560 if (put_user(len, oldlenp))
2564 if (newval && newlen) {
2565 size_t len = newlen;
2566 if (len > table->maxlen)
2567 len = table->maxlen;
2568 if(copy_from_user(table->data, newval, len))
2570 if (len == table->maxlen)
2572 ((char *) table->data)[len] = 0;
2578 * This function makes sure that all of the integers in the vector
2579 * are between the minimum and maximum values given in the arrays
2580 * table->extra1 and table->extra2, respectively.
2582 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2583 void __user *oldval, size_t __user *oldlenp,
2584 void __user *newval, size_t newlen, void **context)
2587 if (newval && newlen) {
2588 int __user *vec = (int __user *) newval;
2589 int *min = (int *) table->extra1;
2590 int *max = (int *) table->extra2;
2594 if (newlen % sizeof(int) != 0)
2597 if (!table->extra1 && !table->extra2)
2600 if (newlen > table->maxlen)
2601 newlen = table->maxlen;
2602 length = newlen / sizeof(int);
2604 for (i = 0; i < length; i++) {
2606 if (get_user(value, vec + i))
2608 if (min && value < min[i])
2610 if (max && value > max[i])
2617 /* Strategy function to convert jiffies to seconds */
2618 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2619 void __user *oldval, size_t __user *oldlenp,
2620 void __user *newval, size_t newlen, void **context)
2625 if (get_user(olen, oldlenp))
2627 if (olen!=sizeof(int))
2630 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2631 (oldlenp && put_user(sizeof(int),oldlenp)))
2634 if (newval && newlen) {
2636 if (newlen != sizeof(int))
2638 if (get_user(new, (int __user *)newval))
2640 *(int *)(table->data) = new*HZ;
2645 /* Strategy function to convert jiffies to seconds */
2646 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2647 void __user *oldval, size_t __user *oldlenp,
2648 void __user *newval, size_t newlen, void **context)
2653 if (get_user(olen, oldlenp))
2655 if (olen!=sizeof(int))
2658 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2659 (oldlenp && put_user(sizeof(int),oldlenp)))
2662 if (newval && newlen) {
2664 if (newlen != sizeof(int))
2666 if (get_user(new, (int __user *)newval))
2668 *(int *)(table->data) = msecs_to_jiffies(new);
2673 #else /* CONFIG_SYSCTL_SYSCALL */
2676 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2678 static int msg_count;
2680 if (msg_count < 5) {
2683 "warning: process `%s' used the removed sysctl "
2684 "system call\n", current->comm);
2689 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2690 void __user *oldval, size_t __user *oldlenp,
2691 void __user *newval, size_t newlen, void **context)
2696 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2697 void __user *oldval, size_t __user *oldlenp,
2698 void __user *newval, size_t newlen, void **context)
2703 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2704 void __user *oldval, size_t __user *oldlenp,
2705 void __user *newval, size_t newlen, void **context)
2710 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2711 void __user *oldval, size_t __user *oldlenp,
2712 void __user *newval, size_t newlen, void **context)
2717 #endif /* CONFIG_SYSCTL_SYSCALL */
2720 * No sense putting this after each symbol definition, twice,
2721 * exception granted :-)
2723 EXPORT_SYMBOL(proc_dointvec);
2724 EXPORT_SYMBOL(proc_dointvec_jiffies);
2725 EXPORT_SYMBOL(proc_dointvec_minmax);
2726 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2727 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2728 EXPORT_SYMBOL(proc_dostring);
2729 EXPORT_SYMBOL(proc_doulongvec_minmax);
2730 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2731 EXPORT_SYMBOL(register_sysctl_table);
2732 EXPORT_SYMBOL(sysctl_intvec);
2733 EXPORT_SYMBOL(sysctl_jiffies);
2734 EXPORT_SYMBOL(sysctl_ms_jiffies);
2735 EXPORT_SYMBOL(sysctl_string);
2736 EXPORT_SYMBOL(unregister_sysctl_table);