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);
57 #include <asm/stacktrace.h>
60 #if defined(CONFIG_SYSCTL)
62 /* External variables not in a header file. */
64 extern int sysctl_overcommit_memory;
65 extern int sysctl_overcommit_ratio;
66 extern int sysctl_panic_on_oom;
67 extern int max_threads;
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_ipc_dointvec(ctl_table *table, int write, struct file *filp,
95 void __user *buffer, size_t *lenp, loff_t *ppos);
96 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
97 void __user *buffer, size_t *lenp, loff_t *ppos);
101 extern char reboot_command [];
102 extern int stop_a_enabled;
103 extern int scons_pwroff;
107 extern int pwrsw_enabled;
108 extern int unaligned_enabled;
112 #ifdef CONFIG_MATHEMU
113 extern int sysctl_ieee_emulation_warnings;
115 extern int sysctl_userprocess_debug;
116 extern int spin_retry;
119 extern int sysctl_hz_timer;
121 #ifdef CONFIG_BSD_PROCESS_ACCT
122 extern int acct_parm[];
126 extern int no_unaligned_warning;
129 #ifdef CONFIG_RT_MUTEXES
130 extern int max_lock_depth;
133 #ifdef CONFIG_SYSCTL_SYSCALL
134 static int parse_table(int __user *, int, void __user *, size_t __user *,
135 void __user *, size_t, ctl_table *);
138 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
139 void __user *buffer, size_t *lenp, loff_t *ppos);
141 static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
142 void __user *oldval, size_t __user *oldlenp,
143 void __user *newval, size_t newlen);
145 #ifdef CONFIG_SYSVIPC
146 static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
147 void __user *oldval, size_t __user *oldlenp,
148 void __user *newval, size_t newlen);
151 #ifdef CONFIG_PROC_SYSCTL
152 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
153 void __user *buffer, size_t *lenp, loff_t *ppos);
156 static ctl_table root_table[];
157 static struct ctl_table_header root_table_header =
158 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
160 static ctl_table kern_table[];
161 static ctl_table vm_table[];
162 static ctl_table fs_table[];
163 static ctl_table debug_table[];
164 static ctl_table dev_table[];
165 extern ctl_table random_table[];
166 #ifdef CONFIG_UNIX98_PTYS
167 extern ctl_table pty_table[];
169 #ifdef CONFIG_INOTIFY_USER
170 extern ctl_table inotify_table[];
173 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
174 int sysctl_legacy_va_layout;
177 static void *get_uts(ctl_table *table, int write)
179 char *which = table->data;
181 struct uts_namespace *uts_ns = current->nsproxy->uts_ns;
182 which = (which - (char *)&init_uts_ns) + (char *)uts_ns;
187 down_write(&uts_sem);
191 static void put_uts(ctl_table *table, int write, void *which)
199 #ifdef CONFIG_SYSVIPC
200 static void *get_ipc(ctl_table *table, int write)
202 char *which = table->data;
203 struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns;
204 which = (which - (char *)&init_ipc_ns) + (char *)ipc_ns;
208 #define get_ipc(T,W) ((T)->data)
211 /* /proc declarations: */
213 #ifdef CONFIG_PROC_SYSCTL
215 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
216 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
217 static int proc_opensys(struct inode *, struct file *);
219 const struct file_operations proc_sys_file_operations = {
220 .open = proc_opensys,
221 .read = proc_readsys,
222 .write = proc_writesys,
225 extern struct proc_dir_entry *proc_sys_root;
227 static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
228 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
231 /* The default sysctl tables: */
233 static ctl_table root_table[] = {
235 .ctl_name = CTL_KERN,
236 .procname = "kernel",
261 .ctl_name = CTL_DEBUG,
264 .child = debug_table,
276 static ctl_table kern_table[] = {
278 .ctl_name = KERN_OSTYPE,
279 .procname = "ostype",
280 .data = init_uts_ns.name.sysname,
281 .maxlen = sizeof(init_uts_ns.name.sysname),
283 .proc_handler = &proc_do_uts_string,
284 .strategy = &sysctl_uts_string,
287 .ctl_name = KERN_OSRELEASE,
288 .procname = "osrelease",
289 .data = init_uts_ns.name.release,
290 .maxlen = sizeof(init_uts_ns.name.release),
292 .proc_handler = &proc_do_uts_string,
293 .strategy = &sysctl_uts_string,
296 .ctl_name = KERN_VERSION,
297 .procname = "version",
298 .data = init_uts_ns.name.version,
299 .maxlen = sizeof(init_uts_ns.name.version),
301 .proc_handler = &proc_do_uts_string,
302 .strategy = &sysctl_uts_string,
305 .ctl_name = KERN_NODENAME,
306 .procname = "hostname",
307 .data = init_uts_ns.name.nodename,
308 .maxlen = sizeof(init_uts_ns.name.nodename),
310 .proc_handler = &proc_do_uts_string,
311 .strategy = &sysctl_uts_string,
314 .ctl_name = KERN_DOMAINNAME,
315 .procname = "domainname",
316 .data = init_uts_ns.name.domainname,
317 .maxlen = sizeof(init_uts_ns.name.domainname),
319 .proc_handler = &proc_do_uts_string,
320 .strategy = &sysctl_uts_string,
323 .ctl_name = KERN_PANIC,
325 .data = &panic_timeout,
326 .maxlen = sizeof(int),
328 .proc_handler = &proc_dointvec,
331 .ctl_name = KERN_CORE_USES_PID,
332 .procname = "core_uses_pid",
333 .data = &core_uses_pid,
334 .maxlen = sizeof(int),
336 .proc_handler = &proc_dointvec,
339 .ctl_name = KERN_CORE_PATTERN,
340 .procname = "core_pattern",
341 .data = core_pattern,
344 .proc_handler = &proc_dostring,
345 .strategy = &sysctl_string,
348 .ctl_name = KERN_TAINTED,
349 .procname = "tainted",
351 .maxlen = sizeof(int),
353 .proc_handler = &proc_dointvec,
356 .ctl_name = KERN_CAP_BSET,
357 .procname = "cap-bound",
359 .maxlen = sizeof(kernel_cap_t),
361 .proc_handler = &proc_dointvec_bset,
363 #ifdef CONFIG_BLK_DEV_INITRD
365 .ctl_name = KERN_REALROOTDEV,
366 .procname = "real-root-dev",
367 .data = &real_root_dev,
368 .maxlen = sizeof(int),
370 .proc_handler = &proc_dointvec,
375 .ctl_name = KERN_SPARC_REBOOT,
376 .procname = "reboot-cmd",
377 .data = reboot_command,
380 .proc_handler = &proc_dostring,
381 .strategy = &sysctl_string,
384 .ctl_name = KERN_SPARC_STOP_A,
385 .procname = "stop-a",
386 .data = &stop_a_enabled,
387 .maxlen = sizeof (int),
389 .proc_handler = &proc_dointvec,
392 .ctl_name = KERN_SPARC_SCONS_PWROFF,
393 .procname = "scons-poweroff",
394 .data = &scons_pwroff,
395 .maxlen = sizeof (int),
397 .proc_handler = &proc_dointvec,
402 .ctl_name = KERN_HPPA_PWRSW,
403 .procname = "soft-power",
404 .data = &pwrsw_enabled,
405 .maxlen = sizeof (int),
407 .proc_handler = &proc_dointvec,
410 .ctl_name = KERN_HPPA_UNALIGNED,
411 .procname = "unaligned-trap",
412 .data = &unaligned_enabled,
413 .maxlen = sizeof (int),
415 .proc_handler = &proc_dointvec,
419 .ctl_name = KERN_CTLALTDEL,
420 .procname = "ctrl-alt-del",
422 .maxlen = sizeof(int),
424 .proc_handler = &proc_dointvec,
427 .ctl_name = KERN_PRINTK,
428 .procname = "printk",
429 .data = &console_loglevel,
430 .maxlen = 4*sizeof(int),
432 .proc_handler = &proc_dointvec,
436 .ctl_name = KERN_MODPROBE,
437 .procname = "modprobe",
438 .data = &modprobe_path,
439 .maxlen = KMOD_PATH_LEN,
441 .proc_handler = &proc_dostring,
442 .strategy = &sysctl_string,
445 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
447 .ctl_name = KERN_HOTPLUG,
448 .procname = "hotplug",
449 .data = &uevent_helper,
450 .maxlen = UEVENT_HELPER_PATH_LEN,
452 .proc_handler = &proc_dostring,
453 .strategy = &sysctl_string,
456 #ifdef CONFIG_CHR_DEV_SG
458 .ctl_name = KERN_SG_BIG_BUFF,
459 .procname = "sg-big-buff",
460 .data = &sg_big_buff,
461 .maxlen = sizeof (int),
463 .proc_handler = &proc_dointvec,
466 #ifdef CONFIG_BSD_PROCESS_ACCT
468 .ctl_name = KERN_ACCT,
471 .maxlen = 3*sizeof(int),
473 .proc_handler = &proc_dointvec,
476 #ifdef CONFIG_SYSVIPC
478 .ctl_name = KERN_SHMMAX,
479 .procname = "shmmax",
480 .data = &init_ipc_ns.shm_ctlmax,
481 .maxlen = sizeof (init_ipc_ns.shm_ctlmax),
483 .proc_handler = &proc_ipc_doulongvec_minmax,
484 .strategy = sysctl_ipc_data,
487 .ctl_name = KERN_SHMALL,
488 .procname = "shmall",
489 .data = &init_ipc_ns.shm_ctlall,
490 .maxlen = sizeof (init_ipc_ns.shm_ctlall),
492 .proc_handler = &proc_ipc_doulongvec_minmax,
493 .strategy = sysctl_ipc_data,
496 .ctl_name = KERN_SHMMNI,
497 .procname = "shmmni",
498 .data = &init_ipc_ns.shm_ctlmni,
499 .maxlen = sizeof (init_ipc_ns.shm_ctlmni),
501 .proc_handler = &proc_ipc_dointvec,
502 .strategy = sysctl_ipc_data,
505 .ctl_name = KERN_MSGMAX,
506 .procname = "msgmax",
507 .data = &init_ipc_ns.msg_ctlmax,
508 .maxlen = sizeof (init_ipc_ns.msg_ctlmax),
510 .proc_handler = &proc_ipc_dointvec,
511 .strategy = sysctl_ipc_data,
514 .ctl_name = KERN_MSGMNI,
515 .procname = "msgmni",
516 .data = &init_ipc_ns.msg_ctlmni,
517 .maxlen = sizeof (init_ipc_ns.msg_ctlmni),
519 .proc_handler = &proc_ipc_dointvec,
520 .strategy = sysctl_ipc_data,
523 .ctl_name = KERN_MSGMNB,
524 .procname = "msgmnb",
525 .data = &init_ipc_ns.msg_ctlmnb,
526 .maxlen = sizeof (init_ipc_ns.msg_ctlmnb),
528 .proc_handler = &proc_ipc_dointvec,
529 .strategy = sysctl_ipc_data,
532 .ctl_name = KERN_SEM,
534 .data = &init_ipc_ns.sem_ctls,
535 .maxlen = 4*sizeof (int),
537 .proc_handler = &proc_ipc_dointvec,
538 .strategy = sysctl_ipc_data,
541 #ifdef CONFIG_MAGIC_SYSRQ
543 .ctl_name = KERN_SYSRQ,
545 .data = &__sysrq_enabled,
546 .maxlen = sizeof (int),
548 .proc_handler = &proc_dointvec,
551 #ifdef CONFIG_PROC_SYSCTL
553 .ctl_name = KERN_CADPID,
554 .procname = "cad_pid",
556 .maxlen = sizeof (int),
558 .proc_handler = &proc_do_cad_pid,
562 .ctl_name = KERN_MAX_THREADS,
563 .procname = "threads-max",
564 .data = &max_threads,
565 .maxlen = sizeof(int),
567 .proc_handler = &proc_dointvec,
570 .ctl_name = KERN_RANDOM,
571 .procname = "random",
573 .child = random_table,
575 #ifdef CONFIG_UNIX98_PTYS
577 .ctl_name = KERN_PTY,
584 .ctl_name = KERN_OVERFLOWUID,
585 .procname = "overflowuid",
586 .data = &overflowuid,
587 .maxlen = sizeof(int),
589 .proc_handler = &proc_dointvec_minmax,
590 .strategy = &sysctl_intvec,
591 .extra1 = &minolduid,
592 .extra2 = &maxolduid,
595 .ctl_name = KERN_OVERFLOWGID,
596 .procname = "overflowgid",
597 .data = &overflowgid,
598 .maxlen = sizeof(int),
600 .proc_handler = &proc_dointvec_minmax,
601 .strategy = &sysctl_intvec,
602 .extra1 = &minolduid,
603 .extra2 = &maxolduid,
606 #ifdef CONFIG_MATHEMU
608 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
609 .procname = "ieee_emulation_warnings",
610 .data = &sysctl_ieee_emulation_warnings,
611 .maxlen = sizeof(int),
613 .proc_handler = &proc_dointvec,
616 #ifdef CONFIG_NO_IDLE_HZ
618 .ctl_name = KERN_HZ_TIMER,
619 .procname = "hz_timer",
620 .data = &sysctl_hz_timer,
621 .maxlen = sizeof(int),
623 .proc_handler = &proc_dointvec,
627 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
628 .procname = "userprocess_debug",
629 .data = &sysctl_userprocess_debug,
630 .maxlen = sizeof(int),
632 .proc_handler = &proc_dointvec,
636 .ctl_name = KERN_PIDMAX,
637 .procname = "pid_max",
639 .maxlen = sizeof (int),
641 .proc_handler = &proc_dointvec_minmax,
642 .strategy = sysctl_intvec,
643 .extra1 = &pid_max_min,
644 .extra2 = &pid_max_max,
647 .ctl_name = KERN_PANIC_ON_OOPS,
648 .procname = "panic_on_oops",
649 .data = &panic_on_oops,
650 .maxlen = sizeof(int),
652 .proc_handler = &proc_dointvec,
655 .ctl_name = KERN_PRINTK_RATELIMIT,
656 .procname = "printk_ratelimit",
657 .data = &printk_ratelimit_jiffies,
658 .maxlen = sizeof(int),
660 .proc_handler = &proc_dointvec_jiffies,
661 .strategy = &sysctl_jiffies,
664 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
665 .procname = "printk_ratelimit_burst",
666 .data = &printk_ratelimit_burst,
667 .maxlen = sizeof(int),
669 .proc_handler = &proc_dointvec,
672 .ctl_name = KERN_NGROUPS_MAX,
673 .procname = "ngroups_max",
674 .data = &ngroups_max,
675 .maxlen = sizeof (int),
677 .proc_handler = &proc_dointvec,
679 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
681 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
682 .procname = "unknown_nmi_panic",
683 .data = &unknown_nmi_panic,
684 .maxlen = sizeof (int),
686 .proc_handler = &proc_dointvec,
689 .ctl_name = KERN_NMI_WATCHDOG,
690 .procname = "nmi_watchdog",
691 .data = &nmi_watchdog_enabled,
692 .maxlen = sizeof (int),
694 .proc_handler = &proc_nmi_enabled,
697 #if defined(CONFIG_X86)
699 .ctl_name = KERN_PANIC_ON_NMI,
700 .procname = "panic_on_unrecovered_nmi",
701 .data = &panic_on_unrecovered_nmi,
702 .maxlen = sizeof(int),
704 .proc_handler = &proc_dointvec,
707 .ctl_name = KERN_BOOTLOADER_TYPE,
708 .procname = "bootloader_type",
709 .data = &bootloader_type,
710 .maxlen = sizeof (int),
712 .proc_handler = &proc_dointvec,
715 .ctl_name = CTL_UNNUMBERED,
716 .procname = "kstack_depth_to_print",
717 .data = &kstack_depth_to_print,
718 .maxlen = sizeof(int),
720 .proc_handler = &proc_dointvec,
723 #if defined(CONFIG_MMU)
725 .ctl_name = KERN_RANDOMIZE,
726 .procname = "randomize_va_space",
727 .data = &randomize_va_space,
728 .maxlen = sizeof(int),
730 .proc_handler = &proc_dointvec,
733 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
735 .ctl_name = KERN_SPIN_RETRY,
736 .procname = "spin_retry",
738 .maxlen = sizeof (int),
740 .proc_handler = &proc_dointvec,
743 #ifdef CONFIG_ACPI_SLEEP
745 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
746 .procname = "acpi_video_flags",
747 .data = &acpi_video_flags,
748 .maxlen = sizeof (unsigned long),
750 .proc_handler = &proc_doulongvec_minmax,
755 .ctl_name = KERN_IA64_UNALIGNED,
756 .procname = "ignore-unaligned-usertrap",
757 .data = &no_unaligned_warning,
758 .maxlen = sizeof (int),
760 .proc_handler = &proc_dointvec,
765 .ctl_name = KERN_COMPAT_LOG,
766 .procname = "compat-log",
768 .maxlen = sizeof (int),
770 .proc_handler = &proc_dointvec,
773 #ifdef CONFIG_RT_MUTEXES
775 .ctl_name = KERN_MAX_LOCK_DEPTH,
776 .procname = "max_lock_depth",
777 .data = &max_lock_depth,
778 .maxlen = sizeof(int),
780 .proc_handler = &proc_dointvec,
787 /* Constants for minimum and maximum testing in vm_table.
788 We use these as one-element integer vectors. */
790 static int one_hundred = 100;
793 static ctl_table vm_table[] = {
795 .ctl_name = VM_OVERCOMMIT_MEMORY,
796 .procname = "overcommit_memory",
797 .data = &sysctl_overcommit_memory,
798 .maxlen = sizeof(sysctl_overcommit_memory),
800 .proc_handler = &proc_dointvec,
803 .ctl_name = VM_PANIC_ON_OOM,
804 .procname = "panic_on_oom",
805 .data = &sysctl_panic_on_oom,
806 .maxlen = sizeof(sysctl_panic_on_oom),
808 .proc_handler = &proc_dointvec,
811 .ctl_name = VM_OVERCOMMIT_RATIO,
812 .procname = "overcommit_ratio",
813 .data = &sysctl_overcommit_ratio,
814 .maxlen = sizeof(sysctl_overcommit_ratio),
816 .proc_handler = &proc_dointvec,
819 .ctl_name = VM_PAGE_CLUSTER,
820 .procname = "page-cluster",
821 .data = &page_cluster,
822 .maxlen = sizeof(int),
824 .proc_handler = &proc_dointvec,
827 .ctl_name = VM_DIRTY_BACKGROUND,
828 .procname = "dirty_background_ratio",
829 .data = &dirty_background_ratio,
830 .maxlen = sizeof(dirty_background_ratio),
832 .proc_handler = &proc_dointvec_minmax,
833 .strategy = &sysctl_intvec,
835 .extra2 = &one_hundred,
838 .ctl_name = VM_DIRTY_RATIO,
839 .procname = "dirty_ratio",
840 .data = &vm_dirty_ratio,
841 .maxlen = sizeof(vm_dirty_ratio),
843 .proc_handler = &proc_dointvec_minmax,
844 .strategy = &sysctl_intvec,
846 .extra2 = &one_hundred,
849 .ctl_name = VM_DIRTY_WB_CS,
850 .procname = "dirty_writeback_centisecs",
851 .data = &dirty_writeback_interval,
852 .maxlen = sizeof(dirty_writeback_interval),
854 .proc_handler = &dirty_writeback_centisecs_handler,
857 .ctl_name = VM_DIRTY_EXPIRE_CS,
858 .procname = "dirty_expire_centisecs",
859 .data = &dirty_expire_interval,
860 .maxlen = sizeof(dirty_expire_interval),
862 .proc_handler = &proc_dointvec_userhz_jiffies,
865 .ctl_name = VM_NR_PDFLUSH_THREADS,
866 .procname = "nr_pdflush_threads",
867 .data = &nr_pdflush_threads,
868 .maxlen = sizeof nr_pdflush_threads,
869 .mode = 0444 /* read-only*/,
870 .proc_handler = &proc_dointvec,
873 .ctl_name = VM_SWAPPINESS,
874 .procname = "swappiness",
875 .data = &vm_swappiness,
876 .maxlen = sizeof(vm_swappiness),
878 .proc_handler = &proc_dointvec_minmax,
879 .strategy = &sysctl_intvec,
881 .extra2 = &one_hundred,
883 #ifdef CONFIG_HUGETLB_PAGE
885 .ctl_name = VM_HUGETLB_PAGES,
886 .procname = "nr_hugepages",
887 .data = &max_huge_pages,
888 .maxlen = sizeof(unsigned long),
890 .proc_handler = &hugetlb_sysctl_handler,
891 .extra1 = (void *)&hugetlb_zero,
892 .extra2 = (void *)&hugetlb_infinity,
895 .ctl_name = VM_HUGETLB_GROUP,
896 .procname = "hugetlb_shm_group",
897 .data = &sysctl_hugetlb_shm_group,
898 .maxlen = sizeof(gid_t),
900 .proc_handler = &proc_dointvec,
904 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
905 .procname = "lowmem_reserve_ratio",
906 .data = &sysctl_lowmem_reserve_ratio,
907 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
909 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
910 .strategy = &sysctl_intvec,
913 .ctl_name = VM_DROP_PAGECACHE,
914 .procname = "drop_caches",
915 .data = &sysctl_drop_caches,
916 .maxlen = sizeof(int),
918 .proc_handler = drop_caches_sysctl_handler,
919 .strategy = &sysctl_intvec,
922 .ctl_name = VM_MIN_FREE_KBYTES,
923 .procname = "min_free_kbytes",
924 .data = &min_free_kbytes,
925 .maxlen = sizeof(min_free_kbytes),
927 .proc_handler = &min_free_kbytes_sysctl_handler,
928 .strategy = &sysctl_intvec,
932 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
933 .procname = "percpu_pagelist_fraction",
934 .data = &percpu_pagelist_fraction,
935 .maxlen = sizeof(percpu_pagelist_fraction),
937 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
938 .strategy = &sysctl_intvec,
939 .extra1 = &min_percpu_pagelist_fract,
943 .ctl_name = VM_MAX_MAP_COUNT,
944 .procname = "max_map_count",
945 .data = &sysctl_max_map_count,
946 .maxlen = sizeof(sysctl_max_map_count),
948 .proc_handler = &proc_dointvec
952 .ctl_name = VM_LAPTOP_MODE,
953 .procname = "laptop_mode",
954 .data = &laptop_mode,
955 .maxlen = sizeof(laptop_mode),
957 .proc_handler = &proc_dointvec_jiffies,
958 .strategy = &sysctl_jiffies,
961 .ctl_name = VM_BLOCK_DUMP,
962 .procname = "block_dump",
964 .maxlen = sizeof(block_dump),
966 .proc_handler = &proc_dointvec,
967 .strategy = &sysctl_intvec,
971 .ctl_name = VM_VFS_CACHE_PRESSURE,
972 .procname = "vfs_cache_pressure",
973 .data = &sysctl_vfs_cache_pressure,
974 .maxlen = sizeof(sysctl_vfs_cache_pressure),
976 .proc_handler = &proc_dointvec,
977 .strategy = &sysctl_intvec,
980 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
982 .ctl_name = VM_LEGACY_VA_LAYOUT,
983 .procname = "legacy_va_layout",
984 .data = &sysctl_legacy_va_layout,
985 .maxlen = sizeof(sysctl_legacy_va_layout),
987 .proc_handler = &proc_dointvec,
988 .strategy = &sysctl_intvec,
994 .ctl_name = VM_ZONE_RECLAIM_MODE,
995 .procname = "zone_reclaim_mode",
996 .data = &zone_reclaim_mode,
997 .maxlen = sizeof(zone_reclaim_mode),
999 .proc_handler = &proc_dointvec,
1000 .strategy = &sysctl_intvec,
1004 .ctl_name = VM_MIN_UNMAPPED,
1005 .procname = "min_unmapped_ratio",
1006 .data = &sysctl_min_unmapped_ratio,
1007 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1009 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1010 .strategy = &sysctl_intvec,
1012 .extra2 = &one_hundred,
1015 .ctl_name = VM_MIN_SLAB,
1016 .procname = "min_slab_ratio",
1017 .data = &sysctl_min_slab_ratio,
1018 .maxlen = sizeof(sysctl_min_slab_ratio),
1020 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1021 .strategy = &sysctl_intvec,
1023 .extra2 = &one_hundred,
1026 #ifdef CONFIG_X86_32
1028 .ctl_name = VM_VDSO_ENABLED,
1029 .procname = "vdso_enabled",
1030 .data = &vdso_enabled,
1031 .maxlen = sizeof(vdso_enabled),
1033 .proc_handler = &proc_dointvec,
1034 .strategy = &sysctl_intvec,
1041 static ctl_table fs_table[] = {
1043 .ctl_name = FS_NRINODE,
1044 .procname = "inode-nr",
1045 .data = &inodes_stat,
1046 .maxlen = 2*sizeof(int),
1048 .proc_handler = &proc_dointvec,
1051 .ctl_name = FS_STATINODE,
1052 .procname = "inode-state",
1053 .data = &inodes_stat,
1054 .maxlen = 7*sizeof(int),
1056 .proc_handler = &proc_dointvec,
1059 .ctl_name = FS_NRFILE,
1060 .procname = "file-nr",
1061 .data = &files_stat,
1062 .maxlen = 3*sizeof(int),
1064 .proc_handler = &proc_nr_files,
1067 .ctl_name = FS_MAXFILE,
1068 .procname = "file-max",
1069 .data = &files_stat.max_files,
1070 .maxlen = sizeof(int),
1072 .proc_handler = &proc_dointvec,
1075 .ctl_name = FS_DENTRY,
1076 .procname = "dentry-state",
1077 .data = &dentry_stat,
1078 .maxlen = 6*sizeof(int),
1080 .proc_handler = &proc_dointvec,
1083 .ctl_name = FS_OVERFLOWUID,
1084 .procname = "overflowuid",
1085 .data = &fs_overflowuid,
1086 .maxlen = sizeof(int),
1088 .proc_handler = &proc_dointvec_minmax,
1089 .strategy = &sysctl_intvec,
1090 .extra1 = &minolduid,
1091 .extra2 = &maxolduid,
1094 .ctl_name = FS_OVERFLOWGID,
1095 .procname = "overflowgid",
1096 .data = &fs_overflowgid,
1097 .maxlen = sizeof(int),
1099 .proc_handler = &proc_dointvec_minmax,
1100 .strategy = &sysctl_intvec,
1101 .extra1 = &minolduid,
1102 .extra2 = &maxolduid,
1105 .ctl_name = FS_LEASES,
1106 .procname = "leases-enable",
1107 .data = &leases_enable,
1108 .maxlen = sizeof(int),
1110 .proc_handler = &proc_dointvec,
1112 #ifdef CONFIG_DNOTIFY
1114 .ctl_name = FS_DIR_NOTIFY,
1115 .procname = "dir-notify-enable",
1116 .data = &dir_notify_enable,
1117 .maxlen = sizeof(int),
1119 .proc_handler = &proc_dointvec,
1124 .ctl_name = FS_LEASE_TIME,
1125 .procname = "lease-break-time",
1126 .data = &lease_break_time,
1127 .maxlen = sizeof(int),
1129 .proc_handler = &proc_dointvec,
1132 .ctl_name = FS_AIO_NR,
1133 .procname = "aio-nr",
1135 .maxlen = sizeof(aio_nr),
1137 .proc_handler = &proc_doulongvec_minmax,
1140 .ctl_name = FS_AIO_MAX_NR,
1141 .procname = "aio-max-nr",
1142 .data = &aio_max_nr,
1143 .maxlen = sizeof(aio_max_nr),
1145 .proc_handler = &proc_doulongvec_minmax,
1147 #ifdef CONFIG_INOTIFY_USER
1149 .ctl_name = FS_INOTIFY,
1150 .procname = "inotify",
1152 .child = inotify_table,
1157 .ctl_name = KERN_SETUID_DUMPABLE,
1158 .procname = "suid_dumpable",
1159 .data = &suid_dumpable,
1160 .maxlen = sizeof(int),
1162 .proc_handler = &proc_dointvec,
1167 static ctl_table debug_table[] = {
1171 static ctl_table dev_table[] = {
1175 extern void init_irq_proc (void);
1177 static DEFINE_SPINLOCK(sysctl_lock);
1179 /* called under sysctl_lock */
1180 static int use_table(struct ctl_table_header *p)
1182 if (unlikely(p->unregistering))
1188 /* called under sysctl_lock */
1189 static void unuse_table(struct ctl_table_header *p)
1192 if (unlikely(p->unregistering))
1193 complete(p->unregistering);
1196 /* called under sysctl_lock, will reacquire if has to wait */
1197 static void start_unregistering(struct ctl_table_header *p)
1200 * if p->used is 0, nobody will ever touch that entry again;
1201 * we'll eliminate all paths to it before dropping sysctl_lock
1203 if (unlikely(p->used)) {
1204 struct completion wait;
1205 init_completion(&wait);
1206 p->unregistering = &wait;
1207 spin_unlock(&sysctl_lock);
1208 wait_for_completion(&wait);
1209 spin_lock(&sysctl_lock);
1212 * do not remove from the list until nobody holds it; walking the
1213 * list in do_sysctl() relies on that.
1215 list_del_init(&p->ctl_entry);
1218 void __init sysctl_init(void)
1220 #ifdef CONFIG_PROC_SYSCTL
1221 register_proc_table(root_table, proc_sys_root, &root_table_header);
1226 #ifdef CONFIG_SYSCTL_SYSCALL
1227 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1228 void __user *newval, size_t newlen)
1230 struct list_head *tmp;
1231 int error = -ENOTDIR;
1233 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1237 if (!oldlenp || get_user(old_len, oldlenp))
1240 spin_lock(&sysctl_lock);
1241 tmp = &root_table_header.ctl_entry;
1243 struct ctl_table_header *head =
1244 list_entry(tmp, struct ctl_table_header, ctl_entry);
1246 if (!use_table(head))
1249 spin_unlock(&sysctl_lock);
1251 error = parse_table(name, nlen, oldval, oldlenp,
1252 newval, newlen, head->ctl_table);
1254 spin_lock(&sysctl_lock);
1256 if (error != -ENOTDIR)
1258 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1259 spin_unlock(&sysctl_lock);
1263 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1265 struct __sysctl_args tmp;
1268 if (copy_from_user(&tmp, args, sizeof(tmp)))
1272 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1273 tmp.newval, tmp.newlen);
1277 #endif /* CONFIG_SYSCTL_SYSCALL */
1280 * ctl_perm does NOT grant the superuser all rights automatically, because
1281 * some sysctl variables are readonly even to root.
1284 static int test_perm(int mode, int op)
1288 else if (in_egroup_p(0))
1290 if ((mode & op & 0007) == op)
1295 static inline int ctl_perm(ctl_table *table, int op)
1298 error = security_sysctl(table, op);
1301 return test_perm(table->mode, op);
1304 #ifdef CONFIG_SYSCTL_SYSCALL
1305 static int parse_table(int __user *name, int nlen,
1306 void __user *oldval, size_t __user *oldlenp,
1307 void __user *newval, size_t newlen,
1314 if (get_user(n, name))
1316 for ( ; table->ctl_name || table->procname; table++) {
1317 if (!table->ctl_name)
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(
1334 table = table->child;
1337 error = do_sysctl_strategy(table, name, nlen,
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)
1359 if (ctl_perm(table, op))
1362 if (table->strategy) {
1363 rc = table->strategy(table, name, nlen, oldval, oldlenp,
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->procname; 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->procname; 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_path.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 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
1758 void __user *buffer, size_t *lenp, loff_t *ppos)
1762 which = get_uts(table, write);
1763 r = _proc_do_string(which, table->maxlen,write,filp,buffer,lenp, ppos);
1764 put_uts(table, write, which);
1768 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1770 int write, void *data)
1773 *valp = *negp ? -*lvalp : *lvalp;
1778 *lvalp = (unsigned long)-val;
1781 *lvalp = (unsigned long)val;
1787 static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1788 int write, struct file *filp, void __user *buffer,
1789 size_t *lenp, loff_t *ppos,
1790 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1791 int write, void *data),
1794 #define TMPBUFLEN 21
1795 int *i, vleft, first=1, neg, val;
1799 char buf[TMPBUFLEN], *p;
1800 char __user *s = buffer;
1802 if (!tbl_data || !table->maxlen || !*lenp ||
1803 (*ppos && !write)) {
1808 i = (int *) tbl_data;
1809 vleft = table->maxlen / sizeof(*i);
1813 conv = do_proc_dointvec_conv;
1815 for (; left && vleft--; i++, first=0) {
1830 if (len > sizeof(buf) - 1)
1831 len = sizeof(buf) - 1;
1832 if (copy_from_user(buf, s, len))
1836 if (*p == '-' && left > 1) {
1840 if (*p < '0' || *p > '9')
1843 lval = simple_strtoul(p, &p, 0);
1846 if ((len < left) && *p && !isspace(*p))
1853 if (conv(&neg, &lval, i, 1, data))
1860 if (conv(&neg, &lval, i, 0, data))
1863 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1867 if(copy_to_user(s, buf, len))
1874 if (!write && !first && left) {
1875 if(put_user('\n', s))
1882 if (get_user(c, s++))
1897 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1898 void __user *buffer, size_t *lenp, loff_t *ppos,
1899 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1900 int write, void *data),
1903 return __do_proc_dointvec(table->data, table, write, filp,
1904 buffer, lenp, ppos, conv, data);
1908 * proc_dointvec - read a vector of integers
1909 * @table: the sysctl table
1910 * @write: %TRUE if this is a write to the sysctl file
1911 * @filp: the file structure
1912 * @buffer: the user buffer
1913 * @lenp: the size of the user buffer
1914 * @ppos: file position
1916 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1917 * values from/to the user buffer, treated as an ASCII string.
1919 * Returns 0 on success.
1921 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1922 void __user *buffer, size_t *lenp, loff_t *ppos)
1924 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1931 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1933 int write, void *data)
1935 int op = *(int *)data;
1937 int val = *negp ? -*lvalp : *lvalp;
1939 case OP_SET: *valp = val; break;
1940 case OP_AND: *valp &= val; break;
1946 *lvalp = (unsigned long)-val;
1949 *lvalp = (unsigned long)val;
1956 * init may raise the set.
1959 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1960 void __user *buffer, size_t *lenp, loff_t *ppos)
1964 if (!capable(CAP_SYS_MODULE)) {
1968 op = is_init(current) ? OP_SET : OP_AND;
1969 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1970 do_proc_dointvec_bset_conv,&op);
1973 struct do_proc_dointvec_minmax_conv_param {
1978 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1980 int write, void *data)
1982 struct do_proc_dointvec_minmax_conv_param *param = data;
1984 int val = *negp ? -*lvalp : *lvalp;
1985 if ((param->min && *param->min > val) ||
1986 (param->max && *param->max < val))
1993 *lvalp = (unsigned long)-val;
1996 *lvalp = (unsigned long)val;
2003 * proc_dointvec_minmax - read a vector of integers with min/max values
2004 * @table: the sysctl table
2005 * @write: %TRUE if this is a write to the sysctl file
2006 * @filp: the file structure
2007 * @buffer: the user buffer
2008 * @lenp: the size of the user buffer
2009 * @ppos: file position
2011 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2012 * values from/to the user buffer, treated as an ASCII string.
2014 * This routine will ensure the values are within the range specified by
2015 * table->extra1 (min) and table->extra2 (max).
2017 * Returns 0 on success.
2019 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2020 void __user *buffer, size_t *lenp, loff_t *ppos)
2022 struct do_proc_dointvec_minmax_conv_param param = {
2023 .min = (int *) table->extra1,
2024 .max = (int *) table->extra2,
2026 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2027 do_proc_dointvec_minmax_conv, ¶m);
2030 static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
2032 void __user *buffer,
2033 size_t *lenp, loff_t *ppos,
2034 unsigned long convmul,
2035 unsigned long convdiv)
2037 #define TMPBUFLEN 21
2038 unsigned long *i, *min, *max, val;
2039 int vleft, first=1, neg;
2041 char buf[TMPBUFLEN], *p;
2042 char __user *s = buffer;
2044 if (!data || !table->maxlen || !*lenp ||
2045 (*ppos && !write)) {
2050 i = (unsigned long *) data;
2051 min = (unsigned long *) table->extra1;
2052 max = (unsigned long *) table->extra2;
2053 vleft = table->maxlen / sizeof(unsigned long);
2056 for (; left && vleft--; i++, min++, max++, first=0) {
2071 if (len > TMPBUFLEN-1)
2073 if (copy_from_user(buf, s, len))
2077 if (*p == '-' && left > 1) {
2081 if (*p < '0' || *p > '9')
2083 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2085 if ((len < left) && *p && !isspace(*p))
2094 if ((min && val < *min) || (max && val > *max))
2101 sprintf(p, "%lu", convdiv * (*i) / convmul);
2105 if(copy_to_user(s, buf, len))
2112 if (!write && !first && left) {
2113 if(put_user('\n', s))
2120 if (get_user(c, s++))
2135 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2137 void __user *buffer,
2138 size_t *lenp, loff_t *ppos,
2139 unsigned long convmul,
2140 unsigned long convdiv)
2142 return __do_proc_doulongvec_minmax(table->data, table, write,
2143 filp, buffer, lenp, ppos, convmul, convdiv);
2147 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2148 * @table: the sysctl table
2149 * @write: %TRUE if this is a write to the sysctl file
2150 * @filp: the file structure
2151 * @buffer: the user buffer
2152 * @lenp: the size of the user buffer
2153 * @ppos: file position
2155 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2156 * values from/to the user buffer, treated as an ASCII string.
2158 * This routine will ensure the values are within the range specified by
2159 * table->extra1 (min) and table->extra2 (max).
2161 * Returns 0 on success.
2163 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2164 void __user *buffer, size_t *lenp, loff_t *ppos)
2166 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2170 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2171 * @table: the sysctl table
2172 * @write: %TRUE if this is a write to the sysctl file
2173 * @filp: the file structure
2174 * @buffer: the user buffer
2175 * @lenp: the size of the user buffer
2176 * @ppos: file position
2178 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2179 * values from/to the user buffer, treated as an ASCII string. The values
2180 * are treated as milliseconds, and converted to jiffies when they are stored.
2182 * This routine will ensure the values are within the range specified by
2183 * table->extra1 (min) and table->extra2 (max).
2185 * Returns 0 on success.
2187 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2189 void __user *buffer,
2190 size_t *lenp, loff_t *ppos)
2192 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2193 lenp, ppos, HZ, 1000l);
2197 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2199 int write, void *data)
2202 if (*lvalp > LONG_MAX / HZ)
2204 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2210 lval = (unsigned long)-val;
2213 lval = (unsigned long)val;
2220 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2222 int write, void *data)
2225 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2227 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2233 lval = (unsigned long)-val;
2236 lval = (unsigned long)val;
2238 *lvalp = jiffies_to_clock_t(lval);
2243 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2245 int write, void *data)
2248 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2254 lval = (unsigned long)-val;
2257 lval = (unsigned long)val;
2259 *lvalp = jiffies_to_msecs(lval);
2265 * proc_dointvec_jiffies - read a vector of integers as seconds
2266 * @table: the sysctl table
2267 * @write: %TRUE if this is a write to the sysctl file
2268 * @filp: the file structure
2269 * @buffer: the user buffer
2270 * @lenp: the size of the user buffer
2271 * @ppos: file position
2273 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2274 * values from/to the user buffer, treated as an ASCII string.
2275 * The values read are assumed to be in seconds, and are converted into
2278 * Returns 0 on success.
2280 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2281 void __user *buffer, size_t *lenp, loff_t *ppos)
2283 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2284 do_proc_dointvec_jiffies_conv,NULL);
2288 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2289 * @table: the sysctl table
2290 * @write: %TRUE if this is a write to the sysctl file
2291 * @filp: the file structure
2292 * @buffer: the user buffer
2293 * @lenp: the size of the user buffer
2294 * @ppos: pointer to the file position
2296 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2297 * values from/to the user buffer, treated as an ASCII string.
2298 * The values read are assumed to be in 1/USER_HZ seconds, and
2299 * are converted into jiffies.
2301 * Returns 0 on success.
2303 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2304 void __user *buffer, size_t *lenp, loff_t *ppos)
2306 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2307 do_proc_dointvec_userhz_jiffies_conv,NULL);
2311 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2312 * @table: the sysctl table
2313 * @write: %TRUE if this is a write to the sysctl file
2314 * @filp: the file structure
2315 * @buffer: the user buffer
2316 * @lenp: the size of the user buffer
2317 * @ppos: file position
2318 * @ppos: the current position in the file
2320 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2321 * values from/to the user buffer, treated as an ASCII string.
2322 * The values read are assumed to be in 1/1000 seconds, and
2323 * are converted into jiffies.
2325 * Returns 0 on success.
2327 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2328 void __user *buffer, size_t *lenp, loff_t *ppos)
2330 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2331 do_proc_dointvec_ms_jiffies_conv, NULL);
2334 #ifdef CONFIG_SYSVIPC
2335 static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
2336 void __user *buffer, size_t *lenp, loff_t *ppos)
2339 which = get_ipc(table, write);
2340 return __do_proc_dointvec(which, table, write, filp, buffer,
2341 lenp, ppos, NULL, NULL);
2344 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
2345 struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
2348 which = get_ipc(table, write);
2349 return __do_proc_doulongvec_minmax(which, table, write, filp, buffer,
2350 lenp, ppos, 1l, 1l);
2355 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2356 void __user *buffer, size_t *lenp, loff_t *ppos)
2358 struct pid *new_pid;
2362 tmp = pid_nr(cad_pid);
2364 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2365 lenp, ppos, NULL, NULL);
2369 new_pid = find_get_pid(tmp);
2373 put_pid(xchg(&cad_pid, new_pid));
2377 #else /* CONFIG_PROC_FS */
2379 int proc_dostring(ctl_table *table, int write, struct file *filp,
2380 void __user *buffer, size_t *lenp, loff_t *ppos)
2385 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
2386 void __user *buffer, size_t *lenp, loff_t *ppos)
2391 #ifdef CONFIG_SYSVIPC
2392 static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2393 void __user *buffer, size_t *lenp, loff_t *ppos)
2397 static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
2398 void __user *buffer, size_t *lenp, loff_t *ppos)
2402 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
2403 struct file *filp, void __user *buffer,
2404 size_t *lenp, loff_t *ppos)
2410 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2411 void __user *buffer, size_t *lenp, loff_t *ppos)
2416 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2417 void __user *buffer, size_t *lenp, loff_t *ppos)
2422 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2423 void __user *buffer, size_t *lenp, loff_t *ppos)
2428 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2429 void __user *buffer, size_t *lenp, loff_t *ppos)
2434 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2435 void __user *buffer, size_t *lenp, loff_t *ppos)
2440 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2441 void __user *buffer, size_t *lenp, loff_t *ppos)
2446 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2447 void __user *buffer, size_t *lenp, loff_t *ppos)
2452 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2454 void __user *buffer,
2455 size_t *lenp, loff_t *ppos)
2461 #endif /* CONFIG_PROC_FS */
2464 #ifdef CONFIG_SYSCTL_SYSCALL
2466 * General sysctl support routines
2469 /* The generic string strategy routine: */
2470 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2471 void __user *oldval, size_t __user *oldlenp,
2472 void __user *newval, size_t newlen)
2474 if (!table->data || !table->maxlen)
2477 if (oldval && oldlenp) {
2479 if (get_user(bufsize, oldlenp))
2482 size_t len = strlen(table->data), copied;
2484 /* This shouldn't trigger for a well-formed sysctl */
2485 if (len > table->maxlen)
2486 len = table->maxlen;
2488 /* Copy up to a max of bufsize-1 bytes of the string */
2489 copied = (len >= bufsize) ? bufsize - 1 : len;
2491 if (copy_to_user(oldval, table->data, copied) ||
2492 put_user(0, (char __user *)(oldval + copied)))
2494 if (put_user(len, oldlenp))
2498 if (newval && newlen) {
2499 size_t len = newlen;
2500 if (len > table->maxlen)
2501 len = table->maxlen;
2502 if(copy_from_user(table->data, newval, len))
2504 if (len == table->maxlen)
2506 ((char *) table->data)[len] = 0;
2512 * This function makes sure that all of the integers in the vector
2513 * are between the minimum and maximum values given in the arrays
2514 * table->extra1 and table->extra2, respectively.
2516 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2517 void __user *oldval, size_t __user *oldlenp,
2518 void __user *newval, size_t newlen)
2521 if (newval && newlen) {
2522 int __user *vec = (int __user *) newval;
2523 int *min = (int *) table->extra1;
2524 int *max = (int *) table->extra2;
2528 if (newlen % sizeof(int) != 0)
2531 if (!table->extra1 && !table->extra2)
2534 if (newlen > table->maxlen)
2535 newlen = table->maxlen;
2536 length = newlen / sizeof(int);
2538 for (i = 0; i < length; i++) {
2540 if (get_user(value, vec + i))
2542 if (min && value < min[i])
2544 if (max && value > max[i])
2551 /* Strategy function to convert jiffies to seconds */
2552 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2553 void __user *oldval, size_t __user *oldlenp,
2554 void __user *newval, size_t newlen)
2559 if (get_user(olen, oldlenp))
2561 if (olen!=sizeof(int))
2564 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2565 (oldlenp && put_user(sizeof(int),oldlenp)))
2568 if (newval && newlen) {
2570 if (newlen != sizeof(int))
2572 if (get_user(new, (int __user *)newval))
2574 *(int *)(table->data) = new*HZ;
2579 /* Strategy function to convert jiffies to seconds */
2580 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2581 void __user *oldval, size_t __user *oldlenp,
2582 void __user *newval, size_t newlen)
2587 if (get_user(olen, oldlenp))
2589 if (olen!=sizeof(int))
2592 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2593 (oldlenp && put_user(sizeof(int),oldlenp)))
2596 if (newval && newlen) {
2598 if (newlen != sizeof(int))
2600 if (get_user(new, (int __user *)newval))
2602 *(int *)(table->data) = msecs_to_jiffies(new);
2608 /* The generic string strategy routine: */
2609 static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2610 void __user *oldval, size_t __user *oldlenp,
2611 void __user *newval, size_t newlen)
2613 struct ctl_table uts_table;
2615 write = newval && newlen;
2616 memcpy(&uts_table, table, sizeof(uts_table));
2617 uts_table.data = get_uts(table, write);
2618 r = sysctl_string(&uts_table, name, nlen,
2619 oldval, oldlenp, newval, newlen);
2620 put_uts(table, write, uts_table.data);
2624 #ifdef CONFIG_SYSVIPC
2625 /* The generic sysctl ipc data routine. */
2626 static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
2627 void __user *oldval, size_t __user *oldlenp,
2628 void __user *newval, size_t newlen)
2633 /* Get out of I don't have a variable */
2634 if (!table->data || !table->maxlen)
2637 data = get_ipc(table, 1);
2641 if (oldval && oldlenp) {
2642 if (get_user(len, oldlenp))
2645 if (len > table->maxlen)
2646 len = table->maxlen;
2647 if (copy_to_user(oldval, data, len))
2649 if (put_user(len, oldlenp))
2654 if (newval && newlen) {
2655 if (newlen > table->maxlen)
2656 newlen = table->maxlen;
2658 if (copy_from_user(data, newval, newlen))
2665 #else /* CONFIG_SYSCTL_SYSCALL */
2668 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2670 static int msg_count;
2671 struct __sysctl_args tmp;
2672 int name[CTL_MAXNAME];
2675 /* Read in the sysctl name for better debug message logging */
2676 if (copy_from_user(&tmp, args, sizeof(tmp)))
2678 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2680 for (i = 0; i < tmp.nlen; i++)
2681 if (get_user(name[i], tmp.name + i))
2684 /* Ignore accesses to kernel.version */
2685 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2688 if (msg_count < 5) {
2691 "warning: process `%s' used the removed sysctl "
2692 "system call with ", current->comm);
2693 for (i = 0; i < tmp.nlen; i++)
2694 printk("%d.", name[i]);
2701 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2702 void __user *oldval, size_t __user *oldlenp,
2703 void __user *newval, size_t newlen)
2708 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2709 void __user *oldval, size_t __user *oldlenp,
2710 void __user *newval, size_t newlen)
2715 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2716 void __user *oldval, size_t __user *oldlenp,
2717 void __user *newval, size_t newlen)
2722 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2723 void __user *oldval, size_t __user *oldlenp,
2724 void __user *newval, size_t newlen)
2729 static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2730 void __user *oldval, size_t __user *oldlenp,
2731 void __user *newval, size_t newlen)
2735 static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
2736 void __user *oldval, size_t __user *oldlenp,
2737 void __user *newval, size_t newlen)
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);