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 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
81 static int maxolduid = 65535;
83 static int min_percpu_pagelist_fract = 8;
85 static int ngroups_max = NGROUPS_MAX;
88 extern char modprobe_path[];
90 #ifdef CONFIG_CHR_DEV_SG
91 extern int sg_big_buff;
95 extern char reboot_command [];
96 extern int stop_a_enabled;
97 extern int scons_pwroff;
101 extern int pwrsw_enabled;
102 extern int unaligned_enabled;
106 #ifdef CONFIG_MATHEMU
107 extern int sysctl_ieee_emulation_warnings;
109 extern int sysctl_userprocess_debug;
110 extern int spin_retry;
113 extern int sysctl_hz_timer;
115 #ifdef CONFIG_BSD_PROCESS_ACCT
116 extern int acct_parm[];
120 extern int no_unaligned_warning;
123 #ifdef CONFIG_RT_MUTEXES
124 extern int max_lock_depth;
127 #ifdef CONFIG_SYSCTL_SYSCALL
128 static int parse_table(int __user *, int, void __user *, size_t __user *,
129 void __user *, size_t, ctl_table *);
133 #ifdef CONFIG_PROC_SYSCTL
134 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
135 void __user *buffer, size_t *lenp, loff_t *ppos);
136 static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
137 void __user *buffer, size_t *lenp, loff_t *ppos);
140 static ctl_table root_table[];
141 static struct ctl_table_header root_table_header =
142 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
144 static ctl_table kern_table[];
145 static ctl_table vm_table[];
146 static ctl_table fs_table[];
147 static ctl_table debug_table[];
148 static ctl_table dev_table[];
149 extern ctl_table random_table[];
150 #ifdef CONFIG_UNIX98_PTYS
151 extern ctl_table pty_table[];
153 #ifdef CONFIG_INOTIFY_USER
154 extern ctl_table inotify_table[];
157 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
158 int sysctl_legacy_va_layout;
162 /* /proc declarations: */
164 #ifdef CONFIG_PROC_SYSCTL
166 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
167 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
168 static int proc_opensys(struct inode *, struct file *);
170 const struct file_operations proc_sys_file_operations = {
171 .open = proc_opensys,
172 .read = proc_readsys,
173 .write = proc_writesys,
176 extern struct proc_dir_entry *proc_sys_root;
178 static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
179 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
182 /* The default sysctl tables: */
184 static ctl_table root_table[] = {
186 .ctl_name = CTL_KERN,
187 .procname = "kernel",
212 .ctl_name = CTL_DEBUG,
215 .child = debug_table,
227 static ctl_table kern_table[] = {
229 .ctl_name = KERN_PANIC,
231 .data = &panic_timeout,
232 .maxlen = sizeof(int),
234 .proc_handler = &proc_dointvec,
237 .ctl_name = KERN_CORE_USES_PID,
238 .procname = "core_uses_pid",
239 .data = &core_uses_pid,
240 .maxlen = sizeof(int),
242 .proc_handler = &proc_dointvec,
245 .ctl_name = KERN_CORE_PATTERN,
246 .procname = "core_pattern",
247 .data = core_pattern,
250 .proc_handler = &proc_dostring,
251 .strategy = &sysctl_string,
253 #ifdef CONFIG_PROC_SYSCTL
255 .ctl_name = KERN_TAINTED,
256 .procname = "tainted",
258 .maxlen = sizeof(int),
260 .proc_handler = &proc_dointvec_taint,
264 .ctl_name = KERN_CAP_BSET,
265 .procname = "cap-bound",
267 .maxlen = sizeof(kernel_cap_t),
269 .proc_handler = &proc_dointvec_bset,
271 #ifdef CONFIG_BLK_DEV_INITRD
273 .ctl_name = KERN_REALROOTDEV,
274 .procname = "real-root-dev",
275 .data = &real_root_dev,
276 .maxlen = sizeof(int),
278 .proc_handler = &proc_dointvec,
283 .ctl_name = KERN_SPARC_REBOOT,
284 .procname = "reboot-cmd",
285 .data = reboot_command,
288 .proc_handler = &proc_dostring,
289 .strategy = &sysctl_string,
292 .ctl_name = KERN_SPARC_STOP_A,
293 .procname = "stop-a",
294 .data = &stop_a_enabled,
295 .maxlen = sizeof (int),
297 .proc_handler = &proc_dointvec,
300 .ctl_name = KERN_SPARC_SCONS_PWROFF,
301 .procname = "scons-poweroff",
302 .data = &scons_pwroff,
303 .maxlen = sizeof (int),
305 .proc_handler = &proc_dointvec,
310 .ctl_name = KERN_HPPA_PWRSW,
311 .procname = "soft-power",
312 .data = &pwrsw_enabled,
313 .maxlen = sizeof (int),
315 .proc_handler = &proc_dointvec,
318 .ctl_name = KERN_HPPA_UNALIGNED,
319 .procname = "unaligned-trap",
320 .data = &unaligned_enabled,
321 .maxlen = sizeof (int),
323 .proc_handler = &proc_dointvec,
327 .ctl_name = KERN_CTLALTDEL,
328 .procname = "ctrl-alt-del",
330 .maxlen = sizeof(int),
332 .proc_handler = &proc_dointvec,
335 .ctl_name = KERN_PRINTK,
336 .procname = "printk",
337 .data = &console_loglevel,
338 .maxlen = 4*sizeof(int),
340 .proc_handler = &proc_dointvec,
344 .ctl_name = KERN_MODPROBE,
345 .procname = "modprobe",
346 .data = &modprobe_path,
347 .maxlen = KMOD_PATH_LEN,
349 .proc_handler = &proc_dostring,
350 .strategy = &sysctl_string,
353 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
355 .ctl_name = KERN_HOTPLUG,
356 .procname = "hotplug",
357 .data = &uevent_helper,
358 .maxlen = UEVENT_HELPER_PATH_LEN,
360 .proc_handler = &proc_dostring,
361 .strategy = &sysctl_string,
364 #ifdef CONFIG_CHR_DEV_SG
366 .ctl_name = KERN_SG_BIG_BUFF,
367 .procname = "sg-big-buff",
368 .data = &sg_big_buff,
369 .maxlen = sizeof (int),
371 .proc_handler = &proc_dointvec,
374 #ifdef CONFIG_BSD_PROCESS_ACCT
376 .ctl_name = KERN_ACCT,
379 .maxlen = 3*sizeof(int),
381 .proc_handler = &proc_dointvec,
384 #ifdef CONFIG_MAGIC_SYSRQ
386 .ctl_name = KERN_SYSRQ,
388 .data = &__sysrq_enabled,
389 .maxlen = sizeof (int),
391 .proc_handler = &proc_dointvec,
394 #ifdef CONFIG_PROC_SYSCTL
396 .ctl_name = KERN_CADPID,
397 .procname = "cad_pid",
399 .maxlen = sizeof (int),
401 .proc_handler = &proc_do_cad_pid,
405 .ctl_name = KERN_MAX_THREADS,
406 .procname = "threads-max",
407 .data = &max_threads,
408 .maxlen = sizeof(int),
410 .proc_handler = &proc_dointvec,
413 .ctl_name = KERN_RANDOM,
414 .procname = "random",
416 .child = random_table,
418 #ifdef CONFIG_UNIX98_PTYS
420 .ctl_name = KERN_PTY,
427 .ctl_name = KERN_OVERFLOWUID,
428 .procname = "overflowuid",
429 .data = &overflowuid,
430 .maxlen = sizeof(int),
432 .proc_handler = &proc_dointvec_minmax,
433 .strategy = &sysctl_intvec,
434 .extra1 = &minolduid,
435 .extra2 = &maxolduid,
438 .ctl_name = KERN_OVERFLOWGID,
439 .procname = "overflowgid",
440 .data = &overflowgid,
441 .maxlen = sizeof(int),
443 .proc_handler = &proc_dointvec_minmax,
444 .strategy = &sysctl_intvec,
445 .extra1 = &minolduid,
446 .extra2 = &maxolduid,
449 #ifdef CONFIG_MATHEMU
451 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
452 .procname = "ieee_emulation_warnings",
453 .data = &sysctl_ieee_emulation_warnings,
454 .maxlen = sizeof(int),
456 .proc_handler = &proc_dointvec,
459 #ifdef CONFIG_NO_IDLE_HZ
461 .ctl_name = KERN_HZ_TIMER,
462 .procname = "hz_timer",
463 .data = &sysctl_hz_timer,
464 .maxlen = sizeof(int),
466 .proc_handler = &proc_dointvec,
470 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
471 .procname = "userprocess_debug",
472 .data = &sysctl_userprocess_debug,
473 .maxlen = sizeof(int),
475 .proc_handler = &proc_dointvec,
479 .ctl_name = KERN_PIDMAX,
480 .procname = "pid_max",
482 .maxlen = sizeof (int),
484 .proc_handler = &proc_dointvec_minmax,
485 .strategy = sysctl_intvec,
486 .extra1 = &pid_max_min,
487 .extra2 = &pid_max_max,
490 .ctl_name = KERN_PANIC_ON_OOPS,
491 .procname = "panic_on_oops",
492 .data = &panic_on_oops,
493 .maxlen = sizeof(int),
495 .proc_handler = &proc_dointvec,
498 .ctl_name = KERN_PRINTK_RATELIMIT,
499 .procname = "printk_ratelimit",
500 .data = &printk_ratelimit_jiffies,
501 .maxlen = sizeof(int),
503 .proc_handler = &proc_dointvec_jiffies,
504 .strategy = &sysctl_jiffies,
507 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
508 .procname = "printk_ratelimit_burst",
509 .data = &printk_ratelimit_burst,
510 .maxlen = sizeof(int),
512 .proc_handler = &proc_dointvec,
515 .ctl_name = KERN_NGROUPS_MAX,
516 .procname = "ngroups_max",
517 .data = &ngroups_max,
518 .maxlen = sizeof (int),
520 .proc_handler = &proc_dointvec,
522 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
524 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
525 .procname = "unknown_nmi_panic",
526 .data = &unknown_nmi_panic,
527 .maxlen = sizeof (int),
529 .proc_handler = &proc_dointvec,
532 .ctl_name = KERN_NMI_WATCHDOG,
533 .procname = "nmi_watchdog",
534 .data = &nmi_watchdog_enabled,
535 .maxlen = sizeof (int),
537 .proc_handler = &proc_nmi_enabled,
540 #if defined(CONFIG_X86)
542 .ctl_name = KERN_PANIC_ON_NMI,
543 .procname = "panic_on_unrecovered_nmi",
544 .data = &panic_on_unrecovered_nmi,
545 .maxlen = sizeof(int),
547 .proc_handler = &proc_dointvec,
550 .ctl_name = KERN_BOOTLOADER_TYPE,
551 .procname = "bootloader_type",
552 .data = &bootloader_type,
553 .maxlen = sizeof (int),
555 .proc_handler = &proc_dointvec,
558 .ctl_name = CTL_UNNUMBERED,
559 .procname = "kstack_depth_to_print",
560 .data = &kstack_depth_to_print,
561 .maxlen = sizeof(int),
563 .proc_handler = &proc_dointvec,
566 #if defined(CONFIG_MMU)
568 .ctl_name = KERN_RANDOMIZE,
569 .procname = "randomize_va_space",
570 .data = &randomize_va_space,
571 .maxlen = sizeof(int),
573 .proc_handler = &proc_dointvec,
576 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
578 .ctl_name = KERN_SPIN_RETRY,
579 .procname = "spin_retry",
581 .maxlen = sizeof (int),
583 .proc_handler = &proc_dointvec,
586 #ifdef CONFIG_ACPI_SLEEP
588 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
589 .procname = "acpi_video_flags",
590 .data = &acpi_video_flags,
591 .maxlen = sizeof (unsigned long),
593 .proc_handler = &proc_doulongvec_minmax,
598 .ctl_name = KERN_IA64_UNALIGNED,
599 .procname = "ignore-unaligned-usertrap",
600 .data = &no_unaligned_warning,
601 .maxlen = sizeof (int),
603 .proc_handler = &proc_dointvec,
608 .ctl_name = KERN_COMPAT_LOG,
609 .procname = "compat-log",
611 .maxlen = sizeof (int),
613 .proc_handler = &proc_dointvec,
616 #ifdef CONFIG_RT_MUTEXES
618 .ctl_name = KERN_MAX_LOCK_DEPTH,
619 .procname = "max_lock_depth",
620 .data = &max_lock_depth,
621 .maxlen = sizeof(int),
623 .proc_handler = &proc_dointvec,
630 /* Constants for minimum and maximum testing in vm_table.
631 We use these as one-element integer vectors. */
633 static int one_hundred = 100;
636 static ctl_table vm_table[] = {
638 .ctl_name = VM_OVERCOMMIT_MEMORY,
639 .procname = "overcommit_memory",
640 .data = &sysctl_overcommit_memory,
641 .maxlen = sizeof(sysctl_overcommit_memory),
643 .proc_handler = &proc_dointvec,
646 .ctl_name = VM_PANIC_ON_OOM,
647 .procname = "panic_on_oom",
648 .data = &sysctl_panic_on_oom,
649 .maxlen = sizeof(sysctl_panic_on_oom),
651 .proc_handler = &proc_dointvec,
654 .ctl_name = VM_OVERCOMMIT_RATIO,
655 .procname = "overcommit_ratio",
656 .data = &sysctl_overcommit_ratio,
657 .maxlen = sizeof(sysctl_overcommit_ratio),
659 .proc_handler = &proc_dointvec,
662 .ctl_name = VM_PAGE_CLUSTER,
663 .procname = "page-cluster",
664 .data = &page_cluster,
665 .maxlen = sizeof(int),
667 .proc_handler = &proc_dointvec,
670 .ctl_name = VM_DIRTY_BACKGROUND,
671 .procname = "dirty_background_ratio",
672 .data = &dirty_background_ratio,
673 .maxlen = sizeof(dirty_background_ratio),
675 .proc_handler = &proc_dointvec_minmax,
676 .strategy = &sysctl_intvec,
678 .extra2 = &one_hundred,
681 .ctl_name = VM_DIRTY_RATIO,
682 .procname = "dirty_ratio",
683 .data = &vm_dirty_ratio,
684 .maxlen = sizeof(vm_dirty_ratio),
686 .proc_handler = &proc_dointvec_minmax,
687 .strategy = &sysctl_intvec,
689 .extra2 = &one_hundred,
692 .ctl_name = VM_DIRTY_WB_CS,
693 .procname = "dirty_writeback_centisecs",
694 .data = &dirty_writeback_interval,
695 .maxlen = sizeof(dirty_writeback_interval),
697 .proc_handler = &dirty_writeback_centisecs_handler,
700 .ctl_name = VM_DIRTY_EXPIRE_CS,
701 .procname = "dirty_expire_centisecs",
702 .data = &dirty_expire_interval,
703 .maxlen = sizeof(dirty_expire_interval),
705 .proc_handler = &proc_dointvec_userhz_jiffies,
708 .ctl_name = VM_NR_PDFLUSH_THREADS,
709 .procname = "nr_pdflush_threads",
710 .data = &nr_pdflush_threads,
711 .maxlen = sizeof nr_pdflush_threads,
712 .mode = 0444 /* read-only*/,
713 .proc_handler = &proc_dointvec,
716 .ctl_name = VM_SWAPPINESS,
717 .procname = "swappiness",
718 .data = &vm_swappiness,
719 .maxlen = sizeof(vm_swappiness),
721 .proc_handler = &proc_dointvec_minmax,
722 .strategy = &sysctl_intvec,
724 .extra2 = &one_hundred,
726 #ifdef CONFIG_HUGETLB_PAGE
728 .ctl_name = VM_HUGETLB_PAGES,
729 .procname = "nr_hugepages",
730 .data = &max_huge_pages,
731 .maxlen = sizeof(unsigned long),
733 .proc_handler = &hugetlb_sysctl_handler,
734 .extra1 = (void *)&hugetlb_zero,
735 .extra2 = (void *)&hugetlb_infinity,
738 .ctl_name = VM_HUGETLB_GROUP,
739 .procname = "hugetlb_shm_group",
740 .data = &sysctl_hugetlb_shm_group,
741 .maxlen = sizeof(gid_t),
743 .proc_handler = &proc_dointvec,
747 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
748 .procname = "lowmem_reserve_ratio",
749 .data = &sysctl_lowmem_reserve_ratio,
750 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
752 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
753 .strategy = &sysctl_intvec,
756 .ctl_name = VM_DROP_PAGECACHE,
757 .procname = "drop_caches",
758 .data = &sysctl_drop_caches,
759 .maxlen = sizeof(int),
761 .proc_handler = drop_caches_sysctl_handler,
762 .strategy = &sysctl_intvec,
765 .ctl_name = VM_MIN_FREE_KBYTES,
766 .procname = "min_free_kbytes",
767 .data = &min_free_kbytes,
768 .maxlen = sizeof(min_free_kbytes),
770 .proc_handler = &min_free_kbytes_sysctl_handler,
771 .strategy = &sysctl_intvec,
775 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
776 .procname = "percpu_pagelist_fraction",
777 .data = &percpu_pagelist_fraction,
778 .maxlen = sizeof(percpu_pagelist_fraction),
780 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
781 .strategy = &sysctl_intvec,
782 .extra1 = &min_percpu_pagelist_fract,
786 .ctl_name = VM_MAX_MAP_COUNT,
787 .procname = "max_map_count",
788 .data = &sysctl_max_map_count,
789 .maxlen = sizeof(sysctl_max_map_count),
791 .proc_handler = &proc_dointvec
795 .ctl_name = VM_LAPTOP_MODE,
796 .procname = "laptop_mode",
797 .data = &laptop_mode,
798 .maxlen = sizeof(laptop_mode),
800 .proc_handler = &proc_dointvec_jiffies,
801 .strategy = &sysctl_jiffies,
804 .ctl_name = VM_BLOCK_DUMP,
805 .procname = "block_dump",
807 .maxlen = sizeof(block_dump),
809 .proc_handler = &proc_dointvec,
810 .strategy = &sysctl_intvec,
814 .ctl_name = VM_VFS_CACHE_PRESSURE,
815 .procname = "vfs_cache_pressure",
816 .data = &sysctl_vfs_cache_pressure,
817 .maxlen = sizeof(sysctl_vfs_cache_pressure),
819 .proc_handler = &proc_dointvec,
820 .strategy = &sysctl_intvec,
823 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
825 .ctl_name = VM_LEGACY_VA_LAYOUT,
826 .procname = "legacy_va_layout",
827 .data = &sysctl_legacy_va_layout,
828 .maxlen = sizeof(sysctl_legacy_va_layout),
830 .proc_handler = &proc_dointvec,
831 .strategy = &sysctl_intvec,
837 .ctl_name = VM_ZONE_RECLAIM_MODE,
838 .procname = "zone_reclaim_mode",
839 .data = &zone_reclaim_mode,
840 .maxlen = sizeof(zone_reclaim_mode),
842 .proc_handler = &proc_dointvec,
843 .strategy = &sysctl_intvec,
847 .ctl_name = VM_MIN_UNMAPPED,
848 .procname = "min_unmapped_ratio",
849 .data = &sysctl_min_unmapped_ratio,
850 .maxlen = sizeof(sysctl_min_unmapped_ratio),
852 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
853 .strategy = &sysctl_intvec,
855 .extra2 = &one_hundred,
858 .ctl_name = VM_MIN_SLAB,
859 .procname = "min_slab_ratio",
860 .data = &sysctl_min_slab_ratio,
861 .maxlen = sizeof(sysctl_min_slab_ratio),
863 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
864 .strategy = &sysctl_intvec,
866 .extra2 = &one_hundred,
871 .ctl_name = VM_VDSO_ENABLED,
872 .procname = "vdso_enabled",
873 .data = &vdso_enabled,
874 .maxlen = sizeof(vdso_enabled),
876 .proc_handler = &proc_dointvec,
877 .strategy = &sysctl_intvec,
884 static ctl_table fs_table[] = {
886 .ctl_name = FS_NRINODE,
887 .procname = "inode-nr",
888 .data = &inodes_stat,
889 .maxlen = 2*sizeof(int),
891 .proc_handler = &proc_dointvec,
894 .ctl_name = FS_STATINODE,
895 .procname = "inode-state",
896 .data = &inodes_stat,
897 .maxlen = 7*sizeof(int),
899 .proc_handler = &proc_dointvec,
902 .ctl_name = FS_NRFILE,
903 .procname = "file-nr",
905 .maxlen = 3*sizeof(int),
907 .proc_handler = &proc_nr_files,
910 .ctl_name = FS_MAXFILE,
911 .procname = "file-max",
912 .data = &files_stat.max_files,
913 .maxlen = sizeof(int),
915 .proc_handler = &proc_dointvec,
918 .ctl_name = FS_DENTRY,
919 .procname = "dentry-state",
920 .data = &dentry_stat,
921 .maxlen = 6*sizeof(int),
923 .proc_handler = &proc_dointvec,
926 .ctl_name = FS_OVERFLOWUID,
927 .procname = "overflowuid",
928 .data = &fs_overflowuid,
929 .maxlen = sizeof(int),
931 .proc_handler = &proc_dointvec_minmax,
932 .strategy = &sysctl_intvec,
933 .extra1 = &minolduid,
934 .extra2 = &maxolduid,
937 .ctl_name = FS_OVERFLOWGID,
938 .procname = "overflowgid",
939 .data = &fs_overflowgid,
940 .maxlen = sizeof(int),
942 .proc_handler = &proc_dointvec_minmax,
943 .strategy = &sysctl_intvec,
944 .extra1 = &minolduid,
945 .extra2 = &maxolduid,
948 .ctl_name = FS_LEASES,
949 .procname = "leases-enable",
950 .data = &leases_enable,
951 .maxlen = sizeof(int),
953 .proc_handler = &proc_dointvec,
955 #ifdef CONFIG_DNOTIFY
957 .ctl_name = FS_DIR_NOTIFY,
958 .procname = "dir-notify-enable",
959 .data = &dir_notify_enable,
960 .maxlen = sizeof(int),
962 .proc_handler = &proc_dointvec,
967 .ctl_name = FS_LEASE_TIME,
968 .procname = "lease-break-time",
969 .data = &lease_break_time,
970 .maxlen = sizeof(int),
972 .proc_handler = &proc_dointvec,
975 .ctl_name = FS_AIO_NR,
976 .procname = "aio-nr",
978 .maxlen = sizeof(aio_nr),
980 .proc_handler = &proc_doulongvec_minmax,
983 .ctl_name = FS_AIO_MAX_NR,
984 .procname = "aio-max-nr",
986 .maxlen = sizeof(aio_max_nr),
988 .proc_handler = &proc_doulongvec_minmax,
990 #ifdef CONFIG_INOTIFY_USER
992 .ctl_name = FS_INOTIFY,
993 .procname = "inotify",
995 .child = inotify_table,
1000 .ctl_name = KERN_SETUID_DUMPABLE,
1001 .procname = "suid_dumpable",
1002 .data = &suid_dumpable,
1003 .maxlen = sizeof(int),
1005 .proc_handler = &proc_dointvec,
1010 static ctl_table debug_table[] = {
1014 static ctl_table dev_table[] = {
1018 static DEFINE_SPINLOCK(sysctl_lock);
1020 /* called under sysctl_lock */
1021 static int use_table(struct ctl_table_header *p)
1023 if (unlikely(p->unregistering))
1029 /* called under sysctl_lock */
1030 static void unuse_table(struct ctl_table_header *p)
1033 if (unlikely(p->unregistering))
1034 complete(p->unregistering);
1037 /* called under sysctl_lock, will reacquire if has to wait */
1038 static void start_unregistering(struct ctl_table_header *p)
1041 * if p->used is 0, nobody will ever touch that entry again;
1042 * we'll eliminate all paths to it before dropping sysctl_lock
1044 if (unlikely(p->used)) {
1045 struct completion wait;
1046 init_completion(&wait);
1047 p->unregistering = &wait;
1048 spin_unlock(&sysctl_lock);
1049 wait_for_completion(&wait);
1050 spin_lock(&sysctl_lock);
1053 * do not remove from the list until nobody holds it; walking the
1054 * list in do_sysctl() relies on that.
1056 list_del_init(&p->ctl_entry);
1059 void __init sysctl_init(void)
1061 #ifdef CONFIG_PROC_SYSCTL
1062 register_proc_table(root_table, proc_sys_root, &root_table_header);
1066 #ifdef CONFIG_SYSCTL_SYSCALL
1067 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1068 void __user *newval, size_t newlen)
1070 struct list_head *tmp;
1071 int error = -ENOTDIR;
1073 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1077 if (!oldlenp || get_user(old_len, oldlenp))
1080 spin_lock(&sysctl_lock);
1081 tmp = &root_table_header.ctl_entry;
1083 struct ctl_table_header *head =
1084 list_entry(tmp, struct ctl_table_header, ctl_entry);
1086 if (!use_table(head))
1089 spin_unlock(&sysctl_lock);
1091 error = parse_table(name, nlen, oldval, oldlenp,
1092 newval, newlen, head->ctl_table);
1094 spin_lock(&sysctl_lock);
1096 if (error != -ENOTDIR)
1098 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1099 spin_unlock(&sysctl_lock);
1103 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1105 struct __sysctl_args tmp;
1108 if (copy_from_user(&tmp, args, sizeof(tmp)))
1112 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1113 tmp.newval, tmp.newlen);
1117 #endif /* CONFIG_SYSCTL_SYSCALL */
1120 * ctl_perm does NOT grant the superuser all rights automatically, because
1121 * some sysctl variables are readonly even to root.
1124 static int test_perm(int mode, int op)
1128 else if (in_egroup_p(0))
1130 if ((mode & op & 0007) == op)
1135 static inline int ctl_perm(ctl_table *table, int op)
1138 error = security_sysctl(table, op);
1141 return test_perm(table->mode, op);
1144 #ifdef CONFIG_SYSCTL_SYSCALL
1145 static int parse_table(int __user *name, int nlen,
1146 void __user *oldval, size_t __user *oldlenp,
1147 void __user *newval, size_t newlen,
1154 if (get_user(n, name))
1156 for ( ; table->ctl_name || table->procname; table++) {
1157 if (!table->ctl_name)
1159 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1162 if (ctl_perm(table, 001))
1164 if (table->strategy) {
1165 error = table->strategy(
1174 table = table->child;
1177 error = do_sysctl_strategy(table, name, nlen,
1186 /* Perform the actual read/write of a sysctl table entry. */
1187 int do_sysctl_strategy (ctl_table *table,
1188 int __user *name, int nlen,
1189 void __user *oldval, size_t __user *oldlenp,
1190 void __user *newval, size_t newlen)
1199 if (ctl_perm(table, op))
1202 if (table->strategy) {
1203 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1211 /* If there is no strategy routine, or if the strategy returns
1212 * zero, proceed with automatic r/w */
1213 if (table->data && table->maxlen) {
1214 if (oldval && oldlenp) {
1215 if (get_user(len, oldlenp))
1218 if (len > table->maxlen)
1219 len = table->maxlen;
1220 if(copy_to_user(oldval, table->data, len))
1222 if(put_user(len, oldlenp))
1226 if (newval && newlen) {
1228 if (len > table->maxlen)
1229 len = table->maxlen;
1230 if(copy_from_user(table->data, newval, len))
1236 #endif /* CONFIG_SYSCTL_SYSCALL */
1239 * register_sysctl_table - register a sysctl hierarchy
1240 * @table: the top-level table structure
1241 * @insert_at_head: whether the entry should be inserted in front or at the end
1243 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1244 * array. An entry with a ctl_name of 0 terminates the table.
1246 * The members of the &ctl_table structure are used as follows:
1248 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1249 * must be unique within that level of sysctl
1251 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1252 * enter a sysctl file
1254 * data - a pointer to data for use by proc_handler
1256 * maxlen - the maximum size in bytes of the data
1258 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1260 * child - a pointer to the child sysctl table if this entry is a directory, or
1263 * proc_handler - the text handler routine (described below)
1265 * strategy - the strategy routine (described below)
1267 * de - for internal use by the sysctl routines
1269 * extra1, extra2 - extra pointers usable by the proc handler routines
1271 * Leaf nodes in the sysctl tree will be represented by a single file
1272 * under /proc; non-leaf nodes will be represented by directories.
1274 * sysctl(2) can automatically manage read and write requests through
1275 * the sysctl table. The data and maxlen fields of the ctl_table
1276 * struct enable minimal validation of the values being written to be
1277 * performed, and the mode field allows minimal authentication.
1279 * More sophisticated management can be enabled by the provision of a
1280 * strategy routine with the table entry. This will be called before
1281 * any automatic read or write of the data is performed.
1283 * The strategy routine may return
1285 * < 0 - Error occurred (error is passed to user process)
1287 * 0 - OK - proceed with automatic read or write.
1289 * > 0 - OK - read or write has been done by the strategy routine, so
1290 * return immediately.
1292 * There must be a proc_handler routine for any terminal nodes
1293 * mirrored under /proc/sys (non-terminals are handled by a built-in
1294 * directory handler). Several default handlers are available to
1295 * cover common cases -
1297 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1298 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1299 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1301 * It is the handler's job to read the input buffer from user memory
1302 * and process it. The handler should return 0 on success.
1304 * This routine returns %NULL on a failure to register, and a pointer
1305 * to the table header on success.
1307 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1310 struct ctl_table_header *tmp;
1311 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1314 tmp->ctl_table = table;
1315 INIT_LIST_HEAD(&tmp->ctl_entry);
1317 tmp->unregistering = NULL;
1318 spin_lock(&sysctl_lock);
1320 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1322 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1323 spin_unlock(&sysctl_lock);
1324 #ifdef CONFIG_PROC_SYSCTL
1325 register_proc_table(table, proc_sys_root, tmp);
1331 * unregister_sysctl_table - unregister a sysctl table hierarchy
1332 * @header: the header returned from register_sysctl_table
1334 * Unregisters the sysctl table and all children. proc entries may not
1335 * actually be removed until they are no longer used by anyone.
1337 void unregister_sysctl_table(struct ctl_table_header * header)
1340 spin_lock(&sysctl_lock);
1341 start_unregistering(header);
1342 #ifdef CONFIG_PROC_SYSCTL
1343 unregister_proc_table(header->ctl_table, proc_sys_root);
1345 spin_unlock(&sysctl_lock);
1349 #else /* !CONFIG_SYSCTL */
1350 struct ctl_table_header * register_sysctl_table(ctl_table * table,
1356 void unregister_sysctl_table(struct ctl_table_header * table)
1360 #endif /* CONFIG_SYSCTL */
1366 #ifdef CONFIG_PROC_SYSCTL
1368 /* Scan the sysctl entries in table and add them all into /proc */
1369 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1371 struct proc_dir_entry *de;
1375 for (; table->ctl_name || table->procname; table++) {
1376 /* Can't do anything without a proc name. */
1377 if (!table->procname)
1379 /* Maybe we can't do anything with it... */
1380 if (!table->proc_handler && !table->child) {
1381 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1386 len = strlen(table->procname);
1390 if (table->proc_handler)
1394 for (de = root->subdir; de; de = de->next) {
1395 if (proc_match(len, table->procname, de))
1398 /* If the subdir exists already, de is non-NULL */
1402 de = create_proc_entry(table->procname, mode, root);
1406 de->data = (void *) table;
1407 if (table->proc_handler)
1408 de->proc_fops = &proc_sys_file_operations;
1411 if (de->mode & S_IFDIR)
1412 register_proc_table(table->child, de, set);
1417 * Unregister a /proc sysctl table and any subdirectories.
1419 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1421 struct proc_dir_entry *de;
1422 for (; table->ctl_name || table->procname; table++) {
1423 if (!(de = table->de))
1425 if (de->mode & S_IFDIR) {
1426 if (!table->child) {
1427 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1430 unregister_proc_table(table->child, de);
1432 /* Don't unregister directories which still have entries.. */
1438 * In any case, mark the entry as goner; we'll keep it
1439 * around if it's busy, but we'll know to do nothing with
1440 * its fields. We are under sysctl_lock here.
1444 /* Don't unregister proc entries that are still being used.. */
1445 if (atomic_read(&de->count))
1449 remove_proc_entry(table->procname, root);
1453 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1454 size_t count, loff_t *ppos)
1457 struct proc_dir_entry *de = PDE(file->f_path.dentry->d_inode);
1458 struct ctl_table *table;
1460 ssize_t error = -ENOTDIR;
1462 spin_lock(&sysctl_lock);
1463 if (de && de->data && use_table(de->set)) {
1465 * at that point we know that sysctl was not unregistered
1466 * and won't be until we finish
1468 spin_unlock(&sysctl_lock);
1469 table = (struct ctl_table *) de->data;
1470 if (!table || !table->proc_handler)
1473 op = (write ? 002 : 004);
1474 if (ctl_perm(table, op))
1477 /* careful: calling conventions are nasty here */
1479 error = (*table->proc_handler)(table, write, file,
1484 spin_lock(&sysctl_lock);
1485 unuse_table(de->set);
1487 spin_unlock(&sysctl_lock);
1491 static int proc_opensys(struct inode *inode, struct file *file)
1493 if (file->f_mode & FMODE_WRITE) {
1495 * sysctl entries that are not writable,
1496 * are _NOT_ writable, capabilities or not.
1498 if (!(inode->i_mode & S_IWUSR))
1505 static ssize_t proc_readsys(struct file * file, char __user * buf,
1506 size_t count, loff_t *ppos)
1508 return do_rw_proc(0, file, buf, count, ppos);
1511 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1512 size_t count, loff_t *ppos)
1514 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1517 static int _proc_do_string(void* data, int maxlen, int write,
1518 struct file *filp, void __user *buffer,
1519 size_t *lenp, loff_t *ppos)
1525 if (!data || !maxlen || !*lenp) {
1533 while (len < *lenp) {
1534 if (get_user(c, p++))
1536 if (c == 0 || c == '\n')
1542 if(copy_from_user(data, buffer, len))
1544 ((char *) data)[len] = 0;
1562 if(copy_to_user(buffer, data, len))
1565 if(put_user('\n', ((char __user *) buffer) + len))
1576 * proc_dostring - read a string sysctl
1577 * @table: the sysctl table
1578 * @write: %TRUE if this is a write to the sysctl file
1579 * @filp: the file structure
1580 * @buffer: the user buffer
1581 * @lenp: the size of the user buffer
1582 * @ppos: file position
1584 * Reads/writes a string from/to the user buffer. If the kernel
1585 * buffer provided is not large enough to hold the string, the
1586 * string is truncated. The copied string is %NULL-terminated.
1587 * If the string is being read by the user process, it is copied
1588 * and a newline '\n' is added. It is truncated if the buffer is
1591 * Returns 0 on success.
1593 int proc_dostring(ctl_table *table, int write, struct file *filp,
1594 void __user *buffer, size_t *lenp, loff_t *ppos)
1596 return _proc_do_string(table->data, table->maxlen, write, filp,
1597 buffer, lenp, ppos);
1601 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1603 int write, void *data)
1606 *valp = *negp ? -*lvalp : *lvalp;
1611 *lvalp = (unsigned long)-val;
1614 *lvalp = (unsigned long)val;
1620 static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1621 int write, struct file *filp, void __user *buffer,
1622 size_t *lenp, loff_t *ppos,
1623 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1624 int write, void *data),
1627 #define TMPBUFLEN 21
1628 int *i, vleft, first=1, neg, val;
1632 char buf[TMPBUFLEN], *p;
1633 char __user *s = buffer;
1635 if (!tbl_data || !table->maxlen || !*lenp ||
1636 (*ppos && !write)) {
1641 i = (int *) tbl_data;
1642 vleft = table->maxlen / sizeof(*i);
1646 conv = do_proc_dointvec_conv;
1648 for (; left && vleft--; i++, first=0) {
1663 if (len > sizeof(buf) - 1)
1664 len = sizeof(buf) - 1;
1665 if (copy_from_user(buf, s, len))
1669 if (*p == '-' && left > 1) {
1673 if (*p < '0' || *p > '9')
1676 lval = simple_strtoul(p, &p, 0);
1679 if ((len < left) && *p && !isspace(*p))
1686 if (conv(&neg, &lval, i, 1, data))
1693 if (conv(&neg, &lval, i, 0, data))
1696 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1700 if(copy_to_user(s, buf, len))
1707 if (!write && !first && left) {
1708 if(put_user('\n', s))
1715 if (get_user(c, s++))
1730 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1731 void __user *buffer, size_t *lenp, loff_t *ppos,
1732 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1733 int write, void *data),
1736 return __do_proc_dointvec(table->data, table, write, filp,
1737 buffer, lenp, ppos, conv, data);
1741 * proc_dointvec - read a vector of integers
1742 * @table: the sysctl table
1743 * @write: %TRUE if this is a write to the sysctl file
1744 * @filp: the file structure
1745 * @buffer: the user buffer
1746 * @lenp: the size of the user buffer
1747 * @ppos: file position
1749 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1750 * values from/to the user buffer, treated as an ASCII string.
1752 * Returns 0 on success.
1754 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1755 void __user *buffer, size_t *lenp, loff_t *ppos)
1757 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1765 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1767 int write, void *data)
1769 int op = *(int *)data;
1771 int val = *negp ? -*lvalp : *lvalp;
1773 case OP_SET: *valp = val; break;
1774 case OP_AND: *valp &= val; break;
1775 case OP_OR: *valp |= val; break;
1781 *lvalp = (unsigned long)-val;
1784 *lvalp = (unsigned long)val;
1791 * init may raise the set.
1794 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1795 void __user *buffer, size_t *lenp, loff_t *ppos)
1799 if (write && !capable(CAP_SYS_MODULE)) {
1803 op = is_init(current) ? OP_SET : OP_AND;
1804 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1805 do_proc_dointvec_bset_conv,&op);
1809 * Taint values can only be increased
1811 static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
1812 void __user *buffer, size_t *lenp, loff_t *ppos)
1816 if (!capable(CAP_SYS_ADMIN))
1820 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1821 do_proc_dointvec_bset_conv,&op);
1824 struct do_proc_dointvec_minmax_conv_param {
1829 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1831 int write, void *data)
1833 struct do_proc_dointvec_minmax_conv_param *param = data;
1835 int val = *negp ? -*lvalp : *lvalp;
1836 if ((param->min && *param->min > val) ||
1837 (param->max && *param->max < val))
1844 *lvalp = (unsigned long)-val;
1847 *lvalp = (unsigned long)val;
1854 * proc_dointvec_minmax - read a vector of integers with min/max values
1855 * @table: the sysctl table
1856 * @write: %TRUE if this is a write to the sysctl file
1857 * @filp: the file structure
1858 * @buffer: the user buffer
1859 * @lenp: the size of the user buffer
1860 * @ppos: file position
1862 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1863 * values from/to the user buffer, treated as an ASCII string.
1865 * This routine will ensure the values are within the range specified by
1866 * table->extra1 (min) and table->extra2 (max).
1868 * Returns 0 on success.
1870 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1871 void __user *buffer, size_t *lenp, loff_t *ppos)
1873 struct do_proc_dointvec_minmax_conv_param param = {
1874 .min = (int *) table->extra1,
1875 .max = (int *) table->extra2,
1877 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1878 do_proc_dointvec_minmax_conv, ¶m);
1881 static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
1883 void __user *buffer,
1884 size_t *lenp, loff_t *ppos,
1885 unsigned long convmul,
1886 unsigned long convdiv)
1888 #define TMPBUFLEN 21
1889 unsigned long *i, *min, *max, val;
1890 int vleft, first=1, neg;
1892 char buf[TMPBUFLEN], *p;
1893 char __user *s = buffer;
1895 if (!data || !table->maxlen || !*lenp ||
1896 (*ppos && !write)) {
1901 i = (unsigned long *) data;
1902 min = (unsigned long *) table->extra1;
1903 max = (unsigned long *) table->extra2;
1904 vleft = table->maxlen / sizeof(unsigned long);
1907 for (; left && vleft--; i++, min++, max++, first=0) {
1922 if (len > TMPBUFLEN-1)
1924 if (copy_from_user(buf, s, len))
1928 if (*p == '-' && left > 1) {
1932 if (*p < '0' || *p > '9')
1934 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1936 if ((len < left) && *p && !isspace(*p))
1945 if ((min && val < *min) || (max && val > *max))
1952 sprintf(p, "%lu", convdiv * (*i) / convmul);
1956 if(copy_to_user(s, buf, len))
1963 if (!write && !first && left) {
1964 if(put_user('\n', s))
1971 if (get_user(c, s++))
1986 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1988 void __user *buffer,
1989 size_t *lenp, loff_t *ppos,
1990 unsigned long convmul,
1991 unsigned long convdiv)
1993 return __do_proc_doulongvec_minmax(table->data, table, write,
1994 filp, buffer, lenp, ppos, convmul, convdiv);
1998 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1999 * @table: the sysctl table
2000 * @write: %TRUE if this is a write to the sysctl file
2001 * @filp: the file structure
2002 * @buffer: the user buffer
2003 * @lenp: the size of the user buffer
2004 * @ppos: file position
2006 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2007 * values from/to the user buffer, treated as an ASCII string.
2009 * This routine will ensure the values are within the range specified by
2010 * table->extra1 (min) and table->extra2 (max).
2012 * Returns 0 on success.
2014 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2015 void __user *buffer, size_t *lenp, loff_t *ppos)
2017 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2021 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2022 * @table: the sysctl table
2023 * @write: %TRUE if this is a write to the sysctl file
2024 * @filp: the file structure
2025 * @buffer: the user buffer
2026 * @lenp: the size of the user buffer
2027 * @ppos: file position
2029 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2030 * values from/to the user buffer, treated as an ASCII string. The values
2031 * are treated as milliseconds, and converted to jiffies when they are stored.
2033 * This routine will ensure the values are within the range specified by
2034 * table->extra1 (min) and table->extra2 (max).
2036 * Returns 0 on success.
2038 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2040 void __user *buffer,
2041 size_t *lenp, loff_t *ppos)
2043 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2044 lenp, ppos, HZ, 1000l);
2048 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2050 int write, void *data)
2053 if (*lvalp > LONG_MAX / HZ)
2055 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2061 lval = (unsigned long)-val;
2064 lval = (unsigned long)val;
2071 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2073 int write, void *data)
2076 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2078 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2084 lval = (unsigned long)-val;
2087 lval = (unsigned long)val;
2089 *lvalp = jiffies_to_clock_t(lval);
2094 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2096 int write, void *data)
2099 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2105 lval = (unsigned long)-val;
2108 lval = (unsigned long)val;
2110 *lvalp = jiffies_to_msecs(lval);
2116 * proc_dointvec_jiffies - read a vector of integers as seconds
2117 * @table: the sysctl table
2118 * @write: %TRUE if this is a write to the sysctl file
2119 * @filp: the file structure
2120 * @buffer: the user buffer
2121 * @lenp: the size of the user buffer
2122 * @ppos: file position
2124 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2125 * values from/to the user buffer, treated as an ASCII string.
2126 * The values read are assumed to be in seconds, and are converted into
2129 * Returns 0 on success.
2131 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2132 void __user *buffer, size_t *lenp, loff_t *ppos)
2134 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2135 do_proc_dointvec_jiffies_conv,NULL);
2139 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2140 * @table: the sysctl table
2141 * @write: %TRUE if this is a write to the sysctl file
2142 * @filp: the file structure
2143 * @buffer: the user buffer
2144 * @lenp: the size of the user buffer
2145 * @ppos: pointer to the file position
2147 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2148 * values from/to the user buffer, treated as an ASCII string.
2149 * The values read are assumed to be in 1/USER_HZ seconds, and
2150 * are converted into jiffies.
2152 * Returns 0 on success.
2154 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2155 void __user *buffer, size_t *lenp, loff_t *ppos)
2157 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2158 do_proc_dointvec_userhz_jiffies_conv,NULL);
2162 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2163 * @table: the sysctl table
2164 * @write: %TRUE if this is a write to the sysctl file
2165 * @filp: the file structure
2166 * @buffer: the user buffer
2167 * @lenp: the size of the user buffer
2168 * @ppos: file position
2169 * @ppos: the current position in the file
2171 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2172 * values from/to the user buffer, treated as an ASCII string.
2173 * The values read are assumed to be in 1/1000 seconds, and
2174 * are converted into jiffies.
2176 * Returns 0 on success.
2178 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2179 void __user *buffer, size_t *lenp, loff_t *ppos)
2181 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2182 do_proc_dointvec_ms_jiffies_conv, NULL);
2185 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2186 void __user *buffer, size_t *lenp, loff_t *ppos)
2188 struct pid *new_pid;
2192 tmp = pid_nr(cad_pid);
2194 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2195 lenp, ppos, NULL, NULL);
2199 new_pid = find_get_pid(tmp);
2203 put_pid(xchg(&cad_pid, new_pid));
2207 #else /* CONFIG_PROC_FS */
2209 int proc_dostring(ctl_table *table, int write, struct file *filp,
2210 void __user *buffer, size_t *lenp, loff_t *ppos)
2215 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2216 void __user *buffer, size_t *lenp, loff_t *ppos)
2221 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2222 void __user *buffer, size_t *lenp, loff_t *ppos)
2227 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2228 void __user *buffer, size_t *lenp, loff_t *ppos)
2233 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2234 void __user *buffer, size_t *lenp, loff_t *ppos)
2239 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2240 void __user *buffer, size_t *lenp, loff_t *ppos)
2245 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2246 void __user *buffer, size_t *lenp, loff_t *ppos)
2251 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2252 void __user *buffer, size_t *lenp, loff_t *ppos)
2257 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2259 void __user *buffer,
2260 size_t *lenp, loff_t *ppos)
2266 #endif /* CONFIG_PROC_FS */
2269 #ifdef CONFIG_SYSCTL_SYSCALL
2271 * General sysctl support routines
2274 /* The generic string strategy routine: */
2275 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2276 void __user *oldval, size_t __user *oldlenp,
2277 void __user *newval, size_t newlen)
2279 if (!table->data || !table->maxlen)
2282 if (oldval && oldlenp) {
2284 if (get_user(bufsize, oldlenp))
2287 size_t len = strlen(table->data), copied;
2289 /* This shouldn't trigger for a well-formed sysctl */
2290 if (len > table->maxlen)
2291 len = table->maxlen;
2293 /* Copy up to a max of bufsize-1 bytes of the string */
2294 copied = (len >= bufsize) ? bufsize - 1 : len;
2296 if (copy_to_user(oldval, table->data, copied) ||
2297 put_user(0, (char __user *)(oldval + copied)))
2299 if (put_user(len, oldlenp))
2303 if (newval && newlen) {
2304 size_t len = newlen;
2305 if (len > table->maxlen)
2306 len = table->maxlen;
2307 if(copy_from_user(table->data, newval, len))
2309 if (len == table->maxlen)
2311 ((char *) table->data)[len] = 0;
2317 * This function makes sure that all of the integers in the vector
2318 * are between the minimum and maximum values given in the arrays
2319 * table->extra1 and table->extra2, respectively.
2321 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2322 void __user *oldval, size_t __user *oldlenp,
2323 void __user *newval, size_t newlen)
2326 if (newval && newlen) {
2327 int __user *vec = (int __user *) newval;
2328 int *min = (int *) table->extra1;
2329 int *max = (int *) table->extra2;
2333 if (newlen % sizeof(int) != 0)
2336 if (!table->extra1 && !table->extra2)
2339 if (newlen > table->maxlen)
2340 newlen = table->maxlen;
2341 length = newlen / sizeof(int);
2343 for (i = 0; i < length; i++) {
2345 if (get_user(value, vec + i))
2347 if (min && value < min[i])
2349 if (max && value > max[i])
2356 /* Strategy function to convert jiffies to seconds */
2357 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2358 void __user *oldval, size_t __user *oldlenp,
2359 void __user *newval, size_t newlen)
2361 if (oldval && oldlenp) {
2364 if (get_user(olen, oldlenp))
2369 if (olen < sizeof(int))
2372 val = *(int *)(table->data) / HZ;
2373 if (put_user(val, (int __user *)oldval))
2375 if (put_user(sizeof(int), oldlenp))
2379 if (newval && newlen) {
2381 if (newlen != sizeof(int))
2383 if (get_user(new, (int __user *)newval))
2385 *(int *)(table->data) = new*HZ;
2390 /* Strategy function to convert jiffies to seconds */
2391 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2392 void __user *oldval, size_t __user *oldlenp,
2393 void __user *newval, size_t newlen)
2395 if (oldval && oldlenp) {
2398 if (get_user(olen, oldlenp))
2403 if (olen < sizeof(int))
2406 val = jiffies_to_msecs(*(int *)(table->data));
2407 if (put_user(val, (int __user *)oldval))
2409 if (put_user(sizeof(int), oldlenp))
2413 if (newval && newlen) {
2415 if (newlen != sizeof(int))
2417 if (get_user(new, (int __user *)newval))
2419 *(int *)(table->data) = msecs_to_jiffies(new);
2426 #else /* CONFIG_SYSCTL_SYSCALL */
2429 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2431 static int msg_count;
2432 struct __sysctl_args tmp;
2433 int name[CTL_MAXNAME];
2436 /* Read in the sysctl name for better debug message logging */
2437 if (copy_from_user(&tmp, args, sizeof(tmp)))
2439 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2441 for (i = 0; i < tmp.nlen; i++)
2442 if (get_user(name[i], tmp.name + i))
2445 /* Ignore accesses to kernel.version */
2446 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2449 if (msg_count < 5) {
2452 "warning: process `%s' used the removed sysctl "
2453 "system call with ", current->comm);
2454 for (i = 0; i < tmp.nlen; i++)
2455 printk("%d.", name[i]);
2462 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2463 void __user *oldval, size_t __user *oldlenp,
2464 void __user *newval, size_t newlen)
2469 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2470 void __user *oldval, size_t __user *oldlenp,
2471 void __user *newval, size_t newlen)
2476 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2477 void __user *oldval, size_t __user *oldlenp,
2478 void __user *newval, size_t newlen)
2483 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2484 void __user *oldval, size_t __user *oldlenp,
2485 void __user *newval, size_t newlen)
2490 #endif /* CONFIG_SYSCTL_SYSCALL */
2493 * No sense putting this after each symbol definition, twice,
2494 * exception granted :-)
2496 EXPORT_SYMBOL(proc_dointvec);
2497 EXPORT_SYMBOL(proc_dointvec_jiffies);
2498 EXPORT_SYMBOL(proc_dointvec_minmax);
2499 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2500 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2501 EXPORT_SYMBOL(proc_dostring);
2502 EXPORT_SYMBOL(proc_doulongvec_minmax);
2503 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2504 EXPORT_SYMBOL(register_sysctl_table);
2505 EXPORT_SYMBOL(sysctl_intvec);
2506 EXPORT_SYMBOL(sysctl_jiffies);
2507 EXPORT_SYMBOL(sysctl_ms_jiffies);
2508 EXPORT_SYMBOL(sysctl_string);
2509 EXPORT_SYMBOL(unregister_sysctl_table);