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;
79 extern int maps_protect;
80 extern int sysctl_stat_interval;
82 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
83 static int maxolduid = 65535;
85 static int min_percpu_pagelist_fract = 8;
87 static int ngroups_max = NGROUPS_MAX;
90 extern char modprobe_path[];
92 #ifdef CONFIG_CHR_DEV_SG
93 extern int sg_big_buff;
97 extern char reboot_command [];
98 extern int stop_a_enabled;
99 extern int scons_pwroff;
103 extern int pwrsw_enabled;
104 extern int unaligned_enabled;
108 #ifdef CONFIG_MATHEMU
109 extern int sysctl_ieee_emulation_warnings;
111 extern int sysctl_userprocess_debug;
112 extern int spin_retry;
115 extern int sysctl_hz_timer;
117 #ifdef CONFIG_BSD_PROCESS_ACCT
118 extern int acct_parm[];
122 extern int no_unaligned_warning;
125 #ifdef CONFIG_RT_MUTEXES
126 extern int max_lock_depth;
129 #ifdef CONFIG_SYSCTL_SYSCALL
130 static int parse_table(int __user *, int, void __user *, size_t __user *,
131 void __user *, size_t, ctl_table *);
135 #ifdef CONFIG_PROC_SYSCTL
136 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
137 void __user *buffer, size_t *lenp, loff_t *ppos);
138 static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
139 void __user *buffer, size_t *lenp, loff_t *ppos);
142 static ctl_table root_table[];
143 static struct ctl_table_header root_table_header =
144 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
146 static ctl_table kern_table[];
147 static ctl_table vm_table[];
148 static ctl_table fs_table[];
149 static ctl_table debug_table[];
150 static ctl_table dev_table[];
151 extern ctl_table random_table[];
152 #ifdef CONFIG_UNIX98_PTYS
153 extern ctl_table pty_table[];
155 #ifdef CONFIG_INOTIFY_USER
156 extern ctl_table inotify_table[];
159 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
160 int sysctl_legacy_va_layout;
164 /* The default sysctl tables: */
166 static ctl_table root_table[] = {
168 .ctl_name = CTL_KERN,
169 .procname = "kernel",
194 .ctl_name = CTL_DEBUG,
197 .child = debug_table,
209 static ctl_table kern_table[] = {
211 .ctl_name = KERN_PANIC,
213 .data = &panic_timeout,
214 .maxlen = sizeof(int),
216 .proc_handler = &proc_dointvec,
219 .ctl_name = KERN_CORE_USES_PID,
220 .procname = "core_uses_pid",
221 .data = &core_uses_pid,
222 .maxlen = sizeof(int),
224 .proc_handler = &proc_dointvec,
227 .ctl_name = KERN_CORE_PATTERN,
228 .procname = "core_pattern",
229 .data = core_pattern,
232 .proc_handler = &proc_dostring,
233 .strategy = &sysctl_string,
235 #ifdef CONFIG_PROC_SYSCTL
237 .ctl_name = KERN_TAINTED,
238 .procname = "tainted",
240 .maxlen = sizeof(int),
242 .proc_handler = &proc_dointvec_taint,
246 .ctl_name = KERN_CAP_BSET,
247 .procname = "cap-bound",
249 .maxlen = sizeof(kernel_cap_t),
251 .proc_handler = &proc_dointvec_bset,
253 #ifdef CONFIG_BLK_DEV_INITRD
255 .ctl_name = KERN_REALROOTDEV,
256 .procname = "real-root-dev",
257 .data = &real_root_dev,
258 .maxlen = sizeof(int),
260 .proc_handler = &proc_dointvec,
265 .ctl_name = KERN_SPARC_REBOOT,
266 .procname = "reboot-cmd",
267 .data = reboot_command,
270 .proc_handler = &proc_dostring,
271 .strategy = &sysctl_string,
274 .ctl_name = KERN_SPARC_STOP_A,
275 .procname = "stop-a",
276 .data = &stop_a_enabled,
277 .maxlen = sizeof (int),
279 .proc_handler = &proc_dointvec,
282 .ctl_name = KERN_SPARC_SCONS_PWROFF,
283 .procname = "scons-poweroff",
284 .data = &scons_pwroff,
285 .maxlen = sizeof (int),
287 .proc_handler = &proc_dointvec,
292 .ctl_name = KERN_HPPA_PWRSW,
293 .procname = "soft-power",
294 .data = &pwrsw_enabled,
295 .maxlen = sizeof (int),
297 .proc_handler = &proc_dointvec,
300 .ctl_name = KERN_HPPA_UNALIGNED,
301 .procname = "unaligned-trap",
302 .data = &unaligned_enabled,
303 .maxlen = sizeof (int),
305 .proc_handler = &proc_dointvec,
309 .ctl_name = KERN_CTLALTDEL,
310 .procname = "ctrl-alt-del",
312 .maxlen = sizeof(int),
314 .proc_handler = &proc_dointvec,
317 .ctl_name = KERN_PRINTK,
318 .procname = "printk",
319 .data = &console_loglevel,
320 .maxlen = 4*sizeof(int),
322 .proc_handler = &proc_dointvec,
326 .ctl_name = KERN_MODPROBE,
327 .procname = "modprobe",
328 .data = &modprobe_path,
329 .maxlen = KMOD_PATH_LEN,
331 .proc_handler = &proc_dostring,
332 .strategy = &sysctl_string,
335 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
337 .ctl_name = KERN_HOTPLUG,
338 .procname = "hotplug",
339 .data = &uevent_helper,
340 .maxlen = UEVENT_HELPER_PATH_LEN,
342 .proc_handler = &proc_dostring,
343 .strategy = &sysctl_string,
346 #ifdef CONFIG_CHR_DEV_SG
348 .ctl_name = KERN_SG_BIG_BUFF,
349 .procname = "sg-big-buff",
350 .data = &sg_big_buff,
351 .maxlen = sizeof (int),
353 .proc_handler = &proc_dointvec,
356 #ifdef CONFIG_BSD_PROCESS_ACCT
358 .ctl_name = KERN_ACCT,
361 .maxlen = 3*sizeof(int),
363 .proc_handler = &proc_dointvec,
366 #ifdef CONFIG_MAGIC_SYSRQ
368 .ctl_name = KERN_SYSRQ,
370 .data = &__sysrq_enabled,
371 .maxlen = sizeof (int),
373 .proc_handler = &proc_dointvec,
376 #ifdef CONFIG_PROC_SYSCTL
378 .ctl_name = KERN_CADPID,
379 .procname = "cad_pid",
381 .maxlen = sizeof (int),
383 .proc_handler = &proc_do_cad_pid,
387 .ctl_name = KERN_MAX_THREADS,
388 .procname = "threads-max",
389 .data = &max_threads,
390 .maxlen = sizeof(int),
392 .proc_handler = &proc_dointvec,
395 .ctl_name = KERN_RANDOM,
396 .procname = "random",
398 .child = random_table,
400 #ifdef CONFIG_UNIX98_PTYS
402 .ctl_name = KERN_PTY,
409 .ctl_name = KERN_OVERFLOWUID,
410 .procname = "overflowuid",
411 .data = &overflowuid,
412 .maxlen = sizeof(int),
414 .proc_handler = &proc_dointvec_minmax,
415 .strategy = &sysctl_intvec,
416 .extra1 = &minolduid,
417 .extra2 = &maxolduid,
420 .ctl_name = KERN_OVERFLOWGID,
421 .procname = "overflowgid",
422 .data = &overflowgid,
423 .maxlen = sizeof(int),
425 .proc_handler = &proc_dointvec_minmax,
426 .strategy = &sysctl_intvec,
427 .extra1 = &minolduid,
428 .extra2 = &maxolduid,
431 #ifdef CONFIG_MATHEMU
433 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
434 .procname = "ieee_emulation_warnings",
435 .data = &sysctl_ieee_emulation_warnings,
436 .maxlen = sizeof(int),
438 .proc_handler = &proc_dointvec,
441 #ifdef CONFIG_NO_IDLE_HZ
443 .ctl_name = KERN_HZ_TIMER,
444 .procname = "hz_timer",
445 .data = &sysctl_hz_timer,
446 .maxlen = sizeof(int),
448 .proc_handler = &proc_dointvec,
452 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
453 .procname = "userprocess_debug",
454 .data = &sysctl_userprocess_debug,
455 .maxlen = sizeof(int),
457 .proc_handler = &proc_dointvec,
461 .ctl_name = KERN_PIDMAX,
462 .procname = "pid_max",
464 .maxlen = sizeof (int),
466 .proc_handler = &proc_dointvec_minmax,
467 .strategy = sysctl_intvec,
468 .extra1 = &pid_max_min,
469 .extra2 = &pid_max_max,
472 .ctl_name = KERN_PANIC_ON_OOPS,
473 .procname = "panic_on_oops",
474 .data = &panic_on_oops,
475 .maxlen = sizeof(int),
477 .proc_handler = &proc_dointvec,
480 .ctl_name = KERN_PRINTK_RATELIMIT,
481 .procname = "printk_ratelimit",
482 .data = &printk_ratelimit_jiffies,
483 .maxlen = sizeof(int),
485 .proc_handler = &proc_dointvec_jiffies,
486 .strategy = &sysctl_jiffies,
489 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
490 .procname = "printk_ratelimit_burst",
491 .data = &printk_ratelimit_burst,
492 .maxlen = sizeof(int),
494 .proc_handler = &proc_dointvec,
497 .ctl_name = KERN_NGROUPS_MAX,
498 .procname = "ngroups_max",
499 .data = &ngroups_max,
500 .maxlen = sizeof (int),
502 .proc_handler = &proc_dointvec,
504 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
506 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
507 .procname = "unknown_nmi_panic",
508 .data = &unknown_nmi_panic,
509 .maxlen = sizeof (int),
511 .proc_handler = &proc_dointvec,
514 .ctl_name = KERN_NMI_WATCHDOG,
515 .procname = "nmi_watchdog",
516 .data = &nmi_watchdog_enabled,
517 .maxlen = sizeof (int),
519 .proc_handler = &proc_nmi_enabled,
522 #if defined(CONFIG_X86)
524 .ctl_name = KERN_PANIC_ON_NMI,
525 .procname = "panic_on_unrecovered_nmi",
526 .data = &panic_on_unrecovered_nmi,
527 .maxlen = sizeof(int),
529 .proc_handler = &proc_dointvec,
532 .ctl_name = KERN_BOOTLOADER_TYPE,
533 .procname = "bootloader_type",
534 .data = &bootloader_type,
535 .maxlen = sizeof (int),
537 .proc_handler = &proc_dointvec,
540 .ctl_name = CTL_UNNUMBERED,
541 .procname = "kstack_depth_to_print",
542 .data = &kstack_depth_to_print,
543 .maxlen = sizeof(int),
545 .proc_handler = &proc_dointvec,
548 #if defined(CONFIG_MMU)
550 .ctl_name = KERN_RANDOMIZE,
551 .procname = "randomize_va_space",
552 .data = &randomize_va_space,
553 .maxlen = sizeof(int),
555 .proc_handler = &proc_dointvec,
558 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
560 .ctl_name = KERN_SPIN_RETRY,
561 .procname = "spin_retry",
563 .maxlen = sizeof (int),
565 .proc_handler = &proc_dointvec,
568 #ifdef CONFIG_ACPI_SLEEP
570 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
571 .procname = "acpi_video_flags",
572 .data = &acpi_video_flags,
573 .maxlen = sizeof (unsigned long),
575 .proc_handler = &proc_doulongvec_minmax,
580 .ctl_name = KERN_IA64_UNALIGNED,
581 .procname = "ignore-unaligned-usertrap",
582 .data = &no_unaligned_warning,
583 .maxlen = sizeof (int),
585 .proc_handler = &proc_dointvec,
590 .ctl_name = KERN_COMPAT_LOG,
591 .procname = "compat-log",
593 .maxlen = sizeof (int),
595 .proc_handler = &proc_dointvec,
598 #ifdef CONFIG_RT_MUTEXES
600 .ctl_name = KERN_MAX_LOCK_DEPTH,
601 .procname = "max_lock_depth",
602 .data = &max_lock_depth,
603 .maxlen = sizeof(int),
605 .proc_handler = &proc_dointvec,
608 #ifdef CONFIG_PROC_FS
610 .ctl_name = CTL_UNNUMBERED,
611 .procname = "maps_protect",
612 .data = &maps_protect,
613 .maxlen = sizeof(int),
615 .proc_handler = &proc_dointvec,
622 /* Constants for minimum and maximum testing in vm_table.
623 We use these as one-element integer vectors. */
625 static int one_hundred = 100;
628 static ctl_table vm_table[] = {
630 .ctl_name = VM_OVERCOMMIT_MEMORY,
631 .procname = "overcommit_memory",
632 .data = &sysctl_overcommit_memory,
633 .maxlen = sizeof(sysctl_overcommit_memory),
635 .proc_handler = &proc_dointvec,
638 .ctl_name = VM_PANIC_ON_OOM,
639 .procname = "panic_on_oom",
640 .data = &sysctl_panic_on_oom,
641 .maxlen = sizeof(sysctl_panic_on_oom),
643 .proc_handler = &proc_dointvec,
646 .ctl_name = VM_OVERCOMMIT_RATIO,
647 .procname = "overcommit_ratio",
648 .data = &sysctl_overcommit_ratio,
649 .maxlen = sizeof(sysctl_overcommit_ratio),
651 .proc_handler = &proc_dointvec,
654 .ctl_name = VM_PAGE_CLUSTER,
655 .procname = "page-cluster",
656 .data = &page_cluster,
657 .maxlen = sizeof(int),
659 .proc_handler = &proc_dointvec,
662 .ctl_name = VM_DIRTY_BACKGROUND,
663 .procname = "dirty_background_ratio",
664 .data = &dirty_background_ratio,
665 .maxlen = sizeof(dirty_background_ratio),
667 .proc_handler = &proc_dointvec_minmax,
668 .strategy = &sysctl_intvec,
670 .extra2 = &one_hundred,
673 .ctl_name = VM_DIRTY_RATIO,
674 .procname = "dirty_ratio",
675 .data = &vm_dirty_ratio,
676 .maxlen = sizeof(vm_dirty_ratio),
678 .proc_handler = &proc_dointvec_minmax,
679 .strategy = &sysctl_intvec,
681 .extra2 = &one_hundred,
684 .ctl_name = VM_DIRTY_WB_CS,
685 .procname = "dirty_writeback_centisecs",
686 .data = &dirty_writeback_interval,
687 .maxlen = sizeof(dirty_writeback_interval),
689 .proc_handler = &dirty_writeback_centisecs_handler,
692 .ctl_name = VM_DIRTY_EXPIRE_CS,
693 .procname = "dirty_expire_centisecs",
694 .data = &dirty_expire_interval,
695 .maxlen = sizeof(dirty_expire_interval),
697 .proc_handler = &proc_dointvec_userhz_jiffies,
700 .ctl_name = VM_NR_PDFLUSH_THREADS,
701 .procname = "nr_pdflush_threads",
702 .data = &nr_pdflush_threads,
703 .maxlen = sizeof nr_pdflush_threads,
704 .mode = 0444 /* read-only*/,
705 .proc_handler = &proc_dointvec,
708 .ctl_name = VM_SWAPPINESS,
709 .procname = "swappiness",
710 .data = &vm_swappiness,
711 .maxlen = sizeof(vm_swappiness),
713 .proc_handler = &proc_dointvec_minmax,
714 .strategy = &sysctl_intvec,
716 .extra2 = &one_hundred,
718 #ifdef CONFIG_HUGETLB_PAGE
720 .ctl_name = VM_HUGETLB_PAGES,
721 .procname = "nr_hugepages",
722 .data = &max_huge_pages,
723 .maxlen = sizeof(unsigned long),
725 .proc_handler = &hugetlb_sysctl_handler,
726 .extra1 = (void *)&hugetlb_zero,
727 .extra2 = (void *)&hugetlb_infinity,
730 .ctl_name = VM_HUGETLB_GROUP,
731 .procname = "hugetlb_shm_group",
732 .data = &sysctl_hugetlb_shm_group,
733 .maxlen = sizeof(gid_t),
735 .proc_handler = &proc_dointvec,
739 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
740 .procname = "lowmem_reserve_ratio",
741 .data = &sysctl_lowmem_reserve_ratio,
742 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
744 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
745 .strategy = &sysctl_intvec,
748 .ctl_name = VM_DROP_PAGECACHE,
749 .procname = "drop_caches",
750 .data = &sysctl_drop_caches,
751 .maxlen = sizeof(int),
753 .proc_handler = drop_caches_sysctl_handler,
754 .strategy = &sysctl_intvec,
757 .ctl_name = VM_MIN_FREE_KBYTES,
758 .procname = "min_free_kbytes",
759 .data = &min_free_kbytes,
760 .maxlen = sizeof(min_free_kbytes),
762 .proc_handler = &min_free_kbytes_sysctl_handler,
763 .strategy = &sysctl_intvec,
767 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
768 .procname = "percpu_pagelist_fraction",
769 .data = &percpu_pagelist_fraction,
770 .maxlen = sizeof(percpu_pagelist_fraction),
772 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
773 .strategy = &sysctl_intvec,
774 .extra1 = &min_percpu_pagelist_fract,
778 .ctl_name = VM_MAX_MAP_COUNT,
779 .procname = "max_map_count",
780 .data = &sysctl_max_map_count,
781 .maxlen = sizeof(sysctl_max_map_count),
783 .proc_handler = &proc_dointvec
787 .ctl_name = VM_LAPTOP_MODE,
788 .procname = "laptop_mode",
789 .data = &laptop_mode,
790 .maxlen = sizeof(laptop_mode),
792 .proc_handler = &proc_dointvec_jiffies,
793 .strategy = &sysctl_jiffies,
796 .ctl_name = VM_BLOCK_DUMP,
797 .procname = "block_dump",
799 .maxlen = sizeof(block_dump),
801 .proc_handler = &proc_dointvec,
802 .strategy = &sysctl_intvec,
806 .ctl_name = VM_VFS_CACHE_PRESSURE,
807 .procname = "vfs_cache_pressure",
808 .data = &sysctl_vfs_cache_pressure,
809 .maxlen = sizeof(sysctl_vfs_cache_pressure),
811 .proc_handler = &proc_dointvec,
812 .strategy = &sysctl_intvec,
815 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
817 .ctl_name = VM_LEGACY_VA_LAYOUT,
818 .procname = "legacy_va_layout",
819 .data = &sysctl_legacy_va_layout,
820 .maxlen = sizeof(sysctl_legacy_va_layout),
822 .proc_handler = &proc_dointvec,
823 .strategy = &sysctl_intvec,
829 .ctl_name = VM_ZONE_RECLAIM_MODE,
830 .procname = "zone_reclaim_mode",
831 .data = &zone_reclaim_mode,
832 .maxlen = sizeof(zone_reclaim_mode),
834 .proc_handler = &proc_dointvec,
835 .strategy = &sysctl_intvec,
839 .ctl_name = VM_MIN_UNMAPPED,
840 .procname = "min_unmapped_ratio",
841 .data = &sysctl_min_unmapped_ratio,
842 .maxlen = sizeof(sysctl_min_unmapped_ratio),
844 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
845 .strategy = &sysctl_intvec,
847 .extra2 = &one_hundred,
850 .ctl_name = VM_MIN_SLAB,
851 .procname = "min_slab_ratio",
852 .data = &sysctl_min_slab_ratio,
853 .maxlen = sizeof(sysctl_min_slab_ratio),
855 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
856 .strategy = &sysctl_intvec,
858 .extra2 = &one_hundred,
863 .ctl_name = CTL_UNNUMBERED,
864 .procname = "stat_interval",
865 .data = &sysctl_stat_interval,
866 .maxlen = sizeof(sysctl_stat_interval),
868 .proc_handler = &proc_dointvec_jiffies,
869 .strategy = &sysctl_jiffies,
872 #if defined(CONFIG_X86_32) || \
873 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
875 .ctl_name = VM_VDSO_ENABLED,
876 .procname = "vdso_enabled",
877 .data = &vdso_enabled,
878 .maxlen = sizeof(vdso_enabled),
880 .proc_handler = &proc_dointvec,
881 .strategy = &sysctl_intvec,
888 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
889 static ctl_table binfmt_misc_table[] = {
894 static ctl_table fs_table[] = {
896 .ctl_name = FS_NRINODE,
897 .procname = "inode-nr",
898 .data = &inodes_stat,
899 .maxlen = 2*sizeof(int),
901 .proc_handler = &proc_dointvec,
904 .ctl_name = FS_STATINODE,
905 .procname = "inode-state",
906 .data = &inodes_stat,
907 .maxlen = 7*sizeof(int),
909 .proc_handler = &proc_dointvec,
912 .ctl_name = FS_NRFILE,
913 .procname = "file-nr",
915 .maxlen = 3*sizeof(int),
917 .proc_handler = &proc_nr_files,
920 .ctl_name = FS_MAXFILE,
921 .procname = "file-max",
922 .data = &files_stat.max_files,
923 .maxlen = sizeof(int),
925 .proc_handler = &proc_dointvec,
928 .ctl_name = FS_DENTRY,
929 .procname = "dentry-state",
930 .data = &dentry_stat,
931 .maxlen = 6*sizeof(int),
933 .proc_handler = &proc_dointvec,
936 .ctl_name = FS_OVERFLOWUID,
937 .procname = "overflowuid",
938 .data = &fs_overflowuid,
939 .maxlen = sizeof(int),
941 .proc_handler = &proc_dointvec_minmax,
942 .strategy = &sysctl_intvec,
943 .extra1 = &minolduid,
944 .extra2 = &maxolduid,
947 .ctl_name = FS_OVERFLOWGID,
948 .procname = "overflowgid",
949 .data = &fs_overflowgid,
950 .maxlen = sizeof(int),
952 .proc_handler = &proc_dointvec_minmax,
953 .strategy = &sysctl_intvec,
954 .extra1 = &minolduid,
955 .extra2 = &maxolduid,
958 .ctl_name = FS_LEASES,
959 .procname = "leases-enable",
960 .data = &leases_enable,
961 .maxlen = sizeof(int),
963 .proc_handler = &proc_dointvec,
965 #ifdef CONFIG_DNOTIFY
967 .ctl_name = FS_DIR_NOTIFY,
968 .procname = "dir-notify-enable",
969 .data = &dir_notify_enable,
970 .maxlen = sizeof(int),
972 .proc_handler = &proc_dointvec,
977 .ctl_name = FS_LEASE_TIME,
978 .procname = "lease-break-time",
979 .data = &lease_break_time,
980 .maxlen = sizeof(int),
982 .proc_handler = &proc_dointvec,
985 .ctl_name = FS_AIO_NR,
986 .procname = "aio-nr",
988 .maxlen = sizeof(aio_nr),
990 .proc_handler = &proc_doulongvec_minmax,
993 .ctl_name = FS_AIO_MAX_NR,
994 .procname = "aio-max-nr",
996 .maxlen = sizeof(aio_max_nr),
998 .proc_handler = &proc_doulongvec_minmax,
1000 #ifdef CONFIG_INOTIFY_USER
1002 .ctl_name = FS_INOTIFY,
1003 .procname = "inotify",
1005 .child = inotify_table,
1010 .ctl_name = KERN_SETUID_DUMPABLE,
1011 .procname = "suid_dumpable",
1012 .data = &suid_dumpable,
1013 .maxlen = sizeof(int),
1015 .proc_handler = &proc_dointvec,
1017 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1019 .ctl_name = CTL_UNNUMBERED,
1020 .procname = "binfmt_misc",
1022 .child = binfmt_misc_table,
1028 static ctl_table debug_table[] = {
1032 static ctl_table dev_table[] = {
1036 static DEFINE_SPINLOCK(sysctl_lock);
1038 /* called under sysctl_lock */
1039 static int use_table(struct ctl_table_header *p)
1041 if (unlikely(p->unregistering))
1047 /* called under sysctl_lock */
1048 static void unuse_table(struct ctl_table_header *p)
1051 if (unlikely(p->unregistering))
1052 complete(p->unregistering);
1055 /* called under sysctl_lock, will reacquire if has to wait */
1056 static void start_unregistering(struct ctl_table_header *p)
1059 * if p->used is 0, nobody will ever touch that entry again;
1060 * we'll eliminate all paths to it before dropping sysctl_lock
1062 if (unlikely(p->used)) {
1063 struct completion wait;
1064 init_completion(&wait);
1065 p->unregistering = &wait;
1066 spin_unlock(&sysctl_lock);
1067 wait_for_completion(&wait);
1068 spin_lock(&sysctl_lock);
1071 * do not remove from the list until nobody holds it; walking the
1072 * list in do_sysctl() relies on that.
1074 list_del_init(&p->ctl_entry);
1077 void sysctl_head_finish(struct ctl_table_header *head)
1081 spin_lock(&sysctl_lock);
1083 spin_unlock(&sysctl_lock);
1086 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1088 struct ctl_table_header *head;
1089 struct list_head *tmp;
1090 spin_lock(&sysctl_lock);
1092 tmp = &prev->ctl_entry;
1096 tmp = &root_table_header.ctl_entry;
1098 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1100 if (!use_table(head))
1102 spin_unlock(&sysctl_lock);
1106 if (tmp == &root_table_header.ctl_entry)
1109 spin_unlock(&sysctl_lock);
1113 #ifdef CONFIG_SYSCTL_SYSCALL
1114 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1115 void __user *newval, size_t newlen)
1117 struct ctl_table_header *head;
1118 int error = -ENOTDIR;
1120 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1124 if (!oldlenp || get_user(old_len, oldlenp))
1128 for (head = sysctl_head_next(NULL); head;
1129 head = sysctl_head_next(head)) {
1130 error = parse_table(name, nlen, oldval, oldlenp,
1131 newval, newlen, head->ctl_table);
1132 if (error != -ENOTDIR) {
1133 sysctl_head_finish(head);
1140 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1142 struct __sysctl_args tmp;
1145 if (copy_from_user(&tmp, args, sizeof(tmp)))
1149 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1150 tmp.newval, tmp.newlen);
1154 #endif /* CONFIG_SYSCTL_SYSCALL */
1157 * sysctl_perm does NOT grant the superuser all rights automatically, because
1158 * some sysctl variables are readonly even to root.
1161 static int test_perm(int mode, int op)
1165 else if (in_egroup_p(0))
1167 if ((mode & op & 0007) == op)
1172 int sysctl_perm(ctl_table *table, int op)
1175 error = security_sysctl(table, op);
1178 return test_perm(table->mode, op);
1181 #ifdef CONFIG_SYSCTL_SYSCALL
1182 static int parse_table(int __user *name, int nlen,
1183 void __user *oldval, size_t __user *oldlenp,
1184 void __user *newval, size_t newlen,
1191 if (get_user(n, name))
1193 for ( ; table->ctl_name || table->procname; table++) {
1194 if (!table->ctl_name)
1196 if (n == table->ctl_name) {
1199 if (sysctl_perm(table, 001))
1203 table = table->child;
1206 error = do_sysctl_strategy(table, name, nlen,
1215 /* Perform the actual read/write of a sysctl table entry. */
1216 int do_sysctl_strategy (ctl_table *table,
1217 int __user *name, int nlen,
1218 void __user *oldval, size_t __user *oldlenp,
1219 void __user *newval, size_t newlen)
1228 if (sysctl_perm(table, op))
1231 if (table->strategy) {
1232 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1240 /* If there is no strategy routine, or if the strategy returns
1241 * zero, proceed with automatic r/w */
1242 if (table->data && table->maxlen) {
1243 if (oldval && oldlenp) {
1244 if (get_user(len, oldlenp))
1247 if (len > table->maxlen)
1248 len = table->maxlen;
1249 if(copy_to_user(oldval, table->data, len))
1251 if(put_user(len, oldlenp))
1255 if (newval && newlen) {
1257 if (len > table->maxlen)
1258 len = table->maxlen;
1259 if(copy_from_user(table->data, newval, len))
1265 #endif /* CONFIG_SYSCTL_SYSCALL */
1267 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1269 for (; table->ctl_name || table->procname; table++) {
1270 table->parent = parent;
1272 sysctl_set_parent(table, table->child);
1276 static __init int sysctl_init(void)
1278 sysctl_set_parent(NULL, root_table);
1282 core_initcall(sysctl_init);
1285 * register_sysctl_table - register a sysctl hierarchy
1286 * @table: the top-level table structure
1288 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1289 * array. An entry with a ctl_name of 0 terminates the table.
1291 * The members of the &ctl_table structure are used as follows:
1293 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1294 * must be unique within that level of sysctl
1296 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1297 * enter a sysctl file
1299 * data - a pointer to data for use by proc_handler
1301 * maxlen - the maximum size in bytes of the data
1303 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1305 * child - a pointer to the child sysctl table if this entry is a directory, or
1308 * proc_handler - the text handler routine (described below)
1310 * strategy - the strategy routine (described below)
1312 * de - for internal use by the sysctl routines
1314 * extra1, extra2 - extra pointers usable by the proc handler routines
1316 * Leaf nodes in the sysctl tree will be represented by a single file
1317 * under /proc; non-leaf nodes will be represented by directories.
1319 * sysctl(2) can automatically manage read and write requests through
1320 * the sysctl table. The data and maxlen fields of the ctl_table
1321 * struct enable minimal validation of the values being written to be
1322 * performed, and the mode field allows minimal authentication.
1324 * More sophisticated management can be enabled by the provision of a
1325 * strategy routine with the table entry. This will be called before
1326 * any automatic read or write of the data is performed.
1328 * The strategy routine may return
1330 * < 0 - Error occurred (error is passed to user process)
1332 * 0 - OK - proceed with automatic read or write.
1334 * > 0 - OK - read or write has been done by the strategy routine, so
1335 * return immediately.
1337 * There must be a proc_handler routine for any terminal nodes
1338 * mirrored under /proc/sys (non-terminals are handled by a built-in
1339 * directory handler). Several default handlers are available to
1340 * cover common cases -
1342 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1343 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1344 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1346 * It is the handler's job to read the input buffer from user memory
1347 * and process it. The handler should return 0 on success.
1349 * This routine returns %NULL on a failure to register, and a pointer
1350 * to the table header on success.
1352 struct ctl_table_header *register_sysctl_table(ctl_table * table)
1354 struct ctl_table_header *tmp;
1355 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1358 tmp->ctl_table = table;
1359 INIT_LIST_HEAD(&tmp->ctl_entry);
1361 tmp->unregistering = NULL;
1362 sysctl_set_parent(NULL, table);
1363 spin_lock(&sysctl_lock);
1364 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1365 spin_unlock(&sysctl_lock);
1370 * unregister_sysctl_table - unregister a sysctl table hierarchy
1371 * @header: the header returned from register_sysctl_table
1373 * Unregisters the sysctl table and all children. proc entries may not
1374 * actually be removed until they are no longer used by anyone.
1376 void unregister_sysctl_table(struct ctl_table_header * header)
1379 spin_lock(&sysctl_lock);
1380 start_unregistering(header);
1381 spin_unlock(&sysctl_lock);
1385 #else /* !CONFIG_SYSCTL */
1386 struct ctl_table_header *register_sysctl_table(ctl_table * table)
1391 void unregister_sysctl_table(struct ctl_table_header * table)
1395 #endif /* CONFIG_SYSCTL */
1401 #ifdef CONFIG_PROC_SYSCTL
1403 static int _proc_do_string(void* data, int maxlen, int write,
1404 struct file *filp, void __user *buffer,
1405 size_t *lenp, loff_t *ppos)
1411 if (!data || !maxlen || !*lenp) {
1419 while (len < *lenp) {
1420 if (get_user(c, p++))
1422 if (c == 0 || c == '\n')
1428 if(copy_from_user(data, buffer, len))
1430 ((char *) data)[len] = 0;
1448 if(copy_to_user(buffer, data, len))
1451 if(put_user('\n', ((char __user *) buffer) + len))
1462 * proc_dostring - read a string sysctl
1463 * @table: the sysctl table
1464 * @write: %TRUE if this is a write to the sysctl file
1465 * @filp: the file structure
1466 * @buffer: the user buffer
1467 * @lenp: the size of the user buffer
1468 * @ppos: file position
1470 * Reads/writes a string from/to the user buffer. If the kernel
1471 * buffer provided is not large enough to hold the string, the
1472 * string is truncated. The copied string is %NULL-terminated.
1473 * If the string is being read by the user process, it is copied
1474 * and a newline '\n' is added. It is truncated if the buffer is
1477 * Returns 0 on success.
1479 int proc_dostring(ctl_table *table, int write, struct file *filp,
1480 void __user *buffer, size_t *lenp, loff_t *ppos)
1482 return _proc_do_string(table->data, table->maxlen, write, filp,
1483 buffer, lenp, ppos);
1487 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1489 int write, void *data)
1492 *valp = *negp ? -*lvalp : *lvalp;
1497 *lvalp = (unsigned long)-val;
1500 *lvalp = (unsigned long)val;
1506 static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1507 int write, struct file *filp, void __user *buffer,
1508 size_t *lenp, loff_t *ppos,
1509 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1510 int write, void *data),
1513 #define TMPBUFLEN 21
1514 int *i, vleft, first=1, neg, val;
1518 char buf[TMPBUFLEN], *p;
1519 char __user *s = buffer;
1521 if (!tbl_data || !table->maxlen || !*lenp ||
1522 (*ppos && !write)) {
1527 i = (int *) tbl_data;
1528 vleft = table->maxlen / sizeof(*i);
1532 conv = do_proc_dointvec_conv;
1534 for (; left && vleft--; i++, first=0) {
1549 if (len > sizeof(buf) - 1)
1550 len = sizeof(buf) - 1;
1551 if (copy_from_user(buf, s, len))
1555 if (*p == '-' && left > 1) {
1559 if (*p < '0' || *p > '9')
1562 lval = simple_strtoul(p, &p, 0);
1565 if ((len < left) && *p && !isspace(*p))
1572 if (conv(&neg, &lval, i, 1, data))
1579 if (conv(&neg, &lval, i, 0, data))
1582 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1586 if(copy_to_user(s, buf, len))
1593 if (!write && !first && left) {
1594 if(put_user('\n', s))
1601 if (get_user(c, s++))
1616 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1617 void __user *buffer, size_t *lenp, loff_t *ppos,
1618 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1619 int write, void *data),
1622 return __do_proc_dointvec(table->data, table, write, filp,
1623 buffer, lenp, ppos, conv, data);
1627 * proc_dointvec - read a vector of integers
1628 * @table: the sysctl table
1629 * @write: %TRUE if this is a write to the sysctl file
1630 * @filp: the file structure
1631 * @buffer: the user buffer
1632 * @lenp: the size of the user buffer
1633 * @ppos: file position
1635 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1636 * values from/to the user buffer, treated as an ASCII string.
1638 * Returns 0 on success.
1640 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1641 void __user *buffer, size_t *lenp, loff_t *ppos)
1643 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1651 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1653 int write, void *data)
1655 int op = *(int *)data;
1657 int val = *negp ? -*lvalp : *lvalp;
1659 case OP_SET: *valp = val; break;
1660 case OP_AND: *valp &= val; break;
1661 case OP_OR: *valp |= val; break;
1667 *lvalp = (unsigned long)-val;
1670 *lvalp = (unsigned long)val;
1677 * init may raise the set.
1680 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1681 void __user *buffer, size_t *lenp, loff_t *ppos)
1685 if (write && !capable(CAP_SYS_MODULE)) {
1689 op = is_init(current) ? OP_SET : OP_AND;
1690 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1691 do_proc_dointvec_bset_conv,&op);
1695 * Taint values can only be increased
1697 static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
1698 void __user *buffer, size_t *lenp, loff_t *ppos)
1702 if (write && !capable(CAP_SYS_ADMIN))
1706 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1707 do_proc_dointvec_bset_conv,&op);
1710 struct do_proc_dointvec_minmax_conv_param {
1715 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1717 int write, void *data)
1719 struct do_proc_dointvec_minmax_conv_param *param = data;
1721 int val = *negp ? -*lvalp : *lvalp;
1722 if ((param->min && *param->min > val) ||
1723 (param->max && *param->max < val))
1730 *lvalp = (unsigned long)-val;
1733 *lvalp = (unsigned long)val;
1740 * proc_dointvec_minmax - read a vector of integers with min/max values
1741 * @table: the sysctl table
1742 * @write: %TRUE if this is a write to the sysctl file
1743 * @filp: the file structure
1744 * @buffer: the user buffer
1745 * @lenp: the size of the user buffer
1746 * @ppos: file position
1748 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1749 * values from/to the user buffer, treated as an ASCII string.
1751 * This routine will ensure the values are within the range specified by
1752 * table->extra1 (min) and table->extra2 (max).
1754 * Returns 0 on success.
1756 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1757 void __user *buffer, size_t *lenp, loff_t *ppos)
1759 struct do_proc_dointvec_minmax_conv_param param = {
1760 .min = (int *) table->extra1,
1761 .max = (int *) table->extra2,
1763 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1764 do_proc_dointvec_minmax_conv, ¶m);
1767 static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
1769 void __user *buffer,
1770 size_t *lenp, loff_t *ppos,
1771 unsigned long convmul,
1772 unsigned long convdiv)
1774 #define TMPBUFLEN 21
1775 unsigned long *i, *min, *max, val;
1776 int vleft, first=1, neg;
1778 char buf[TMPBUFLEN], *p;
1779 char __user *s = buffer;
1781 if (!data || !table->maxlen || !*lenp ||
1782 (*ppos && !write)) {
1787 i = (unsigned long *) data;
1788 min = (unsigned long *) table->extra1;
1789 max = (unsigned long *) table->extra2;
1790 vleft = table->maxlen / sizeof(unsigned long);
1793 for (; left && vleft--; i++, min++, max++, first=0) {
1808 if (len > TMPBUFLEN-1)
1810 if (copy_from_user(buf, s, len))
1814 if (*p == '-' && left > 1) {
1818 if (*p < '0' || *p > '9')
1820 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1822 if ((len < left) && *p && !isspace(*p))
1831 if ((min && val < *min) || (max && val > *max))
1838 sprintf(p, "%lu", convdiv * (*i) / convmul);
1842 if(copy_to_user(s, buf, len))
1849 if (!write && !first && left) {
1850 if(put_user('\n', s))
1857 if (get_user(c, s++))
1872 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1874 void __user *buffer,
1875 size_t *lenp, loff_t *ppos,
1876 unsigned long convmul,
1877 unsigned long convdiv)
1879 return __do_proc_doulongvec_minmax(table->data, table, write,
1880 filp, buffer, lenp, ppos, convmul, convdiv);
1884 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1885 * @table: the sysctl table
1886 * @write: %TRUE if this is a write to the sysctl file
1887 * @filp: the file structure
1888 * @buffer: the user buffer
1889 * @lenp: the size of the user buffer
1890 * @ppos: file position
1892 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1893 * values from/to the user buffer, treated as an ASCII string.
1895 * This routine will ensure the values are within the range specified by
1896 * table->extra1 (min) and table->extra2 (max).
1898 * Returns 0 on success.
1900 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1901 void __user *buffer, size_t *lenp, loff_t *ppos)
1903 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
1907 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1908 * @table: the sysctl table
1909 * @write: %TRUE if this is a write to the sysctl file
1910 * @filp: the file structure
1911 * @buffer: the user buffer
1912 * @lenp: the size of the user buffer
1913 * @ppos: file position
1915 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1916 * values from/to the user buffer, treated as an ASCII string. The values
1917 * are treated as milliseconds, and converted to jiffies when they are stored.
1919 * This routine will ensure the values are within the range specified by
1920 * table->extra1 (min) and table->extra2 (max).
1922 * Returns 0 on success.
1924 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1926 void __user *buffer,
1927 size_t *lenp, loff_t *ppos)
1929 return do_proc_doulongvec_minmax(table, write, filp, buffer,
1930 lenp, ppos, HZ, 1000l);
1934 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
1936 int write, void *data)
1939 if (*lvalp > LONG_MAX / HZ)
1941 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1947 lval = (unsigned long)-val;
1950 lval = (unsigned long)val;
1957 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
1959 int write, void *data)
1962 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
1964 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1970 lval = (unsigned long)-val;
1973 lval = (unsigned long)val;
1975 *lvalp = jiffies_to_clock_t(lval);
1980 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
1982 int write, void *data)
1985 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1991 lval = (unsigned long)-val;
1994 lval = (unsigned long)val;
1996 *lvalp = jiffies_to_msecs(lval);
2002 * proc_dointvec_jiffies - read a vector of integers as seconds
2003 * @table: the sysctl table
2004 * @write: %TRUE if this is a write to the sysctl file
2005 * @filp: the file structure
2006 * @buffer: the user buffer
2007 * @lenp: the size of the user buffer
2008 * @ppos: file position
2010 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2011 * values from/to the user buffer, treated as an ASCII string.
2012 * The values read are assumed to be in seconds, and are converted into
2015 * Returns 0 on success.
2017 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2018 void __user *buffer, size_t *lenp, loff_t *ppos)
2020 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2021 do_proc_dointvec_jiffies_conv,NULL);
2025 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2026 * @table: the sysctl table
2027 * @write: %TRUE if this is a write to the sysctl file
2028 * @filp: the file structure
2029 * @buffer: the user buffer
2030 * @lenp: the size of the user buffer
2031 * @ppos: pointer to the file position
2033 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2034 * values from/to the user buffer, treated as an ASCII string.
2035 * The values read are assumed to be in 1/USER_HZ seconds, and
2036 * are converted into jiffies.
2038 * Returns 0 on success.
2040 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2041 void __user *buffer, size_t *lenp, loff_t *ppos)
2043 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2044 do_proc_dointvec_userhz_jiffies_conv,NULL);
2048 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2049 * @table: the sysctl table
2050 * @write: %TRUE if this is a write to the sysctl file
2051 * @filp: the file structure
2052 * @buffer: the user buffer
2053 * @lenp: the size of the user buffer
2054 * @ppos: file position
2055 * @ppos: the current position in the file
2057 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2058 * values from/to the user buffer, treated as an ASCII string.
2059 * The values read are assumed to be in 1/1000 seconds, and
2060 * are converted into jiffies.
2062 * Returns 0 on success.
2064 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2065 void __user *buffer, size_t *lenp, loff_t *ppos)
2067 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2068 do_proc_dointvec_ms_jiffies_conv, NULL);
2071 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2072 void __user *buffer, size_t *lenp, loff_t *ppos)
2074 struct pid *new_pid;
2078 tmp = pid_nr(cad_pid);
2080 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2081 lenp, ppos, NULL, NULL);
2085 new_pid = find_get_pid(tmp);
2089 put_pid(xchg(&cad_pid, new_pid));
2093 #else /* CONFIG_PROC_FS */
2095 int proc_dostring(ctl_table *table, int write, struct file *filp,
2096 void __user *buffer, size_t *lenp, loff_t *ppos)
2101 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2102 void __user *buffer, size_t *lenp, loff_t *ppos)
2107 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2108 void __user *buffer, size_t *lenp, loff_t *ppos)
2113 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2114 void __user *buffer, size_t *lenp, loff_t *ppos)
2119 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2120 void __user *buffer, size_t *lenp, loff_t *ppos)
2125 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2126 void __user *buffer, size_t *lenp, loff_t *ppos)
2131 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2132 void __user *buffer, size_t *lenp, loff_t *ppos)
2137 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2138 void __user *buffer, size_t *lenp, loff_t *ppos)
2143 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2145 void __user *buffer,
2146 size_t *lenp, loff_t *ppos)
2152 #endif /* CONFIG_PROC_FS */
2155 #ifdef CONFIG_SYSCTL_SYSCALL
2157 * General sysctl support routines
2160 /* The generic string strategy routine: */
2161 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2162 void __user *oldval, size_t __user *oldlenp,
2163 void __user *newval, size_t newlen)
2165 if (!table->data || !table->maxlen)
2168 if (oldval && oldlenp) {
2170 if (get_user(bufsize, oldlenp))
2173 size_t len = strlen(table->data), copied;
2175 /* This shouldn't trigger for a well-formed sysctl */
2176 if (len > table->maxlen)
2177 len = table->maxlen;
2179 /* Copy up to a max of bufsize-1 bytes of the string */
2180 copied = (len >= bufsize) ? bufsize - 1 : len;
2182 if (copy_to_user(oldval, table->data, copied) ||
2183 put_user(0, (char __user *)(oldval + copied)))
2185 if (put_user(len, oldlenp))
2189 if (newval && newlen) {
2190 size_t len = newlen;
2191 if (len > table->maxlen)
2192 len = table->maxlen;
2193 if(copy_from_user(table->data, newval, len))
2195 if (len == table->maxlen)
2197 ((char *) table->data)[len] = 0;
2203 * This function makes sure that all of the integers in the vector
2204 * are between the minimum and maximum values given in the arrays
2205 * table->extra1 and table->extra2, respectively.
2207 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2208 void __user *oldval, size_t __user *oldlenp,
2209 void __user *newval, size_t newlen)
2212 if (newval && newlen) {
2213 int __user *vec = (int __user *) newval;
2214 int *min = (int *) table->extra1;
2215 int *max = (int *) table->extra2;
2219 if (newlen % sizeof(int) != 0)
2222 if (!table->extra1 && !table->extra2)
2225 if (newlen > table->maxlen)
2226 newlen = table->maxlen;
2227 length = newlen / sizeof(int);
2229 for (i = 0; i < length; i++) {
2231 if (get_user(value, vec + i))
2233 if (min && value < min[i])
2235 if (max && value > max[i])
2242 /* Strategy function to convert jiffies to seconds */
2243 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2244 void __user *oldval, size_t __user *oldlenp,
2245 void __user *newval, size_t newlen)
2247 if (oldval && oldlenp) {
2250 if (get_user(olen, oldlenp))
2255 if (olen < sizeof(int))
2258 val = *(int *)(table->data) / HZ;
2259 if (put_user(val, (int __user *)oldval))
2261 if (put_user(sizeof(int), oldlenp))
2265 if (newval && newlen) {
2267 if (newlen != sizeof(int))
2269 if (get_user(new, (int __user *)newval))
2271 *(int *)(table->data) = new*HZ;
2276 /* Strategy function to convert jiffies to seconds */
2277 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2278 void __user *oldval, size_t __user *oldlenp,
2279 void __user *newval, size_t newlen)
2281 if (oldval && oldlenp) {
2284 if (get_user(olen, oldlenp))
2289 if (olen < sizeof(int))
2292 val = jiffies_to_msecs(*(int *)(table->data));
2293 if (put_user(val, (int __user *)oldval))
2295 if (put_user(sizeof(int), oldlenp))
2299 if (newval && newlen) {
2301 if (newlen != sizeof(int))
2303 if (get_user(new, (int __user *)newval))
2305 *(int *)(table->data) = msecs_to_jiffies(new);
2312 #else /* CONFIG_SYSCTL_SYSCALL */
2315 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2317 static int msg_count;
2318 struct __sysctl_args tmp;
2319 int name[CTL_MAXNAME];
2322 /* Read in the sysctl name for better debug message logging */
2323 if (copy_from_user(&tmp, args, sizeof(tmp)))
2325 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2327 for (i = 0; i < tmp.nlen; i++)
2328 if (get_user(name[i], tmp.name + i))
2331 /* Ignore accesses to kernel.version */
2332 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2335 if (msg_count < 5) {
2338 "warning: process `%s' used the removed sysctl "
2339 "system call with ", current->comm);
2340 for (i = 0; i < tmp.nlen; i++)
2341 printk("%d.", name[i]);
2348 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2349 void __user *oldval, size_t __user *oldlenp,
2350 void __user *newval, size_t newlen)
2355 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2356 void __user *oldval, size_t __user *oldlenp,
2357 void __user *newval, size_t newlen)
2362 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2363 void __user *oldval, size_t __user *oldlenp,
2364 void __user *newval, size_t newlen)
2369 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2370 void __user *oldval, size_t __user *oldlenp,
2371 void __user *newval, size_t newlen)
2376 #endif /* CONFIG_SYSCTL_SYSCALL */
2379 * No sense putting this after each symbol definition, twice,
2380 * exception granted :-)
2382 EXPORT_SYMBOL(proc_dointvec);
2383 EXPORT_SYMBOL(proc_dointvec_jiffies);
2384 EXPORT_SYMBOL(proc_dointvec_minmax);
2385 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2386 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2387 EXPORT_SYMBOL(proc_dostring);
2388 EXPORT_SYMBOL(proc_doulongvec_minmax);
2389 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2390 EXPORT_SYMBOL(register_sysctl_table);
2391 EXPORT_SYMBOL(sysctl_intvec);
2392 EXPORT_SYMBOL(sysctl_jiffies);
2393 EXPORT_SYMBOL(sysctl_ms_jiffies);
2394 EXPORT_SYMBOL(sysctl_string);
2395 EXPORT_SYMBOL(unregister_sysctl_table);