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
;
81 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
82 static int maxolduid
= 65535;
84 static int min_percpu_pagelist_fract
= 8;
86 static int ngroups_max
= NGROUPS_MAX
;
89 extern char modprobe_path
[];
91 #ifdef CONFIG_CHR_DEV_SG
92 extern int sg_big_buff
;
96 extern char reboot_command
[];
97 extern int stop_a_enabled
;
98 extern int scons_pwroff
;
102 extern int pwrsw_enabled
;
103 extern int unaligned_enabled
;
107 #ifdef CONFIG_MATHEMU
108 extern int sysctl_ieee_emulation_warnings
;
110 extern int sysctl_userprocess_debug
;
111 extern int spin_retry
;
114 extern int sysctl_hz_timer
;
116 #ifdef CONFIG_BSD_PROCESS_ACCT
117 extern int acct_parm
[];
121 extern int no_unaligned_warning
;
124 #ifdef CONFIG_RT_MUTEXES
125 extern int max_lock_depth
;
128 #ifdef CONFIG_SYSCTL_SYSCALL
129 static int parse_table(int __user
*, int, void __user
*, size_t __user
*,
130 void __user
*, size_t, ctl_table
*);
134 #ifdef CONFIG_PROC_SYSCTL
135 static int proc_do_cad_pid(ctl_table
*table
, int write
, struct file
*filp
,
136 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
137 static int proc_dointvec_taint(ctl_table
*table
, int write
, struct file
*filp
,
138 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
141 static ctl_table root_table
[];
142 static struct ctl_table_header root_table_header
=
143 { root_table
, LIST_HEAD_INIT(root_table_header
.ctl_entry
) };
145 static ctl_table kern_table
[];
146 static ctl_table vm_table
[];
147 static ctl_table fs_table
[];
148 static ctl_table debug_table
[];
149 static ctl_table dev_table
[];
150 extern ctl_table random_table
[];
151 #ifdef CONFIG_UNIX98_PTYS
152 extern ctl_table pty_table
[];
154 #ifdef CONFIG_INOTIFY_USER
155 extern ctl_table inotify_table
[];
158 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
159 int sysctl_legacy_va_layout
;
163 /* The default sysctl tables: */
165 static ctl_table root_table
[] = {
167 .ctl_name
= CTL_KERN
,
168 .procname
= "kernel",
193 .ctl_name
= CTL_DEBUG
,
196 .child
= debug_table
,
208 static ctl_table kern_table
[] = {
210 .ctl_name
= KERN_PANIC
,
212 .data
= &panic_timeout
,
213 .maxlen
= sizeof(int),
215 .proc_handler
= &proc_dointvec
,
218 .ctl_name
= KERN_CORE_USES_PID
,
219 .procname
= "core_uses_pid",
220 .data
= &core_uses_pid
,
221 .maxlen
= sizeof(int),
223 .proc_handler
= &proc_dointvec
,
226 .ctl_name
= KERN_CORE_PATTERN
,
227 .procname
= "core_pattern",
228 .data
= core_pattern
,
231 .proc_handler
= &proc_dostring
,
232 .strategy
= &sysctl_string
,
234 #ifdef CONFIG_PROC_SYSCTL
236 .ctl_name
= KERN_TAINTED
,
237 .procname
= "tainted",
239 .maxlen
= sizeof(int),
241 .proc_handler
= &proc_dointvec_taint
,
245 .ctl_name
= KERN_CAP_BSET
,
246 .procname
= "cap-bound",
248 .maxlen
= sizeof(kernel_cap_t
),
250 .proc_handler
= &proc_dointvec_bset
,
252 #ifdef CONFIG_BLK_DEV_INITRD
254 .ctl_name
= KERN_REALROOTDEV
,
255 .procname
= "real-root-dev",
256 .data
= &real_root_dev
,
257 .maxlen
= sizeof(int),
259 .proc_handler
= &proc_dointvec
,
264 .ctl_name
= KERN_SPARC_REBOOT
,
265 .procname
= "reboot-cmd",
266 .data
= reboot_command
,
269 .proc_handler
= &proc_dostring
,
270 .strategy
= &sysctl_string
,
273 .ctl_name
= KERN_SPARC_STOP_A
,
274 .procname
= "stop-a",
275 .data
= &stop_a_enabled
,
276 .maxlen
= sizeof (int),
278 .proc_handler
= &proc_dointvec
,
281 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
282 .procname
= "scons-poweroff",
283 .data
= &scons_pwroff
,
284 .maxlen
= sizeof (int),
286 .proc_handler
= &proc_dointvec
,
291 .ctl_name
= KERN_HPPA_PWRSW
,
292 .procname
= "soft-power",
293 .data
= &pwrsw_enabled
,
294 .maxlen
= sizeof (int),
296 .proc_handler
= &proc_dointvec
,
299 .ctl_name
= KERN_HPPA_UNALIGNED
,
300 .procname
= "unaligned-trap",
301 .data
= &unaligned_enabled
,
302 .maxlen
= sizeof (int),
304 .proc_handler
= &proc_dointvec
,
308 .ctl_name
= KERN_CTLALTDEL
,
309 .procname
= "ctrl-alt-del",
311 .maxlen
= sizeof(int),
313 .proc_handler
= &proc_dointvec
,
316 .ctl_name
= KERN_PRINTK
,
317 .procname
= "printk",
318 .data
= &console_loglevel
,
319 .maxlen
= 4*sizeof(int),
321 .proc_handler
= &proc_dointvec
,
325 .ctl_name
= KERN_MODPROBE
,
326 .procname
= "modprobe",
327 .data
= &modprobe_path
,
328 .maxlen
= KMOD_PATH_LEN
,
330 .proc_handler
= &proc_dostring
,
331 .strategy
= &sysctl_string
,
334 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
336 .ctl_name
= KERN_HOTPLUG
,
337 .procname
= "hotplug",
338 .data
= &uevent_helper
,
339 .maxlen
= UEVENT_HELPER_PATH_LEN
,
341 .proc_handler
= &proc_dostring
,
342 .strategy
= &sysctl_string
,
345 #ifdef CONFIG_CHR_DEV_SG
347 .ctl_name
= KERN_SG_BIG_BUFF
,
348 .procname
= "sg-big-buff",
349 .data
= &sg_big_buff
,
350 .maxlen
= sizeof (int),
352 .proc_handler
= &proc_dointvec
,
355 #ifdef CONFIG_BSD_PROCESS_ACCT
357 .ctl_name
= KERN_ACCT
,
360 .maxlen
= 3*sizeof(int),
362 .proc_handler
= &proc_dointvec
,
365 #ifdef CONFIG_MAGIC_SYSRQ
367 .ctl_name
= KERN_SYSRQ
,
369 .data
= &__sysrq_enabled
,
370 .maxlen
= sizeof (int),
372 .proc_handler
= &proc_dointvec
,
375 #ifdef CONFIG_PROC_SYSCTL
377 .ctl_name
= KERN_CADPID
,
378 .procname
= "cad_pid",
380 .maxlen
= sizeof (int),
382 .proc_handler
= &proc_do_cad_pid
,
386 .ctl_name
= KERN_MAX_THREADS
,
387 .procname
= "threads-max",
388 .data
= &max_threads
,
389 .maxlen
= sizeof(int),
391 .proc_handler
= &proc_dointvec
,
394 .ctl_name
= KERN_RANDOM
,
395 .procname
= "random",
397 .child
= random_table
,
399 #ifdef CONFIG_UNIX98_PTYS
401 .ctl_name
= KERN_PTY
,
408 .ctl_name
= KERN_OVERFLOWUID
,
409 .procname
= "overflowuid",
410 .data
= &overflowuid
,
411 .maxlen
= sizeof(int),
413 .proc_handler
= &proc_dointvec_minmax
,
414 .strategy
= &sysctl_intvec
,
415 .extra1
= &minolduid
,
416 .extra2
= &maxolduid
,
419 .ctl_name
= KERN_OVERFLOWGID
,
420 .procname
= "overflowgid",
421 .data
= &overflowgid
,
422 .maxlen
= sizeof(int),
424 .proc_handler
= &proc_dointvec_minmax
,
425 .strategy
= &sysctl_intvec
,
426 .extra1
= &minolduid
,
427 .extra2
= &maxolduid
,
430 #ifdef CONFIG_MATHEMU
432 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
433 .procname
= "ieee_emulation_warnings",
434 .data
= &sysctl_ieee_emulation_warnings
,
435 .maxlen
= sizeof(int),
437 .proc_handler
= &proc_dointvec
,
440 #ifdef CONFIG_NO_IDLE_HZ
442 .ctl_name
= KERN_HZ_TIMER
,
443 .procname
= "hz_timer",
444 .data
= &sysctl_hz_timer
,
445 .maxlen
= sizeof(int),
447 .proc_handler
= &proc_dointvec
,
451 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
452 .procname
= "userprocess_debug",
453 .data
= &sysctl_userprocess_debug
,
454 .maxlen
= sizeof(int),
456 .proc_handler
= &proc_dointvec
,
460 .ctl_name
= KERN_PIDMAX
,
461 .procname
= "pid_max",
463 .maxlen
= sizeof (int),
465 .proc_handler
= &proc_dointvec_minmax
,
466 .strategy
= sysctl_intvec
,
467 .extra1
= &pid_max_min
,
468 .extra2
= &pid_max_max
,
471 .ctl_name
= KERN_PANIC_ON_OOPS
,
472 .procname
= "panic_on_oops",
473 .data
= &panic_on_oops
,
474 .maxlen
= sizeof(int),
476 .proc_handler
= &proc_dointvec
,
479 .ctl_name
= KERN_PRINTK_RATELIMIT
,
480 .procname
= "printk_ratelimit",
481 .data
= &printk_ratelimit_jiffies
,
482 .maxlen
= sizeof(int),
484 .proc_handler
= &proc_dointvec_jiffies
,
485 .strategy
= &sysctl_jiffies
,
488 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
489 .procname
= "printk_ratelimit_burst",
490 .data
= &printk_ratelimit_burst
,
491 .maxlen
= sizeof(int),
493 .proc_handler
= &proc_dointvec
,
496 .ctl_name
= KERN_NGROUPS_MAX
,
497 .procname
= "ngroups_max",
498 .data
= &ngroups_max
,
499 .maxlen
= sizeof (int),
501 .proc_handler
= &proc_dointvec
,
503 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
505 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
506 .procname
= "unknown_nmi_panic",
507 .data
= &unknown_nmi_panic
,
508 .maxlen
= sizeof (int),
510 .proc_handler
= &proc_dointvec
,
513 .ctl_name
= KERN_NMI_WATCHDOG
,
514 .procname
= "nmi_watchdog",
515 .data
= &nmi_watchdog_enabled
,
516 .maxlen
= sizeof (int),
518 .proc_handler
= &proc_nmi_enabled
,
521 #if defined(CONFIG_X86)
523 .ctl_name
= KERN_PANIC_ON_NMI
,
524 .procname
= "panic_on_unrecovered_nmi",
525 .data
= &panic_on_unrecovered_nmi
,
526 .maxlen
= sizeof(int),
528 .proc_handler
= &proc_dointvec
,
531 .ctl_name
= KERN_BOOTLOADER_TYPE
,
532 .procname
= "bootloader_type",
533 .data
= &bootloader_type
,
534 .maxlen
= sizeof (int),
536 .proc_handler
= &proc_dointvec
,
539 .ctl_name
= CTL_UNNUMBERED
,
540 .procname
= "kstack_depth_to_print",
541 .data
= &kstack_depth_to_print
,
542 .maxlen
= sizeof(int),
544 .proc_handler
= &proc_dointvec
,
547 #if defined(CONFIG_MMU)
549 .ctl_name
= KERN_RANDOMIZE
,
550 .procname
= "randomize_va_space",
551 .data
= &randomize_va_space
,
552 .maxlen
= sizeof(int),
554 .proc_handler
= &proc_dointvec
,
557 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
559 .ctl_name
= KERN_SPIN_RETRY
,
560 .procname
= "spin_retry",
562 .maxlen
= sizeof (int),
564 .proc_handler
= &proc_dointvec
,
567 #ifdef CONFIG_ACPI_SLEEP
569 .ctl_name
= KERN_ACPI_VIDEO_FLAGS
,
570 .procname
= "acpi_video_flags",
571 .data
= &acpi_video_flags
,
572 .maxlen
= sizeof (unsigned long),
574 .proc_handler
= &proc_doulongvec_minmax
,
579 .ctl_name
= KERN_IA64_UNALIGNED
,
580 .procname
= "ignore-unaligned-usertrap",
581 .data
= &no_unaligned_warning
,
582 .maxlen
= sizeof (int),
584 .proc_handler
= &proc_dointvec
,
589 .ctl_name
= KERN_COMPAT_LOG
,
590 .procname
= "compat-log",
592 .maxlen
= sizeof (int),
594 .proc_handler
= &proc_dointvec
,
597 #ifdef CONFIG_RT_MUTEXES
599 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
600 .procname
= "max_lock_depth",
601 .data
= &max_lock_depth
,
602 .maxlen
= sizeof(int),
604 .proc_handler
= &proc_dointvec
,
607 #ifdef CONFIG_PROC_FS
609 .ctl_name
= CTL_UNNUMBERED
,
610 .procname
= "maps_protect",
611 .data
= &maps_protect
,
612 .maxlen
= sizeof(int),
614 .proc_handler
= &proc_dointvec
,
621 /* Constants for minimum and maximum testing in vm_table.
622 We use these as one-element integer vectors. */
624 static int one_hundred
= 100;
627 static ctl_table vm_table
[] = {
629 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
630 .procname
= "overcommit_memory",
631 .data
= &sysctl_overcommit_memory
,
632 .maxlen
= sizeof(sysctl_overcommit_memory
),
634 .proc_handler
= &proc_dointvec
,
637 .ctl_name
= VM_PANIC_ON_OOM
,
638 .procname
= "panic_on_oom",
639 .data
= &sysctl_panic_on_oom
,
640 .maxlen
= sizeof(sysctl_panic_on_oom
),
642 .proc_handler
= &proc_dointvec
,
645 .ctl_name
= VM_OVERCOMMIT_RATIO
,
646 .procname
= "overcommit_ratio",
647 .data
= &sysctl_overcommit_ratio
,
648 .maxlen
= sizeof(sysctl_overcommit_ratio
),
650 .proc_handler
= &proc_dointvec
,
653 .ctl_name
= VM_PAGE_CLUSTER
,
654 .procname
= "page-cluster",
655 .data
= &page_cluster
,
656 .maxlen
= sizeof(int),
658 .proc_handler
= &proc_dointvec
,
661 .ctl_name
= VM_DIRTY_BACKGROUND
,
662 .procname
= "dirty_background_ratio",
663 .data
= &dirty_background_ratio
,
664 .maxlen
= sizeof(dirty_background_ratio
),
666 .proc_handler
= &proc_dointvec_minmax
,
667 .strategy
= &sysctl_intvec
,
669 .extra2
= &one_hundred
,
672 .ctl_name
= VM_DIRTY_RATIO
,
673 .procname
= "dirty_ratio",
674 .data
= &vm_dirty_ratio
,
675 .maxlen
= sizeof(vm_dirty_ratio
),
677 .proc_handler
= &proc_dointvec_minmax
,
678 .strategy
= &sysctl_intvec
,
680 .extra2
= &one_hundred
,
683 .ctl_name
= VM_DIRTY_WB_CS
,
684 .procname
= "dirty_writeback_centisecs",
685 .data
= &dirty_writeback_interval
,
686 .maxlen
= sizeof(dirty_writeback_interval
),
688 .proc_handler
= &dirty_writeback_centisecs_handler
,
691 .ctl_name
= VM_DIRTY_EXPIRE_CS
,
692 .procname
= "dirty_expire_centisecs",
693 .data
= &dirty_expire_interval
,
694 .maxlen
= sizeof(dirty_expire_interval
),
696 .proc_handler
= &proc_dointvec_userhz_jiffies
,
699 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
700 .procname
= "nr_pdflush_threads",
701 .data
= &nr_pdflush_threads
,
702 .maxlen
= sizeof nr_pdflush_threads
,
703 .mode
= 0444 /* read-only*/,
704 .proc_handler
= &proc_dointvec
,
707 .ctl_name
= VM_SWAPPINESS
,
708 .procname
= "swappiness",
709 .data
= &vm_swappiness
,
710 .maxlen
= sizeof(vm_swappiness
),
712 .proc_handler
= &proc_dointvec_minmax
,
713 .strategy
= &sysctl_intvec
,
715 .extra2
= &one_hundred
,
717 #ifdef CONFIG_HUGETLB_PAGE
719 .ctl_name
= VM_HUGETLB_PAGES
,
720 .procname
= "nr_hugepages",
721 .data
= &max_huge_pages
,
722 .maxlen
= sizeof(unsigned long),
724 .proc_handler
= &hugetlb_sysctl_handler
,
725 .extra1
= (void *)&hugetlb_zero
,
726 .extra2
= (void *)&hugetlb_infinity
,
729 .ctl_name
= VM_HUGETLB_GROUP
,
730 .procname
= "hugetlb_shm_group",
731 .data
= &sysctl_hugetlb_shm_group
,
732 .maxlen
= sizeof(gid_t
),
734 .proc_handler
= &proc_dointvec
,
738 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
739 .procname
= "lowmem_reserve_ratio",
740 .data
= &sysctl_lowmem_reserve_ratio
,
741 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
743 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
744 .strategy
= &sysctl_intvec
,
747 .ctl_name
= VM_DROP_PAGECACHE
,
748 .procname
= "drop_caches",
749 .data
= &sysctl_drop_caches
,
750 .maxlen
= sizeof(int),
752 .proc_handler
= drop_caches_sysctl_handler
,
753 .strategy
= &sysctl_intvec
,
756 .ctl_name
= VM_MIN_FREE_KBYTES
,
757 .procname
= "min_free_kbytes",
758 .data
= &min_free_kbytes
,
759 .maxlen
= sizeof(min_free_kbytes
),
761 .proc_handler
= &min_free_kbytes_sysctl_handler
,
762 .strategy
= &sysctl_intvec
,
766 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
767 .procname
= "percpu_pagelist_fraction",
768 .data
= &percpu_pagelist_fraction
,
769 .maxlen
= sizeof(percpu_pagelist_fraction
),
771 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
772 .strategy
= &sysctl_intvec
,
773 .extra1
= &min_percpu_pagelist_fract
,
777 .ctl_name
= VM_MAX_MAP_COUNT
,
778 .procname
= "max_map_count",
779 .data
= &sysctl_max_map_count
,
780 .maxlen
= sizeof(sysctl_max_map_count
),
782 .proc_handler
= &proc_dointvec
786 .ctl_name
= VM_LAPTOP_MODE
,
787 .procname
= "laptop_mode",
788 .data
= &laptop_mode
,
789 .maxlen
= sizeof(laptop_mode
),
791 .proc_handler
= &proc_dointvec_jiffies
,
792 .strategy
= &sysctl_jiffies
,
795 .ctl_name
= VM_BLOCK_DUMP
,
796 .procname
= "block_dump",
798 .maxlen
= sizeof(block_dump
),
800 .proc_handler
= &proc_dointvec
,
801 .strategy
= &sysctl_intvec
,
805 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
806 .procname
= "vfs_cache_pressure",
807 .data
= &sysctl_vfs_cache_pressure
,
808 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
810 .proc_handler
= &proc_dointvec
,
811 .strategy
= &sysctl_intvec
,
814 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
816 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
817 .procname
= "legacy_va_layout",
818 .data
= &sysctl_legacy_va_layout
,
819 .maxlen
= sizeof(sysctl_legacy_va_layout
),
821 .proc_handler
= &proc_dointvec
,
822 .strategy
= &sysctl_intvec
,
828 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
829 .procname
= "zone_reclaim_mode",
830 .data
= &zone_reclaim_mode
,
831 .maxlen
= sizeof(zone_reclaim_mode
),
833 .proc_handler
= &proc_dointvec
,
834 .strategy
= &sysctl_intvec
,
838 .ctl_name
= VM_MIN_UNMAPPED
,
839 .procname
= "min_unmapped_ratio",
840 .data
= &sysctl_min_unmapped_ratio
,
841 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
843 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
844 .strategy
= &sysctl_intvec
,
846 .extra2
= &one_hundred
,
849 .ctl_name
= VM_MIN_SLAB
,
850 .procname
= "min_slab_ratio",
851 .data
= &sysctl_min_slab_ratio
,
852 .maxlen
= sizeof(sysctl_min_slab_ratio
),
854 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
855 .strategy
= &sysctl_intvec
,
857 .extra2
= &one_hundred
,
860 #if defined(CONFIG_X86_32) || \
861 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
863 .ctl_name
= VM_VDSO_ENABLED
,
864 .procname
= "vdso_enabled",
865 .data
= &vdso_enabled
,
866 .maxlen
= sizeof(vdso_enabled
),
868 .proc_handler
= &proc_dointvec
,
869 .strategy
= &sysctl_intvec
,
876 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
877 static ctl_table binfmt_misc_table
[] = {
882 static ctl_table fs_table
[] = {
884 .ctl_name
= FS_NRINODE
,
885 .procname
= "inode-nr",
886 .data
= &inodes_stat
,
887 .maxlen
= 2*sizeof(int),
889 .proc_handler
= &proc_dointvec
,
892 .ctl_name
= FS_STATINODE
,
893 .procname
= "inode-state",
894 .data
= &inodes_stat
,
895 .maxlen
= 7*sizeof(int),
897 .proc_handler
= &proc_dointvec
,
900 .ctl_name
= FS_NRFILE
,
901 .procname
= "file-nr",
903 .maxlen
= 3*sizeof(int),
905 .proc_handler
= &proc_nr_files
,
908 .ctl_name
= FS_MAXFILE
,
909 .procname
= "file-max",
910 .data
= &files_stat
.max_files
,
911 .maxlen
= sizeof(int),
913 .proc_handler
= &proc_dointvec
,
916 .ctl_name
= FS_DENTRY
,
917 .procname
= "dentry-state",
918 .data
= &dentry_stat
,
919 .maxlen
= 6*sizeof(int),
921 .proc_handler
= &proc_dointvec
,
924 .ctl_name
= FS_OVERFLOWUID
,
925 .procname
= "overflowuid",
926 .data
= &fs_overflowuid
,
927 .maxlen
= sizeof(int),
929 .proc_handler
= &proc_dointvec_minmax
,
930 .strategy
= &sysctl_intvec
,
931 .extra1
= &minolduid
,
932 .extra2
= &maxolduid
,
935 .ctl_name
= FS_OVERFLOWGID
,
936 .procname
= "overflowgid",
937 .data
= &fs_overflowgid
,
938 .maxlen
= sizeof(int),
940 .proc_handler
= &proc_dointvec_minmax
,
941 .strategy
= &sysctl_intvec
,
942 .extra1
= &minolduid
,
943 .extra2
= &maxolduid
,
946 .ctl_name
= FS_LEASES
,
947 .procname
= "leases-enable",
948 .data
= &leases_enable
,
949 .maxlen
= sizeof(int),
951 .proc_handler
= &proc_dointvec
,
953 #ifdef CONFIG_DNOTIFY
955 .ctl_name
= FS_DIR_NOTIFY
,
956 .procname
= "dir-notify-enable",
957 .data
= &dir_notify_enable
,
958 .maxlen
= sizeof(int),
960 .proc_handler
= &proc_dointvec
,
965 .ctl_name
= FS_LEASE_TIME
,
966 .procname
= "lease-break-time",
967 .data
= &lease_break_time
,
968 .maxlen
= sizeof(int),
970 .proc_handler
= &proc_dointvec
,
973 .ctl_name
= FS_AIO_NR
,
974 .procname
= "aio-nr",
976 .maxlen
= sizeof(aio_nr
),
978 .proc_handler
= &proc_doulongvec_minmax
,
981 .ctl_name
= FS_AIO_MAX_NR
,
982 .procname
= "aio-max-nr",
984 .maxlen
= sizeof(aio_max_nr
),
986 .proc_handler
= &proc_doulongvec_minmax
,
988 #ifdef CONFIG_INOTIFY_USER
990 .ctl_name
= FS_INOTIFY
,
991 .procname
= "inotify",
993 .child
= inotify_table
,
998 .ctl_name
= KERN_SETUID_DUMPABLE
,
999 .procname
= "suid_dumpable",
1000 .data
= &suid_dumpable
,
1001 .maxlen
= sizeof(int),
1003 .proc_handler
= &proc_dointvec
,
1005 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1007 .ctl_name
= CTL_UNNUMBERED
,
1008 .procname
= "binfmt_misc",
1010 .child
= binfmt_misc_table
,
1016 static ctl_table debug_table
[] = {
1020 static ctl_table dev_table
[] = {
1024 static DEFINE_SPINLOCK(sysctl_lock
);
1026 /* called under sysctl_lock */
1027 static int use_table(struct ctl_table_header
*p
)
1029 if (unlikely(p
->unregistering
))
1035 /* called under sysctl_lock */
1036 static void unuse_table(struct ctl_table_header
*p
)
1039 if (unlikely(p
->unregistering
))
1040 complete(p
->unregistering
);
1043 /* called under sysctl_lock, will reacquire if has to wait */
1044 static void start_unregistering(struct ctl_table_header
*p
)
1047 * if p->used is 0, nobody will ever touch that entry again;
1048 * we'll eliminate all paths to it before dropping sysctl_lock
1050 if (unlikely(p
->used
)) {
1051 struct completion wait
;
1052 init_completion(&wait
);
1053 p
->unregistering
= &wait
;
1054 spin_unlock(&sysctl_lock
);
1055 wait_for_completion(&wait
);
1056 spin_lock(&sysctl_lock
);
1059 * do not remove from the list until nobody holds it; walking the
1060 * list in do_sysctl() relies on that.
1062 list_del_init(&p
->ctl_entry
);
1065 void sysctl_head_finish(struct ctl_table_header
*head
)
1069 spin_lock(&sysctl_lock
);
1071 spin_unlock(&sysctl_lock
);
1074 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1076 struct ctl_table_header
*head
;
1077 struct list_head
*tmp
;
1078 spin_lock(&sysctl_lock
);
1080 tmp
= &prev
->ctl_entry
;
1084 tmp
= &root_table_header
.ctl_entry
;
1086 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1088 if (!use_table(head
))
1090 spin_unlock(&sysctl_lock
);
1094 if (tmp
== &root_table_header
.ctl_entry
)
1097 spin_unlock(&sysctl_lock
);
1101 #ifdef CONFIG_SYSCTL_SYSCALL
1102 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1103 void __user
*newval
, size_t newlen
)
1105 struct ctl_table_header
*head
;
1106 int error
= -ENOTDIR
;
1108 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1112 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1116 for (head
= sysctl_head_next(NULL
); head
;
1117 head
= sysctl_head_next(head
)) {
1118 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1119 newval
, newlen
, head
->ctl_table
);
1120 if (error
!= -ENOTDIR
) {
1121 sysctl_head_finish(head
);
1128 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1130 struct __sysctl_args tmp
;
1133 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1137 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1138 tmp
.newval
, tmp
.newlen
);
1142 #endif /* CONFIG_SYSCTL_SYSCALL */
1145 * sysctl_perm does NOT grant the superuser all rights automatically, because
1146 * some sysctl variables are readonly even to root.
1149 static int test_perm(int mode
, int op
)
1153 else if (in_egroup_p(0))
1155 if ((mode
& op
& 0007) == op
)
1160 int sysctl_perm(ctl_table
*table
, int op
)
1163 error
= security_sysctl(table
, op
);
1166 return test_perm(table
->mode
, op
);
1169 #ifdef CONFIG_SYSCTL_SYSCALL
1170 static int parse_table(int __user
*name
, int nlen
,
1171 void __user
*oldval
, size_t __user
*oldlenp
,
1172 void __user
*newval
, size_t newlen
,
1179 if (get_user(n
, name
))
1181 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1182 if (!table
->ctl_name
)
1184 if (n
== table
->ctl_name
) {
1187 if (sysctl_perm(table
, 001))
1191 table
= table
->child
;
1194 error
= do_sysctl_strategy(table
, name
, nlen
,
1203 /* Perform the actual read/write of a sysctl table entry. */
1204 int do_sysctl_strategy (ctl_table
*table
,
1205 int __user
*name
, int nlen
,
1206 void __user
*oldval
, size_t __user
*oldlenp
,
1207 void __user
*newval
, size_t newlen
)
1216 if (sysctl_perm(table
, op
))
1219 if (table
->strategy
) {
1220 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1228 /* If there is no strategy routine, or if the strategy returns
1229 * zero, proceed with automatic r/w */
1230 if (table
->data
&& table
->maxlen
) {
1231 if (oldval
&& oldlenp
) {
1232 if (get_user(len
, oldlenp
))
1235 if (len
> table
->maxlen
)
1236 len
= table
->maxlen
;
1237 if(copy_to_user(oldval
, table
->data
, len
))
1239 if(put_user(len
, oldlenp
))
1243 if (newval
&& newlen
) {
1245 if (len
> table
->maxlen
)
1246 len
= table
->maxlen
;
1247 if(copy_from_user(table
->data
, newval
, len
))
1253 #endif /* CONFIG_SYSCTL_SYSCALL */
1255 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1257 for (; table
->ctl_name
|| table
->procname
; table
++) {
1258 table
->parent
= parent
;
1260 sysctl_set_parent(table
, table
->child
);
1264 static __init
int sysctl_init(void)
1266 sysctl_set_parent(NULL
, root_table
);
1270 core_initcall(sysctl_init
);
1273 * register_sysctl_table - register a sysctl hierarchy
1274 * @table: the top-level table structure
1276 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1277 * array. An entry with a ctl_name of 0 terminates the table.
1279 * The members of the &ctl_table structure are used as follows:
1281 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1282 * must be unique within that level of sysctl
1284 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1285 * enter a sysctl file
1287 * data - a pointer to data for use by proc_handler
1289 * maxlen - the maximum size in bytes of the data
1291 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1293 * child - a pointer to the child sysctl table if this entry is a directory, or
1296 * proc_handler - the text handler routine (described below)
1298 * strategy - the strategy routine (described below)
1300 * de - for internal use by the sysctl routines
1302 * extra1, extra2 - extra pointers usable by the proc handler routines
1304 * Leaf nodes in the sysctl tree will be represented by a single file
1305 * under /proc; non-leaf nodes will be represented by directories.
1307 * sysctl(2) can automatically manage read and write requests through
1308 * the sysctl table. The data and maxlen fields of the ctl_table
1309 * struct enable minimal validation of the values being written to be
1310 * performed, and the mode field allows minimal authentication.
1312 * More sophisticated management can be enabled by the provision of a
1313 * strategy routine with the table entry. This will be called before
1314 * any automatic read or write of the data is performed.
1316 * The strategy routine may return
1318 * < 0 - Error occurred (error is passed to user process)
1320 * 0 - OK - proceed with automatic read or write.
1322 * > 0 - OK - read or write has been done by the strategy routine, so
1323 * return immediately.
1325 * There must be a proc_handler routine for any terminal nodes
1326 * mirrored under /proc/sys (non-terminals are handled by a built-in
1327 * directory handler). Several default handlers are available to
1328 * cover common cases -
1330 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1331 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1332 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1334 * It is the handler's job to read the input buffer from user memory
1335 * and process it. The handler should return 0 on success.
1337 * This routine returns %NULL on a failure to register, and a pointer
1338 * to the table header on success.
1340 struct ctl_table_header
*register_sysctl_table(ctl_table
* table
)
1342 struct ctl_table_header
*tmp
;
1343 tmp
= kmalloc(sizeof(struct ctl_table_header
), GFP_KERNEL
);
1346 tmp
->ctl_table
= table
;
1347 INIT_LIST_HEAD(&tmp
->ctl_entry
);
1349 tmp
->unregistering
= NULL
;
1350 sysctl_set_parent(NULL
, table
);
1351 spin_lock(&sysctl_lock
);
1352 list_add_tail(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1353 spin_unlock(&sysctl_lock
);
1358 * unregister_sysctl_table - unregister a sysctl table hierarchy
1359 * @header: the header returned from register_sysctl_table
1361 * Unregisters the sysctl table and all children. proc entries may not
1362 * actually be removed until they are no longer used by anyone.
1364 void unregister_sysctl_table(struct ctl_table_header
* header
)
1367 spin_lock(&sysctl_lock
);
1368 start_unregistering(header
);
1369 spin_unlock(&sysctl_lock
);
1373 #else /* !CONFIG_SYSCTL */
1374 struct ctl_table_header
*register_sysctl_table(ctl_table
* table
)
1379 void unregister_sysctl_table(struct ctl_table_header
* table
)
1383 #endif /* CONFIG_SYSCTL */
1389 #ifdef CONFIG_PROC_SYSCTL
1391 static int _proc_do_string(void* data
, int maxlen
, int write
,
1392 struct file
*filp
, void __user
*buffer
,
1393 size_t *lenp
, loff_t
*ppos
)
1399 if (!data
|| !maxlen
|| !*lenp
) {
1407 while (len
< *lenp
) {
1408 if (get_user(c
, p
++))
1410 if (c
== 0 || c
== '\n')
1416 if(copy_from_user(data
, buffer
, len
))
1418 ((char *) data
)[len
] = 0;
1436 if(copy_to_user(buffer
, data
, len
))
1439 if(put_user('\n', ((char __user
*) buffer
) + len
))
1450 * proc_dostring - read a string sysctl
1451 * @table: the sysctl table
1452 * @write: %TRUE if this is a write to the sysctl file
1453 * @filp: the file structure
1454 * @buffer: the user buffer
1455 * @lenp: the size of the user buffer
1456 * @ppos: file position
1458 * Reads/writes a string from/to the user buffer. If the kernel
1459 * buffer provided is not large enough to hold the string, the
1460 * string is truncated. The copied string is %NULL-terminated.
1461 * If the string is being read by the user process, it is copied
1462 * and a newline '\n' is added. It is truncated if the buffer is
1465 * Returns 0 on success.
1467 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1468 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1470 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
1471 buffer
, lenp
, ppos
);
1475 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1477 int write
, void *data
)
1480 *valp
= *negp
? -*lvalp
: *lvalp
;
1485 *lvalp
= (unsigned long)-val
;
1488 *lvalp
= (unsigned long)val
;
1494 static int __do_proc_dointvec(void *tbl_data
, ctl_table
*table
,
1495 int write
, struct file
*filp
, void __user
*buffer
,
1496 size_t *lenp
, loff_t
*ppos
,
1497 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1498 int write
, void *data
),
1501 #define TMPBUFLEN 21
1502 int *i
, vleft
, first
=1, neg
, val
;
1506 char buf
[TMPBUFLEN
], *p
;
1507 char __user
*s
= buffer
;
1509 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
1510 (*ppos
&& !write
)) {
1515 i
= (int *) tbl_data
;
1516 vleft
= table
->maxlen
/ sizeof(*i
);
1520 conv
= do_proc_dointvec_conv
;
1522 for (; left
&& vleft
--; i
++, first
=0) {
1537 if (len
> sizeof(buf
) - 1)
1538 len
= sizeof(buf
) - 1;
1539 if (copy_from_user(buf
, s
, len
))
1543 if (*p
== '-' && left
> 1) {
1547 if (*p
< '0' || *p
> '9')
1550 lval
= simple_strtoul(p
, &p
, 0);
1553 if ((len
< left
) && *p
&& !isspace(*p
))
1560 if (conv(&neg
, &lval
, i
, 1, data
))
1567 if (conv(&neg
, &lval
, i
, 0, data
))
1570 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
1574 if(copy_to_user(s
, buf
, len
))
1581 if (!write
&& !first
&& left
) {
1582 if(put_user('\n', s
))
1589 if (get_user(c
, s
++))
1604 static int do_proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1605 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1606 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1607 int write
, void *data
),
1610 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
1611 buffer
, lenp
, ppos
, conv
, data
);
1615 * proc_dointvec - read a vector of integers
1616 * @table: the sysctl table
1617 * @write: %TRUE if this is a write to the sysctl file
1618 * @filp: the file structure
1619 * @buffer: the user buffer
1620 * @lenp: the size of the user buffer
1621 * @ppos: file position
1623 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1624 * values from/to the user buffer, treated as an ASCII string.
1626 * Returns 0 on success.
1628 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1629 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1631 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1639 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
1641 int write
, void *data
)
1643 int op
= *(int *)data
;
1645 int val
= *negp
? -*lvalp
: *lvalp
;
1647 case OP_SET
: *valp
= val
; break;
1648 case OP_AND
: *valp
&= val
; break;
1649 case OP_OR
: *valp
|= val
; break;
1655 *lvalp
= (unsigned long)-val
;
1658 *lvalp
= (unsigned long)val
;
1665 * init may raise the set.
1668 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1669 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1673 if (write
&& !capable(CAP_SYS_MODULE
)) {
1677 op
= is_init(current
) ? OP_SET
: OP_AND
;
1678 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1679 do_proc_dointvec_bset_conv
,&op
);
1683 * Taint values can only be increased
1685 static int proc_dointvec_taint(ctl_table
*table
, int write
, struct file
*filp
,
1686 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1690 if (write
&& !capable(CAP_SYS_ADMIN
))
1694 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1695 do_proc_dointvec_bset_conv
,&op
);
1698 struct do_proc_dointvec_minmax_conv_param
{
1703 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
1705 int write
, void *data
)
1707 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
1709 int val
= *negp
? -*lvalp
: *lvalp
;
1710 if ((param
->min
&& *param
->min
> val
) ||
1711 (param
->max
&& *param
->max
< val
))
1718 *lvalp
= (unsigned long)-val
;
1721 *lvalp
= (unsigned long)val
;
1728 * proc_dointvec_minmax - read a vector of integers with min/max values
1729 * @table: the sysctl table
1730 * @write: %TRUE if this is a write to the sysctl file
1731 * @filp: the file structure
1732 * @buffer: the user buffer
1733 * @lenp: the size of the user buffer
1734 * @ppos: file position
1736 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1737 * values from/to the user buffer, treated as an ASCII string.
1739 * This routine will ensure the values are within the range specified by
1740 * table->extra1 (min) and table->extra2 (max).
1742 * Returns 0 on success.
1744 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1745 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1747 struct do_proc_dointvec_minmax_conv_param param
= {
1748 .min
= (int *) table
->extra1
,
1749 .max
= (int *) table
->extra2
,
1751 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
1752 do_proc_dointvec_minmax_conv
, ¶m
);
1755 static int __do_proc_doulongvec_minmax(void *data
, ctl_table
*table
, int write
,
1757 void __user
*buffer
,
1758 size_t *lenp
, loff_t
*ppos
,
1759 unsigned long convmul
,
1760 unsigned long convdiv
)
1762 #define TMPBUFLEN 21
1763 unsigned long *i
, *min
, *max
, val
;
1764 int vleft
, first
=1, neg
;
1766 char buf
[TMPBUFLEN
], *p
;
1767 char __user
*s
= buffer
;
1769 if (!data
|| !table
->maxlen
|| !*lenp
||
1770 (*ppos
&& !write
)) {
1775 i
= (unsigned long *) data
;
1776 min
= (unsigned long *) table
->extra1
;
1777 max
= (unsigned long *) table
->extra2
;
1778 vleft
= table
->maxlen
/ sizeof(unsigned long);
1781 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
1796 if (len
> TMPBUFLEN
-1)
1798 if (copy_from_user(buf
, s
, len
))
1802 if (*p
== '-' && left
> 1) {
1806 if (*p
< '0' || *p
> '9')
1808 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
1810 if ((len
< left
) && *p
&& !isspace(*p
))
1819 if ((min
&& val
< *min
) || (max
&& val
> *max
))
1826 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
1830 if(copy_to_user(s
, buf
, len
))
1837 if (!write
&& !first
&& left
) {
1838 if(put_user('\n', s
))
1845 if (get_user(c
, s
++))
1860 static int do_proc_doulongvec_minmax(ctl_table
*table
, int write
,
1862 void __user
*buffer
,
1863 size_t *lenp
, loff_t
*ppos
,
1864 unsigned long convmul
,
1865 unsigned long convdiv
)
1867 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
1868 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
1872 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1873 * @table: the sysctl table
1874 * @write: %TRUE if this is a write to the sysctl file
1875 * @filp: the file structure
1876 * @buffer: the user buffer
1877 * @lenp: the size of the user buffer
1878 * @ppos: file position
1880 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1881 * values from/to the user buffer, treated as an ASCII string.
1883 * This routine will ensure the values are within the range specified by
1884 * table->extra1 (min) and table->extra2 (max).
1886 * Returns 0 on success.
1888 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1889 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1891 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
1895 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1896 * @table: the sysctl table
1897 * @write: %TRUE if this is a write to the sysctl file
1898 * @filp: the file structure
1899 * @buffer: the user buffer
1900 * @lenp: the size of the user buffer
1901 * @ppos: file position
1903 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1904 * values from/to the user buffer, treated as an ASCII string. The values
1905 * are treated as milliseconds, and converted to jiffies when they are stored.
1907 * This routine will ensure the values are within the range specified by
1908 * table->extra1 (min) and table->extra2 (max).
1910 * Returns 0 on success.
1912 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
1914 void __user
*buffer
,
1915 size_t *lenp
, loff_t
*ppos
)
1917 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
1918 lenp
, ppos
, HZ
, 1000l);
1922 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
1924 int write
, void *data
)
1927 if (*lvalp
> LONG_MAX
/ HZ
)
1929 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
1935 lval
= (unsigned long)-val
;
1938 lval
= (unsigned long)val
;
1945 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
1947 int write
, void *data
)
1950 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
1952 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
1958 lval
= (unsigned long)-val
;
1961 lval
= (unsigned long)val
;
1963 *lvalp
= jiffies_to_clock_t(lval
);
1968 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
1970 int write
, void *data
)
1973 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
1979 lval
= (unsigned long)-val
;
1982 lval
= (unsigned long)val
;
1984 *lvalp
= jiffies_to_msecs(lval
);
1990 * proc_dointvec_jiffies - read a vector of integers as seconds
1991 * @table: the sysctl table
1992 * @write: %TRUE if this is a write to the sysctl file
1993 * @filp: the file structure
1994 * @buffer: the user buffer
1995 * @lenp: the size of the user buffer
1996 * @ppos: file position
1998 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1999 * values from/to the user buffer, treated as an ASCII string.
2000 * The values read are assumed to be in seconds, and are converted into
2003 * Returns 0 on success.
2005 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2006 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2008 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2009 do_proc_dointvec_jiffies_conv
,NULL
);
2013 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2014 * @table: the sysctl table
2015 * @write: %TRUE if this is a write to the sysctl file
2016 * @filp: the file structure
2017 * @buffer: the user buffer
2018 * @lenp: the size of the user buffer
2019 * @ppos: pointer to the file position
2021 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2022 * values from/to the user buffer, treated as an ASCII string.
2023 * The values read are assumed to be in 1/USER_HZ seconds, and
2024 * are converted into jiffies.
2026 * Returns 0 on success.
2028 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2029 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2031 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2032 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2036 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2037 * @table: the sysctl table
2038 * @write: %TRUE if this is a write to the sysctl file
2039 * @filp: the file structure
2040 * @buffer: the user buffer
2041 * @lenp: the size of the user buffer
2042 * @ppos: file position
2043 * @ppos: the current position in the file
2045 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2046 * values from/to the user buffer, treated as an ASCII string.
2047 * The values read are assumed to be in 1/1000 seconds, and
2048 * are converted into jiffies.
2050 * Returns 0 on success.
2052 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2053 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2055 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2056 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2059 static int proc_do_cad_pid(ctl_table
*table
, int write
, struct file
*filp
,
2060 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2062 struct pid
*new_pid
;
2066 tmp
= pid_nr(cad_pid
);
2068 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2069 lenp
, ppos
, NULL
, NULL
);
2073 new_pid
= find_get_pid(tmp
);
2077 put_pid(xchg(&cad_pid
, new_pid
));
2081 #else /* CONFIG_PROC_FS */
2083 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2084 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2089 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2090 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2095 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2096 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2101 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2102 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2107 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2108 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2113 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2114 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2119 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2120 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2125 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2126 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2131 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2133 void __user
*buffer
,
2134 size_t *lenp
, loff_t
*ppos
)
2140 #endif /* CONFIG_PROC_FS */
2143 #ifdef CONFIG_SYSCTL_SYSCALL
2145 * General sysctl support routines
2148 /* The generic string strategy routine: */
2149 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2150 void __user
*oldval
, size_t __user
*oldlenp
,
2151 void __user
*newval
, size_t newlen
)
2153 if (!table
->data
|| !table
->maxlen
)
2156 if (oldval
&& oldlenp
) {
2158 if (get_user(bufsize
, oldlenp
))
2161 size_t len
= strlen(table
->data
), copied
;
2163 /* This shouldn't trigger for a well-formed sysctl */
2164 if (len
> table
->maxlen
)
2165 len
= table
->maxlen
;
2167 /* Copy up to a max of bufsize-1 bytes of the string */
2168 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2170 if (copy_to_user(oldval
, table
->data
, copied
) ||
2171 put_user(0, (char __user
*)(oldval
+ copied
)))
2173 if (put_user(len
, oldlenp
))
2177 if (newval
&& newlen
) {
2178 size_t len
= newlen
;
2179 if (len
> table
->maxlen
)
2180 len
= table
->maxlen
;
2181 if(copy_from_user(table
->data
, newval
, len
))
2183 if (len
== table
->maxlen
)
2185 ((char *) table
->data
)[len
] = 0;
2191 * This function makes sure that all of the integers in the vector
2192 * are between the minimum and maximum values given in the arrays
2193 * table->extra1 and table->extra2, respectively.
2195 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2196 void __user
*oldval
, size_t __user
*oldlenp
,
2197 void __user
*newval
, size_t newlen
)
2200 if (newval
&& newlen
) {
2201 int __user
*vec
= (int __user
*) newval
;
2202 int *min
= (int *) table
->extra1
;
2203 int *max
= (int *) table
->extra2
;
2207 if (newlen
% sizeof(int) != 0)
2210 if (!table
->extra1
&& !table
->extra2
)
2213 if (newlen
> table
->maxlen
)
2214 newlen
= table
->maxlen
;
2215 length
= newlen
/ sizeof(int);
2217 for (i
= 0; i
< length
; i
++) {
2219 if (get_user(value
, vec
+ i
))
2221 if (min
&& value
< min
[i
])
2223 if (max
&& value
> max
[i
])
2230 /* Strategy function to convert jiffies to seconds */
2231 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2232 void __user
*oldval
, size_t __user
*oldlenp
,
2233 void __user
*newval
, size_t newlen
)
2235 if (oldval
&& oldlenp
) {
2238 if (get_user(olen
, oldlenp
))
2243 if (olen
< sizeof(int))
2246 val
= *(int *)(table
->data
) / HZ
;
2247 if (put_user(val
, (int __user
*)oldval
))
2249 if (put_user(sizeof(int), oldlenp
))
2253 if (newval
&& newlen
) {
2255 if (newlen
!= sizeof(int))
2257 if (get_user(new, (int __user
*)newval
))
2259 *(int *)(table
->data
) = new*HZ
;
2264 /* Strategy function to convert jiffies to seconds */
2265 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2266 void __user
*oldval
, size_t __user
*oldlenp
,
2267 void __user
*newval
, size_t newlen
)
2269 if (oldval
&& oldlenp
) {
2272 if (get_user(olen
, oldlenp
))
2277 if (olen
< sizeof(int))
2280 val
= jiffies_to_msecs(*(int *)(table
->data
));
2281 if (put_user(val
, (int __user
*)oldval
))
2283 if (put_user(sizeof(int), oldlenp
))
2287 if (newval
&& newlen
) {
2289 if (newlen
!= sizeof(int))
2291 if (get_user(new, (int __user
*)newval
))
2293 *(int *)(table
->data
) = msecs_to_jiffies(new);
2300 #else /* CONFIG_SYSCTL_SYSCALL */
2303 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2305 static int msg_count
;
2306 struct __sysctl_args tmp
;
2307 int name
[CTL_MAXNAME
];
2310 /* Read in the sysctl name for better debug message logging */
2311 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
2313 if (tmp
.nlen
<= 0 || tmp
.nlen
>= CTL_MAXNAME
)
2315 for (i
= 0; i
< tmp
.nlen
; i
++)
2316 if (get_user(name
[i
], tmp
.name
+ i
))
2319 /* Ignore accesses to kernel.version */
2320 if ((tmp
.nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
2323 if (msg_count
< 5) {
2326 "warning: process `%s' used the removed sysctl "
2327 "system call with ", current
->comm
);
2328 for (i
= 0; i
< tmp
.nlen
; i
++)
2329 printk("%d.", name
[i
]);
2336 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2337 void __user
*oldval
, size_t __user
*oldlenp
,
2338 void __user
*newval
, size_t newlen
)
2343 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2344 void __user
*oldval
, size_t __user
*oldlenp
,
2345 void __user
*newval
, size_t newlen
)
2350 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2351 void __user
*oldval
, size_t __user
*oldlenp
,
2352 void __user
*newval
, size_t newlen
)
2357 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2358 void __user
*oldval
, size_t __user
*oldlenp
,
2359 void __user
*newval
, size_t newlen
)
2364 #endif /* CONFIG_SYSCTL_SYSCALL */
2367 * No sense putting this after each symbol definition, twice,
2368 * exception granted :-)
2370 EXPORT_SYMBOL(proc_dointvec
);
2371 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2372 EXPORT_SYMBOL(proc_dointvec_minmax
);
2373 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2374 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2375 EXPORT_SYMBOL(proc_dostring
);
2376 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2377 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2378 EXPORT_SYMBOL(register_sysctl_table
);
2379 EXPORT_SYMBOL(sysctl_intvec
);
2380 EXPORT_SYMBOL(sysctl_jiffies
);
2381 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2382 EXPORT_SYMBOL(sysctl_string
);
2383 EXPORT_SYMBOL(unregister_sysctl_table
);