2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/proc_fs.h>
27 #include <linux/capability.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/capability.h>
31 #include <linux/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/hugetlb.h>
40 #include <linux/security.h>
41 #include <linux/initrd.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/nfs_fs.h>
47 #include <linux/acpi.h>
49 #include <asm/uaccess.h>
50 #include <asm/processor.h>
52 extern int proc_nr_files(ctl_table *table, int write, struct file *filp,
53 void __user *buffer, size_t *lenp, loff_t *ppos);
57 #include <asm/stacktrace.h>
60 #if defined(CONFIG_SYSCTL)
62 /* External variables not in a header file. */
64 extern int sysctl_overcommit_memory;
65 extern int sysctl_overcommit_ratio;
66 extern int sysctl_panic_on_oom;
67 extern int max_threads;
68 extern int core_uses_pid;
69 extern int suid_dumpable;
70 extern char core_pattern[];
72 extern int min_free_kbytes;
73 extern int printk_ratelimit_jiffies;
74 extern int printk_ratelimit_burst;
75 extern int pid_max_min, pid_max_max;
76 extern int sysctl_drop_caches;
77 extern int percpu_pagelist_fraction;
78 extern int compat_log;
80 int exec_shield = (1<<0);
81 /* exec_shield is a bitmask:
82 0: off; vdso at STACK_TOP, 1 page below TASK_SIZE
83 (1<<0) 1: on [also on if !=0]
84 (1<<1) 2: force noexecstack regardless of PT_GNU_STACK
86 (1<<2) 4: vdso just below .text of main (unless too low)
87 (1<<3) 8: vdso just below .text of PT_INTERP (unless too low)
88 are ignored because the vdso is placed completely randomly
91 static int __init setup_exec_shield(char *str)
93 get_option (&str, &exec_shield);
98 __setup("exec-shield=", setup_exec_shield);
100 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
101 static int maxolduid = 65535;
102 static int minolduid;
103 static int min_percpu_pagelist_fract = 8;
105 static int ngroups_max = NGROUPS_MAX;
108 extern char modprobe_path[];
110 extern char vshelper_path[];
111 #ifdef CONFIG_CHR_DEV_SG
112 extern int sg_big_buff;
114 #ifdef CONFIG_SYSVIPC
115 static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
116 void __user *buffer, size_t *lenp, loff_t *ppos);
117 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
118 void __user *buffer, size_t *lenp, loff_t *ppos);
122 extern char reboot_command [];
123 extern int stop_a_enabled;
124 extern int scons_pwroff;
128 extern int pwrsw_enabled;
129 extern int unaligned_enabled;
133 #ifdef CONFIG_MATHEMU
134 extern int sysctl_ieee_emulation_warnings;
136 extern int sysctl_userprocess_debug;
137 extern int spin_retry;
140 extern int sysctl_hz_timer;
142 #ifdef CONFIG_BSD_PROCESS_ACCT
143 extern int acct_parm[];
147 extern int no_unaligned_warning;
150 #ifdef CONFIG_RT_MUTEXES
151 extern int max_lock_depth;
154 #ifdef CONFIG_SYSCTL_SYSCALL
155 static int parse_table(int __user *, int, void __user *, size_t __user *,
156 void __user *, size_t, ctl_table *);
159 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
160 void __user *buffer, size_t *lenp, loff_t *ppos);
162 static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
163 void __user *oldval, size_t __user *oldlenp,
164 void __user *newval, size_t newlen);
166 #ifdef CONFIG_SYSVIPC
167 static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
168 void __user *oldval, size_t __user *oldlenp,
169 void __user *newval, size_t newlen);
172 #ifdef CONFIG_PROC_SYSCTL
173 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
174 void __user *buffer, size_t *lenp, loff_t *ppos);
177 static ctl_table root_table[];
178 static struct ctl_table_header root_table_header =
179 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
181 static ctl_table kern_table[];
182 static ctl_table vm_table[];
183 static ctl_table fs_table[];
184 static ctl_table debug_table[];
185 static ctl_table dev_table[];
186 extern ctl_table random_table[];
187 #ifdef CONFIG_UNIX98_PTYS
188 extern ctl_table pty_table[];
190 #ifdef CONFIG_INOTIFY_USER
191 extern ctl_table inotify_table[];
194 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
195 int sysctl_legacy_va_layout;
198 static void *get_uts(ctl_table *table, int write)
200 char *which = table->data;
202 struct uts_namespace *uts_ns = current->nsproxy->uts_ns;
203 which = (which - (char *)&init_uts_ns) + (char *)uts_ns;
208 down_write(&uts_sem);
212 static void put_uts(ctl_table *table, int write, void *which)
220 #ifdef CONFIG_SYSVIPC
221 static void *get_ipc(ctl_table *table, int write)
223 char *which = table->data;
224 struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns;
225 which = (which - (char *)&init_ipc_ns) + (char *)ipc_ns;
229 #define get_ipc(T,W) ((T)->data)
232 /* /proc declarations: */
234 #ifdef CONFIG_PROC_SYSCTL
236 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
237 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
238 static int proc_opensys(struct inode *, struct file *);
240 const struct file_operations proc_sys_file_operations = {
241 .open = proc_opensys,
242 .read = proc_readsys,
243 .write = proc_writesys,
246 extern struct proc_dir_entry *proc_sys_root;
248 static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
249 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
252 /* The default sysctl tables: */
254 static ctl_table root_table[] = {
256 .ctl_name = CTL_KERN,
257 .procname = "kernel",
282 .ctl_name = CTL_DEBUG,
285 .child = debug_table,
297 static ctl_table kern_table[] = {
299 .ctl_name = KERN_OSTYPE,
300 .procname = "ostype",
301 .data = init_uts_ns.name.sysname,
302 .maxlen = sizeof(init_uts_ns.name.sysname),
304 .proc_handler = &proc_do_uts_string,
305 .strategy = &sysctl_uts_string,
308 .ctl_name = KERN_OSRELEASE,
309 .procname = "osrelease",
310 .data = init_uts_ns.name.release,
311 .maxlen = sizeof(init_uts_ns.name.release),
313 .proc_handler = &proc_do_uts_string,
314 .strategy = &sysctl_uts_string,
317 .ctl_name = KERN_VERSION,
318 .procname = "version",
319 .data = init_uts_ns.name.version,
320 .maxlen = sizeof(init_uts_ns.name.version),
322 .proc_handler = &proc_do_uts_string,
323 .strategy = &sysctl_uts_string,
326 .ctl_name = KERN_NODENAME,
327 .procname = "hostname",
328 .data = init_uts_ns.name.nodename,
329 .maxlen = sizeof(init_uts_ns.name.nodename),
331 .proc_handler = &proc_do_uts_string,
332 .strategy = &sysctl_uts_string,
335 .ctl_name = KERN_DOMAINNAME,
336 .procname = "domainname",
337 .data = init_uts_ns.name.domainname,
338 .maxlen = sizeof(init_uts_ns.name.domainname),
340 .proc_handler = &proc_do_uts_string,
341 .strategy = &sysctl_uts_string,
344 .ctl_name = KERN_PANIC,
346 .data = &panic_timeout,
347 .maxlen = sizeof(int),
349 .proc_handler = &proc_dointvec,
352 .ctl_name = KERN_EXEC_SHIELD,
353 .procname = "exec-shield",
354 .data = &exec_shield,
355 .maxlen = sizeof(int),
357 .proc_handler = &proc_dointvec,
360 .ctl_name = KERN_PRINT_FATAL,
361 .procname = "print-fatal-signals",
362 .data = &print_fatal_signals,
363 .maxlen = sizeof(int),
365 .proc_handler = &proc_dointvec,
368 .ctl_name = KERN_CORE_USES_PID,
369 .procname = "core_uses_pid",
370 .data = &core_uses_pid,
371 .maxlen = sizeof(int),
373 .proc_handler = &proc_dointvec,
376 .ctl_name = KERN_CORE_PATTERN,
377 .procname = "core_pattern",
378 .data = core_pattern,
381 .proc_handler = &proc_dostring,
382 .strategy = &sysctl_string,
385 .ctl_name = KERN_TAINTED,
386 .procname = "tainted",
388 .maxlen = sizeof(int),
390 .proc_handler = &proc_dointvec,
393 .ctl_name = KERN_CAP_BSET,
394 .procname = "cap-bound",
396 .maxlen = sizeof(kernel_cap_t),
398 .proc_handler = &proc_dointvec_bset,
400 #ifdef CONFIG_BLK_DEV_INITRD
402 .ctl_name = KERN_REALROOTDEV,
403 .procname = "real-root-dev",
404 .data = &real_root_dev,
405 .maxlen = sizeof(int),
407 .proc_handler = &proc_dointvec,
412 .ctl_name = KERN_SPARC_REBOOT,
413 .procname = "reboot-cmd",
414 .data = reboot_command,
417 .proc_handler = &proc_dostring,
418 .strategy = &sysctl_string,
421 .ctl_name = KERN_SPARC_STOP_A,
422 .procname = "stop-a",
423 .data = &stop_a_enabled,
424 .maxlen = sizeof (int),
426 .proc_handler = &proc_dointvec,
429 .ctl_name = KERN_SPARC_SCONS_PWROFF,
430 .procname = "scons-poweroff",
431 .data = &scons_pwroff,
432 .maxlen = sizeof (int),
434 .proc_handler = &proc_dointvec,
439 .ctl_name = KERN_HPPA_PWRSW,
440 .procname = "soft-power",
441 .data = &pwrsw_enabled,
442 .maxlen = sizeof (int),
444 .proc_handler = &proc_dointvec,
447 .ctl_name = KERN_HPPA_UNALIGNED,
448 .procname = "unaligned-trap",
449 .data = &unaligned_enabled,
450 .maxlen = sizeof (int),
452 .proc_handler = &proc_dointvec,
456 .ctl_name = KERN_CTLALTDEL,
457 .procname = "ctrl-alt-del",
459 .maxlen = sizeof(int),
461 .proc_handler = &proc_dointvec,
464 .ctl_name = KERN_PRINTK,
465 .procname = "printk",
466 .data = &console_loglevel,
467 .maxlen = 4*sizeof(int),
469 .proc_handler = &proc_dointvec,
473 .ctl_name = KERN_MODPROBE,
474 .procname = "modprobe",
475 .data = &modprobe_path,
476 .maxlen = KMOD_PATH_LEN,
478 .proc_handler = &proc_dostring,
479 .strategy = &sysctl_string,
482 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
484 .ctl_name = KERN_HOTPLUG,
485 .procname = "hotplug",
486 .data = &uevent_helper,
487 .maxlen = UEVENT_HELPER_PATH_LEN,
489 .proc_handler = &proc_dostring,
490 .strategy = &sysctl_string,
494 .ctl_name = KERN_VSHELPER,
495 .procname = "vshelper",
496 .data = &vshelper_path,
499 .proc_handler = &proc_dostring,
500 .strategy = &sysctl_string,
502 #ifdef CONFIG_CHR_DEV_SG
504 .ctl_name = KERN_SG_BIG_BUFF,
505 .procname = "sg-big-buff",
506 .data = &sg_big_buff,
507 .maxlen = sizeof (int),
509 .proc_handler = &proc_dointvec,
512 #ifdef CONFIG_BSD_PROCESS_ACCT
514 .ctl_name = KERN_ACCT,
517 .maxlen = 3*sizeof(int),
519 .proc_handler = &proc_dointvec,
522 #ifdef CONFIG_SYSVIPC
524 .ctl_name = KERN_SHMMAX,
525 .procname = "shmmax",
526 .data = &init_ipc_ns.shm_ctlmax,
527 .maxlen = sizeof (init_ipc_ns.shm_ctlmax),
529 .proc_handler = &proc_ipc_doulongvec_minmax,
530 .strategy = sysctl_ipc_data,
533 .ctl_name = KERN_SHMALL,
534 .procname = "shmall",
535 .data = &init_ipc_ns.shm_ctlall,
536 .maxlen = sizeof (init_ipc_ns.shm_ctlall),
538 .proc_handler = &proc_ipc_doulongvec_minmax,
539 .strategy = sysctl_ipc_data,
542 .ctl_name = KERN_SHMMNI,
543 .procname = "shmmni",
544 .data = &init_ipc_ns.shm_ctlmni,
545 .maxlen = sizeof (init_ipc_ns.shm_ctlmni),
547 .proc_handler = &proc_ipc_dointvec,
548 .strategy = sysctl_ipc_data,
551 .ctl_name = KERN_MSGMAX,
552 .procname = "msgmax",
553 .data = &init_ipc_ns.msg_ctlmax,
554 .maxlen = sizeof (init_ipc_ns.msg_ctlmax),
556 .proc_handler = &proc_ipc_dointvec,
557 .strategy = sysctl_ipc_data,
560 .ctl_name = KERN_MSGMNI,
561 .procname = "msgmni",
562 .data = &init_ipc_ns.msg_ctlmni,
563 .maxlen = sizeof (init_ipc_ns.msg_ctlmni),
565 .proc_handler = &proc_ipc_dointvec,
566 .strategy = sysctl_ipc_data,
569 .ctl_name = KERN_MSGMNB,
570 .procname = "msgmnb",
571 .data = &init_ipc_ns.msg_ctlmnb,
572 .maxlen = sizeof (init_ipc_ns.msg_ctlmnb),
574 .proc_handler = &proc_ipc_dointvec,
575 .strategy = sysctl_ipc_data,
578 .ctl_name = KERN_SEM,
580 .data = &init_ipc_ns.sem_ctls,
581 .maxlen = 4*sizeof (int),
583 .proc_handler = &proc_ipc_dointvec,
584 .strategy = sysctl_ipc_data,
587 #ifdef CONFIG_MAGIC_SYSRQ
589 .ctl_name = KERN_SYSRQ,
591 .data = &__sysrq_enabled,
592 .maxlen = sizeof (int),
594 .proc_handler = &proc_dointvec,
597 #ifdef CONFIG_PROC_SYSCTL
599 .ctl_name = KERN_CADPID,
600 .procname = "cad_pid",
602 .maxlen = sizeof (int),
604 .proc_handler = &proc_do_cad_pid,
608 .ctl_name = KERN_MAX_THREADS,
609 .procname = "threads-max",
610 .data = &max_threads,
611 .maxlen = sizeof(int),
613 .proc_handler = &proc_dointvec,
616 .ctl_name = KERN_RANDOM,
617 .procname = "random",
619 .child = random_table,
621 #ifdef CONFIG_UNIX98_PTYS
623 .ctl_name = KERN_PTY,
630 .ctl_name = KERN_OVERFLOWUID,
631 .procname = "overflowuid",
632 .data = &overflowuid,
633 .maxlen = sizeof(int),
635 .proc_handler = &proc_dointvec_minmax,
636 .strategy = &sysctl_intvec,
637 .extra1 = &minolduid,
638 .extra2 = &maxolduid,
641 .ctl_name = KERN_OVERFLOWGID,
642 .procname = "overflowgid",
643 .data = &overflowgid,
644 .maxlen = sizeof(int),
646 .proc_handler = &proc_dointvec_minmax,
647 .strategy = &sysctl_intvec,
648 .extra1 = &minolduid,
649 .extra2 = &maxolduid,
652 #ifdef CONFIG_MATHEMU
654 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
655 .procname = "ieee_emulation_warnings",
656 .data = &sysctl_ieee_emulation_warnings,
657 .maxlen = sizeof(int),
659 .proc_handler = &proc_dointvec,
662 #ifdef CONFIG_NO_IDLE_HZ
664 .ctl_name = KERN_HZ_TIMER,
665 .procname = "hz_timer",
666 .data = &sysctl_hz_timer,
667 .maxlen = sizeof(int),
669 .proc_handler = &proc_dointvec,
673 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
674 .procname = "userprocess_debug",
675 .data = &sysctl_userprocess_debug,
676 .maxlen = sizeof(int),
678 .proc_handler = &proc_dointvec,
682 .ctl_name = KERN_PIDMAX,
683 .procname = "pid_max",
685 .maxlen = sizeof (int),
687 .proc_handler = &proc_dointvec_minmax,
688 .strategy = sysctl_intvec,
689 .extra1 = &pid_max_min,
690 .extra2 = &pid_max_max,
693 .ctl_name = KERN_PANIC_ON_OOPS,
694 .procname = "panic_on_oops",
695 .data = &panic_on_oops,
696 .maxlen = sizeof(int),
698 .proc_handler = &proc_dointvec,
701 .ctl_name = KERN_PRINTK_RATELIMIT,
702 .procname = "printk_ratelimit",
703 .data = &printk_ratelimit_jiffies,
704 .maxlen = sizeof(int),
706 .proc_handler = &proc_dointvec_jiffies,
707 .strategy = &sysctl_jiffies,
710 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
711 .procname = "printk_ratelimit_burst",
712 .data = &printk_ratelimit_burst,
713 .maxlen = sizeof(int),
715 .proc_handler = &proc_dointvec,
718 .ctl_name = KERN_NGROUPS_MAX,
719 .procname = "ngroups_max",
720 .data = &ngroups_max,
721 .maxlen = sizeof (int),
723 .proc_handler = &proc_dointvec,
725 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
727 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
728 .procname = "unknown_nmi_panic",
729 .data = &unknown_nmi_panic,
730 .maxlen = sizeof (int),
732 .proc_handler = &proc_dointvec,
735 .ctl_name = KERN_NMI_WATCHDOG,
736 .procname = "nmi_watchdog",
737 .data = &nmi_watchdog_enabled,
738 .maxlen = sizeof (int),
740 .proc_handler = &proc_nmi_enabled,
743 #if defined(CONFIG_X86)
745 .ctl_name = KERN_PANIC_ON_NMI,
746 .procname = "panic_on_unrecovered_nmi",
747 .data = &panic_on_unrecovered_nmi,
748 .maxlen = sizeof(int),
750 .proc_handler = &proc_dointvec,
753 .ctl_name = KERN_BOOTLOADER_TYPE,
754 .procname = "bootloader_type",
755 .data = &bootloader_type,
756 .maxlen = sizeof (int),
758 .proc_handler = &proc_dointvec,
761 .ctl_name = CTL_UNNUMBERED,
762 .procname = "kstack_depth_to_print",
763 .data = &kstack_depth_to_print,
764 .maxlen = sizeof(int),
766 .proc_handler = &proc_dointvec,
769 #if defined(CONFIG_MMU)
771 .ctl_name = KERN_RANDOMIZE,
772 .procname = "randomize_va_space",
773 .data = &randomize_va_space,
774 .maxlen = sizeof(int),
776 .proc_handler = &proc_dointvec,
779 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
781 .ctl_name = KERN_SPIN_RETRY,
782 .procname = "spin_retry",
784 .maxlen = sizeof (int),
786 .proc_handler = &proc_dointvec,
789 #ifdef CONFIG_ACPI_SLEEP
791 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
792 .procname = "acpi_video_flags",
793 .data = &acpi_video_flags,
794 .maxlen = sizeof (unsigned long),
796 .proc_handler = &proc_doulongvec_minmax,
801 .ctl_name = KERN_IA64_UNALIGNED,
802 .procname = "ignore-unaligned-usertrap",
803 .data = &no_unaligned_warning,
804 .maxlen = sizeof (int),
806 .proc_handler = &proc_dointvec,
811 .ctl_name = KERN_COMPAT_LOG,
812 .procname = "compat-log",
814 .maxlen = sizeof (int),
816 .proc_handler = &proc_dointvec,
819 #ifdef CONFIG_RT_MUTEXES
821 .ctl_name = KERN_MAX_LOCK_DEPTH,
822 .procname = "max_lock_depth",
823 .data = &max_lock_depth,
824 .maxlen = sizeof(int),
826 .proc_handler = &proc_dointvec,
833 /* Constants for minimum and maximum testing in vm_table.
834 We use these as one-element integer vectors. */
836 static int one_hundred = 100;
839 static ctl_table vm_table[] = {
841 .ctl_name = VM_OVERCOMMIT_MEMORY,
842 .procname = "overcommit_memory",
843 .data = &sysctl_overcommit_memory,
844 .maxlen = sizeof(sysctl_overcommit_memory),
846 .proc_handler = &proc_dointvec,
849 .ctl_name = VM_PANIC_ON_OOM,
850 .procname = "panic_on_oom",
851 .data = &sysctl_panic_on_oom,
852 .maxlen = sizeof(sysctl_panic_on_oom),
854 .proc_handler = &proc_dointvec,
857 .ctl_name = VM_OVERCOMMIT_RATIO,
858 .procname = "overcommit_ratio",
859 .data = &sysctl_overcommit_ratio,
860 .maxlen = sizeof(sysctl_overcommit_ratio),
862 .proc_handler = &proc_dointvec,
865 .ctl_name = VM_PAGE_CLUSTER,
866 .procname = "page-cluster",
867 .data = &page_cluster,
868 .maxlen = sizeof(int),
870 .proc_handler = &proc_dointvec,
873 .ctl_name = VM_DIRTY_BACKGROUND,
874 .procname = "dirty_background_ratio",
875 .data = &dirty_background_ratio,
876 .maxlen = sizeof(dirty_background_ratio),
878 .proc_handler = &proc_dointvec_minmax,
879 .strategy = &sysctl_intvec,
881 .extra2 = &one_hundred,
884 .ctl_name = VM_DIRTY_RATIO,
885 .procname = "dirty_ratio",
886 .data = &vm_dirty_ratio,
887 .maxlen = sizeof(vm_dirty_ratio),
889 .proc_handler = &proc_dointvec_minmax,
890 .strategy = &sysctl_intvec,
892 .extra2 = &one_hundred,
895 .ctl_name = VM_DIRTY_WB_CS,
896 .procname = "dirty_writeback_centisecs",
897 .data = &dirty_writeback_interval,
898 .maxlen = sizeof(dirty_writeback_interval),
900 .proc_handler = &dirty_writeback_centisecs_handler,
903 .ctl_name = VM_DIRTY_EXPIRE_CS,
904 .procname = "dirty_expire_centisecs",
905 .data = &dirty_expire_interval,
906 .maxlen = sizeof(dirty_expire_interval),
908 .proc_handler = &proc_dointvec_userhz_jiffies,
911 .ctl_name = VM_NR_PDFLUSH_THREADS,
912 .procname = "nr_pdflush_threads",
913 .data = &nr_pdflush_threads,
914 .maxlen = sizeof nr_pdflush_threads,
915 .mode = 0444 /* read-only*/,
916 .proc_handler = &proc_dointvec,
919 .ctl_name = VM_SWAPPINESS,
920 .procname = "swappiness",
921 .data = &vm_swappiness,
922 .maxlen = sizeof(vm_swappiness),
924 .proc_handler = &proc_dointvec_minmax,
925 .strategy = &sysctl_intvec,
927 .extra2 = &one_hundred,
929 #ifdef CONFIG_HUGETLB_PAGE
931 .ctl_name = VM_HUGETLB_PAGES,
932 .procname = "nr_hugepages",
933 .data = &max_huge_pages,
934 .maxlen = sizeof(unsigned long),
936 .proc_handler = &hugetlb_sysctl_handler,
937 .extra1 = (void *)&hugetlb_zero,
938 .extra2 = (void *)&hugetlb_infinity,
941 .ctl_name = VM_HUGETLB_GROUP,
942 .procname = "hugetlb_shm_group",
943 .data = &sysctl_hugetlb_shm_group,
944 .maxlen = sizeof(gid_t),
946 .proc_handler = &proc_dointvec,
950 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
951 .procname = "lowmem_reserve_ratio",
952 .data = &sysctl_lowmem_reserve_ratio,
953 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
955 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
956 .strategy = &sysctl_intvec,
959 .ctl_name = VM_DROP_PAGECACHE,
960 .procname = "drop_caches",
961 .data = &sysctl_drop_caches,
962 .maxlen = sizeof(int),
964 .proc_handler = drop_caches_sysctl_handler,
965 .strategy = &sysctl_intvec,
968 .ctl_name = VM_MIN_FREE_KBYTES,
969 .procname = "min_free_kbytes",
970 .data = &min_free_kbytes,
971 .maxlen = sizeof(min_free_kbytes),
973 .proc_handler = &min_free_kbytes_sysctl_handler,
974 .strategy = &sysctl_intvec,
978 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
979 .procname = "percpu_pagelist_fraction",
980 .data = &percpu_pagelist_fraction,
981 .maxlen = sizeof(percpu_pagelist_fraction),
983 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
984 .strategy = &sysctl_intvec,
985 .extra1 = &min_percpu_pagelist_fract,
989 .ctl_name = VM_MAX_MAP_COUNT,
990 .procname = "max_map_count",
991 .data = &sysctl_max_map_count,
992 .maxlen = sizeof(sysctl_max_map_count),
994 .proc_handler = &proc_dointvec
998 .ctl_name = VM_LAPTOP_MODE,
999 .procname = "laptop_mode",
1000 .data = &laptop_mode,
1001 .maxlen = sizeof(laptop_mode),
1003 .proc_handler = &proc_dointvec_jiffies,
1004 .strategy = &sysctl_jiffies,
1007 .ctl_name = VM_BLOCK_DUMP,
1008 .procname = "block_dump",
1009 .data = &block_dump,
1010 .maxlen = sizeof(block_dump),
1012 .proc_handler = &proc_dointvec,
1013 .strategy = &sysctl_intvec,
1017 .ctl_name = VM_VFS_CACHE_PRESSURE,
1018 .procname = "vfs_cache_pressure",
1019 .data = &sysctl_vfs_cache_pressure,
1020 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1022 .proc_handler = &proc_dointvec,
1023 .strategy = &sysctl_intvec,
1026 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1028 .ctl_name = VM_LEGACY_VA_LAYOUT,
1029 .procname = "legacy_va_layout",
1030 .data = &sysctl_legacy_va_layout,
1031 .maxlen = sizeof(sysctl_legacy_va_layout),
1033 .proc_handler = &proc_dointvec,
1034 .strategy = &sysctl_intvec,
1040 .ctl_name = VM_ZONE_RECLAIM_MODE,
1041 .procname = "zone_reclaim_mode",
1042 .data = &zone_reclaim_mode,
1043 .maxlen = sizeof(zone_reclaim_mode),
1045 .proc_handler = &proc_dointvec,
1046 .strategy = &sysctl_intvec,
1050 .ctl_name = VM_MIN_UNMAPPED,
1051 .procname = "min_unmapped_ratio",
1052 .data = &sysctl_min_unmapped_ratio,
1053 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1055 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1056 .strategy = &sysctl_intvec,
1058 .extra2 = &one_hundred,
1061 .ctl_name = VM_MIN_SLAB,
1062 .procname = "min_slab_ratio",
1063 .data = &sysctl_min_slab_ratio,
1064 .maxlen = sizeof(sysctl_min_slab_ratio),
1066 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1067 .strategy = &sysctl_intvec,
1069 .extra2 = &one_hundred,
1072 #ifdef CONFIG_X86_32
1074 .ctl_name = VM_VDSO_ENABLED,
1075 .procname = "vdso_enabled",
1076 .data = &vdso_enabled,
1077 .maxlen = sizeof(vdso_enabled),
1079 .proc_handler = &proc_dointvec,
1080 .strategy = &sysctl_intvec,
1087 static ctl_table fs_table[] = {
1089 .ctl_name = FS_NRINODE,
1090 .procname = "inode-nr",
1091 .data = &inodes_stat,
1092 .maxlen = 2*sizeof(int),
1094 .proc_handler = &proc_dointvec,
1097 .ctl_name = FS_STATINODE,
1098 .procname = "inode-state",
1099 .data = &inodes_stat,
1100 .maxlen = 7*sizeof(int),
1102 .proc_handler = &proc_dointvec,
1105 .ctl_name = FS_NRFILE,
1106 .procname = "file-nr",
1107 .data = &files_stat,
1108 .maxlen = 3*sizeof(int),
1110 .proc_handler = &proc_nr_files,
1113 .ctl_name = FS_MAXFILE,
1114 .procname = "file-max",
1115 .data = &files_stat.max_files,
1116 .maxlen = sizeof(int),
1118 .proc_handler = &proc_dointvec,
1121 .ctl_name = FS_DENTRY,
1122 .procname = "dentry-state",
1123 .data = &dentry_stat,
1124 .maxlen = 6*sizeof(int),
1126 .proc_handler = &proc_dointvec,
1129 .ctl_name = FS_OVERFLOWUID,
1130 .procname = "overflowuid",
1131 .data = &fs_overflowuid,
1132 .maxlen = sizeof(int),
1134 .proc_handler = &proc_dointvec_minmax,
1135 .strategy = &sysctl_intvec,
1136 .extra1 = &minolduid,
1137 .extra2 = &maxolduid,
1140 .ctl_name = FS_OVERFLOWGID,
1141 .procname = "overflowgid",
1142 .data = &fs_overflowgid,
1143 .maxlen = sizeof(int),
1145 .proc_handler = &proc_dointvec_minmax,
1146 .strategy = &sysctl_intvec,
1147 .extra1 = &minolduid,
1148 .extra2 = &maxolduid,
1151 .ctl_name = FS_LEASES,
1152 .procname = "leases-enable",
1153 .data = &leases_enable,
1154 .maxlen = sizeof(int),
1156 .proc_handler = &proc_dointvec,
1158 #ifdef CONFIG_DNOTIFY
1160 .ctl_name = FS_DIR_NOTIFY,
1161 .procname = "dir-notify-enable",
1162 .data = &dir_notify_enable,
1163 .maxlen = sizeof(int),
1165 .proc_handler = &proc_dointvec,
1170 .ctl_name = FS_LEASE_TIME,
1171 .procname = "lease-break-time",
1172 .data = &lease_break_time,
1173 .maxlen = sizeof(int),
1175 .proc_handler = &proc_dointvec,
1178 .ctl_name = FS_AIO_NR,
1179 .procname = "aio-nr",
1181 .maxlen = sizeof(aio_nr),
1183 .proc_handler = &proc_doulongvec_minmax,
1186 .ctl_name = FS_AIO_MAX_NR,
1187 .procname = "aio-max-nr",
1188 .data = &aio_max_nr,
1189 .maxlen = sizeof(aio_max_nr),
1191 .proc_handler = &proc_doulongvec_minmax,
1193 #ifdef CONFIG_INOTIFY_USER
1195 .ctl_name = FS_INOTIFY,
1196 .procname = "inotify",
1198 .child = inotify_table,
1203 .ctl_name = KERN_SETUID_DUMPABLE,
1204 .procname = "suid_dumpable",
1205 .data = &suid_dumpable,
1206 .maxlen = sizeof(int),
1208 .proc_handler = &proc_dointvec,
1213 static ctl_table debug_table[] = {
1217 static ctl_table dev_table[] = {
1221 extern void init_irq_proc (void);
1223 static DEFINE_SPINLOCK(sysctl_lock);
1225 /* called under sysctl_lock */
1226 static int use_table(struct ctl_table_header *p)
1228 if (unlikely(p->unregistering))
1234 /* called under sysctl_lock */
1235 static void unuse_table(struct ctl_table_header *p)
1238 if (unlikely(p->unregistering))
1239 complete(p->unregistering);
1242 /* called under sysctl_lock, will reacquire if has to wait */
1243 static void start_unregistering(struct ctl_table_header *p)
1246 * if p->used is 0, nobody will ever touch that entry again;
1247 * we'll eliminate all paths to it before dropping sysctl_lock
1249 if (unlikely(p->used)) {
1250 struct completion wait;
1251 init_completion(&wait);
1252 p->unregistering = &wait;
1253 spin_unlock(&sysctl_lock);
1254 wait_for_completion(&wait);
1255 spin_lock(&sysctl_lock);
1258 * do not remove from the list until nobody holds it; walking the
1259 * list in do_sysctl() relies on that.
1261 list_del_init(&p->ctl_entry);
1264 void __init sysctl_init(void)
1266 #ifdef CONFIG_PROC_SYSCTL
1267 register_proc_table(root_table, proc_sys_root, &root_table_header);
1272 #ifdef CONFIG_SYSCTL_SYSCALL
1273 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1274 void __user *newval, size_t newlen)
1276 struct list_head *tmp;
1277 int error = -ENOTDIR;
1279 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1283 if (!oldlenp || get_user(old_len, oldlenp))
1286 spin_lock(&sysctl_lock);
1287 tmp = &root_table_header.ctl_entry;
1289 struct ctl_table_header *head =
1290 list_entry(tmp, struct ctl_table_header, ctl_entry);
1292 if (!use_table(head))
1295 spin_unlock(&sysctl_lock);
1297 error = parse_table(name, nlen, oldval, oldlenp,
1298 newval, newlen, head->ctl_table);
1300 spin_lock(&sysctl_lock);
1302 if (error != -ENOTDIR)
1304 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1305 spin_unlock(&sysctl_lock);
1309 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1311 struct __sysctl_args tmp;
1314 if (copy_from_user(&tmp, args, sizeof(tmp)))
1318 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1319 tmp.newval, tmp.newlen);
1323 #endif /* CONFIG_SYSCTL_SYSCALL */
1326 * ctl_perm does NOT grant the superuser all rights automatically, because
1327 * some sysctl variables are readonly even to root.
1330 static int test_perm(int mode, int op)
1334 else if (in_egroup_p(0))
1336 if ((mode & op & 0007) == op)
1341 static inline int ctl_perm(ctl_table *table, int op)
1344 error = security_sysctl(table, op);
1347 return test_perm(table->mode, op);
1350 #ifdef CONFIG_SYSCTL_SYSCALL
1351 static int parse_table(int __user *name, int nlen,
1352 void __user *oldval, size_t __user *oldlenp,
1353 void __user *newval, size_t newlen,
1360 if (get_user(n, name))
1362 for ( ; table->ctl_name || table->procname; table++) {
1363 if (!table->ctl_name)
1365 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1368 if (ctl_perm(table, 001))
1370 if (table->strategy) {
1371 error = table->strategy(
1380 table = table->child;
1383 error = do_sysctl_strategy(table, name, nlen,
1392 /* Perform the actual read/write of a sysctl table entry. */
1393 int do_sysctl_strategy (ctl_table *table,
1394 int __user *name, int nlen,
1395 void __user *oldval, size_t __user *oldlenp,
1396 void __user *newval, size_t newlen)
1405 if (ctl_perm(table, op))
1408 if (table->strategy) {
1409 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1417 /* If there is no strategy routine, or if the strategy returns
1418 * zero, proceed with automatic r/w */
1419 if (table->data && table->maxlen) {
1420 if (oldval && oldlenp) {
1421 if (get_user(len, oldlenp))
1424 if (len > table->maxlen)
1425 len = table->maxlen;
1426 if(copy_to_user(oldval, table->data, len))
1428 if(put_user(len, oldlenp))
1432 if (newval && newlen) {
1434 if (len > table->maxlen)
1435 len = table->maxlen;
1436 if(copy_from_user(table->data, newval, len))
1442 #endif /* CONFIG_SYSCTL_SYSCALL */
1445 * register_sysctl_table - register a sysctl hierarchy
1446 * @table: the top-level table structure
1447 * @insert_at_head: whether the entry should be inserted in front or at the end
1449 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1450 * array. An entry with a ctl_name of 0 terminates the table.
1452 * The members of the &ctl_table structure are used as follows:
1454 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1455 * must be unique within that level of sysctl
1457 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1458 * enter a sysctl file
1460 * data - a pointer to data for use by proc_handler
1462 * maxlen - the maximum size in bytes of the data
1464 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1466 * child - a pointer to the child sysctl table if this entry is a directory, or
1469 * proc_handler - the text handler routine (described below)
1471 * strategy - the strategy routine (described below)
1473 * de - for internal use by the sysctl routines
1475 * extra1, extra2 - extra pointers usable by the proc handler routines
1477 * Leaf nodes in the sysctl tree will be represented by a single file
1478 * under /proc; non-leaf nodes will be represented by directories.
1480 * sysctl(2) can automatically manage read and write requests through
1481 * the sysctl table. The data and maxlen fields of the ctl_table
1482 * struct enable minimal validation of the values being written to be
1483 * performed, and the mode field allows minimal authentication.
1485 * More sophisticated management can be enabled by the provision of a
1486 * strategy routine with the table entry. This will be called before
1487 * any automatic read or write of the data is performed.
1489 * The strategy routine may return
1491 * < 0 - Error occurred (error is passed to user process)
1493 * 0 - OK - proceed with automatic read or write.
1495 * > 0 - OK - read or write has been done by the strategy routine, so
1496 * return immediately.
1498 * There must be a proc_handler routine for any terminal nodes
1499 * mirrored under /proc/sys (non-terminals are handled by a built-in
1500 * directory handler). Several default handlers are available to
1501 * cover common cases -
1503 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1504 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1505 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1507 * It is the handler's job to read the input buffer from user memory
1508 * and process it. The handler should return 0 on success.
1510 * This routine returns %NULL on a failure to register, and a pointer
1511 * to the table header on success.
1513 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1516 struct ctl_table_header *tmp;
1517 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1520 tmp->ctl_table = table;
1521 INIT_LIST_HEAD(&tmp->ctl_entry);
1523 tmp->unregistering = NULL;
1524 spin_lock(&sysctl_lock);
1526 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1528 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1529 spin_unlock(&sysctl_lock);
1530 #ifdef CONFIG_PROC_SYSCTL
1531 register_proc_table(table, proc_sys_root, tmp);
1537 * unregister_sysctl_table - unregister a sysctl table hierarchy
1538 * @header: the header returned from register_sysctl_table
1540 * Unregisters the sysctl table and all children. proc entries may not
1541 * actually be removed until they are no longer used by anyone.
1543 void unregister_sysctl_table(struct ctl_table_header * header)
1546 spin_lock(&sysctl_lock);
1547 start_unregistering(header);
1548 #ifdef CONFIG_PROC_SYSCTL
1549 unregister_proc_table(header->ctl_table, proc_sys_root);
1551 spin_unlock(&sysctl_lock);
1555 #else /* !CONFIG_SYSCTL */
1556 struct ctl_table_header * register_sysctl_table(ctl_table * table,
1562 void unregister_sysctl_table(struct ctl_table_header * table)
1566 #endif /* CONFIG_SYSCTL */
1572 #ifdef CONFIG_PROC_SYSCTL
1574 /* Scan the sysctl entries in table and add them all into /proc */
1575 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1577 struct proc_dir_entry *de;
1581 for (; table->ctl_name || table->procname; table++) {
1582 /* Can't do anything without a proc name. */
1583 if (!table->procname)
1585 /* Maybe we can't do anything with it... */
1586 if (!table->proc_handler && !table->child) {
1587 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1592 len = strlen(table->procname);
1596 if (table->proc_handler)
1600 for (de = root->subdir; de; de = de->next) {
1601 if (proc_match(len, table->procname, de))
1604 /* If the subdir exists already, de is non-NULL */
1608 de = create_proc_entry(table->procname, mode, root);
1612 de->data = (void *) table;
1613 if (table->proc_handler)
1614 de->proc_fops = &proc_sys_file_operations;
1617 if (de->mode & S_IFDIR)
1618 register_proc_table(table->child, de, set);
1623 * Unregister a /proc sysctl table and any subdirectories.
1625 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1627 struct proc_dir_entry *de;
1628 for (; table->ctl_name || table->procname; table++) {
1629 if (!(de = table->de))
1631 if (de->mode & S_IFDIR) {
1632 if (!table->child) {
1633 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1636 unregister_proc_table(table->child, de);
1638 /* Don't unregister directories which still have entries.. */
1644 * In any case, mark the entry as goner; we'll keep it
1645 * around if it's busy, but we'll know to do nothing with
1646 * its fields. We are under sysctl_lock here.
1650 /* Don't unregister proc entries that are still being used.. */
1651 if (atomic_read(&de->count))
1655 remove_proc_entry(table->procname, root);
1659 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1660 size_t count, loff_t *ppos)
1663 struct proc_dir_entry *de = PDE(file->f_path.dentry->d_inode);
1664 struct ctl_table *table;
1666 ssize_t error = -ENOTDIR;
1668 spin_lock(&sysctl_lock);
1669 if (de && de->data && use_table(de->set)) {
1671 * at that point we know that sysctl was not unregistered
1672 * and won't be until we finish
1674 spin_unlock(&sysctl_lock);
1675 table = (struct ctl_table *) de->data;
1676 if (!table || !table->proc_handler)
1679 op = (write ? 002 : 004);
1680 if (ctl_perm(table, op))
1683 /* careful: calling conventions are nasty here */
1685 error = (*table->proc_handler)(table, write, file,
1690 spin_lock(&sysctl_lock);
1691 unuse_table(de->set);
1693 spin_unlock(&sysctl_lock);
1697 static int proc_opensys(struct inode *inode, struct file *file)
1699 if (file->f_mode & FMODE_WRITE) {
1701 * sysctl entries that are not writable,
1702 * are _NOT_ writable, capabilities or not.
1704 if (!(inode->i_mode & S_IWUSR))
1711 static ssize_t proc_readsys(struct file * file, char __user * buf,
1712 size_t count, loff_t *ppos)
1714 return do_rw_proc(0, file, buf, count, ppos);
1717 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1718 size_t count, loff_t *ppos)
1720 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1723 static int _proc_do_string(void* data, int maxlen, int write,
1724 struct file *filp, void __user *buffer,
1725 size_t *lenp, loff_t *ppos)
1731 if (!data || !maxlen || !*lenp ||
1732 (*ppos && !write)) {
1740 while (len < *lenp) {
1741 if (get_user(c, p++))
1743 if (c == 0 || c == '\n')
1749 if(copy_from_user(data, buffer, len))
1751 ((char *) data)[len] = 0;
1760 if(copy_to_user(buffer, data, len))
1763 if(put_user('\n', ((char __user *) buffer) + len))
1774 * proc_dostring - read a string sysctl
1775 * @table: the sysctl table
1776 * @write: %TRUE if this is a write to the sysctl file
1777 * @filp: the file structure
1778 * @buffer: the user buffer
1779 * @lenp: the size of the user buffer
1780 * @ppos: file position
1782 * Reads/writes a string from/to the user buffer. If the kernel
1783 * buffer provided is not large enough to hold the string, the
1784 * string is truncated. The copied string is %NULL-terminated.
1785 * If the string is being read by the user process, it is copied
1786 * and a newline '\n' is added. It is truncated if the buffer is
1789 * Returns 0 on success.
1791 int proc_dostring(ctl_table *table, int write, struct file *filp,
1792 void __user *buffer, size_t *lenp, loff_t *ppos)
1794 return _proc_do_string(table->data, table->maxlen, write, filp,
1795 buffer, lenp, ppos);
1799 * Special case of dostring for the UTS structure. This has locks
1800 * to observe. Should this be in kernel/sys.c ????
1803 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
1804 void __user *buffer, size_t *lenp, loff_t *ppos)
1808 which = get_uts(table, write);
1809 r = _proc_do_string(which, table->maxlen,write,filp,buffer,lenp, ppos);
1810 put_uts(table, write, which);
1814 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1816 int write, void *data)
1819 *valp = *negp ? -*lvalp : *lvalp;
1824 *lvalp = (unsigned long)-val;
1827 *lvalp = (unsigned long)val;
1833 static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1834 int write, struct file *filp, void __user *buffer,
1835 size_t *lenp, loff_t *ppos,
1836 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1837 int write, void *data),
1840 #define TMPBUFLEN 21
1841 int *i, vleft, first=1, neg, val;
1845 char buf[TMPBUFLEN], *p;
1846 char __user *s = buffer;
1848 if (!tbl_data || !table->maxlen || !*lenp ||
1849 (*ppos && !write)) {
1854 i = (int *) tbl_data;
1855 vleft = table->maxlen / sizeof(*i);
1859 conv = do_proc_dointvec_conv;
1861 for (; left && vleft--; i++, first=0) {
1876 if (len > sizeof(buf) - 1)
1877 len = sizeof(buf) - 1;
1878 if (copy_from_user(buf, s, len))
1882 if (*p == '-' && left > 1) {
1886 if (*p < '0' || *p > '9')
1889 lval = simple_strtoul(p, &p, 0);
1892 if ((len < left) && *p && !isspace(*p))
1899 if (conv(&neg, &lval, i, 1, data))
1906 if (conv(&neg, &lval, i, 0, data))
1909 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1913 if(copy_to_user(s, buf, len))
1920 if (!write && !first && left) {
1921 if(put_user('\n', s))
1928 if (get_user(c, s++))
1943 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1944 void __user *buffer, size_t *lenp, loff_t *ppos,
1945 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1946 int write, void *data),
1949 return __do_proc_dointvec(table->data, table, write, filp,
1950 buffer, lenp, ppos, conv, data);
1954 * proc_dointvec - read a vector of integers
1955 * @table: the sysctl table
1956 * @write: %TRUE if this is a write to the sysctl file
1957 * @filp: the file structure
1958 * @buffer: the user buffer
1959 * @lenp: the size of the user buffer
1960 * @ppos: file position
1962 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1963 * values from/to the user buffer, treated as an ASCII string.
1965 * Returns 0 on success.
1967 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1968 void __user *buffer, size_t *lenp, loff_t *ppos)
1970 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1977 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1979 int write, void *data)
1981 int op = *(int *)data;
1983 int val = *negp ? -*lvalp : *lvalp;
1985 case OP_SET: *valp = val; break;
1986 case OP_AND: *valp &= val; break;
1992 *lvalp = (unsigned long)-val;
1995 *lvalp = (unsigned long)val;
2002 * init may raise the set.
2005 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2006 void __user *buffer, size_t *lenp, loff_t *ppos)
2010 if (!capable(CAP_SYS_MODULE)) {
2014 op = is_init(current) ? OP_SET : OP_AND;
2015 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2016 do_proc_dointvec_bset_conv,&op);
2019 struct do_proc_dointvec_minmax_conv_param {
2024 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2026 int write, void *data)
2028 struct do_proc_dointvec_minmax_conv_param *param = data;
2030 int val = *negp ? -*lvalp : *lvalp;
2031 if ((param->min && *param->min > val) ||
2032 (param->max && *param->max < val))
2039 *lvalp = (unsigned long)-val;
2042 *lvalp = (unsigned long)val;
2049 * proc_dointvec_minmax - read a vector of integers with min/max values
2050 * @table: the sysctl table
2051 * @write: %TRUE if this is a write to the sysctl file
2052 * @filp: the file structure
2053 * @buffer: the user buffer
2054 * @lenp: the size of the user buffer
2055 * @ppos: file position
2057 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2058 * values from/to the user buffer, treated as an ASCII string.
2060 * This routine will ensure the values are within the range specified by
2061 * table->extra1 (min) and table->extra2 (max).
2063 * Returns 0 on success.
2065 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2066 void __user *buffer, size_t *lenp, loff_t *ppos)
2068 struct do_proc_dointvec_minmax_conv_param param = {
2069 .min = (int *) table->extra1,
2070 .max = (int *) table->extra2,
2072 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2073 do_proc_dointvec_minmax_conv, ¶m);
2076 static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
2078 void __user *buffer,
2079 size_t *lenp, loff_t *ppos,
2080 unsigned long convmul,
2081 unsigned long convdiv)
2083 #define TMPBUFLEN 21
2084 unsigned long *i, *min, *max, val;
2085 int vleft, first=1, neg;
2087 char buf[TMPBUFLEN], *p;
2088 char __user *s = buffer;
2090 if (!data || !table->maxlen || !*lenp ||
2091 (*ppos && !write)) {
2096 i = (unsigned long *) data;
2097 min = (unsigned long *) table->extra1;
2098 max = (unsigned long *) table->extra2;
2099 vleft = table->maxlen / sizeof(unsigned long);
2102 for (; left && vleft--; i++, min++, max++, first=0) {
2117 if (len > TMPBUFLEN-1)
2119 if (copy_from_user(buf, s, len))
2123 if (*p == '-' && left > 1) {
2127 if (*p < '0' || *p > '9')
2129 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2131 if ((len < left) && *p && !isspace(*p))
2140 if ((min && val < *min) || (max && val > *max))
2147 sprintf(p, "%lu", convdiv * (*i) / convmul);
2151 if(copy_to_user(s, buf, len))
2158 if (!write && !first && left) {
2159 if(put_user('\n', s))
2166 if (get_user(c, s++))
2181 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2183 void __user *buffer,
2184 size_t *lenp, loff_t *ppos,
2185 unsigned long convmul,
2186 unsigned long convdiv)
2188 return __do_proc_doulongvec_minmax(table->data, table, write,
2189 filp, buffer, lenp, ppos, convmul, convdiv);
2193 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2194 * @table: the sysctl table
2195 * @write: %TRUE if this is a write to the sysctl file
2196 * @filp: the file structure
2197 * @buffer: the user buffer
2198 * @lenp: the size of the user buffer
2199 * @ppos: file position
2201 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2202 * values from/to the user buffer, treated as an ASCII string.
2204 * This routine will ensure the values are within the range specified by
2205 * table->extra1 (min) and table->extra2 (max).
2207 * Returns 0 on success.
2209 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2210 void __user *buffer, size_t *lenp, loff_t *ppos)
2212 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2216 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2217 * @table: the sysctl table
2218 * @write: %TRUE if this is a write to the sysctl file
2219 * @filp: the file structure
2220 * @buffer: the user buffer
2221 * @lenp: the size of the user buffer
2222 * @ppos: file position
2224 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2225 * values from/to the user buffer, treated as an ASCII string. The values
2226 * are treated as milliseconds, and converted to jiffies when they are stored.
2228 * This routine will ensure the values are within the range specified by
2229 * table->extra1 (min) and table->extra2 (max).
2231 * Returns 0 on success.
2233 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2235 void __user *buffer,
2236 size_t *lenp, loff_t *ppos)
2238 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2239 lenp, ppos, HZ, 1000l);
2243 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2245 int write, void *data)
2248 if (*lvalp > LONG_MAX / HZ)
2250 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2256 lval = (unsigned long)-val;
2259 lval = (unsigned long)val;
2266 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2268 int write, void *data)
2271 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2273 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2279 lval = (unsigned long)-val;
2282 lval = (unsigned long)val;
2284 *lvalp = jiffies_to_clock_t(lval);
2289 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2291 int write, void *data)
2294 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2300 lval = (unsigned long)-val;
2303 lval = (unsigned long)val;
2305 *lvalp = jiffies_to_msecs(lval);
2311 * proc_dointvec_jiffies - read a vector of integers as seconds
2312 * @table: the sysctl table
2313 * @write: %TRUE if this is a write to the sysctl file
2314 * @filp: the file structure
2315 * @buffer: the user buffer
2316 * @lenp: the size of the user buffer
2317 * @ppos: file position
2319 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2320 * values from/to the user buffer, treated as an ASCII string.
2321 * The values read are assumed to be in seconds, and are converted into
2324 * Returns 0 on success.
2326 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2327 void __user *buffer, size_t *lenp, loff_t *ppos)
2329 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2330 do_proc_dointvec_jiffies_conv,NULL);
2334 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2335 * @table: the sysctl table
2336 * @write: %TRUE if this is a write to the sysctl file
2337 * @filp: the file structure
2338 * @buffer: the user buffer
2339 * @lenp: the size of the user buffer
2340 * @ppos: pointer to the file position
2342 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2343 * values from/to the user buffer, treated as an ASCII string.
2344 * The values read are assumed to be in 1/USER_HZ seconds, and
2345 * are converted into jiffies.
2347 * Returns 0 on success.
2349 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2350 void __user *buffer, size_t *lenp, loff_t *ppos)
2352 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2353 do_proc_dointvec_userhz_jiffies_conv,NULL);
2357 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2358 * @table: the sysctl table
2359 * @write: %TRUE if this is a write to the sysctl file
2360 * @filp: the file structure
2361 * @buffer: the user buffer
2362 * @lenp: the size of the user buffer
2363 * @ppos: file position
2364 * @ppos: the current position in the file
2366 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2367 * values from/to the user buffer, treated as an ASCII string.
2368 * The values read are assumed to be in 1/1000 seconds, and
2369 * are converted into jiffies.
2371 * Returns 0 on success.
2373 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2374 void __user *buffer, size_t *lenp, loff_t *ppos)
2376 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2377 do_proc_dointvec_ms_jiffies_conv, NULL);
2380 #ifdef CONFIG_SYSVIPC
2381 static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
2382 void __user *buffer, size_t *lenp, loff_t *ppos)
2385 which = get_ipc(table, write);
2386 return __do_proc_dointvec(which, table, write, filp, buffer,
2387 lenp, ppos, NULL, NULL);
2390 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
2391 struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
2394 which = get_ipc(table, write);
2395 return __do_proc_doulongvec_minmax(which, table, write, filp, buffer,
2396 lenp, ppos, 1l, 1l);
2401 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2402 void __user *buffer, size_t *lenp, loff_t *ppos)
2404 struct pid *new_pid;
2408 tmp = pid_nr(cad_pid);
2410 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2411 lenp, ppos, NULL, NULL);
2415 new_pid = find_get_pid(tmp);
2419 put_pid(xchg(&cad_pid, new_pid));
2423 #else /* CONFIG_PROC_FS */
2425 int proc_dostring(ctl_table *table, int write, struct file *filp,
2426 void __user *buffer, size_t *lenp, loff_t *ppos)
2431 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
2432 void __user *buffer, size_t *lenp, loff_t *ppos)
2437 #ifdef CONFIG_SYSVIPC
2438 static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2439 void __user *buffer, size_t *lenp, loff_t *ppos)
2443 static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
2444 void __user *buffer, size_t *lenp, loff_t *ppos)
2448 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
2449 struct file *filp, void __user *buffer,
2450 size_t *lenp, loff_t *ppos)
2456 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2457 void __user *buffer, size_t *lenp, loff_t *ppos)
2462 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2463 void __user *buffer, size_t *lenp, loff_t *ppos)
2468 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2469 void __user *buffer, size_t *lenp, loff_t *ppos)
2474 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2475 void __user *buffer, size_t *lenp, loff_t *ppos)
2480 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2481 void __user *buffer, size_t *lenp, loff_t *ppos)
2486 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2487 void __user *buffer, size_t *lenp, loff_t *ppos)
2492 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2493 void __user *buffer, size_t *lenp, loff_t *ppos)
2498 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2500 void __user *buffer,
2501 size_t *lenp, loff_t *ppos)
2507 #endif /* CONFIG_PROC_FS */
2510 #ifdef CONFIG_SYSCTL_SYSCALL
2512 * General sysctl support routines
2515 /* The generic string strategy routine: */
2516 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2517 void __user *oldval, size_t __user *oldlenp,
2518 void __user *newval, size_t newlen)
2520 if (!table->data || !table->maxlen)
2523 if (oldval && oldlenp) {
2525 if (get_user(bufsize, oldlenp))
2528 size_t len = strlen(table->data), copied;
2530 /* This shouldn't trigger for a well-formed sysctl */
2531 if (len > table->maxlen)
2532 len = table->maxlen;
2534 /* Copy up to a max of bufsize-1 bytes of the string */
2535 copied = (len >= bufsize) ? bufsize - 1 : len;
2537 if (copy_to_user(oldval, table->data, copied) ||
2538 put_user(0, (char __user *)(oldval + copied)))
2540 if (put_user(len, oldlenp))
2544 if (newval && newlen) {
2545 size_t len = newlen;
2546 if (len > table->maxlen)
2547 len = table->maxlen;
2548 if(copy_from_user(table->data, newval, len))
2550 if (len == table->maxlen)
2552 ((char *) table->data)[len] = 0;
2558 * This function makes sure that all of the integers in the vector
2559 * are between the minimum and maximum values given in the arrays
2560 * table->extra1 and table->extra2, respectively.
2562 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2563 void __user *oldval, size_t __user *oldlenp,
2564 void __user *newval, size_t newlen)
2567 if (newval && newlen) {
2568 int __user *vec = (int __user *) newval;
2569 int *min = (int *) table->extra1;
2570 int *max = (int *) table->extra2;
2574 if (newlen % sizeof(int) != 0)
2577 if (!table->extra1 && !table->extra2)
2580 if (newlen > table->maxlen)
2581 newlen = table->maxlen;
2582 length = newlen / sizeof(int);
2584 for (i = 0; i < length; i++) {
2586 if (get_user(value, vec + i))
2588 if (min && value < min[i])
2590 if (max && value > max[i])
2597 /* Strategy function to convert jiffies to seconds */
2598 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2599 void __user *oldval, size_t __user *oldlenp,
2600 void __user *newval, size_t newlen)
2605 if (get_user(olen, oldlenp))
2607 if (olen!=sizeof(int))
2610 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2611 (oldlenp && put_user(sizeof(int),oldlenp)))
2614 if (newval && newlen) {
2616 if (newlen != sizeof(int))
2618 if (get_user(new, (int __user *)newval))
2620 *(int *)(table->data) = new*HZ;
2625 /* Strategy function to convert jiffies to seconds */
2626 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2627 void __user *oldval, size_t __user *oldlenp,
2628 void __user *newval, size_t newlen)
2633 if (get_user(olen, oldlenp))
2635 if (olen!=sizeof(int))
2638 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2639 (oldlenp && put_user(sizeof(int),oldlenp)))
2642 if (newval && newlen) {
2644 if (newlen != sizeof(int))
2646 if (get_user(new, (int __user *)newval))
2648 *(int *)(table->data) = msecs_to_jiffies(new);
2654 /* The generic string strategy routine: */
2655 static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2656 void __user *oldval, size_t __user *oldlenp,
2657 void __user *newval, size_t newlen)
2659 struct ctl_table uts_table;
2661 write = newval && newlen;
2662 memcpy(&uts_table, table, sizeof(uts_table));
2663 uts_table.data = get_uts(table, write);
2664 r = sysctl_string(&uts_table, name, nlen,
2665 oldval, oldlenp, newval, newlen);
2666 put_uts(table, write, uts_table.data);
2670 #ifdef CONFIG_SYSVIPC
2671 /* The generic sysctl ipc data routine. */
2672 static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
2673 void __user *oldval, size_t __user *oldlenp,
2674 void __user *newval, size_t newlen)
2679 /* Get out of I don't have a variable */
2680 if (!table->data || !table->maxlen)
2683 data = get_ipc(table, 1);
2687 if (oldval && oldlenp) {
2688 if (get_user(len, oldlenp))
2691 if (len > table->maxlen)
2692 len = table->maxlen;
2693 if (copy_to_user(oldval, data, len))
2695 if (put_user(len, oldlenp))
2700 if (newval && newlen) {
2701 if (newlen > table->maxlen)
2702 newlen = table->maxlen;
2704 if (copy_from_user(data, newval, newlen))
2711 #else /* CONFIG_SYSCTL_SYSCALL */
2714 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2716 static int msg_count;
2717 struct __sysctl_args tmp;
2718 int name[CTL_MAXNAME];
2721 /* Read in the sysctl name for better debug message logging */
2722 if (copy_from_user(&tmp, args, sizeof(tmp)))
2724 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2726 for (i = 0; i < tmp.nlen; i++)
2727 if (get_user(name[i], tmp.name + i))
2730 /* Ignore accesses to kernel.version */
2731 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2734 if (msg_count < 5) {
2737 "warning: process `%s' used the removed sysctl "
2738 "system call with ", current->comm);
2739 for (i = 0; i < tmp.nlen; i++)
2740 printk("%d.", name[i]);
2747 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2748 void __user *oldval, size_t __user *oldlenp,
2749 void __user *newval, size_t newlen)
2754 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2755 void __user *oldval, size_t __user *oldlenp,
2756 void __user *newval, size_t newlen)
2761 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2762 void __user *oldval, size_t __user *oldlenp,
2763 void __user *newval, size_t newlen)
2768 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2769 void __user *oldval, size_t __user *oldlenp,
2770 void __user *newval, size_t newlen)
2775 static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2776 void __user *oldval, size_t __user *oldlenp,
2777 void __user *newval, size_t newlen)
2781 static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
2782 void __user *oldval, size_t __user *oldlenp,
2783 void __user *newval, size_t newlen)
2787 #endif /* CONFIG_SYSCTL_SYSCALL */
2790 * No sense putting this after each symbol definition, twice,
2791 * exception granted :-)
2793 EXPORT_SYMBOL(proc_dointvec);
2794 EXPORT_SYMBOL(proc_dointvec_jiffies);
2795 EXPORT_SYMBOL(proc_dointvec_minmax);
2796 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2797 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2798 EXPORT_SYMBOL(proc_dostring);
2799 EXPORT_SYMBOL(proc_doulongvec_minmax);
2800 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2801 EXPORT_SYMBOL(register_sysctl_table);
2802 EXPORT_SYMBOL(sysctl_intvec);
2803 EXPORT_SYMBOL(sysctl_jiffies);
2804 EXPORT_SYMBOL(sysctl_ms_jiffies);
2805 EXPORT_SYMBOL(sysctl_string);
2806 EXPORT_SYMBOL(unregister_sysctl_table);