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 #ifdef CONFIG_PROC_SYSCTL
140 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
141 void __user *buffer, size_t *lenp, loff_t *ppos);
144 static ctl_table root_table[];
145 static struct ctl_table_header root_table_header =
146 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
148 static ctl_table kern_table[];
149 static ctl_table vm_table[];
150 static ctl_table fs_table[];
151 static ctl_table debug_table[];
152 static ctl_table dev_table[];
153 extern ctl_table random_table[];
154 #ifdef CONFIG_UNIX98_PTYS
155 extern ctl_table pty_table[];
157 #ifdef CONFIG_INOTIFY_USER
158 extern ctl_table inotify_table[];
161 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
162 int sysctl_legacy_va_layout;
165 /* /proc declarations: */
167 #ifdef CONFIG_PROC_SYSCTL
169 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
170 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
171 static int proc_opensys(struct inode *, struct file *);
173 struct file_operations proc_sys_file_operations = {
174 .open = proc_opensys,
175 .read = proc_readsys,
176 .write = proc_writesys,
179 extern struct proc_dir_entry *proc_sys_root;
181 static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
182 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
185 /* The default sysctl tables: */
187 static ctl_table root_table[] = {
189 .ctl_name = CTL_KERN,
190 .procname = "kernel",
215 .ctl_name = CTL_DEBUG,
218 .child = debug_table,
230 static ctl_table kern_table[] = {
231 #ifndef CONFIG_UTS_NS
233 .ctl_name = KERN_OSTYPE,
234 .procname = "ostype",
235 .data = init_uts_ns.name.sysname,
236 .maxlen = sizeof(init_uts_ns.name.sysname),
238 .proc_handler = &proc_do_uts_string,
239 .strategy = &sysctl_string,
242 .ctl_name = KERN_OSRELEASE,
243 .procname = "osrelease",
244 .data = init_uts_ns.name.release,
245 .maxlen = sizeof(init_uts_ns.name.release),
247 .proc_handler = &proc_do_uts_string,
248 .strategy = &sysctl_string,
251 .ctl_name = KERN_VERSION,
252 .procname = "version",
253 .data = init_uts_ns.name.version,
254 .maxlen = sizeof(init_uts_ns.name.version),
256 .proc_handler = &proc_do_uts_string,
257 .strategy = &sysctl_string,
260 .ctl_name = KERN_NODENAME,
261 .procname = "hostname",
262 .data = init_uts_ns.name.nodename,
263 .maxlen = sizeof(init_uts_ns.name.nodename),
265 .proc_handler = &proc_do_uts_string,
266 .strategy = &sysctl_string,
269 .ctl_name = KERN_DOMAINNAME,
270 .procname = "domainname",
271 .data = init_uts_ns.name.domainname,
272 .maxlen = sizeof(init_uts_ns.name.domainname),
274 .proc_handler = &proc_do_uts_string,
275 .strategy = &sysctl_string,
277 #else /* !CONFIG_UTS_NS */
279 .ctl_name = KERN_OSTYPE,
280 .procname = "ostype",
282 /* could maybe use __NEW_UTS_LEN here? */
283 .maxlen = FIELD_SIZEOF(struct new_utsname, sysname),
285 .proc_handler = &proc_do_uts_string,
286 .strategy = &sysctl_string,
289 .ctl_name = KERN_OSRELEASE,
290 .procname = "osrelease",
292 .maxlen = FIELD_SIZEOF(struct new_utsname, release),
294 .proc_handler = &proc_do_uts_string,
295 .strategy = &sysctl_string,
298 .ctl_name = KERN_VERSION,
299 .procname = "version",
301 .maxlen = FIELD_SIZEOF(struct new_utsname, version),
303 .proc_handler = &proc_do_uts_string,
304 .strategy = &sysctl_string,
307 .ctl_name = KERN_NODENAME,
308 .procname = "hostname",
310 .maxlen = FIELD_SIZEOF(struct new_utsname, nodename),
312 .proc_handler = &proc_do_uts_string,
313 .strategy = &sysctl_string,
316 .ctl_name = KERN_DOMAINNAME,
317 .procname = "domainname",
319 .maxlen = FIELD_SIZEOF(struct new_utsname, domainname),
321 .proc_handler = &proc_do_uts_string,
322 .strategy = &sysctl_string,
324 #endif /* !CONFIG_UTS_NS */
326 .ctl_name = KERN_PANIC,
328 .data = &panic_timeout,
329 .maxlen = sizeof(int),
331 .proc_handler = &proc_dointvec,
334 .ctl_name = KERN_CORE_USES_PID,
335 .procname = "core_uses_pid",
336 .data = &core_uses_pid,
337 .maxlen = sizeof(int),
339 .proc_handler = &proc_dointvec,
342 .ctl_name = KERN_CORE_PATTERN,
343 .procname = "core_pattern",
344 .data = core_pattern,
347 .proc_handler = &proc_dostring,
348 .strategy = &sysctl_string,
351 .ctl_name = KERN_TAINTED,
352 .procname = "tainted",
354 .maxlen = sizeof(int),
356 .proc_handler = &proc_dointvec,
359 .ctl_name = KERN_CAP_BSET,
360 .procname = "cap-bound",
362 .maxlen = sizeof(kernel_cap_t),
364 .proc_handler = &proc_dointvec_bset,
366 #ifdef CONFIG_BLK_DEV_INITRD
368 .ctl_name = KERN_REALROOTDEV,
369 .procname = "real-root-dev",
370 .data = &real_root_dev,
371 .maxlen = sizeof(int),
373 .proc_handler = &proc_dointvec,
378 .ctl_name = KERN_SPARC_REBOOT,
379 .procname = "reboot-cmd",
380 .data = reboot_command,
383 .proc_handler = &proc_dostring,
384 .strategy = &sysctl_string,
387 .ctl_name = KERN_SPARC_STOP_A,
388 .procname = "stop-a",
389 .data = &stop_a_enabled,
390 .maxlen = sizeof (int),
392 .proc_handler = &proc_dointvec,
395 .ctl_name = KERN_SPARC_SCONS_PWROFF,
396 .procname = "scons-poweroff",
397 .data = &scons_pwroff,
398 .maxlen = sizeof (int),
400 .proc_handler = &proc_dointvec,
405 .ctl_name = KERN_HPPA_PWRSW,
406 .procname = "soft-power",
407 .data = &pwrsw_enabled,
408 .maxlen = sizeof (int),
410 .proc_handler = &proc_dointvec,
413 .ctl_name = KERN_HPPA_UNALIGNED,
414 .procname = "unaligned-trap",
415 .data = &unaligned_enabled,
416 .maxlen = sizeof (int),
418 .proc_handler = &proc_dointvec,
422 .ctl_name = KERN_CTLALTDEL,
423 .procname = "ctrl-alt-del",
425 .maxlen = sizeof(int),
427 .proc_handler = &proc_dointvec,
430 .ctl_name = KERN_PRINTK,
431 .procname = "printk",
432 .data = &console_loglevel,
433 .maxlen = 4*sizeof(int),
435 .proc_handler = &proc_dointvec,
439 .ctl_name = KERN_MODPROBE,
440 .procname = "modprobe",
441 .data = &modprobe_path,
442 .maxlen = KMOD_PATH_LEN,
444 .proc_handler = &proc_dostring,
445 .strategy = &sysctl_string,
448 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
450 .ctl_name = KERN_HOTPLUG,
451 .procname = "hotplug",
452 .data = &uevent_helper,
453 .maxlen = UEVENT_HELPER_PATH_LEN,
455 .proc_handler = &proc_dostring,
456 .strategy = &sysctl_string,
459 #ifdef CONFIG_CHR_DEV_SG
461 .ctl_name = KERN_SG_BIG_BUFF,
462 .procname = "sg-big-buff",
463 .data = &sg_big_buff,
464 .maxlen = sizeof (int),
466 .proc_handler = &proc_dointvec,
469 #ifdef CONFIG_BSD_PROCESS_ACCT
471 .ctl_name = KERN_ACCT,
474 .maxlen = 3*sizeof(int),
476 .proc_handler = &proc_dointvec,
479 #ifdef CONFIG_SYSVIPC
481 .ctl_name = KERN_SHMMAX,
482 .procname = "shmmax",
484 .maxlen = sizeof (size_t),
486 .proc_handler = &proc_do_ipc_string,
489 .ctl_name = KERN_SHMALL,
490 .procname = "shmall",
492 .maxlen = sizeof (size_t),
494 .proc_handler = &proc_do_ipc_string,
497 .ctl_name = KERN_SHMMNI,
498 .procname = "shmmni",
500 .maxlen = sizeof (int),
502 .proc_handler = &proc_do_ipc_string,
505 .ctl_name = KERN_MSGMAX,
506 .procname = "msgmax",
508 .maxlen = sizeof (int),
510 .proc_handler = &proc_do_ipc_string,
513 .ctl_name = KERN_MSGMNI,
514 .procname = "msgmni",
516 .maxlen = sizeof (int),
518 .proc_handler = &proc_do_ipc_string,
521 .ctl_name = KERN_MSGMNB,
522 .procname = "msgmnb",
524 .maxlen = sizeof (int),
526 .proc_handler = &proc_do_ipc_string,
529 .ctl_name = KERN_SEM,
532 .maxlen = 4*sizeof (int),
534 .proc_handler = &proc_do_ipc_string,
537 #ifdef CONFIG_MAGIC_SYSRQ
539 .ctl_name = KERN_SYSRQ,
541 .data = &sysrq_enabled,
542 .maxlen = sizeof (int),
544 .proc_handler = &proc_dointvec,
547 #ifdef CONFIG_PROC_SYSCTL
549 .ctl_name = KERN_CADPID,
550 .procname = "cad_pid",
552 .maxlen = sizeof (int),
554 .proc_handler = &proc_do_cad_pid,
558 .ctl_name = KERN_MAX_THREADS,
559 .procname = "threads-max",
560 .data = &max_threads,
561 .maxlen = sizeof(int),
563 .proc_handler = &proc_dointvec,
566 .ctl_name = KERN_RANDOM,
567 .procname = "random",
569 .child = random_table,
571 #ifdef CONFIG_UNIX98_PTYS
573 .ctl_name = KERN_PTY,
580 .ctl_name = KERN_OVERFLOWUID,
581 .procname = "overflowuid",
582 .data = &overflowuid,
583 .maxlen = sizeof(int),
585 .proc_handler = &proc_dointvec_minmax,
586 .strategy = &sysctl_intvec,
587 .extra1 = &minolduid,
588 .extra2 = &maxolduid,
591 .ctl_name = KERN_OVERFLOWGID,
592 .procname = "overflowgid",
593 .data = &overflowgid,
594 .maxlen = sizeof(int),
596 .proc_handler = &proc_dointvec_minmax,
597 .strategy = &sysctl_intvec,
598 .extra1 = &minolduid,
599 .extra2 = &maxolduid,
602 #ifdef CONFIG_MATHEMU
604 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
605 .procname = "ieee_emulation_warnings",
606 .data = &sysctl_ieee_emulation_warnings,
607 .maxlen = sizeof(int),
609 .proc_handler = &proc_dointvec,
612 #ifdef CONFIG_NO_IDLE_HZ
614 .ctl_name = KERN_HZ_TIMER,
615 .procname = "hz_timer",
616 .data = &sysctl_hz_timer,
617 .maxlen = sizeof(int),
619 .proc_handler = &proc_dointvec,
623 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
624 .procname = "userprocess_debug",
625 .data = &sysctl_userprocess_debug,
626 .maxlen = sizeof(int),
628 .proc_handler = &proc_dointvec,
632 .ctl_name = KERN_PIDMAX,
633 .procname = "pid_max",
635 .maxlen = sizeof (int),
637 .proc_handler = &proc_dointvec_minmax,
638 .strategy = sysctl_intvec,
639 .extra1 = &pid_max_min,
640 .extra2 = &pid_max_max,
643 .ctl_name = KERN_PANIC_ON_OOPS,
644 .procname = "panic_on_oops",
645 .data = &panic_on_oops,
646 .maxlen = sizeof(int),
648 .proc_handler = &proc_dointvec,
651 .ctl_name = KERN_PRINTK_RATELIMIT,
652 .procname = "printk_ratelimit",
653 .data = &printk_ratelimit_jiffies,
654 .maxlen = sizeof(int),
656 .proc_handler = &proc_dointvec_jiffies,
657 .strategy = &sysctl_jiffies,
660 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
661 .procname = "printk_ratelimit_burst",
662 .data = &printk_ratelimit_burst,
663 .maxlen = sizeof(int),
665 .proc_handler = &proc_dointvec,
668 .ctl_name = KERN_NGROUPS_MAX,
669 .procname = "ngroups_max",
670 .data = &ngroups_max,
671 .maxlen = sizeof (int),
673 .proc_handler = &proc_dointvec,
675 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
677 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
678 .procname = "unknown_nmi_panic",
679 .data = &unknown_nmi_panic,
680 .maxlen = sizeof (int),
682 .proc_handler = &proc_dointvec,
685 .ctl_name = KERN_NMI_WATCHDOG,
686 .procname = "nmi_watchdog",
687 .data = &nmi_watchdog_enabled,
688 .maxlen = sizeof (int),
690 .proc_handler = &proc_nmi_enabled,
693 #if defined(CONFIG_X86)
695 .ctl_name = KERN_PANIC_ON_NMI,
696 .procname = "panic_on_unrecovered_nmi",
697 .data = &panic_on_unrecovered_nmi,
698 .maxlen = sizeof(int),
700 .proc_handler = &proc_dointvec,
703 .ctl_name = KERN_BOOTLOADER_TYPE,
704 .procname = "bootloader_type",
705 .data = &bootloader_type,
706 .maxlen = sizeof (int),
708 .proc_handler = &proc_dointvec,
711 #if defined(CONFIG_MMU)
713 .ctl_name = KERN_RANDOMIZE,
714 .procname = "randomize_va_space",
715 .data = &randomize_va_space,
716 .maxlen = sizeof(int),
718 .proc_handler = &proc_dointvec,
721 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
723 .ctl_name = KERN_SPIN_RETRY,
724 .procname = "spin_retry",
726 .maxlen = sizeof (int),
728 .proc_handler = &proc_dointvec,
731 #ifdef CONFIG_ACPI_SLEEP
733 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
734 .procname = "acpi_video_flags",
735 .data = &acpi_video_flags,
736 .maxlen = sizeof (unsigned long),
738 .proc_handler = &proc_doulongvec_minmax,
743 .ctl_name = KERN_IA64_UNALIGNED,
744 .procname = "ignore-unaligned-usertrap",
745 .data = &no_unaligned_warning,
746 .maxlen = sizeof (int),
748 .proc_handler = &proc_dointvec,
753 .ctl_name = KERN_COMPAT_LOG,
754 .procname = "compat-log",
756 .maxlen = sizeof (int),
758 .proc_handler = &proc_dointvec,
761 #ifdef CONFIG_RT_MUTEXES
763 .ctl_name = KERN_MAX_LOCK_DEPTH,
764 .procname = "max_lock_depth",
765 .data = &max_lock_depth,
766 .maxlen = sizeof(int),
768 .proc_handler = &proc_dointvec,
775 /* Constants for minimum and maximum testing in vm_table.
776 We use these as one-element integer vectors. */
778 static int one_hundred = 100;
781 static ctl_table vm_table[] = {
783 .ctl_name = VM_OVERCOMMIT_MEMORY,
784 .procname = "overcommit_memory",
785 .data = &sysctl_overcommit_memory,
786 .maxlen = sizeof(sysctl_overcommit_memory),
788 .proc_handler = &proc_dointvec,
791 .ctl_name = VM_PANIC_ON_OOM,
792 .procname = "panic_on_oom",
793 .data = &sysctl_panic_on_oom,
794 .maxlen = sizeof(sysctl_panic_on_oom),
796 .proc_handler = &proc_dointvec,
799 .ctl_name = VM_OVERCOMMIT_RATIO,
800 .procname = "overcommit_ratio",
801 .data = &sysctl_overcommit_ratio,
802 .maxlen = sizeof(sysctl_overcommit_ratio),
804 .proc_handler = &proc_dointvec,
807 .ctl_name = VM_PAGE_CLUSTER,
808 .procname = "page-cluster",
809 .data = &page_cluster,
810 .maxlen = sizeof(int),
812 .proc_handler = &proc_dointvec,
815 .ctl_name = VM_DIRTY_BACKGROUND,
816 .procname = "dirty_background_ratio",
817 .data = &dirty_background_ratio,
818 .maxlen = sizeof(dirty_background_ratio),
820 .proc_handler = &proc_dointvec_minmax,
821 .strategy = &sysctl_intvec,
823 .extra2 = &one_hundred,
826 .ctl_name = VM_DIRTY_RATIO,
827 .procname = "dirty_ratio",
828 .data = &vm_dirty_ratio,
829 .maxlen = sizeof(vm_dirty_ratio),
831 .proc_handler = &proc_dointvec_minmax,
832 .strategy = &sysctl_intvec,
834 .extra2 = &one_hundred,
837 .ctl_name = VM_DIRTY_WB_CS,
838 .procname = "dirty_writeback_centisecs",
839 .data = &dirty_writeback_interval,
840 .maxlen = sizeof(dirty_writeback_interval),
842 .proc_handler = &dirty_writeback_centisecs_handler,
845 .ctl_name = VM_DIRTY_EXPIRE_CS,
846 .procname = "dirty_expire_centisecs",
847 .data = &dirty_expire_interval,
848 .maxlen = sizeof(dirty_expire_interval),
850 .proc_handler = &proc_dointvec_userhz_jiffies,
853 .ctl_name = VM_NR_PDFLUSH_THREADS,
854 .procname = "nr_pdflush_threads",
855 .data = &nr_pdflush_threads,
856 .maxlen = sizeof nr_pdflush_threads,
857 .mode = 0444 /* read-only*/,
858 .proc_handler = &proc_dointvec,
861 .ctl_name = VM_SWAPPINESS,
862 .procname = "swappiness",
863 .data = &vm_swappiness,
864 .maxlen = sizeof(vm_swappiness),
866 .proc_handler = &proc_dointvec_minmax,
867 .strategy = &sysctl_intvec,
869 .extra2 = &one_hundred,
871 #ifdef CONFIG_HUGETLB_PAGE
873 .ctl_name = VM_HUGETLB_PAGES,
874 .procname = "nr_hugepages",
875 .data = &max_huge_pages,
876 .maxlen = sizeof(unsigned long),
878 .proc_handler = &hugetlb_sysctl_handler,
879 .extra1 = (void *)&hugetlb_zero,
880 .extra2 = (void *)&hugetlb_infinity,
883 .ctl_name = VM_HUGETLB_GROUP,
884 .procname = "hugetlb_shm_group",
885 .data = &sysctl_hugetlb_shm_group,
886 .maxlen = sizeof(gid_t),
888 .proc_handler = &proc_dointvec,
892 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
893 .procname = "lowmem_reserve_ratio",
894 .data = &sysctl_lowmem_reserve_ratio,
895 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
897 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
898 .strategy = &sysctl_intvec,
901 .ctl_name = VM_DROP_PAGECACHE,
902 .procname = "drop_caches",
903 .data = &sysctl_drop_caches,
904 .maxlen = sizeof(int),
906 .proc_handler = drop_caches_sysctl_handler,
907 .strategy = &sysctl_intvec,
910 .ctl_name = VM_MIN_FREE_KBYTES,
911 .procname = "min_free_kbytes",
912 .data = &min_free_kbytes,
913 .maxlen = sizeof(min_free_kbytes),
915 .proc_handler = &min_free_kbytes_sysctl_handler,
916 .strategy = &sysctl_intvec,
920 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
921 .procname = "percpu_pagelist_fraction",
922 .data = &percpu_pagelist_fraction,
923 .maxlen = sizeof(percpu_pagelist_fraction),
925 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
926 .strategy = &sysctl_intvec,
927 .extra1 = &min_percpu_pagelist_fract,
931 .ctl_name = VM_MAX_MAP_COUNT,
932 .procname = "max_map_count",
933 .data = &sysctl_max_map_count,
934 .maxlen = sizeof(sysctl_max_map_count),
936 .proc_handler = &proc_dointvec
940 .ctl_name = VM_LAPTOP_MODE,
941 .procname = "laptop_mode",
942 .data = &laptop_mode,
943 .maxlen = sizeof(laptop_mode),
945 .proc_handler = &proc_dointvec_jiffies,
946 .strategy = &sysctl_jiffies,
949 .ctl_name = VM_BLOCK_DUMP,
950 .procname = "block_dump",
952 .maxlen = sizeof(block_dump),
954 .proc_handler = &proc_dointvec,
955 .strategy = &sysctl_intvec,
959 .ctl_name = VM_VFS_CACHE_PRESSURE,
960 .procname = "vfs_cache_pressure",
961 .data = &sysctl_vfs_cache_pressure,
962 .maxlen = sizeof(sysctl_vfs_cache_pressure),
964 .proc_handler = &proc_dointvec,
965 .strategy = &sysctl_intvec,
968 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
970 .ctl_name = VM_LEGACY_VA_LAYOUT,
971 .procname = "legacy_va_layout",
972 .data = &sysctl_legacy_va_layout,
973 .maxlen = sizeof(sysctl_legacy_va_layout),
975 .proc_handler = &proc_dointvec,
976 .strategy = &sysctl_intvec,
982 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
983 .procname = "swap_token_timeout",
984 .data = &swap_token_default_timeout,
985 .maxlen = sizeof(swap_token_default_timeout),
987 .proc_handler = &proc_dointvec_jiffies,
988 .strategy = &sysctl_jiffies,
993 .ctl_name = VM_ZONE_RECLAIM_MODE,
994 .procname = "zone_reclaim_mode",
995 .data = &zone_reclaim_mode,
996 .maxlen = sizeof(zone_reclaim_mode),
998 .proc_handler = &proc_dointvec,
999 .strategy = &sysctl_intvec,
1003 .ctl_name = VM_MIN_UNMAPPED,
1004 .procname = "min_unmapped_ratio",
1005 .data = &sysctl_min_unmapped_ratio,
1006 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1008 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1009 .strategy = &sysctl_intvec,
1011 .extra2 = &one_hundred,
1014 .ctl_name = VM_MIN_SLAB,
1015 .procname = "min_slab_ratio",
1016 .data = &sysctl_min_slab_ratio,
1017 .maxlen = sizeof(sysctl_min_slab_ratio),
1019 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1020 .strategy = &sysctl_intvec,
1022 .extra2 = &one_hundred,
1025 #ifdef CONFIG_X86_32
1027 .ctl_name = VM_VDSO_ENABLED,
1028 .procname = "vdso_enabled",
1029 .data = &vdso_enabled,
1030 .maxlen = sizeof(vdso_enabled),
1032 .proc_handler = &proc_dointvec,
1033 .strategy = &sysctl_intvec,
1040 static ctl_table fs_table[] = {
1042 .ctl_name = FS_NRINODE,
1043 .procname = "inode-nr",
1044 .data = &inodes_stat,
1045 .maxlen = 2*sizeof(int),
1047 .proc_handler = &proc_dointvec,
1050 .ctl_name = FS_STATINODE,
1051 .procname = "inode-state",
1052 .data = &inodes_stat,
1053 .maxlen = 7*sizeof(int),
1055 .proc_handler = &proc_dointvec,
1058 .ctl_name = FS_NRFILE,
1059 .procname = "file-nr",
1060 .data = &files_stat,
1061 .maxlen = 3*sizeof(int),
1063 .proc_handler = &proc_nr_files,
1066 .ctl_name = FS_MAXFILE,
1067 .procname = "file-max",
1068 .data = &files_stat.max_files,
1069 .maxlen = sizeof(int),
1071 .proc_handler = &proc_dointvec,
1074 .ctl_name = FS_DENTRY,
1075 .procname = "dentry-state",
1076 .data = &dentry_stat,
1077 .maxlen = 6*sizeof(int),
1079 .proc_handler = &proc_dointvec,
1082 .ctl_name = FS_OVERFLOWUID,
1083 .procname = "overflowuid",
1084 .data = &fs_overflowuid,
1085 .maxlen = sizeof(int),
1087 .proc_handler = &proc_dointvec_minmax,
1088 .strategy = &sysctl_intvec,
1089 .extra1 = &minolduid,
1090 .extra2 = &maxolduid,
1093 .ctl_name = FS_OVERFLOWGID,
1094 .procname = "overflowgid",
1095 .data = &fs_overflowgid,
1096 .maxlen = sizeof(int),
1098 .proc_handler = &proc_dointvec_minmax,
1099 .strategy = &sysctl_intvec,
1100 .extra1 = &minolduid,
1101 .extra2 = &maxolduid,
1104 .ctl_name = FS_LEASES,
1105 .procname = "leases-enable",
1106 .data = &leases_enable,
1107 .maxlen = sizeof(int),
1109 .proc_handler = &proc_dointvec,
1111 #ifdef CONFIG_DNOTIFY
1113 .ctl_name = FS_DIR_NOTIFY,
1114 .procname = "dir-notify-enable",
1115 .data = &dir_notify_enable,
1116 .maxlen = sizeof(int),
1118 .proc_handler = &proc_dointvec,
1123 .ctl_name = FS_LEASE_TIME,
1124 .procname = "lease-break-time",
1125 .data = &lease_break_time,
1126 .maxlen = sizeof(int),
1128 .proc_handler = &proc_dointvec,
1131 .ctl_name = FS_AIO_NR,
1132 .procname = "aio-nr",
1134 .maxlen = sizeof(aio_nr),
1136 .proc_handler = &proc_doulongvec_minmax,
1139 .ctl_name = FS_AIO_MAX_NR,
1140 .procname = "aio-max-nr",
1141 .data = &aio_max_nr,
1142 .maxlen = sizeof(aio_max_nr),
1144 .proc_handler = &proc_doulongvec_minmax,
1146 #ifdef CONFIG_INOTIFY_USER
1148 .ctl_name = FS_INOTIFY,
1149 .procname = "inotify",
1151 .child = inotify_table,
1156 .ctl_name = KERN_SETUID_DUMPABLE,
1157 .procname = "suid_dumpable",
1158 .data = &suid_dumpable,
1159 .maxlen = sizeof(int),
1161 .proc_handler = &proc_dointvec,
1166 static ctl_table debug_table[] = {
1170 static ctl_table dev_table[] = {
1174 extern void init_irq_proc (void);
1176 static DEFINE_SPINLOCK(sysctl_lock);
1178 /* called under sysctl_lock */
1179 static int use_table(struct ctl_table_header *p)
1181 if (unlikely(p->unregistering))
1187 /* called under sysctl_lock */
1188 static void unuse_table(struct ctl_table_header *p)
1191 if (unlikely(p->unregistering))
1192 complete(p->unregistering);
1195 /* called under sysctl_lock, will reacquire if has to wait */
1196 static void start_unregistering(struct ctl_table_header *p)
1199 * if p->used is 0, nobody will ever touch that entry again;
1200 * we'll eliminate all paths to it before dropping sysctl_lock
1202 if (unlikely(p->used)) {
1203 struct completion wait;
1204 init_completion(&wait);
1205 p->unregistering = &wait;
1206 spin_unlock(&sysctl_lock);
1207 wait_for_completion(&wait);
1208 spin_lock(&sysctl_lock);
1211 * do not remove from the list until nobody holds it; walking the
1212 * list in do_sysctl() relies on that.
1214 list_del_init(&p->ctl_entry);
1217 void __init sysctl_init(void)
1219 #ifdef CONFIG_PROC_SYSCTL
1220 register_proc_table(root_table, proc_sys_root, &root_table_header);
1225 #ifdef CONFIG_SYSCTL_SYSCALL
1226 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1227 void __user *newval, size_t newlen)
1229 struct list_head *tmp;
1230 int error = -ENOTDIR;
1232 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1236 if (!oldlenp || get_user(old_len, oldlenp))
1239 spin_lock(&sysctl_lock);
1240 tmp = &root_table_header.ctl_entry;
1242 struct ctl_table_header *head =
1243 list_entry(tmp, struct ctl_table_header, ctl_entry);
1244 void *context = NULL;
1246 if (!use_table(head))
1249 spin_unlock(&sysctl_lock);
1251 error = parse_table(name, nlen, oldval, oldlenp,
1252 newval, newlen, head->ctl_table,
1256 spin_lock(&sysctl_lock);
1258 if (error != -ENOTDIR)
1260 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1261 spin_unlock(&sysctl_lock);
1265 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1267 struct __sysctl_args tmp;
1270 if (copy_from_user(&tmp, args, sizeof(tmp)))
1274 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1275 tmp.newval, tmp.newlen);
1279 #endif /* CONFIG_SYSCTL_SYSCALL */
1282 * ctl_perm does NOT grant the superuser all rights automatically, because
1283 * some sysctl variables are readonly even to root.
1286 static int test_perm(int mode, int op)
1290 else if (in_egroup_p(0))
1292 if ((mode & op & 0007) == op)
1297 static inline int ctl_perm(ctl_table *table, int op)
1300 error = security_sysctl(table, op);
1303 return test_perm(table->mode, op);
1306 #ifdef CONFIG_SYSCTL_SYSCALL
1307 static int parse_table(int __user *name, int nlen,
1308 void __user *oldval, size_t __user *oldlenp,
1309 void __user *newval, size_t newlen,
1310 ctl_table *table, void **context)
1316 if (get_user(n, name))
1318 for ( ; table->ctl_name; table++) {
1319 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1322 if (ctl_perm(table, 001))
1324 if (table->strategy) {
1325 error = table->strategy(
1328 newval, newlen, context);
1334 table = table->child;
1337 error = do_sysctl_strategy(table, name, nlen,
1339 newval, newlen, context);
1346 /* Perform the actual read/write of a sysctl table entry. */
1347 int do_sysctl_strategy (ctl_table *table,
1348 int __user *name, int nlen,
1349 void __user *oldval, size_t __user *oldlenp,
1350 void __user *newval, size_t newlen, void **context)
1359 if (ctl_perm(table, op))
1362 if (table->strategy) {
1363 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1364 newval, newlen, context);
1371 /* If there is no strategy routine, or if the strategy returns
1372 * zero, proceed with automatic r/w */
1373 if (table->data && table->maxlen) {
1374 if (oldval && oldlenp) {
1375 if (get_user(len, oldlenp))
1378 if (len > table->maxlen)
1379 len = table->maxlen;
1380 if(copy_to_user(oldval, table->data, len))
1382 if(put_user(len, oldlenp))
1386 if (newval && newlen) {
1388 if (len > table->maxlen)
1389 len = table->maxlen;
1390 if(copy_from_user(table->data, newval, len))
1396 #endif /* CONFIG_SYSCTL_SYSCALL */
1399 * register_sysctl_table - register a sysctl hierarchy
1400 * @table: the top-level table structure
1401 * @insert_at_head: whether the entry should be inserted in front or at the end
1403 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1404 * array. An entry with a ctl_name of 0 terminates the table.
1406 * The members of the &ctl_table structure are used as follows:
1408 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1409 * must be unique within that level of sysctl
1411 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1412 * enter a sysctl file
1414 * data - a pointer to data for use by proc_handler
1416 * maxlen - the maximum size in bytes of the data
1418 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1420 * child - a pointer to the child sysctl table if this entry is a directory, or
1423 * proc_handler - the text handler routine (described below)
1425 * strategy - the strategy routine (described below)
1427 * de - for internal use by the sysctl routines
1429 * extra1, extra2 - extra pointers usable by the proc handler routines
1431 * Leaf nodes in the sysctl tree will be represented by a single file
1432 * under /proc; non-leaf nodes will be represented by directories.
1434 * sysctl(2) can automatically manage read and write requests through
1435 * the sysctl table. The data and maxlen fields of the ctl_table
1436 * struct enable minimal validation of the values being written to be
1437 * performed, and the mode field allows minimal authentication.
1439 * More sophisticated management can be enabled by the provision of a
1440 * strategy routine with the table entry. This will be called before
1441 * any automatic read or write of the data is performed.
1443 * The strategy routine may return
1445 * < 0 - Error occurred (error is passed to user process)
1447 * 0 - OK - proceed with automatic read or write.
1449 * > 0 - OK - read or write has been done by the strategy routine, so
1450 * return immediately.
1452 * There must be a proc_handler routine for any terminal nodes
1453 * mirrored under /proc/sys (non-terminals are handled by a built-in
1454 * directory handler). Several default handlers are available to
1455 * cover common cases -
1457 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1458 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1459 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1461 * It is the handler's job to read the input buffer from user memory
1462 * and process it. The handler should return 0 on success.
1464 * This routine returns %NULL on a failure to register, and a pointer
1465 * to the table header on success.
1467 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1470 struct ctl_table_header *tmp;
1471 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1474 tmp->ctl_table = table;
1475 INIT_LIST_HEAD(&tmp->ctl_entry);
1477 tmp->unregistering = NULL;
1478 spin_lock(&sysctl_lock);
1480 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1482 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1483 spin_unlock(&sysctl_lock);
1484 #ifdef CONFIG_PROC_SYSCTL
1485 register_proc_table(table, proc_sys_root, tmp);
1491 * unregister_sysctl_table - unregister a sysctl table hierarchy
1492 * @header: the header returned from register_sysctl_table
1494 * Unregisters the sysctl table and all children. proc entries may not
1495 * actually be removed until they are no longer used by anyone.
1497 void unregister_sysctl_table(struct ctl_table_header * header)
1500 spin_lock(&sysctl_lock);
1501 start_unregistering(header);
1502 #ifdef CONFIG_PROC_SYSCTL
1503 unregister_proc_table(header->ctl_table, proc_sys_root);
1505 spin_unlock(&sysctl_lock);
1509 #else /* !CONFIG_SYSCTL */
1510 struct ctl_table_header * register_sysctl_table(ctl_table * table,
1516 void unregister_sysctl_table(struct ctl_table_header * table)
1520 #endif /* CONFIG_SYSCTL */
1526 #ifdef CONFIG_PROC_SYSCTL
1528 /* Scan the sysctl entries in table and add them all into /proc */
1529 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1531 struct proc_dir_entry *de;
1535 for (; table->ctl_name; table++) {
1536 /* Can't do anything without a proc name. */
1537 if (!table->procname)
1539 /* Maybe we can't do anything with it... */
1540 if (!table->proc_handler && !table->child) {
1541 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1546 len = strlen(table->procname);
1550 if (table->proc_handler)
1554 for (de = root->subdir; de; de = de->next) {
1555 if (proc_match(len, table->procname, de))
1558 /* If the subdir exists already, de is non-NULL */
1562 de = create_proc_entry(table->procname, mode, root);
1566 de->data = (void *) table;
1567 if (table->proc_handler)
1568 de->proc_fops = &proc_sys_file_operations;
1571 if (de->mode & S_IFDIR)
1572 register_proc_table(table->child, de, set);
1577 * Unregister a /proc sysctl table and any subdirectories.
1579 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1581 struct proc_dir_entry *de;
1582 for (; table->ctl_name; table++) {
1583 if (!(de = table->de))
1585 if (de->mode & S_IFDIR) {
1586 if (!table->child) {
1587 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1590 unregister_proc_table(table->child, de);
1592 /* Don't unregister directories which still have entries.. */
1598 * In any case, mark the entry as goner; we'll keep it
1599 * around if it's busy, but we'll know to do nothing with
1600 * its fields. We are under sysctl_lock here.
1604 /* Don't unregister proc entries that are still being used.. */
1605 if (atomic_read(&de->count))
1609 remove_proc_entry(table->procname, root);
1613 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1614 size_t count, loff_t *ppos)
1617 struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
1618 struct ctl_table *table;
1620 ssize_t error = -ENOTDIR;
1622 spin_lock(&sysctl_lock);
1623 if (de && de->data && use_table(de->set)) {
1625 * at that point we know that sysctl was not unregistered
1626 * and won't be until we finish
1628 spin_unlock(&sysctl_lock);
1629 table = (struct ctl_table *) de->data;
1630 if (!table || !table->proc_handler)
1633 op = (write ? 002 : 004);
1634 if (ctl_perm(table, op))
1637 /* careful: calling conventions are nasty here */
1639 error = (*table->proc_handler)(table, write, file,
1644 spin_lock(&sysctl_lock);
1645 unuse_table(de->set);
1647 spin_unlock(&sysctl_lock);
1651 static int proc_opensys(struct inode *inode, struct file *file)
1653 if (file->f_mode & FMODE_WRITE) {
1655 * sysctl entries that are not writable,
1656 * are _NOT_ writable, capabilities or not.
1658 if (!(inode->i_mode & S_IWUSR))
1665 static ssize_t proc_readsys(struct file * file, char __user * buf,
1666 size_t count, loff_t *ppos)
1668 return do_rw_proc(0, file, buf, count, ppos);
1671 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1672 size_t count, loff_t *ppos)
1674 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1677 static int _proc_do_string(void* data, int maxlen, int write,
1678 struct file *filp, void __user *buffer,
1679 size_t *lenp, loff_t *ppos)
1685 if (!data || !maxlen || !*lenp ||
1686 (*ppos && !write)) {
1694 while (len < *lenp) {
1695 if (get_user(c, p++))
1697 if (c == 0 || c == '\n')
1703 if(copy_from_user(data, buffer, len))
1705 ((char *) data)[len] = 0;
1714 if(copy_to_user(buffer, data, len))
1717 if(put_user('\n', ((char __user *) buffer) + len))
1728 * proc_dostring - read a string sysctl
1729 * @table: the sysctl table
1730 * @write: %TRUE if this is a write to the sysctl file
1731 * @filp: the file structure
1732 * @buffer: the user buffer
1733 * @lenp: the size of the user buffer
1734 * @ppos: file position
1736 * Reads/writes a string from/to the user buffer. If the kernel
1737 * buffer provided is not large enough to hold the string, the
1738 * string is truncated. The copied string is %NULL-terminated.
1739 * If the string is being read by the user process, it is copied
1740 * and a newline '\n' is added. It is truncated if the buffer is
1743 * Returns 0 on success.
1745 int proc_dostring(ctl_table *table, int write, struct file *filp,
1746 void __user *buffer, size_t *lenp, loff_t *ppos)
1748 return _proc_do_string(table->data, table->maxlen, write, filp,
1749 buffer, lenp, ppos);
1753 * Special case of dostring for the UTS structure. This has locks
1754 * to observe. Should this be in kernel/sys.c ????
1757 #ifndef CONFIG_UTS_NS
1758 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
1759 void __user *buffer, size_t *lenp, loff_t *ppos)
1764 down_read(&uts_sem);
1765 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1768 down_write(&uts_sem);
1769 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1774 #else /* !CONFIG_UTS_NS */
1775 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
1776 void __user *buffer, size_t *lenp, loff_t *ppos)
1779 struct uts_namespace* uts_ns = current->nsproxy->uts_ns;
1782 switch (table->ctl_name) {
1784 which = uts_ns->name.sysname;
1787 which = uts_ns->name.nodename;
1789 case KERN_OSRELEASE:
1790 which = uts_ns->name.release;
1793 which = uts_ns->name.version;
1795 case KERN_DOMAINNAME:
1796 which = uts_ns->name.domainname;
1804 down_read(&uts_sem);
1805 r=_proc_do_string(which,table->maxlen,0,filp,buffer,lenp, ppos);
1808 down_write(&uts_sem);
1809 r=_proc_do_string(which,table->maxlen,1,filp,buffer,lenp, ppos);
1815 #endif /* !CONFIG_UTS_NS */
1817 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1819 int write, void *data)
1822 *valp = *negp ? -*lvalp : *lvalp;
1827 *lvalp = (unsigned long)-val;
1830 *lvalp = (unsigned long)val;
1836 static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1837 int write, struct file *filp, void __user *buffer,
1838 size_t *lenp, loff_t *ppos,
1839 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1840 int write, void *data),
1843 #define TMPBUFLEN 21
1844 int *i, vleft, first=1, neg, val;
1848 char buf[TMPBUFLEN], *p;
1849 char __user *s = buffer;
1851 if (!tbl_data || !table->maxlen || !*lenp ||
1852 (*ppos && !write)) {
1857 i = (int *) tbl_data;
1858 vleft = table->maxlen / sizeof(*i);
1862 conv = do_proc_dointvec_conv;
1864 for (; left && vleft--; i++, first=0) {
1879 if (len > sizeof(buf) - 1)
1880 len = sizeof(buf) - 1;
1881 if (copy_from_user(buf, s, len))
1885 if (*p == '-' && left > 1) {
1889 if (*p < '0' || *p > '9')
1892 lval = simple_strtoul(p, &p, 0);
1895 if ((len < left) && *p && !isspace(*p))
1902 if (conv(&neg, &lval, i, 1, data))
1909 if (conv(&neg, &lval, i, 0, data))
1912 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1916 if(copy_to_user(s, buf, len))
1923 if (!write && !first && left) {
1924 if(put_user('\n', s))
1931 if (get_user(c, s++))
1946 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1947 void __user *buffer, size_t *lenp, loff_t *ppos,
1948 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1949 int write, void *data),
1952 return __do_proc_dointvec(table->data, table, write, filp,
1953 buffer, lenp, ppos, conv, data);
1957 * proc_dointvec - read a vector of integers
1958 * @table: the sysctl table
1959 * @write: %TRUE if this is a write to the sysctl file
1960 * @filp: the file structure
1961 * @buffer: the user buffer
1962 * @lenp: the size of the user buffer
1963 * @ppos: file position
1965 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1966 * values from/to the user buffer, treated as an ASCII string.
1968 * Returns 0 on success.
1970 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1971 void __user *buffer, size_t *lenp, loff_t *ppos)
1973 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1983 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1985 int write, void *data)
1987 int op = *(int *)data;
1989 int val = *negp ? -*lvalp : *lvalp;
1991 case OP_SET: *valp = val; break;
1992 case OP_AND: *valp &= val; break;
1993 case OP_OR: *valp |= val; break;
1994 case OP_MAX: if(*valp < val)
1997 case OP_MIN: if(*valp > val)
2005 *lvalp = (unsigned long)-val;
2008 *lvalp = (unsigned long)val;
2015 * init may raise the set.
2018 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2019 void __user *buffer, size_t *lenp, loff_t *ppos)
2023 if (!capable(CAP_SYS_MODULE)) {
2027 op = is_init(current) ? OP_SET : OP_AND;
2028 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2029 do_proc_dointvec_bset_conv,&op);
2032 struct do_proc_dointvec_minmax_conv_param {
2037 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2039 int write, void *data)
2041 struct do_proc_dointvec_minmax_conv_param *param = data;
2043 int val = *negp ? -*lvalp : *lvalp;
2044 if ((param->min && *param->min > val) ||
2045 (param->max && *param->max < val))
2052 *lvalp = (unsigned long)-val;
2055 *lvalp = (unsigned long)val;
2062 * proc_dointvec_minmax - read a vector of integers with min/max values
2063 * @table: the sysctl table
2064 * @write: %TRUE if this is a write to the sysctl file
2065 * @filp: the file structure
2066 * @buffer: the user buffer
2067 * @lenp: the size of the user buffer
2068 * @ppos: file position
2070 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2071 * values from/to the user buffer, treated as an ASCII string.
2073 * This routine will ensure the values are within the range specified by
2074 * table->extra1 (min) and table->extra2 (max).
2076 * Returns 0 on success.
2078 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2079 void __user *buffer, size_t *lenp, loff_t *ppos)
2081 struct do_proc_dointvec_minmax_conv_param param = {
2082 .min = (int *) table->extra1,
2083 .max = (int *) table->extra2,
2085 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2086 do_proc_dointvec_minmax_conv, ¶m);
2089 static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
2091 void __user *buffer,
2092 size_t *lenp, loff_t *ppos,
2093 unsigned long convmul,
2094 unsigned long convdiv)
2096 #define TMPBUFLEN 21
2097 unsigned long *i, *min, *max, val;
2098 int vleft, first=1, neg;
2100 char buf[TMPBUFLEN], *p;
2101 char __user *s = buffer;
2103 if (!data || !table->maxlen || !*lenp ||
2104 (*ppos && !write)) {
2109 i = (unsigned long *) data;
2110 min = (unsigned long *) table->extra1;
2111 max = (unsigned long *) table->extra2;
2112 vleft = table->maxlen / sizeof(unsigned long);
2115 for (; left && vleft--; i++, min++, max++, first=0) {
2130 if (len > TMPBUFLEN-1)
2132 if (copy_from_user(buf, s, len))
2136 if (*p == '-' && left > 1) {
2140 if (*p < '0' || *p > '9')
2142 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2144 if ((len < left) && *p && !isspace(*p))
2153 if ((min && val < *min) || (max && val > *max))
2160 sprintf(p, "%lu", convdiv * (*i) / convmul);
2164 if(copy_to_user(s, buf, len))
2171 if (!write && !first && left) {
2172 if(put_user('\n', s))
2179 if (get_user(c, s++))
2194 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2196 void __user *buffer,
2197 size_t *lenp, loff_t *ppos,
2198 unsigned long convmul,
2199 unsigned long convdiv)
2201 return __do_proc_doulongvec_minmax(table->data, table, write,
2202 filp, buffer, lenp, ppos, convmul, convdiv);
2206 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2207 * @table: the sysctl table
2208 * @write: %TRUE if this is a write to the sysctl file
2209 * @filp: the file structure
2210 * @buffer: the user buffer
2211 * @lenp: the size of the user buffer
2212 * @ppos: file position
2214 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2215 * values from/to the user buffer, treated as an ASCII string.
2217 * This routine will ensure the values are within the range specified by
2218 * table->extra1 (min) and table->extra2 (max).
2220 * Returns 0 on success.
2222 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2223 void __user *buffer, size_t *lenp, loff_t *ppos)
2225 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2229 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2230 * @table: the sysctl table
2231 * @write: %TRUE if this is a write to the sysctl file
2232 * @filp: the file structure
2233 * @buffer: the user buffer
2234 * @lenp: the size of the user buffer
2235 * @ppos: file position
2237 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2238 * values from/to the user buffer, treated as an ASCII string. The values
2239 * are treated as milliseconds, and converted to jiffies when they are stored.
2241 * This routine will ensure the values are within the range specified by
2242 * table->extra1 (min) and table->extra2 (max).
2244 * Returns 0 on success.
2246 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2248 void __user *buffer,
2249 size_t *lenp, loff_t *ppos)
2251 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2252 lenp, ppos, HZ, 1000l);
2256 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2258 int write, void *data)
2261 if (*lvalp > LONG_MAX / HZ)
2263 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2269 lval = (unsigned long)-val;
2272 lval = (unsigned long)val;
2279 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2281 int write, void *data)
2284 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2286 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2292 lval = (unsigned long)-val;
2295 lval = (unsigned long)val;
2297 *lvalp = jiffies_to_clock_t(lval);
2302 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2304 int write, void *data)
2307 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2313 lval = (unsigned long)-val;
2316 lval = (unsigned long)val;
2318 *lvalp = jiffies_to_msecs(lval);
2324 * proc_dointvec_jiffies - read a vector of integers as seconds
2325 * @table: the sysctl table
2326 * @write: %TRUE if this is a write to the sysctl file
2327 * @filp: the file structure
2328 * @buffer: the user buffer
2329 * @lenp: the size of the user buffer
2330 * @ppos: file position
2332 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2333 * values from/to the user buffer, treated as an ASCII string.
2334 * The values read are assumed to be in seconds, and are converted into
2337 * Returns 0 on success.
2339 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2340 void __user *buffer, size_t *lenp, loff_t *ppos)
2342 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2343 do_proc_dointvec_jiffies_conv,NULL);
2347 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2348 * @table: the sysctl table
2349 * @write: %TRUE if this is a write to the sysctl file
2350 * @filp: the file structure
2351 * @buffer: the user buffer
2352 * @lenp: the size of the user buffer
2353 * @ppos: pointer to the file position
2355 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2356 * values from/to the user buffer, treated as an ASCII string.
2357 * The values read are assumed to be in 1/USER_HZ seconds, and
2358 * are converted into jiffies.
2360 * Returns 0 on success.
2362 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2363 void __user *buffer, size_t *lenp, loff_t *ppos)
2365 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2366 do_proc_dointvec_userhz_jiffies_conv,NULL);
2370 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2371 * @table: the sysctl table
2372 * @write: %TRUE if this is a write to the sysctl file
2373 * @filp: the file structure
2374 * @buffer: the user buffer
2375 * @lenp: the size of the user buffer
2376 * @ppos: file position
2377 * @ppos: the current position in the file
2379 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2380 * values from/to the user buffer, treated as an ASCII string.
2381 * The values read are assumed to be in 1/1000 seconds, and
2382 * are converted into jiffies.
2384 * Returns 0 on success.
2386 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2387 void __user *buffer, size_t *lenp, loff_t *ppos)
2389 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2390 do_proc_dointvec_ms_jiffies_conv, NULL);
2393 #ifdef CONFIG_SYSVIPC
2394 static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2395 void __user *buffer, size_t *lenp, loff_t *ppos)
2398 struct ipc_namespace *ns;
2400 ns = current->nsproxy->ipc_ns;
2402 switch (table->ctl_name) {
2404 data = &ns->shm_ctlmax;
2407 data = &ns->shm_ctlall;
2410 data = &ns->shm_ctlmni;
2413 data = &ns->msg_ctlmax;
2416 data = &ns->msg_ctlmni;
2419 data = &ns->msg_ctlmnb;
2422 data = &ns->sem_ctls;
2428 return __do_proc_dointvec(data, table, write, filp, buffer,
2429 lenp, ppos, NULL, NULL);
2431 return __do_proc_doulongvec_minmax(data, table, write, filp, buffer,
2432 lenp, ppos, 1l, 1l);
2436 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2437 void __user *buffer, size_t *lenp, loff_t *ppos)
2439 struct pid *new_pid;
2443 tmp = pid_nr(cad_pid);
2445 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2446 lenp, ppos, NULL, NULL);
2450 new_pid = find_get_pid(tmp);
2454 put_pid(xchg(&cad_pid, new_pid));
2458 #else /* CONFIG_PROC_FS */
2460 int proc_dostring(ctl_table *table, int write, struct file *filp,
2461 void __user *buffer, size_t *lenp, loff_t *ppos)
2466 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
2467 void __user *buffer, size_t *lenp, loff_t *ppos)
2472 #ifdef CONFIG_SYSVIPC
2473 static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2474 void __user *buffer, size_t *lenp, loff_t *ppos)
2480 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2481 void __user *buffer, size_t *lenp, loff_t *ppos)
2486 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2487 void __user *buffer, size_t *lenp, loff_t *ppos)
2492 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2493 void __user *buffer, size_t *lenp, loff_t *ppos)
2498 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2499 void __user *buffer, size_t *lenp, loff_t *ppos)
2504 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2505 void __user *buffer, size_t *lenp, loff_t *ppos)
2510 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2511 void __user *buffer, size_t *lenp, loff_t *ppos)
2516 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2517 void __user *buffer, size_t *lenp, loff_t *ppos)
2522 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2524 void __user *buffer,
2525 size_t *lenp, loff_t *ppos)
2531 #endif /* CONFIG_PROC_FS */
2534 #ifdef CONFIG_SYSCTL_SYSCALL
2536 * General sysctl support routines
2539 /* The generic string strategy routine: */
2540 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2541 void __user *oldval, size_t __user *oldlenp,
2542 void __user *newval, size_t newlen, void **context)
2544 if (!table->data || !table->maxlen)
2547 if (oldval && oldlenp) {
2549 if (get_user(bufsize, oldlenp))
2552 size_t len = strlen(table->data), copied;
2554 /* This shouldn't trigger for a well-formed sysctl */
2555 if (len > table->maxlen)
2556 len = table->maxlen;
2558 /* Copy up to a max of bufsize-1 bytes of the string */
2559 copied = (len >= bufsize) ? bufsize - 1 : len;
2561 if (copy_to_user(oldval, table->data, copied) ||
2562 put_user(0, (char __user *)(oldval + copied)))
2564 if (put_user(len, oldlenp))
2568 if (newval && newlen) {
2569 size_t len = newlen;
2570 if (len > table->maxlen)
2571 len = table->maxlen;
2572 if(copy_from_user(table->data, newval, len))
2574 if (len == table->maxlen)
2576 ((char *) table->data)[len] = 0;
2582 * This function makes sure that all of the integers in the vector
2583 * are between the minimum and maximum values given in the arrays
2584 * table->extra1 and table->extra2, respectively.
2586 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2587 void __user *oldval, size_t __user *oldlenp,
2588 void __user *newval, size_t newlen, void **context)
2591 if (newval && newlen) {
2592 int __user *vec = (int __user *) newval;
2593 int *min = (int *) table->extra1;
2594 int *max = (int *) table->extra2;
2598 if (newlen % sizeof(int) != 0)
2601 if (!table->extra1 && !table->extra2)
2604 if (newlen > table->maxlen)
2605 newlen = table->maxlen;
2606 length = newlen / sizeof(int);
2608 for (i = 0; i < length; i++) {
2610 if (get_user(value, vec + i))
2612 if (min && value < min[i])
2614 if (max && value > max[i])
2621 /* Strategy function to convert jiffies to seconds */
2622 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2623 void __user *oldval, size_t __user *oldlenp,
2624 void __user *newval, size_t newlen, void **context)
2629 if (get_user(olen, oldlenp))
2631 if (olen!=sizeof(int))
2634 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2635 (oldlenp && put_user(sizeof(int),oldlenp)))
2638 if (newval && newlen) {
2640 if (newlen != sizeof(int))
2642 if (get_user(new, (int __user *)newval))
2644 *(int *)(table->data) = new*HZ;
2649 /* Strategy function to convert jiffies to seconds */
2650 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2651 void __user *oldval, size_t __user *oldlenp,
2652 void __user *newval, size_t newlen, void **context)
2657 if (get_user(olen, oldlenp))
2659 if (olen!=sizeof(int))
2662 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2663 (oldlenp && put_user(sizeof(int),oldlenp)))
2666 if (newval && newlen) {
2668 if (newlen != sizeof(int))
2670 if (get_user(new, (int __user *)newval))
2672 *(int *)(table->data) = msecs_to_jiffies(new);
2677 #else /* CONFIG_SYSCTL_SYSCALL */
2680 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2682 static int msg_count;
2683 struct __sysctl_args tmp;
2684 int name[CTL_MAXNAME];
2687 /* Read in the sysctl name for better debug message logging */
2688 if (copy_from_user(&tmp, args, sizeof(tmp)))
2690 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2692 for (i = 0; i < tmp.nlen; i++)
2693 if (get_user(name[i], tmp.name + i))
2696 /* Ignore accesses to kernel.version */
2697 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2700 if (msg_count < 5) {
2703 "warning: process `%s' used the removed sysctl "
2704 "system call with ", current->comm);
2705 for (i = 0; i < tmp.nlen; i++)
2706 printk("%d.", name[i]);
2713 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2714 void __user *oldval, size_t __user *oldlenp,
2715 void __user *newval, size_t newlen, void **context)
2720 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2721 void __user *oldval, size_t __user *oldlenp,
2722 void __user *newval, size_t newlen, void **context)
2727 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2728 void __user *oldval, size_t __user *oldlenp,
2729 void __user *newval, size_t newlen, void **context)
2734 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2735 void __user *oldval, size_t __user *oldlenp,
2736 void __user *newval, size_t newlen, void **context)
2741 #endif /* CONFIG_SYSCTL_SYSCALL */
2744 * No sense putting this after each symbol definition, twice,
2745 * exception granted :-)
2747 EXPORT_SYMBOL(proc_dointvec);
2748 EXPORT_SYMBOL(proc_dointvec_jiffies);
2749 EXPORT_SYMBOL(proc_dointvec_minmax);
2750 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2751 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2752 EXPORT_SYMBOL(proc_dostring);
2753 EXPORT_SYMBOL(proc_doulongvec_minmax);
2754 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2755 EXPORT_SYMBOL(register_sysctl_table);
2756 EXPORT_SYMBOL(sysctl_intvec);
2757 EXPORT_SYMBOL(sysctl_jiffies);
2758 EXPORT_SYMBOL(sysctl_ms_jiffies);
2759 EXPORT_SYMBOL(sysctl_string);
2760 EXPORT_SYMBOL(unregister_sysctl_table);