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 #ifdef CONFIG_PROC_SYSCTL
141 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
142 void __user *buffer, size_t *lenp, loff_t *ppos);
145 static ctl_table root_table[];
146 static struct ctl_table_header root_table_header =
147 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
149 static ctl_table kern_table[];
150 static ctl_table vm_table[];
151 static ctl_table fs_table[];
152 static ctl_table debug_table[];
153 static ctl_table dev_table[];
154 extern ctl_table random_table[];
155 #ifdef CONFIG_UNIX98_PTYS
156 extern ctl_table pty_table[];
158 #ifdef CONFIG_INOTIFY_USER
159 extern ctl_table inotify_table[];
162 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
163 int sysctl_legacy_va_layout;
166 static void *get_uts(ctl_table *table, int write)
168 char *which = table->data;
170 struct uts_namespace *uts_ns = current->nsproxy->uts_ns;
171 which = (which - (char *)&init_uts_ns) + (char *)uts_ns;
176 down_write(&uts_sem);
180 static void put_uts(ctl_table *table, int write, void *which)
188 /* /proc declarations: */
190 #ifdef CONFIG_PROC_SYSCTL
192 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
193 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
194 static int proc_opensys(struct inode *, struct file *);
196 const struct file_operations proc_sys_file_operations = {
197 .open = proc_opensys,
198 .read = proc_readsys,
199 .write = proc_writesys,
202 extern struct proc_dir_entry *proc_sys_root;
204 static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
205 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
208 /* The default sysctl tables: */
210 static ctl_table root_table[] = {
212 .ctl_name = CTL_KERN,
213 .procname = "kernel",
238 .ctl_name = CTL_DEBUG,
241 .child = debug_table,
253 static ctl_table kern_table[] = {
255 .ctl_name = KERN_OSTYPE,
256 .procname = "ostype",
257 .data = init_uts_ns.name.sysname,
258 .maxlen = sizeof(init_uts_ns.name.sysname),
260 .proc_handler = &proc_do_uts_string,
261 .strategy = &sysctl_string,
264 .ctl_name = KERN_OSRELEASE,
265 .procname = "osrelease",
266 .data = init_uts_ns.name.release,
267 .maxlen = sizeof(init_uts_ns.name.release),
269 .proc_handler = &proc_do_uts_string,
270 .strategy = &sysctl_string,
273 .ctl_name = KERN_VERSION,
274 .procname = "version",
275 .data = init_uts_ns.name.version,
276 .maxlen = sizeof(init_uts_ns.name.version),
278 .proc_handler = &proc_do_uts_string,
279 .strategy = &sysctl_string,
282 .ctl_name = KERN_NODENAME,
283 .procname = "hostname",
284 .data = init_uts_ns.name.nodename,
285 .maxlen = sizeof(init_uts_ns.name.nodename),
287 .proc_handler = &proc_do_uts_string,
288 .strategy = &sysctl_string,
291 .ctl_name = KERN_DOMAINNAME,
292 .procname = "domainname",
293 .data = init_uts_ns.name.domainname,
294 .maxlen = sizeof(init_uts_ns.name.domainname),
296 .proc_handler = &proc_do_uts_string,
297 .strategy = &sysctl_string,
300 .ctl_name = KERN_PANIC,
302 .data = &panic_timeout,
303 .maxlen = sizeof(int),
305 .proc_handler = &proc_dointvec,
308 .ctl_name = KERN_CORE_USES_PID,
309 .procname = "core_uses_pid",
310 .data = &core_uses_pid,
311 .maxlen = sizeof(int),
313 .proc_handler = &proc_dointvec,
316 .ctl_name = KERN_CORE_PATTERN,
317 .procname = "core_pattern",
318 .data = core_pattern,
321 .proc_handler = &proc_dostring,
322 .strategy = &sysctl_string,
325 .ctl_name = KERN_TAINTED,
326 .procname = "tainted",
328 .maxlen = sizeof(int),
330 .proc_handler = &proc_dointvec,
333 .ctl_name = KERN_CAP_BSET,
334 .procname = "cap-bound",
336 .maxlen = sizeof(kernel_cap_t),
338 .proc_handler = &proc_dointvec_bset,
340 #ifdef CONFIG_BLK_DEV_INITRD
342 .ctl_name = KERN_REALROOTDEV,
343 .procname = "real-root-dev",
344 .data = &real_root_dev,
345 .maxlen = sizeof(int),
347 .proc_handler = &proc_dointvec,
352 .ctl_name = KERN_SPARC_REBOOT,
353 .procname = "reboot-cmd",
354 .data = reboot_command,
357 .proc_handler = &proc_dostring,
358 .strategy = &sysctl_string,
361 .ctl_name = KERN_SPARC_STOP_A,
362 .procname = "stop-a",
363 .data = &stop_a_enabled,
364 .maxlen = sizeof (int),
366 .proc_handler = &proc_dointvec,
369 .ctl_name = KERN_SPARC_SCONS_PWROFF,
370 .procname = "scons-poweroff",
371 .data = &scons_pwroff,
372 .maxlen = sizeof (int),
374 .proc_handler = &proc_dointvec,
379 .ctl_name = KERN_HPPA_PWRSW,
380 .procname = "soft-power",
381 .data = &pwrsw_enabled,
382 .maxlen = sizeof (int),
384 .proc_handler = &proc_dointvec,
387 .ctl_name = KERN_HPPA_UNALIGNED,
388 .procname = "unaligned-trap",
389 .data = &unaligned_enabled,
390 .maxlen = sizeof (int),
392 .proc_handler = &proc_dointvec,
396 .ctl_name = KERN_CTLALTDEL,
397 .procname = "ctrl-alt-del",
399 .maxlen = sizeof(int),
401 .proc_handler = &proc_dointvec,
404 .ctl_name = KERN_PRINTK,
405 .procname = "printk",
406 .data = &console_loglevel,
407 .maxlen = 4*sizeof(int),
409 .proc_handler = &proc_dointvec,
413 .ctl_name = KERN_MODPROBE,
414 .procname = "modprobe",
415 .data = &modprobe_path,
416 .maxlen = KMOD_PATH_LEN,
418 .proc_handler = &proc_dostring,
419 .strategy = &sysctl_string,
422 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
424 .ctl_name = KERN_HOTPLUG,
425 .procname = "hotplug",
426 .data = &uevent_helper,
427 .maxlen = UEVENT_HELPER_PATH_LEN,
429 .proc_handler = &proc_dostring,
430 .strategy = &sysctl_string,
433 #ifdef CONFIG_CHR_DEV_SG
435 .ctl_name = KERN_SG_BIG_BUFF,
436 .procname = "sg-big-buff",
437 .data = &sg_big_buff,
438 .maxlen = sizeof (int),
440 .proc_handler = &proc_dointvec,
443 #ifdef CONFIG_BSD_PROCESS_ACCT
445 .ctl_name = KERN_ACCT,
448 .maxlen = 3*sizeof(int),
450 .proc_handler = &proc_dointvec,
453 #ifdef CONFIG_SYSVIPC
455 .ctl_name = KERN_SHMMAX,
456 .procname = "shmmax",
458 .maxlen = sizeof (size_t),
460 .proc_handler = &proc_do_ipc_string,
463 .ctl_name = KERN_SHMALL,
464 .procname = "shmall",
466 .maxlen = sizeof (size_t),
468 .proc_handler = &proc_do_ipc_string,
471 .ctl_name = KERN_SHMMNI,
472 .procname = "shmmni",
474 .maxlen = sizeof (int),
476 .proc_handler = &proc_do_ipc_string,
479 .ctl_name = KERN_MSGMAX,
480 .procname = "msgmax",
482 .maxlen = sizeof (int),
484 .proc_handler = &proc_do_ipc_string,
487 .ctl_name = KERN_MSGMNI,
488 .procname = "msgmni",
490 .maxlen = sizeof (int),
492 .proc_handler = &proc_do_ipc_string,
495 .ctl_name = KERN_MSGMNB,
496 .procname = "msgmnb",
498 .maxlen = sizeof (int),
500 .proc_handler = &proc_do_ipc_string,
503 .ctl_name = KERN_SEM,
506 .maxlen = 4*sizeof (int),
508 .proc_handler = &proc_do_ipc_string,
511 #ifdef CONFIG_MAGIC_SYSRQ
513 .ctl_name = KERN_SYSRQ,
515 .data = &sysrq_enabled,
516 .maxlen = sizeof (int),
518 .proc_handler = &proc_dointvec,
521 #ifdef CONFIG_PROC_SYSCTL
523 .ctl_name = KERN_CADPID,
524 .procname = "cad_pid",
526 .maxlen = sizeof (int),
528 .proc_handler = &proc_do_cad_pid,
532 .ctl_name = KERN_MAX_THREADS,
533 .procname = "threads-max",
534 .data = &max_threads,
535 .maxlen = sizeof(int),
537 .proc_handler = &proc_dointvec,
540 .ctl_name = KERN_RANDOM,
541 .procname = "random",
543 .child = random_table,
545 #ifdef CONFIG_UNIX98_PTYS
547 .ctl_name = KERN_PTY,
554 .ctl_name = KERN_OVERFLOWUID,
555 .procname = "overflowuid",
556 .data = &overflowuid,
557 .maxlen = sizeof(int),
559 .proc_handler = &proc_dointvec_minmax,
560 .strategy = &sysctl_intvec,
561 .extra1 = &minolduid,
562 .extra2 = &maxolduid,
565 .ctl_name = KERN_OVERFLOWGID,
566 .procname = "overflowgid",
567 .data = &overflowgid,
568 .maxlen = sizeof(int),
570 .proc_handler = &proc_dointvec_minmax,
571 .strategy = &sysctl_intvec,
572 .extra1 = &minolduid,
573 .extra2 = &maxolduid,
576 #ifdef CONFIG_MATHEMU
578 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
579 .procname = "ieee_emulation_warnings",
580 .data = &sysctl_ieee_emulation_warnings,
581 .maxlen = sizeof(int),
583 .proc_handler = &proc_dointvec,
586 #ifdef CONFIG_NO_IDLE_HZ
588 .ctl_name = KERN_HZ_TIMER,
589 .procname = "hz_timer",
590 .data = &sysctl_hz_timer,
591 .maxlen = sizeof(int),
593 .proc_handler = &proc_dointvec,
597 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
598 .procname = "userprocess_debug",
599 .data = &sysctl_userprocess_debug,
600 .maxlen = sizeof(int),
602 .proc_handler = &proc_dointvec,
606 .ctl_name = KERN_PIDMAX,
607 .procname = "pid_max",
609 .maxlen = sizeof (int),
611 .proc_handler = &proc_dointvec_minmax,
612 .strategy = sysctl_intvec,
613 .extra1 = &pid_max_min,
614 .extra2 = &pid_max_max,
617 .ctl_name = KERN_PANIC_ON_OOPS,
618 .procname = "panic_on_oops",
619 .data = &panic_on_oops,
620 .maxlen = sizeof(int),
622 .proc_handler = &proc_dointvec,
625 .ctl_name = KERN_PRINTK_RATELIMIT,
626 .procname = "printk_ratelimit",
627 .data = &printk_ratelimit_jiffies,
628 .maxlen = sizeof(int),
630 .proc_handler = &proc_dointvec_jiffies,
631 .strategy = &sysctl_jiffies,
634 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
635 .procname = "printk_ratelimit_burst",
636 .data = &printk_ratelimit_burst,
637 .maxlen = sizeof(int),
639 .proc_handler = &proc_dointvec,
642 .ctl_name = KERN_NGROUPS_MAX,
643 .procname = "ngroups_max",
644 .data = &ngroups_max,
645 .maxlen = sizeof (int),
647 .proc_handler = &proc_dointvec,
649 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
651 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
652 .procname = "unknown_nmi_panic",
653 .data = &unknown_nmi_panic,
654 .maxlen = sizeof (int),
656 .proc_handler = &proc_dointvec,
659 .ctl_name = KERN_NMI_WATCHDOG,
660 .procname = "nmi_watchdog",
661 .data = &nmi_watchdog_enabled,
662 .maxlen = sizeof (int),
664 .proc_handler = &proc_nmi_enabled,
667 #if defined(CONFIG_X86)
669 .ctl_name = KERN_PANIC_ON_NMI,
670 .procname = "panic_on_unrecovered_nmi",
671 .data = &panic_on_unrecovered_nmi,
672 .maxlen = sizeof(int),
674 .proc_handler = &proc_dointvec,
677 .ctl_name = KERN_BOOTLOADER_TYPE,
678 .procname = "bootloader_type",
679 .data = &bootloader_type,
680 .maxlen = sizeof (int),
682 .proc_handler = &proc_dointvec,
685 .ctl_name = CTL_UNNUMBERED,
686 .procname = "kstack_depth_to_print",
687 .data = &kstack_depth_to_print,
688 .maxlen = sizeof(int),
690 .proc_handler = &proc_dointvec,
693 #if defined(CONFIG_MMU)
695 .ctl_name = KERN_RANDOMIZE,
696 .procname = "randomize_va_space",
697 .data = &randomize_va_space,
698 .maxlen = sizeof(int),
700 .proc_handler = &proc_dointvec,
703 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
705 .ctl_name = KERN_SPIN_RETRY,
706 .procname = "spin_retry",
708 .maxlen = sizeof (int),
710 .proc_handler = &proc_dointvec,
713 #ifdef CONFIG_ACPI_SLEEP
715 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
716 .procname = "acpi_video_flags",
717 .data = &acpi_video_flags,
718 .maxlen = sizeof (unsigned long),
720 .proc_handler = &proc_doulongvec_minmax,
725 .ctl_name = KERN_IA64_UNALIGNED,
726 .procname = "ignore-unaligned-usertrap",
727 .data = &no_unaligned_warning,
728 .maxlen = sizeof (int),
730 .proc_handler = &proc_dointvec,
735 .ctl_name = KERN_COMPAT_LOG,
736 .procname = "compat-log",
738 .maxlen = sizeof (int),
740 .proc_handler = &proc_dointvec,
743 #ifdef CONFIG_RT_MUTEXES
745 .ctl_name = KERN_MAX_LOCK_DEPTH,
746 .procname = "max_lock_depth",
747 .data = &max_lock_depth,
748 .maxlen = sizeof(int),
750 .proc_handler = &proc_dointvec,
757 /* Constants for minimum and maximum testing in vm_table.
758 We use these as one-element integer vectors. */
760 static int one_hundred = 100;
763 static ctl_table vm_table[] = {
765 .ctl_name = VM_OVERCOMMIT_MEMORY,
766 .procname = "overcommit_memory",
767 .data = &sysctl_overcommit_memory,
768 .maxlen = sizeof(sysctl_overcommit_memory),
770 .proc_handler = &proc_dointvec,
773 .ctl_name = VM_PANIC_ON_OOM,
774 .procname = "panic_on_oom",
775 .data = &sysctl_panic_on_oom,
776 .maxlen = sizeof(sysctl_panic_on_oom),
778 .proc_handler = &proc_dointvec,
781 .ctl_name = VM_OVERCOMMIT_RATIO,
782 .procname = "overcommit_ratio",
783 .data = &sysctl_overcommit_ratio,
784 .maxlen = sizeof(sysctl_overcommit_ratio),
786 .proc_handler = &proc_dointvec,
789 .ctl_name = VM_PAGE_CLUSTER,
790 .procname = "page-cluster",
791 .data = &page_cluster,
792 .maxlen = sizeof(int),
794 .proc_handler = &proc_dointvec,
797 .ctl_name = VM_DIRTY_BACKGROUND,
798 .procname = "dirty_background_ratio",
799 .data = &dirty_background_ratio,
800 .maxlen = sizeof(dirty_background_ratio),
802 .proc_handler = &proc_dointvec_minmax,
803 .strategy = &sysctl_intvec,
805 .extra2 = &one_hundred,
808 .ctl_name = VM_DIRTY_RATIO,
809 .procname = "dirty_ratio",
810 .data = &vm_dirty_ratio,
811 .maxlen = sizeof(vm_dirty_ratio),
813 .proc_handler = &proc_dointvec_minmax,
814 .strategy = &sysctl_intvec,
816 .extra2 = &one_hundred,
819 .ctl_name = VM_DIRTY_WB_CS,
820 .procname = "dirty_writeback_centisecs",
821 .data = &dirty_writeback_interval,
822 .maxlen = sizeof(dirty_writeback_interval),
824 .proc_handler = &dirty_writeback_centisecs_handler,
827 .ctl_name = VM_DIRTY_EXPIRE_CS,
828 .procname = "dirty_expire_centisecs",
829 .data = &dirty_expire_interval,
830 .maxlen = sizeof(dirty_expire_interval),
832 .proc_handler = &proc_dointvec_userhz_jiffies,
835 .ctl_name = VM_NR_PDFLUSH_THREADS,
836 .procname = "nr_pdflush_threads",
837 .data = &nr_pdflush_threads,
838 .maxlen = sizeof nr_pdflush_threads,
839 .mode = 0444 /* read-only*/,
840 .proc_handler = &proc_dointvec,
843 .ctl_name = VM_SWAPPINESS,
844 .procname = "swappiness",
845 .data = &vm_swappiness,
846 .maxlen = sizeof(vm_swappiness),
848 .proc_handler = &proc_dointvec_minmax,
849 .strategy = &sysctl_intvec,
851 .extra2 = &one_hundred,
853 #ifdef CONFIG_HUGETLB_PAGE
855 .ctl_name = VM_HUGETLB_PAGES,
856 .procname = "nr_hugepages",
857 .data = &max_huge_pages,
858 .maxlen = sizeof(unsigned long),
860 .proc_handler = &hugetlb_sysctl_handler,
861 .extra1 = (void *)&hugetlb_zero,
862 .extra2 = (void *)&hugetlb_infinity,
865 .ctl_name = VM_HUGETLB_GROUP,
866 .procname = "hugetlb_shm_group",
867 .data = &sysctl_hugetlb_shm_group,
868 .maxlen = sizeof(gid_t),
870 .proc_handler = &proc_dointvec,
874 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
875 .procname = "lowmem_reserve_ratio",
876 .data = &sysctl_lowmem_reserve_ratio,
877 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
879 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
880 .strategy = &sysctl_intvec,
883 .ctl_name = VM_DROP_PAGECACHE,
884 .procname = "drop_caches",
885 .data = &sysctl_drop_caches,
886 .maxlen = sizeof(int),
888 .proc_handler = drop_caches_sysctl_handler,
889 .strategy = &sysctl_intvec,
892 .ctl_name = VM_MIN_FREE_KBYTES,
893 .procname = "min_free_kbytes",
894 .data = &min_free_kbytes,
895 .maxlen = sizeof(min_free_kbytes),
897 .proc_handler = &min_free_kbytes_sysctl_handler,
898 .strategy = &sysctl_intvec,
902 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
903 .procname = "percpu_pagelist_fraction",
904 .data = &percpu_pagelist_fraction,
905 .maxlen = sizeof(percpu_pagelist_fraction),
907 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
908 .strategy = &sysctl_intvec,
909 .extra1 = &min_percpu_pagelist_fract,
913 .ctl_name = VM_MAX_MAP_COUNT,
914 .procname = "max_map_count",
915 .data = &sysctl_max_map_count,
916 .maxlen = sizeof(sysctl_max_map_count),
918 .proc_handler = &proc_dointvec
922 .ctl_name = VM_LAPTOP_MODE,
923 .procname = "laptop_mode",
924 .data = &laptop_mode,
925 .maxlen = sizeof(laptop_mode),
927 .proc_handler = &proc_dointvec_jiffies,
928 .strategy = &sysctl_jiffies,
931 .ctl_name = VM_BLOCK_DUMP,
932 .procname = "block_dump",
934 .maxlen = sizeof(block_dump),
936 .proc_handler = &proc_dointvec,
937 .strategy = &sysctl_intvec,
941 .ctl_name = VM_VFS_CACHE_PRESSURE,
942 .procname = "vfs_cache_pressure",
943 .data = &sysctl_vfs_cache_pressure,
944 .maxlen = sizeof(sysctl_vfs_cache_pressure),
946 .proc_handler = &proc_dointvec,
947 .strategy = &sysctl_intvec,
950 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
952 .ctl_name = VM_LEGACY_VA_LAYOUT,
953 .procname = "legacy_va_layout",
954 .data = &sysctl_legacy_va_layout,
955 .maxlen = sizeof(sysctl_legacy_va_layout),
957 .proc_handler = &proc_dointvec,
958 .strategy = &sysctl_intvec,
964 .ctl_name = VM_ZONE_RECLAIM_MODE,
965 .procname = "zone_reclaim_mode",
966 .data = &zone_reclaim_mode,
967 .maxlen = sizeof(zone_reclaim_mode),
969 .proc_handler = &proc_dointvec,
970 .strategy = &sysctl_intvec,
974 .ctl_name = VM_MIN_UNMAPPED,
975 .procname = "min_unmapped_ratio",
976 .data = &sysctl_min_unmapped_ratio,
977 .maxlen = sizeof(sysctl_min_unmapped_ratio),
979 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
980 .strategy = &sysctl_intvec,
982 .extra2 = &one_hundred,
985 .ctl_name = VM_MIN_SLAB,
986 .procname = "min_slab_ratio",
987 .data = &sysctl_min_slab_ratio,
988 .maxlen = sizeof(sysctl_min_slab_ratio),
990 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
991 .strategy = &sysctl_intvec,
993 .extra2 = &one_hundred,
998 .ctl_name = VM_VDSO_ENABLED,
999 .procname = "vdso_enabled",
1000 .data = &vdso_enabled,
1001 .maxlen = sizeof(vdso_enabled),
1003 .proc_handler = &proc_dointvec,
1004 .strategy = &sysctl_intvec,
1011 static ctl_table fs_table[] = {
1013 .ctl_name = FS_NRINODE,
1014 .procname = "inode-nr",
1015 .data = &inodes_stat,
1016 .maxlen = 2*sizeof(int),
1018 .proc_handler = &proc_dointvec,
1021 .ctl_name = FS_STATINODE,
1022 .procname = "inode-state",
1023 .data = &inodes_stat,
1024 .maxlen = 7*sizeof(int),
1026 .proc_handler = &proc_dointvec,
1029 .ctl_name = FS_NRFILE,
1030 .procname = "file-nr",
1031 .data = &files_stat,
1032 .maxlen = 3*sizeof(int),
1034 .proc_handler = &proc_nr_files,
1037 .ctl_name = FS_MAXFILE,
1038 .procname = "file-max",
1039 .data = &files_stat.max_files,
1040 .maxlen = sizeof(int),
1042 .proc_handler = &proc_dointvec,
1045 .ctl_name = FS_DENTRY,
1046 .procname = "dentry-state",
1047 .data = &dentry_stat,
1048 .maxlen = 6*sizeof(int),
1050 .proc_handler = &proc_dointvec,
1053 .ctl_name = FS_OVERFLOWUID,
1054 .procname = "overflowuid",
1055 .data = &fs_overflowuid,
1056 .maxlen = sizeof(int),
1058 .proc_handler = &proc_dointvec_minmax,
1059 .strategy = &sysctl_intvec,
1060 .extra1 = &minolduid,
1061 .extra2 = &maxolduid,
1064 .ctl_name = FS_OVERFLOWGID,
1065 .procname = "overflowgid",
1066 .data = &fs_overflowgid,
1067 .maxlen = sizeof(int),
1069 .proc_handler = &proc_dointvec_minmax,
1070 .strategy = &sysctl_intvec,
1071 .extra1 = &minolduid,
1072 .extra2 = &maxolduid,
1075 .ctl_name = FS_LEASES,
1076 .procname = "leases-enable",
1077 .data = &leases_enable,
1078 .maxlen = sizeof(int),
1080 .proc_handler = &proc_dointvec,
1082 #ifdef CONFIG_DNOTIFY
1084 .ctl_name = FS_DIR_NOTIFY,
1085 .procname = "dir-notify-enable",
1086 .data = &dir_notify_enable,
1087 .maxlen = sizeof(int),
1089 .proc_handler = &proc_dointvec,
1094 .ctl_name = FS_LEASE_TIME,
1095 .procname = "lease-break-time",
1096 .data = &lease_break_time,
1097 .maxlen = sizeof(int),
1099 .proc_handler = &proc_dointvec,
1102 .ctl_name = FS_AIO_NR,
1103 .procname = "aio-nr",
1105 .maxlen = sizeof(aio_nr),
1107 .proc_handler = &proc_doulongvec_minmax,
1110 .ctl_name = FS_AIO_MAX_NR,
1111 .procname = "aio-max-nr",
1112 .data = &aio_max_nr,
1113 .maxlen = sizeof(aio_max_nr),
1115 .proc_handler = &proc_doulongvec_minmax,
1117 #ifdef CONFIG_INOTIFY_USER
1119 .ctl_name = FS_INOTIFY,
1120 .procname = "inotify",
1122 .child = inotify_table,
1127 .ctl_name = KERN_SETUID_DUMPABLE,
1128 .procname = "suid_dumpable",
1129 .data = &suid_dumpable,
1130 .maxlen = sizeof(int),
1132 .proc_handler = &proc_dointvec,
1137 static ctl_table debug_table[] = {
1141 static ctl_table dev_table[] = {
1145 extern void init_irq_proc (void);
1147 static DEFINE_SPINLOCK(sysctl_lock);
1149 /* called under sysctl_lock */
1150 static int use_table(struct ctl_table_header *p)
1152 if (unlikely(p->unregistering))
1158 /* called under sysctl_lock */
1159 static void unuse_table(struct ctl_table_header *p)
1162 if (unlikely(p->unregistering))
1163 complete(p->unregistering);
1166 /* called under sysctl_lock, will reacquire if has to wait */
1167 static void start_unregistering(struct ctl_table_header *p)
1170 * if p->used is 0, nobody will ever touch that entry again;
1171 * we'll eliminate all paths to it before dropping sysctl_lock
1173 if (unlikely(p->used)) {
1174 struct completion wait;
1175 init_completion(&wait);
1176 p->unregistering = &wait;
1177 spin_unlock(&sysctl_lock);
1178 wait_for_completion(&wait);
1179 spin_lock(&sysctl_lock);
1182 * do not remove from the list until nobody holds it; walking the
1183 * list in do_sysctl() relies on that.
1185 list_del_init(&p->ctl_entry);
1188 void __init sysctl_init(void)
1190 #ifdef CONFIG_PROC_SYSCTL
1191 register_proc_table(root_table, proc_sys_root, &root_table_header);
1196 #ifdef CONFIG_SYSCTL_SYSCALL
1197 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1198 void __user *newval, size_t newlen)
1200 struct list_head *tmp;
1201 int error = -ENOTDIR;
1203 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1207 if (!oldlenp || get_user(old_len, oldlenp))
1210 spin_lock(&sysctl_lock);
1211 tmp = &root_table_header.ctl_entry;
1213 struct ctl_table_header *head =
1214 list_entry(tmp, struct ctl_table_header, ctl_entry);
1215 void *context = NULL;
1217 if (!use_table(head))
1220 spin_unlock(&sysctl_lock);
1222 error = parse_table(name, nlen, oldval, oldlenp,
1223 newval, newlen, head->ctl_table,
1227 spin_lock(&sysctl_lock);
1229 if (error != -ENOTDIR)
1231 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1232 spin_unlock(&sysctl_lock);
1236 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1238 struct __sysctl_args tmp;
1241 if (copy_from_user(&tmp, args, sizeof(tmp)))
1245 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1246 tmp.newval, tmp.newlen);
1250 #endif /* CONFIG_SYSCTL_SYSCALL */
1253 * ctl_perm does NOT grant the superuser all rights automatically, because
1254 * some sysctl variables are readonly even to root.
1257 static int test_perm(int mode, int op)
1261 else if (in_egroup_p(0))
1263 if ((mode & op & 0007) == op)
1268 static inline int ctl_perm(ctl_table *table, int op)
1271 error = security_sysctl(table, op);
1274 return test_perm(table->mode, op);
1277 #ifdef CONFIG_SYSCTL_SYSCALL
1278 static int parse_table(int __user *name, int nlen,
1279 void __user *oldval, size_t __user *oldlenp,
1280 void __user *newval, size_t newlen,
1281 ctl_table *table, void **context)
1287 if (get_user(n, name))
1289 for ( ; table->ctl_name || table->procname; table++) {
1290 if (!table->ctl_name)
1292 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1295 if (ctl_perm(table, 001))
1297 if (table->strategy) {
1298 error = table->strategy(
1301 newval, newlen, context);
1307 table = table->child;
1310 error = do_sysctl_strategy(table, name, nlen,
1312 newval, newlen, context);
1319 /* Perform the actual read/write of a sysctl table entry. */
1320 int do_sysctl_strategy (ctl_table *table,
1321 int __user *name, int nlen,
1322 void __user *oldval, size_t __user *oldlenp,
1323 void __user *newval, size_t newlen, void **context)
1332 if (ctl_perm(table, op))
1335 if (table->strategy) {
1336 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1337 newval, newlen, context);
1344 /* If there is no strategy routine, or if the strategy returns
1345 * zero, proceed with automatic r/w */
1346 if (table->data && table->maxlen) {
1347 if (oldval && oldlenp) {
1348 if (get_user(len, oldlenp))
1351 if (len > table->maxlen)
1352 len = table->maxlen;
1353 if(copy_to_user(oldval, table->data, len))
1355 if(put_user(len, oldlenp))
1359 if (newval && newlen) {
1361 if (len > table->maxlen)
1362 len = table->maxlen;
1363 if(copy_from_user(table->data, newval, len))
1369 #endif /* CONFIG_SYSCTL_SYSCALL */
1372 * register_sysctl_table - register a sysctl hierarchy
1373 * @table: the top-level table structure
1374 * @insert_at_head: whether the entry should be inserted in front or at the end
1376 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1377 * array. An entry with a ctl_name of 0 terminates the table.
1379 * The members of the &ctl_table structure are used as follows:
1381 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1382 * must be unique within that level of sysctl
1384 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1385 * enter a sysctl file
1387 * data - a pointer to data for use by proc_handler
1389 * maxlen - the maximum size in bytes of the data
1391 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1393 * child - a pointer to the child sysctl table if this entry is a directory, or
1396 * proc_handler - the text handler routine (described below)
1398 * strategy - the strategy routine (described below)
1400 * de - for internal use by the sysctl routines
1402 * extra1, extra2 - extra pointers usable by the proc handler routines
1404 * Leaf nodes in the sysctl tree will be represented by a single file
1405 * under /proc; non-leaf nodes will be represented by directories.
1407 * sysctl(2) can automatically manage read and write requests through
1408 * the sysctl table. The data and maxlen fields of the ctl_table
1409 * struct enable minimal validation of the values being written to be
1410 * performed, and the mode field allows minimal authentication.
1412 * More sophisticated management can be enabled by the provision of a
1413 * strategy routine with the table entry. This will be called before
1414 * any automatic read or write of the data is performed.
1416 * The strategy routine may return
1418 * < 0 - Error occurred (error is passed to user process)
1420 * 0 - OK - proceed with automatic read or write.
1422 * > 0 - OK - read or write has been done by the strategy routine, so
1423 * return immediately.
1425 * There must be a proc_handler routine for any terminal nodes
1426 * mirrored under /proc/sys (non-terminals are handled by a built-in
1427 * directory handler). Several default handlers are available to
1428 * cover common cases -
1430 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1431 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1432 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1434 * It is the handler's job to read the input buffer from user memory
1435 * and process it. The handler should return 0 on success.
1437 * This routine returns %NULL on a failure to register, and a pointer
1438 * to the table header on success.
1440 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1443 struct ctl_table_header *tmp;
1444 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1447 tmp->ctl_table = table;
1448 INIT_LIST_HEAD(&tmp->ctl_entry);
1450 tmp->unregistering = NULL;
1451 spin_lock(&sysctl_lock);
1453 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1455 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1456 spin_unlock(&sysctl_lock);
1457 #ifdef CONFIG_PROC_SYSCTL
1458 register_proc_table(table, proc_sys_root, tmp);
1464 * unregister_sysctl_table - unregister a sysctl table hierarchy
1465 * @header: the header returned from register_sysctl_table
1467 * Unregisters the sysctl table and all children. proc entries may not
1468 * actually be removed until they are no longer used by anyone.
1470 void unregister_sysctl_table(struct ctl_table_header * header)
1473 spin_lock(&sysctl_lock);
1474 start_unregistering(header);
1475 #ifdef CONFIG_PROC_SYSCTL
1476 unregister_proc_table(header->ctl_table, proc_sys_root);
1478 spin_unlock(&sysctl_lock);
1482 #else /* !CONFIG_SYSCTL */
1483 struct ctl_table_header * register_sysctl_table(ctl_table * table,
1489 void unregister_sysctl_table(struct ctl_table_header * table)
1493 #endif /* CONFIG_SYSCTL */
1499 #ifdef CONFIG_PROC_SYSCTL
1501 /* Scan the sysctl entries in table and add them all into /proc */
1502 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1504 struct proc_dir_entry *de;
1508 for (; table->ctl_name || table->procname; table++) {
1509 /* Can't do anything without a proc name. */
1510 if (!table->procname)
1512 /* Maybe we can't do anything with it... */
1513 if (!table->proc_handler && !table->child) {
1514 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1519 len = strlen(table->procname);
1523 if (table->proc_handler)
1527 for (de = root->subdir; de; de = de->next) {
1528 if (proc_match(len, table->procname, de))
1531 /* If the subdir exists already, de is non-NULL */
1535 de = create_proc_entry(table->procname, mode, root);
1539 de->data = (void *) table;
1540 if (table->proc_handler)
1541 de->proc_fops = &proc_sys_file_operations;
1544 if (de->mode & S_IFDIR)
1545 register_proc_table(table->child, de, set);
1550 * Unregister a /proc sysctl table and any subdirectories.
1552 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1554 struct proc_dir_entry *de;
1555 for (; table->ctl_name || table->procname; table++) {
1556 if (!(de = table->de))
1558 if (de->mode & S_IFDIR) {
1559 if (!table->child) {
1560 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1563 unregister_proc_table(table->child, de);
1565 /* Don't unregister directories which still have entries.. */
1571 * In any case, mark the entry as goner; we'll keep it
1572 * around if it's busy, but we'll know to do nothing with
1573 * its fields. We are under sysctl_lock here.
1577 /* Don't unregister proc entries that are still being used.. */
1578 if (atomic_read(&de->count))
1582 remove_proc_entry(table->procname, root);
1586 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1587 size_t count, loff_t *ppos)
1590 struct proc_dir_entry *de = PDE(file->f_path.dentry->d_inode);
1591 struct ctl_table *table;
1593 ssize_t error = -ENOTDIR;
1595 spin_lock(&sysctl_lock);
1596 if (de && de->data && use_table(de->set)) {
1598 * at that point we know that sysctl was not unregistered
1599 * and won't be until we finish
1601 spin_unlock(&sysctl_lock);
1602 table = (struct ctl_table *) de->data;
1603 if (!table || !table->proc_handler)
1606 op = (write ? 002 : 004);
1607 if (ctl_perm(table, op))
1610 /* careful: calling conventions are nasty here */
1612 error = (*table->proc_handler)(table, write, file,
1617 spin_lock(&sysctl_lock);
1618 unuse_table(de->set);
1620 spin_unlock(&sysctl_lock);
1624 static int proc_opensys(struct inode *inode, struct file *file)
1626 if (file->f_mode & FMODE_WRITE) {
1628 * sysctl entries that are not writable,
1629 * are _NOT_ writable, capabilities or not.
1631 if (!(inode->i_mode & S_IWUSR))
1638 static ssize_t proc_readsys(struct file * file, char __user * buf,
1639 size_t count, loff_t *ppos)
1641 return do_rw_proc(0, file, buf, count, ppos);
1644 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1645 size_t count, loff_t *ppos)
1647 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1650 static int _proc_do_string(void* data, int maxlen, int write,
1651 struct file *filp, void __user *buffer,
1652 size_t *lenp, loff_t *ppos)
1658 if (!data || !maxlen || !*lenp ||
1659 (*ppos && !write)) {
1667 while (len < *lenp) {
1668 if (get_user(c, p++))
1670 if (c == 0 || c == '\n')
1676 if(copy_from_user(data, buffer, len))
1678 ((char *) data)[len] = 0;
1687 if(copy_to_user(buffer, data, len))
1690 if(put_user('\n', ((char __user *) buffer) + len))
1701 * proc_dostring - read a string sysctl
1702 * @table: the sysctl table
1703 * @write: %TRUE if this is a write to the sysctl file
1704 * @filp: the file structure
1705 * @buffer: the user buffer
1706 * @lenp: the size of the user buffer
1707 * @ppos: file position
1709 * Reads/writes a string from/to the user buffer. If the kernel
1710 * buffer provided is not large enough to hold the string, the
1711 * string is truncated. The copied string is %NULL-terminated.
1712 * If the string is being read by the user process, it is copied
1713 * and a newline '\n' is added. It is truncated if the buffer is
1716 * Returns 0 on success.
1718 int proc_dostring(ctl_table *table, int write, struct file *filp,
1719 void __user *buffer, size_t *lenp, loff_t *ppos)
1721 return _proc_do_string(table->data, table->maxlen, write, filp,
1722 buffer, lenp, ppos);
1726 * Special case of dostring for the UTS structure. This has locks
1727 * to observe. Should this be in kernel/sys.c ????
1730 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
1731 void __user *buffer, size_t *lenp, loff_t *ppos)
1735 which = get_uts(table, write);
1736 r = _proc_do_string(which, table->maxlen,write,filp,buffer,lenp, ppos);
1737 put_uts(table, write, which);
1741 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1743 int write, void *data)
1746 *valp = *negp ? -*lvalp : *lvalp;
1751 *lvalp = (unsigned long)-val;
1754 *lvalp = (unsigned long)val;
1760 static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1761 int write, struct file *filp, void __user *buffer,
1762 size_t *lenp, loff_t *ppos,
1763 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1764 int write, void *data),
1767 #define TMPBUFLEN 21
1768 int *i, vleft, first=1, neg, val;
1772 char buf[TMPBUFLEN], *p;
1773 char __user *s = buffer;
1775 if (!tbl_data || !table->maxlen || !*lenp ||
1776 (*ppos && !write)) {
1781 i = (int *) tbl_data;
1782 vleft = table->maxlen / sizeof(*i);
1786 conv = do_proc_dointvec_conv;
1788 for (; left && vleft--; i++, first=0) {
1803 if (len > sizeof(buf) - 1)
1804 len = sizeof(buf) - 1;
1805 if (copy_from_user(buf, s, len))
1809 if (*p == '-' && left > 1) {
1813 if (*p < '0' || *p > '9')
1816 lval = simple_strtoul(p, &p, 0);
1819 if ((len < left) && *p && !isspace(*p))
1826 if (conv(&neg, &lval, i, 1, data))
1833 if (conv(&neg, &lval, i, 0, data))
1836 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1840 if(copy_to_user(s, buf, len))
1847 if (!write && !first && left) {
1848 if(put_user('\n', s))
1855 if (get_user(c, s++))
1870 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1871 void __user *buffer, size_t *lenp, loff_t *ppos,
1872 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1873 int write, void *data),
1876 return __do_proc_dointvec(table->data, table, write, filp,
1877 buffer, lenp, ppos, conv, data);
1881 * proc_dointvec - read a vector of integers
1882 * @table: the sysctl table
1883 * @write: %TRUE if this is a write to the sysctl file
1884 * @filp: the file structure
1885 * @buffer: the user buffer
1886 * @lenp: the size of the user buffer
1887 * @ppos: file position
1889 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1890 * values from/to the user buffer, treated as an ASCII string.
1892 * Returns 0 on success.
1894 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1895 void __user *buffer, size_t *lenp, loff_t *ppos)
1897 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1907 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1909 int write, void *data)
1911 int op = *(int *)data;
1913 int val = *negp ? -*lvalp : *lvalp;
1915 case OP_SET: *valp = val; break;
1916 case OP_AND: *valp &= val; break;
1917 case OP_OR: *valp |= val; break;
1918 case OP_MAX: if(*valp < val)
1921 case OP_MIN: if(*valp > val)
1929 *lvalp = (unsigned long)-val;
1932 *lvalp = (unsigned long)val;
1939 * init may raise the set.
1942 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1943 void __user *buffer, size_t *lenp, loff_t *ppos)
1947 if (!capable(CAP_SYS_MODULE)) {
1951 op = is_init(current) ? OP_SET : OP_AND;
1952 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1953 do_proc_dointvec_bset_conv,&op);
1956 struct do_proc_dointvec_minmax_conv_param {
1961 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1963 int write, void *data)
1965 struct do_proc_dointvec_minmax_conv_param *param = data;
1967 int val = *negp ? -*lvalp : *lvalp;
1968 if ((param->min && *param->min > val) ||
1969 (param->max && *param->max < val))
1976 *lvalp = (unsigned long)-val;
1979 *lvalp = (unsigned long)val;
1986 * proc_dointvec_minmax - read a vector of integers with min/max values
1987 * @table: the sysctl table
1988 * @write: %TRUE if this is a write to the sysctl file
1989 * @filp: the file structure
1990 * @buffer: the user buffer
1991 * @lenp: the size of the user buffer
1992 * @ppos: file position
1994 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1995 * values from/to the user buffer, treated as an ASCII string.
1997 * This routine will ensure the values are within the range specified by
1998 * table->extra1 (min) and table->extra2 (max).
2000 * Returns 0 on success.
2002 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2003 void __user *buffer, size_t *lenp, loff_t *ppos)
2005 struct do_proc_dointvec_minmax_conv_param param = {
2006 .min = (int *) table->extra1,
2007 .max = (int *) table->extra2,
2009 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2010 do_proc_dointvec_minmax_conv, ¶m);
2013 static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
2015 void __user *buffer,
2016 size_t *lenp, loff_t *ppos,
2017 unsigned long convmul,
2018 unsigned long convdiv)
2020 #define TMPBUFLEN 21
2021 unsigned long *i, *min, *max, val;
2022 int vleft, first=1, neg;
2024 char buf[TMPBUFLEN], *p;
2025 char __user *s = buffer;
2027 if (!data || !table->maxlen || !*lenp ||
2028 (*ppos && !write)) {
2033 i = (unsigned long *) data;
2034 min = (unsigned long *) table->extra1;
2035 max = (unsigned long *) table->extra2;
2036 vleft = table->maxlen / sizeof(unsigned long);
2039 for (; left && vleft--; i++, min++, max++, first=0) {
2054 if (len > TMPBUFLEN-1)
2056 if (copy_from_user(buf, s, len))
2060 if (*p == '-' && left > 1) {
2064 if (*p < '0' || *p > '9')
2066 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2068 if ((len < left) && *p && !isspace(*p))
2077 if ((min && val < *min) || (max && val > *max))
2084 sprintf(p, "%lu", convdiv * (*i) / convmul);
2088 if(copy_to_user(s, buf, len))
2095 if (!write && !first && left) {
2096 if(put_user('\n', s))
2103 if (get_user(c, s++))
2118 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2120 void __user *buffer,
2121 size_t *lenp, loff_t *ppos,
2122 unsigned long convmul,
2123 unsigned long convdiv)
2125 return __do_proc_doulongvec_minmax(table->data, table, write,
2126 filp, buffer, lenp, ppos, convmul, convdiv);
2130 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2131 * @table: the sysctl table
2132 * @write: %TRUE if this is a write to the sysctl file
2133 * @filp: the file structure
2134 * @buffer: the user buffer
2135 * @lenp: the size of the user buffer
2136 * @ppos: file position
2138 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2139 * values from/to the user buffer, treated as an ASCII string.
2141 * This routine will ensure the values are within the range specified by
2142 * table->extra1 (min) and table->extra2 (max).
2144 * Returns 0 on success.
2146 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2147 void __user *buffer, size_t *lenp, loff_t *ppos)
2149 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2153 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2154 * @table: the sysctl table
2155 * @write: %TRUE if this is a write to the sysctl file
2156 * @filp: the file structure
2157 * @buffer: the user buffer
2158 * @lenp: the size of the user buffer
2159 * @ppos: file position
2161 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2162 * values from/to the user buffer, treated as an ASCII string. The values
2163 * are treated as milliseconds, and converted to jiffies when they are stored.
2165 * This routine will ensure the values are within the range specified by
2166 * table->extra1 (min) and table->extra2 (max).
2168 * Returns 0 on success.
2170 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2172 void __user *buffer,
2173 size_t *lenp, loff_t *ppos)
2175 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2176 lenp, ppos, HZ, 1000l);
2180 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2182 int write, void *data)
2185 if (*lvalp > LONG_MAX / HZ)
2187 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2193 lval = (unsigned long)-val;
2196 lval = (unsigned long)val;
2203 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2205 int write, void *data)
2208 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2210 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2216 lval = (unsigned long)-val;
2219 lval = (unsigned long)val;
2221 *lvalp = jiffies_to_clock_t(lval);
2226 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2228 int write, void *data)
2231 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2237 lval = (unsigned long)-val;
2240 lval = (unsigned long)val;
2242 *lvalp = jiffies_to_msecs(lval);
2248 * proc_dointvec_jiffies - read a vector of integers as seconds
2249 * @table: the sysctl table
2250 * @write: %TRUE if this is a write to the sysctl file
2251 * @filp: the file structure
2252 * @buffer: the user buffer
2253 * @lenp: the size of the user buffer
2254 * @ppos: file position
2256 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2257 * values from/to the user buffer, treated as an ASCII string.
2258 * The values read are assumed to be in seconds, and are converted into
2261 * Returns 0 on success.
2263 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2264 void __user *buffer, size_t *lenp, loff_t *ppos)
2266 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2267 do_proc_dointvec_jiffies_conv,NULL);
2271 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2272 * @table: the sysctl table
2273 * @write: %TRUE if this is a write to the sysctl file
2274 * @filp: the file structure
2275 * @buffer: the user buffer
2276 * @lenp: the size of the user buffer
2277 * @ppos: pointer to the file position
2279 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2280 * values from/to the user buffer, treated as an ASCII string.
2281 * The values read are assumed to be in 1/USER_HZ seconds, and
2282 * are converted into jiffies.
2284 * Returns 0 on success.
2286 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2287 void __user *buffer, size_t *lenp, loff_t *ppos)
2289 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2290 do_proc_dointvec_userhz_jiffies_conv,NULL);
2294 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2295 * @table: the sysctl table
2296 * @write: %TRUE if this is a write to the sysctl file
2297 * @filp: the file structure
2298 * @buffer: the user buffer
2299 * @lenp: the size of the user buffer
2300 * @ppos: file position
2301 * @ppos: the current position in the file
2303 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2304 * values from/to the user buffer, treated as an ASCII string.
2305 * The values read are assumed to be in 1/1000 seconds, and
2306 * are converted into jiffies.
2308 * Returns 0 on success.
2310 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2311 void __user *buffer, size_t *lenp, loff_t *ppos)
2313 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2314 do_proc_dointvec_ms_jiffies_conv, NULL);
2317 #ifdef CONFIG_SYSVIPC
2318 static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2319 void __user *buffer, size_t *lenp, loff_t *ppos)
2322 struct ipc_namespace *ns;
2324 ns = current->nsproxy->ipc_ns;
2326 switch (table->ctl_name) {
2328 data = &ns->shm_ctlmax;
2331 data = &ns->shm_ctlall;
2334 data = &ns->shm_ctlmni;
2337 data = &ns->msg_ctlmax;
2340 data = &ns->msg_ctlmni;
2343 data = &ns->msg_ctlmnb;
2346 data = &ns->sem_ctls;
2352 return __do_proc_dointvec(data, table, write, filp, buffer,
2353 lenp, ppos, NULL, NULL);
2355 return __do_proc_doulongvec_minmax(data, table, write, filp, buffer,
2356 lenp, ppos, 1l, 1l);
2360 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2361 void __user *buffer, size_t *lenp, loff_t *ppos)
2363 struct pid *new_pid;
2367 tmp = pid_nr(cad_pid);
2369 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2370 lenp, ppos, NULL, NULL);
2374 new_pid = find_get_pid(tmp);
2378 put_pid(xchg(&cad_pid, new_pid));
2382 #else /* CONFIG_PROC_FS */
2384 int proc_dostring(ctl_table *table, int write, struct file *filp,
2385 void __user *buffer, size_t *lenp, loff_t *ppos)
2390 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
2391 void __user *buffer, size_t *lenp, loff_t *ppos)
2396 #ifdef CONFIG_SYSVIPC
2397 static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2398 void __user *buffer, size_t *lenp, loff_t *ppos)
2404 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2405 void __user *buffer, size_t *lenp, loff_t *ppos)
2410 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2411 void __user *buffer, size_t *lenp, loff_t *ppos)
2416 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2417 void __user *buffer, size_t *lenp, loff_t *ppos)
2422 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2423 void __user *buffer, size_t *lenp, loff_t *ppos)
2428 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2429 void __user *buffer, size_t *lenp, loff_t *ppos)
2434 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2435 void __user *buffer, size_t *lenp, loff_t *ppos)
2440 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2441 void __user *buffer, size_t *lenp, loff_t *ppos)
2446 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2448 void __user *buffer,
2449 size_t *lenp, loff_t *ppos)
2455 #endif /* CONFIG_PROC_FS */
2458 #ifdef CONFIG_SYSCTL_SYSCALL
2460 * General sysctl support routines
2463 /* The generic string strategy routine: */
2464 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2465 void __user *oldval, size_t __user *oldlenp,
2466 void __user *newval, size_t newlen, void **context)
2468 if (!table->data || !table->maxlen)
2471 if (oldval && oldlenp) {
2473 if (get_user(bufsize, oldlenp))
2476 size_t len = strlen(table->data), copied;
2478 /* This shouldn't trigger for a well-formed sysctl */
2479 if (len > table->maxlen)
2480 len = table->maxlen;
2482 /* Copy up to a max of bufsize-1 bytes of the string */
2483 copied = (len >= bufsize) ? bufsize - 1 : len;
2485 if (copy_to_user(oldval, table->data, copied) ||
2486 put_user(0, (char __user *)(oldval + copied)))
2488 if (put_user(len, oldlenp))
2492 if (newval && newlen) {
2493 size_t len = newlen;
2494 if (len > table->maxlen)
2495 len = table->maxlen;
2496 if(copy_from_user(table->data, newval, len))
2498 if (len == table->maxlen)
2500 ((char *) table->data)[len] = 0;
2506 * This function makes sure that all of the integers in the vector
2507 * are between the minimum and maximum values given in the arrays
2508 * table->extra1 and table->extra2, respectively.
2510 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2511 void __user *oldval, size_t __user *oldlenp,
2512 void __user *newval, size_t newlen, void **context)
2515 if (newval && newlen) {
2516 int __user *vec = (int __user *) newval;
2517 int *min = (int *) table->extra1;
2518 int *max = (int *) table->extra2;
2522 if (newlen % sizeof(int) != 0)
2525 if (!table->extra1 && !table->extra2)
2528 if (newlen > table->maxlen)
2529 newlen = table->maxlen;
2530 length = newlen / sizeof(int);
2532 for (i = 0; i < length; i++) {
2534 if (get_user(value, vec + i))
2536 if (min && value < min[i])
2538 if (max && value > max[i])
2545 /* Strategy function to convert jiffies to seconds */
2546 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2547 void __user *oldval, size_t __user *oldlenp,
2548 void __user *newval, size_t newlen, void **context)
2553 if (get_user(olen, oldlenp))
2555 if (olen!=sizeof(int))
2558 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2559 (oldlenp && put_user(sizeof(int),oldlenp)))
2562 if (newval && newlen) {
2564 if (newlen != sizeof(int))
2566 if (get_user(new, (int __user *)newval))
2568 *(int *)(table->data) = new*HZ;
2573 /* Strategy function to convert jiffies to seconds */
2574 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2575 void __user *oldval, size_t __user *oldlenp,
2576 void __user *newval, size_t newlen, void **context)
2581 if (get_user(olen, oldlenp))
2583 if (olen!=sizeof(int))
2586 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2587 (oldlenp && put_user(sizeof(int),oldlenp)))
2590 if (newval && newlen) {
2592 if (newlen != sizeof(int))
2594 if (get_user(new, (int __user *)newval))
2596 *(int *)(table->data) = msecs_to_jiffies(new);
2601 #else /* CONFIG_SYSCTL_SYSCALL */
2604 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2606 static int msg_count;
2607 struct __sysctl_args tmp;
2608 int name[CTL_MAXNAME];
2611 /* Read in the sysctl name for better debug message logging */
2612 if (copy_from_user(&tmp, args, sizeof(tmp)))
2614 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2616 for (i = 0; i < tmp.nlen; i++)
2617 if (get_user(name[i], tmp.name + i))
2620 /* Ignore accesses to kernel.version */
2621 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2624 if (msg_count < 5) {
2627 "warning: process `%s' used the removed sysctl "
2628 "system call with ", current->comm);
2629 for (i = 0; i < tmp.nlen; i++)
2630 printk("%d.", name[i]);
2637 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2638 void __user *oldval, size_t __user *oldlenp,
2639 void __user *newval, size_t newlen, void **context)
2644 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2645 void __user *oldval, size_t __user *oldlenp,
2646 void __user *newval, size_t newlen, void **context)
2651 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2652 void __user *oldval, size_t __user *oldlenp,
2653 void __user *newval, size_t newlen, void **context)
2658 int sysctl_ms_jiffies(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 #endif /* CONFIG_SYSCTL_SYSCALL */
2668 * No sense putting this after each symbol definition, twice,
2669 * exception granted :-)
2671 EXPORT_SYMBOL(proc_dointvec);
2672 EXPORT_SYMBOL(proc_dointvec_jiffies);
2673 EXPORT_SYMBOL(proc_dointvec_minmax);
2674 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2675 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2676 EXPORT_SYMBOL(proc_dostring);
2677 EXPORT_SYMBOL(proc_doulongvec_minmax);
2678 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2679 EXPORT_SYMBOL(register_sysctl_table);
2680 EXPORT_SYMBOL(sysctl_intvec);
2681 EXPORT_SYMBOL(sysctl_jiffies);
2682 EXPORT_SYMBOL(sysctl_ms_jiffies);
2683 EXPORT_SYMBOL(sysctl_string);
2684 EXPORT_SYMBOL(unregister_sysctl_table);