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[];
73 extern int min_free_kbytes;
74 extern int printk_ratelimit_jiffies;
75 extern int printk_ratelimit_burst;
76 extern int pid_max_min, pid_max_max;
77 extern int sysctl_drop_caches;
78 extern int percpu_pagelist_fraction;
79 extern int compat_log;
81 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
82 static int maxolduid = 65535;
84 static int min_percpu_pagelist_fract = 8;
86 static int ngroups_max = NGROUPS_MAX;
89 extern char modprobe_path[];
91 #ifdef CONFIG_CHR_DEV_SG
92 extern int sg_big_buff;
95 static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
96 void __user *buffer, size_t *lenp, loff_t *ppos);
100 extern char reboot_command [];
101 extern int stop_a_enabled;
102 extern int scons_pwroff;
106 extern int pwrsw_enabled;
107 extern int unaligned_enabled;
111 #ifdef CONFIG_MATHEMU
112 extern int sysctl_ieee_emulation_warnings;
114 extern int sysctl_userprocess_debug;
115 extern int spin_retry;
118 extern int sysctl_hz_timer;
120 #ifdef CONFIG_BSD_PROCESS_ACCT
121 extern int acct_parm[];
125 extern int no_unaligned_warning;
128 #ifdef CONFIG_RT_MUTEXES
129 extern int max_lock_depth;
132 #ifdef CONFIG_SYSCTL_SYSCALL
133 static int parse_table(int __user *, int, void __user *, size_t __user *,
134 void __user *, size_t, ctl_table *, void **);
137 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
138 void __user *buffer, size_t *lenp, loff_t *ppos);
140 static ctl_table root_table[];
141 static struct ctl_table_header root_table_header =
142 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
144 static ctl_table kern_table[];
145 static ctl_table vm_table[];
146 static ctl_table fs_table[];
147 static ctl_table debug_table[];
148 static ctl_table dev_table[];
149 extern ctl_table random_table[];
150 #ifdef CONFIG_UNIX98_PTYS
151 extern ctl_table pty_table[];
153 #ifdef CONFIG_INOTIFY_USER
154 extern ctl_table inotify_table[];
157 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
158 int sysctl_legacy_va_layout;
161 /* /proc declarations: */
163 #ifdef CONFIG_PROC_SYSCTL
165 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
166 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
167 static int proc_opensys(struct inode *, struct file *);
169 struct file_operations proc_sys_file_operations = {
170 .open = proc_opensys,
171 .read = proc_readsys,
172 .write = proc_writesys,
175 extern struct proc_dir_entry *proc_sys_root;
177 static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
178 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
181 /* The default sysctl tables: */
183 static ctl_table root_table[] = {
185 .ctl_name = CTL_KERN,
186 .procname = "kernel",
211 .ctl_name = CTL_DEBUG,
214 .child = debug_table,
226 static ctl_table kern_table[] = {
227 #ifndef CONFIG_UTS_NS
229 .ctl_name = KERN_OSTYPE,
230 .procname = "ostype",
231 .data = init_uts_ns.name.sysname,
232 .maxlen = sizeof(init_uts_ns.name.sysname),
234 .proc_handler = &proc_do_uts_string,
235 .strategy = &sysctl_string,
238 .ctl_name = KERN_OSRELEASE,
239 .procname = "osrelease",
240 .data = init_uts_ns.name.release,
241 .maxlen = sizeof(init_uts_ns.name.release),
243 .proc_handler = &proc_do_uts_string,
244 .strategy = &sysctl_string,
247 .ctl_name = KERN_VERSION,
248 .procname = "version",
249 .data = init_uts_ns.name.version,
250 .maxlen = sizeof(init_uts_ns.name.version),
252 .proc_handler = &proc_do_uts_string,
253 .strategy = &sysctl_string,
256 .ctl_name = KERN_NODENAME,
257 .procname = "hostname",
258 .data = init_uts_ns.name.nodename,
259 .maxlen = sizeof(init_uts_ns.name.nodename),
261 .proc_handler = &proc_do_uts_string,
262 .strategy = &sysctl_string,
265 .ctl_name = KERN_DOMAINNAME,
266 .procname = "domainname",
267 .data = init_uts_ns.name.domainname,
268 .maxlen = sizeof(init_uts_ns.name.domainname),
270 .proc_handler = &proc_do_uts_string,
271 .strategy = &sysctl_string,
273 #else /* !CONFIG_UTS_NS */
275 .ctl_name = KERN_OSTYPE,
276 .procname = "ostype",
278 /* could maybe use __NEW_UTS_LEN here? */
279 .maxlen = FIELD_SIZEOF(struct new_utsname, sysname),
281 .proc_handler = &proc_do_uts_string,
282 .strategy = &sysctl_string,
285 .ctl_name = KERN_OSRELEASE,
286 .procname = "osrelease",
288 .maxlen = FIELD_SIZEOF(struct new_utsname, release),
290 .proc_handler = &proc_do_uts_string,
291 .strategy = &sysctl_string,
294 .ctl_name = KERN_VERSION,
295 .procname = "version",
297 .maxlen = FIELD_SIZEOF(struct new_utsname, version),
299 .proc_handler = &proc_do_uts_string,
300 .strategy = &sysctl_string,
303 .ctl_name = KERN_NODENAME,
304 .procname = "hostname",
306 .maxlen = FIELD_SIZEOF(struct new_utsname, nodename),
308 .proc_handler = &proc_do_uts_string,
309 .strategy = &sysctl_string,
312 .ctl_name = KERN_DOMAINNAME,
313 .procname = "domainname",
315 .maxlen = FIELD_SIZEOF(struct new_utsname, domainname),
317 .proc_handler = &proc_do_uts_string,
318 .strategy = &sysctl_string,
320 #endif /* !CONFIG_UTS_NS */
322 .ctl_name = KERN_PANIC,
324 .data = &panic_timeout,
325 .maxlen = sizeof(int),
327 .proc_handler = &proc_dointvec,
330 .ctl_name = KERN_CORE_USES_PID,
331 .procname = "core_uses_pid",
332 .data = &core_uses_pid,
333 .maxlen = sizeof(int),
335 .proc_handler = &proc_dointvec,
338 .ctl_name = KERN_CORE_PATTERN,
339 .procname = "core_pattern",
340 .data = core_pattern,
343 .proc_handler = &proc_dostring,
344 .strategy = &sysctl_string,
347 .ctl_name = KERN_TAINTED,
348 .procname = "tainted",
350 .maxlen = sizeof(int),
352 .proc_handler = &proc_dointvec,
355 .ctl_name = KERN_CAP_BSET,
356 .procname = "cap-bound",
358 .maxlen = sizeof(kernel_cap_t),
360 .proc_handler = &proc_dointvec_bset,
362 #ifdef CONFIG_BLK_DEV_INITRD
364 .ctl_name = KERN_REALROOTDEV,
365 .procname = "real-root-dev",
366 .data = &real_root_dev,
367 .maxlen = sizeof(int),
369 .proc_handler = &proc_dointvec,
374 .ctl_name = KERN_SPARC_REBOOT,
375 .procname = "reboot-cmd",
376 .data = reboot_command,
379 .proc_handler = &proc_dostring,
380 .strategy = &sysctl_string,
383 .ctl_name = KERN_SPARC_STOP_A,
384 .procname = "stop-a",
385 .data = &stop_a_enabled,
386 .maxlen = sizeof (int),
388 .proc_handler = &proc_dointvec,
391 .ctl_name = KERN_SPARC_SCONS_PWROFF,
392 .procname = "scons-poweroff",
393 .data = &scons_pwroff,
394 .maxlen = sizeof (int),
396 .proc_handler = &proc_dointvec,
401 .ctl_name = KERN_HPPA_PWRSW,
402 .procname = "soft-power",
403 .data = &pwrsw_enabled,
404 .maxlen = sizeof (int),
406 .proc_handler = &proc_dointvec,
409 .ctl_name = KERN_HPPA_UNALIGNED,
410 .procname = "unaligned-trap",
411 .data = &unaligned_enabled,
412 .maxlen = sizeof (int),
414 .proc_handler = &proc_dointvec,
418 .ctl_name = KERN_CTLALTDEL,
419 .procname = "ctrl-alt-del",
421 .maxlen = sizeof(int),
423 .proc_handler = &proc_dointvec,
426 .ctl_name = KERN_PRINTK,
427 .procname = "printk",
428 .data = &console_loglevel,
429 .maxlen = 4*sizeof(int),
431 .proc_handler = &proc_dointvec,
435 .ctl_name = KERN_MODPROBE,
436 .procname = "modprobe",
437 .data = &modprobe_path,
438 .maxlen = KMOD_PATH_LEN,
440 .proc_handler = &proc_dostring,
441 .strategy = &sysctl_string,
444 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
446 .ctl_name = KERN_HOTPLUG,
447 .procname = "hotplug",
448 .data = &uevent_helper,
449 .maxlen = UEVENT_HELPER_PATH_LEN,
451 .proc_handler = &proc_dostring,
452 .strategy = &sysctl_string,
455 #ifdef CONFIG_CHR_DEV_SG
457 .ctl_name = KERN_SG_BIG_BUFF,
458 .procname = "sg-big-buff",
459 .data = &sg_big_buff,
460 .maxlen = sizeof (int),
462 .proc_handler = &proc_dointvec,
465 #ifdef CONFIG_BSD_PROCESS_ACCT
467 .ctl_name = KERN_ACCT,
470 .maxlen = 3*sizeof(int),
472 .proc_handler = &proc_dointvec,
475 #ifdef CONFIG_SYSVIPC
477 .ctl_name = KERN_SHMMAX,
478 .procname = "shmmax",
480 .maxlen = sizeof (size_t),
482 .proc_handler = &proc_do_ipc_string,
485 .ctl_name = KERN_SHMALL,
486 .procname = "shmall",
488 .maxlen = sizeof (size_t),
490 .proc_handler = &proc_do_ipc_string,
493 .ctl_name = KERN_SHMMNI,
494 .procname = "shmmni",
496 .maxlen = sizeof (int),
498 .proc_handler = &proc_do_ipc_string,
501 .ctl_name = KERN_MSGMAX,
502 .procname = "msgmax",
504 .maxlen = sizeof (int),
506 .proc_handler = &proc_do_ipc_string,
509 .ctl_name = KERN_MSGMNI,
510 .procname = "msgmni",
512 .maxlen = sizeof (int),
514 .proc_handler = &proc_do_ipc_string,
517 .ctl_name = KERN_MSGMNB,
518 .procname = "msgmnb",
520 .maxlen = sizeof (int),
522 .proc_handler = &proc_do_ipc_string,
525 .ctl_name = KERN_SEM,
528 .maxlen = 4*sizeof (int),
530 .proc_handler = &proc_do_ipc_string,
533 #ifdef CONFIG_MAGIC_SYSRQ
535 .ctl_name = KERN_SYSRQ,
537 .data = &sysrq_enabled,
538 .maxlen = sizeof (int),
540 .proc_handler = &proc_dointvec,
544 .ctl_name = KERN_CADPID,
545 .procname = "cad_pid",
547 .maxlen = sizeof (int),
549 .proc_handler = &proc_dointvec,
552 .ctl_name = KERN_MAX_THREADS,
553 .procname = "threads-max",
554 .data = &max_threads,
555 .maxlen = sizeof(int),
557 .proc_handler = &proc_dointvec,
560 .ctl_name = KERN_RANDOM,
561 .procname = "random",
563 .child = random_table,
565 #ifdef CONFIG_UNIX98_PTYS
567 .ctl_name = KERN_PTY,
574 .ctl_name = KERN_OVERFLOWUID,
575 .procname = "overflowuid",
576 .data = &overflowuid,
577 .maxlen = sizeof(int),
579 .proc_handler = &proc_dointvec_minmax,
580 .strategy = &sysctl_intvec,
581 .extra1 = &minolduid,
582 .extra2 = &maxolduid,
585 .ctl_name = KERN_OVERFLOWGID,
586 .procname = "overflowgid",
587 .data = &overflowgid,
588 .maxlen = sizeof(int),
590 .proc_handler = &proc_dointvec_minmax,
591 .strategy = &sysctl_intvec,
592 .extra1 = &minolduid,
593 .extra2 = &maxolduid,
596 #ifdef CONFIG_MATHEMU
598 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
599 .procname = "ieee_emulation_warnings",
600 .data = &sysctl_ieee_emulation_warnings,
601 .maxlen = sizeof(int),
603 .proc_handler = &proc_dointvec,
606 #ifdef CONFIG_NO_IDLE_HZ
608 .ctl_name = KERN_HZ_TIMER,
609 .procname = "hz_timer",
610 .data = &sysctl_hz_timer,
611 .maxlen = sizeof(int),
613 .proc_handler = &proc_dointvec,
617 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
618 .procname = "userprocess_debug",
619 .data = &sysctl_userprocess_debug,
620 .maxlen = sizeof(int),
622 .proc_handler = &proc_dointvec,
626 .ctl_name = KERN_PIDMAX,
627 .procname = "pid_max",
629 .maxlen = sizeof (int),
631 .proc_handler = &proc_dointvec_minmax,
632 .strategy = sysctl_intvec,
633 .extra1 = &pid_max_min,
634 .extra2 = &pid_max_max,
637 .ctl_name = KERN_PANIC_ON_OOPS,
638 .procname = "panic_on_oops",
639 .data = &panic_on_oops,
640 .maxlen = sizeof(int),
642 .proc_handler = &proc_dointvec,
645 .ctl_name = KERN_PRINTK_RATELIMIT,
646 .procname = "printk_ratelimit",
647 .data = &printk_ratelimit_jiffies,
648 .maxlen = sizeof(int),
650 .proc_handler = &proc_dointvec_jiffies,
651 .strategy = &sysctl_jiffies,
654 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
655 .procname = "printk_ratelimit_burst",
656 .data = &printk_ratelimit_burst,
657 .maxlen = sizeof(int),
659 .proc_handler = &proc_dointvec,
662 .ctl_name = KERN_NGROUPS_MAX,
663 .procname = "ngroups_max",
664 .data = &ngroups_max,
665 .maxlen = sizeof (int),
667 .proc_handler = &proc_dointvec,
669 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
671 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
672 .procname = "unknown_nmi_panic",
673 .data = &unknown_nmi_panic,
674 .maxlen = sizeof (int),
676 .proc_handler = &proc_dointvec,
679 .ctl_name = KERN_NMI_WATCHDOG,
680 .procname = "nmi_watchdog",
681 .data = &nmi_watchdog_enabled,
682 .maxlen = sizeof (int),
684 .proc_handler = &proc_nmi_enabled,
687 #if defined(CONFIG_X86)
689 .ctl_name = KERN_PANIC_ON_NMI,
690 .procname = "panic_on_unrecovered_nmi",
691 .data = &panic_on_unrecovered_nmi,
692 .maxlen = sizeof(int),
694 .proc_handler = &proc_dointvec,
697 .ctl_name = KERN_BOOTLOADER_TYPE,
698 .procname = "bootloader_type",
699 .data = &bootloader_type,
700 .maxlen = sizeof (int),
702 .proc_handler = &proc_dointvec,
705 #if defined(CONFIG_MMU)
707 .ctl_name = KERN_RANDOMIZE,
708 .procname = "randomize_va_space",
709 .data = &randomize_va_space,
710 .maxlen = sizeof(int),
712 .proc_handler = &proc_dointvec,
715 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
717 .ctl_name = KERN_SPIN_RETRY,
718 .procname = "spin_retry",
720 .maxlen = sizeof (int),
722 .proc_handler = &proc_dointvec,
725 #ifdef CONFIG_ACPI_SLEEP
727 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
728 .procname = "acpi_video_flags",
729 .data = &acpi_video_flags,
730 .maxlen = sizeof (unsigned long),
732 .proc_handler = &proc_doulongvec_minmax,
737 .ctl_name = KERN_IA64_UNALIGNED,
738 .procname = "ignore-unaligned-usertrap",
739 .data = &no_unaligned_warning,
740 .maxlen = sizeof (int),
742 .proc_handler = &proc_dointvec,
747 .ctl_name = KERN_COMPAT_LOG,
748 .procname = "compat-log",
750 .maxlen = sizeof (int),
752 .proc_handler = &proc_dointvec,
755 #ifdef CONFIG_RT_MUTEXES
757 .ctl_name = KERN_MAX_LOCK_DEPTH,
758 .procname = "max_lock_depth",
759 .data = &max_lock_depth,
760 .maxlen = sizeof(int),
762 .proc_handler = &proc_dointvec,
769 /* Constants for minimum and maximum testing in vm_table.
770 We use these as one-element integer vectors. */
772 static int one_hundred = 100;
775 static ctl_table vm_table[] = {
777 .ctl_name = VM_OVERCOMMIT_MEMORY,
778 .procname = "overcommit_memory",
779 .data = &sysctl_overcommit_memory,
780 .maxlen = sizeof(sysctl_overcommit_memory),
782 .proc_handler = &proc_dointvec,
785 .ctl_name = VM_PANIC_ON_OOM,
786 .procname = "panic_on_oom",
787 .data = &sysctl_panic_on_oom,
788 .maxlen = sizeof(sysctl_panic_on_oom),
790 .proc_handler = &proc_dointvec,
793 .ctl_name = VM_OVERCOMMIT_RATIO,
794 .procname = "overcommit_ratio",
795 .data = &sysctl_overcommit_ratio,
796 .maxlen = sizeof(sysctl_overcommit_ratio),
798 .proc_handler = &proc_dointvec,
801 .ctl_name = VM_PAGE_CLUSTER,
802 .procname = "page-cluster",
803 .data = &page_cluster,
804 .maxlen = sizeof(int),
806 .proc_handler = &proc_dointvec,
809 .ctl_name = VM_DIRTY_BACKGROUND,
810 .procname = "dirty_background_ratio",
811 .data = &dirty_background_ratio,
812 .maxlen = sizeof(dirty_background_ratio),
814 .proc_handler = &proc_dointvec_minmax,
815 .strategy = &sysctl_intvec,
817 .extra2 = &one_hundred,
820 .ctl_name = VM_DIRTY_RATIO,
821 .procname = "dirty_ratio",
822 .data = &vm_dirty_ratio,
823 .maxlen = sizeof(vm_dirty_ratio),
825 .proc_handler = &proc_dointvec_minmax,
826 .strategy = &sysctl_intvec,
828 .extra2 = &one_hundred,
831 .ctl_name = VM_DIRTY_WB_CS,
832 .procname = "dirty_writeback_centisecs",
833 .data = &dirty_writeback_interval,
834 .maxlen = sizeof(dirty_writeback_interval),
836 .proc_handler = &dirty_writeback_centisecs_handler,
839 .ctl_name = VM_DIRTY_EXPIRE_CS,
840 .procname = "dirty_expire_centisecs",
841 .data = &dirty_expire_interval,
842 .maxlen = sizeof(dirty_expire_interval),
844 .proc_handler = &proc_dointvec_userhz_jiffies,
847 .ctl_name = VM_NR_PDFLUSH_THREADS,
848 .procname = "nr_pdflush_threads",
849 .data = &nr_pdflush_threads,
850 .maxlen = sizeof nr_pdflush_threads,
851 .mode = 0444 /* read-only*/,
852 .proc_handler = &proc_dointvec,
855 .ctl_name = VM_SWAPPINESS,
856 .procname = "swappiness",
857 .data = &vm_swappiness,
858 .maxlen = sizeof(vm_swappiness),
860 .proc_handler = &proc_dointvec_minmax,
861 .strategy = &sysctl_intvec,
863 .extra2 = &one_hundred,
865 #ifdef CONFIG_HUGETLB_PAGE
867 .ctl_name = VM_HUGETLB_PAGES,
868 .procname = "nr_hugepages",
869 .data = &max_huge_pages,
870 .maxlen = sizeof(unsigned long),
872 .proc_handler = &hugetlb_sysctl_handler,
873 .extra1 = (void *)&hugetlb_zero,
874 .extra2 = (void *)&hugetlb_infinity,
877 .ctl_name = VM_HUGETLB_GROUP,
878 .procname = "hugetlb_shm_group",
879 .data = &sysctl_hugetlb_shm_group,
880 .maxlen = sizeof(gid_t),
882 .proc_handler = &proc_dointvec,
886 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
887 .procname = "lowmem_reserve_ratio",
888 .data = &sysctl_lowmem_reserve_ratio,
889 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
891 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
892 .strategy = &sysctl_intvec,
895 .ctl_name = VM_DROP_PAGECACHE,
896 .procname = "drop_caches",
897 .data = &sysctl_drop_caches,
898 .maxlen = sizeof(int),
900 .proc_handler = drop_caches_sysctl_handler,
901 .strategy = &sysctl_intvec,
904 .ctl_name = VM_MIN_FREE_KBYTES,
905 .procname = "min_free_kbytes",
906 .data = &min_free_kbytes,
907 .maxlen = sizeof(min_free_kbytes),
909 .proc_handler = &min_free_kbytes_sysctl_handler,
910 .strategy = &sysctl_intvec,
914 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
915 .procname = "percpu_pagelist_fraction",
916 .data = &percpu_pagelist_fraction,
917 .maxlen = sizeof(percpu_pagelist_fraction),
919 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
920 .strategy = &sysctl_intvec,
921 .extra1 = &min_percpu_pagelist_fract,
925 .ctl_name = VM_MAX_MAP_COUNT,
926 .procname = "max_map_count",
927 .data = &sysctl_max_map_count,
928 .maxlen = sizeof(sysctl_max_map_count),
930 .proc_handler = &proc_dointvec
934 .ctl_name = VM_LAPTOP_MODE,
935 .procname = "laptop_mode",
936 .data = &laptop_mode,
937 .maxlen = sizeof(laptop_mode),
939 .proc_handler = &proc_dointvec_jiffies,
940 .strategy = &sysctl_jiffies,
943 .ctl_name = VM_BLOCK_DUMP,
944 .procname = "block_dump",
946 .maxlen = sizeof(block_dump),
948 .proc_handler = &proc_dointvec,
949 .strategy = &sysctl_intvec,
953 .ctl_name = VM_VFS_CACHE_PRESSURE,
954 .procname = "vfs_cache_pressure",
955 .data = &sysctl_vfs_cache_pressure,
956 .maxlen = sizeof(sysctl_vfs_cache_pressure),
958 .proc_handler = &proc_dointvec,
959 .strategy = &sysctl_intvec,
962 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
964 .ctl_name = VM_LEGACY_VA_LAYOUT,
965 .procname = "legacy_va_layout",
966 .data = &sysctl_legacy_va_layout,
967 .maxlen = sizeof(sysctl_legacy_va_layout),
969 .proc_handler = &proc_dointvec,
970 .strategy = &sysctl_intvec,
976 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
977 .procname = "swap_token_timeout",
978 .data = &swap_token_default_timeout,
979 .maxlen = sizeof(swap_token_default_timeout),
981 .proc_handler = &proc_dointvec_jiffies,
982 .strategy = &sysctl_jiffies,
987 .ctl_name = VM_ZONE_RECLAIM_MODE,
988 .procname = "zone_reclaim_mode",
989 .data = &zone_reclaim_mode,
990 .maxlen = sizeof(zone_reclaim_mode),
992 .proc_handler = &proc_dointvec,
993 .strategy = &sysctl_intvec,
997 .ctl_name = VM_MIN_UNMAPPED,
998 .procname = "min_unmapped_ratio",
999 .data = &sysctl_min_unmapped_ratio,
1000 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1002 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1003 .strategy = &sysctl_intvec,
1005 .extra2 = &one_hundred,
1008 .ctl_name = VM_MIN_SLAB,
1009 .procname = "min_slab_ratio",
1010 .data = &sysctl_min_slab_ratio,
1011 .maxlen = sizeof(sysctl_min_slab_ratio),
1013 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1014 .strategy = &sysctl_intvec,
1016 .extra2 = &one_hundred,
1019 #ifdef CONFIG_X86_32
1021 .ctl_name = VM_VDSO_ENABLED,
1022 .procname = "vdso_enabled",
1023 .data = &vdso_enabled,
1024 .maxlen = sizeof(vdso_enabled),
1026 .proc_handler = &proc_dointvec,
1027 .strategy = &sysctl_intvec,
1034 static ctl_table fs_table[] = {
1036 .ctl_name = FS_NRINODE,
1037 .procname = "inode-nr",
1038 .data = &inodes_stat,
1039 .maxlen = 2*sizeof(int),
1041 .proc_handler = &proc_dointvec,
1044 .ctl_name = FS_STATINODE,
1045 .procname = "inode-state",
1046 .data = &inodes_stat,
1047 .maxlen = 7*sizeof(int),
1049 .proc_handler = &proc_dointvec,
1052 .ctl_name = FS_NRFILE,
1053 .procname = "file-nr",
1054 .data = &files_stat,
1055 .maxlen = 3*sizeof(int),
1057 .proc_handler = &proc_nr_files,
1060 .ctl_name = FS_MAXFILE,
1061 .procname = "file-max",
1062 .data = &files_stat.max_files,
1063 .maxlen = sizeof(int),
1065 .proc_handler = &proc_dointvec,
1068 .ctl_name = FS_DENTRY,
1069 .procname = "dentry-state",
1070 .data = &dentry_stat,
1071 .maxlen = 6*sizeof(int),
1073 .proc_handler = &proc_dointvec,
1076 .ctl_name = FS_OVERFLOWUID,
1077 .procname = "overflowuid",
1078 .data = &fs_overflowuid,
1079 .maxlen = sizeof(int),
1081 .proc_handler = &proc_dointvec_minmax,
1082 .strategy = &sysctl_intvec,
1083 .extra1 = &minolduid,
1084 .extra2 = &maxolduid,
1087 .ctl_name = FS_OVERFLOWGID,
1088 .procname = "overflowgid",
1089 .data = &fs_overflowgid,
1090 .maxlen = sizeof(int),
1092 .proc_handler = &proc_dointvec_minmax,
1093 .strategy = &sysctl_intvec,
1094 .extra1 = &minolduid,
1095 .extra2 = &maxolduid,
1098 .ctl_name = FS_LEASES,
1099 .procname = "leases-enable",
1100 .data = &leases_enable,
1101 .maxlen = sizeof(int),
1103 .proc_handler = &proc_dointvec,
1105 #ifdef CONFIG_DNOTIFY
1107 .ctl_name = FS_DIR_NOTIFY,
1108 .procname = "dir-notify-enable",
1109 .data = &dir_notify_enable,
1110 .maxlen = sizeof(int),
1112 .proc_handler = &proc_dointvec,
1117 .ctl_name = FS_LEASE_TIME,
1118 .procname = "lease-break-time",
1119 .data = &lease_break_time,
1120 .maxlen = sizeof(int),
1122 .proc_handler = &proc_dointvec,
1125 .ctl_name = FS_AIO_NR,
1126 .procname = "aio-nr",
1128 .maxlen = sizeof(aio_nr),
1130 .proc_handler = &proc_doulongvec_minmax,
1133 .ctl_name = FS_AIO_MAX_NR,
1134 .procname = "aio-max-nr",
1135 .data = &aio_max_nr,
1136 .maxlen = sizeof(aio_max_nr),
1138 .proc_handler = &proc_doulongvec_minmax,
1140 #ifdef CONFIG_INOTIFY_USER
1142 .ctl_name = FS_INOTIFY,
1143 .procname = "inotify",
1145 .child = inotify_table,
1150 .ctl_name = KERN_SETUID_DUMPABLE,
1151 .procname = "suid_dumpable",
1152 .data = &suid_dumpable,
1153 .maxlen = sizeof(int),
1155 .proc_handler = &proc_dointvec,
1160 static ctl_table debug_table[] = {
1164 static ctl_table dev_table[] = {
1168 extern void init_irq_proc (void);
1170 static DEFINE_SPINLOCK(sysctl_lock);
1172 /* called under sysctl_lock */
1173 static int use_table(struct ctl_table_header *p)
1175 if (unlikely(p->unregistering))
1181 /* called under sysctl_lock */
1182 static void unuse_table(struct ctl_table_header *p)
1185 if (unlikely(p->unregistering))
1186 complete(p->unregistering);
1189 /* called under sysctl_lock, will reacquire if has to wait */
1190 static void start_unregistering(struct ctl_table_header *p)
1193 * if p->used is 0, nobody will ever touch that entry again;
1194 * we'll eliminate all paths to it before dropping sysctl_lock
1196 if (unlikely(p->used)) {
1197 struct completion wait;
1198 init_completion(&wait);
1199 p->unregistering = &wait;
1200 spin_unlock(&sysctl_lock);
1201 wait_for_completion(&wait);
1202 spin_lock(&sysctl_lock);
1205 * do not remove from the list until nobody holds it; walking the
1206 * list in do_sysctl() relies on that.
1208 list_del_init(&p->ctl_entry);
1211 void __init sysctl_init(void)
1213 #ifdef CONFIG_PROC_SYSCTL
1214 register_proc_table(root_table, proc_sys_root, &root_table_header);
1219 #ifdef CONFIG_SYSCTL_SYSCALL
1220 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1221 void __user *newval, size_t newlen)
1223 struct list_head *tmp;
1224 int error = -ENOTDIR;
1226 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1230 if (!oldlenp || get_user(old_len, oldlenp))
1233 spin_lock(&sysctl_lock);
1234 tmp = &root_table_header.ctl_entry;
1236 struct ctl_table_header *head =
1237 list_entry(tmp, struct ctl_table_header, ctl_entry);
1238 void *context = NULL;
1240 if (!use_table(head))
1243 spin_unlock(&sysctl_lock);
1245 error = parse_table(name, nlen, oldval, oldlenp,
1246 newval, newlen, head->ctl_table,
1250 spin_lock(&sysctl_lock);
1252 if (error != -ENOTDIR)
1254 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1255 spin_unlock(&sysctl_lock);
1259 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1261 struct __sysctl_args tmp;
1264 if (copy_from_user(&tmp, args, sizeof(tmp)))
1268 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1269 tmp.newval, tmp.newlen);
1273 #endif /* CONFIG_SYSCTL_SYSCALL */
1276 * ctl_perm does NOT grant the superuser all rights automatically, because
1277 * some sysctl variables are readonly even to root.
1280 static int test_perm(int mode, int op)
1284 else if (in_egroup_p(0))
1286 if ((mode & op & 0007) == op)
1291 static inline int ctl_perm(ctl_table *table, int op)
1294 error = security_sysctl(table, op);
1297 return test_perm(table->mode, op);
1300 #ifdef CONFIG_SYSCTL_SYSCALL
1301 static int parse_table(int __user *name, int nlen,
1302 void __user *oldval, size_t __user *oldlenp,
1303 void __user *newval, size_t newlen,
1304 ctl_table *table, void **context)
1310 if (get_user(n, name))
1312 for ( ; table->ctl_name; table++) {
1313 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1316 if (ctl_perm(table, 001))
1318 if (table->strategy) {
1319 error = table->strategy(
1322 newval, newlen, context);
1328 table = table->child;
1331 error = do_sysctl_strategy(table, name, nlen,
1333 newval, newlen, context);
1340 /* Perform the actual read/write of a sysctl table entry. */
1341 int do_sysctl_strategy (ctl_table *table,
1342 int __user *name, int nlen,
1343 void __user *oldval, size_t __user *oldlenp,
1344 void __user *newval, size_t newlen, void **context)
1353 if (ctl_perm(table, op))
1356 if (table->strategy) {
1357 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1358 newval, newlen, context);
1365 /* If there is no strategy routine, or if the strategy returns
1366 * zero, proceed with automatic r/w */
1367 if (table->data && table->maxlen) {
1368 if (oldval && oldlenp) {
1369 if (get_user(len, oldlenp))
1372 if (len > table->maxlen)
1373 len = table->maxlen;
1374 if(copy_to_user(oldval, table->data, len))
1376 if(put_user(len, oldlenp))
1380 if (newval && newlen) {
1382 if (len > table->maxlen)
1383 len = table->maxlen;
1384 if(copy_from_user(table->data, newval, len))
1390 #endif /* CONFIG_SYSCTL_SYSCALL */
1393 * register_sysctl_table - register a sysctl hierarchy
1394 * @table: the top-level table structure
1395 * @insert_at_head: whether the entry should be inserted in front or at the end
1397 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1398 * array. An entry with a ctl_name of 0 terminates the table.
1400 * The members of the &ctl_table structure are used as follows:
1402 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1403 * must be unique within that level of sysctl
1405 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1406 * enter a sysctl file
1408 * data - a pointer to data for use by proc_handler
1410 * maxlen - the maximum size in bytes of the data
1412 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1414 * child - a pointer to the child sysctl table if this entry is a directory, or
1417 * proc_handler - the text handler routine (described below)
1419 * strategy - the strategy routine (described below)
1421 * de - for internal use by the sysctl routines
1423 * extra1, extra2 - extra pointers usable by the proc handler routines
1425 * Leaf nodes in the sysctl tree will be represented by a single file
1426 * under /proc; non-leaf nodes will be represented by directories.
1428 * sysctl(2) can automatically manage read and write requests through
1429 * the sysctl table. The data and maxlen fields of the ctl_table
1430 * struct enable minimal validation of the values being written to be
1431 * performed, and the mode field allows minimal authentication.
1433 * More sophisticated management can be enabled by the provision of a
1434 * strategy routine with the table entry. This will be called before
1435 * any automatic read or write of the data is performed.
1437 * The strategy routine may return
1439 * < 0 - Error occurred (error is passed to user process)
1441 * 0 - OK - proceed with automatic read or write.
1443 * > 0 - OK - read or write has been done by the strategy routine, so
1444 * return immediately.
1446 * There must be a proc_handler routine for any terminal nodes
1447 * mirrored under /proc/sys (non-terminals are handled by a built-in
1448 * directory handler). Several default handlers are available to
1449 * cover common cases -
1451 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1452 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1453 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1455 * It is the handler's job to read the input buffer from user memory
1456 * and process it. The handler should return 0 on success.
1458 * This routine returns %NULL on a failure to register, and a pointer
1459 * to the table header on success.
1461 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1464 struct ctl_table_header *tmp;
1465 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1468 tmp->ctl_table = table;
1469 INIT_LIST_HEAD(&tmp->ctl_entry);
1471 tmp->unregistering = NULL;
1472 spin_lock(&sysctl_lock);
1474 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1476 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1477 spin_unlock(&sysctl_lock);
1478 #ifdef CONFIG_PROC_SYSCTL
1479 register_proc_table(table, proc_sys_root, tmp);
1485 * unregister_sysctl_table - unregister a sysctl table hierarchy
1486 * @header: the header returned from register_sysctl_table
1488 * Unregisters the sysctl table and all children. proc entries may not
1489 * actually be removed until they are no longer used by anyone.
1491 void unregister_sysctl_table(struct ctl_table_header * header)
1494 spin_lock(&sysctl_lock);
1495 start_unregistering(header);
1496 #ifdef CONFIG_PROC_SYSCTL
1497 unregister_proc_table(header->ctl_table, proc_sys_root);
1499 spin_unlock(&sysctl_lock);
1503 #else /* !CONFIG_SYSCTL */
1504 struct ctl_table_header * register_sysctl_table(ctl_table * table,
1510 void unregister_sysctl_table(struct ctl_table_header * table)
1514 #endif /* CONFIG_SYSCTL */
1520 #ifdef CONFIG_PROC_SYSCTL
1522 /* Scan the sysctl entries in table and add them all into /proc */
1523 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1525 struct proc_dir_entry *de;
1529 for (; table->ctl_name; table++) {
1530 /* Can't do anything without a proc name. */
1531 if (!table->procname)
1533 /* Maybe we can't do anything with it... */
1534 if (!table->proc_handler && !table->child) {
1535 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1540 len = strlen(table->procname);
1544 if (table->proc_handler)
1548 for (de = root->subdir; de; de = de->next) {
1549 if (proc_match(len, table->procname, de))
1552 /* If the subdir exists already, de is non-NULL */
1556 de = create_proc_entry(table->procname, mode, root);
1560 de->data = (void *) table;
1561 if (table->proc_handler)
1562 de->proc_fops = &proc_sys_file_operations;
1565 if (de->mode & S_IFDIR)
1566 register_proc_table(table->child, de, set);
1571 * Unregister a /proc sysctl table and any subdirectories.
1573 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1575 struct proc_dir_entry *de;
1576 for (; table->ctl_name; table++) {
1577 if (!(de = table->de))
1579 if (de->mode & S_IFDIR) {
1580 if (!table->child) {
1581 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1584 unregister_proc_table(table->child, de);
1586 /* Don't unregister directories which still have entries.. */
1592 * In any case, mark the entry as goner; we'll keep it
1593 * around if it's busy, but we'll know to do nothing with
1594 * its fields. We are under sysctl_lock here.
1598 /* Don't unregister proc entries that are still being used.. */
1599 if (atomic_read(&de->count))
1603 remove_proc_entry(table->procname, root);
1607 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1608 size_t count, loff_t *ppos)
1611 struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
1612 struct ctl_table *table;
1614 ssize_t error = -ENOTDIR;
1616 spin_lock(&sysctl_lock);
1617 if (de && de->data && use_table(de->set)) {
1619 * at that point we know that sysctl was not unregistered
1620 * and won't be until we finish
1622 spin_unlock(&sysctl_lock);
1623 table = (struct ctl_table *) de->data;
1624 if (!table || !table->proc_handler)
1627 op = (write ? 002 : 004);
1628 if (ctl_perm(table, op))
1631 /* careful: calling conventions are nasty here */
1633 error = (*table->proc_handler)(table, write, file,
1638 spin_lock(&sysctl_lock);
1639 unuse_table(de->set);
1641 spin_unlock(&sysctl_lock);
1645 static int proc_opensys(struct inode *inode, struct file *file)
1647 if (file->f_mode & FMODE_WRITE) {
1649 * sysctl entries that are not writable,
1650 * are _NOT_ writable, capabilities or not.
1652 if (!(inode->i_mode & S_IWUSR))
1659 static ssize_t proc_readsys(struct file * file, char __user * buf,
1660 size_t count, loff_t *ppos)
1662 return do_rw_proc(0, file, buf, count, ppos);
1665 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1666 size_t count, loff_t *ppos)
1668 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1671 static int _proc_do_string(void* data, int maxlen, int write,
1672 struct file *filp, void __user *buffer,
1673 size_t *lenp, loff_t *ppos)
1679 if (!data || !maxlen || !*lenp ||
1680 (*ppos && !write)) {
1688 while (len < *lenp) {
1689 if (get_user(c, p++))
1691 if (c == 0 || c == '\n')
1697 if(copy_from_user(data, buffer, len))
1699 ((char *) data)[len] = 0;
1708 if(copy_to_user(buffer, data, len))
1711 if(put_user('\n', ((char __user *) buffer) + len))
1722 * proc_dostring - read a string sysctl
1723 * @table: the sysctl table
1724 * @write: %TRUE if this is a write to the sysctl file
1725 * @filp: the file structure
1726 * @buffer: the user buffer
1727 * @lenp: the size of the user buffer
1728 * @ppos: file position
1730 * Reads/writes a string from/to the user buffer. If the kernel
1731 * buffer provided is not large enough to hold the string, the
1732 * string is truncated. The copied string is %NULL-terminated.
1733 * If the string is being read by the user process, it is copied
1734 * and a newline '\n' is added. It is truncated if the buffer is
1737 * Returns 0 on success.
1739 int proc_dostring(ctl_table *table, int write, struct file *filp,
1740 void __user *buffer, size_t *lenp, loff_t *ppos)
1742 return _proc_do_string(table->data, table->maxlen, write, filp,
1743 buffer, lenp, ppos);
1747 * Special case of dostring for the UTS structure. This has locks
1748 * to observe. Should this be in kernel/sys.c ????
1751 #ifndef CONFIG_UTS_NS
1752 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
1753 void __user *buffer, size_t *lenp, loff_t *ppos)
1758 down_read(&uts_sem);
1759 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1762 down_write(&uts_sem);
1763 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1768 #else /* !CONFIG_UTS_NS */
1769 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
1770 void __user *buffer, size_t *lenp, loff_t *ppos)
1773 struct uts_namespace* uts_ns = current->nsproxy->uts_ns;
1776 switch (table->ctl_name) {
1778 which = uts_ns->name.sysname;
1781 which = uts_ns->name.nodename;
1783 case KERN_OSRELEASE:
1784 which = uts_ns->name.release;
1787 which = uts_ns->name.version;
1789 case KERN_DOMAINNAME:
1790 which = uts_ns->name.domainname;
1798 down_read(&uts_sem);
1799 r=_proc_do_string(which,table->maxlen,0,filp,buffer,lenp, ppos);
1802 down_write(&uts_sem);
1803 r=_proc_do_string(which,table->maxlen,1,filp,buffer,lenp, ppos);
1809 #endif /* !CONFIG_UTS_NS */
1811 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1813 int write, void *data)
1816 *valp = *negp ? -*lvalp : *lvalp;
1821 *lvalp = (unsigned long)-val;
1824 *lvalp = (unsigned long)val;
1830 static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1831 int write, struct file *filp, void __user *buffer,
1832 size_t *lenp, loff_t *ppos,
1833 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1834 int write, void *data),
1837 #define TMPBUFLEN 21
1838 int *i, vleft, first=1, neg, val;
1842 char buf[TMPBUFLEN], *p;
1843 char __user *s = buffer;
1845 if (!tbl_data || !table->maxlen || !*lenp ||
1846 (*ppos && !write)) {
1851 i = (int *) tbl_data;
1852 vleft = table->maxlen / sizeof(*i);
1856 conv = do_proc_dointvec_conv;
1858 for (; left && vleft--; i++, first=0) {
1873 if (len > sizeof(buf) - 1)
1874 len = sizeof(buf) - 1;
1875 if (copy_from_user(buf, s, len))
1879 if (*p == '-' && left > 1) {
1883 if (*p < '0' || *p > '9')
1886 lval = simple_strtoul(p, &p, 0);
1889 if ((len < left) && *p && !isspace(*p))
1896 if (conv(&neg, &lval, i, 1, data))
1903 if (conv(&neg, &lval, i, 0, data))
1906 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1910 if(copy_to_user(s, buf, len))
1917 if (!write && !first && left) {
1918 if(put_user('\n', s))
1925 if (get_user(c, s++))
1940 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1941 void __user *buffer, size_t *lenp, loff_t *ppos,
1942 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1943 int write, void *data),
1946 return __do_proc_dointvec(table->data, table, write, filp,
1947 buffer, lenp, ppos, conv, data);
1951 * proc_dointvec - read a vector of integers
1952 * @table: the sysctl table
1953 * @write: %TRUE if this is a write to the sysctl file
1954 * @filp: the file structure
1955 * @buffer: the user buffer
1956 * @lenp: the size of the user buffer
1957 * @ppos: file position
1959 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1960 * values from/to the user buffer, treated as an ASCII string.
1962 * Returns 0 on success.
1964 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1965 void __user *buffer, size_t *lenp, loff_t *ppos)
1967 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1977 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1979 int write, void *data)
1981 int op = *(int *)data;
1983 int val = *negp ? -*lvalp : *lvalp;
1985 case OP_SET: *valp = val; break;
1986 case OP_AND: *valp &= val; break;
1987 case OP_OR: *valp |= val; break;
1988 case OP_MAX: if(*valp < val)
1991 case OP_MIN: if(*valp > val)
1999 *lvalp = (unsigned long)-val;
2002 *lvalp = (unsigned long)val;
2009 * init may raise the set.
2012 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2013 void __user *buffer, size_t *lenp, loff_t *ppos)
2017 if (!capable(CAP_SYS_MODULE)) {
2021 op = is_init(current) ? OP_SET : OP_AND;
2022 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2023 do_proc_dointvec_bset_conv,&op);
2026 struct do_proc_dointvec_minmax_conv_param {
2031 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2033 int write, void *data)
2035 struct do_proc_dointvec_minmax_conv_param *param = data;
2037 int val = *negp ? -*lvalp : *lvalp;
2038 if ((param->min && *param->min > val) ||
2039 (param->max && *param->max < val))
2046 *lvalp = (unsigned long)-val;
2049 *lvalp = (unsigned long)val;
2056 * proc_dointvec_minmax - read a vector of integers with min/max values
2057 * @table: the sysctl table
2058 * @write: %TRUE if this is a write to the sysctl file
2059 * @filp: the file structure
2060 * @buffer: the user buffer
2061 * @lenp: the size of the user buffer
2062 * @ppos: file position
2064 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2065 * values from/to the user buffer, treated as an ASCII string.
2067 * This routine will ensure the values are within the range specified by
2068 * table->extra1 (min) and table->extra2 (max).
2070 * Returns 0 on success.
2072 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2073 void __user *buffer, size_t *lenp, loff_t *ppos)
2075 struct do_proc_dointvec_minmax_conv_param param = {
2076 .min = (int *) table->extra1,
2077 .max = (int *) table->extra2,
2079 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2080 do_proc_dointvec_minmax_conv, ¶m);
2083 static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
2085 void __user *buffer,
2086 size_t *lenp, loff_t *ppos,
2087 unsigned long convmul,
2088 unsigned long convdiv)
2090 #define TMPBUFLEN 21
2091 unsigned long *i, *min, *max, val;
2092 int vleft, first=1, neg;
2094 char buf[TMPBUFLEN], *p;
2095 char __user *s = buffer;
2097 if (!data || !table->maxlen || !*lenp ||
2098 (*ppos && !write)) {
2103 i = (unsigned long *) data;
2104 min = (unsigned long *) table->extra1;
2105 max = (unsigned long *) table->extra2;
2106 vleft = table->maxlen / sizeof(unsigned long);
2109 for (; left && vleft--; i++, min++, max++, first=0) {
2124 if (len > TMPBUFLEN-1)
2126 if (copy_from_user(buf, s, len))
2130 if (*p == '-' && left > 1) {
2134 if (*p < '0' || *p > '9')
2136 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2138 if ((len < left) && *p && !isspace(*p))
2147 if ((min && val < *min) || (max && val > *max))
2154 sprintf(p, "%lu", convdiv * (*i) / convmul);
2158 if(copy_to_user(s, buf, len))
2165 if (!write && !first && left) {
2166 if(put_user('\n', s))
2173 if (get_user(c, s++))
2188 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2190 void __user *buffer,
2191 size_t *lenp, loff_t *ppos,
2192 unsigned long convmul,
2193 unsigned long convdiv)
2195 return __do_proc_doulongvec_minmax(table->data, table, write,
2196 filp, buffer, lenp, ppos, convmul, convdiv);
2200 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2201 * @table: the sysctl table
2202 * @write: %TRUE if this is a write to the sysctl file
2203 * @filp: the file structure
2204 * @buffer: the user buffer
2205 * @lenp: the size of the user buffer
2206 * @ppos: file position
2208 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2209 * values from/to the user buffer, treated as an ASCII string.
2211 * This routine will ensure the values are within the range specified by
2212 * table->extra1 (min) and table->extra2 (max).
2214 * Returns 0 on success.
2216 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2217 void __user *buffer, size_t *lenp, loff_t *ppos)
2219 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2223 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2224 * @table: the sysctl table
2225 * @write: %TRUE if this is a write to the sysctl file
2226 * @filp: the file structure
2227 * @buffer: the user buffer
2228 * @lenp: the size of the user buffer
2229 * @ppos: file position
2231 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2232 * values from/to the user buffer, treated as an ASCII string. The values
2233 * are treated as milliseconds, and converted to jiffies when they are stored.
2235 * This routine will ensure the values are within the range specified by
2236 * table->extra1 (min) and table->extra2 (max).
2238 * Returns 0 on success.
2240 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2242 void __user *buffer,
2243 size_t *lenp, loff_t *ppos)
2245 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2246 lenp, ppos, HZ, 1000l);
2250 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2252 int write, void *data)
2255 if (*lvalp > LONG_MAX / HZ)
2257 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2263 lval = (unsigned long)-val;
2266 lval = (unsigned long)val;
2273 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2275 int write, void *data)
2278 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2280 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2286 lval = (unsigned long)-val;
2289 lval = (unsigned long)val;
2291 *lvalp = jiffies_to_clock_t(lval);
2296 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2298 int write, void *data)
2301 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2307 lval = (unsigned long)-val;
2310 lval = (unsigned long)val;
2312 *lvalp = jiffies_to_msecs(lval);
2318 * proc_dointvec_jiffies - read a vector of integers as seconds
2319 * @table: the sysctl table
2320 * @write: %TRUE if this is a write to the sysctl file
2321 * @filp: the file structure
2322 * @buffer: the user buffer
2323 * @lenp: the size of the user buffer
2324 * @ppos: file position
2326 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2327 * values from/to the user buffer, treated as an ASCII string.
2328 * The values read are assumed to be in seconds, and are converted into
2331 * Returns 0 on success.
2333 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2334 void __user *buffer, size_t *lenp, loff_t *ppos)
2336 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2337 do_proc_dointvec_jiffies_conv,NULL);
2341 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2342 * @table: the sysctl table
2343 * @write: %TRUE if this is a write to the sysctl file
2344 * @filp: the file structure
2345 * @buffer: the user buffer
2346 * @lenp: the size of the user buffer
2347 * @ppos: pointer to the file position
2349 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2350 * values from/to the user buffer, treated as an ASCII string.
2351 * The values read are assumed to be in 1/USER_HZ seconds, and
2352 * are converted into jiffies.
2354 * Returns 0 on success.
2356 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2357 void __user *buffer, size_t *lenp, loff_t *ppos)
2359 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2360 do_proc_dointvec_userhz_jiffies_conv,NULL);
2364 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2365 * @table: the sysctl table
2366 * @write: %TRUE if this is a write to the sysctl file
2367 * @filp: the file structure
2368 * @buffer: the user buffer
2369 * @lenp: the size of the user buffer
2370 * @ppos: file position
2371 * @ppos: the current position in the file
2373 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2374 * values from/to the user buffer, treated as an ASCII string.
2375 * The values read are assumed to be in 1/1000 seconds, and
2376 * are converted into jiffies.
2378 * Returns 0 on success.
2380 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2381 void __user *buffer, size_t *lenp, loff_t *ppos)
2383 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2384 do_proc_dointvec_ms_jiffies_conv, NULL);
2387 #ifdef CONFIG_SYSVIPC
2388 static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2389 void __user *buffer, size_t *lenp, loff_t *ppos)
2392 struct ipc_namespace *ns;
2394 ns = current->nsproxy->ipc_ns;
2396 switch (table->ctl_name) {
2398 data = &ns->shm_ctlmax;
2401 data = &ns->shm_ctlall;
2404 data = &ns->shm_ctlmni;
2407 data = &ns->msg_ctlmax;
2410 data = &ns->msg_ctlmni;
2413 data = &ns->msg_ctlmnb;
2416 data = &ns->sem_ctls;
2422 return __do_proc_dointvec(data, table, write, filp, buffer,
2423 lenp, ppos, NULL, NULL);
2425 return __do_proc_doulongvec_minmax(data, table, write, filp, buffer,
2426 lenp, ppos, 1l, 1l);
2430 #else /* CONFIG_PROC_FS */
2432 int proc_dostring(ctl_table *table, int write, struct file *filp,
2433 void __user *buffer, size_t *lenp, loff_t *ppos)
2438 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
2439 void __user *buffer, size_t *lenp, loff_t *ppos)
2444 #ifdef CONFIG_SYSVIPC
2445 static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2446 void __user *buffer, size_t *lenp, loff_t *ppos)
2452 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2453 void __user *buffer, size_t *lenp, loff_t *ppos)
2458 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2459 void __user *buffer, size_t *lenp, loff_t *ppos)
2464 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2465 void __user *buffer, size_t *lenp, loff_t *ppos)
2470 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2471 void __user *buffer, size_t *lenp, loff_t *ppos)
2476 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2477 void __user *buffer, size_t *lenp, loff_t *ppos)
2482 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2483 void __user *buffer, size_t *lenp, loff_t *ppos)
2488 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2489 void __user *buffer, size_t *lenp, loff_t *ppos)
2494 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2496 void __user *buffer,
2497 size_t *lenp, loff_t *ppos)
2503 #endif /* CONFIG_PROC_FS */
2506 #ifdef CONFIG_SYSCTL_SYSCALL
2508 * General sysctl support routines
2511 /* The generic string strategy routine: */
2512 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2513 void __user *oldval, size_t __user *oldlenp,
2514 void __user *newval, size_t newlen, void **context)
2516 if (!table->data || !table->maxlen)
2519 if (oldval && oldlenp) {
2521 if (get_user(bufsize, oldlenp))
2524 size_t len = strlen(table->data), copied;
2526 /* This shouldn't trigger for a well-formed sysctl */
2527 if (len > table->maxlen)
2528 len = table->maxlen;
2530 /* Copy up to a max of bufsize-1 bytes of the string */
2531 copied = (len >= bufsize) ? bufsize - 1 : len;
2533 if (copy_to_user(oldval, table->data, copied) ||
2534 put_user(0, (char __user *)(oldval + copied)))
2536 if (put_user(len, oldlenp))
2540 if (newval && newlen) {
2541 size_t len = newlen;
2542 if (len > table->maxlen)
2543 len = table->maxlen;
2544 if(copy_from_user(table->data, newval, len))
2546 if (len == table->maxlen)
2548 ((char *) table->data)[len] = 0;
2554 * This function makes sure that all of the integers in the vector
2555 * are between the minimum and maximum values given in the arrays
2556 * table->extra1 and table->extra2, respectively.
2558 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2559 void __user *oldval, size_t __user *oldlenp,
2560 void __user *newval, size_t newlen, void **context)
2563 if (newval && newlen) {
2564 int __user *vec = (int __user *) newval;
2565 int *min = (int *) table->extra1;
2566 int *max = (int *) table->extra2;
2570 if (newlen % sizeof(int) != 0)
2573 if (!table->extra1 && !table->extra2)
2576 if (newlen > table->maxlen)
2577 newlen = table->maxlen;
2578 length = newlen / sizeof(int);
2580 for (i = 0; i < length; i++) {
2582 if (get_user(value, vec + i))
2584 if (min && value < min[i])
2586 if (max && value > max[i])
2593 /* Strategy function to convert jiffies to seconds */
2594 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2595 void __user *oldval, size_t __user *oldlenp,
2596 void __user *newval, size_t newlen, void **context)
2601 if (get_user(olen, oldlenp))
2603 if (olen!=sizeof(int))
2606 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2607 (oldlenp && put_user(sizeof(int),oldlenp)))
2610 if (newval && newlen) {
2612 if (newlen != sizeof(int))
2614 if (get_user(new, (int __user *)newval))
2616 *(int *)(table->data) = new*HZ;
2621 /* Strategy function to convert jiffies to seconds */
2622 int sysctl_ms_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(jiffies_to_msecs(*(int *)(table->data)), (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) = msecs_to_jiffies(new);
2649 #else /* CONFIG_SYSCTL_SYSCALL */
2652 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2654 static int msg_count;
2656 if (msg_count < 5) {
2659 "warning: process `%s' used the removed sysctl "
2660 "system call\n", current->comm);
2665 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2666 void __user *oldval, size_t __user *oldlenp,
2667 void __user *newval, size_t newlen, void **context)
2672 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2673 void __user *oldval, size_t __user *oldlenp,
2674 void __user *newval, size_t newlen, void **context)
2679 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2680 void __user *oldval, size_t __user *oldlenp,
2681 void __user *newval, size_t newlen, void **context)
2686 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2687 void __user *oldval, size_t __user *oldlenp,
2688 void __user *newval, size_t newlen, void **context)
2693 #endif /* CONFIG_SYSCTL_SYSCALL */
2696 * No sense putting this after each symbol definition, twice,
2697 * exception granted :-)
2699 EXPORT_SYMBOL(proc_dointvec);
2700 EXPORT_SYMBOL(proc_dointvec_jiffies);
2701 EXPORT_SYMBOL(proc_dointvec_minmax);
2702 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2703 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2704 EXPORT_SYMBOL(proc_dostring);
2705 EXPORT_SYMBOL(proc_doulongvec_minmax);
2706 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2707 EXPORT_SYMBOL(register_sysctl_table);
2708 EXPORT_SYMBOL(sysctl_intvec);
2709 EXPORT_SYMBOL(sysctl_jiffies);
2710 EXPORT_SYMBOL(sysctl_ms_jiffies);
2711 EXPORT_SYMBOL(sysctl_string);
2712 EXPORT_SYMBOL(unregister_sysctl_table);