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_do_ipc_string(ctl_table *table, int write, struct file *filp,
96 void __user *buffer, size_t *lenp, loff_t *ppos);
100 extern char reboot_command [];
101 extern int stop_a_enabled;
102 extern int scons_pwroff;
106 extern int pwrsw_enabled;
107 extern int unaligned_enabled;
111 #ifdef CONFIG_MATHEMU
112 extern int sysctl_ieee_emulation_warnings;
114 extern int sysctl_userprocess_debug;
115 extern int spin_retry;
118 extern int sysctl_hz_timer;
120 #ifdef CONFIG_BSD_PROCESS_ACCT
121 extern int acct_parm[];
125 extern int no_unaligned_warning;
128 #ifdef CONFIG_RT_MUTEXES
129 extern int max_lock_depth;
132 #ifdef CONFIG_SYSCTL_SYSCALL
133 static int parse_table(int __user *, int, void __user *, size_t __user *,
134 void __user *, size_t, ctl_table *, void **);
137 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
138 void __user *buffer, size_t *lenp, loff_t *ppos);
140 static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
141 void __user *oldval, size_t __user *oldlenp,
142 void __user *newval, size_t newlen, void **context);
144 #ifdef CONFIG_PROC_SYSCTL
145 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
146 void __user *buffer, size_t *lenp, loff_t *ppos);
149 static ctl_table root_table[];
150 static struct ctl_table_header root_table_header =
151 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
153 static ctl_table kern_table[];
154 static ctl_table vm_table[];
155 static ctl_table fs_table[];
156 static ctl_table debug_table[];
157 static ctl_table dev_table[];
158 extern ctl_table random_table[];
159 #ifdef CONFIG_UNIX98_PTYS
160 extern ctl_table pty_table[];
162 #ifdef CONFIG_INOTIFY_USER
163 extern ctl_table inotify_table[];
166 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
167 int sysctl_legacy_va_layout;
170 static void *get_uts(ctl_table *table, int write)
172 char *which = table->data;
174 struct uts_namespace *uts_ns = current->nsproxy->uts_ns;
175 which = (which - (char *)&init_uts_ns) + (char *)uts_ns;
180 down_write(&uts_sem);
184 static void put_uts(ctl_table *table, int write, void *which)
192 /* /proc declarations: */
194 #ifdef CONFIG_PROC_SYSCTL
196 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
197 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
198 static int proc_opensys(struct inode *, struct file *);
200 const struct file_operations proc_sys_file_operations = {
201 .open = proc_opensys,
202 .read = proc_readsys,
203 .write = proc_writesys,
206 extern struct proc_dir_entry *proc_sys_root;
208 static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
209 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
212 /* The default sysctl tables: */
214 static ctl_table root_table[] = {
216 .ctl_name = CTL_KERN,
217 .procname = "kernel",
242 .ctl_name = CTL_DEBUG,
245 .child = debug_table,
257 static ctl_table kern_table[] = {
259 .ctl_name = KERN_OSTYPE,
260 .procname = "ostype",
261 .data = init_uts_ns.name.sysname,
262 .maxlen = sizeof(init_uts_ns.name.sysname),
264 .proc_handler = &proc_do_uts_string,
265 .strategy = &sysctl_uts_string,
268 .ctl_name = KERN_OSRELEASE,
269 .procname = "osrelease",
270 .data = init_uts_ns.name.release,
271 .maxlen = sizeof(init_uts_ns.name.release),
273 .proc_handler = &proc_do_uts_string,
274 .strategy = &sysctl_uts_string,
277 .ctl_name = KERN_VERSION,
278 .procname = "version",
279 .data = init_uts_ns.name.version,
280 .maxlen = sizeof(init_uts_ns.name.version),
282 .proc_handler = &proc_do_uts_string,
283 .strategy = &sysctl_uts_string,
286 .ctl_name = KERN_NODENAME,
287 .procname = "hostname",
288 .data = init_uts_ns.name.nodename,
289 .maxlen = sizeof(init_uts_ns.name.nodename),
291 .proc_handler = &proc_do_uts_string,
292 .strategy = &sysctl_uts_string,
295 .ctl_name = KERN_DOMAINNAME,
296 .procname = "domainname",
297 .data = init_uts_ns.name.domainname,
298 .maxlen = sizeof(init_uts_ns.name.domainname),
300 .proc_handler = &proc_do_uts_string,
301 .strategy = &sysctl_uts_string,
304 .ctl_name = KERN_PANIC,
306 .data = &panic_timeout,
307 .maxlen = sizeof(int),
309 .proc_handler = &proc_dointvec,
312 .ctl_name = KERN_CORE_USES_PID,
313 .procname = "core_uses_pid",
314 .data = &core_uses_pid,
315 .maxlen = sizeof(int),
317 .proc_handler = &proc_dointvec,
320 .ctl_name = KERN_CORE_PATTERN,
321 .procname = "core_pattern",
322 .data = core_pattern,
325 .proc_handler = &proc_dostring,
326 .strategy = &sysctl_string,
329 .ctl_name = KERN_TAINTED,
330 .procname = "tainted",
332 .maxlen = sizeof(int),
334 .proc_handler = &proc_dointvec,
337 .ctl_name = KERN_CAP_BSET,
338 .procname = "cap-bound",
340 .maxlen = sizeof(kernel_cap_t),
342 .proc_handler = &proc_dointvec_bset,
344 #ifdef CONFIG_BLK_DEV_INITRD
346 .ctl_name = KERN_REALROOTDEV,
347 .procname = "real-root-dev",
348 .data = &real_root_dev,
349 .maxlen = sizeof(int),
351 .proc_handler = &proc_dointvec,
356 .ctl_name = KERN_SPARC_REBOOT,
357 .procname = "reboot-cmd",
358 .data = reboot_command,
361 .proc_handler = &proc_dostring,
362 .strategy = &sysctl_string,
365 .ctl_name = KERN_SPARC_STOP_A,
366 .procname = "stop-a",
367 .data = &stop_a_enabled,
368 .maxlen = sizeof (int),
370 .proc_handler = &proc_dointvec,
373 .ctl_name = KERN_SPARC_SCONS_PWROFF,
374 .procname = "scons-poweroff",
375 .data = &scons_pwroff,
376 .maxlen = sizeof (int),
378 .proc_handler = &proc_dointvec,
383 .ctl_name = KERN_HPPA_PWRSW,
384 .procname = "soft-power",
385 .data = &pwrsw_enabled,
386 .maxlen = sizeof (int),
388 .proc_handler = &proc_dointvec,
391 .ctl_name = KERN_HPPA_UNALIGNED,
392 .procname = "unaligned-trap",
393 .data = &unaligned_enabled,
394 .maxlen = sizeof (int),
396 .proc_handler = &proc_dointvec,
400 .ctl_name = KERN_CTLALTDEL,
401 .procname = "ctrl-alt-del",
403 .maxlen = sizeof(int),
405 .proc_handler = &proc_dointvec,
408 .ctl_name = KERN_PRINTK,
409 .procname = "printk",
410 .data = &console_loglevel,
411 .maxlen = 4*sizeof(int),
413 .proc_handler = &proc_dointvec,
417 .ctl_name = KERN_MODPROBE,
418 .procname = "modprobe",
419 .data = &modprobe_path,
420 .maxlen = KMOD_PATH_LEN,
422 .proc_handler = &proc_dostring,
423 .strategy = &sysctl_string,
426 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
428 .ctl_name = KERN_HOTPLUG,
429 .procname = "hotplug",
430 .data = &uevent_helper,
431 .maxlen = UEVENT_HELPER_PATH_LEN,
433 .proc_handler = &proc_dostring,
434 .strategy = &sysctl_string,
437 #ifdef CONFIG_CHR_DEV_SG
439 .ctl_name = KERN_SG_BIG_BUFF,
440 .procname = "sg-big-buff",
441 .data = &sg_big_buff,
442 .maxlen = sizeof (int),
444 .proc_handler = &proc_dointvec,
447 #ifdef CONFIG_BSD_PROCESS_ACCT
449 .ctl_name = KERN_ACCT,
452 .maxlen = 3*sizeof(int),
454 .proc_handler = &proc_dointvec,
457 #ifdef CONFIG_SYSVIPC
459 .ctl_name = KERN_SHMMAX,
460 .procname = "shmmax",
462 .maxlen = sizeof (size_t),
464 .proc_handler = &proc_do_ipc_string,
467 .ctl_name = KERN_SHMALL,
468 .procname = "shmall",
470 .maxlen = sizeof (size_t),
472 .proc_handler = &proc_do_ipc_string,
475 .ctl_name = KERN_SHMMNI,
476 .procname = "shmmni",
478 .maxlen = sizeof (int),
480 .proc_handler = &proc_do_ipc_string,
483 .ctl_name = KERN_MSGMAX,
484 .procname = "msgmax",
486 .maxlen = sizeof (int),
488 .proc_handler = &proc_do_ipc_string,
491 .ctl_name = KERN_MSGMNI,
492 .procname = "msgmni",
494 .maxlen = sizeof (int),
496 .proc_handler = &proc_do_ipc_string,
499 .ctl_name = KERN_MSGMNB,
500 .procname = "msgmnb",
502 .maxlen = sizeof (int),
504 .proc_handler = &proc_do_ipc_string,
507 .ctl_name = KERN_SEM,
510 .maxlen = 4*sizeof (int),
512 .proc_handler = &proc_do_ipc_string,
515 #ifdef CONFIG_MAGIC_SYSRQ
517 .ctl_name = KERN_SYSRQ,
519 .data = &sysrq_enabled,
520 .maxlen = sizeof (int),
522 .proc_handler = &proc_dointvec,
525 #ifdef CONFIG_PROC_SYSCTL
527 .ctl_name = KERN_CADPID,
528 .procname = "cad_pid",
530 .maxlen = sizeof (int),
532 .proc_handler = &proc_do_cad_pid,
536 .ctl_name = KERN_MAX_THREADS,
537 .procname = "threads-max",
538 .data = &max_threads,
539 .maxlen = sizeof(int),
541 .proc_handler = &proc_dointvec,
544 .ctl_name = KERN_RANDOM,
545 .procname = "random",
547 .child = random_table,
549 #ifdef CONFIG_UNIX98_PTYS
551 .ctl_name = KERN_PTY,
558 .ctl_name = KERN_OVERFLOWUID,
559 .procname = "overflowuid",
560 .data = &overflowuid,
561 .maxlen = sizeof(int),
563 .proc_handler = &proc_dointvec_minmax,
564 .strategy = &sysctl_intvec,
565 .extra1 = &minolduid,
566 .extra2 = &maxolduid,
569 .ctl_name = KERN_OVERFLOWGID,
570 .procname = "overflowgid",
571 .data = &overflowgid,
572 .maxlen = sizeof(int),
574 .proc_handler = &proc_dointvec_minmax,
575 .strategy = &sysctl_intvec,
576 .extra1 = &minolduid,
577 .extra2 = &maxolduid,
580 #ifdef CONFIG_MATHEMU
582 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
583 .procname = "ieee_emulation_warnings",
584 .data = &sysctl_ieee_emulation_warnings,
585 .maxlen = sizeof(int),
587 .proc_handler = &proc_dointvec,
590 #ifdef CONFIG_NO_IDLE_HZ
592 .ctl_name = KERN_HZ_TIMER,
593 .procname = "hz_timer",
594 .data = &sysctl_hz_timer,
595 .maxlen = sizeof(int),
597 .proc_handler = &proc_dointvec,
601 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
602 .procname = "userprocess_debug",
603 .data = &sysctl_userprocess_debug,
604 .maxlen = sizeof(int),
606 .proc_handler = &proc_dointvec,
610 .ctl_name = KERN_PIDMAX,
611 .procname = "pid_max",
613 .maxlen = sizeof (int),
615 .proc_handler = &proc_dointvec_minmax,
616 .strategy = sysctl_intvec,
617 .extra1 = &pid_max_min,
618 .extra2 = &pid_max_max,
621 .ctl_name = KERN_PANIC_ON_OOPS,
622 .procname = "panic_on_oops",
623 .data = &panic_on_oops,
624 .maxlen = sizeof(int),
626 .proc_handler = &proc_dointvec,
629 .ctl_name = KERN_PRINTK_RATELIMIT,
630 .procname = "printk_ratelimit",
631 .data = &printk_ratelimit_jiffies,
632 .maxlen = sizeof(int),
634 .proc_handler = &proc_dointvec_jiffies,
635 .strategy = &sysctl_jiffies,
638 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
639 .procname = "printk_ratelimit_burst",
640 .data = &printk_ratelimit_burst,
641 .maxlen = sizeof(int),
643 .proc_handler = &proc_dointvec,
646 .ctl_name = KERN_NGROUPS_MAX,
647 .procname = "ngroups_max",
648 .data = &ngroups_max,
649 .maxlen = sizeof (int),
651 .proc_handler = &proc_dointvec,
653 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
655 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
656 .procname = "unknown_nmi_panic",
657 .data = &unknown_nmi_panic,
658 .maxlen = sizeof (int),
660 .proc_handler = &proc_dointvec,
663 .ctl_name = KERN_NMI_WATCHDOG,
664 .procname = "nmi_watchdog",
665 .data = &nmi_watchdog_enabled,
666 .maxlen = sizeof (int),
668 .proc_handler = &proc_nmi_enabled,
671 #if defined(CONFIG_X86)
673 .ctl_name = KERN_PANIC_ON_NMI,
674 .procname = "panic_on_unrecovered_nmi",
675 .data = &panic_on_unrecovered_nmi,
676 .maxlen = sizeof(int),
678 .proc_handler = &proc_dointvec,
681 .ctl_name = KERN_BOOTLOADER_TYPE,
682 .procname = "bootloader_type",
683 .data = &bootloader_type,
684 .maxlen = sizeof (int),
686 .proc_handler = &proc_dointvec,
689 .ctl_name = CTL_UNNUMBERED,
690 .procname = "kstack_depth_to_print",
691 .data = &kstack_depth_to_print,
692 .maxlen = sizeof(int),
694 .proc_handler = &proc_dointvec,
697 #if defined(CONFIG_MMU)
699 .ctl_name = KERN_RANDOMIZE,
700 .procname = "randomize_va_space",
701 .data = &randomize_va_space,
702 .maxlen = sizeof(int),
704 .proc_handler = &proc_dointvec,
707 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
709 .ctl_name = KERN_SPIN_RETRY,
710 .procname = "spin_retry",
712 .maxlen = sizeof (int),
714 .proc_handler = &proc_dointvec,
717 #ifdef CONFIG_ACPI_SLEEP
719 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
720 .procname = "acpi_video_flags",
721 .data = &acpi_video_flags,
722 .maxlen = sizeof (unsigned long),
724 .proc_handler = &proc_doulongvec_minmax,
729 .ctl_name = KERN_IA64_UNALIGNED,
730 .procname = "ignore-unaligned-usertrap",
731 .data = &no_unaligned_warning,
732 .maxlen = sizeof (int),
734 .proc_handler = &proc_dointvec,
739 .ctl_name = KERN_COMPAT_LOG,
740 .procname = "compat-log",
742 .maxlen = sizeof (int),
744 .proc_handler = &proc_dointvec,
747 #ifdef CONFIG_RT_MUTEXES
749 .ctl_name = KERN_MAX_LOCK_DEPTH,
750 .procname = "max_lock_depth",
751 .data = &max_lock_depth,
752 .maxlen = sizeof(int),
754 .proc_handler = &proc_dointvec,
761 /* Constants for minimum and maximum testing in vm_table.
762 We use these as one-element integer vectors. */
764 static int one_hundred = 100;
767 static ctl_table vm_table[] = {
769 .ctl_name = VM_OVERCOMMIT_MEMORY,
770 .procname = "overcommit_memory",
771 .data = &sysctl_overcommit_memory,
772 .maxlen = sizeof(sysctl_overcommit_memory),
774 .proc_handler = &proc_dointvec,
777 .ctl_name = VM_PANIC_ON_OOM,
778 .procname = "panic_on_oom",
779 .data = &sysctl_panic_on_oom,
780 .maxlen = sizeof(sysctl_panic_on_oom),
782 .proc_handler = &proc_dointvec,
785 .ctl_name = VM_OVERCOMMIT_RATIO,
786 .procname = "overcommit_ratio",
787 .data = &sysctl_overcommit_ratio,
788 .maxlen = sizeof(sysctl_overcommit_ratio),
790 .proc_handler = &proc_dointvec,
793 .ctl_name = VM_PAGE_CLUSTER,
794 .procname = "page-cluster",
795 .data = &page_cluster,
796 .maxlen = sizeof(int),
798 .proc_handler = &proc_dointvec,
801 .ctl_name = VM_DIRTY_BACKGROUND,
802 .procname = "dirty_background_ratio",
803 .data = &dirty_background_ratio,
804 .maxlen = sizeof(dirty_background_ratio),
806 .proc_handler = &proc_dointvec_minmax,
807 .strategy = &sysctl_intvec,
809 .extra2 = &one_hundred,
812 .ctl_name = VM_DIRTY_RATIO,
813 .procname = "dirty_ratio",
814 .data = &vm_dirty_ratio,
815 .maxlen = sizeof(vm_dirty_ratio),
817 .proc_handler = &proc_dointvec_minmax,
818 .strategy = &sysctl_intvec,
820 .extra2 = &one_hundred,
823 .ctl_name = VM_DIRTY_WB_CS,
824 .procname = "dirty_writeback_centisecs",
825 .data = &dirty_writeback_interval,
826 .maxlen = sizeof(dirty_writeback_interval),
828 .proc_handler = &dirty_writeback_centisecs_handler,
831 .ctl_name = VM_DIRTY_EXPIRE_CS,
832 .procname = "dirty_expire_centisecs",
833 .data = &dirty_expire_interval,
834 .maxlen = sizeof(dirty_expire_interval),
836 .proc_handler = &proc_dointvec_userhz_jiffies,
839 .ctl_name = VM_NR_PDFLUSH_THREADS,
840 .procname = "nr_pdflush_threads",
841 .data = &nr_pdflush_threads,
842 .maxlen = sizeof nr_pdflush_threads,
843 .mode = 0444 /* read-only*/,
844 .proc_handler = &proc_dointvec,
847 .ctl_name = VM_SWAPPINESS,
848 .procname = "swappiness",
849 .data = &vm_swappiness,
850 .maxlen = sizeof(vm_swappiness),
852 .proc_handler = &proc_dointvec_minmax,
853 .strategy = &sysctl_intvec,
855 .extra2 = &one_hundred,
857 #ifdef CONFIG_HUGETLB_PAGE
859 .ctl_name = VM_HUGETLB_PAGES,
860 .procname = "nr_hugepages",
861 .data = &max_huge_pages,
862 .maxlen = sizeof(unsigned long),
864 .proc_handler = &hugetlb_sysctl_handler,
865 .extra1 = (void *)&hugetlb_zero,
866 .extra2 = (void *)&hugetlb_infinity,
869 .ctl_name = VM_HUGETLB_GROUP,
870 .procname = "hugetlb_shm_group",
871 .data = &sysctl_hugetlb_shm_group,
872 .maxlen = sizeof(gid_t),
874 .proc_handler = &proc_dointvec,
878 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
879 .procname = "lowmem_reserve_ratio",
880 .data = &sysctl_lowmem_reserve_ratio,
881 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
883 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
884 .strategy = &sysctl_intvec,
887 .ctl_name = VM_DROP_PAGECACHE,
888 .procname = "drop_caches",
889 .data = &sysctl_drop_caches,
890 .maxlen = sizeof(int),
892 .proc_handler = drop_caches_sysctl_handler,
893 .strategy = &sysctl_intvec,
896 .ctl_name = VM_MIN_FREE_KBYTES,
897 .procname = "min_free_kbytes",
898 .data = &min_free_kbytes,
899 .maxlen = sizeof(min_free_kbytes),
901 .proc_handler = &min_free_kbytes_sysctl_handler,
902 .strategy = &sysctl_intvec,
906 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
907 .procname = "percpu_pagelist_fraction",
908 .data = &percpu_pagelist_fraction,
909 .maxlen = sizeof(percpu_pagelist_fraction),
911 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
912 .strategy = &sysctl_intvec,
913 .extra1 = &min_percpu_pagelist_fract,
917 .ctl_name = VM_MAX_MAP_COUNT,
918 .procname = "max_map_count",
919 .data = &sysctl_max_map_count,
920 .maxlen = sizeof(sysctl_max_map_count),
922 .proc_handler = &proc_dointvec
926 .ctl_name = VM_LAPTOP_MODE,
927 .procname = "laptop_mode",
928 .data = &laptop_mode,
929 .maxlen = sizeof(laptop_mode),
931 .proc_handler = &proc_dointvec_jiffies,
932 .strategy = &sysctl_jiffies,
935 .ctl_name = VM_BLOCK_DUMP,
936 .procname = "block_dump",
938 .maxlen = sizeof(block_dump),
940 .proc_handler = &proc_dointvec,
941 .strategy = &sysctl_intvec,
945 .ctl_name = VM_VFS_CACHE_PRESSURE,
946 .procname = "vfs_cache_pressure",
947 .data = &sysctl_vfs_cache_pressure,
948 .maxlen = sizeof(sysctl_vfs_cache_pressure),
950 .proc_handler = &proc_dointvec,
951 .strategy = &sysctl_intvec,
954 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
956 .ctl_name = VM_LEGACY_VA_LAYOUT,
957 .procname = "legacy_va_layout",
958 .data = &sysctl_legacy_va_layout,
959 .maxlen = sizeof(sysctl_legacy_va_layout),
961 .proc_handler = &proc_dointvec,
962 .strategy = &sysctl_intvec,
968 .ctl_name = VM_ZONE_RECLAIM_MODE,
969 .procname = "zone_reclaim_mode",
970 .data = &zone_reclaim_mode,
971 .maxlen = sizeof(zone_reclaim_mode),
973 .proc_handler = &proc_dointvec,
974 .strategy = &sysctl_intvec,
978 .ctl_name = VM_MIN_UNMAPPED,
979 .procname = "min_unmapped_ratio",
980 .data = &sysctl_min_unmapped_ratio,
981 .maxlen = sizeof(sysctl_min_unmapped_ratio),
983 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
984 .strategy = &sysctl_intvec,
986 .extra2 = &one_hundred,
989 .ctl_name = VM_MIN_SLAB,
990 .procname = "min_slab_ratio",
991 .data = &sysctl_min_slab_ratio,
992 .maxlen = sizeof(sysctl_min_slab_ratio),
994 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
995 .strategy = &sysctl_intvec,
997 .extra2 = &one_hundred,
1000 #ifdef CONFIG_X86_32
1002 .ctl_name = VM_VDSO_ENABLED,
1003 .procname = "vdso_enabled",
1004 .data = &vdso_enabled,
1005 .maxlen = sizeof(vdso_enabled),
1007 .proc_handler = &proc_dointvec,
1008 .strategy = &sysctl_intvec,
1015 static ctl_table fs_table[] = {
1017 .ctl_name = FS_NRINODE,
1018 .procname = "inode-nr",
1019 .data = &inodes_stat,
1020 .maxlen = 2*sizeof(int),
1022 .proc_handler = &proc_dointvec,
1025 .ctl_name = FS_STATINODE,
1026 .procname = "inode-state",
1027 .data = &inodes_stat,
1028 .maxlen = 7*sizeof(int),
1030 .proc_handler = &proc_dointvec,
1033 .ctl_name = FS_NRFILE,
1034 .procname = "file-nr",
1035 .data = &files_stat,
1036 .maxlen = 3*sizeof(int),
1038 .proc_handler = &proc_nr_files,
1041 .ctl_name = FS_MAXFILE,
1042 .procname = "file-max",
1043 .data = &files_stat.max_files,
1044 .maxlen = sizeof(int),
1046 .proc_handler = &proc_dointvec,
1049 .ctl_name = FS_DENTRY,
1050 .procname = "dentry-state",
1051 .data = &dentry_stat,
1052 .maxlen = 6*sizeof(int),
1054 .proc_handler = &proc_dointvec,
1057 .ctl_name = FS_OVERFLOWUID,
1058 .procname = "overflowuid",
1059 .data = &fs_overflowuid,
1060 .maxlen = sizeof(int),
1062 .proc_handler = &proc_dointvec_minmax,
1063 .strategy = &sysctl_intvec,
1064 .extra1 = &minolduid,
1065 .extra2 = &maxolduid,
1068 .ctl_name = FS_OVERFLOWGID,
1069 .procname = "overflowgid",
1070 .data = &fs_overflowgid,
1071 .maxlen = sizeof(int),
1073 .proc_handler = &proc_dointvec_minmax,
1074 .strategy = &sysctl_intvec,
1075 .extra1 = &minolduid,
1076 .extra2 = &maxolduid,
1079 .ctl_name = FS_LEASES,
1080 .procname = "leases-enable",
1081 .data = &leases_enable,
1082 .maxlen = sizeof(int),
1084 .proc_handler = &proc_dointvec,
1086 #ifdef CONFIG_DNOTIFY
1088 .ctl_name = FS_DIR_NOTIFY,
1089 .procname = "dir-notify-enable",
1090 .data = &dir_notify_enable,
1091 .maxlen = sizeof(int),
1093 .proc_handler = &proc_dointvec,
1098 .ctl_name = FS_LEASE_TIME,
1099 .procname = "lease-break-time",
1100 .data = &lease_break_time,
1101 .maxlen = sizeof(int),
1103 .proc_handler = &proc_dointvec,
1106 .ctl_name = FS_AIO_NR,
1107 .procname = "aio-nr",
1109 .maxlen = sizeof(aio_nr),
1111 .proc_handler = &proc_doulongvec_minmax,
1114 .ctl_name = FS_AIO_MAX_NR,
1115 .procname = "aio-max-nr",
1116 .data = &aio_max_nr,
1117 .maxlen = sizeof(aio_max_nr),
1119 .proc_handler = &proc_doulongvec_minmax,
1121 #ifdef CONFIG_INOTIFY_USER
1123 .ctl_name = FS_INOTIFY,
1124 .procname = "inotify",
1126 .child = inotify_table,
1131 .ctl_name = KERN_SETUID_DUMPABLE,
1132 .procname = "suid_dumpable",
1133 .data = &suid_dumpable,
1134 .maxlen = sizeof(int),
1136 .proc_handler = &proc_dointvec,
1141 static ctl_table debug_table[] = {
1145 static ctl_table dev_table[] = {
1149 extern void init_irq_proc (void);
1151 static DEFINE_SPINLOCK(sysctl_lock);
1153 /* called under sysctl_lock */
1154 static int use_table(struct ctl_table_header *p)
1156 if (unlikely(p->unregistering))
1162 /* called under sysctl_lock */
1163 static void unuse_table(struct ctl_table_header *p)
1166 if (unlikely(p->unregistering))
1167 complete(p->unregistering);
1170 /* called under sysctl_lock, will reacquire if has to wait */
1171 static void start_unregistering(struct ctl_table_header *p)
1174 * if p->used is 0, nobody will ever touch that entry again;
1175 * we'll eliminate all paths to it before dropping sysctl_lock
1177 if (unlikely(p->used)) {
1178 struct completion wait;
1179 init_completion(&wait);
1180 p->unregistering = &wait;
1181 spin_unlock(&sysctl_lock);
1182 wait_for_completion(&wait);
1183 spin_lock(&sysctl_lock);
1186 * do not remove from the list until nobody holds it; walking the
1187 * list in do_sysctl() relies on that.
1189 list_del_init(&p->ctl_entry);
1192 void __init sysctl_init(void)
1194 #ifdef CONFIG_PROC_SYSCTL
1195 register_proc_table(root_table, proc_sys_root, &root_table_header);
1200 #ifdef CONFIG_SYSCTL_SYSCALL
1201 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1202 void __user *newval, size_t newlen)
1204 struct list_head *tmp;
1205 int error = -ENOTDIR;
1207 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1211 if (!oldlenp || get_user(old_len, oldlenp))
1214 spin_lock(&sysctl_lock);
1215 tmp = &root_table_header.ctl_entry;
1217 struct ctl_table_header *head =
1218 list_entry(tmp, struct ctl_table_header, ctl_entry);
1219 void *context = NULL;
1221 if (!use_table(head))
1224 spin_unlock(&sysctl_lock);
1226 error = parse_table(name, nlen, oldval, oldlenp,
1227 newval, newlen, head->ctl_table,
1231 spin_lock(&sysctl_lock);
1233 if (error != -ENOTDIR)
1235 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1236 spin_unlock(&sysctl_lock);
1240 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1242 struct __sysctl_args tmp;
1245 if (copy_from_user(&tmp, args, sizeof(tmp)))
1249 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1250 tmp.newval, tmp.newlen);
1254 #endif /* CONFIG_SYSCTL_SYSCALL */
1257 * ctl_perm does NOT grant the superuser all rights automatically, because
1258 * some sysctl variables are readonly even to root.
1261 static int test_perm(int mode, int op)
1265 else if (in_egroup_p(0))
1267 if ((mode & op & 0007) == op)
1272 static inline int ctl_perm(ctl_table *table, int op)
1275 error = security_sysctl(table, op);
1278 return test_perm(table->mode, op);
1281 #ifdef CONFIG_SYSCTL_SYSCALL
1282 static int parse_table(int __user *name, int nlen,
1283 void __user *oldval, size_t __user *oldlenp,
1284 void __user *newval, size_t newlen,
1285 ctl_table *table, void **context)
1291 if (get_user(n, name))
1293 for ( ; table->ctl_name || table->procname; table++) {
1294 if (!table->ctl_name)
1296 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1299 if (ctl_perm(table, 001))
1301 if (table->strategy) {
1302 error = table->strategy(
1305 newval, newlen, context);
1311 table = table->child;
1314 error = do_sysctl_strategy(table, name, nlen,
1316 newval, newlen, context);
1323 /* Perform the actual read/write of a sysctl table entry. */
1324 int do_sysctl_strategy (ctl_table *table,
1325 int __user *name, int nlen,
1326 void __user *oldval, size_t __user *oldlenp,
1327 void __user *newval, size_t newlen, void **context)
1336 if (ctl_perm(table, op))
1339 if (table->strategy) {
1340 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1341 newval, newlen, context);
1348 /* If there is no strategy routine, or if the strategy returns
1349 * zero, proceed with automatic r/w */
1350 if (table->data && table->maxlen) {
1351 if (oldval && oldlenp) {
1352 if (get_user(len, oldlenp))
1355 if (len > table->maxlen)
1356 len = table->maxlen;
1357 if(copy_to_user(oldval, table->data, len))
1359 if(put_user(len, oldlenp))
1363 if (newval && newlen) {
1365 if (len > table->maxlen)
1366 len = table->maxlen;
1367 if(copy_from_user(table->data, newval, len))
1373 #endif /* CONFIG_SYSCTL_SYSCALL */
1376 * register_sysctl_table - register a sysctl hierarchy
1377 * @table: the top-level table structure
1378 * @insert_at_head: whether the entry should be inserted in front or at the end
1380 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1381 * array. An entry with a ctl_name of 0 terminates the table.
1383 * The members of the &ctl_table structure are used as follows:
1385 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1386 * must be unique within that level of sysctl
1388 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1389 * enter a sysctl file
1391 * data - a pointer to data for use by proc_handler
1393 * maxlen - the maximum size in bytes of the data
1395 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1397 * child - a pointer to the child sysctl table if this entry is a directory, or
1400 * proc_handler - the text handler routine (described below)
1402 * strategy - the strategy routine (described below)
1404 * de - for internal use by the sysctl routines
1406 * extra1, extra2 - extra pointers usable by the proc handler routines
1408 * Leaf nodes in the sysctl tree will be represented by a single file
1409 * under /proc; non-leaf nodes will be represented by directories.
1411 * sysctl(2) can automatically manage read and write requests through
1412 * the sysctl table. The data and maxlen fields of the ctl_table
1413 * struct enable minimal validation of the values being written to be
1414 * performed, and the mode field allows minimal authentication.
1416 * More sophisticated management can be enabled by the provision of a
1417 * strategy routine with the table entry. This will be called before
1418 * any automatic read or write of the data is performed.
1420 * The strategy routine may return
1422 * < 0 - Error occurred (error is passed to user process)
1424 * 0 - OK - proceed with automatic read or write.
1426 * > 0 - OK - read or write has been done by the strategy routine, so
1427 * return immediately.
1429 * There must be a proc_handler routine for any terminal nodes
1430 * mirrored under /proc/sys (non-terminals are handled by a built-in
1431 * directory handler). Several default handlers are available to
1432 * cover common cases -
1434 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1435 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1436 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1438 * It is the handler's job to read the input buffer from user memory
1439 * and process it. The handler should return 0 on success.
1441 * This routine returns %NULL on a failure to register, and a pointer
1442 * to the table header on success.
1444 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1447 struct ctl_table_header *tmp;
1448 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1451 tmp->ctl_table = table;
1452 INIT_LIST_HEAD(&tmp->ctl_entry);
1454 tmp->unregistering = NULL;
1455 spin_lock(&sysctl_lock);
1457 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1459 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1460 spin_unlock(&sysctl_lock);
1461 #ifdef CONFIG_PROC_SYSCTL
1462 register_proc_table(table, proc_sys_root, tmp);
1468 * unregister_sysctl_table - unregister a sysctl table hierarchy
1469 * @header: the header returned from register_sysctl_table
1471 * Unregisters the sysctl table and all children. proc entries may not
1472 * actually be removed until they are no longer used by anyone.
1474 void unregister_sysctl_table(struct ctl_table_header * header)
1477 spin_lock(&sysctl_lock);
1478 start_unregistering(header);
1479 #ifdef CONFIG_PROC_SYSCTL
1480 unregister_proc_table(header->ctl_table, proc_sys_root);
1482 spin_unlock(&sysctl_lock);
1486 #else /* !CONFIG_SYSCTL */
1487 struct ctl_table_header * register_sysctl_table(ctl_table * table,
1493 void unregister_sysctl_table(struct ctl_table_header * table)
1497 #endif /* CONFIG_SYSCTL */
1503 #ifdef CONFIG_PROC_SYSCTL
1505 /* Scan the sysctl entries in table and add them all into /proc */
1506 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1508 struct proc_dir_entry *de;
1512 for (; table->ctl_name || table->procname; table++) {
1513 /* Can't do anything without a proc name. */
1514 if (!table->procname)
1516 /* Maybe we can't do anything with it... */
1517 if (!table->proc_handler && !table->child) {
1518 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1523 len = strlen(table->procname);
1527 if (table->proc_handler)
1531 for (de = root->subdir; de; de = de->next) {
1532 if (proc_match(len, table->procname, de))
1535 /* If the subdir exists already, de is non-NULL */
1539 de = create_proc_entry(table->procname, mode, root);
1543 de->data = (void *) table;
1544 if (table->proc_handler)
1545 de->proc_fops = &proc_sys_file_operations;
1548 if (de->mode & S_IFDIR)
1549 register_proc_table(table->child, de, set);
1554 * Unregister a /proc sysctl table and any subdirectories.
1556 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1558 struct proc_dir_entry *de;
1559 for (; table->ctl_name || table->procname; table++) {
1560 if (!(de = table->de))
1562 if (de->mode & S_IFDIR) {
1563 if (!table->child) {
1564 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1567 unregister_proc_table(table->child, de);
1569 /* Don't unregister directories which still have entries.. */
1575 * In any case, mark the entry as goner; we'll keep it
1576 * around if it's busy, but we'll know to do nothing with
1577 * its fields. We are under sysctl_lock here.
1581 /* Don't unregister proc entries that are still being used.. */
1582 if (atomic_read(&de->count))
1586 remove_proc_entry(table->procname, root);
1590 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1591 size_t count, loff_t *ppos)
1594 struct proc_dir_entry *de = PDE(file->f_path.dentry->d_inode);
1595 struct ctl_table *table;
1597 ssize_t error = -ENOTDIR;
1599 spin_lock(&sysctl_lock);
1600 if (de && de->data && use_table(de->set)) {
1602 * at that point we know that sysctl was not unregistered
1603 * and won't be until we finish
1605 spin_unlock(&sysctl_lock);
1606 table = (struct ctl_table *) de->data;
1607 if (!table || !table->proc_handler)
1610 op = (write ? 002 : 004);
1611 if (ctl_perm(table, op))
1614 /* careful: calling conventions are nasty here */
1616 error = (*table->proc_handler)(table, write, file,
1621 spin_lock(&sysctl_lock);
1622 unuse_table(de->set);
1624 spin_unlock(&sysctl_lock);
1628 static int proc_opensys(struct inode *inode, struct file *file)
1630 if (file->f_mode & FMODE_WRITE) {
1632 * sysctl entries that are not writable,
1633 * are _NOT_ writable, capabilities or not.
1635 if (!(inode->i_mode & S_IWUSR))
1642 static ssize_t proc_readsys(struct file * file, char __user * buf,
1643 size_t count, loff_t *ppos)
1645 return do_rw_proc(0, file, buf, count, ppos);
1648 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1649 size_t count, loff_t *ppos)
1651 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1654 static int _proc_do_string(void* data, int maxlen, int write,
1655 struct file *filp, void __user *buffer,
1656 size_t *lenp, loff_t *ppos)
1662 if (!data || !maxlen || !*lenp ||
1663 (*ppos && !write)) {
1671 while (len < *lenp) {
1672 if (get_user(c, p++))
1674 if (c == 0 || c == '\n')
1680 if(copy_from_user(data, buffer, len))
1682 ((char *) data)[len] = 0;
1691 if(copy_to_user(buffer, data, len))
1694 if(put_user('\n', ((char __user *) buffer) + len))
1705 * proc_dostring - read a string sysctl
1706 * @table: the sysctl table
1707 * @write: %TRUE if this is a write to the sysctl file
1708 * @filp: the file structure
1709 * @buffer: the user buffer
1710 * @lenp: the size of the user buffer
1711 * @ppos: file position
1713 * Reads/writes a string from/to the user buffer. If the kernel
1714 * buffer provided is not large enough to hold the string, the
1715 * string is truncated. The copied string is %NULL-terminated.
1716 * If the string is being read by the user process, it is copied
1717 * and a newline '\n' is added. It is truncated if the buffer is
1720 * Returns 0 on success.
1722 int proc_dostring(ctl_table *table, int write, struct file *filp,
1723 void __user *buffer, size_t *lenp, loff_t *ppos)
1725 return _proc_do_string(table->data, table->maxlen, write, filp,
1726 buffer, lenp, ppos);
1730 * Special case of dostring for the UTS structure. This has locks
1731 * to observe. Should this be in kernel/sys.c ????
1734 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
1735 void __user *buffer, size_t *lenp, loff_t *ppos)
1739 which = get_uts(table, write);
1740 r = _proc_do_string(which, table->maxlen,write,filp,buffer,lenp, ppos);
1741 put_uts(table, write, which);
1745 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1747 int write, void *data)
1750 *valp = *negp ? -*lvalp : *lvalp;
1755 *lvalp = (unsigned long)-val;
1758 *lvalp = (unsigned long)val;
1764 static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1765 int write, struct file *filp, void __user *buffer,
1766 size_t *lenp, loff_t *ppos,
1767 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1768 int write, void *data),
1771 #define TMPBUFLEN 21
1772 int *i, vleft, first=1, neg, val;
1776 char buf[TMPBUFLEN], *p;
1777 char __user *s = buffer;
1779 if (!tbl_data || !table->maxlen || !*lenp ||
1780 (*ppos && !write)) {
1785 i = (int *) tbl_data;
1786 vleft = table->maxlen / sizeof(*i);
1790 conv = do_proc_dointvec_conv;
1792 for (; left && vleft--; i++, first=0) {
1807 if (len > sizeof(buf) - 1)
1808 len = sizeof(buf) - 1;
1809 if (copy_from_user(buf, s, len))
1813 if (*p == '-' && left > 1) {
1817 if (*p < '0' || *p > '9')
1820 lval = simple_strtoul(p, &p, 0);
1823 if ((len < left) && *p && !isspace(*p))
1830 if (conv(&neg, &lval, i, 1, data))
1837 if (conv(&neg, &lval, i, 0, data))
1840 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1844 if(copy_to_user(s, buf, len))
1851 if (!write && !first && left) {
1852 if(put_user('\n', s))
1859 if (get_user(c, s++))
1874 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1875 void __user *buffer, size_t *lenp, loff_t *ppos,
1876 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1877 int write, void *data),
1880 return __do_proc_dointvec(table->data, table, write, filp,
1881 buffer, lenp, ppos, conv, data);
1885 * proc_dointvec - read a vector of integers
1886 * @table: the sysctl table
1887 * @write: %TRUE if this is a write to the sysctl file
1888 * @filp: the file structure
1889 * @buffer: the user buffer
1890 * @lenp: the size of the user buffer
1891 * @ppos: file position
1893 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1894 * values from/to the user buffer, treated as an ASCII string.
1896 * Returns 0 on success.
1898 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1899 void __user *buffer, size_t *lenp, loff_t *ppos)
1901 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1911 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1913 int write, void *data)
1915 int op = *(int *)data;
1917 int val = *negp ? -*lvalp : *lvalp;
1919 case OP_SET: *valp = val; break;
1920 case OP_AND: *valp &= val; break;
1921 case OP_OR: *valp |= val; break;
1922 case OP_MAX: if(*valp < val)
1925 case OP_MIN: if(*valp > val)
1933 *lvalp = (unsigned long)-val;
1936 *lvalp = (unsigned long)val;
1943 * init may raise the set.
1946 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1947 void __user *buffer, size_t *lenp, loff_t *ppos)
1951 if (!capable(CAP_SYS_MODULE)) {
1955 op = is_init(current) ? OP_SET : OP_AND;
1956 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1957 do_proc_dointvec_bset_conv,&op);
1960 struct do_proc_dointvec_minmax_conv_param {
1965 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1967 int write, void *data)
1969 struct do_proc_dointvec_minmax_conv_param *param = data;
1971 int val = *negp ? -*lvalp : *lvalp;
1972 if ((param->min && *param->min > val) ||
1973 (param->max && *param->max < val))
1980 *lvalp = (unsigned long)-val;
1983 *lvalp = (unsigned long)val;
1990 * proc_dointvec_minmax - read a vector of integers with min/max values
1991 * @table: the sysctl table
1992 * @write: %TRUE if this is a write to the sysctl file
1993 * @filp: the file structure
1994 * @buffer: the user buffer
1995 * @lenp: the size of the user buffer
1996 * @ppos: file position
1998 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1999 * values from/to the user buffer, treated as an ASCII string.
2001 * This routine will ensure the values are within the range specified by
2002 * table->extra1 (min) and table->extra2 (max).
2004 * Returns 0 on success.
2006 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2007 void __user *buffer, size_t *lenp, loff_t *ppos)
2009 struct do_proc_dointvec_minmax_conv_param param = {
2010 .min = (int *) table->extra1,
2011 .max = (int *) table->extra2,
2013 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2014 do_proc_dointvec_minmax_conv, ¶m);
2017 static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
2019 void __user *buffer,
2020 size_t *lenp, loff_t *ppos,
2021 unsigned long convmul,
2022 unsigned long convdiv)
2024 #define TMPBUFLEN 21
2025 unsigned long *i, *min, *max, val;
2026 int vleft, first=1, neg;
2028 char buf[TMPBUFLEN], *p;
2029 char __user *s = buffer;
2031 if (!data || !table->maxlen || !*lenp ||
2032 (*ppos && !write)) {
2037 i = (unsigned long *) data;
2038 min = (unsigned long *) table->extra1;
2039 max = (unsigned long *) table->extra2;
2040 vleft = table->maxlen / sizeof(unsigned long);
2043 for (; left && vleft--; i++, min++, max++, first=0) {
2058 if (len > TMPBUFLEN-1)
2060 if (copy_from_user(buf, s, len))
2064 if (*p == '-' && left > 1) {
2068 if (*p < '0' || *p > '9')
2070 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2072 if ((len < left) && *p && !isspace(*p))
2081 if ((min && val < *min) || (max && val > *max))
2088 sprintf(p, "%lu", convdiv * (*i) / convmul);
2092 if(copy_to_user(s, buf, len))
2099 if (!write && !first && left) {
2100 if(put_user('\n', s))
2107 if (get_user(c, s++))
2122 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2124 void __user *buffer,
2125 size_t *lenp, loff_t *ppos,
2126 unsigned long convmul,
2127 unsigned long convdiv)
2129 return __do_proc_doulongvec_minmax(table->data, table, write,
2130 filp, buffer, lenp, ppos, convmul, convdiv);
2134 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2135 * @table: the sysctl table
2136 * @write: %TRUE if this is a write to the sysctl file
2137 * @filp: the file structure
2138 * @buffer: the user buffer
2139 * @lenp: the size of the user buffer
2140 * @ppos: file position
2142 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2143 * values from/to the user buffer, treated as an ASCII string.
2145 * This routine will ensure the values are within the range specified by
2146 * table->extra1 (min) and table->extra2 (max).
2148 * Returns 0 on success.
2150 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2151 void __user *buffer, size_t *lenp, loff_t *ppos)
2153 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2157 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2158 * @table: the sysctl table
2159 * @write: %TRUE if this is a write to the sysctl file
2160 * @filp: the file structure
2161 * @buffer: the user buffer
2162 * @lenp: the size of the user buffer
2163 * @ppos: file position
2165 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2166 * values from/to the user buffer, treated as an ASCII string. The values
2167 * are treated as milliseconds, and converted to jiffies when they are stored.
2169 * This routine will ensure the values are within the range specified by
2170 * table->extra1 (min) and table->extra2 (max).
2172 * Returns 0 on success.
2174 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2176 void __user *buffer,
2177 size_t *lenp, loff_t *ppos)
2179 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2180 lenp, ppos, HZ, 1000l);
2184 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2186 int write, void *data)
2189 if (*lvalp > LONG_MAX / HZ)
2191 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2197 lval = (unsigned long)-val;
2200 lval = (unsigned long)val;
2207 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2209 int write, void *data)
2212 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2214 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2220 lval = (unsigned long)-val;
2223 lval = (unsigned long)val;
2225 *lvalp = jiffies_to_clock_t(lval);
2230 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2232 int write, void *data)
2235 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2241 lval = (unsigned long)-val;
2244 lval = (unsigned long)val;
2246 *lvalp = jiffies_to_msecs(lval);
2252 * proc_dointvec_jiffies - read a vector of integers as seconds
2253 * @table: the sysctl table
2254 * @write: %TRUE if this is a write to the sysctl file
2255 * @filp: the file structure
2256 * @buffer: the user buffer
2257 * @lenp: the size of the user buffer
2258 * @ppos: file position
2260 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2261 * values from/to the user buffer, treated as an ASCII string.
2262 * The values read are assumed to be in seconds, and are converted into
2265 * Returns 0 on success.
2267 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2268 void __user *buffer, size_t *lenp, loff_t *ppos)
2270 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2271 do_proc_dointvec_jiffies_conv,NULL);
2275 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2276 * @table: the sysctl table
2277 * @write: %TRUE if this is a write to the sysctl file
2278 * @filp: the file structure
2279 * @buffer: the user buffer
2280 * @lenp: the size of the user buffer
2281 * @ppos: pointer to the file position
2283 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2284 * values from/to the user buffer, treated as an ASCII string.
2285 * The values read are assumed to be in 1/USER_HZ seconds, and
2286 * are converted into jiffies.
2288 * Returns 0 on success.
2290 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2291 void __user *buffer, size_t *lenp, loff_t *ppos)
2293 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2294 do_proc_dointvec_userhz_jiffies_conv,NULL);
2298 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2299 * @table: the sysctl table
2300 * @write: %TRUE if this is a write to the sysctl file
2301 * @filp: the file structure
2302 * @buffer: the user buffer
2303 * @lenp: the size of the user buffer
2304 * @ppos: file position
2305 * @ppos: the current position in the file
2307 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2308 * values from/to the user buffer, treated as an ASCII string.
2309 * The values read are assumed to be in 1/1000 seconds, and
2310 * are converted into jiffies.
2312 * Returns 0 on success.
2314 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2315 void __user *buffer, size_t *lenp, loff_t *ppos)
2317 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2318 do_proc_dointvec_ms_jiffies_conv, NULL);
2321 #ifdef CONFIG_SYSVIPC
2322 static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2323 void __user *buffer, size_t *lenp, loff_t *ppos)
2326 struct ipc_namespace *ns;
2328 ns = current->nsproxy->ipc_ns;
2330 switch (table->ctl_name) {
2332 data = &ns->shm_ctlmax;
2335 data = &ns->shm_ctlall;
2338 data = &ns->shm_ctlmni;
2341 data = &ns->msg_ctlmax;
2344 data = &ns->msg_ctlmni;
2347 data = &ns->msg_ctlmnb;
2350 data = &ns->sem_ctls;
2356 return __do_proc_dointvec(data, table, write, filp, buffer,
2357 lenp, ppos, NULL, NULL);
2359 return __do_proc_doulongvec_minmax(data, table, write, filp, buffer,
2360 lenp, ppos, 1l, 1l);
2364 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2365 void __user *buffer, size_t *lenp, loff_t *ppos)
2367 struct pid *new_pid;
2371 tmp = pid_nr(cad_pid);
2373 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2374 lenp, ppos, NULL, NULL);
2378 new_pid = find_get_pid(tmp);
2382 put_pid(xchg(&cad_pid, new_pid));
2386 #else /* CONFIG_PROC_FS */
2388 int proc_dostring(ctl_table *table, int write, struct file *filp,
2389 void __user *buffer, size_t *lenp, loff_t *ppos)
2394 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
2395 void __user *buffer, size_t *lenp, loff_t *ppos)
2400 #ifdef CONFIG_SYSVIPC
2401 static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2402 void __user *buffer, size_t *lenp, loff_t *ppos)
2408 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2409 void __user *buffer, size_t *lenp, loff_t *ppos)
2414 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2415 void __user *buffer, size_t *lenp, loff_t *ppos)
2420 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2421 void __user *buffer, size_t *lenp, loff_t *ppos)
2426 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2427 void __user *buffer, size_t *lenp, loff_t *ppos)
2432 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2433 void __user *buffer, size_t *lenp, loff_t *ppos)
2438 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2439 void __user *buffer, size_t *lenp, loff_t *ppos)
2444 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2445 void __user *buffer, size_t *lenp, loff_t *ppos)
2450 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2452 void __user *buffer,
2453 size_t *lenp, loff_t *ppos)
2459 #endif /* CONFIG_PROC_FS */
2462 #ifdef CONFIG_SYSCTL_SYSCALL
2464 * General sysctl support routines
2467 /* The generic string strategy routine: */
2468 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2469 void __user *oldval, size_t __user *oldlenp,
2470 void __user *newval, size_t newlen, void **context)
2472 if (!table->data || !table->maxlen)
2475 if (oldval && oldlenp) {
2477 if (get_user(bufsize, oldlenp))
2480 size_t len = strlen(table->data), copied;
2482 /* This shouldn't trigger for a well-formed sysctl */
2483 if (len > table->maxlen)
2484 len = table->maxlen;
2486 /* Copy up to a max of bufsize-1 bytes of the string */
2487 copied = (len >= bufsize) ? bufsize - 1 : len;
2489 if (copy_to_user(oldval, table->data, copied) ||
2490 put_user(0, (char __user *)(oldval + copied)))
2492 if (put_user(len, oldlenp))
2496 if (newval && newlen) {
2497 size_t len = newlen;
2498 if (len > table->maxlen)
2499 len = table->maxlen;
2500 if(copy_from_user(table->data, newval, len))
2502 if (len == table->maxlen)
2504 ((char *) table->data)[len] = 0;
2510 * This function makes sure that all of the integers in the vector
2511 * are between the minimum and maximum values given in the arrays
2512 * table->extra1 and table->extra2, respectively.
2514 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2515 void __user *oldval, size_t __user *oldlenp,
2516 void __user *newval, size_t newlen, void **context)
2519 if (newval && newlen) {
2520 int __user *vec = (int __user *) newval;
2521 int *min = (int *) table->extra1;
2522 int *max = (int *) table->extra2;
2526 if (newlen % sizeof(int) != 0)
2529 if (!table->extra1 && !table->extra2)
2532 if (newlen > table->maxlen)
2533 newlen = table->maxlen;
2534 length = newlen / sizeof(int);
2536 for (i = 0; i < length; i++) {
2538 if (get_user(value, vec + i))
2540 if (min && value < min[i])
2542 if (max && value > max[i])
2549 /* Strategy function to convert jiffies to seconds */
2550 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2551 void __user *oldval, size_t __user *oldlenp,
2552 void __user *newval, size_t newlen, void **context)
2557 if (get_user(olen, oldlenp))
2559 if (olen!=sizeof(int))
2562 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2563 (oldlenp && put_user(sizeof(int),oldlenp)))
2566 if (newval && newlen) {
2568 if (newlen != sizeof(int))
2570 if (get_user(new, (int __user *)newval))
2572 *(int *)(table->data) = new*HZ;
2577 /* Strategy function to convert jiffies to seconds */
2578 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2579 void __user *oldval, size_t __user *oldlenp,
2580 void __user *newval, size_t newlen, void **context)
2585 if (get_user(olen, oldlenp))
2587 if (olen!=sizeof(int))
2590 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2591 (oldlenp && put_user(sizeof(int),oldlenp)))
2594 if (newval && newlen) {
2596 if (newlen != sizeof(int))
2598 if (get_user(new, (int __user *)newval))
2600 *(int *)(table->data) = msecs_to_jiffies(new);
2606 /* The generic string strategy routine: */
2607 static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2608 void __user *oldval, size_t __user *oldlenp,
2609 void __user *newval, size_t newlen, void **context)
2611 struct ctl_table uts_table;
2613 write = newval && newlen;
2614 memcpy(&uts_table, table, sizeof(uts_table));
2615 uts_table.data = get_uts(table, write);
2616 r = sysctl_string(&uts_table, name, nlen,
2617 oldval, oldlenp, newval, newlen, context);
2618 put_uts(table, write, uts_table.data);
2622 #else /* CONFIG_SYSCTL_SYSCALL */
2625 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2627 static int msg_count;
2628 struct __sysctl_args tmp;
2629 int name[CTL_MAXNAME];
2632 /* Read in the sysctl name for better debug message logging */
2633 if (copy_from_user(&tmp, args, sizeof(tmp)))
2635 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2637 for (i = 0; i < tmp.nlen; i++)
2638 if (get_user(name[i], tmp.name + i))
2641 /* Ignore accesses to kernel.version */
2642 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2645 if (msg_count < 5) {
2648 "warning: process `%s' used the removed sysctl "
2649 "system call with ", current->comm);
2650 for (i = 0; i < tmp.nlen; i++)
2651 printk("%d.", name[i]);
2658 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2659 void __user *oldval, size_t __user *oldlenp,
2660 void __user *newval, size_t newlen, void **context)
2665 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2666 void __user *oldval, size_t __user *oldlenp,
2667 void __user *newval, size_t newlen, void **context)
2672 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2673 void __user *oldval, size_t __user *oldlenp,
2674 void __user *newval, size_t newlen, void **context)
2679 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2680 void __user *oldval, size_t __user *oldlenp,
2681 void __user *newval, size_t newlen, void **context)
2686 static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2687 void __user *oldval, size_t __user *oldlenp,
2688 void __user *newval, size_t newlen, void **context)
2692 #endif /* CONFIG_SYSCTL_SYSCALL */
2695 * No sense putting this after each symbol definition, twice,
2696 * exception granted :-)
2698 EXPORT_SYMBOL(proc_dointvec);
2699 EXPORT_SYMBOL(proc_dointvec_jiffies);
2700 EXPORT_SYMBOL(proc_dointvec_minmax);
2701 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2702 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2703 EXPORT_SYMBOL(proc_dostring);
2704 EXPORT_SYMBOL(proc_doulongvec_minmax);
2705 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2706 EXPORT_SYMBOL(register_sysctl_table);
2707 EXPORT_SYMBOL(sysctl_intvec);
2708 EXPORT_SYMBOL(sysctl_jiffies);
2709 EXPORT_SYMBOL(sysctl_ms_jiffies);
2710 EXPORT_SYMBOL(sysctl_string);
2711 EXPORT_SYMBOL(unregister_sysctl_table);