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 sysrq_enabled;
69 extern int core_uses_pid;
70 extern int suid_dumpable;
71 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_ipc_dointvec(ctl_table *table, int write, struct file *filp,
96 void __user *buffer, size_t *lenp, loff_t *ppos);
97 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
98 void __user *buffer, size_t *lenp, loff_t *ppos);
102 extern char reboot_command [];
103 extern int stop_a_enabled;
104 extern int scons_pwroff;
108 extern int pwrsw_enabled;
109 extern int unaligned_enabled;
113 #ifdef CONFIG_MATHEMU
114 extern int sysctl_ieee_emulation_warnings;
116 extern int sysctl_userprocess_debug;
117 extern int spin_retry;
120 extern int sysctl_hz_timer;
122 #ifdef CONFIG_BSD_PROCESS_ACCT
123 extern int acct_parm[];
127 extern int no_unaligned_warning;
130 #ifdef CONFIG_RT_MUTEXES
131 extern int max_lock_depth;
134 #ifdef CONFIG_SYSCTL_SYSCALL
135 static int parse_table(int __user *, int, void __user *, size_t __user *,
136 void __user *, size_t, ctl_table *, void **);
139 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
140 void __user *buffer, size_t *lenp, loff_t *ppos);
142 static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
143 void __user *oldval, size_t __user *oldlenp,
144 void __user *newval, size_t newlen, void **context);
146 #ifdef CONFIG_SYSVIPC
147 static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
148 void __user *oldval, size_t __user *oldlenp,
149 void __user *newval, size_t newlen, void **context);
152 #ifdef CONFIG_PROC_SYSCTL
153 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
154 void __user *buffer, size_t *lenp, loff_t *ppos);
157 static ctl_table root_table[];
158 static struct ctl_table_header root_table_header =
159 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
161 static ctl_table kern_table[];
162 static ctl_table vm_table[];
163 static ctl_table fs_table[];
164 static ctl_table debug_table[];
165 static ctl_table dev_table[];
166 extern ctl_table random_table[];
167 #ifdef CONFIG_UNIX98_PTYS
168 extern ctl_table pty_table[];
170 #ifdef CONFIG_INOTIFY_USER
171 extern ctl_table inotify_table[];
174 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
175 int sysctl_legacy_va_layout;
178 static void *get_uts(ctl_table *table, int write)
180 char *which = table->data;
182 struct uts_namespace *uts_ns = current->nsproxy->uts_ns;
183 which = (which - (char *)&init_uts_ns) + (char *)uts_ns;
188 down_write(&uts_sem);
192 static void put_uts(ctl_table *table, int write, void *which)
200 #ifdef CONFIG_SYSVIPC
201 static void *get_ipc(ctl_table *table, int write)
203 char *which = table->data;
204 struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns;
205 which = (which - (char *)&init_ipc_ns) + (char *)ipc_ns;
209 #define get_ipc(T,W) ((T)->data)
212 /* /proc declarations: */
214 #ifdef CONFIG_PROC_SYSCTL
216 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
217 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
218 static int proc_opensys(struct inode *, struct file *);
220 const struct file_operations proc_sys_file_operations = {
221 .open = proc_opensys,
222 .read = proc_readsys,
223 .write = proc_writesys,
226 extern struct proc_dir_entry *proc_sys_root;
228 static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
229 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
232 /* The default sysctl tables: */
234 static ctl_table root_table[] = {
236 .ctl_name = CTL_KERN,
237 .procname = "kernel",
262 .ctl_name = CTL_DEBUG,
265 .child = debug_table,
277 static ctl_table kern_table[] = {
279 .ctl_name = KERN_OSTYPE,
280 .procname = "ostype",
281 .data = init_uts_ns.name.sysname,
282 .maxlen = sizeof(init_uts_ns.name.sysname),
284 .proc_handler = &proc_do_uts_string,
285 .strategy = &sysctl_uts_string,
288 .ctl_name = KERN_OSRELEASE,
289 .procname = "osrelease",
290 .data = init_uts_ns.name.release,
291 .maxlen = sizeof(init_uts_ns.name.release),
293 .proc_handler = &proc_do_uts_string,
294 .strategy = &sysctl_uts_string,
297 .ctl_name = KERN_VERSION,
298 .procname = "version",
299 .data = init_uts_ns.name.version,
300 .maxlen = sizeof(init_uts_ns.name.version),
302 .proc_handler = &proc_do_uts_string,
303 .strategy = &sysctl_uts_string,
306 .ctl_name = KERN_NODENAME,
307 .procname = "hostname",
308 .data = init_uts_ns.name.nodename,
309 .maxlen = sizeof(init_uts_ns.name.nodename),
311 .proc_handler = &proc_do_uts_string,
312 .strategy = &sysctl_uts_string,
315 .ctl_name = KERN_DOMAINNAME,
316 .procname = "domainname",
317 .data = init_uts_ns.name.domainname,
318 .maxlen = sizeof(init_uts_ns.name.domainname),
320 .proc_handler = &proc_do_uts_string,
321 .strategy = &sysctl_uts_string,
324 .ctl_name = KERN_PANIC,
326 .data = &panic_timeout,
327 .maxlen = sizeof(int),
329 .proc_handler = &proc_dointvec,
332 .ctl_name = KERN_CORE_USES_PID,
333 .procname = "core_uses_pid",
334 .data = &core_uses_pid,
335 .maxlen = sizeof(int),
337 .proc_handler = &proc_dointvec,
340 .ctl_name = KERN_CORE_PATTERN,
341 .procname = "core_pattern",
342 .data = core_pattern,
345 .proc_handler = &proc_dostring,
346 .strategy = &sysctl_string,
349 .ctl_name = KERN_TAINTED,
350 .procname = "tainted",
352 .maxlen = sizeof(int),
354 .proc_handler = &proc_dointvec,
357 .ctl_name = KERN_CAP_BSET,
358 .procname = "cap-bound",
360 .maxlen = sizeof(kernel_cap_t),
362 .proc_handler = &proc_dointvec_bset,
364 #ifdef CONFIG_BLK_DEV_INITRD
366 .ctl_name = KERN_REALROOTDEV,
367 .procname = "real-root-dev",
368 .data = &real_root_dev,
369 .maxlen = sizeof(int),
371 .proc_handler = &proc_dointvec,
376 .ctl_name = KERN_SPARC_REBOOT,
377 .procname = "reboot-cmd",
378 .data = reboot_command,
381 .proc_handler = &proc_dostring,
382 .strategy = &sysctl_string,
385 .ctl_name = KERN_SPARC_STOP_A,
386 .procname = "stop-a",
387 .data = &stop_a_enabled,
388 .maxlen = sizeof (int),
390 .proc_handler = &proc_dointvec,
393 .ctl_name = KERN_SPARC_SCONS_PWROFF,
394 .procname = "scons-poweroff",
395 .data = &scons_pwroff,
396 .maxlen = sizeof (int),
398 .proc_handler = &proc_dointvec,
403 .ctl_name = KERN_HPPA_PWRSW,
404 .procname = "soft-power",
405 .data = &pwrsw_enabled,
406 .maxlen = sizeof (int),
408 .proc_handler = &proc_dointvec,
411 .ctl_name = KERN_HPPA_UNALIGNED,
412 .procname = "unaligned-trap",
413 .data = &unaligned_enabled,
414 .maxlen = sizeof (int),
416 .proc_handler = &proc_dointvec,
420 .ctl_name = KERN_CTLALTDEL,
421 .procname = "ctrl-alt-del",
423 .maxlen = sizeof(int),
425 .proc_handler = &proc_dointvec,
428 .ctl_name = KERN_PRINTK,
429 .procname = "printk",
430 .data = &console_loglevel,
431 .maxlen = 4*sizeof(int),
433 .proc_handler = &proc_dointvec,
437 .ctl_name = KERN_MODPROBE,
438 .procname = "modprobe",
439 .data = &modprobe_path,
440 .maxlen = KMOD_PATH_LEN,
442 .proc_handler = &proc_dostring,
443 .strategy = &sysctl_string,
446 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
448 .ctl_name = KERN_HOTPLUG,
449 .procname = "hotplug",
450 .data = &uevent_helper,
451 .maxlen = UEVENT_HELPER_PATH_LEN,
453 .proc_handler = &proc_dostring,
454 .strategy = &sysctl_string,
457 #ifdef CONFIG_CHR_DEV_SG
459 .ctl_name = KERN_SG_BIG_BUFF,
460 .procname = "sg-big-buff",
461 .data = &sg_big_buff,
462 .maxlen = sizeof (int),
464 .proc_handler = &proc_dointvec,
467 #ifdef CONFIG_BSD_PROCESS_ACCT
469 .ctl_name = KERN_ACCT,
472 .maxlen = 3*sizeof(int),
474 .proc_handler = &proc_dointvec,
477 #ifdef CONFIG_SYSVIPC
479 .ctl_name = KERN_SHMMAX,
480 .procname = "shmmax",
481 .data = &init_ipc_ns.shm_ctlmax,
482 .maxlen = sizeof (init_ipc_ns.shm_ctlmax),
484 .proc_handler = &proc_ipc_doulongvec_minmax,
485 .strategy = sysctl_ipc_data,
488 .ctl_name = KERN_SHMALL,
489 .procname = "shmall",
490 .data = &init_ipc_ns.shm_ctlall,
491 .maxlen = sizeof (init_ipc_ns.shm_ctlall),
493 .proc_handler = &proc_ipc_doulongvec_minmax,
494 .strategy = sysctl_ipc_data,
497 .ctl_name = KERN_SHMMNI,
498 .procname = "shmmni",
499 .data = &init_ipc_ns.shm_ctlmni,
500 .maxlen = sizeof (init_ipc_ns.shm_ctlmni),
502 .proc_handler = &proc_ipc_dointvec,
503 .strategy = sysctl_ipc_data,
506 .ctl_name = KERN_MSGMAX,
507 .procname = "msgmax",
508 .data = &init_ipc_ns.msg_ctlmax,
509 .maxlen = sizeof (init_ipc_ns.msg_ctlmax),
511 .proc_handler = &proc_ipc_dointvec,
512 .strategy = sysctl_ipc_data,
515 .ctl_name = KERN_MSGMNI,
516 .procname = "msgmni",
517 .data = &init_ipc_ns.msg_ctlmni,
518 .maxlen = sizeof (init_ipc_ns.msg_ctlmni),
520 .proc_handler = &proc_ipc_dointvec,
521 .strategy = sysctl_ipc_data,
524 .ctl_name = KERN_MSGMNB,
525 .procname = "msgmnb",
526 .data = &init_ipc_ns.msg_ctlmnb,
527 .maxlen = sizeof (init_ipc_ns.msg_ctlmnb),
529 .proc_handler = &proc_ipc_dointvec,
530 .strategy = sysctl_ipc_data,
533 .ctl_name = KERN_SEM,
535 .data = &init_ipc_ns.sem_ctls,
536 .maxlen = 4*sizeof (int),
538 .proc_handler = &proc_ipc_dointvec,
539 .strategy = sysctl_ipc_data,
542 #ifdef CONFIG_MAGIC_SYSRQ
544 .ctl_name = KERN_SYSRQ,
546 .data = &sysrq_enabled,
547 .maxlen = sizeof (int),
549 .proc_handler = &proc_dointvec,
552 #ifdef CONFIG_PROC_SYSCTL
554 .ctl_name = KERN_CADPID,
555 .procname = "cad_pid",
557 .maxlen = sizeof (int),
559 .proc_handler = &proc_do_cad_pid,
563 .ctl_name = KERN_MAX_THREADS,
564 .procname = "threads-max",
565 .data = &max_threads,
566 .maxlen = sizeof(int),
568 .proc_handler = &proc_dointvec,
571 .ctl_name = KERN_RANDOM,
572 .procname = "random",
574 .child = random_table,
576 #ifdef CONFIG_UNIX98_PTYS
578 .ctl_name = KERN_PTY,
585 .ctl_name = KERN_OVERFLOWUID,
586 .procname = "overflowuid",
587 .data = &overflowuid,
588 .maxlen = sizeof(int),
590 .proc_handler = &proc_dointvec_minmax,
591 .strategy = &sysctl_intvec,
592 .extra1 = &minolduid,
593 .extra2 = &maxolduid,
596 .ctl_name = KERN_OVERFLOWGID,
597 .procname = "overflowgid",
598 .data = &overflowgid,
599 .maxlen = sizeof(int),
601 .proc_handler = &proc_dointvec_minmax,
602 .strategy = &sysctl_intvec,
603 .extra1 = &minolduid,
604 .extra2 = &maxolduid,
607 #ifdef CONFIG_MATHEMU
609 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
610 .procname = "ieee_emulation_warnings",
611 .data = &sysctl_ieee_emulation_warnings,
612 .maxlen = sizeof(int),
614 .proc_handler = &proc_dointvec,
617 #ifdef CONFIG_NO_IDLE_HZ
619 .ctl_name = KERN_HZ_TIMER,
620 .procname = "hz_timer",
621 .data = &sysctl_hz_timer,
622 .maxlen = sizeof(int),
624 .proc_handler = &proc_dointvec,
628 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
629 .procname = "userprocess_debug",
630 .data = &sysctl_userprocess_debug,
631 .maxlen = sizeof(int),
633 .proc_handler = &proc_dointvec,
637 .ctl_name = KERN_PIDMAX,
638 .procname = "pid_max",
640 .maxlen = sizeof (int),
642 .proc_handler = &proc_dointvec_minmax,
643 .strategy = sysctl_intvec,
644 .extra1 = &pid_max_min,
645 .extra2 = &pid_max_max,
648 .ctl_name = KERN_PANIC_ON_OOPS,
649 .procname = "panic_on_oops",
650 .data = &panic_on_oops,
651 .maxlen = sizeof(int),
653 .proc_handler = &proc_dointvec,
656 .ctl_name = KERN_PRINTK_RATELIMIT,
657 .procname = "printk_ratelimit",
658 .data = &printk_ratelimit_jiffies,
659 .maxlen = sizeof(int),
661 .proc_handler = &proc_dointvec_jiffies,
662 .strategy = &sysctl_jiffies,
665 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
666 .procname = "printk_ratelimit_burst",
667 .data = &printk_ratelimit_burst,
668 .maxlen = sizeof(int),
670 .proc_handler = &proc_dointvec,
673 .ctl_name = KERN_NGROUPS_MAX,
674 .procname = "ngroups_max",
675 .data = &ngroups_max,
676 .maxlen = sizeof (int),
678 .proc_handler = &proc_dointvec,
680 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
682 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
683 .procname = "unknown_nmi_panic",
684 .data = &unknown_nmi_panic,
685 .maxlen = sizeof (int),
687 .proc_handler = &proc_dointvec,
690 .ctl_name = KERN_NMI_WATCHDOG,
691 .procname = "nmi_watchdog",
692 .data = &nmi_watchdog_enabled,
693 .maxlen = sizeof (int),
695 .proc_handler = &proc_nmi_enabled,
698 #if defined(CONFIG_X86)
700 .ctl_name = KERN_PANIC_ON_NMI,
701 .procname = "panic_on_unrecovered_nmi",
702 .data = &panic_on_unrecovered_nmi,
703 .maxlen = sizeof(int),
705 .proc_handler = &proc_dointvec,
708 .ctl_name = KERN_BOOTLOADER_TYPE,
709 .procname = "bootloader_type",
710 .data = &bootloader_type,
711 .maxlen = sizeof (int),
713 .proc_handler = &proc_dointvec,
716 .ctl_name = CTL_UNNUMBERED,
717 .procname = "kstack_depth_to_print",
718 .data = &kstack_depth_to_print,
719 .maxlen = sizeof(int),
721 .proc_handler = &proc_dointvec,
724 #if defined(CONFIG_MMU)
726 .ctl_name = KERN_RANDOMIZE,
727 .procname = "randomize_va_space",
728 .data = &randomize_va_space,
729 .maxlen = sizeof(int),
731 .proc_handler = &proc_dointvec,
734 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
736 .ctl_name = KERN_SPIN_RETRY,
737 .procname = "spin_retry",
739 .maxlen = sizeof (int),
741 .proc_handler = &proc_dointvec,
744 #ifdef CONFIG_ACPI_SLEEP
746 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
747 .procname = "acpi_video_flags",
748 .data = &acpi_video_flags,
749 .maxlen = sizeof (unsigned long),
751 .proc_handler = &proc_doulongvec_minmax,
756 .ctl_name = KERN_IA64_UNALIGNED,
757 .procname = "ignore-unaligned-usertrap",
758 .data = &no_unaligned_warning,
759 .maxlen = sizeof (int),
761 .proc_handler = &proc_dointvec,
766 .ctl_name = KERN_COMPAT_LOG,
767 .procname = "compat-log",
769 .maxlen = sizeof (int),
771 .proc_handler = &proc_dointvec,
774 #ifdef CONFIG_RT_MUTEXES
776 .ctl_name = KERN_MAX_LOCK_DEPTH,
777 .procname = "max_lock_depth",
778 .data = &max_lock_depth,
779 .maxlen = sizeof(int),
781 .proc_handler = &proc_dointvec,
788 /* Constants for minimum and maximum testing in vm_table.
789 We use these as one-element integer vectors. */
791 static int one_hundred = 100;
794 static ctl_table vm_table[] = {
796 .ctl_name = VM_OVERCOMMIT_MEMORY,
797 .procname = "overcommit_memory",
798 .data = &sysctl_overcommit_memory,
799 .maxlen = sizeof(sysctl_overcommit_memory),
801 .proc_handler = &proc_dointvec,
804 .ctl_name = VM_PANIC_ON_OOM,
805 .procname = "panic_on_oom",
806 .data = &sysctl_panic_on_oom,
807 .maxlen = sizeof(sysctl_panic_on_oom),
809 .proc_handler = &proc_dointvec,
812 .ctl_name = VM_OVERCOMMIT_RATIO,
813 .procname = "overcommit_ratio",
814 .data = &sysctl_overcommit_ratio,
815 .maxlen = sizeof(sysctl_overcommit_ratio),
817 .proc_handler = &proc_dointvec,
820 .ctl_name = VM_PAGE_CLUSTER,
821 .procname = "page-cluster",
822 .data = &page_cluster,
823 .maxlen = sizeof(int),
825 .proc_handler = &proc_dointvec,
828 .ctl_name = VM_DIRTY_BACKGROUND,
829 .procname = "dirty_background_ratio",
830 .data = &dirty_background_ratio,
831 .maxlen = sizeof(dirty_background_ratio),
833 .proc_handler = &proc_dointvec_minmax,
834 .strategy = &sysctl_intvec,
836 .extra2 = &one_hundred,
839 .ctl_name = VM_DIRTY_RATIO,
840 .procname = "dirty_ratio",
841 .data = &vm_dirty_ratio,
842 .maxlen = sizeof(vm_dirty_ratio),
844 .proc_handler = &proc_dointvec_minmax,
845 .strategy = &sysctl_intvec,
847 .extra2 = &one_hundred,
850 .ctl_name = VM_DIRTY_WB_CS,
851 .procname = "dirty_writeback_centisecs",
852 .data = &dirty_writeback_interval,
853 .maxlen = sizeof(dirty_writeback_interval),
855 .proc_handler = &dirty_writeback_centisecs_handler,
858 .ctl_name = VM_DIRTY_EXPIRE_CS,
859 .procname = "dirty_expire_centisecs",
860 .data = &dirty_expire_interval,
861 .maxlen = sizeof(dirty_expire_interval),
863 .proc_handler = &proc_dointvec_userhz_jiffies,
866 .ctl_name = VM_NR_PDFLUSH_THREADS,
867 .procname = "nr_pdflush_threads",
868 .data = &nr_pdflush_threads,
869 .maxlen = sizeof nr_pdflush_threads,
870 .mode = 0444 /* read-only*/,
871 .proc_handler = &proc_dointvec,
874 .ctl_name = VM_SWAPPINESS,
875 .procname = "swappiness",
876 .data = &vm_swappiness,
877 .maxlen = sizeof(vm_swappiness),
879 .proc_handler = &proc_dointvec_minmax,
880 .strategy = &sysctl_intvec,
882 .extra2 = &one_hundred,
884 #ifdef CONFIG_HUGETLB_PAGE
886 .ctl_name = VM_HUGETLB_PAGES,
887 .procname = "nr_hugepages",
888 .data = &max_huge_pages,
889 .maxlen = sizeof(unsigned long),
891 .proc_handler = &hugetlb_sysctl_handler,
892 .extra1 = (void *)&hugetlb_zero,
893 .extra2 = (void *)&hugetlb_infinity,
896 .ctl_name = VM_HUGETLB_GROUP,
897 .procname = "hugetlb_shm_group",
898 .data = &sysctl_hugetlb_shm_group,
899 .maxlen = sizeof(gid_t),
901 .proc_handler = &proc_dointvec,
905 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
906 .procname = "lowmem_reserve_ratio",
907 .data = &sysctl_lowmem_reserve_ratio,
908 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
910 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
911 .strategy = &sysctl_intvec,
914 .ctl_name = VM_DROP_PAGECACHE,
915 .procname = "drop_caches",
916 .data = &sysctl_drop_caches,
917 .maxlen = sizeof(int),
919 .proc_handler = drop_caches_sysctl_handler,
920 .strategy = &sysctl_intvec,
923 .ctl_name = VM_MIN_FREE_KBYTES,
924 .procname = "min_free_kbytes",
925 .data = &min_free_kbytes,
926 .maxlen = sizeof(min_free_kbytes),
928 .proc_handler = &min_free_kbytes_sysctl_handler,
929 .strategy = &sysctl_intvec,
933 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
934 .procname = "percpu_pagelist_fraction",
935 .data = &percpu_pagelist_fraction,
936 .maxlen = sizeof(percpu_pagelist_fraction),
938 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
939 .strategy = &sysctl_intvec,
940 .extra1 = &min_percpu_pagelist_fract,
944 .ctl_name = VM_MAX_MAP_COUNT,
945 .procname = "max_map_count",
946 .data = &sysctl_max_map_count,
947 .maxlen = sizeof(sysctl_max_map_count),
949 .proc_handler = &proc_dointvec
953 .ctl_name = VM_LAPTOP_MODE,
954 .procname = "laptop_mode",
955 .data = &laptop_mode,
956 .maxlen = sizeof(laptop_mode),
958 .proc_handler = &proc_dointvec_jiffies,
959 .strategy = &sysctl_jiffies,
962 .ctl_name = VM_BLOCK_DUMP,
963 .procname = "block_dump",
965 .maxlen = sizeof(block_dump),
967 .proc_handler = &proc_dointvec,
968 .strategy = &sysctl_intvec,
972 .ctl_name = VM_VFS_CACHE_PRESSURE,
973 .procname = "vfs_cache_pressure",
974 .data = &sysctl_vfs_cache_pressure,
975 .maxlen = sizeof(sysctl_vfs_cache_pressure),
977 .proc_handler = &proc_dointvec,
978 .strategy = &sysctl_intvec,
981 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
983 .ctl_name = VM_LEGACY_VA_LAYOUT,
984 .procname = "legacy_va_layout",
985 .data = &sysctl_legacy_va_layout,
986 .maxlen = sizeof(sysctl_legacy_va_layout),
988 .proc_handler = &proc_dointvec,
989 .strategy = &sysctl_intvec,
995 .ctl_name = VM_ZONE_RECLAIM_MODE,
996 .procname = "zone_reclaim_mode",
997 .data = &zone_reclaim_mode,
998 .maxlen = sizeof(zone_reclaim_mode),
1000 .proc_handler = &proc_dointvec,
1001 .strategy = &sysctl_intvec,
1005 .ctl_name = VM_MIN_UNMAPPED,
1006 .procname = "min_unmapped_ratio",
1007 .data = &sysctl_min_unmapped_ratio,
1008 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1010 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1011 .strategy = &sysctl_intvec,
1013 .extra2 = &one_hundred,
1016 .ctl_name = VM_MIN_SLAB,
1017 .procname = "min_slab_ratio",
1018 .data = &sysctl_min_slab_ratio,
1019 .maxlen = sizeof(sysctl_min_slab_ratio),
1021 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1022 .strategy = &sysctl_intvec,
1024 .extra2 = &one_hundred,
1027 #ifdef CONFIG_X86_32
1029 .ctl_name = VM_VDSO_ENABLED,
1030 .procname = "vdso_enabled",
1031 .data = &vdso_enabled,
1032 .maxlen = sizeof(vdso_enabled),
1034 .proc_handler = &proc_dointvec,
1035 .strategy = &sysctl_intvec,
1042 static ctl_table fs_table[] = {
1044 .ctl_name = FS_NRINODE,
1045 .procname = "inode-nr",
1046 .data = &inodes_stat,
1047 .maxlen = 2*sizeof(int),
1049 .proc_handler = &proc_dointvec,
1052 .ctl_name = FS_STATINODE,
1053 .procname = "inode-state",
1054 .data = &inodes_stat,
1055 .maxlen = 7*sizeof(int),
1057 .proc_handler = &proc_dointvec,
1060 .ctl_name = FS_NRFILE,
1061 .procname = "file-nr",
1062 .data = &files_stat,
1063 .maxlen = 3*sizeof(int),
1065 .proc_handler = &proc_nr_files,
1068 .ctl_name = FS_MAXFILE,
1069 .procname = "file-max",
1070 .data = &files_stat.max_files,
1071 .maxlen = sizeof(int),
1073 .proc_handler = &proc_dointvec,
1076 .ctl_name = FS_DENTRY,
1077 .procname = "dentry-state",
1078 .data = &dentry_stat,
1079 .maxlen = 6*sizeof(int),
1081 .proc_handler = &proc_dointvec,
1084 .ctl_name = FS_OVERFLOWUID,
1085 .procname = "overflowuid",
1086 .data = &fs_overflowuid,
1087 .maxlen = sizeof(int),
1089 .proc_handler = &proc_dointvec_minmax,
1090 .strategy = &sysctl_intvec,
1091 .extra1 = &minolduid,
1092 .extra2 = &maxolduid,
1095 .ctl_name = FS_OVERFLOWGID,
1096 .procname = "overflowgid",
1097 .data = &fs_overflowgid,
1098 .maxlen = sizeof(int),
1100 .proc_handler = &proc_dointvec_minmax,
1101 .strategy = &sysctl_intvec,
1102 .extra1 = &minolduid,
1103 .extra2 = &maxolduid,
1106 .ctl_name = FS_LEASES,
1107 .procname = "leases-enable",
1108 .data = &leases_enable,
1109 .maxlen = sizeof(int),
1111 .proc_handler = &proc_dointvec,
1113 #ifdef CONFIG_DNOTIFY
1115 .ctl_name = FS_DIR_NOTIFY,
1116 .procname = "dir-notify-enable",
1117 .data = &dir_notify_enable,
1118 .maxlen = sizeof(int),
1120 .proc_handler = &proc_dointvec,
1125 .ctl_name = FS_LEASE_TIME,
1126 .procname = "lease-break-time",
1127 .data = &lease_break_time,
1128 .maxlen = sizeof(int),
1130 .proc_handler = &proc_dointvec,
1133 .ctl_name = FS_AIO_NR,
1134 .procname = "aio-nr",
1136 .maxlen = sizeof(aio_nr),
1138 .proc_handler = &proc_doulongvec_minmax,
1141 .ctl_name = FS_AIO_MAX_NR,
1142 .procname = "aio-max-nr",
1143 .data = &aio_max_nr,
1144 .maxlen = sizeof(aio_max_nr),
1146 .proc_handler = &proc_doulongvec_minmax,
1148 #ifdef CONFIG_INOTIFY_USER
1150 .ctl_name = FS_INOTIFY,
1151 .procname = "inotify",
1153 .child = inotify_table,
1158 .ctl_name = KERN_SETUID_DUMPABLE,
1159 .procname = "suid_dumpable",
1160 .data = &suid_dumpable,
1161 .maxlen = sizeof(int),
1163 .proc_handler = &proc_dointvec,
1168 static ctl_table debug_table[] = {
1172 static ctl_table dev_table[] = {
1176 extern void init_irq_proc (void);
1178 static DEFINE_SPINLOCK(sysctl_lock);
1180 /* called under sysctl_lock */
1181 static int use_table(struct ctl_table_header *p)
1183 if (unlikely(p->unregistering))
1189 /* called under sysctl_lock */
1190 static void unuse_table(struct ctl_table_header *p)
1193 if (unlikely(p->unregistering))
1194 complete(p->unregistering);
1197 /* called under sysctl_lock, will reacquire if has to wait */
1198 static void start_unregistering(struct ctl_table_header *p)
1201 * if p->used is 0, nobody will ever touch that entry again;
1202 * we'll eliminate all paths to it before dropping sysctl_lock
1204 if (unlikely(p->used)) {
1205 struct completion wait;
1206 init_completion(&wait);
1207 p->unregistering = &wait;
1208 spin_unlock(&sysctl_lock);
1209 wait_for_completion(&wait);
1210 spin_lock(&sysctl_lock);
1213 * do not remove from the list until nobody holds it; walking the
1214 * list in do_sysctl() relies on that.
1216 list_del_init(&p->ctl_entry);
1219 void __init sysctl_init(void)
1221 #ifdef CONFIG_PROC_SYSCTL
1222 register_proc_table(root_table, proc_sys_root, &root_table_header);
1227 #ifdef CONFIG_SYSCTL_SYSCALL
1228 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1229 void __user *newval, size_t newlen)
1231 struct list_head *tmp;
1232 int error = -ENOTDIR;
1234 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1238 if (!oldlenp || get_user(old_len, oldlenp))
1241 spin_lock(&sysctl_lock);
1242 tmp = &root_table_header.ctl_entry;
1244 struct ctl_table_header *head =
1245 list_entry(tmp, struct ctl_table_header, ctl_entry);
1246 void *context = NULL;
1248 if (!use_table(head))
1251 spin_unlock(&sysctl_lock);
1253 error = parse_table(name, nlen, oldval, oldlenp,
1254 newval, newlen, head->ctl_table,
1258 spin_lock(&sysctl_lock);
1260 if (error != -ENOTDIR)
1262 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1263 spin_unlock(&sysctl_lock);
1267 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1269 struct __sysctl_args tmp;
1272 if (copy_from_user(&tmp, args, sizeof(tmp)))
1276 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1277 tmp.newval, tmp.newlen);
1281 #endif /* CONFIG_SYSCTL_SYSCALL */
1284 * ctl_perm does NOT grant the superuser all rights automatically, because
1285 * some sysctl variables are readonly even to root.
1288 static int test_perm(int mode, int op)
1292 else if (in_egroup_p(0))
1294 if ((mode & op & 0007) == op)
1299 static inline int ctl_perm(ctl_table *table, int op)
1302 error = security_sysctl(table, op);
1305 return test_perm(table->mode, op);
1308 #ifdef CONFIG_SYSCTL_SYSCALL
1309 static int parse_table(int __user *name, int nlen,
1310 void __user *oldval, size_t __user *oldlenp,
1311 void __user *newval, size_t newlen,
1312 ctl_table *table, void **context)
1318 if (get_user(n, name))
1320 for ( ; table->ctl_name || table->procname; table++) {
1321 if (!table->ctl_name)
1323 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1326 if (ctl_perm(table, 001))
1328 if (table->strategy) {
1329 error = table->strategy(
1332 newval, newlen, context);
1338 table = table->child;
1341 error = do_sysctl_strategy(table, name, nlen,
1343 newval, newlen, context);
1350 /* Perform the actual read/write of a sysctl table entry. */
1351 int do_sysctl_strategy (ctl_table *table,
1352 int __user *name, int nlen,
1353 void __user *oldval, size_t __user *oldlenp,
1354 void __user *newval, size_t newlen, void **context)
1363 if (ctl_perm(table, op))
1366 if (table->strategy) {
1367 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1368 newval, newlen, context);
1375 /* If there is no strategy routine, or if the strategy returns
1376 * zero, proceed with automatic r/w */
1377 if (table->data && table->maxlen) {
1378 if (oldval && oldlenp) {
1379 if (get_user(len, oldlenp))
1382 if (len > table->maxlen)
1383 len = table->maxlen;
1384 if(copy_to_user(oldval, table->data, len))
1386 if(put_user(len, oldlenp))
1390 if (newval && newlen) {
1392 if (len > table->maxlen)
1393 len = table->maxlen;
1394 if(copy_from_user(table->data, newval, len))
1400 #endif /* CONFIG_SYSCTL_SYSCALL */
1403 * register_sysctl_table - register a sysctl hierarchy
1404 * @table: the top-level table structure
1405 * @insert_at_head: whether the entry should be inserted in front or at the end
1407 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1408 * array. An entry with a ctl_name of 0 terminates the table.
1410 * The members of the &ctl_table structure are used as follows:
1412 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1413 * must be unique within that level of sysctl
1415 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1416 * enter a sysctl file
1418 * data - a pointer to data for use by proc_handler
1420 * maxlen - the maximum size in bytes of the data
1422 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1424 * child - a pointer to the child sysctl table if this entry is a directory, or
1427 * proc_handler - the text handler routine (described below)
1429 * strategy - the strategy routine (described below)
1431 * de - for internal use by the sysctl routines
1433 * extra1, extra2 - extra pointers usable by the proc handler routines
1435 * Leaf nodes in the sysctl tree will be represented by a single file
1436 * under /proc; non-leaf nodes will be represented by directories.
1438 * sysctl(2) can automatically manage read and write requests through
1439 * the sysctl table. The data and maxlen fields of the ctl_table
1440 * struct enable minimal validation of the values being written to be
1441 * performed, and the mode field allows minimal authentication.
1443 * More sophisticated management can be enabled by the provision of a
1444 * strategy routine with the table entry. This will be called before
1445 * any automatic read or write of the data is performed.
1447 * The strategy routine may return
1449 * < 0 - Error occurred (error is passed to user process)
1451 * 0 - OK - proceed with automatic read or write.
1453 * > 0 - OK - read or write has been done by the strategy routine, so
1454 * return immediately.
1456 * There must be a proc_handler routine for any terminal nodes
1457 * mirrored under /proc/sys (non-terminals are handled by a built-in
1458 * directory handler). Several default handlers are available to
1459 * cover common cases -
1461 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1462 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1463 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1465 * It is the handler's job to read the input buffer from user memory
1466 * and process it. The handler should return 0 on success.
1468 * This routine returns %NULL on a failure to register, and a pointer
1469 * to the table header on success.
1471 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1474 struct ctl_table_header *tmp;
1475 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1478 tmp->ctl_table = table;
1479 INIT_LIST_HEAD(&tmp->ctl_entry);
1481 tmp->unregistering = NULL;
1482 spin_lock(&sysctl_lock);
1484 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1486 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1487 spin_unlock(&sysctl_lock);
1488 #ifdef CONFIG_PROC_SYSCTL
1489 register_proc_table(table, proc_sys_root, tmp);
1495 * unregister_sysctl_table - unregister a sysctl table hierarchy
1496 * @header: the header returned from register_sysctl_table
1498 * Unregisters the sysctl table and all children. proc entries may not
1499 * actually be removed until they are no longer used by anyone.
1501 void unregister_sysctl_table(struct ctl_table_header * header)
1504 spin_lock(&sysctl_lock);
1505 start_unregistering(header);
1506 #ifdef CONFIG_PROC_SYSCTL
1507 unregister_proc_table(header->ctl_table, proc_sys_root);
1509 spin_unlock(&sysctl_lock);
1513 #else /* !CONFIG_SYSCTL */
1514 struct ctl_table_header * register_sysctl_table(ctl_table * table,
1520 void unregister_sysctl_table(struct ctl_table_header * table)
1524 #endif /* CONFIG_SYSCTL */
1530 #ifdef CONFIG_PROC_SYSCTL
1532 /* Scan the sysctl entries in table and add them all into /proc */
1533 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1535 struct proc_dir_entry *de;
1539 for (; table->ctl_name || table->procname; table++) {
1540 /* Can't do anything without a proc name. */
1541 if (!table->procname)
1543 /* Maybe we can't do anything with it... */
1544 if (!table->proc_handler && !table->child) {
1545 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1550 len = strlen(table->procname);
1554 if (table->proc_handler)
1558 for (de = root->subdir; de; de = de->next) {
1559 if (proc_match(len, table->procname, de))
1562 /* If the subdir exists already, de is non-NULL */
1566 de = create_proc_entry(table->procname, mode, root);
1570 de->data = (void *) table;
1571 if (table->proc_handler)
1572 de->proc_fops = &proc_sys_file_operations;
1575 if (de->mode & S_IFDIR)
1576 register_proc_table(table->child, de, set);
1581 * Unregister a /proc sysctl table and any subdirectories.
1583 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1585 struct proc_dir_entry *de;
1586 for (; table->ctl_name || table->procname; table++) {
1587 if (!(de = table->de))
1589 if (de->mode & S_IFDIR) {
1590 if (!table->child) {
1591 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1594 unregister_proc_table(table->child, de);
1596 /* Don't unregister directories which still have entries.. */
1602 * In any case, mark the entry as goner; we'll keep it
1603 * around if it's busy, but we'll know to do nothing with
1604 * its fields. We are under sysctl_lock here.
1608 /* Don't unregister proc entries that are still being used.. */
1609 if (atomic_read(&de->count))
1613 remove_proc_entry(table->procname, root);
1617 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1618 size_t count, loff_t *ppos)
1621 struct proc_dir_entry *de = PDE(file->f_path.dentry->d_inode);
1622 struct ctl_table *table;
1624 ssize_t error = -ENOTDIR;
1626 spin_lock(&sysctl_lock);
1627 if (de && de->data && use_table(de->set)) {
1629 * at that point we know that sysctl was not unregistered
1630 * and won't be until we finish
1632 spin_unlock(&sysctl_lock);
1633 table = (struct ctl_table *) de->data;
1634 if (!table || !table->proc_handler)
1637 op = (write ? 002 : 004);
1638 if (ctl_perm(table, op))
1641 /* careful: calling conventions are nasty here */
1643 error = (*table->proc_handler)(table, write, file,
1648 spin_lock(&sysctl_lock);
1649 unuse_table(de->set);
1651 spin_unlock(&sysctl_lock);
1655 static int proc_opensys(struct inode *inode, struct file *file)
1657 if (file->f_mode & FMODE_WRITE) {
1659 * sysctl entries that are not writable,
1660 * are _NOT_ writable, capabilities or not.
1662 if (!(inode->i_mode & S_IWUSR))
1669 static ssize_t proc_readsys(struct file * file, char __user * buf,
1670 size_t count, loff_t *ppos)
1672 return do_rw_proc(0, file, buf, count, ppos);
1675 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1676 size_t count, loff_t *ppos)
1678 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1681 static int _proc_do_string(void* data, int maxlen, int write,
1682 struct file *filp, void __user *buffer,
1683 size_t *lenp, loff_t *ppos)
1689 if (!data || !maxlen || !*lenp ||
1690 (*ppos && !write)) {
1698 while (len < *lenp) {
1699 if (get_user(c, p++))
1701 if (c == 0 || c == '\n')
1707 if(copy_from_user(data, buffer, len))
1709 ((char *) data)[len] = 0;
1718 if(copy_to_user(buffer, data, len))
1721 if(put_user('\n', ((char __user *) buffer) + len))
1732 * proc_dostring - read a string sysctl
1733 * @table: the sysctl table
1734 * @write: %TRUE if this is a write to the sysctl file
1735 * @filp: the file structure
1736 * @buffer: the user buffer
1737 * @lenp: the size of the user buffer
1738 * @ppos: file position
1740 * Reads/writes a string from/to the user buffer. If the kernel
1741 * buffer provided is not large enough to hold the string, the
1742 * string is truncated. The copied string is %NULL-terminated.
1743 * If the string is being read by the user process, it is copied
1744 * and a newline '\n' is added. It is truncated if the buffer is
1747 * Returns 0 on success.
1749 int proc_dostring(ctl_table *table, int write, struct file *filp,
1750 void __user *buffer, size_t *lenp, loff_t *ppos)
1752 return _proc_do_string(table->data, table->maxlen, write, filp,
1753 buffer, lenp, ppos);
1757 * Special case of dostring for the UTS structure. This has locks
1758 * to observe. Should this be in kernel/sys.c ????
1761 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
1762 void __user *buffer, size_t *lenp, loff_t *ppos)
1766 which = get_uts(table, write);
1767 r = _proc_do_string(which, table->maxlen,write,filp,buffer,lenp, ppos);
1768 put_uts(table, write, which);
1772 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1774 int write, void *data)
1777 *valp = *negp ? -*lvalp : *lvalp;
1782 *lvalp = (unsigned long)-val;
1785 *lvalp = (unsigned long)val;
1791 static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1792 int write, struct file *filp, void __user *buffer,
1793 size_t *lenp, loff_t *ppos,
1794 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1795 int write, void *data),
1798 #define TMPBUFLEN 21
1799 int *i, vleft, first=1, neg, val;
1803 char buf[TMPBUFLEN], *p;
1804 char __user *s = buffer;
1806 if (!tbl_data || !table->maxlen || !*lenp ||
1807 (*ppos && !write)) {
1812 i = (int *) tbl_data;
1813 vleft = table->maxlen / sizeof(*i);
1817 conv = do_proc_dointvec_conv;
1819 for (; left && vleft--; i++, first=0) {
1834 if (len > sizeof(buf) - 1)
1835 len = sizeof(buf) - 1;
1836 if (copy_from_user(buf, s, len))
1840 if (*p == '-' && left > 1) {
1844 if (*p < '0' || *p > '9')
1847 lval = simple_strtoul(p, &p, 0);
1850 if ((len < left) && *p && !isspace(*p))
1857 if (conv(&neg, &lval, i, 1, data))
1864 if (conv(&neg, &lval, i, 0, data))
1867 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1871 if(copy_to_user(s, buf, len))
1878 if (!write && !first && left) {
1879 if(put_user('\n', s))
1886 if (get_user(c, s++))
1901 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1902 void __user *buffer, size_t *lenp, loff_t *ppos,
1903 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1904 int write, void *data),
1907 return __do_proc_dointvec(table->data, table, write, filp,
1908 buffer, lenp, ppos, conv, data);
1912 * proc_dointvec - read a vector of integers
1913 * @table: the sysctl table
1914 * @write: %TRUE if this is a write to the sysctl file
1915 * @filp: the file structure
1916 * @buffer: the user buffer
1917 * @lenp: the size of the user buffer
1918 * @ppos: file position
1920 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1921 * values from/to the user buffer, treated as an ASCII string.
1923 * Returns 0 on success.
1925 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1926 void __user *buffer, size_t *lenp, loff_t *ppos)
1928 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1938 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1940 int write, void *data)
1942 int op = *(int *)data;
1944 int val = *negp ? -*lvalp : *lvalp;
1946 case OP_SET: *valp = val; break;
1947 case OP_AND: *valp &= val; break;
1948 case OP_OR: *valp |= val; break;
1949 case OP_MAX: if(*valp < val)
1952 case OP_MIN: if(*valp > val)
1960 *lvalp = (unsigned long)-val;
1963 *lvalp = (unsigned long)val;
1970 * init may raise the set.
1973 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1974 void __user *buffer, size_t *lenp, loff_t *ppos)
1978 if (!capable(CAP_SYS_MODULE)) {
1982 op = is_init(current) ? OP_SET : OP_AND;
1983 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1984 do_proc_dointvec_bset_conv,&op);
1987 struct do_proc_dointvec_minmax_conv_param {
1992 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1994 int write, void *data)
1996 struct do_proc_dointvec_minmax_conv_param *param = data;
1998 int val = *negp ? -*lvalp : *lvalp;
1999 if ((param->min && *param->min > val) ||
2000 (param->max && *param->max < val))
2007 *lvalp = (unsigned long)-val;
2010 *lvalp = (unsigned long)val;
2017 * proc_dointvec_minmax - read a vector of integers with min/max values
2018 * @table: the sysctl table
2019 * @write: %TRUE if this is a write to the sysctl file
2020 * @filp: the file structure
2021 * @buffer: the user buffer
2022 * @lenp: the size of the user buffer
2023 * @ppos: file position
2025 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2026 * values from/to the user buffer, treated as an ASCII string.
2028 * This routine will ensure the values are within the range specified by
2029 * table->extra1 (min) and table->extra2 (max).
2031 * Returns 0 on success.
2033 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2034 void __user *buffer, size_t *lenp, loff_t *ppos)
2036 struct do_proc_dointvec_minmax_conv_param param = {
2037 .min = (int *) table->extra1,
2038 .max = (int *) table->extra2,
2040 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2041 do_proc_dointvec_minmax_conv, ¶m);
2044 static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
2046 void __user *buffer,
2047 size_t *lenp, loff_t *ppos,
2048 unsigned long convmul,
2049 unsigned long convdiv)
2051 #define TMPBUFLEN 21
2052 unsigned long *i, *min, *max, val;
2053 int vleft, first=1, neg;
2055 char buf[TMPBUFLEN], *p;
2056 char __user *s = buffer;
2058 if (!data || !table->maxlen || !*lenp ||
2059 (*ppos && !write)) {
2064 i = (unsigned long *) data;
2065 min = (unsigned long *) table->extra1;
2066 max = (unsigned long *) table->extra2;
2067 vleft = table->maxlen / sizeof(unsigned long);
2070 for (; left && vleft--; i++, min++, max++, first=0) {
2085 if (len > TMPBUFLEN-1)
2087 if (copy_from_user(buf, s, len))
2091 if (*p == '-' && left > 1) {
2095 if (*p < '0' || *p > '9')
2097 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2099 if ((len < left) && *p && !isspace(*p))
2108 if ((min && val < *min) || (max && val > *max))
2115 sprintf(p, "%lu", convdiv * (*i) / convmul);
2119 if(copy_to_user(s, buf, len))
2126 if (!write && !first && left) {
2127 if(put_user('\n', s))
2134 if (get_user(c, s++))
2149 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2151 void __user *buffer,
2152 size_t *lenp, loff_t *ppos,
2153 unsigned long convmul,
2154 unsigned long convdiv)
2156 return __do_proc_doulongvec_minmax(table->data, table, write,
2157 filp, buffer, lenp, ppos, convmul, convdiv);
2161 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2162 * @table: the sysctl table
2163 * @write: %TRUE if this is a write to the sysctl file
2164 * @filp: the file structure
2165 * @buffer: the user buffer
2166 * @lenp: the size of the user buffer
2167 * @ppos: file position
2169 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2170 * values from/to the user buffer, treated as an ASCII string.
2172 * This routine will ensure the values are within the range specified by
2173 * table->extra1 (min) and table->extra2 (max).
2175 * Returns 0 on success.
2177 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2178 void __user *buffer, size_t *lenp, loff_t *ppos)
2180 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2184 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2185 * @table: the sysctl table
2186 * @write: %TRUE if this is a write to the sysctl file
2187 * @filp: the file structure
2188 * @buffer: the user buffer
2189 * @lenp: the size of the user buffer
2190 * @ppos: file position
2192 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2193 * values from/to the user buffer, treated as an ASCII string. The values
2194 * are treated as milliseconds, and converted to jiffies when they are stored.
2196 * This routine will ensure the values are within the range specified by
2197 * table->extra1 (min) and table->extra2 (max).
2199 * Returns 0 on success.
2201 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2203 void __user *buffer,
2204 size_t *lenp, loff_t *ppos)
2206 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2207 lenp, ppos, HZ, 1000l);
2211 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2213 int write, void *data)
2216 if (*lvalp > LONG_MAX / HZ)
2218 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2224 lval = (unsigned long)-val;
2227 lval = (unsigned long)val;
2234 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2236 int write, void *data)
2239 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2241 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2247 lval = (unsigned long)-val;
2250 lval = (unsigned long)val;
2252 *lvalp = jiffies_to_clock_t(lval);
2257 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2259 int write, void *data)
2262 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2268 lval = (unsigned long)-val;
2271 lval = (unsigned long)val;
2273 *lvalp = jiffies_to_msecs(lval);
2279 * proc_dointvec_jiffies - read a vector of integers as seconds
2280 * @table: the sysctl table
2281 * @write: %TRUE if this is a write to the sysctl file
2282 * @filp: the file structure
2283 * @buffer: the user buffer
2284 * @lenp: the size of the user buffer
2285 * @ppos: file position
2287 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2288 * values from/to the user buffer, treated as an ASCII string.
2289 * The values read are assumed to be in seconds, and are converted into
2292 * Returns 0 on success.
2294 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2295 void __user *buffer, size_t *lenp, loff_t *ppos)
2297 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2298 do_proc_dointvec_jiffies_conv,NULL);
2302 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2303 * @table: the sysctl table
2304 * @write: %TRUE if this is a write to the sysctl file
2305 * @filp: the file structure
2306 * @buffer: the user buffer
2307 * @lenp: the size of the user buffer
2308 * @ppos: pointer to the file position
2310 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2311 * values from/to the user buffer, treated as an ASCII string.
2312 * The values read are assumed to be in 1/USER_HZ seconds, and
2313 * are converted into jiffies.
2315 * Returns 0 on success.
2317 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2318 void __user *buffer, size_t *lenp, loff_t *ppos)
2320 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2321 do_proc_dointvec_userhz_jiffies_conv,NULL);
2325 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2326 * @table: the sysctl table
2327 * @write: %TRUE if this is a write to the sysctl file
2328 * @filp: the file structure
2329 * @buffer: the user buffer
2330 * @lenp: the size of the user buffer
2331 * @ppos: file position
2332 * @ppos: the current position in the file
2334 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2335 * values from/to the user buffer, treated as an ASCII string.
2336 * The values read are assumed to be in 1/1000 seconds, and
2337 * are converted into jiffies.
2339 * Returns 0 on success.
2341 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2342 void __user *buffer, size_t *lenp, loff_t *ppos)
2344 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2345 do_proc_dointvec_ms_jiffies_conv, NULL);
2348 #ifdef CONFIG_SYSVIPC
2349 static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
2350 void __user *buffer, size_t *lenp, loff_t *ppos)
2353 which = get_ipc(table, write);
2354 return __do_proc_dointvec(which, table, write, filp, buffer,
2355 lenp, ppos, NULL, NULL);
2358 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
2359 struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
2362 which = get_ipc(table, write);
2363 return __do_proc_doulongvec_minmax(which, table, write, filp, buffer,
2364 lenp, ppos, 1l, 1l);
2369 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2370 void __user *buffer, size_t *lenp, loff_t *ppos)
2372 struct pid *new_pid;
2376 tmp = pid_nr(cad_pid);
2378 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2379 lenp, ppos, NULL, NULL);
2383 new_pid = find_get_pid(tmp);
2387 put_pid(xchg(&cad_pid, new_pid));
2391 #else /* CONFIG_PROC_FS */
2393 int proc_dostring(ctl_table *table, int write, struct file *filp,
2394 void __user *buffer, size_t *lenp, loff_t *ppos)
2399 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
2400 void __user *buffer, size_t *lenp, loff_t *ppos)
2405 #ifdef CONFIG_SYSVIPC
2406 static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2407 void __user *buffer, size_t *lenp, loff_t *ppos)
2413 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2414 void __user *buffer, size_t *lenp, loff_t *ppos)
2419 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2420 void __user *buffer, size_t *lenp, loff_t *ppos)
2425 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2426 void __user *buffer, size_t *lenp, loff_t *ppos)
2431 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2432 void __user *buffer, size_t *lenp, loff_t *ppos)
2437 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2438 void __user *buffer, size_t *lenp, loff_t *ppos)
2443 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2444 void __user *buffer, size_t *lenp, loff_t *ppos)
2449 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2450 void __user *buffer, size_t *lenp, loff_t *ppos)
2455 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2457 void __user *buffer,
2458 size_t *lenp, loff_t *ppos)
2464 #endif /* CONFIG_PROC_FS */
2467 #ifdef CONFIG_SYSCTL_SYSCALL
2469 * General sysctl support routines
2472 /* The generic string strategy routine: */
2473 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2474 void __user *oldval, size_t __user *oldlenp,
2475 void __user *newval, size_t newlen, void **context)
2477 if (!table->data || !table->maxlen)
2480 if (oldval && oldlenp) {
2482 if (get_user(bufsize, oldlenp))
2485 size_t len = strlen(table->data), copied;
2487 /* This shouldn't trigger for a well-formed sysctl */
2488 if (len > table->maxlen)
2489 len = table->maxlen;
2491 /* Copy up to a max of bufsize-1 bytes of the string */
2492 copied = (len >= bufsize) ? bufsize - 1 : len;
2494 if (copy_to_user(oldval, table->data, copied) ||
2495 put_user(0, (char __user *)(oldval + copied)))
2497 if (put_user(len, oldlenp))
2501 if (newval && newlen) {
2502 size_t len = newlen;
2503 if (len > table->maxlen)
2504 len = table->maxlen;
2505 if(copy_from_user(table->data, newval, len))
2507 if (len == table->maxlen)
2509 ((char *) table->data)[len] = 0;
2515 * This function makes sure that all of the integers in the vector
2516 * are between the minimum and maximum values given in the arrays
2517 * table->extra1 and table->extra2, respectively.
2519 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2520 void __user *oldval, size_t __user *oldlenp,
2521 void __user *newval, size_t newlen, void **context)
2524 if (newval && newlen) {
2525 int __user *vec = (int __user *) newval;
2526 int *min = (int *) table->extra1;
2527 int *max = (int *) table->extra2;
2531 if (newlen % sizeof(int) != 0)
2534 if (!table->extra1 && !table->extra2)
2537 if (newlen > table->maxlen)
2538 newlen = table->maxlen;
2539 length = newlen / sizeof(int);
2541 for (i = 0; i < length; i++) {
2543 if (get_user(value, vec + i))
2545 if (min && value < min[i])
2547 if (max && value > max[i])
2554 /* Strategy function to convert jiffies to seconds */
2555 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2556 void __user *oldval, size_t __user *oldlenp,
2557 void __user *newval, size_t newlen, void **context)
2562 if (get_user(olen, oldlenp))
2564 if (olen!=sizeof(int))
2567 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2568 (oldlenp && put_user(sizeof(int),oldlenp)))
2571 if (newval && newlen) {
2573 if (newlen != sizeof(int))
2575 if (get_user(new, (int __user *)newval))
2577 *(int *)(table->data) = new*HZ;
2582 /* Strategy function to convert jiffies to seconds */
2583 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2584 void __user *oldval, size_t __user *oldlenp,
2585 void __user *newval, size_t newlen, void **context)
2590 if (get_user(olen, oldlenp))
2592 if (olen!=sizeof(int))
2595 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2596 (oldlenp && put_user(sizeof(int),oldlenp)))
2599 if (newval && newlen) {
2601 if (newlen != sizeof(int))
2603 if (get_user(new, (int __user *)newval))
2605 *(int *)(table->data) = msecs_to_jiffies(new);
2611 /* The generic string strategy routine: */
2612 static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2613 void __user *oldval, size_t __user *oldlenp,
2614 void __user *newval, size_t newlen, void **context)
2616 struct ctl_table uts_table;
2618 write = newval && newlen;
2619 memcpy(&uts_table, table, sizeof(uts_table));
2620 uts_table.data = get_uts(table, write);
2621 r = sysctl_string(&uts_table, name, nlen,
2622 oldval, oldlenp, newval, newlen, context);
2623 put_uts(table, write, uts_table.data);
2627 #ifdef CONFIG_SYSVIPC
2628 /* The generic sysctl ipc data routine. */
2629 static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
2630 void __user *oldval, size_t __user *oldlenp,
2631 void __user *newval, size_t newlen, void **context)
2636 /* Get out of I don't have a variable */
2637 if (!table->data || !table->maxlen)
2640 data = get_ipc(table, 1);
2644 if (oldval && oldlenp) {
2645 if (get_user(len, oldlenp))
2648 if (len > table->maxlen)
2649 len = table->maxlen;
2650 if (copy_to_user(oldval, data, len))
2652 if (put_user(len, oldlenp))
2657 if (newval && newlen) {
2658 if (newlen > table->maxlen)
2659 newlen = table->maxlen;
2661 if (copy_from_user(data, newval, newlen))
2668 #else /* CONFIG_SYSCTL_SYSCALL */
2671 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2673 static int msg_count;
2674 struct __sysctl_args tmp;
2675 int name[CTL_MAXNAME];
2678 /* Read in the sysctl name for better debug message logging */
2679 if (copy_from_user(&tmp, args, sizeof(tmp)))
2681 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2683 for (i = 0; i < tmp.nlen; i++)
2684 if (get_user(name[i], tmp.name + i))
2687 /* Ignore accesses to kernel.version */
2688 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2691 if (msg_count < 5) {
2694 "warning: process `%s' used the removed sysctl "
2695 "system call with ", current->comm);
2696 for (i = 0; i < tmp.nlen; i++)
2697 printk("%d.", name[i]);
2704 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2705 void __user *oldval, size_t __user *oldlenp,
2706 void __user *newval, size_t newlen, void **context)
2711 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2712 void __user *oldval, size_t __user *oldlenp,
2713 void __user *newval, size_t newlen, void **context)
2718 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2719 void __user *oldval, size_t __user *oldlenp,
2720 void __user *newval, size_t newlen, void **context)
2725 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2726 void __user *oldval, size_t __user *oldlenp,
2727 void __user *newval, size_t newlen, void **context)
2732 static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2733 void __user *oldval, size_t __user *oldlenp,
2734 void __user *newval, size_t newlen, void **context)
2738 static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
2739 void __user *oldval, size_t __user *oldlenp,
2740 void __user *newval, size_t newlen, void **context)
2744 #endif /* CONFIG_SYSCTL_SYSCALL */
2747 * No sense putting this after each symbol definition, twice,
2748 * exception granted :-)
2750 EXPORT_SYMBOL(proc_dointvec);
2751 EXPORT_SYMBOL(proc_dointvec_jiffies);
2752 EXPORT_SYMBOL(proc_dointvec_minmax);
2753 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2754 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2755 EXPORT_SYMBOL(proc_dostring);
2756 EXPORT_SYMBOL(proc_doulongvec_minmax);
2757 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2758 EXPORT_SYMBOL(register_sysctl_table);
2759 EXPORT_SYMBOL(sysctl_intvec);
2760 EXPORT_SYMBOL(sysctl_jiffies);
2761 EXPORT_SYMBOL(sysctl_ms_jiffies);
2762 EXPORT_SYMBOL(sysctl_string);
2763 EXPORT_SYMBOL(unregister_sysctl_table);