2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/proc_fs.h>
27 #include <linux/capability.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/capability.h>
31 #include <linux/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/hugetlb.h>
40 #include <linux/security.h>
41 #include <linux/initrd.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/nfs_fs.h>
47 #include <linux/acpi.h>
49 #include <asm/uaccess.h>
50 #include <asm/processor.h>
52 extern int proc_nr_files(ctl_table
*table
, int write
, struct file
*filp
,
53 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
57 #include <asm/stacktrace.h>
60 #if defined(CONFIG_SYSCTL)
62 /* External variables not in a header file. */
64 extern int sysctl_overcommit_memory
;
65 extern int sysctl_overcommit_ratio
;
66 extern int sysctl_panic_on_oom
;
67 extern int max_threads
;
68 extern int core_uses_pid
;
69 extern int suid_dumpable
;
70 extern char core_pattern
[];
72 extern int min_free_kbytes
;
73 extern int printk_ratelimit_jiffies
;
74 extern int printk_ratelimit_burst
;
75 extern int pid_max_min
, pid_max_max
;
76 extern int sysctl_drop_caches
;
77 extern int percpu_pagelist_fraction
;
78 extern int compat_log
;
79 extern int maps_protect
;
80 extern int sysctl_stat_interval
;
82 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
83 static int maxolduid
= 65535;
85 static int min_percpu_pagelist_fract
= 8;
87 static int ngroups_max
= NGROUPS_MAX
;
90 extern char modprobe_path
[];
92 #ifdef CONFIG_CHR_DEV_SG
93 extern int sg_big_buff
;
97 extern char reboot_command
[];
98 extern int stop_a_enabled
;
99 extern int scons_pwroff
;
103 extern int pwrsw_enabled
;
104 extern int unaligned_enabled
;
108 #ifdef CONFIG_MATHEMU
109 extern int sysctl_ieee_emulation_warnings
;
111 extern int sysctl_userprocess_debug
;
112 extern int spin_retry
;
115 extern int sysctl_hz_timer
;
117 #ifdef CONFIG_BSD_PROCESS_ACCT
118 extern int acct_parm
[];
122 extern int no_unaligned_warning
;
125 #ifdef CONFIG_RT_MUTEXES
126 extern int max_lock_depth
;
129 #ifdef CONFIG_SYSCTL_SYSCALL
130 static int parse_table(int __user
*, int, void __user
*, size_t __user
*,
131 void __user
*, size_t, ctl_table
*);
135 #ifdef CONFIG_PROC_SYSCTL
136 static int proc_do_cad_pid(ctl_table
*table
, int write
, struct file
*filp
,
137 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
138 static int proc_dointvec_taint(ctl_table
*table
, int write
, struct file
*filp
,
139 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
142 static ctl_table root_table
[];
143 static struct ctl_table_header root_table_header
=
144 { root_table
, LIST_HEAD_INIT(root_table_header
.ctl_entry
) };
146 static ctl_table kern_table
[];
147 static ctl_table vm_table
[];
148 static ctl_table fs_table
[];
149 static ctl_table debug_table
[];
150 static ctl_table dev_table
[];
151 extern ctl_table random_table
[];
152 #ifdef CONFIG_UNIX98_PTYS
153 extern ctl_table pty_table
[];
155 #ifdef CONFIG_INOTIFY_USER
156 extern ctl_table inotify_table
[];
159 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
160 int sysctl_legacy_va_layout
;
164 /* The default sysctl tables: */
166 static ctl_table root_table
[] = {
168 .ctl_name
= CTL_KERN
,
169 .procname
= "kernel",
194 .ctl_name
= CTL_DEBUG
,
197 .child
= debug_table
,
209 #ifdef CONFIG_SCHED_DEBUG
210 static unsigned long min_sched_granularity_ns
= 100000; /* 100 usecs */
211 static unsigned long max_sched_granularity_ns
= 1000000000; /* 1 second */
212 static unsigned long min_wakeup_granularity_ns
; /* 0 usecs */
213 static unsigned long max_wakeup_granularity_ns
= 1000000000; /* 1 second */
216 static ctl_table kern_table
[] = {
217 #ifdef CONFIG_SCHED_DEBUG
219 .ctl_name
= CTL_UNNUMBERED
,
220 .procname
= "sched_granularity_ns",
221 .data
= &sysctl_sched_granularity
,
222 .maxlen
= sizeof(unsigned int),
224 .proc_handler
= &proc_dointvec_minmax
,
225 .strategy
= &sysctl_intvec
,
226 .extra1
= &min_sched_granularity_ns
,
227 .extra2
= &max_sched_granularity_ns
,
230 .ctl_name
= CTL_UNNUMBERED
,
231 .procname
= "sched_wakeup_granularity_ns",
232 .data
= &sysctl_sched_wakeup_granularity
,
233 .maxlen
= sizeof(unsigned int),
235 .proc_handler
= &proc_dointvec_minmax
,
236 .strategy
= &sysctl_intvec
,
237 .extra1
= &min_wakeup_granularity_ns
,
238 .extra2
= &max_wakeup_granularity_ns
,
241 .ctl_name
= CTL_UNNUMBERED
,
242 .procname
= "sched_batch_wakeup_granularity_ns",
243 .data
= &sysctl_sched_batch_wakeup_granularity
,
244 .maxlen
= sizeof(unsigned int),
246 .proc_handler
= &proc_dointvec_minmax
,
247 .strategy
= &sysctl_intvec
,
248 .extra1
= &min_wakeup_granularity_ns
,
249 .extra2
= &max_wakeup_granularity_ns
,
252 .ctl_name
= CTL_UNNUMBERED
,
253 .procname
= "sched_stat_granularity_ns",
254 .data
= &sysctl_sched_stat_granularity
,
255 .maxlen
= sizeof(unsigned int),
257 .proc_handler
= &proc_dointvec_minmax
,
258 .strategy
= &sysctl_intvec
,
259 .extra1
= &min_wakeup_granularity_ns
,
260 .extra2
= &max_wakeup_granularity_ns
,
263 .ctl_name
= CTL_UNNUMBERED
,
264 .procname
= "sched_runtime_limit_ns",
265 .data
= &sysctl_sched_runtime_limit
,
266 .maxlen
= sizeof(unsigned int),
268 .proc_handler
= &proc_dointvec_minmax
,
269 .strategy
= &sysctl_intvec
,
270 .extra1
= &min_sched_granularity_ns
,
271 .extra2
= &max_sched_granularity_ns
,
274 .ctl_name
= CTL_UNNUMBERED
,
275 .procname
= "sched_child_runs_first",
276 .data
= &sysctl_sched_child_runs_first
,
277 .maxlen
= sizeof(unsigned int),
279 .proc_handler
= &proc_dointvec
,
282 .ctl_name
= CTL_UNNUMBERED
,
283 .procname
= "sched_features",
284 .data
= &sysctl_sched_features
,
285 .maxlen
= sizeof(unsigned int),
287 .proc_handler
= &proc_dointvec
,
291 .ctl_name
= KERN_PANIC
,
293 .data
= &panic_timeout
,
294 .maxlen
= sizeof(int),
296 .proc_handler
= &proc_dointvec
,
299 .ctl_name
= KERN_CORE_USES_PID
,
300 .procname
= "core_uses_pid",
301 .data
= &core_uses_pid
,
302 .maxlen
= sizeof(int),
304 .proc_handler
= &proc_dointvec
,
307 .ctl_name
= KERN_CORE_PATTERN
,
308 .procname
= "core_pattern",
309 .data
= core_pattern
,
310 .maxlen
= CORENAME_MAX_SIZE
,
312 .proc_handler
= &proc_dostring
,
313 .strategy
= &sysctl_string
,
315 #ifdef CONFIG_PROC_SYSCTL
317 .ctl_name
= KERN_TAINTED
,
318 .procname
= "tainted",
320 .maxlen
= sizeof(int),
322 .proc_handler
= &proc_dointvec_taint
,
326 .ctl_name
= KERN_CAP_BSET
,
327 .procname
= "cap-bound",
329 .maxlen
= sizeof(kernel_cap_t
),
331 .proc_handler
= &proc_dointvec_bset
,
333 #ifdef CONFIG_BLK_DEV_INITRD
335 .ctl_name
= KERN_REALROOTDEV
,
336 .procname
= "real-root-dev",
337 .data
= &real_root_dev
,
338 .maxlen
= sizeof(int),
340 .proc_handler
= &proc_dointvec
,
345 .ctl_name
= KERN_SPARC_REBOOT
,
346 .procname
= "reboot-cmd",
347 .data
= reboot_command
,
350 .proc_handler
= &proc_dostring
,
351 .strategy
= &sysctl_string
,
354 .ctl_name
= KERN_SPARC_STOP_A
,
355 .procname
= "stop-a",
356 .data
= &stop_a_enabled
,
357 .maxlen
= sizeof (int),
359 .proc_handler
= &proc_dointvec
,
362 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
363 .procname
= "scons-poweroff",
364 .data
= &scons_pwroff
,
365 .maxlen
= sizeof (int),
367 .proc_handler
= &proc_dointvec
,
372 .ctl_name
= KERN_HPPA_PWRSW
,
373 .procname
= "soft-power",
374 .data
= &pwrsw_enabled
,
375 .maxlen
= sizeof (int),
377 .proc_handler
= &proc_dointvec
,
380 .ctl_name
= KERN_HPPA_UNALIGNED
,
381 .procname
= "unaligned-trap",
382 .data
= &unaligned_enabled
,
383 .maxlen
= sizeof (int),
385 .proc_handler
= &proc_dointvec
,
389 .ctl_name
= KERN_CTLALTDEL
,
390 .procname
= "ctrl-alt-del",
392 .maxlen
= sizeof(int),
394 .proc_handler
= &proc_dointvec
,
397 .ctl_name
= KERN_PRINTK
,
398 .procname
= "printk",
399 .data
= &console_loglevel
,
400 .maxlen
= 4*sizeof(int),
402 .proc_handler
= &proc_dointvec
,
406 .ctl_name
= KERN_MODPROBE
,
407 .procname
= "modprobe",
408 .data
= &modprobe_path
,
409 .maxlen
= KMOD_PATH_LEN
,
411 .proc_handler
= &proc_dostring
,
412 .strategy
= &sysctl_string
,
415 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
417 .ctl_name
= KERN_HOTPLUG
,
418 .procname
= "hotplug",
419 .data
= &uevent_helper
,
420 .maxlen
= UEVENT_HELPER_PATH_LEN
,
422 .proc_handler
= &proc_dostring
,
423 .strategy
= &sysctl_string
,
426 #ifdef CONFIG_CHR_DEV_SG
428 .ctl_name
= KERN_SG_BIG_BUFF
,
429 .procname
= "sg-big-buff",
430 .data
= &sg_big_buff
,
431 .maxlen
= sizeof (int),
433 .proc_handler
= &proc_dointvec
,
436 #ifdef CONFIG_BSD_PROCESS_ACCT
438 .ctl_name
= KERN_ACCT
,
441 .maxlen
= 3*sizeof(int),
443 .proc_handler
= &proc_dointvec
,
446 #ifdef CONFIG_MAGIC_SYSRQ
448 .ctl_name
= KERN_SYSRQ
,
450 .data
= &__sysrq_enabled
,
451 .maxlen
= sizeof (int),
453 .proc_handler
= &proc_dointvec
,
456 #ifdef CONFIG_PROC_SYSCTL
458 .ctl_name
= KERN_CADPID
,
459 .procname
= "cad_pid",
461 .maxlen
= sizeof (int),
463 .proc_handler
= &proc_do_cad_pid
,
467 .ctl_name
= KERN_MAX_THREADS
,
468 .procname
= "threads-max",
469 .data
= &max_threads
,
470 .maxlen
= sizeof(int),
472 .proc_handler
= &proc_dointvec
,
475 .ctl_name
= KERN_RANDOM
,
476 .procname
= "random",
478 .child
= random_table
,
480 #ifdef CONFIG_UNIX98_PTYS
482 .ctl_name
= KERN_PTY
,
489 .ctl_name
= KERN_OVERFLOWUID
,
490 .procname
= "overflowuid",
491 .data
= &overflowuid
,
492 .maxlen
= sizeof(int),
494 .proc_handler
= &proc_dointvec_minmax
,
495 .strategy
= &sysctl_intvec
,
496 .extra1
= &minolduid
,
497 .extra2
= &maxolduid
,
500 .ctl_name
= KERN_OVERFLOWGID
,
501 .procname
= "overflowgid",
502 .data
= &overflowgid
,
503 .maxlen
= sizeof(int),
505 .proc_handler
= &proc_dointvec_minmax
,
506 .strategy
= &sysctl_intvec
,
507 .extra1
= &minolduid
,
508 .extra2
= &maxolduid
,
511 #ifdef CONFIG_MATHEMU
513 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
514 .procname
= "ieee_emulation_warnings",
515 .data
= &sysctl_ieee_emulation_warnings
,
516 .maxlen
= sizeof(int),
518 .proc_handler
= &proc_dointvec
,
521 #ifdef CONFIG_NO_IDLE_HZ
523 .ctl_name
= KERN_HZ_TIMER
,
524 .procname
= "hz_timer",
525 .data
= &sysctl_hz_timer
,
526 .maxlen
= sizeof(int),
528 .proc_handler
= &proc_dointvec
,
532 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
533 .procname
= "userprocess_debug",
534 .data
= &sysctl_userprocess_debug
,
535 .maxlen
= sizeof(int),
537 .proc_handler
= &proc_dointvec
,
541 .ctl_name
= KERN_PIDMAX
,
542 .procname
= "pid_max",
544 .maxlen
= sizeof (int),
546 .proc_handler
= &proc_dointvec_minmax
,
547 .strategy
= sysctl_intvec
,
548 .extra1
= &pid_max_min
,
549 .extra2
= &pid_max_max
,
552 .ctl_name
= KERN_PANIC_ON_OOPS
,
553 .procname
= "panic_on_oops",
554 .data
= &panic_on_oops
,
555 .maxlen
= sizeof(int),
557 .proc_handler
= &proc_dointvec
,
560 .ctl_name
= KERN_PRINTK_RATELIMIT
,
561 .procname
= "printk_ratelimit",
562 .data
= &printk_ratelimit_jiffies
,
563 .maxlen
= sizeof(int),
565 .proc_handler
= &proc_dointvec_jiffies
,
566 .strategy
= &sysctl_jiffies
,
569 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
570 .procname
= "printk_ratelimit_burst",
571 .data
= &printk_ratelimit_burst
,
572 .maxlen
= sizeof(int),
574 .proc_handler
= &proc_dointvec
,
577 .ctl_name
= KERN_NGROUPS_MAX
,
578 .procname
= "ngroups_max",
579 .data
= &ngroups_max
,
580 .maxlen
= sizeof (int),
582 .proc_handler
= &proc_dointvec
,
584 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
586 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
587 .procname
= "unknown_nmi_panic",
588 .data
= &unknown_nmi_panic
,
589 .maxlen
= sizeof (int),
591 .proc_handler
= &proc_dointvec
,
594 .ctl_name
= KERN_NMI_WATCHDOG
,
595 .procname
= "nmi_watchdog",
596 .data
= &nmi_watchdog_enabled
,
597 .maxlen
= sizeof (int),
599 .proc_handler
= &proc_nmi_enabled
,
602 #if defined(CONFIG_X86)
604 .ctl_name
= KERN_PANIC_ON_NMI
,
605 .procname
= "panic_on_unrecovered_nmi",
606 .data
= &panic_on_unrecovered_nmi
,
607 .maxlen
= sizeof(int),
609 .proc_handler
= &proc_dointvec
,
612 .ctl_name
= KERN_BOOTLOADER_TYPE
,
613 .procname
= "bootloader_type",
614 .data
= &bootloader_type
,
615 .maxlen
= sizeof (int),
617 .proc_handler
= &proc_dointvec
,
620 .ctl_name
= CTL_UNNUMBERED
,
621 .procname
= "kstack_depth_to_print",
622 .data
= &kstack_depth_to_print
,
623 .maxlen
= sizeof(int),
625 .proc_handler
= &proc_dointvec
,
628 #if defined(CONFIG_MMU)
630 .ctl_name
= KERN_RANDOMIZE
,
631 .procname
= "randomize_va_space",
632 .data
= &randomize_va_space
,
633 .maxlen
= sizeof(int),
635 .proc_handler
= &proc_dointvec
,
638 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
640 .ctl_name
= KERN_SPIN_RETRY
,
641 .procname
= "spin_retry",
643 .maxlen
= sizeof (int),
645 .proc_handler
= &proc_dointvec
,
648 #ifdef CONFIG_ACPI_SLEEP
650 .ctl_name
= KERN_ACPI_VIDEO_FLAGS
,
651 .procname
= "acpi_video_flags",
652 .data
= &acpi_video_flags
,
653 .maxlen
= sizeof (unsigned long),
655 .proc_handler
= &proc_doulongvec_minmax
,
660 .ctl_name
= KERN_IA64_UNALIGNED
,
661 .procname
= "ignore-unaligned-usertrap",
662 .data
= &no_unaligned_warning
,
663 .maxlen
= sizeof (int),
665 .proc_handler
= &proc_dointvec
,
670 .ctl_name
= KERN_COMPAT_LOG
,
671 .procname
= "compat-log",
673 .maxlen
= sizeof (int),
675 .proc_handler
= &proc_dointvec
,
678 #ifdef CONFIG_RT_MUTEXES
680 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
681 .procname
= "max_lock_depth",
682 .data
= &max_lock_depth
,
683 .maxlen
= sizeof(int),
685 .proc_handler
= &proc_dointvec
,
688 #ifdef CONFIG_PROC_FS
690 .ctl_name
= CTL_UNNUMBERED
,
691 .procname
= "maps_protect",
692 .data
= &maps_protect
,
693 .maxlen
= sizeof(int),
695 .proc_handler
= &proc_dointvec
,
702 /* Constants for minimum and maximum testing in vm_table.
703 We use these as one-element integer vectors. */
705 static int one_hundred
= 100;
708 static ctl_table vm_table
[] = {
710 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
711 .procname
= "overcommit_memory",
712 .data
= &sysctl_overcommit_memory
,
713 .maxlen
= sizeof(sysctl_overcommit_memory
),
715 .proc_handler
= &proc_dointvec
,
718 .ctl_name
= VM_PANIC_ON_OOM
,
719 .procname
= "panic_on_oom",
720 .data
= &sysctl_panic_on_oom
,
721 .maxlen
= sizeof(sysctl_panic_on_oom
),
723 .proc_handler
= &proc_dointvec
,
726 .ctl_name
= VM_OVERCOMMIT_RATIO
,
727 .procname
= "overcommit_ratio",
728 .data
= &sysctl_overcommit_ratio
,
729 .maxlen
= sizeof(sysctl_overcommit_ratio
),
731 .proc_handler
= &proc_dointvec
,
734 .ctl_name
= VM_PAGE_CLUSTER
,
735 .procname
= "page-cluster",
736 .data
= &page_cluster
,
737 .maxlen
= sizeof(int),
739 .proc_handler
= &proc_dointvec
,
742 .ctl_name
= VM_DIRTY_BACKGROUND
,
743 .procname
= "dirty_background_ratio",
744 .data
= &dirty_background_ratio
,
745 .maxlen
= sizeof(dirty_background_ratio
),
747 .proc_handler
= &proc_dointvec_minmax
,
748 .strategy
= &sysctl_intvec
,
750 .extra2
= &one_hundred
,
753 .ctl_name
= VM_DIRTY_RATIO
,
754 .procname
= "dirty_ratio",
755 .data
= &vm_dirty_ratio
,
756 .maxlen
= sizeof(vm_dirty_ratio
),
758 .proc_handler
= &proc_dointvec_minmax
,
759 .strategy
= &sysctl_intvec
,
761 .extra2
= &one_hundred
,
764 .ctl_name
= VM_DIRTY_WB_CS
,
765 .procname
= "dirty_writeback_centisecs",
766 .data
= &dirty_writeback_interval
,
767 .maxlen
= sizeof(dirty_writeback_interval
),
769 .proc_handler
= &dirty_writeback_centisecs_handler
,
772 .ctl_name
= VM_DIRTY_EXPIRE_CS
,
773 .procname
= "dirty_expire_centisecs",
774 .data
= &dirty_expire_interval
,
775 .maxlen
= sizeof(dirty_expire_interval
),
777 .proc_handler
= &proc_dointvec_userhz_jiffies
,
780 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
781 .procname
= "nr_pdflush_threads",
782 .data
= &nr_pdflush_threads
,
783 .maxlen
= sizeof nr_pdflush_threads
,
784 .mode
= 0444 /* read-only*/,
785 .proc_handler
= &proc_dointvec
,
788 .ctl_name
= VM_SWAPPINESS
,
789 .procname
= "swappiness",
790 .data
= &vm_swappiness
,
791 .maxlen
= sizeof(vm_swappiness
),
793 .proc_handler
= &proc_dointvec_minmax
,
794 .strategy
= &sysctl_intvec
,
796 .extra2
= &one_hundred
,
798 #ifdef CONFIG_HUGETLB_PAGE
800 .ctl_name
= VM_HUGETLB_PAGES
,
801 .procname
= "nr_hugepages",
802 .data
= &max_huge_pages
,
803 .maxlen
= sizeof(unsigned long),
805 .proc_handler
= &hugetlb_sysctl_handler
,
806 .extra1
= (void *)&hugetlb_zero
,
807 .extra2
= (void *)&hugetlb_infinity
,
810 .ctl_name
= VM_HUGETLB_GROUP
,
811 .procname
= "hugetlb_shm_group",
812 .data
= &sysctl_hugetlb_shm_group
,
813 .maxlen
= sizeof(gid_t
),
815 .proc_handler
= &proc_dointvec
,
819 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
820 .procname
= "lowmem_reserve_ratio",
821 .data
= &sysctl_lowmem_reserve_ratio
,
822 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
824 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
825 .strategy
= &sysctl_intvec
,
828 .ctl_name
= VM_DROP_PAGECACHE
,
829 .procname
= "drop_caches",
830 .data
= &sysctl_drop_caches
,
831 .maxlen
= sizeof(int),
833 .proc_handler
= drop_caches_sysctl_handler
,
834 .strategy
= &sysctl_intvec
,
837 .ctl_name
= VM_MIN_FREE_KBYTES
,
838 .procname
= "min_free_kbytes",
839 .data
= &min_free_kbytes
,
840 .maxlen
= sizeof(min_free_kbytes
),
842 .proc_handler
= &min_free_kbytes_sysctl_handler
,
843 .strategy
= &sysctl_intvec
,
847 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
848 .procname
= "percpu_pagelist_fraction",
849 .data
= &percpu_pagelist_fraction
,
850 .maxlen
= sizeof(percpu_pagelist_fraction
),
852 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
853 .strategy
= &sysctl_intvec
,
854 .extra1
= &min_percpu_pagelist_fract
,
858 .ctl_name
= VM_MAX_MAP_COUNT
,
859 .procname
= "max_map_count",
860 .data
= &sysctl_max_map_count
,
861 .maxlen
= sizeof(sysctl_max_map_count
),
863 .proc_handler
= &proc_dointvec
867 .ctl_name
= VM_LAPTOP_MODE
,
868 .procname
= "laptop_mode",
869 .data
= &laptop_mode
,
870 .maxlen
= sizeof(laptop_mode
),
872 .proc_handler
= &proc_dointvec_jiffies
,
873 .strategy
= &sysctl_jiffies
,
876 .ctl_name
= VM_BLOCK_DUMP
,
877 .procname
= "block_dump",
879 .maxlen
= sizeof(block_dump
),
881 .proc_handler
= &proc_dointvec
,
882 .strategy
= &sysctl_intvec
,
886 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
887 .procname
= "vfs_cache_pressure",
888 .data
= &sysctl_vfs_cache_pressure
,
889 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
891 .proc_handler
= &proc_dointvec
,
892 .strategy
= &sysctl_intvec
,
895 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
897 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
898 .procname
= "legacy_va_layout",
899 .data
= &sysctl_legacy_va_layout
,
900 .maxlen
= sizeof(sysctl_legacy_va_layout
),
902 .proc_handler
= &proc_dointvec
,
903 .strategy
= &sysctl_intvec
,
909 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
910 .procname
= "zone_reclaim_mode",
911 .data
= &zone_reclaim_mode
,
912 .maxlen
= sizeof(zone_reclaim_mode
),
914 .proc_handler
= &proc_dointvec
,
915 .strategy
= &sysctl_intvec
,
919 .ctl_name
= VM_MIN_UNMAPPED
,
920 .procname
= "min_unmapped_ratio",
921 .data
= &sysctl_min_unmapped_ratio
,
922 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
924 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
925 .strategy
= &sysctl_intvec
,
927 .extra2
= &one_hundred
,
930 .ctl_name
= VM_MIN_SLAB
,
931 .procname
= "min_slab_ratio",
932 .data
= &sysctl_min_slab_ratio
,
933 .maxlen
= sizeof(sysctl_min_slab_ratio
),
935 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
936 .strategy
= &sysctl_intvec
,
938 .extra2
= &one_hundred
,
943 .ctl_name
= CTL_UNNUMBERED
,
944 .procname
= "stat_interval",
945 .data
= &sysctl_stat_interval
,
946 .maxlen
= sizeof(sysctl_stat_interval
),
948 .proc_handler
= &proc_dointvec_jiffies
,
949 .strategy
= &sysctl_jiffies
,
952 #ifdef CONFIG_SECURITY
954 .ctl_name
= CTL_UNNUMBERED
,
955 .procname
= "mmap_min_addr",
956 .data
= &mmap_min_addr
,
957 .maxlen
= sizeof(unsigned long),
959 .proc_handler
= &proc_doulongvec_minmax
,
962 #if defined(CONFIG_X86_32) || \
963 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
965 .ctl_name
= VM_VDSO_ENABLED
,
966 .procname
= "vdso_enabled",
967 .data
= &vdso_enabled
,
968 .maxlen
= sizeof(vdso_enabled
),
970 .proc_handler
= &proc_dointvec
,
971 .strategy
= &sysctl_intvec
,
978 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
979 static ctl_table binfmt_misc_table
[] = {
984 static ctl_table fs_table
[] = {
986 .ctl_name
= FS_NRINODE
,
987 .procname
= "inode-nr",
988 .data
= &inodes_stat
,
989 .maxlen
= 2*sizeof(int),
991 .proc_handler
= &proc_dointvec
,
994 .ctl_name
= FS_STATINODE
,
995 .procname
= "inode-state",
996 .data
= &inodes_stat
,
997 .maxlen
= 7*sizeof(int),
999 .proc_handler
= &proc_dointvec
,
1002 .ctl_name
= FS_NRFILE
,
1003 .procname
= "file-nr",
1004 .data
= &files_stat
,
1005 .maxlen
= 3*sizeof(int),
1007 .proc_handler
= &proc_nr_files
,
1010 .ctl_name
= FS_MAXFILE
,
1011 .procname
= "file-max",
1012 .data
= &files_stat
.max_files
,
1013 .maxlen
= sizeof(int),
1015 .proc_handler
= &proc_dointvec
,
1018 .ctl_name
= FS_DENTRY
,
1019 .procname
= "dentry-state",
1020 .data
= &dentry_stat
,
1021 .maxlen
= 6*sizeof(int),
1023 .proc_handler
= &proc_dointvec
,
1026 .ctl_name
= FS_OVERFLOWUID
,
1027 .procname
= "overflowuid",
1028 .data
= &fs_overflowuid
,
1029 .maxlen
= sizeof(int),
1031 .proc_handler
= &proc_dointvec_minmax
,
1032 .strategy
= &sysctl_intvec
,
1033 .extra1
= &minolduid
,
1034 .extra2
= &maxolduid
,
1037 .ctl_name
= FS_OVERFLOWGID
,
1038 .procname
= "overflowgid",
1039 .data
= &fs_overflowgid
,
1040 .maxlen
= sizeof(int),
1042 .proc_handler
= &proc_dointvec_minmax
,
1043 .strategy
= &sysctl_intvec
,
1044 .extra1
= &minolduid
,
1045 .extra2
= &maxolduid
,
1048 .ctl_name
= FS_LEASES
,
1049 .procname
= "leases-enable",
1050 .data
= &leases_enable
,
1051 .maxlen
= sizeof(int),
1053 .proc_handler
= &proc_dointvec
,
1055 #ifdef CONFIG_DNOTIFY
1057 .ctl_name
= FS_DIR_NOTIFY
,
1058 .procname
= "dir-notify-enable",
1059 .data
= &dir_notify_enable
,
1060 .maxlen
= sizeof(int),
1062 .proc_handler
= &proc_dointvec
,
1067 .ctl_name
= FS_LEASE_TIME
,
1068 .procname
= "lease-break-time",
1069 .data
= &lease_break_time
,
1070 .maxlen
= sizeof(int),
1072 .proc_handler
= &proc_dointvec
,
1075 .ctl_name
= FS_AIO_NR
,
1076 .procname
= "aio-nr",
1078 .maxlen
= sizeof(aio_nr
),
1080 .proc_handler
= &proc_doulongvec_minmax
,
1083 .ctl_name
= FS_AIO_MAX_NR
,
1084 .procname
= "aio-max-nr",
1085 .data
= &aio_max_nr
,
1086 .maxlen
= sizeof(aio_max_nr
),
1088 .proc_handler
= &proc_doulongvec_minmax
,
1090 #ifdef CONFIG_INOTIFY_USER
1092 .ctl_name
= FS_INOTIFY
,
1093 .procname
= "inotify",
1095 .child
= inotify_table
,
1100 .ctl_name
= KERN_SETUID_DUMPABLE
,
1101 .procname
= "suid_dumpable",
1102 .data
= &suid_dumpable
,
1103 .maxlen
= sizeof(int),
1105 .proc_handler
= &proc_dointvec
,
1107 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1109 .ctl_name
= CTL_UNNUMBERED
,
1110 .procname
= "binfmt_misc",
1112 .child
= binfmt_misc_table
,
1118 static ctl_table debug_table
[] = {
1122 static ctl_table dev_table
[] = {
1126 static DEFINE_SPINLOCK(sysctl_lock
);
1128 /* called under sysctl_lock */
1129 static int use_table(struct ctl_table_header
*p
)
1131 if (unlikely(p
->unregistering
))
1137 /* called under sysctl_lock */
1138 static void unuse_table(struct ctl_table_header
*p
)
1141 if (unlikely(p
->unregistering
))
1142 complete(p
->unregistering
);
1145 /* called under sysctl_lock, will reacquire if has to wait */
1146 static void start_unregistering(struct ctl_table_header
*p
)
1149 * if p->used is 0, nobody will ever touch that entry again;
1150 * we'll eliminate all paths to it before dropping sysctl_lock
1152 if (unlikely(p
->used
)) {
1153 struct completion wait
;
1154 init_completion(&wait
);
1155 p
->unregistering
= &wait
;
1156 spin_unlock(&sysctl_lock
);
1157 wait_for_completion(&wait
);
1158 spin_lock(&sysctl_lock
);
1161 * do not remove from the list until nobody holds it; walking the
1162 * list in do_sysctl() relies on that.
1164 list_del_init(&p
->ctl_entry
);
1167 void sysctl_head_finish(struct ctl_table_header
*head
)
1171 spin_lock(&sysctl_lock
);
1173 spin_unlock(&sysctl_lock
);
1176 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1178 struct ctl_table_header
*head
;
1179 struct list_head
*tmp
;
1180 spin_lock(&sysctl_lock
);
1182 tmp
= &prev
->ctl_entry
;
1186 tmp
= &root_table_header
.ctl_entry
;
1188 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1190 if (!use_table(head
))
1192 spin_unlock(&sysctl_lock
);
1196 if (tmp
== &root_table_header
.ctl_entry
)
1199 spin_unlock(&sysctl_lock
);
1203 #ifdef CONFIG_SYSCTL_SYSCALL
1204 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1205 void __user
*newval
, size_t newlen
)
1207 struct ctl_table_header
*head
;
1208 int error
= -ENOTDIR
;
1210 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1214 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1218 for (head
= sysctl_head_next(NULL
); head
;
1219 head
= sysctl_head_next(head
)) {
1220 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1221 newval
, newlen
, head
->ctl_table
);
1222 if (error
!= -ENOTDIR
) {
1223 sysctl_head_finish(head
);
1230 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1232 struct __sysctl_args tmp
;
1235 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1239 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1240 tmp
.newval
, tmp
.newlen
);
1244 #endif /* CONFIG_SYSCTL_SYSCALL */
1247 * sysctl_perm does NOT grant the superuser all rights automatically, because
1248 * some sysctl variables are readonly even to root.
1251 static int test_perm(int mode
, int op
)
1255 else if (in_egroup_p(0))
1257 if ((mode
& op
& 0007) == op
)
1262 int sysctl_perm(ctl_table
*table
, int op
)
1265 error
= security_sysctl(table
, op
);
1268 return test_perm(table
->mode
, op
);
1271 #ifdef CONFIG_SYSCTL_SYSCALL
1272 static int parse_table(int __user
*name
, int nlen
,
1273 void __user
*oldval
, size_t __user
*oldlenp
,
1274 void __user
*newval
, size_t newlen
,
1281 if (get_user(n
, name
))
1283 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1284 if (!table
->ctl_name
)
1286 if (n
== table
->ctl_name
) {
1289 if (sysctl_perm(table
, 001))
1293 table
= table
->child
;
1296 error
= do_sysctl_strategy(table
, name
, nlen
,
1305 /* Perform the actual read/write of a sysctl table entry. */
1306 int do_sysctl_strategy (ctl_table
*table
,
1307 int __user
*name
, int nlen
,
1308 void __user
*oldval
, size_t __user
*oldlenp
,
1309 void __user
*newval
, size_t newlen
)
1318 if (sysctl_perm(table
, op
))
1321 if (table
->strategy
) {
1322 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1330 /* If there is no strategy routine, or if the strategy returns
1331 * zero, proceed with automatic r/w */
1332 if (table
->data
&& table
->maxlen
) {
1333 if (oldval
&& oldlenp
) {
1334 if (get_user(len
, oldlenp
))
1337 if (len
> table
->maxlen
)
1338 len
= table
->maxlen
;
1339 if(copy_to_user(oldval
, table
->data
, len
))
1341 if(put_user(len
, oldlenp
))
1345 if (newval
&& newlen
) {
1347 if (len
> table
->maxlen
)
1348 len
= table
->maxlen
;
1349 if(copy_from_user(table
->data
, newval
, len
))
1355 #endif /* CONFIG_SYSCTL_SYSCALL */
1357 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1359 for (; table
->ctl_name
|| table
->procname
; table
++) {
1360 table
->parent
= parent
;
1362 sysctl_set_parent(table
, table
->child
);
1366 static __init
int sysctl_init(void)
1368 sysctl_set_parent(NULL
, root_table
);
1372 core_initcall(sysctl_init
);
1375 * register_sysctl_table - register a sysctl hierarchy
1376 * @table: the top-level table structure
1378 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1379 * array. An entry with a ctl_name of 0 terminates the table.
1381 * The members of the &ctl_table structure are used as follows:
1383 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1384 * must be unique within that level of sysctl
1386 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1387 * enter a sysctl file
1389 * data - a pointer to data for use by proc_handler
1391 * maxlen - the maximum size in bytes of the data
1393 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1395 * child - a pointer to the child sysctl table if this entry is a directory, or
1398 * proc_handler - the text handler routine (described below)
1400 * strategy - the strategy routine (described below)
1402 * de - for internal use by the sysctl routines
1404 * extra1, extra2 - extra pointers usable by the proc handler routines
1406 * Leaf nodes in the sysctl tree will be represented by a single file
1407 * under /proc; non-leaf nodes will be represented by directories.
1409 * sysctl(2) can automatically manage read and write requests through
1410 * the sysctl table. The data and maxlen fields of the ctl_table
1411 * struct enable minimal validation of the values being written to be
1412 * performed, and the mode field allows minimal authentication.
1414 * More sophisticated management can be enabled by the provision of a
1415 * strategy routine with the table entry. This will be called before
1416 * any automatic read or write of the data is performed.
1418 * The strategy routine may return
1420 * < 0 - Error occurred (error is passed to user process)
1422 * 0 - OK - proceed with automatic read or write.
1424 * > 0 - OK - read or write has been done by the strategy routine, so
1425 * return immediately.
1427 * There must be a proc_handler routine for any terminal nodes
1428 * mirrored under /proc/sys (non-terminals are handled by a built-in
1429 * directory handler). Several default handlers are available to
1430 * cover common cases -
1432 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1433 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1434 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1436 * It is the handler's job to read the input buffer from user memory
1437 * and process it. The handler should return 0 on success.
1439 * This routine returns %NULL on a failure to register, and a pointer
1440 * to the table header on success.
1442 struct ctl_table_header
*register_sysctl_table(ctl_table
* table
)
1444 struct ctl_table_header
*tmp
;
1445 tmp
= kmalloc(sizeof(struct ctl_table_header
), GFP_KERNEL
);
1448 tmp
->ctl_table
= table
;
1449 INIT_LIST_HEAD(&tmp
->ctl_entry
);
1451 tmp
->unregistering
= NULL
;
1452 sysctl_set_parent(NULL
, table
);
1453 spin_lock(&sysctl_lock
);
1454 list_add_tail(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1455 spin_unlock(&sysctl_lock
);
1460 * unregister_sysctl_table - unregister a sysctl table hierarchy
1461 * @header: the header returned from register_sysctl_table
1463 * Unregisters the sysctl table and all children. proc entries may not
1464 * actually be removed until they are no longer used by anyone.
1466 void unregister_sysctl_table(struct ctl_table_header
* header
)
1469 spin_lock(&sysctl_lock
);
1470 start_unregistering(header
);
1471 spin_unlock(&sysctl_lock
);
1475 #else /* !CONFIG_SYSCTL */
1476 struct ctl_table_header
*register_sysctl_table(ctl_table
* table
)
1481 void unregister_sysctl_table(struct ctl_table_header
* table
)
1485 #endif /* CONFIG_SYSCTL */
1491 #ifdef CONFIG_PROC_SYSCTL
1493 static int _proc_do_string(void* data
, int maxlen
, int write
,
1494 struct file
*filp
, void __user
*buffer
,
1495 size_t *lenp
, loff_t
*ppos
)
1501 if (!data
|| !maxlen
|| !*lenp
) {
1509 while (len
< *lenp
) {
1510 if (get_user(c
, p
++))
1512 if (c
== 0 || c
== '\n')
1518 if(copy_from_user(data
, buffer
, len
))
1520 ((char *) data
)[len
] = 0;
1538 if(copy_to_user(buffer
, data
, len
))
1541 if(put_user('\n', ((char __user
*) buffer
) + len
))
1552 * proc_dostring - read a string sysctl
1553 * @table: the sysctl table
1554 * @write: %TRUE if this is a write to the sysctl file
1555 * @filp: the file structure
1556 * @buffer: the user buffer
1557 * @lenp: the size of the user buffer
1558 * @ppos: file position
1560 * Reads/writes a string from/to the user buffer. If the kernel
1561 * buffer provided is not large enough to hold the string, the
1562 * string is truncated. The copied string is %NULL-terminated.
1563 * If the string is being read by the user process, it is copied
1564 * and a newline '\n' is added. It is truncated if the buffer is
1567 * Returns 0 on success.
1569 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1570 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1572 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
1573 buffer
, lenp
, ppos
);
1577 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1579 int write
, void *data
)
1582 *valp
= *negp
? -*lvalp
: *lvalp
;
1587 *lvalp
= (unsigned long)-val
;
1590 *lvalp
= (unsigned long)val
;
1596 static int __do_proc_dointvec(void *tbl_data
, ctl_table
*table
,
1597 int write
, struct file
*filp
, void __user
*buffer
,
1598 size_t *lenp
, loff_t
*ppos
,
1599 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1600 int write
, void *data
),
1603 #define TMPBUFLEN 21
1604 int *i
, vleft
, first
=1, neg
, val
;
1608 char buf
[TMPBUFLEN
], *p
;
1609 char __user
*s
= buffer
;
1611 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
1612 (*ppos
&& !write
)) {
1617 i
= (int *) tbl_data
;
1618 vleft
= table
->maxlen
/ sizeof(*i
);
1622 conv
= do_proc_dointvec_conv
;
1624 for (; left
&& vleft
--; i
++, first
=0) {
1639 if (len
> sizeof(buf
) - 1)
1640 len
= sizeof(buf
) - 1;
1641 if (copy_from_user(buf
, s
, len
))
1645 if (*p
== '-' && left
> 1) {
1649 if (*p
< '0' || *p
> '9')
1652 lval
= simple_strtoul(p
, &p
, 0);
1655 if ((len
< left
) && *p
&& !isspace(*p
))
1662 if (conv(&neg
, &lval
, i
, 1, data
))
1669 if (conv(&neg
, &lval
, i
, 0, data
))
1672 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
1676 if(copy_to_user(s
, buf
, len
))
1683 if (!write
&& !first
&& left
) {
1684 if(put_user('\n', s
))
1691 if (get_user(c
, s
++))
1706 static int do_proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1707 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1708 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1709 int write
, void *data
),
1712 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
1713 buffer
, lenp
, ppos
, conv
, data
);
1717 * proc_dointvec - read a vector of integers
1718 * @table: the sysctl table
1719 * @write: %TRUE if this is a write to the sysctl file
1720 * @filp: the file structure
1721 * @buffer: the user buffer
1722 * @lenp: the size of the user buffer
1723 * @ppos: file position
1725 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1726 * values from/to the user buffer, treated as an ASCII string.
1728 * Returns 0 on success.
1730 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1731 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1733 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1741 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
1743 int write
, void *data
)
1745 int op
= *(int *)data
;
1747 int val
= *negp
? -*lvalp
: *lvalp
;
1749 case OP_SET
: *valp
= val
; break;
1750 case OP_AND
: *valp
&= val
; break;
1751 case OP_OR
: *valp
|= val
; break;
1757 *lvalp
= (unsigned long)-val
;
1760 *lvalp
= (unsigned long)val
;
1767 * init may raise the set.
1770 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1771 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1775 if (write
&& !capable(CAP_SYS_MODULE
)) {
1779 op
= is_init(current
) ? OP_SET
: OP_AND
;
1780 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1781 do_proc_dointvec_bset_conv
,&op
);
1785 * Taint values can only be increased
1787 static int proc_dointvec_taint(ctl_table
*table
, int write
, struct file
*filp
,
1788 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1792 if (write
&& !capable(CAP_SYS_ADMIN
))
1796 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1797 do_proc_dointvec_bset_conv
,&op
);
1800 struct do_proc_dointvec_minmax_conv_param
{
1805 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
1807 int write
, void *data
)
1809 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
1811 int val
= *negp
? -*lvalp
: *lvalp
;
1812 if ((param
->min
&& *param
->min
> val
) ||
1813 (param
->max
&& *param
->max
< val
))
1820 *lvalp
= (unsigned long)-val
;
1823 *lvalp
= (unsigned long)val
;
1830 * proc_dointvec_minmax - read a vector of integers with min/max values
1831 * @table: the sysctl table
1832 * @write: %TRUE if this is a write to the sysctl file
1833 * @filp: the file structure
1834 * @buffer: the user buffer
1835 * @lenp: the size of the user buffer
1836 * @ppos: file position
1838 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1839 * values from/to the user buffer, treated as an ASCII string.
1841 * This routine will ensure the values are within the range specified by
1842 * table->extra1 (min) and table->extra2 (max).
1844 * Returns 0 on success.
1846 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1847 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1849 struct do_proc_dointvec_minmax_conv_param param
= {
1850 .min
= (int *) table
->extra1
,
1851 .max
= (int *) table
->extra2
,
1853 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
1854 do_proc_dointvec_minmax_conv
, ¶m
);
1857 static int __do_proc_doulongvec_minmax(void *data
, ctl_table
*table
, int write
,
1859 void __user
*buffer
,
1860 size_t *lenp
, loff_t
*ppos
,
1861 unsigned long convmul
,
1862 unsigned long convdiv
)
1864 #define TMPBUFLEN 21
1865 unsigned long *i
, *min
, *max
, val
;
1866 int vleft
, first
=1, neg
;
1868 char buf
[TMPBUFLEN
], *p
;
1869 char __user
*s
= buffer
;
1871 if (!data
|| !table
->maxlen
|| !*lenp
||
1872 (*ppos
&& !write
)) {
1877 i
= (unsigned long *) data
;
1878 min
= (unsigned long *) table
->extra1
;
1879 max
= (unsigned long *) table
->extra2
;
1880 vleft
= table
->maxlen
/ sizeof(unsigned long);
1883 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
1898 if (len
> TMPBUFLEN
-1)
1900 if (copy_from_user(buf
, s
, len
))
1904 if (*p
== '-' && left
> 1) {
1908 if (*p
< '0' || *p
> '9')
1910 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
1912 if ((len
< left
) && *p
&& !isspace(*p
))
1921 if ((min
&& val
< *min
) || (max
&& val
> *max
))
1928 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
1932 if(copy_to_user(s
, buf
, len
))
1939 if (!write
&& !first
&& left
) {
1940 if(put_user('\n', s
))
1947 if (get_user(c
, s
++))
1962 static int do_proc_doulongvec_minmax(ctl_table
*table
, int write
,
1964 void __user
*buffer
,
1965 size_t *lenp
, loff_t
*ppos
,
1966 unsigned long convmul
,
1967 unsigned long convdiv
)
1969 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
1970 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
1974 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1975 * @table: the sysctl table
1976 * @write: %TRUE if this is a write to the sysctl file
1977 * @filp: the file structure
1978 * @buffer: the user buffer
1979 * @lenp: the size of the user buffer
1980 * @ppos: file position
1982 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1983 * values from/to the user buffer, treated as an ASCII string.
1985 * This routine will ensure the values are within the range specified by
1986 * table->extra1 (min) and table->extra2 (max).
1988 * Returns 0 on success.
1990 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1991 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1993 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
1997 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1998 * @table: the sysctl table
1999 * @write: %TRUE if this is a write to the sysctl file
2000 * @filp: the file structure
2001 * @buffer: the user buffer
2002 * @lenp: the size of the user buffer
2003 * @ppos: file position
2005 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2006 * values from/to the user buffer, treated as an ASCII string. The values
2007 * are treated as milliseconds, and converted to jiffies when they are stored.
2009 * This routine will ensure the values are within the range specified by
2010 * table->extra1 (min) and table->extra2 (max).
2012 * Returns 0 on success.
2014 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2016 void __user
*buffer
,
2017 size_t *lenp
, loff_t
*ppos
)
2019 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2020 lenp
, ppos
, HZ
, 1000l);
2024 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2026 int write
, void *data
)
2029 if (*lvalp
> LONG_MAX
/ HZ
)
2031 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2037 lval
= (unsigned long)-val
;
2040 lval
= (unsigned long)val
;
2047 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2049 int write
, void *data
)
2052 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2054 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2060 lval
= (unsigned long)-val
;
2063 lval
= (unsigned long)val
;
2065 *lvalp
= jiffies_to_clock_t(lval
);
2070 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2072 int write
, void *data
)
2075 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2081 lval
= (unsigned long)-val
;
2084 lval
= (unsigned long)val
;
2086 *lvalp
= jiffies_to_msecs(lval
);
2092 * proc_dointvec_jiffies - read a vector of integers as seconds
2093 * @table: the sysctl table
2094 * @write: %TRUE if this is a write to the sysctl file
2095 * @filp: the file structure
2096 * @buffer: the user buffer
2097 * @lenp: the size of the user buffer
2098 * @ppos: file position
2100 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2101 * values from/to the user buffer, treated as an ASCII string.
2102 * The values read are assumed to be in seconds, and are converted into
2105 * Returns 0 on success.
2107 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2108 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2110 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2111 do_proc_dointvec_jiffies_conv
,NULL
);
2115 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2116 * @table: the sysctl table
2117 * @write: %TRUE if this is a write to the sysctl file
2118 * @filp: the file structure
2119 * @buffer: the user buffer
2120 * @lenp: the size of the user buffer
2121 * @ppos: pointer to the file position
2123 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2124 * values from/to the user buffer, treated as an ASCII string.
2125 * The values read are assumed to be in 1/USER_HZ seconds, and
2126 * are converted into jiffies.
2128 * Returns 0 on success.
2130 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2131 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2133 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2134 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2138 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2139 * @table: the sysctl table
2140 * @write: %TRUE if this is a write to the sysctl file
2141 * @filp: the file structure
2142 * @buffer: the user buffer
2143 * @lenp: the size of the user buffer
2144 * @ppos: file position
2145 * @ppos: the current position in the file
2147 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2148 * values from/to the user buffer, treated as an ASCII string.
2149 * The values read are assumed to be in 1/1000 seconds, and
2150 * are converted into jiffies.
2152 * Returns 0 on success.
2154 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2155 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2157 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2158 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2161 static int proc_do_cad_pid(ctl_table
*table
, int write
, struct file
*filp
,
2162 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2164 struct pid
*new_pid
;
2168 tmp
= pid_nr(cad_pid
);
2170 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2171 lenp
, ppos
, NULL
, NULL
);
2175 new_pid
= find_get_pid(tmp
);
2179 put_pid(xchg(&cad_pid
, new_pid
));
2183 #else /* CONFIG_PROC_FS */
2185 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2186 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2191 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2192 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2197 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2198 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2203 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2204 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2209 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2210 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2215 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2216 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2221 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2222 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2227 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2228 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2233 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2235 void __user
*buffer
,
2236 size_t *lenp
, loff_t
*ppos
)
2242 #endif /* CONFIG_PROC_FS */
2245 #ifdef CONFIG_SYSCTL_SYSCALL
2247 * General sysctl support routines
2250 /* The generic string strategy routine: */
2251 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2252 void __user
*oldval
, size_t __user
*oldlenp
,
2253 void __user
*newval
, size_t newlen
)
2255 if (!table
->data
|| !table
->maxlen
)
2258 if (oldval
&& oldlenp
) {
2260 if (get_user(bufsize
, oldlenp
))
2263 size_t len
= strlen(table
->data
), copied
;
2265 /* This shouldn't trigger for a well-formed sysctl */
2266 if (len
> table
->maxlen
)
2267 len
= table
->maxlen
;
2269 /* Copy up to a max of bufsize-1 bytes of the string */
2270 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2272 if (copy_to_user(oldval
, table
->data
, copied
) ||
2273 put_user(0, (char __user
*)(oldval
+ copied
)))
2275 if (put_user(len
, oldlenp
))
2279 if (newval
&& newlen
) {
2280 size_t len
= newlen
;
2281 if (len
> table
->maxlen
)
2282 len
= table
->maxlen
;
2283 if(copy_from_user(table
->data
, newval
, len
))
2285 if (len
== table
->maxlen
)
2287 ((char *) table
->data
)[len
] = 0;
2293 * This function makes sure that all of the integers in the vector
2294 * are between the minimum and maximum values given in the arrays
2295 * table->extra1 and table->extra2, respectively.
2297 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2298 void __user
*oldval
, size_t __user
*oldlenp
,
2299 void __user
*newval
, size_t newlen
)
2302 if (newval
&& newlen
) {
2303 int __user
*vec
= (int __user
*) newval
;
2304 int *min
= (int *) table
->extra1
;
2305 int *max
= (int *) table
->extra2
;
2309 if (newlen
% sizeof(int) != 0)
2312 if (!table
->extra1
&& !table
->extra2
)
2315 if (newlen
> table
->maxlen
)
2316 newlen
= table
->maxlen
;
2317 length
= newlen
/ sizeof(int);
2319 for (i
= 0; i
< length
; i
++) {
2321 if (get_user(value
, vec
+ i
))
2323 if (min
&& value
< min
[i
])
2325 if (max
&& value
> max
[i
])
2332 /* Strategy function to convert jiffies to seconds */
2333 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2334 void __user
*oldval
, size_t __user
*oldlenp
,
2335 void __user
*newval
, size_t newlen
)
2337 if (oldval
&& oldlenp
) {
2340 if (get_user(olen
, oldlenp
))
2345 if (olen
< sizeof(int))
2348 val
= *(int *)(table
->data
) / HZ
;
2349 if (put_user(val
, (int __user
*)oldval
))
2351 if (put_user(sizeof(int), oldlenp
))
2355 if (newval
&& newlen
) {
2357 if (newlen
!= sizeof(int))
2359 if (get_user(new, (int __user
*)newval
))
2361 *(int *)(table
->data
) = new*HZ
;
2366 /* Strategy function to convert jiffies to seconds */
2367 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2368 void __user
*oldval
, size_t __user
*oldlenp
,
2369 void __user
*newval
, size_t newlen
)
2371 if (oldval
&& oldlenp
) {
2374 if (get_user(olen
, oldlenp
))
2379 if (olen
< sizeof(int))
2382 val
= jiffies_to_msecs(*(int *)(table
->data
));
2383 if (put_user(val
, (int __user
*)oldval
))
2385 if (put_user(sizeof(int), oldlenp
))
2389 if (newval
&& newlen
) {
2391 if (newlen
!= sizeof(int))
2393 if (get_user(new, (int __user
*)newval
))
2395 *(int *)(table
->data
) = msecs_to_jiffies(new);
2402 #else /* CONFIG_SYSCTL_SYSCALL */
2405 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2407 static int msg_count
;
2408 struct __sysctl_args tmp
;
2409 int name
[CTL_MAXNAME
];
2412 /* Read in the sysctl name for better debug message logging */
2413 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
2415 if (tmp
.nlen
<= 0 || tmp
.nlen
>= CTL_MAXNAME
)
2417 for (i
= 0; i
< tmp
.nlen
; i
++)
2418 if (get_user(name
[i
], tmp
.name
+ i
))
2421 /* Ignore accesses to kernel.version */
2422 if ((tmp
.nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
2425 if (msg_count
< 5) {
2428 "warning: process `%s' used the removed sysctl "
2429 "system call with ", current
->comm
);
2430 for (i
= 0; i
< tmp
.nlen
; i
++)
2431 printk("%d.", name
[i
]);
2438 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2439 void __user
*oldval
, size_t __user
*oldlenp
,
2440 void __user
*newval
, size_t newlen
)
2445 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2446 void __user
*oldval
, size_t __user
*oldlenp
,
2447 void __user
*newval
, size_t newlen
)
2452 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2453 void __user
*oldval
, size_t __user
*oldlenp
,
2454 void __user
*newval
, size_t newlen
)
2459 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2460 void __user
*oldval
, size_t __user
*oldlenp
,
2461 void __user
*newval
, size_t newlen
)
2466 #endif /* CONFIG_SYSCTL_SYSCALL */
2469 * No sense putting this after each symbol definition, twice,
2470 * exception granted :-)
2472 EXPORT_SYMBOL(proc_dointvec
);
2473 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2474 EXPORT_SYMBOL(proc_dointvec_minmax
);
2475 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2476 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2477 EXPORT_SYMBOL(proc_dostring
);
2478 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2479 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2480 EXPORT_SYMBOL(register_sysctl_table
);
2481 EXPORT_SYMBOL(sysctl_intvec
);
2482 EXPORT_SYMBOL(sysctl_jiffies
);
2483 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2484 EXPORT_SYMBOL(sysctl_string
);
2485 EXPORT_SYMBOL(unregister_sysctl_table
);