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 sysctl_oom_kill_allocating_task
;
68 extern int max_threads
;
69 extern int core_uses_pid
;
70 extern int suid_dumpable
;
71 extern char core_pattern
[];
73 extern int min_free_kbytes
;
74 extern int printk_ratelimit_jiffies
;
75 extern int printk_ratelimit_burst
;
76 extern int pid_max_min
, pid_max_max
;
77 extern int sysctl_drop_caches
;
78 extern int percpu_pagelist_fraction
;
79 extern int compat_log
;
80 extern int maps_protect
;
81 extern int sysctl_stat_interval
;
83 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
84 static int maxolduid
= 65535;
86 static int min_percpu_pagelist_fract
= 8;
88 static int ngroups_max
= NGROUPS_MAX
;
91 extern char modprobe_path
[];
93 #ifdef CONFIG_CHR_DEV_SG
94 extern int sg_big_buff
;
98 extern char reboot_command
[];
99 extern int stop_a_enabled
;
100 extern int scons_pwroff
;
104 extern int pwrsw_enabled
;
105 extern int unaligned_enabled
;
109 #ifdef CONFIG_MATHEMU
110 extern int sysctl_ieee_emulation_warnings
;
112 extern int sysctl_userprocess_debug
;
113 extern int spin_retry
;
116 extern int sysctl_hz_timer
;
118 #ifdef CONFIG_BSD_PROCESS_ACCT
119 extern int acct_parm
[];
123 extern int no_unaligned_warning
;
126 #ifdef CONFIG_RT_MUTEXES
127 extern int max_lock_depth
;
130 #ifdef CONFIG_SYSCTL_SYSCALL
131 static int parse_table(int __user
*, int, void __user
*, size_t __user
*,
132 void __user
*, size_t, ctl_table
*);
136 #ifdef CONFIG_PROC_SYSCTL
137 static int proc_do_cad_pid(ctl_table
*table
, int write
, struct file
*filp
,
138 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
139 static int proc_dointvec_taint(ctl_table
*table
, int write
, struct file
*filp
,
140 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
143 static ctl_table root_table
[];
144 static struct ctl_table_header root_table_header
=
145 { root_table
, LIST_HEAD_INIT(root_table_header
.ctl_entry
) };
147 static ctl_table kern_table
[];
148 static ctl_table vm_table
[];
149 static ctl_table fs_table
[];
150 static ctl_table debug_table
[];
151 static ctl_table dev_table
[];
152 extern ctl_table random_table
[];
153 #ifdef CONFIG_UNIX98_PTYS
154 extern ctl_table pty_table
[];
156 #ifdef CONFIG_INOTIFY_USER
157 extern ctl_table inotify_table
[];
160 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
161 int sysctl_legacy_va_layout
;
165 /* The default sysctl tables: */
167 static ctl_table root_table
[] = {
169 .ctl_name
= CTL_KERN
,
170 .procname
= "kernel",
195 .ctl_name
= CTL_DEBUG
,
198 .child
= debug_table
,
210 static ctl_table kern_table
[] = {
212 .ctl_name
= KERN_PANIC
,
214 .data
= &panic_timeout
,
215 .maxlen
= sizeof(int),
217 .proc_handler
= &proc_dointvec
,
220 .ctl_name
= KERN_CORE_USES_PID
,
221 .procname
= "core_uses_pid",
222 .data
= &core_uses_pid
,
223 .maxlen
= sizeof(int),
225 .proc_handler
= &proc_dointvec
,
228 .ctl_name
= KERN_CORE_PATTERN
,
229 .procname
= "core_pattern",
230 .data
= core_pattern
,
231 .maxlen
= CORENAME_MAX_SIZE
,
233 .proc_handler
= &proc_dostring
,
234 .strategy
= &sysctl_string
,
236 #ifdef CONFIG_PROC_SYSCTL
238 .ctl_name
= KERN_TAINTED
,
239 .procname
= "tainted",
241 .maxlen
= sizeof(int),
243 .proc_handler
= &proc_dointvec_taint
,
247 .ctl_name
= KERN_CAP_BSET
,
248 .procname
= "cap-bound",
250 .maxlen
= sizeof(kernel_cap_t
),
252 .proc_handler
= &proc_dointvec_bset
,
254 #ifdef CONFIG_BLK_DEV_INITRD
256 .ctl_name
= KERN_REALROOTDEV
,
257 .procname
= "real-root-dev",
258 .data
= &real_root_dev
,
259 .maxlen
= sizeof(int),
261 .proc_handler
= &proc_dointvec
,
266 .ctl_name
= KERN_SPARC_REBOOT
,
267 .procname
= "reboot-cmd",
268 .data
= reboot_command
,
271 .proc_handler
= &proc_dostring
,
272 .strategy
= &sysctl_string
,
275 .ctl_name
= KERN_SPARC_STOP_A
,
276 .procname
= "stop-a",
277 .data
= &stop_a_enabled
,
278 .maxlen
= sizeof (int),
280 .proc_handler
= &proc_dointvec
,
283 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
284 .procname
= "scons-poweroff",
285 .data
= &scons_pwroff
,
286 .maxlen
= sizeof (int),
288 .proc_handler
= &proc_dointvec
,
293 .ctl_name
= KERN_HPPA_PWRSW
,
294 .procname
= "soft-power",
295 .data
= &pwrsw_enabled
,
296 .maxlen
= sizeof (int),
298 .proc_handler
= &proc_dointvec
,
301 .ctl_name
= KERN_HPPA_UNALIGNED
,
302 .procname
= "unaligned-trap",
303 .data
= &unaligned_enabled
,
304 .maxlen
= sizeof (int),
306 .proc_handler
= &proc_dointvec
,
310 .ctl_name
= KERN_CTLALTDEL
,
311 .procname
= "ctrl-alt-del",
313 .maxlen
= sizeof(int),
315 .proc_handler
= &proc_dointvec
,
318 .ctl_name
= KERN_PRINTK
,
319 .procname
= "printk",
320 .data
= &console_loglevel
,
321 .maxlen
= 4*sizeof(int),
323 .proc_handler
= &proc_dointvec
,
327 .ctl_name
= KERN_MODPROBE
,
328 .procname
= "modprobe",
329 .data
= &modprobe_path
,
330 .maxlen
= KMOD_PATH_LEN
,
332 .proc_handler
= &proc_dostring
,
333 .strategy
= &sysctl_string
,
336 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
338 .ctl_name
= KERN_HOTPLUG
,
339 .procname
= "hotplug",
340 .data
= &uevent_helper
,
341 .maxlen
= UEVENT_HELPER_PATH_LEN
,
343 .proc_handler
= &proc_dostring
,
344 .strategy
= &sysctl_string
,
347 #ifdef CONFIG_CHR_DEV_SG
349 .ctl_name
= KERN_SG_BIG_BUFF
,
350 .procname
= "sg-big-buff",
351 .data
= &sg_big_buff
,
352 .maxlen
= sizeof (int),
354 .proc_handler
= &proc_dointvec
,
357 #ifdef CONFIG_BSD_PROCESS_ACCT
359 .ctl_name
= KERN_ACCT
,
362 .maxlen
= 3*sizeof(int),
364 .proc_handler
= &proc_dointvec
,
367 #ifdef CONFIG_MAGIC_SYSRQ
369 .ctl_name
= KERN_SYSRQ
,
371 .data
= &__sysrq_enabled
,
372 .maxlen
= sizeof (int),
374 .proc_handler
= &proc_dointvec
,
377 #ifdef CONFIG_PROC_SYSCTL
379 .ctl_name
= KERN_CADPID
,
380 .procname
= "cad_pid",
382 .maxlen
= sizeof (int),
384 .proc_handler
= &proc_do_cad_pid
,
388 .ctl_name
= KERN_MAX_THREADS
,
389 .procname
= "threads-max",
390 .data
= &max_threads
,
391 .maxlen
= sizeof(int),
393 .proc_handler
= &proc_dointvec
,
396 .ctl_name
= KERN_RANDOM
,
397 .procname
= "random",
399 .child
= random_table
,
401 #ifdef CONFIG_UNIX98_PTYS
403 .ctl_name
= KERN_PTY
,
410 .ctl_name
= KERN_OVERFLOWUID
,
411 .procname
= "overflowuid",
412 .data
= &overflowuid
,
413 .maxlen
= sizeof(int),
415 .proc_handler
= &proc_dointvec_minmax
,
416 .strategy
= &sysctl_intvec
,
417 .extra1
= &minolduid
,
418 .extra2
= &maxolduid
,
421 .ctl_name
= KERN_OVERFLOWGID
,
422 .procname
= "overflowgid",
423 .data
= &overflowgid
,
424 .maxlen
= sizeof(int),
426 .proc_handler
= &proc_dointvec_minmax
,
427 .strategy
= &sysctl_intvec
,
428 .extra1
= &minolduid
,
429 .extra2
= &maxolduid
,
432 #ifdef CONFIG_MATHEMU
434 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
435 .procname
= "ieee_emulation_warnings",
436 .data
= &sysctl_ieee_emulation_warnings
,
437 .maxlen
= sizeof(int),
439 .proc_handler
= &proc_dointvec
,
442 #ifdef CONFIG_NO_IDLE_HZ
444 .ctl_name
= KERN_HZ_TIMER
,
445 .procname
= "hz_timer",
446 .data
= &sysctl_hz_timer
,
447 .maxlen
= sizeof(int),
449 .proc_handler
= &proc_dointvec
,
453 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
454 .procname
= "userprocess_debug",
455 .data
= &sysctl_userprocess_debug
,
456 .maxlen
= sizeof(int),
458 .proc_handler
= &proc_dointvec
,
462 .ctl_name
= KERN_PIDMAX
,
463 .procname
= "pid_max",
465 .maxlen
= sizeof (int),
467 .proc_handler
= &proc_dointvec_minmax
,
468 .strategy
= sysctl_intvec
,
469 .extra1
= &pid_max_min
,
470 .extra2
= &pid_max_max
,
473 .ctl_name
= KERN_PANIC_ON_OOPS
,
474 .procname
= "panic_on_oops",
475 .data
= &panic_on_oops
,
476 .maxlen
= sizeof(int),
478 .proc_handler
= &proc_dointvec
,
481 .ctl_name
= KERN_PRINTK_RATELIMIT
,
482 .procname
= "printk_ratelimit",
483 .data
= &printk_ratelimit_jiffies
,
484 .maxlen
= sizeof(int),
486 .proc_handler
= &proc_dointvec_jiffies
,
487 .strategy
= &sysctl_jiffies
,
490 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
491 .procname
= "printk_ratelimit_burst",
492 .data
= &printk_ratelimit_burst
,
493 .maxlen
= sizeof(int),
495 .proc_handler
= &proc_dointvec
,
498 .ctl_name
= KERN_NGROUPS_MAX
,
499 .procname
= "ngroups_max",
500 .data
= &ngroups_max
,
501 .maxlen
= sizeof (int),
503 .proc_handler
= &proc_dointvec
,
505 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
507 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
508 .procname
= "unknown_nmi_panic",
509 .data
= &unknown_nmi_panic
,
510 .maxlen
= sizeof (int),
512 .proc_handler
= &proc_dointvec
,
515 .ctl_name
= KERN_NMI_WATCHDOG
,
516 .procname
= "nmi_watchdog",
517 .data
= &nmi_watchdog_enabled
,
518 .maxlen
= sizeof (int),
520 .proc_handler
= &proc_nmi_enabled
,
523 #if defined(CONFIG_X86)
525 .ctl_name
= KERN_PANIC_ON_NMI
,
526 .procname
= "panic_on_unrecovered_nmi",
527 .data
= &panic_on_unrecovered_nmi
,
528 .maxlen
= sizeof(int),
530 .proc_handler
= &proc_dointvec
,
533 .ctl_name
= KERN_BOOTLOADER_TYPE
,
534 .procname
= "bootloader_type",
535 .data
= &bootloader_type
,
536 .maxlen
= sizeof (int),
538 .proc_handler
= &proc_dointvec
,
541 .ctl_name
= CTL_UNNUMBERED
,
542 .procname
= "kstack_depth_to_print",
543 .data
= &kstack_depth_to_print
,
544 .maxlen
= sizeof(int),
546 .proc_handler
= &proc_dointvec
,
549 #if defined(CONFIG_MMU)
551 .ctl_name
= KERN_RANDOMIZE
,
552 .procname
= "randomize_va_space",
553 .data
= &randomize_va_space
,
554 .maxlen
= sizeof(int),
556 .proc_handler
= &proc_dointvec
,
559 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
561 .ctl_name
= KERN_SPIN_RETRY
,
562 .procname
= "spin_retry",
564 .maxlen
= sizeof (int),
566 .proc_handler
= &proc_dointvec
,
569 #ifdef CONFIG_ACPI_SLEEP
571 .ctl_name
= KERN_ACPI_VIDEO_FLAGS
,
572 .procname
= "acpi_video_flags",
573 .data
= &acpi_video_flags
,
574 .maxlen
= sizeof (unsigned long),
576 .proc_handler
= &proc_doulongvec_minmax
,
581 .ctl_name
= KERN_IA64_UNALIGNED
,
582 .procname
= "ignore-unaligned-usertrap",
583 .data
= &no_unaligned_warning
,
584 .maxlen
= sizeof (int),
586 .proc_handler
= &proc_dointvec
,
591 .ctl_name
= KERN_COMPAT_LOG
,
592 .procname
= "compat-log",
594 .maxlen
= sizeof (int),
596 .proc_handler
= &proc_dointvec
,
599 #ifdef CONFIG_RT_MUTEXES
601 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
602 .procname
= "max_lock_depth",
603 .data
= &max_lock_depth
,
604 .maxlen
= sizeof(int),
606 .proc_handler
= &proc_dointvec
,
609 #ifdef CONFIG_PROC_FS
611 .ctl_name
= CTL_UNNUMBERED
,
612 .procname
= "maps_protect",
613 .data
= &maps_protect
,
614 .maxlen
= sizeof(int),
616 .proc_handler
= &proc_dointvec
,
623 /* Constants for minimum and maximum testing in vm_table.
624 We use these as one-element integer vectors. */
626 static int one_hundred
= 100;
629 static ctl_table vm_table
[] = {
631 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
632 .procname
= "overcommit_memory",
633 .data
= &sysctl_overcommit_memory
,
634 .maxlen
= sizeof(sysctl_overcommit_memory
),
636 .proc_handler
= &proc_dointvec
,
639 .ctl_name
= VM_PANIC_ON_OOM
,
640 .procname
= "panic_on_oom",
641 .data
= &sysctl_panic_on_oom
,
642 .maxlen
= sizeof(sysctl_panic_on_oom
),
644 .proc_handler
= &proc_dointvec
,
647 .ctl_name
= CTL_UNNUMBERED
,
648 .procname
= "oom_kill_allocating_task",
649 .data
= &sysctl_oom_kill_allocating_task
,
650 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
652 .proc_handler
= &proc_dointvec
,
655 .ctl_name
= VM_OVERCOMMIT_RATIO
,
656 .procname
= "overcommit_ratio",
657 .data
= &sysctl_overcommit_ratio
,
658 .maxlen
= sizeof(sysctl_overcommit_ratio
),
660 .proc_handler
= &proc_dointvec
,
663 .ctl_name
= VM_PAGE_CLUSTER
,
664 .procname
= "page-cluster",
665 .data
= &page_cluster
,
666 .maxlen
= sizeof(int),
668 .proc_handler
= &proc_dointvec
,
671 .ctl_name
= VM_DIRTY_BACKGROUND
,
672 .procname
= "dirty_background_ratio",
673 .data
= &dirty_background_ratio
,
674 .maxlen
= sizeof(dirty_background_ratio
),
676 .proc_handler
= &proc_dointvec_minmax
,
677 .strategy
= &sysctl_intvec
,
679 .extra2
= &one_hundred
,
682 .ctl_name
= VM_DIRTY_RATIO
,
683 .procname
= "dirty_ratio",
684 .data
= &vm_dirty_ratio
,
685 .maxlen
= sizeof(vm_dirty_ratio
),
687 .proc_handler
= &dirty_ratio_handler
,
688 .strategy
= &sysctl_intvec
,
690 .extra2
= &one_hundred
,
693 .ctl_name
= VM_DIRTY_WB_CS
,
694 .procname
= "dirty_writeback_centisecs",
695 .data
= &dirty_writeback_interval
,
696 .maxlen
= sizeof(dirty_writeback_interval
),
698 .proc_handler
= &dirty_writeback_centisecs_handler
,
701 .ctl_name
= VM_DIRTY_EXPIRE_CS
,
702 .procname
= "dirty_expire_centisecs",
703 .data
= &dirty_expire_interval
,
704 .maxlen
= sizeof(dirty_expire_interval
),
706 .proc_handler
= &proc_dointvec_userhz_jiffies
,
709 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
710 .procname
= "nr_pdflush_threads",
711 .data
= &nr_pdflush_threads
,
712 .maxlen
= sizeof nr_pdflush_threads
,
713 .mode
= 0444 /* read-only*/,
714 .proc_handler
= &proc_dointvec
,
717 .ctl_name
= VM_SWAPPINESS
,
718 .procname
= "swappiness",
719 .data
= &vm_swappiness
,
720 .maxlen
= sizeof(vm_swappiness
),
722 .proc_handler
= &proc_dointvec_minmax
,
723 .strategy
= &sysctl_intvec
,
725 .extra2
= &one_hundred
,
727 #ifdef CONFIG_HUGETLB_PAGE
729 .ctl_name
= VM_HUGETLB_PAGES
,
730 .procname
= "nr_hugepages",
731 .data
= &max_huge_pages
,
732 .maxlen
= sizeof(unsigned long),
734 .proc_handler
= &hugetlb_sysctl_handler
,
735 .extra1
= (void *)&hugetlb_zero
,
736 .extra2
= (void *)&hugetlb_infinity
,
739 .ctl_name
= VM_HUGETLB_GROUP
,
740 .procname
= "hugetlb_shm_group",
741 .data
= &sysctl_hugetlb_shm_group
,
742 .maxlen
= sizeof(gid_t
),
744 .proc_handler
= &proc_dointvec
,
748 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
749 .procname
= "lowmem_reserve_ratio",
750 .data
= &sysctl_lowmem_reserve_ratio
,
751 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
753 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
754 .strategy
= &sysctl_intvec
,
757 .ctl_name
= VM_DROP_PAGECACHE
,
758 .procname
= "drop_caches",
759 .data
= &sysctl_drop_caches
,
760 .maxlen
= sizeof(int),
762 .proc_handler
= drop_caches_sysctl_handler
,
763 .strategy
= &sysctl_intvec
,
766 .ctl_name
= VM_MIN_FREE_KBYTES
,
767 .procname
= "min_free_kbytes",
768 .data
= &min_free_kbytes
,
769 .maxlen
= sizeof(min_free_kbytes
),
771 .proc_handler
= &min_free_kbytes_sysctl_handler
,
772 .strategy
= &sysctl_intvec
,
776 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
777 .procname
= "percpu_pagelist_fraction",
778 .data
= &percpu_pagelist_fraction
,
779 .maxlen
= sizeof(percpu_pagelist_fraction
),
781 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
782 .strategy
= &sysctl_intvec
,
783 .extra1
= &min_percpu_pagelist_fract
,
787 .ctl_name
= VM_MAX_MAP_COUNT
,
788 .procname
= "max_map_count",
789 .data
= &sysctl_max_map_count
,
790 .maxlen
= sizeof(sysctl_max_map_count
),
792 .proc_handler
= &proc_dointvec
796 .ctl_name
= VM_LAPTOP_MODE
,
797 .procname
= "laptop_mode",
798 .data
= &laptop_mode
,
799 .maxlen
= sizeof(laptop_mode
),
801 .proc_handler
= &proc_dointvec_jiffies
,
802 .strategy
= &sysctl_jiffies
,
805 .ctl_name
= VM_BLOCK_DUMP
,
806 .procname
= "block_dump",
808 .maxlen
= sizeof(block_dump
),
810 .proc_handler
= &proc_dointvec
,
811 .strategy
= &sysctl_intvec
,
815 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
816 .procname
= "vfs_cache_pressure",
817 .data
= &sysctl_vfs_cache_pressure
,
818 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
820 .proc_handler
= &proc_dointvec
,
821 .strategy
= &sysctl_intvec
,
824 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
826 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
827 .procname
= "legacy_va_layout",
828 .data
= &sysctl_legacy_va_layout
,
829 .maxlen
= sizeof(sysctl_legacy_va_layout
),
831 .proc_handler
= &proc_dointvec
,
832 .strategy
= &sysctl_intvec
,
838 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
839 .procname
= "zone_reclaim_mode",
840 .data
= &zone_reclaim_mode
,
841 .maxlen
= sizeof(zone_reclaim_mode
),
843 .proc_handler
= &proc_dointvec
,
844 .strategy
= &sysctl_intvec
,
848 .ctl_name
= VM_MIN_UNMAPPED
,
849 .procname
= "min_unmapped_ratio",
850 .data
= &sysctl_min_unmapped_ratio
,
851 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
853 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
854 .strategy
= &sysctl_intvec
,
856 .extra2
= &one_hundred
,
859 .ctl_name
= VM_MIN_SLAB
,
860 .procname
= "min_slab_ratio",
861 .data
= &sysctl_min_slab_ratio
,
862 .maxlen
= sizeof(sysctl_min_slab_ratio
),
864 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
865 .strategy
= &sysctl_intvec
,
867 .extra2
= &one_hundred
,
872 .ctl_name
= CTL_UNNUMBERED
,
873 .procname
= "stat_interval",
874 .data
= &sysctl_stat_interval
,
875 .maxlen
= sizeof(sysctl_stat_interval
),
877 .proc_handler
= &proc_dointvec_jiffies
,
878 .strategy
= &sysctl_jiffies
,
881 #if defined(CONFIG_X86_32) || \
882 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
884 .ctl_name
= VM_VDSO_ENABLED
,
885 .procname
= "vdso_enabled",
886 .data
= &vdso_enabled
,
887 .maxlen
= sizeof(vdso_enabled
),
889 .proc_handler
= &proc_dointvec
,
890 .strategy
= &sysctl_intvec
,
897 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
898 static ctl_table binfmt_misc_table
[] = {
903 static ctl_table fs_table
[] = {
905 .ctl_name
= FS_NRINODE
,
906 .procname
= "inode-nr",
907 .data
= &inodes_stat
,
908 .maxlen
= 2*sizeof(int),
910 .proc_handler
= &proc_dointvec
,
913 .ctl_name
= FS_STATINODE
,
914 .procname
= "inode-state",
915 .data
= &inodes_stat
,
916 .maxlen
= 7*sizeof(int),
918 .proc_handler
= &proc_dointvec
,
921 .ctl_name
= FS_NRFILE
,
922 .procname
= "file-nr",
924 .maxlen
= 3*sizeof(int),
926 .proc_handler
= &proc_nr_files
,
929 .ctl_name
= FS_MAXFILE
,
930 .procname
= "file-max",
931 .data
= &files_stat
.max_files
,
932 .maxlen
= sizeof(int),
934 .proc_handler
= &proc_dointvec
,
937 .ctl_name
= FS_DENTRY
,
938 .procname
= "dentry-state",
939 .data
= &dentry_stat
,
940 .maxlen
= 6*sizeof(int),
942 .proc_handler
= &proc_dointvec
,
945 .ctl_name
= FS_OVERFLOWUID
,
946 .procname
= "overflowuid",
947 .data
= &fs_overflowuid
,
948 .maxlen
= sizeof(int),
950 .proc_handler
= &proc_dointvec_minmax
,
951 .strategy
= &sysctl_intvec
,
952 .extra1
= &minolduid
,
953 .extra2
= &maxolduid
,
956 .ctl_name
= FS_OVERFLOWGID
,
957 .procname
= "overflowgid",
958 .data
= &fs_overflowgid
,
959 .maxlen
= sizeof(int),
961 .proc_handler
= &proc_dointvec_minmax
,
962 .strategy
= &sysctl_intvec
,
963 .extra1
= &minolduid
,
964 .extra2
= &maxolduid
,
967 .ctl_name
= FS_LEASES
,
968 .procname
= "leases-enable",
969 .data
= &leases_enable
,
970 .maxlen
= sizeof(int),
972 .proc_handler
= &proc_dointvec
,
974 #ifdef CONFIG_DNOTIFY
976 .ctl_name
= FS_DIR_NOTIFY
,
977 .procname
= "dir-notify-enable",
978 .data
= &dir_notify_enable
,
979 .maxlen
= sizeof(int),
981 .proc_handler
= &proc_dointvec
,
986 .ctl_name
= FS_LEASE_TIME
,
987 .procname
= "lease-break-time",
988 .data
= &lease_break_time
,
989 .maxlen
= sizeof(int),
991 .proc_handler
= &proc_dointvec
,
994 .ctl_name
= FS_AIO_NR
,
995 .procname
= "aio-nr",
997 .maxlen
= sizeof(aio_nr
),
999 .proc_handler
= &proc_doulongvec_minmax
,
1002 .ctl_name
= FS_AIO_MAX_NR
,
1003 .procname
= "aio-max-nr",
1004 .data
= &aio_max_nr
,
1005 .maxlen
= sizeof(aio_max_nr
),
1007 .proc_handler
= &proc_doulongvec_minmax
,
1009 #ifdef CONFIG_INOTIFY_USER
1011 .ctl_name
= FS_INOTIFY
,
1012 .procname
= "inotify",
1014 .child
= inotify_table
,
1019 .ctl_name
= KERN_SETUID_DUMPABLE
,
1020 .procname
= "suid_dumpable",
1021 .data
= &suid_dumpable
,
1022 .maxlen
= sizeof(int),
1024 .proc_handler
= &proc_dointvec
,
1026 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1028 .ctl_name
= CTL_UNNUMBERED
,
1029 .procname
= "binfmt_misc",
1031 .child
= binfmt_misc_table
,
1037 static ctl_table debug_table
[] = {
1041 static ctl_table dev_table
[] = {
1045 static DEFINE_SPINLOCK(sysctl_lock
);
1047 /* called under sysctl_lock */
1048 static int use_table(struct ctl_table_header
*p
)
1050 if (unlikely(p
->unregistering
))
1056 /* called under sysctl_lock */
1057 static void unuse_table(struct ctl_table_header
*p
)
1060 if (unlikely(p
->unregistering
))
1061 complete(p
->unregistering
);
1064 /* called under sysctl_lock, will reacquire if has to wait */
1065 static void start_unregistering(struct ctl_table_header
*p
)
1068 * if p->used is 0, nobody will ever touch that entry again;
1069 * we'll eliminate all paths to it before dropping sysctl_lock
1071 if (unlikely(p
->used
)) {
1072 struct completion wait
;
1073 init_completion(&wait
);
1074 p
->unregistering
= &wait
;
1075 spin_unlock(&sysctl_lock
);
1076 wait_for_completion(&wait
);
1077 spin_lock(&sysctl_lock
);
1080 * do not remove from the list until nobody holds it; walking the
1081 * list in do_sysctl() relies on that.
1083 list_del_init(&p
->ctl_entry
);
1086 void sysctl_head_finish(struct ctl_table_header
*head
)
1090 spin_lock(&sysctl_lock
);
1092 spin_unlock(&sysctl_lock
);
1095 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1097 struct ctl_table_header
*head
;
1098 struct list_head
*tmp
;
1099 spin_lock(&sysctl_lock
);
1101 tmp
= &prev
->ctl_entry
;
1105 tmp
= &root_table_header
.ctl_entry
;
1107 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1109 if (!use_table(head
))
1111 spin_unlock(&sysctl_lock
);
1115 if (tmp
== &root_table_header
.ctl_entry
)
1118 spin_unlock(&sysctl_lock
);
1122 #ifdef CONFIG_SYSCTL_SYSCALL
1123 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1124 void __user
*newval
, size_t newlen
)
1126 struct ctl_table_header
*head
;
1127 int error
= -ENOTDIR
;
1129 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1133 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1137 for (head
= sysctl_head_next(NULL
); head
;
1138 head
= sysctl_head_next(head
)) {
1139 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1140 newval
, newlen
, head
->ctl_table
);
1141 if (error
!= -ENOTDIR
) {
1142 sysctl_head_finish(head
);
1149 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1151 struct __sysctl_args tmp
;
1154 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1158 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1159 tmp
.newval
, tmp
.newlen
);
1163 #endif /* CONFIG_SYSCTL_SYSCALL */
1166 * sysctl_perm does NOT grant the superuser all rights automatically, because
1167 * some sysctl variables are readonly even to root.
1170 static int test_perm(int mode
, int op
)
1174 else if (in_egroup_p(0))
1176 if ((mode
& op
& 0007) == op
)
1181 int sysctl_perm(ctl_table
*table
, int op
)
1184 error
= security_sysctl(table
, op
);
1187 return test_perm(table
->mode
, op
);
1190 #ifdef CONFIG_SYSCTL_SYSCALL
1191 static int parse_table(int __user
*name
, int nlen
,
1192 void __user
*oldval
, size_t __user
*oldlenp
,
1193 void __user
*newval
, size_t newlen
,
1200 if (get_user(n
, name
))
1202 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1203 if (!table
->ctl_name
)
1205 if (n
== table
->ctl_name
) {
1208 if (sysctl_perm(table
, 001))
1212 table
= table
->child
;
1215 error
= do_sysctl_strategy(table
, name
, nlen
,
1224 /* Perform the actual read/write of a sysctl table entry. */
1225 int do_sysctl_strategy (ctl_table
*table
,
1226 int __user
*name
, int nlen
,
1227 void __user
*oldval
, size_t __user
*oldlenp
,
1228 void __user
*newval
, size_t newlen
)
1237 if (sysctl_perm(table
, op
))
1240 if (table
->strategy
) {
1241 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1249 /* If there is no strategy routine, or if the strategy returns
1250 * zero, proceed with automatic r/w */
1251 if (table
->data
&& table
->maxlen
) {
1252 if (oldval
&& oldlenp
) {
1253 if (get_user(len
, oldlenp
))
1256 if (len
> table
->maxlen
)
1257 len
= table
->maxlen
;
1258 if(copy_to_user(oldval
, table
->data
, len
))
1260 if(put_user(len
, oldlenp
))
1264 if (newval
&& newlen
) {
1266 if (len
> table
->maxlen
)
1267 len
= table
->maxlen
;
1268 if(copy_from_user(table
->data
, newval
, len
))
1274 #endif /* CONFIG_SYSCTL_SYSCALL */
1276 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1278 for (; table
->ctl_name
|| table
->procname
; table
++) {
1279 table
->parent
= parent
;
1281 sysctl_set_parent(table
, table
->child
);
1285 static __init
int sysctl_init(void)
1287 sysctl_set_parent(NULL
, root_table
);
1291 core_initcall(sysctl_init
);
1294 * register_sysctl_table - register a sysctl hierarchy
1295 * @table: the top-level table structure
1297 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1298 * array. An entry with a ctl_name of 0 terminates the table.
1300 * The members of the &ctl_table structure are used as follows:
1302 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1303 * must be unique within that level of sysctl
1305 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1306 * enter a sysctl file
1308 * data - a pointer to data for use by proc_handler
1310 * maxlen - the maximum size in bytes of the data
1312 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1314 * child - a pointer to the child sysctl table if this entry is a directory, or
1317 * proc_handler - the text handler routine (described below)
1319 * strategy - the strategy routine (described below)
1321 * de - for internal use by the sysctl routines
1323 * extra1, extra2 - extra pointers usable by the proc handler routines
1325 * Leaf nodes in the sysctl tree will be represented by a single file
1326 * under /proc; non-leaf nodes will be represented by directories.
1328 * sysctl(2) can automatically manage read and write requests through
1329 * the sysctl table. The data and maxlen fields of the ctl_table
1330 * struct enable minimal validation of the values being written to be
1331 * performed, and the mode field allows minimal authentication.
1333 * More sophisticated management can be enabled by the provision of a
1334 * strategy routine with the table entry. This will be called before
1335 * any automatic read or write of the data is performed.
1337 * The strategy routine may return
1339 * < 0 - Error occurred (error is passed to user process)
1341 * 0 - OK - proceed with automatic read or write.
1343 * > 0 - OK - read or write has been done by the strategy routine, so
1344 * return immediately.
1346 * There must be a proc_handler routine for any terminal nodes
1347 * mirrored under /proc/sys (non-terminals are handled by a built-in
1348 * directory handler). Several default handlers are available to
1349 * cover common cases -
1351 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1352 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1353 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1355 * It is the handler's job to read the input buffer from user memory
1356 * and process it. The handler should return 0 on success.
1358 * This routine returns %NULL on a failure to register, and a pointer
1359 * to the table header on success.
1361 struct ctl_table_header
*register_sysctl_table(ctl_table
* table
)
1363 struct ctl_table_header
*tmp
;
1364 tmp
= kmalloc(sizeof(struct ctl_table_header
), GFP_KERNEL
);
1367 tmp
->ctl_table
= table
;
1368 INIT_LIST_HEAD(&tmp
->ctl_entry
);
1370 tmp
->unregistering
= NULL
;
1371 sysctl_set_parent(NULL
, table
);
1372 spin_lock(&sysctl_lock
);
1373 list_add_tail(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1374 spin_unlock(&sysctl_lock
);
1379 * unregister_sysctl_table - unregister a sysctl table hierarchy
1380 * @header: the header returned from register_sysctl_table
1382 * Unregisters the sysctl table and all children. proc entries may not
1383 * actually be removed until they are no longer used by anyone.
1385 void unregister_sysctl_table(struct ctl_table_header
* header
)
1388 spin_lock(&sysctl_lock
);
1389 start_unregistering(header
);
1390 spin_unlock(&sysctl_lock
);
1394 #else /* !CONFIG_SYSCTL */
1395 struct ctl_table_header
*register_sysctl_table(ctl_table
* table
)
1400 void unregister_sysctl_table(struct ctl_table_header
* table
)
1404 #endif /* CONFIG_SYSCTL */
1410 #ifdef CONFIG_PROC_SYSCTL
1412 static int _proc_do_string(void* data
, int maxlen
, int write
,
1413 struct file
*filp
, void __user
*buffer
,
1414 size_t *lenp
, loff_t
*ppos
)
1420 if (!data
|| !maxlen
|| !*lenp
) {
1428 while (len
< *lenp
) {
1429 if (get_user(c
, p
++))
1431 if (c
== 0 || c
== '\n')
1437 if(copy_from_user(data
, buffer
, len
))
1439 ((char *) data
)[len
] = 0;
1457 if(copy_to_user(buffer
, data
, len
))
1460 if(put_user('\n', ((char __user
*) buffer
) + len
))
1471 * proc_dostring - read a string sysctl
1472 * @table: the sysctl table
1473 * @write: %TRUE if this is a write to the sysctl file
1474 * @filp: the file structure
1475 * @buffer: the user buffer
1476 * @lenp: the size of the user buffer
1477 * @ppos: file position
1479 * Reads/writes a string from/to the user buffer. If the kernel
1480 * buffer provided is not large enough to hold the string, the
1481 * string is truncated. The copied string is %NULL-terminated.
1482 * If the string is being read by the user process, it is copied
1483 * and a newline '\n' is added. It is truncated if the buffer is
1486 * Returns 0 on success.
1488 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1489 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1491 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
1492 buffer
, lenp
, ppos
);
1496 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1498 int write
, void *data
)
1501 *valp
= *negp
? -*lvalp
: *lvalp
;
1506 *lvalp
= (unsigned long)-val
;
1509 *lvalp
= (unsigned long)val
;
1515 static int __do_proc_dointvec(void *tbl_data
, ctl_table
*table
,
1516 int write
, struct file
*filp
, void __user
*buffer
,
1517 size_t *lenp
, loff_t
*ppos
,
1518 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1519 int write
, void *data
),
1522 #define TMPBUFLEN 21
1523 int *i
, vleft
, first
=1, neg
, val
;
1527 char buf
[TMPBUFLEN
], *p
;
1528 char __user
*s
= buffer
;
1530 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
1531 (*ppos
&& !write
)) {
1536 i
= (int *) tbl_data
;
1537 vleft
= table
->maxlen
/ sizeof(*i
);
1541 conv
= do_proc_dointvec_conv
;
1543 for (; left
&& vleft
--; i
++, first
=0) {
1558 if (len
> sizeof(buf
) - 1)
1559 len
= sizeof(buf
) - 1;
1560 if (copy_from_user(buf
, s
, len
))
1564 if (*p
== '-' && left
> 1) {
1568 if (*p
< '0' || *p
> '9')
1571 lval
= simple_strtoul(p
, &p
, 0);
1574 if ((len
< left
) && *p
&& !isspace(*p
))
1581 if (conv(&neg
, &lval
, i
, 1, data
))
1588 if (conv(&neg
, &lval
, i
, 0, data
))
1591 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
1595 if(copy_to_user(s
, buf
, len
))
1602 if (!write
&& !first
&& left
) {
1603 if(put_user('\n', s
))
1610 if (get_user(c
, s
++))
1625 static int do_proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1626 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1627 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1628 int write
, void *data
),
1631 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
1632 buffer
, lenp
, ppos
, conv
, data
);
1636 * proc_dointvec - read a vector of integers
1637 * @table: the sysctl table
1638 * @write: %TRUE if this is a write to the sysctl file
1639 * @filp: the file structure
1640 * @buffer: the user buffer
1641 * @lenp: the size of the user buffer
1642 * @ppos: file position
1644 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1645 * values from/to the user buffer, treated as an ASCII string.
1647 * Returns 0 on success.
1649 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1650 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1652 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1660 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
1662 int write
, void *data
)
1664 int op
= *(int *)data
;
1666 int val
= *negp
? -*lvalp
: *lvalp
;
1668 case OP_SET
: *valp
= val
; break;
1669 case OP_AND
: *valp
&= val
; break;
1670 case OP_OR
: *valp
|= val
; break;
1676 *lvalp
= (unsigned long)-val
;
1679 *lvalp
= (unsigned long)val
;
1686 * init may raise the set.
1689 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1690 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1694 if (write
&& !capable(CAP_SYS_MODULE
)) {
1698 op
= is_init(current
) ? OP_SET
: OP_AND
;
1699 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1700 do_proc_dointvec_bset_conv
,&op
);
1704 * Taint values can only be increased
1706 static int proc_dointvec_taint(ctl_table
*table
, int write
, struct file
*filp
,
1707 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1711 if (write
&& !capable(CAP_SYS_ADMIN
))
1715 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1716 do_proc_dointvec_bset_conv
,&op
);
1719 struct do_proc_dointvec_minmax_conv_param
{
1724 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
1726 int write
, void *data
)
1728 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
1730 int val
= *negp
? -*lvalp
: *lvalp
;
1731 if ((param
->min
&& *param
->min
> val
) ||
1732 (param
->max
&& *param
->max
< val
))
1739 *lvalp
= (unsigned long)-val
;
1742 *lvalp
= (unsigned long)val
;
1749 * proc_dointvec_minmax - read a vector of integers with min/max values
1750 * @table: the sysctl table
1751 * @write: %TRUE if this is a write to the sysctl file
1752 * @filp: the file structure
1753 * @buffer: the user buffer
1754 * @lenp: the size of the user buffer
1755 * @ppos: file position
1757 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1758 * values from/to the user buffer, treated as an ASCII string.
1760 * This routine will ensure the values are within the range specified by
1761 * table->extra1 (min) and table->extra2 (max).
1763 * Returns 0 on success.
1765 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1766 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1768 struct do_proc_dointvec_minmax_conv_param param
= {
1769 .min
= (int *) table
->extra1
,
1770 .max
= (int *) table
->extra2
,
1772 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
1773 do_proc_dointvec_minmax_conv
, ¶m
);
1776 static int __do_proc_doulongvec_minmax(void *data
, ctl_table
*table
, int write
,
1778 void __user
*buffer
,
1779 size_t *lenp
, loff_t
*ppos
,
1780 unsigned long convmul
,
1781 unsigned long convdiv
)
1783 #define TMPBUFLEN 21
1784 unsigned long *i
, *min
, *max
, val
;
1785 int vleft
, first
=1, neg
;
1787 char buf
[TMPBUFLEN
], *p
;
1788 char __user
*s
= buffer
;
1790 if (!data
|| !table
->maxlen
|| !*lenp
||
1791 (*ppos
&& !write
)) {
1796 i
= (unsigned long *) data
;
1797 min
= (unsigned long *) table
->extra1
;
1798 max
= (unsigned long *) table
->extra2
;
1799 vleft
= table
->maxlen
/ sizeof(unsigned long);
1802 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
1817 if (len
> TMPBUFLEN
-1)
1819 if (copy_from_user(buf
, s
, len
))
1823 if (*p
== '-' && left
> 1) {
1827 if (*p
< '0' || *p
> '9')
1829 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
1831 if ((len
< left
) && *p
&& !isspace(*p
))
1840 if ((min
&& val
< *min
) || (max
&& val
> *max
))
1847 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
1851 if(copy_to_user(s
, buf
, len
))
1858 if (!write
&& !first
&& left
) {
1859 if(put_user('\n', s
))
1866 if (get_user(c
, s
++))
1881 static int do_proc_doulongvec_minmax(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 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
1889 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
1893 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1894 * @table: the sysctl table
1895 * @write: %TRUE if this is a write to the sysctl file
1896 * @filp: the file structure
1897 * @buffer: the user buffer
1898 * @lenp: the size of the user buffer
1899 * @ppos: file position
1901 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1902 * values from/to the user buffer, treated as an ASCII string.
1904 * This routine will ensure the values are within the range specified by
1905 * table->extra1 (min) and table->extra2 (max).
1907 * Returns 0 on success.
1909 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1910 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1912 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
1916 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1917 * @table: the sysctl table
1918 * @write: %TRUE if this is a write to the sysctl file
1919 * @filp: the file structure
1920 * @buffer: the user buffer
1921 * @lenp: the size of the user buffer
1922 * @ppos: file position
1924 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1925 * values from/to the user buffer, treated as an ASCII string. The values
1926 * are treated as milliseconds, and converted to jiffies when they are stored.
1928 * This routine will ensure the values are within the range specified by
1929 * table->extra1 (min) and table->extra2 (max).
1931 * Returns 0 on success.
1933 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
1935 void __user
*buffer
,
1936 size_t *lenp
, loff_t
*ppos
)
1938 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
1939 lenp
, ppos
, HZ
, 1000l);
1943 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
1945 int write
, void *data
)
1948 if (*lvalp
> LONG_MAX
/ HZ
)
1950 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
1956 lval
= (unsigned long)-val
;
1959 lval
= (unsigned long)val
;
1966 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
1968 int write
, void *data
)
1971 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
1973 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
1979 lval
= (unsigned long)-val
;
1982 lval
= (unsigned long)val
;
1984 *lvalp
= jiffies_to_clock_t(lval
);
1989 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
1991 int write
, void *data
)
1994 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2000 lval
= (unsigned long)-val
;
2003 lval
= (unsigned long)val
;
2005 *lvalp
= jiffies_to_msecs(lval
);
2011 * proc_dointvec_jiffies - read a vector of integers as seconds
2012 * @table: the sysctl table
2013 * @write: %TRUE if this is a write to the sysctl file
2014 * @filp: the file structure
2015 * @buffer: the user buffer
2016 * @lenp: the size of the user buffer
2017 * @ppos: file position
2019 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2020 * values from/to the user buffer, treated as an ASCII string.
2021 * The values read are assumed to be in seconds, and are converted into
2024 * Returns 0 on success.
2026 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2027 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2029 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2030 do_proc_dointvec_jiffies_conv
,NULL
);
2034 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2035 * @table: the sysctl table
2036 * @write: %TRUE if this is a write to the sysctl file
2037 * @filp: the file structure
2038 * @buffer: the user buffer
2039 * @lenp: the size of the user buffer
2040 * @ppos: pointer to the file position
2042 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2043 * values from/to the user buffer, treated as an ASCII string.
2044 * The values read are assumed to be in 1/USER_HZ seconds, and
2045 * are converted into jiffies.
2047 * Returns 0 on success.
2049 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2050 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2052 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2053 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2057 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2058 * @table: the sysctl table
2059 * @write: %TRUE if this is a write to the sysctl file
2060 * @filp: the file structure
2061 * @buffer: the user buffer
2062 * @lenp: the size of the user buffer
2063 * @ppos: file position
2064 * @ppos: the current position in the file
2066 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2067 * values from/to the user buffer, treated as an ASCII string.
2068 * The values read are assumed to be in 1/1000 seconds, and
2069 * are converted into jiffies.
2071 * Returns 0 on success.
2073 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2074 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2076 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2077 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2080 static int proc_do_cad_pid(ctl_table
*table
, int write
, struct file
*filp
,
2081 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2083 struct pid
*new_pid
;
2087 tmp
= pid_nr(cad_pid
);
2089 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2090 lenp
, ppos
, NULL
, NULL
);
2094 new_pid
= find_get_pid(tmp
);
2098 put_pid(xchg(&cad_pid
, new_pid
));
2102 #else /* CONFIG_PROC_FS */
2104 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2105 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2110 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2111 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2116 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2117 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2122 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2123 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2128 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2129 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2134 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2135 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2140 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2141 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2146 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2147 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2152 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2154 void __user
*buffer
,
2155 size_t *lenp
, loff_t
*ppos
)
2161 #endif /* CONFIG_PROC_FS */
2164 #ifdef CONFIG_SYSCTL_SYSCALL
2166 * General sysctl support routines
2169 /* The generic string strategy routine: */
2170 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2171 void __user
*oldval
, size_t __user
*oldlenp
,
2172 void __user
*newval
, size_t newlen
)
2174 if (!table
->data
|| !table
->maxlen
)
2177 if (oldval
&& oldlenp
) {
2179 if (get_user(bufsize
, oldlenp
))
2182 size_t len
= strlen(table
->data
), copied
;
2184 /* This shouldn't trigger for a well-formed sysctl */
2185 if (len
> table
->maxlen
)
2186 len
= table
->maxlen
;
2188 /* Copy up to a max of bufsize-1 bytes of the string */
2189 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2191 if (copy_to_user(oldval
, table
->data
, copied
) ||
2192 put_user(0, (char __user
*)(oldval
+ copied
)))
2194 if (put_user(len
, oldlenp
))
2198 if (newval
&& newlen
) {
2199 size_t len
= newlen
;
2200 if (len
> table
->maxlen
)
2201 len
= table
->maxlen
;
2202 if(copy_from_user(table
->data
, newval
, len
))
2204 if (len
== table
->maxlen
)
2206 ((char *) table
->data
)[len
] = 0;
2212 * This function makes sure that all of the integers in the vector
2213 * are between the minimum and maximum values given in the arrays
2214 * table->extra1 and table->extra2, respectively.
2216 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2217 void __user
*oldval
, size_t __user
*oldlenp
,
2218 void __user
*newval
, size_t newlen
)
2221 if (newval
&& newlen
) {
2222 int __user
*vec
= (int __user
*) newval
;
2223 int *min
= (int *) table
->extra1
;
2224 int *max
= (int *) table
->extra2
;
2228 if (newlen
% sizeof(int) != 0)
2231 if (!table
->extra1
&& !table
->extra2
)
2234 if (newlen
> table
->maxlen
)
2235 newlen
= table
->maxlen
;
2236 length
= newlen
/ sizeof(int);
2238 for (i
= 0; i
< length
; i
++) {
2240 if (get_user(value
, vec
+ i
))
2242 if (min
&& value
< min
[i
])
2244 if (max
&& value
> max
[i
])
2251 /* Strategy function to convert jiffies to seconds */
2252 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2253 void __user
*oldval
, size_t __user
*oldlenp
,
2254 void __user
*newval
, size_t newlen
)
2256 if (oldval
&& oldlenp
) {
2259 if (get_user(olen
, oldlenp
))
2264 if (olen
< sizeof(int))
2267 val
= *(int *)(table
->data
) / HZ
;
2268 if (put_user(val
, (int __user
*)oldval
))
2270 if (put_user(sizeof(int), oldlenp
))
2274 if (newval
&& newlen
) {
2276 if (newlen
!= sizeof(int))
2278 if (get_user(new, (int __user
*)newval
))
2280 *(int *)(table
->data
) = new*HZ
;
2285 /* Strategy function to convert jiffies to seconds */
2286 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2287 void __user
*oldval
, size_t __user
*oldlenp
,
2288 void __user
*newval
, size_t newlen
)
2290 if (oldval
&& oldlenp
) {
2293 if (get_user(olen
, oldlenp
))
2298 if (olen
< sizeof(int))
2301 val
= jiffies_to_msecs(*(int *)(table
->data
));
2302 if (put_user(val
, (int __user
*)oldval
))
2304 if (put_user(sizeof(int), oldlenp
))
2308 if (newval
&& newlen
) {
2310 if (newlen
!= sizeof(int))
2312 if (get_user(new, (int __user
*)newval
))
2314 *(int *)(table
->data
) = msecs_to_jiffies(new);
2321 #else /* CONFIG_SYSCTL_SYSCALL */
2324 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2326 static int msg_count
;
2327 struct __sysctl_args tmp
;
2328 int name
[CTL_MAXNAME
];
2331 /* Read in the sysctl name for better debug message logging */
2332 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
2334 if (tmp
.nlen
<= 0 || tmp
.nlen
>= CTL_MAXNAME
)
2336 for (i
= 0; i
< tmp
.nlen
; i
++)
2337 if (get_user(name
[i
], tmp
.name
+ i
))
2340 /* Ignore accesses to kernel.version */
2341 if ((tmp
.nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
2344 if (msg_count
< 5) {
2347 "warning: process `%s' used the removed sysctl "
2348 "system call with ", current
->comm
);
2349 for (i
= 0; i
< tmp
.nlen
; i
++)
2350 printk("%d.", name
[i
]);
2357 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2358 void __user
*oldval
, size_t __user
*oldlenp
,
2359 void __user
*newval
, size_t newlen
)
2364 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2365 void __user
*oldval
, size_t __user
*oldlenp
,
2366 void __user
*newval
, size_t newlen
)
2371 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2372 void __user
*oldval
, size_t __user
*oldlenp
,
2373 void __user
*newval
, size_t newlen
)
2378 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2379 void __user
*oldval
, size_t __user
*oldlenp
,
2380 void __user
*newval
, size_t newlen
)
2385 #endif /* CONFIG_SYSCTL_SYSCALL */
2388 * No sense putting this after each symbol definition, twice,
2389 * exception granted :-)
2391 EXPORT_SYMBOL(proc_dointvec
);
2392 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2393 EXPORT_SYMBOL(proc_dointvec_minmax
);
2394 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2395 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2396 EXPORT_SYMBOL(proc_dostring
);
2397 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2398 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2399 EXPORT_SYMBOL(register_sysctl_table
);
2400 EXPORT_SYMBOL(sysctl_intvec
);
2401 EXPORT_SYMBOL(sysctl_jiffies
);
2402 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2403 EXPORT_SYMBOL(sysctl_string
);
2404 EXPORT_SYMBOL(unregister_sysctl_table
);