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 *);
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);
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);
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);
1247 if (!use_table(head))
1250 spin_unlock(&sysctl_lock);
1252 error = parse_table(name, nlen, oldval, oldlenp,
1253 newval, newlen, head->ctl_table);
1255 spin_lock(&sysctl_lock);
1257 if (error != -ENOTDIR)
1259 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1260 spin_unlock(&sysctl_lock);
1264 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1266 struct __sysctl_args tmp;
1269 if (copy_from_user(&tmp, args, sizeof(tmp)))
1273 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1274 tmp.newval, tmp.newlen);
1278 #endif /* CONFIG_SYSCTL_SYSCALL */
1281 * ctl_perm does NOT grant the superuser all rights automatically, because
1282 * some sysctl variables are readonly even to root.
1285 static int test_perm(int mode, int op)
1289 else if (in_egroup_p(0))
1291 if ((mode & op & 0007) == op)
1296 static inline int ctl_perm(ctl_table *table, int op)
1299 error = security_sysctl(table, op);
1302 return test_perm(table->mode, op);
1305 #ifdef CONFIG_SYSCTL_SYSCALL
1306 static int parse_table(int __user *name, int nlen,
1307 void __user *oldval, size_t __user *oldlenp,
1308 void __user *newval, size_t newlen,
1315 if (get_user(n, name))
1317 for ( ; table->ctl_name || table->procname; table++) {
1318 if (!table->ctl_name)
1320 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1323 if (ctl_perm(table, 001))
1325 if (table->strategy) {
1326 error = table->strategy(
1335 table = table->child;
1338 error = do_sysctl_strategy(table, name, nlen,
1347 /* Perform the actual read/write of a sysctl table entry. */
1348 int do_sysctl_strategy (ctl_table *table,
1349 int __user *name, int nlen,
1350 void __user *oldval, size_t __user *oldlenp,
1351 void __user *newval, size_t newlen)
1360 if (ctl_perm(table, op))
1363 if (table->strategy) {
1364 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1372 /* If there is no strategy routine, or if the strategy returns
1373 * zero, proceed with automatic r/w */
1374 if (table->data && table->maxlen) {
1375 if (oldval && oldlenp) {
1376 if (get_user(len, oldlenp))
1379 if (len > table->maxlen)
1380 len = table->maxlen;
1381 if(copy_to_user(oldval, table->data, len))
1383 if(put_user(len, oldlenp))
1387 if (newval && newlen) {
1389 if (len > table->maxlen)
1390 len = table->maxlen;
1391 if(copy_from_user(table->data, newval, len))
1397 #endif /* CONFIG_SYSCTL_SYSCALL */
1400 * register_sysctl_table - register a sysctl hierarchy
1401 * @table: the top-level table structure
1402 * @insert_at_head: whether the entry should be inserted in front or at the end
1404 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1405 * array. An entry with a ctl_name of 0 terminates the table.
1407 * The members of the &ctl_table structure are used as follows:
1409 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1410 * must be unique within that level of sysctl
1412 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1413 * enter a sysctl file
1415 * data - a pointer to data for use by proc_handler
1417 * maxlen - the maximum size in bytes of the data
1419 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1421 * child - a pointer to the child sysctl table if this entry is a directory, or
1424 * proc_handler - the text handler routine (described below)
1426 * strategy - the strategy routine (described below)
1428 * de - for internal use by the sysctl routines
1430 * extra1, extra2 - extra pointers usable by the proc handler routines
1432 * Leaf nodes in the sysctl tree will be represented by a single file
1433 * under /proc; non-leaf nodes will be represented by directories.
1435 * sysctl(2) can automatically manage read and write requests through
1436 * the sysctl table. The data and maxlen fields of the ctl_table
1437 * struct enable minimal validation of the values being written to be
1438 * performed, and the mode field allows minimal authentication.
1440 * More sophisticated management can be enabled by the provision of a
1441 * strategy routine with the table entry. This will be called before
1442 * any automatic read or write of the data is performed.
1444 * The strategy routine may return
1446 * < 0 - Error occurred (error is passed to user process)
1448 * 0 - OK - proceed with automatic read or write.
1450 * > 0 - OK - read or write has been done by the strategy routine, so
1451 * return immediately.
1453 * There must be a proc_handler routine for any terminal nodes
1454 * mirrored under /proc/sys (non-terminals are handled by a built-in
1455 * directory handler). Several default handlers are available to
1456 * cover common cases -
1458 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1459 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1460 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1462 * It is the handler's job to read the input buffer from user memory
1463 * and process it. The handler should return 0 on success.
1465 * This routine returns %NULL on a failure to register, and a pointer
1466 * to the table header on success.
1468 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1471 struct ctl_table_header *tmp;
1472 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1475 tmp->ctl_table = table;
1476 INIT_LIST_HEAD(&tmp->ctl_entry);
1478 tmp->unregistering = NULL;
1479 spin_lock(&sysctl_lock);
1481 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1483 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1484 spin_unlock(&sysctl_lock);
1485 #ifdef CONFIG_PROC_SYSCTL
1486 register_proc_table(table, proc_sys_root, tmp);
1492 * unregister_sysctl_table - unregister a sysctl table hierarchy
1493 * @header: the header returned from register_sysctl_table
1495 * Unregisters the sysctl table and all children. proc entries may not
1496 * actually be removed until they are no longer used by anyone.
1498 void unregister_sysctl_table(struct ctl_table_header * header)
1501 spin_lock(&sysctl_lock);
1502 start_unregistering(header);
1503 #ifdef CONFIG_PROC_SYSCTL
1504 unregister_proc_table(header->ctl_table, proc_sys_root);
1506 spin_unlock(&sysctl_lock);
1510 #else /* !CONFIG_SYSCTL */
1511 struct ctl_table_header * register_sysctl_table(ctl_table * table,
1517 void unregister_sysctl_table(struct ctl_table_header * table)
1521 #endif /* CONFIG_SYSCTL */
1527 #ifdef CONFIG_PROC_SYSCTL
1529 /* Scan the sysctl entries in table and add them all into /proc */
1530 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1532 struct proc_dir_entry *de;
1536 for (; table->ctl_name || table->procname; table++) {
1537 /* Can't do anything without a proc name. */
1538 if (!table->procname)
1540 /* Maybe we can't do anything with it... */
1541 if (!table->proc_handler && !table->child) {
1542 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1547 len = strlen(table->procname);
1551 if (table->proc_handler)
1555 for (de = root->subdir; de; de = de->next) {
1556 if (proc_match(len, table->procname, de))
1559 /* If the subdir exists already, de is non-NULL */
1563 de = create_proc_entry(table->procname, mode, root);
1567 de->data = (void *) table;
1568 if (table->proc_handler)
1569 de->proc_fops = &proc_sys_file_operations;
1572 if (de->mode & S_IFDIR)
1573 register_proc_table(table->child, de, set);
1578 * Unregister a /proc sysctl table and any subdirectories.
1580 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1582 struct proc_dir_entry *de;
1583 for (; table->ctl_name || table->procname; table++) {
1584 if (!(de = table->de))
1586 if (de->mode & S_IFDIR) {
1587 if (!table->child) {
1588 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1591 unregister_proc_table(table->child, de);
1593 /* Don't unregister directories which still have entries.. */
1599 * In any case, mark the entry as goner; we'll keep it
1600 * around if it's busy, but we'll know to do nothing with
1601 * its fields. We are under sysctl_lock here.
1605 /* Don't unregister proc entries that are still being used.. */
1606 if (atomic_read(&de->count))
1610 remove_proc_entry(table->procname, root);
1614 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1615 size_t count, loff_t *ppos)
1618 struct proc_dir_entry *de = PDE(file->f_path.dentry->d_inode);
1619 struct ctl_table *table;
1621 ssize_t error = -ENOTDIR;
1623 spin_lock(&sysctl_lock);
1624 if (de && de->data && use_table(de->set)) {
1626 * at that point we know that sysctl was not unregistered
1627 * and won't be until we finish
1629 spin_unlock(&sysctl_lock);
1630 table = (struct ctl_table *) de->data;
1631 if (!table || !table->proc_handler)
1634 op = (write ? 002 : 004);
1635 if (ctl_perm(table, op))
1638 /* careful: calling conventions are nasty here */
1640 error = (*table->proc_handler)(table, write, file,
1645 spin_lock(&sysctl_lock);
1646 unuse_table(de->set);
1648 spin_unlock(&sysctl_lock);
1652 static int proc_opensys(struct inode *inode, struct file *file)
1654 if (file->f_mode & FMODE_WRITE) {
1656 * sysctl entries that are not writable,
1657 * are _NOT_ writable, capabilities or not.
1659 if (!(inode->i_mode & S_IWUSR))
1666 static ssize_t proc_readsys(struct file * file, char __user * buf,
1667 size_t count, loff_t *ppos)
1669 return do_rw_proc(0, file, buf, count, ppos);
1672 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1673 size_t count, loff_t *ppos)
1675 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1678 static int _proc_do_string(void* data, int maxlen, int write,
1679 struct file *filp, void __user *buffer,
1680 size_t *lenp, loff_t *ppos)
1686 if (!data || !maxlen || !*lenp ||
1687 (*ppos && !write)) {
1695 while (len < *lenp) {
1696 if (get_user(c, p++))
1698 if (c == 0 || c == '\n')
1704 if(copy_from_user(data, buffer, len))
1706 ((char *) data)[len] = 0;
1715 if(copy_to_user(buffer, data, len))
1718 if(put_user('\n', ((char __user *) buffer) + len))
1729 * proc_dostring - read a string sysctl
1730 * @table: the sysctl table
1731 * @write: %TRUE if this is a write to the sysctl file
1732 * @filp: the file structure
1733 * @buffer: the user buffer
1734 * @lenp: the size of the user buffer
1735 * @ppos: file position
1737 * Reads/writes a string from/to the user buffer. If the kernel
1738 * buffer provided is not large enough to hold the string, the
1739 * string is truncated. The copied string is %NULL-terminated.
1740 * If the string is being read by the user process, it is copied
1741 * and a newline '\n' is added. It is truncated if the buffer is
1744 * Returns 0 on success.
1746 int proc_dostring(ctl_table *table, int write, struct file *filp,
1747 void __user *buffer, size_t *lenp, loff_t *ppos)
1749 return _proc_do_string(table->data, table->maxlen, write, filp,
1750 buffer, lenp, ppos);
1754 * Special case of dostring for the UTS structure. This has locks
1755 * to observe. Should this be in kernel/sys.c ????
1758 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
1759 void __user *buffer, size_t *lenp, loff_t *ppos)
1763 which = get_uts(table, write);
1764 r = _proc_do_string(which, table->maxlen,write,filp,buffer,lenp, ppos);
1765 put_uts(table, write, which);
1769 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1771 int write, void *data)
1774 *valp = *negp ? -*lvalp : *lvalp;
1779 *lvalp = (unsigned long)-val;
1782 *lvalp = (unsigned long)val;
1788 static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1789 int write, struct file *filp, void __user *buffer,
1790 size_t *lenp, loff_t *ppos,
1791 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1792 int write, void *data),
1795 #define TMPBUFLEN 21
1796 int *i, vleft, first=1, neg, val;
1800 char buf[TMPBUFLEN], *p;
1801 char __user *s = buffer;
1803 if (!tbl_data || !table->maxlen || !*lenp ||
1804 (*ppos && !write)) {
1809 i = (int *) tbl_data;
1810 vleft = table->maxlen / sizeof(*i);
1814 conv = do_proc_dointvec_conv;
1816 for (; left && vleft--; i++, first=0) {
1831 if (len > sizeof(buf) - 1)
1832 len = sizeof(buf) - 1;
1833 if (copy_from_user(buf, s, len))
1837 if (*p == '-' && left > 1) {
1841 if (*p < '0' || *p > '9')
1844 lval = simple_strtoul(p, &p, 0);
1847 if ((len < left) && *p && !isspace(*p))
1854 if (conv(&neg, &lval, i, 1, data))
1861 if (conv(&neg, &lval, i, 0, data))
1864 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1868 if(copy_to_user(s, buf, len))
1875 if (!write && !first && left) {
1876 if(put_user('\n', s))
1883 if (get_user(c, s++))
1898 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1899 void __user *buffer, size_t *lenp, loff_t *ppos,
1900 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1901 int write, void *data),
1904 return __do_proc_dointvec(table->data, table, write, filp,
1905 buffer, lenp, ppos, conv, data);
1909 * proc_dointvec - read a vector of integers
1910 * @table: the sysctl table
1911 * @write: %TRUE if this is a write to the sysctl file
1912 * @filp: the file structure
1913 * @buffer: the user buffer
1914 * @lenp: the size of the user buffer
1915 * @ppos: file position
1917 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1918 * values from/to the user buffer, treated as an ASCII string.
1920 * Returns 0 on success.
1922 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1923 void __user *buffer, size_t *lenp, loff_t *ppos)
1925 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1932 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1934 int write, void *data)
1936 int op = *(int *)data;
1938 int val = *negp ? -*lvalp : *lvalp;
1940 case OP_SET: *valp = val; break;
1941 case OP_AND: *valp &= val; break;
1947 *lvalp = (unsigned long)-val;
1950 *lvalp = (unsigned long)val;
1957 * init may raise the set.
1960 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1961 void __user *buffer, size_t *lenp, loff_t *ppos)
1965 if (!capable(CAP_SYS_MODULE)) {
1969 op = is_init(current) ? OP_SET : OP_AND;
1970 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1971 do_proc_dointvec_bset_conv,&op);
1974 struct do_proc_dointvec_minmax_conv_param {
1979 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1981 int write, void *data)
1983 struct do_proc_dointvec_minmax_conv_param *param = data;
1985 int val = *negp ? -*lvalp : *lvalp;
1986 if ((param->min && *param->min > val) ||
1987 (param->max && *param->max < val))
1994 *lvalp = (unsigned long)-val;
1997 *lvalp = (unsigned long)val;
2004 * proc_dointvec_minmax - read a vector of integers with min/max values
2005 * @table: the sysctl table
2006 * @write: %TRUE if this is a write to the sysctl file
2007 * @filp: the file structure
2008 * @buffer: the user buffer
2009 * @lenp: the size of the user buffer
2010 * @ppos: file position
2012 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2013 * values from/to the user buffer, treated as an ASCII string.
2015 * This routine will ensure the values are within the range specified by
2016 * table->extra1 (min) and table->extra2 (max).
2018 * Returns 0 on success.
2020 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2021 void __user *buffer, size_t *lenp, loff_t *ppos)
2023 struct do_proc_dointvec_minmax_conv_param param = {
2024 .min = (int *) table->extra1,
2025 .max = (int *) table->extra2,
2027 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2028 do_proc_dointvec_minmax_conv, ¶m);
2031 static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
2033 void __user *buffer,
2034 size_t *lenp, loff_t *ppos,
2035 unsigned long convmul,
2036 unsigned long convdiv)
2038 #define TMPBUFLEN 21
2039 unsigned long *i, *min, *max, val;
2040 int vleft, first=1, neg;
2042 char buf[TMPBUFLEN], *p;
2043 char __user *s = buffer;
2045 if (!data || !table->maxlen || !*lenp ||
2046 (*ppos && !write)) {
2051 i = (unsigned long *) data;
2052 min = (unsigned long *) table->extra1;
2053 max = (unsigned long *) table->extra2;
2054 vleft = table->maxlen / sizeof(unsigned long);
2057 for (; left && vleft--; i++, min++, max++, first=0) {
2072 if (len > TMPBUFLEN-1)
2074 if (copy_from_user(buf, s, len))
2078 if (*p == '-' && left > 1) {
2082 if (*p < '0' || *p > '9')
2084 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2086 if ((len < left) && *p && !isspace(*p))
2095 if ((min && val < *min) || (max && val > *max))
2102 sprintf(p, "%lu", convdiv * (*i) / convmul);
2106 if(copy_to_user(s, buf, len))
2113 if (!write && !first && left) {
2114 if(put_user('\n', s))
2121 if (get_user(c, s++))
2136 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2138 void __user *buffer,
2139 size_t *lenp, loff_t *ppos,
2140 unsigned long convmul,
2141 unsigned long convdiv)
2143 return __do_proc_doulongvec_minmax(table->data, table, write,
2144 filp, buffer, lenp, ppos, convmul, convdiv);
2148 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2149 * @table: the sysctl table
2150 * @write: %TRUE if this is a write to the sysctl file
2151 * @filp: the file structure
2152 * @buffer: the user buffer
2153 * @lenp: the size of the user buffer
2154 * @ppos: file position
2156 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2157 * values from/to the user buffer, treated as an ASCII string.
2159 * This routine will ensure the values are within the range specified by
2160 * table->extra1 (min) and table->extra2 (max).
2162 * Returns 0 on success.
2164 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2165 void __user *buffer, size_t *lenp, loff_t *ppos)
2167 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2171 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2172 * @table: the sysctl table
2173 * @write: %TRUE if this is a write to the sysctl file
2174 * @filp: the file structure
2175 * @buffer: the user buffer
2176 * @lenp: the size of the user buffer
2177 * @ppos: file position
2179 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2180 * values from/to the user buffer, treated as an ASCII string. The values
2181 * are treated as milliseconds, and converted to jiffies when they are stored.
2183 * This routine will ensure the values are within the range specified by
2184 * table->extra1 (min) and table->extra2 (max).
2186 * Returns 0 on success.
2188 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2190 void __user *buffer,
2191 size_t *lenp, loff_t *ppos)
2193 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2194 lenp, ppos, HZ, 1000l);
2198 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2200 int write, void *data)
2203 if (*lvalp > LONG_MAX / HZ)
2205 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2211 lval = (unsigned long)-val;
2214 lval = (unsigned long)val;
2221 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2223 int write, void *data)
2226 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2228 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2234 lval = (unsigned long)-val;
2237 lval = (unsigned long)val;
2239 *lvalp = jiffies_to_clock_t(lval);
2244 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2246 int write, void *data)
2249 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2255 lval = (unsigned long)-val;
2258 lval = (unsigned long)val;
2260 *lvalp = jiffies_to_msecs(lval);
2266 * proc_dointvec_jiffies - read a vector of integers as seconds
2267 * @table: the sysctl table
2268 * @write: %TRUE if this is a write to the sysctl file
2269 * @filp: the file structure
2270 * @buffer: the user buffer
2271 * @lenp: the size of the user buffer
2272 * @ppos: file position
2274 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2275 * values from/to the user buffer, treated as an ASCII string.
2276 * The values read are assumed to be in seconds, and are converted into
2279 * Returns 0 on success.
2281 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2282 void __user *buffer, size_t *lenp, loff_t *ppos)
2284 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2285 do_proc_dointvec_jiffies_conv,NULL);
2289 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2290 * @table: the sysctl table
2291 * @write: %TRUE if this is a write to the sysctl file
2292 * @filp: the file structure
2293 * @buffer: the user buffer
2294 * @lenp: the size of the user buffer
2295 * @ppos: pointer to the file position
2297 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2298 * values from/to the user buffer, treated as an ASCII string.
2299 * The values read are assumed to be in 1/USER_HZ seconds, and
2300 * are converted into jiffies.
2302 * Returns 0 on success.
2304 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2305 void __user *buffer, size_t *lenp, loff_t *ppos)
2307 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2308 do_proc_dointvec_userhz_jiffies_conv,NULL);
2312 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2313 * @table: the sysctl table
2314 * @write: %TRUE if this is a write to the sysctl file
2315 * @filp: the file structure
2316 * @buffer: the user buffer
2317 * @lenp: the size of the user buffer
2318 * @ppos: file position
2319 * @ppos: the current position in the file
2321 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2322 * values from/to the user buffer, treated as an ASCII string.
2323 * The values read are assumed to be in 1/1000 seconds, and
2324 * are converted into jiffies.
2326 * Returns 0 on success.
2328 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2329 void __user *buffer, size_t *lenp, loff_t *ppos)
2331 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2332 do_proc_dointvec_ms_jiffies_conv, NULL);
2335 #ifdef CONFIG_SYSVIPC
2336 static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
2337 void __user *buffer, size_t *lenp, loff_t *ppos)
2340 which = get_ipc(table, write);
2341 return __do_proc_dointvec(which, table, write, filp, buffer,
2342 lenp, ppos, NULL, NULL);
2345 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
2346 struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
2349 which = get_ipc(table, write);
2350 return __do_proc_doulongvec_minmax(which, table, write, filp, buffer,
2351 lenp, ppos, 1l, 1l);
2356 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2357 void __user *buffer, size_t *lenp, loff_t *ppos)
2359 struct pid *new_pid;
2363 tmp = pid_nr(cad_pid);
2365 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2366 lenp, ppos, NULL, NULL);
2370 new_pid = find_get_pid(tmp);
2374 put_pid(xchg(&cad_pid, new_pid));
2378 #else /* CONFIG_PROC_FS */
2380 int proc_dostring(ctl_table *table, int write, struct file *filp,
2381 void __user *buffer, size_t *lenp, loff_t *ppos)
2386 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
2387 void __user *buffer, size_t *lenp, loff_t *ppos)
2392 #ifdef CONFIG_SYSVIPC
2393 static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2394 void __user *buffer, size_t *lenp, loff_t *ppos)
2398 static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
2399 void __user *buffer, size_t *lenp, loff_t *ppos)
2403 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
2404 struct file *filp, void __user *buffer,
2405 size_t *lenp, loff_t *ppos)
2411 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2412 void __user *buffer, size_t *lenp, loff_t *ppos)
2417 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2418 void __user *buffer, size_t *lenp, loff_t *ppos)
2423 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2424 void __user *buffer, size_t *lenp, loff_t *ppos)
2429 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2430 void __user *buffer, size_t *lenp, loff_t *ppos)
2435 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2436 void __user *buffer, size_t *lenp, loff_t *ppos)
2441 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2442 void __user *buffer, size_t *lenp, loff_t *ppos)
2447 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2448 void __user *buffer, size_t *lenp, loff_t *ppos)
2453 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2455 void __user *buffer,
2456 size_t *lenp, loff_t *ppos)
2462 #endif /* CONFIG_PROC_FS */
2465 #ifdef CONFIG_SYSCTL_SYSCALL
2467 * General sysctl support routines
2470 /* The generic string strategy routine: */
2471 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2472 void __user *oldval, size_t __user *oldlenp,
2473 void __user *newval, size_t newlen)
2475 if (!table->data || !table->maxlen)
2478 if (oldval && oldlenp) {
2480 if (get_user(bufsize, oldlenp))
2483 size_t len = strlen(table->data), copied;
2485 /* This shouldn't trigger for a well-formed sysctl */
2486 if (len > table->maxlen)
2487 len = table->maxlen;
2489 /* Copy up to a max of bufsize-1 bytes of the string */
2490 copied = (len >= bufsize) ? bufsize - 1 : len;
2492 if (copy_to_user(oldval, table->data, copied) ||
2493 put_user(0, (char __user *)(oldval + copied)))
2495 if (put_user(len, oldlenp))
2499 if (newval && newlen) {
2500 size_t len = newlen;
2501 if (len > table->maxlen)
2502 len = table->maxlen;
2503 if(copy_from_user(table->data, newval, len))
2505 if (len == table->maxlen)
2507 ((char *) table->data)[len] = 0;
2513 * This function makes sure that all of the integers in the vector
2514 * are between the minimum and maximum values given in the arrays
2515 * table->extra1 and table->extra2, respectively.
2517 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2518 void __user *oldval, size_t __user *oldlenp,
2519 void __user *newval, size_t newlen)
2522 if (newval && newlen) {
2523 int __user *vec = (int __user *) newval;
2524 int *min = (int *) table->extra1;
2525 int *max = (int *) table->extra2;
2529 if (newlen % sizeof(int) != 0)
2532 if (!table->extra1 && !table->extra2)
2535 if (newlen > table->maxlen)
2536 newlen = table->maxlen;
2537 length = newlen / sizeof(int);
2539 for (i = 0; i < length; i++) {
2541 if (get_user(value, vec + i))
2543 if (min && value < min[i])
2545 if (max && value > max[i])
2552 /* Strategy function to convert jiffies to seconds */
2553 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2554 void __user *oldval, size_t __user *oldlenp,
2555 void __user *newval, size_t newlen)
2560 if (get_user(olen, oldlenp))
2562 if (olen!=sizeof(int))
2565 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2566 (oldlenp && put_user(sizeof(int),oldlenp)))
2569 if (newval && newlen) {
2571 if (newlen != sizeof(int))
2573 if (get_user(new, (int __user *)newval))
2575 *(int *)(table->data) = new*HZ;
2580 /* Strategy function to convert jiffies to seconds */
2581 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2582 void __user *oldval, size_t __user *oldlenp,
2583 void __user *newval, size_t newlen)
2588 if (get_user(olen, oldlenp))
2590 if (olen!=sizeof(int))
2593 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2594 (oldlenp && put_user(sizeof(int),oldlenp)))
2597 if (newval && newlen) {
2599 if (newlen != sizeof(int))
2601 if (get_user(new, (int __user *)newval))
2603 *(int *)(table->data) = msecs_to_jiffies(new);
2609 /* The generic string strategy routine: */
2610 static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2611 void __user *oldval, size_t __user *oldlenp,
2612 void __user *newval, size_t newlen)
2614 struct ctl_table uts_table;
2616 write = newval && newlen;
2617 memcpy(&uts_table, table, sizeof(uts_table));
2618 uts_table.data = get_uts(table, write);
2619 r = sysctl_string(&uts_table, name, nlen,
2620 oldval, oldlenp, newval, newlen);
2621 put_uts(table, write, uts_table.data);
2625 #ifdef CONFIG_SYSVIPC
2626 /* The generic sysctl ipc data routine. */
2627 static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
2628 void __user *oldval, size_t __user *oldlenp,
2629 void __user *newval, size_t newlen)
2634 /* Get out of I don't have a variable */
2635 if (!table->data || !table->maxlen)
2638 data = get_ipc(table, 1);
2642 if (oldval && oldlenp) {
2643 if (get_user(len, oldlenp))
2646 if (len > table->maxlen)
2647 len = table->maxlen;
2648 if (copy_to_user(oldval, data, len))
2650 if (put_user(len, oldlenp))
2655 if (newval && newlen) {
2656 if (newlen > table->maxlen)
2657 newlen = table->maxlen;
2659 if (copy_from_user(data, newval, newlen))
2666 #else /* CONFIG_SYSCTL_SYSCALL */
2669 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2671 static int msg_count;
2672 struct __sysctl_args tmp;
2673 int name[CTL_MAXNAME];
2676 /* Read in the sysctl name for better debug message logging */
2677 if (copy_from_user(&tmp, args, sizeof(tmp)))
2679 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2681 for (i = 0; i < tmp.nlen; i++)
2682 if (get_user(name[i], tmp.name + i))
2685 /* Ignore accesses to kernel.version */
2686 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2689 if (msg_count < 5) {
2692 "warning: process `%s' used the removed sysctl "
2693 "system call with ", current->comm);
2694 for (i = 0; i < tmp.nlen; i++)
2695 printk("%d.", name[i]);
2702 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2703 void __user *oldval, size_t __user *oldlenp,
2704 void __user *newval, size_t newlen)
2709 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2710 void __user *oldval, size_t __user *oldlenp,
2711 void __user *newval, size_t newlen)
2716 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2717 void __user *oldval, size_t __user *oldlenp,
2718 void __user *newval, size_t newlen)
2723 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2724 void __user *oldval, size_t __user *oldlenp,
2725 void __user *newval, size_t newlen)
2730 static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2731 void __user *oldval, size_t __user *oldlenp,
2732 void __user *newval, size_t newlen)
2736 static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
2737 void __user *oldval, size_t __user *oldlenp,
2738 void __user *newval, size_t newlen)
2742 #endif /* CONFIG_SYSCTL_SYSCALL */
2745 * No sense putting this after each symbol definition, twice,
2746 * exception granted :-)
2748 EXPORT_SYMBOL(proc_dointvec);
2749 EXPORT_SYMBOL(proc_dointvec_jiffies);
2750 EXPORT_SYMBOL(proc_dointvec_minmax);
2751 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2752 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2753 EXPORT_SYMBOL(proc_dostring);
2754 EXPORT_SYMBOL(proc_doulongvec_minmax);
2755 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2756 EXPORT_SYMBOL(register_sysctl_table);
2757 EXPORT_SYMBOL(sysctl_intvec);
2758 EXPORT_SYMBOL(sysctl_jiffies);
2759 EXPORT_SYMBOL(sysctl_ms_jiffies);
2760 EXPORT_SYMBOL(sysctl_string);
2761 EXPORT_SYMBOL(unregister_sysctl_table);