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>
33 #include <linux/init.h>
34 #include <linux/kernel.h>
35 #include <linux/kobject.h>
36 #include <linux/net.h>
37 #include <linux/sysrq.h>
38 #include <linux/highuid.h>
39 #include <linux/writeback.h>
40 #include <linux/hugetlb.h>
41 #include <linux/security.h>
42 #include <linux/initrd.h>
43 #include <linux/times.h>
44 #include <linux/limits.h>
45 #include <linux/dcache.h>
46 #include <linux/syscalls.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/acpi.h>
49 #include <linux/reboot.h>
51 #include <asm/uaccess.h>
52 #include <asm/processor.h>
56 #include <asm/stacktrace.h>
59 #if defined(CONFIG_SYSCTL)
61 /* External variables not in a header file. */
63 extern int print_fatal_signals
;
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
,
206 * NOTE: do not add new entries to this table unless you have read
207 * Documentation/sysctl/ctl_unnumbered.txt
212 #ifdef CONFIG_SCHED_DEBUG
213 static unsigned long min_sched_granularity_ns
= 100000; /* 100 usecs */
214 static unsigned long max_sched_granularity_ns
= 1000000000; /* 1 second */
215 static unsigned long min_wakeup_granularity_ns
; /* 0 usecs */
216 static unsigned long max_wakeup_granularity_ns
= 1000000000; /* 1 second */
219 static ctl_table kern_table
[] = {
220 #ifdef CONFIG_SCHED_DEBUG
222 .ctl_name
= CTL_UNNUMBERED
,
223 .procname
= "sched_granularity_ns",
224 .data
= &sysctl_sched_granularity
,
225 .maxlen
= sizeof(unsigned int),
227 .proc_handler
= &proc_dointvec_minmax
,
228 .strategy
= &sysctl_intvec
,
229 .extra1
= &min_sched_granularity_ns
,
230 .extra2
= &max_sched_granularity_ns
,
233 .ctl_name
= CTL_UNNUMBERED
,
234 .procname
= "sched_wakeup_granularity_ns",
235 .data
= &sysctl_sched_wakeup_granularity
,
236 .maxlen
= sizeof(unsigned int),
238 .proc_handler
= &proc_dointvec_minmax
,
239 .strategy
= &sysctl_intvec
,
240 .extra1
= &min_wakeup_granularity_ns
,
241 .extra2
= &max_wakeup_granularity_ns
,
244 .ctl_name
= CTL_UNNUMBERED
,
245 .procname
= "sched_batch_wakeup_granularity_ns",
246 .data
= &sysctl_sched_batch_wakeup_granularity
,
247 .maxlen
= sizeof(unsigned int),
249 .proc_handler
= &proc_dointvec_minmax
,
250 .strategy
= &sysctl_intvec
,
251 .extra1
= &min_wakeup_granularity_ns
,
252 .extra2
= &max_wakeup_granularity_ns
,
255 .ctl_name
= CTL_UNNUMBERED
,
256 .procname
= "sched_stat_granularity_ns",
257 .data
= &sysctl_sched_stat_granularity
,
258 .maxlen
= sizeof(unsigned int),
260 .proc_handler
= &proc_dointvec_minmax
,
261 .strategy
= &sysctl_intvec
,
262 .extra1
= &min_wakeup_granularity_ns
,
263 .extra2
= &max_wakeup_granularity_ns
,
266 .ctl_name
= CTL_UNNUMBERED
,
267 .procname
= "sched_runtime_limit_ns",
268 .data
= &sysctl_sched_runtime_limit
,
269 .maxlen
= sizeof(unsigned int),
271 .proc_handler
= &proc_dointvec_minmax
,
272 .strategy
= &sysctl_intvec
,
273 .extra1
= &min_sched_granularity_ns
,
274 .extra2
= &max_sched_granularity_ns
,
277 .ctl_name
= CTL_UNNUMBERED
,
278 .procname
= "sched_child_runs_first",
279 .data
= &sysctl_sched_child_runs_first
,
280 .maxlen
= sizeof(unsigned int),
282 .proc_handler
= &proc_dointvec
,
285 .ctl_name
= CTL_UNNUMBERED
,
286 .procname
= "sched_features",
287 .data
= &sysctl_sched_features
,
288 .maxlen
= sizeof(unsigned int),
290 .proc_handler
= &proc_dointvec
,
294 .ctl_name
= KERN_PANIC
,
296 .data
= &panic_timeout
,
297 .maxlen
= sizeof(int),
299 .proc_handler
= &proc_dointvec
,
302 .ctl_name
= KERN_CORE_USES_PID
,
303 .procname
= "core_uses_pid",
304 .data
= &core_uses_pid
,
305 .maxlen
= sizeof(int),
307 .proc_handler
= &proc_dointvec
,
310 .ctl_name
= KERN_CORE_PATTERN
,
311 .procname
= "core_pattern",
312 .data
= core_pattern
,
313 .maxlen
= CORENAME_MAX_SIZE
,
315 .proc_handler
= &proc_dostring
,
316 .strategy
= &sysctl_string
,
318 #ifdef CONFIG_PROC_SYSCTL
320 .ctl_name
= KERN_TAINTED
,
321 .procname
= "tainted",
323 .maxlen
= sizeof(int),
325 .proc_handler
= &proc_dointvec_taint
,
329 .ctl_name
= KERN_CAP_BSET
,
330 .procname
= "cap-bound",
332 .maxlen
= sizeof(kernel_cap_t
),
334 .proc_handler
= &proc_dointvec_bset
,
336 #ifdef CONFIG_BLK_DEV_INITRD
338 .ctl_name
= KERN_REALROOTDEV
,
339 .procname
= "real-root-dev",
340 .data
= &real_root_dev
,
341 .maxlen
= sizeof(int),
343 .proc_handler
= &proc_dointvec
,
347 .ctl_name
= CTL_UNNUMBERED
,
348 .procname
= "print-fatal-signals",
349 .data
= &print_fatal_signals
,
350 .maxlen
= sizeof(int),
352 .proc_handler
= &proc_dointvec
,
356 .ctl_name
= KERN_SPARC_REBOOT
,
357 .procname
= "reboot-cmd",
358 .data
= reboot_command
,
361 .proc_handler
= &proc_dostring
,
362 .strategy
= &sysctl_string
,
365 .ctl_name
= KERN_SPARC_STOP_A
,
366 .procname
= "stop-a",
367 .data
= &stop_a_enabled
,
368 .maxlen
= sizeof (int),
370 .proc_handler
= &proc_dointvec
,
373 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
374 .procname
= "scons-poweroff",
375 .data
= &scons_pwroff
,
376 .maxlen
= sizeof (int),
378 .proc_handler
= &proc_dointvec
,
383 .ctl_name
= KERN_HPPA_PWRSW
,
384 .procname
= "soft-power",
385 .data
= &pwrsw_enabled
,
386 .maxlen
= sizeof (int),
388 .proc_handler
= &proc_dointvec
,
391 .ctl_name
= KERN_HPPA_UNALIGNED
,
392 .procname
= "unaligned-trap",
393 .data
= &unaligned_enabled
,
394 .maxlen
= sizeof (int),
396 .proc_handler
= &proc_dointvec
,
400 .ctl_name
= KERN_CTLALTDEL
,
401 .procname
= "ctrl-alt-del",
403 .maxlen
= sizeof(int),
405 .proc_handler
= &proc_dointvec
,
408 .ctl_name
= KERN_PRINTK
,
409 .procname
= "printk",
410 .data
= &console_loglevel
,
411 .maxlen
= 4*sizeof(int),
413 .proc_handler
= &proc_dointvec
,
417 .ctl_name
= KERN_MODPROBE
,
418 .procname
= "modprobe",
419 .data
= &modprobe_path
,
420 .maxlen
= KMOD_PATH_LEN
,
422 .proc_handler
= &proc_dostring
,
423 .strategy
= &sysctl_string
,
426 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
428 .ctl_name
= KERN_HOTPLUG
,
429 .procname
= "hotplug",
430 .data
= &uevent_helper
,
431 .maxlen
= UEVENT_HELPER_PATH_LEN
,
433 .proc_handler
= &proc_dostring
,
434 .strategy
= &sysctl_string
,
437 #ifdef CONFIG_CHR_DEV_SG
439 .ctl_name
= KERN_SG_BIG_BUFF
,
440 .procname
= "sg-big-buff",
441 .data
= &sg_big_buff
,
442 .maxlen
= sizeof (int),
444 .proc_handler
= &proc_dointvec
,
447 #ifdef CONFIG_BSD_PROCESS_ACCT
449 .ctl_name
= KERN_ACCT
,
452 .maxlen
= 3*sizeof(int),
454 .proc_handler
= &proc_dointvec
,
457 #ifdef CONFIG_MAGIC_SYSRQ
459 .ctl_name
= KERN_SYSRQ
,
461 .data
= &__sysrq_enabled
,
462 .maxlen
= sizeof (int),
464 .proc_handler
= &proc_dointvec
,
467 #ifdef CONFIG_PROC_SYSCTL
469 .ctl_name
= KERN_CADPID
,
470 .procname
= "cad_pid",
472 .maxlen
= sizeof (int),
474 .proc_handler
= &proc_do_cad_pid
,
478 .ctl_name
= KERN_MAX_THREADS
,
479 .procname
= "threads-max",
480 .data
= &max_threads
,
481 .maxlen
= sizeof(int),
483 .proc_handler
= &proc_dointvec
,
486 .ctl_name
= KERN_RANDOM
,
487 .procname
= "random",
489 .child
= random_table
,
491 #ifdef CONFIG_UNIX98_PTYS
493 .ctl_name
= KERN_PTY
,
500 .ctl_name
= KERN_OVERFLOWUID
,
501 .procname
= "overflowuid",
502 .data
= &overflowuid
,
503 .maxlen
= sizeof(int),
505 .proc_handler
= &proc_dointvec_minmax
,
506 .strategy
= &sysctl_intvec
,
507 .extra1
= &minolduid
,
508 .extra2
= &maxolduid
,
511 .ctl_name
= KERN_OVERFLOWGID
,
512 .procname
= "overflowgid",
513 .data
= &overflowgid
,
514 .maxlen
= sizeof(int),
516 .proc_handler
= &proc_dointvec_minmax
,
517 .strategy
= &sysctl_intvec
,
518 .extra1
= &minolduid
,
519 .extra2
= &maxolduid
,
522 #ifdef CONFIG_MATHEMU
524 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
525 .procname
= "ieee_emulation_warnings",
526 .data
= &sysctl_ieee_emulation_warnings
,
527 .maxlen
= sizeof(int),
529 .proc_handler
= &proc_dointvec
,
532 #ifdef CONFIG_NO_IDLE_HZ
534 .ctl_name
= KERN_HZ_TIMER
,
535 .procname
= "hz_timer",
536 .data
= &sysctl_hz_timer
,
537 .maxlen
= sizeof(int),
539 .proc_handler
= &proc_dointvec
,
543 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
544 .procname
= "userprocess_debug",
545 .data
= &sysctl_userprocess_debug
,
546 .maxlen
= sizeof(int),
548 .proc_handler
= &proc_dointvec
,
552 .ctl_name
= KERN_PIDMAX
,
553 .procname
= "pid_max",
555 .maxlen
= sizeof (int),
557 .proc_handler
= &proc_dointvec_minmax
,
558 .strategy
= sysctl_intvec
,
559 .extra1
= &pid_max_min
,
560 .extra2
= &pid_max_max
,
563 .ctl_name
= KERN_PANIC_ON_OOPS
,
564 .procname
= "panic_on_oops",
565 .data
= &panic_on_oops
,
566 .maxlen
= sizeof(int),
568 .proc_handler
= &proc_dointvec
,
571 .ctl_name
= KERN_PRINTK_RATELIMIT
,
572 .procname
= "printk_ratelimit",
573 .data
= &printk_ratelimit_jiffies
,
574 .maxlen
= sizeof(int),
576 .proc_handler
= &proc_dointvec_jiffies
,
577 .strategy
= &sysctl_jiffies
,
580 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
581 .procname
= "printk_ratelimit_burst",
582 .data
= &printk_ratelimit_burst
,
583 .maxlen
= sizeof(int),
585 .proc_handler
= &proc_dointvec
,
588 .ctl_name
= KERN_NGROUPS_MAX
,
589 .procname
= "ngroups_max",
590 .data
= &ngroups_max
,
591 .maxlen
= sizeof (int),
593 .proc_handler
= &proc_dointvec
,
595 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
597 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
598 .procname
= "unknown_nmi_panic",
599 .data
= &unknown_nmi_panic
,
600 .maxlen
= sizeof (int),
602 .proc_handler
= &proc_dointvec
,
605 .ctl_name
= KERN_NMI_WATCHDOG
,
606 .procname
= "nmi_watchdog",
607 .data
= &nmi_watchdog_enabled
,
608 .maxlen
= sizeof (int),
610 .proc_handler
= &proc_nmi_enabled
,
613 #if defined(CONFIG_X86)
615 .ctl_name
= KERN_PANIC_ON_NMI
,
616 .procname
= "panic_on_unrecovered_nmi",
617 .data
= &panic_on_unrecovered_nmi
,
618 .maxlen
= sizeof(int),
620 .proc_handler
= &proc_dointvec
,
623 .ctl_name
= KERN_BOOTLOADER_TYPE
,
624 .procname
= "bootloader_type",
625 .data
= &bootloader_type
,
626 .maxlen
= sizeof (int),
628 .proc_handler
= &proc_dointvec
,
631 .ctl_name
= CTL_UNNUMBERED
,
632 .procname
= "kstack_depth_to_print",
633 .data
= &kstack_depth_to_print
,
634 .maxlen
= sizeof(int),
636 .proc_handler
= &proc_dointvec
,
639 #if defined(CONFIG_MMU)
641 .ctl_name
= KERN_RANDOMIZE
,
642 .procname
= "randomize_va_space",
643 .data
= &randomize_va_space
,
644 .maxlen
= sizeof(int),
646 .proc_handler
= &proc_dointvec
,
649 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
651 .ctl_name
= KERN_SPIN_RETRY
,
652 .procname
= "spin_retry",
654 .maxlen
= sizeof (int),
656 .proc_handler
= &proc_dointvec
,
659 #ifdef CONFIG_ACPI_SLEEP
661 .ctl_name
= KERN_ACPI_VIDEO_FLAGS
,
662 .procname
= "acpi_video_flags",
663 .data
= &acpi_video_flags
,
664 .maxlen
= sizeof (unsigned long),
666 .proc_handler
= &proc_doulongvec_minmax
,
671 .ctl_name
= KERN_IA64_UNALIGNED
,
672 .procname
= "ignore-unaligned-usertrap",
673 .data
= &no_unaligned_warning
,
674 .maxlen
= sizeof (int),
676 .proc_handler
= &proc_dointvec
,
681 .ctl_name
= KERN_COMPAT_LOG
,
682 .procname
= "compat-log",
684 .maxlen
= sizeof (int),
686 .proc_handler
= &proc_dointvec
,
689 #ifdef CONFIG_RT_MUTEXES
691 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
692 .procname
= "max_lock_depth",
693 .data
= &max_lock_depth
,
694 .maxlen
= sizeof(int),
696 .proc_handler
= &proc_dointvec
,
699 #ifdef CONFIG_PROC_FS
701 .ctl_name
= CTL_UNNUMBERED
,
702 .procname
= "maps_protect",
703 .data
= &maps_protect
,
704 .maxlen
= sizeof(int),
706 .proc_handler
= &proc_dointvec
,
710 .ctl_name
= CTL_UNNUMBERED
,
711 .procname
= "poweroff_cmd",
712 .data
= &poweroff_cmd
,
713 .maxlen
= POWEROFF_CMD_PATH_LEN
,
715 .proc_handler
= &proc_dostring
,
716 .strategy
= &sysctl_string
,
722 /* Constants for minimum and maximum testing in vm_table.
723 We use these as one-element integer vectors. */
725 static int one_hundred
= 100;
728 static ctl_table vm_table
[] = {
730 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
731 .procname
= "overcommit_memory",
732 .data
= &sysctl_overcommit_memory
,
733 .maxlen
= sizeof(sysctl_overcommit_memory
),
735 .proc_handler
= &proc_dointvec
,
738 .ctl_name
= VM_PANIC_ON_OOM
,
739 .procname
= "panic_on_oom",
740 .data
= &sysctl_panic_on_oom
,
741 .maxlen
= sizeof(sysctl_panic_on_oom
),
743 .proc_handler
= &proc_dointvec
,
746 .ctl_name
= VM_OVERCOMMIT_RATIO
,
747 .procname
= "overcommit_ratio",
748 .data
= &sysctl_overcommit_ratio
,
749 .maxlen
= sizeof(sysctl_overcommit_ratio
),
751 .proc_handler
= &proc_dointvec
,
754 .ctl_name
= VM_PAGE_CLUSTER
,
755 .procname
= "page-cluster",
756 .data
= &page_cluster
,
757 .maxlen
= sizeof(int),
759 .proc_handler
= &proc_dointvec
,
762 .ctl_name
= VM_DIRTY_BACKGROUND
,
763 .procname
= "dirty_background_ratio",
764 .data
= &dirty_background_ratio
,
765 .maxlen
= sizeof(dirty_background_ratio
),
767 .proc_handler
= &proc_dointvec_minmax
,
768 .strategy
= &sysctl_intvec
,
770 .extra2
= &one_hundred
,
773 .ctl_name
= VM_DIRTY_RATIO
,
774 .procname
= "dirty_ratio",
775 .data
= &vm_dirty_ratio
,
776 .maxlen
= sizeof(vm_dirty_ratio
),
778 .proc_handler
= &proc_dointvec_minmax
,
779 .strategy
= &sysctl_intvec
,
781 .extra2
= &one_hundred
,
784 .ctl_name
= VM_DIRTY_WB_CS
,
785 .procname
= "dirty_writeback_centisecs",
786 .data
= &dirty_writeback_interval
,
787 .maxlen
= sizeof(dirty_writeback_interval
),
789 .proc_handler
= &dirty_writeback_centisecs_handler
,
792 .ctl_name
= VM_DIRTY_EXPIRE_CS
,
793 .procname
= "dirty_expire_centisecs",
794 .data
= &dirty_expire_interval
,
795 .maxlen
= sizeof(dirty_expire_interval
),
797 .proc_handler
= &proc_dointvec_userhz_jiffies
,
800 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
801 .procname
= "nr_pdflush_threads",
802 .data
= &nr_pdflush_threads
,
803 .maxlen
= sizeof nr_pdflush_threads
,
804 .mode
= 0444 /* read-only*/,
805 .proc_handler
= &proc_dointvec
,
808 .ctl_name
= VM_SWAPPINESS
,
809 .procname
= "swappiness",
810 .data
= &vm_swappiness
,
811 .maxlen
= sizeof(vm_swappiness
),
813 .proc_handler
= &proc_dointvec_minmax
,
814 .strategy
= &sysctl_intvec
,
816 .extra2
= &one_hundred
,
818 #ifdef CONFIG_HUGETLB_PAGE
820 .ctl_name
= VM_HUGETLB_PAGES
,
821 .procname
= "nr_hugepages",
822 .data
= &max_huge_pages
,
823 .maxlen
= sizeof(unsigned long),
825 .proc_handler
= &hugetlb_sysctl_handler
,
826 .extra1
= (void *)&hugetlb_zero
,
827 .extra2
= (void *)&hugetlb_infinity
,
830 .ctl_name
= VM_HUGETLB_GROUP
,
831 .procname
= "hugetlb_shm_group",
832 .data
= &sysctl_hugetlb_shm_group
,
833 .maxlen
= sizeof(gid_t
),
835 .proc_handler
= &proc_dointvec
,
838 .ctl_name
= CTL_UNNUMBERED
,
839 .procname
= "hugepages_treat_as_movable",
840 .data
= &hugepages_treat_as_movable
,
841 .maxlen
= sizeof(int),
843 .proc_handler
= &hugetlb_treat_movable_handler
,
847 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
848 .procname
= "lowmem_reserve_ratio",
849 .data
= &sysctl_lowmem_reserve_ratio
,
850 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
852 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
853 .strategy
= &sysctl_intvec
,
856 .ctl_name
= VM_DROP_PAGECACHE
,
857 .procname
= "drop_caches",
858 .data
= &sysctl_drop_caches
,
859 .maxlen
= sizeof(int),
861 .proc_handler
= drop_caches_sysctl_handler
,
862 .strategy
= &sysctl_intvec
,
865 .ctl_name
= VM_MIN_FREE_KBYTES
,
866 .procname
= "min_free_kbytes",
867 .data
= &min_free_kbytes
,
868 .maxlen
= sizeof(min_free_kbytes
),
870 .proc_handler
= &min_free_kbytes_sysctl_handler
,
871 .strategy
= &sysctl_intvec
,
875 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
876 .procname
= "percpu_pagelist_fraction",
877 .data
= &percpu_pagelist_fraction
,
878 .maxlen
= sizeof(percpu_pagelist_fraction
),
880 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
881 .strategy
= &sysctl_intvec
,
882 .extra1
= &min_percpu_pagelist_fract
,
886 .ctl_name
= VM_MAX_MAP_COUNT
,
887 .procname
= "max_map_count",
888 .data
= &sysctl_max_map_count
,
889 .maxlen
= sizeof(sysctl_max_map_count
),
891 .proc_handler
= &proc_dointvec
895 .ctl_name
= VM_LAPTOP_MODE
,
896 .procname
= "laptop_mode",
897 .data
= &laptop_mode
,
898 .maxlen
= sizeof(laptop_mode
),
900 .proc_handler
= &proc_dointvec_jiffies
,
901 .strategy
= &sysctl_jiffies
,
904 .ctl_name
= VM_BLOCK_DUMP
,
905 .procname
= "block_dump",
907 .maxlen
= sizeof(block_dump
),
909 .proc_handler
= &proc_dointvec
,
910 .strategy
= &sysctl_intvec
,
914 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
915 .procname
= "vfs_cache_pressure",
916 .data
= &sysctl_vfs_cache_pressure
,
917 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
919 .proc_handler
= &proc_dointvec
,
920 .strategy
= &sysctl_intvec
,
923 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
925 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
926 .procname
= "legacy_va_layout",
927 .data
= &sysctl_legacy_va_layout
,
928 .maxlen
= sizeof(sysctl_legacy_va_layout
),
930 .proc_handler
= &proc_dointvec
,
931 .strategy
= &sysctl_intvec
,
937 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
938 .procname
= "zone_reclaim_mode",
939 .data
= &zone_reclaim_mode
,
940 .maxlen
= sizeof(zone_reclaim_mode
),
942 .proc_handler
= &proc_dointvec
,
943 .strategy
= &sysctl_intvec
,
947 .ctl_name
= VM_MIN_UNMAPPED
,
948 .procname
= "min_unmapped_ratio",
949 .data
= &sysctl_min_unmapped_ratio
,
950 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
952 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
953 .strategy
= &sysctl_intvec
,
955 .extra2
= &one_hundred
,
958 .ctl_name
= VM_MIN_SLAB
,
959 .procname
= "min_slab_ratio",
960 .data
= &sysctl_min_slab_ratio
,
961 .maxlen
= sizeof(sysctl_min_slab_ratio
),
963 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
964 .strategy
= &sysctl_intvec
,
966 .extra2
= &one_hundred
,
971 .ctl_name
= CTL_UNNUMBERED
,
972 .procname
= "stat_interval",
973 .data
= &sysctl_stat_interval
,
974 .maxlen
= sizeof(sysctl_stat_interval
),
976 .proc_handler
= &proc_dointvec_jiffies
,
977 .strategy
= &sysctl_jiffies
,
980 #ifdef CONFIG_SECURITY
982 .ctl_name
= CTL_UNNUMBERED
,
983 .procname
= "mmap_min_addr",
984 .data
= &mmap_min_addr
,
985 .maxlen
= sizeof(unsigned long),
987 .proc_handler
= &proc_doulongvec_minmax
,
991 .ctl_name
= CTL_UNNUMBERED
,
992 .procname
= "numa_zonelist_order",
993 .data
= &numa_zonelist_order
,
994 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
996 .proc_handler
= &numa_zonelist_order_handler
,
997 .strategy
= &sysctl_string
,
1001 #if defined(CONFIG_X86_32) || \
1002 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1004 .ctl_name
= VM_VDSO_ENABLED
,
1005 .procname
= "vdso_enabled",
1006 .data
= &vdso_enabled
,
1007 .maxlen
= sizeof(vdso_enabled
),
1009 .proc_handler
= &proc_dointvec
,
1010 .strategy
= &sysctl_intvec
,
1015 * NOTE: do not add new entries to this table unless you have read
1016 * Documentation/sysctl/ctl_unnumbered.txt
1021 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1022 static ctl_table binfmt_misc_table
[] = {
1027 static ctl_table fs_table
[] = {
1029 .ctl_name
= FS_NRINODE
,
1030 .procname
= "inode-nr",
1031 .data
= &inodes_stat
,
1032 .maxlen
= 2*sizeof(int),
1034 .proc_handler
= &proc_dointvec
,
1037 .ctl_name
= FS_STATINODE
,
1038 .procname
= "inode-state",
1039 .data
= &inodes_stat
,
1040 .maxlen
= 7*sizeof(int),
1042 .proc_handler
= &proc_dointvec
,
1045 .ctl_name
= FS_NRFILE
,
1046 .procname
= "file-nr",
1047 .data
= &files_stat
,
1048 .maxlen
= 3*sizeof(int),
1050 .proc_handler
= &proc_nr_files
,
1053 .ctl_name
= FS_MAXFILE
,
1054 .procname
= "file-max",
1055 .data
= &files_stat
.max_files
,
1056 .maxlen
= sizeof(int),
1058 .proc_handler
= &proc_dointvec
,
1061 .ctl_name
= FS_DENTRY
,
1062 .procname
= "dentry-state",
1063 .data
= &dentry_stat
,
1064 .maxlen
= 6*sizeof(int),
1066 .proc_handler
= &proc_dointvec
,
1069 .ctl_name
= FS_OVERFLOWUID
,
1070 .procname
= "overflowuid",
1071 .data
= &fs_overflowuid
,
1072 .maxlen
= sizeof(int),
1074 .proc_handler
= &proc_dointvec_minmax
,
1075 .strategy
= &sysctl_intvec
,
1076 .extra1
= &minolduid
,
1077 .extra2
= &maxolduid
,
1080 .ctl_name
= FS_OVERFLOWGID
,
1081 .procname
= "overflowgid",
1082 .data
= &fs_overflowgid
,
1083 .maxlen
= sizeof(int),
1085 .proc_handler
= &proc_dointvec_minmax
,
1086 .strategy
= &sysctl_intvec
,
1087 .extra1
= &minolduid
,
1088 .extra2
= &maxolduid
,
1091 .ctl_name
= FS_LEASES
,
1092 .procname
= "leases-enable",
1093 .data
= &leases_enable
,
1094 .maxlen
= sizeof(int),
1096 .proc_handler
= &proc_dointvec
,
1098 #ifdef CONFIG_DNOTIFY
1100 .ctl_name
= FS_DIR_NOTIFY
,
1101 .procname
= "dir-notify-enable",
1102 .data
= &dir_notify_enable
,
1103 .maxlen
= sizeof(int),
1105 .proc_handler
= &proc_dointvec
,
1110 .ctl_name
= FS_LEASE_TIME
,
1111 .procname
= "lease-break-time",
1112 .data
= &lease_break_time
,
1113 .maxlen
= sizeof(int),
1115 .proc_handler
= &proc_dointvec
,
1118 .ctl_name
= FS_AIO_NR
,
1119 .procname
= "aio-nr",
1121 .maxlen
= sizeof(aio_nr
),
1123 .proc_handler
= &proc_doulongvec_minmax
,
1126 .ctl_name
= FS_AIO_MAX_NR
,
1127 .procname
= "aio-max-nr",
1128 .data
= &aio_max_nr
,
1129 .maxlen
= sizeof(aio_max_nr
),
1131 .proc_handler
= &proc_doulongvec_minmax
,
1133 #ifdef CONFIG_INOTIFY_USER
1135 .ctl_name
= FS_INOTIFY
,
1136 .procname
= "inotify",
1138 .child
= inotify_table
,
1143 .ctl_name
= KERN_SETUID_DUMPABLE
,
1144 .procname
= "suid_dumpable",
1145 .data
= &suid_dumpable
,
1146 .maxlen
= sizeof(int),
1148 .proc_handler
= &proc_dointvec
,
1150 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1152 .ctl_name
= CTL_UNNUMBERED
,
1153 .procname
= "binfmt_misc",
1155 .child
= binfmt_misc_table
,
1159 * NOTE: do not add new entries to this table unless you have read
1160 * Documentation/sysctl/ctl_unnumbered.txt
1165 static ctl_table debug_table
[] = {
1169 static ctl_table dev_table
[] = {
1173 static DEFINE_SPINLOCK(sysctl_lock
);
1175 /* called under sysctl_lock */
1176 static int use_table(struct ctl_table_header
*p
)
1178 if (unlikely(p
->unregistering
))
1184 /* called under sysctl_lock */
1185 static void unuse_table(struct ctl_table_header
*p
)
1188 if (unlikely(p
->unregistering
))
1189 complete(p
->unregistering
);
1192 /* called under sysctl_lock, will reacquire if has to wait */
1193 static void start_unregistering(struct ctl_table_header
*p
)
1196 * if p->used is 0, nobody will ever touch that entry again;
1197 * we'll eliminate all paths to it before dropping sysctl_lock
1199 if (unlikely(p
->used
)) {
1200 struct completion wait
;
1201 init_completion(&wait
);
1202 p
->unregistering
= &wait
;
1203 spin_unlock(&sysctl_lock
);
1204 wait_for_completion(&wait
);
1205 spin_lock(&sysctl_lock
);
1208 * do not remove from the list until nobody holds it; walking the
1209 * list in do_sysctl() relies on that.
1211 list_del_init(&p
->ctl_entry
);
1214 void sysctl_head_finish(struct ctl_table_header
*head
)
1218 spin_lock(&sysctl_lock
);
1220 spin_unlock(&sysctl_lock
);
1223 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1225 struct ctl_table_header
*head
;
1226 struct list_head
*tmp
;
1227 spin_lock(&sysctl_lock
);
1229 tmp
= &prev
->ctl_entry
;
1233 tmp
= &root_table_header
.ctl_entry
;
1235 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1237 if (!use_table(head
))
1239 spin_unlock(&sysctl_lock
);
1243 if (tmp
== &root_table_header
.ctl_entry
)
1246 spin_unlock(&sysctl_lock
);
1250 #ifdef CONFIG_SYSCTL_SYSCALL
1251 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1252 void __user
*newval
, size_t newlen
)
1254 struct ctl_table_header
*head
;
1255 int error
= -ENOTDIR
;
1257 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1261 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1265 for (head
= sysctl_head_next(NULL
); head
;
1266 head
= sysctl_head_next(head
)) {
1267 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1268 newval
, newlen
, head
->ctl_table
);
1269 if (error
!= -ENOTDIR
) {
1270 sysctl_head_finish(head
);
1277 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1279 struct __sysctl_args tmp
;
1282 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1286 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1287 tmp
.newval
, tmp
.newlen
);
1291 #endif /* CONFIG_SYSCTL_SYSCALL */
1294 * sysctl_perm does NOT grant the superuser all rights automatically, because
1295 * some sysctl variables are readonly even to root.
1298 static int test_perm(int mode
, int op
)
1302 else if (in_egroup_p(0))
1304 if ((mode
& op
& 0007) == op
)
1309 int sysctl_perm(ctl_table
*table
, int op
)
1312 error
= security_sysctl(table
, op
);
1315 return test_perm(table
->mode
, op
);
1318 #ifdef CONFIG_SYSCTL_SYSCALL
1319 static int parse_table(int __user
*name
, int nlen
,
1320 void __user
*oldval
, size_t __user
*oldlenp
,
1321 void __user
*newval
, size_t newlen
,
1328 if (get_user(n
, name
))
1330 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1331 if (!table
->ctl_name
)
1333 if (n
== table
->ctl_name
) {
1336 if (sysctl_perm(table
, 001))
1340 table
= table
->child
;
1343 error
= do_sysctl_strategy(table
, name
, nlen
,
1352 /* Perform the actual read/write of a sysctl table entry. */
1353 int do_sysctl_strategy (ctl_table
*table
,
1354 int __user
*name
, int nlen
,
1355 void __user
*oldval
, size_t __user
*oldlenp
,
1356 void __user
*newval
, size_t newlen
)
1365 if (sysctl_perm(table
, op
))
1368 if (table
->strategy
) {
1369 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1377 /* If there is no strategy routine, or if the strategy returns
1378 * zero, proceed with automatic r/w */
1379 if (table
->data
&& table
->maxlen
) {
1380 if (oldval
&& oldlenp
) {
1381 if (get_user(len
, oldlenp
))
1384 if (len
> table
->maxlen
)
1385 len
= table
->maxlen
;
1386 if(copy_to_user(oldval
, table
->data
, len
))
1388 if(put_user(len
, oldlenp
))
1392 if (newval
&& newlen
) {
1394 if (len
> table
->maxlen
)
1395 len
= table
->maxlen
;
1396 if(copy_from_user(table
->data
, newval
, len
))
1402 #endif /* CONFIG_SYSCTL_SYSCALL */
1404 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1406 for (; table
->ctl_name
|| table
->procname
; table
++) {
1407 table
->parent
= parent
;
1409 sysctl_set_parent(table
, table
->child
);
1413 static __init
int sysctl_init(void)
1415 sysctl_set_parent(NULL
, root_table
);
1419 core_initcall(sysctl_init
);
1422 * register_sysctl_table - register a sysctl hierarchy
1423 * @table: the top-level table structure
1425 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1426 * array. An entry with a ctl_name of 0 terminates the table.
1428 * The members of the &ctl_table structure are used as follows:
1430 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1431 * must be unique within that level of sysctl
1433 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1434 * enter a sysctl file
1436 * data - a pointer to data for use by proc_handler
1438 * maxlen - the maximum size in bytes of the data
1440 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1442 * child - a pointer to the child sysctl table if this entry is a directory, or
1445 * proc_handler - the text handler routine (described below)
1447 * strategy - the strategy routine (described below)
1449 * de - for internal use by the sysctl routines
1451 * extra1, extra2 - extra pointers usable by the proc handler routines
1453 * Leaf nodes in the sysctl tree will be represented by a single file
1454 * under /proc; non-leaf nodes will be represented by directories.
1456 * sysctl(2) can automatically manage read and write requests through
1457 * the sysctl table. The data and maxlen fields of the ctl_table
1458 * struct enable minimal validation of the values being written to be
1459 * performed, and the mode field allows minimal authentication.
1461 * More sophisticated management can be enabled by the provision of a
1462 * strategy routine with the table entry. This will be called before
1463 * any automatic read or write of the data is performed.
1465 * The strategy routine may return
1467 * < 0 - Error occurred (error is passed to user process)
1469 * 0 - OK - proceed with automatic read or write.
1471 * > 0 - OK - read or write has been done by the strategy routine, so
1472 * return immediately.
1474 * There must be a proc_handler routine for any terminal nodes
1475 * mirrored under /proc/sys (non-terminals are handled by a built-in
1476 * directory handler). Several default handlers are available to
1477 * cover common cases -
1479 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1480 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1481 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1483 * It is the handler's job to read the input buffer from user memory
1484 * and process it. The handler should return 0 on success.
1486 * This routine returns %NULL on a failure to register, and a pointer
1487 * to the table header on success.
1489 struct ctl_table_header
*register_sysctl_table(ctl_table
* table
)
1491 struct ctl_table_header
*tmp
;
1492 tmp
= kmalloc(sizeof(struct ctl_table_header
), GFP_KERNEL
);
1495 tmp
->ctl_table
= table
;
1496 INIT_LIST_HEAD(&tmp
->ctl_entry
);
1498 tmp
->unregistering
= NULL
;
1499 sysctl_set_parent(NULL
, table
);
1500 spin_lock(&sysctl_lock
);
1501 list_add_tail(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1502 spin_unlock(&sysctl_lock
);
1507 * unregister_sysctl_table - unregister a sysctl table hierarchy
1508 * @header: the header returned from register_sysctl_table
1510 * Unregisters the sysctl table and all children. proc entries may not
1511 * actually be removed until they are no longer used by anyone.
1513 void unregister_sysctl_table(struct ctl_table_header
* header
)
1516 spin_lock(&sysctl_lock
);
1517 start_unregistering(header
);
1518 spin_unlock(&sysctl_lock
);
1522 #else /* !CONFIG_SYSCTL */
1523 struct ctl_table_header
*register_sysctl_table(ctl_table
* table
)
1528 void unregister_sysctl_table(struct ctl_table_header
* table
)
1532 #endif /* CONFIG_SYSCTL */
1538 #ifdef CONFIG_PROC_SYSCTL
1540 static int _proc_do_string(void* data
, int maxlen
, int write
,
1541 struct file
*filp
, void __user
*buffer
,
1542 size_t *lenp
, loff_t
*ppos
)
1548 if (!data
|| !maxlen
|| !*lenp
) {
1556 while (len
< *lenp
) {
1557 if (get_user(c
, p
++))
1559 if (c
== 0 || c
== '\n')
1565 if(copy_from_user(data
, buffer
, len
))
1567 ((char *) data
)[len
] = 0;
1585 if(copy_to_user(buffer
, data
, len
))
1588 if(put_user('\n', ((char __user
*) buffer
) + len
))
1599 * proc_dostring - read a string sysctl
1600 * @table: the sysctl table
1601 * @write: %TRUE if this is a write to the sysctl file
1602 * @filp: the file structure
1603 * @buffer: the user buffer
1604 * @lenp: the size of the user buffer
1605 * @ppos: file position
1607 * Reads/writes a string from/to the user buffer. If the kernel
1608 * buffer provided is not large enough to hold the string, the
1609 * string is truncated. The copied string is %NULL-terminated.
1610 * If the string is being read by the user process, it is copied
1611 * and a newline '\n' is added. It is truncated if the buffer is
1614 * Returns 0 on success.
1616 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1617 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1619 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
1620 buffer
, lenp
, ppos
);
1624 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1626 int write
, void *data
)
1629 *valp
= *negp
? -*lvalp
: *lvalp
;
1634 *lvalp
= (unsigned long)-val
;
1637 *lvalp
= (unsigned long)val
;
1643 static int __do_proc_dointvec(void *tbl_data
, ctl_table
*table
,
1644 int write
, struct file
*filp
, void __user
*buffer
,
1645 size_t *lenp
, loff_t
*ppos
,
1646 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1647 int write
, void *data
),
1650 #define TMPBUFLEN 21
1651 int *i
, vleft
, first
=1, neg
, val
;
1655 char buf
[TMPBUFLEN
], *p
;
1656 char __user
*s
= buffer
;
1658 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
1659 (*ppos
&& !write
)) {
1664 i
= (int *) tbl_data
;
1665 vleft
= table
->maxlen
/ sizeof(*i
);
1669 conv
= do_proc_dointvec_conv
;
1671 for (; left
&& vleft
--; i
++, first
=0) {
1686 if (len
> sizeof(buf
) - 1)
1687 len
= sizeof(buf
) - 1;
1688 if (copy_from_user(buf
, s
, len
))
1692 if (*p
== '-' && left
> 1) {
1696 if (*p
< '0' || *p
> '9')
1699 lval
= simple_strtoul(p
, &p
, 0);
1702 if ((len
< left
) && *p
&& !isspace(*p
))
1709 if (conv(&neg
, &lval
, i
, 1, data
))
1716 if (conv(&neg
, &lval
, i
, 0, data
))
1719 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
1723 if(copy_to_user(s
, buf
, len
))
1730 if (!write
&& !first
&& left
) {
1731 if(put_user('\n', s
))
1738 if (get_user(c
, s
++))
1753 static int do_proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1754 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1755 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1756 int write
, void *data
),
1759 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
1760 buffer
, lenp
, ppos
, conv
, data
);
1764 * proc_dointvec - read a vector of integers
1765 * @table: the sysctl table
1766 * @write: %TRUE if this is a write to the sysctl file
1767 * @filp: the file structure
1768 * @buffer: the user buffer
1769 * @lenp: the size of the user buffer
1770 * @ppos: file position
1772 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1773 * values from/to the user buffer, treated as an ASCII string.
1775 * Returns 0 on success.
1777 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1778 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1780 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1788 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
1790 int write
, void *data
)
1792 int op
= *(int *)data
;
1794 int val
= *negp
? -*lvalp
: *lvalp
;
1796 case OP_SET
: *valp
= val
; break;
1797 case OP_AND
: *valp
&= val
; break;
1798 case OP_OR
: *valp
|= val
; break;
1804 *lvalp
= (unsigned long)-val
;
1807 *lvalp
= (unsigned long)val
;
1814 * init may raise the set.
1817 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1818 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1822 if (write
&& !capable(CAP_SYS_MODULE
)) {
1826 op
= is_init(current
) ? OP_SET
: OP_AND
;
1827 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1828 do_proc_dointvec_bset_conv
,&op
);
1832 * Taint values can only be increased
1834 static int proc_dointvec_taint(ctl_table
*table
, int write
, struct file
*filp
,
1835 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1839 if (write
&& !capable(CAP_SYS_ADMIN
))
1843 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1844 do_proc_dointvec_bset_conv
,&op
);
1847 struct do_proc_dointvec_minmax_conv_param
{
1852 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
1854 int write
, void *data
)
1856 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
1858 int val
= *negp
? -*lvalp
: *lvalp
;
1859 if ((param
->min
&& *param
->min
> val
) ||
1860 (param
->max
&& *param
->max
< val
))
1867 *lvalp
= (unsigned long)-val
;
1870 *lvalp
= (unsigned long)val
;
1877 * proc_dointvec_minmax - read a vector of integers with min/max values
1878 * @table: the sysctl table
1879 * @write: %TRUE if this is a write to the sysctl file
1880 * @filp: the file structure
1881 * @buffer: the user buffer
1882 * @lenp: the size of the user buffer
1883 * @ppos: file position
1885 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1886 * values from/to the user buffer, treated as an ASCII string.
1888 * This routine will ensure the values are within the range specified by
1889 * table->extra1 (min) and table->extra2 (max).
1891 * Returns 0 on success.
1893 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1894 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1896 struct do_proc_dointvec_minmax_conv_param param
= {
1897 .min
= (int *) table
->extra1
,
1898 .max
= (int *) table
->extra2
,
1900 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
1901 do_proc_dointvec_minmax_conv
, ¶m
);
1904 static int __do_proc_doulongvec_minmax(void *data
, ctl_table
*table
, int write
,
1906 void __user
*buffer
,
1907 size_t *lenp
, loff_t
*ppos
,
1908 unsigned long convmul
,
1909 unsigned long convdiv
)
1911 #define TMPBUFLEN 21
1912 unsigned long *i
, *min
, *max
, val
;
1913 int vleft
, first
=1, neg
;
1915 char buf
[TMPBUFLEN
], *p
;
1916 char __user
*s
= buffer
;
1918 if (!data
|| !table
->maxlen
|| !*lenp
||
1919 (*ppos
&& !write
)) {
1924 i
= (unsigned long *) data
;
1925 min
= (unsigned long *) table
->extra1
;
1926 max
= (unsigned long *) table
->extra2
;
1927 vleft
= table
->maxlen
/ sizeof(unsigned long);
1930 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
1945 if (len
> TMPBUFLEN
-1)
1947 if (copy_from_user(buf
, s
, len
))
1951 if (*p
== '-' && left
> 1) {
1955 if (*p
< '0' || *p
> '9')
1957 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
1959 if ((len
< left
) && *p
&& !isspace(*p
))
1968 if ((min
&& val
< *min
) || (max
&& val
> *max
))
1975 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
1979 if(copy_to_user(s
, buf
, len
))
1986 if (!write
&& !first
&& left
) {
1987 if(put_user('\n', s
))
1994 if (get_user(c
, s
++))
2009 static int do_proc_doulongvec_minmax(ctl_table
*table
, int write
,
2011 void __user
*buffer
,
2012 size_t *lenp
, loff_t
*ppos
,
2013 unsigned long convmul
,
2014 unsigned long convdiv
)
2016 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2017 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2021 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2022 * @table: the sysctl table
2023 * @write: %TRUE if this is a write to the sysctl file
2024 * @filp: the file structure
2025 * @buffer: the user buffer
2026 * @lenp: the size of the user buffer
2027 * @ppos: file position
2029 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2030 * values from/to the user buffer, treated as an ASCII string.
2032 * This routine will ensure the values are within the range specified by
2033 * table->extra1 (min) and table->extra2 (max).
2035 * Returns 0 on success.
2037 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2038 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2040 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2044 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2045 * @table: the sysctl table
2046 * @write: %TRUE if this is a write to the sysctl file
2047 * @filp: the file structure
2048 * @buffer: the user buffer
2049 * @lenp: the size of the user buffer
2050 * @ppos: file position
2052 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2053 * values from/to the user buffer, treated as an ASCII string. The values
2054 * are treated as milliseconds, and converted to jiffies when they are stored.
2056 * This routine will ensure the values are within the range specified by
2057 * table->extra1 (min) and table->extra2 (max).
2059 * Returns 0 on success.
2061 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2063 void __user
*buffer
,
2064 size_t *lenp
, loff_t
*ppos
)
2066 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2067 lenp
, ppos
, HZ
, 1000l);
2071 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2073 int write
, void *data
)
2076 if (*lvalp
> LONG_MAX
/ HZ
)
2078 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2084 lval
= (unsigned long)-val
;
2087 lval
= (unsigned long)val
;
2094 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2096 int write
, void *data
)
2099 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2101 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2107 lval
= (unsigned long)-val
;
2110 lval
= (unsigned long)val
;
2112 *lvalp
= jiffies_to_clock_t(lval
);
2117 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2119 int write
, void *data
)
2122 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2128 lval
= (unsigned long)-val
;
2131 lval
= (unsigned long)val
;
2133 *lvalp
= jiffies_to_msecs(lval
);
2139 * proc_dointvec_jiffies - read a vector of integers as seconds
2140 * @table: the sysctl table
2141 * @write: %TRUE if this is a write to the sysctl file
2142 * @filp: the file structure
2143 * @buffer: the user buffer
2144 * @lenp: the size of the user buffer
2145 * @ppos: file position
2147 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2148 * values from/to the user buffer, treated as an ASCII string.
2149 * The values read are assumed to be in seconds, and are converted into
2152 * Returns 0 on success.
2154 int proc_dointvec_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_jiffies_conv
,NULL
);
2162 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2163 * @table: the sysctl table
2164 * @write: %TRUE if this is a write to the sysctl file
2165 * @filp: the file structure
2166 * @buffer: the user buffer
2167 * @lenp: the size of the user buffer
2168 * @ppos: pointer to the file position
2170 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2171 * values from/to the user buffer, treated as an ASCII string.
2172 * The values read are assumed to be in 1/USER_HZ seconds, and
2173 * are converted into jiffies.
2175 * Returns 0 on success.
2177 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2178 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2180 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2181 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2185 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2186 * @table: the sysctl table
2187 * @write: %TRUE if this is a write to the sysctl file
2188 * @filp: the file structure
2189 * @buffer: the user buffer
2190 * @lenp: the size of the user buffer
2191 * @ppos: file position
2192 * @ppos: the current position in the file
2194 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2195 * values from/to the user buffer, treated as an ASCII string.
2196 * The values read are assumed to be in 1/1000 seconds, and
2197 * are converted into jiffies.
2199 * Returns 0 on success.
2201 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2202 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2204 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2205 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2208 static int proc_do_cad_pid(ctl_table
*table
, int write
, struct file
*filp
,
2209 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2211 struct pid
*new_pid
;
2215 tmp
= pid_nr(cad_pid
);
2217 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2218 lenp
, ppos
, NULL
, NULL
);
2222 new_pid
= find_get_pid(tmp
);
2226 put_pid(xchg(&cad_pid
, new_pid
));
2230 #else /* CONFIG_PROC_FS */
2232 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2233 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2238 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2239 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2244 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2245 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2250 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2251 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2256 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2257 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2262 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2263 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2268 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2269 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2274 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2275 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2280 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2282 void __user
*buffer
,
2283 size_t *lenp
, loff_t
*ppos
)
2289 #endif /* CONFIG_PROC_FS */
2292 #ifdef CONFIG_SYSCTL_SYSCALL
2294 * General sysctl support routines
2297 /* The generic string strategy routine: */
2298 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2299 void __user
*oldval
, size_t __user
*oldlenp
,
2300 void __user
*newval
, size_t newlen
)
2302 if (!table
->data
|| !table
->maxlen
)
2305 if (oldval
&& oldlenp
) {
2307 if (get_user(bufsize
, oldlenp
))
2310 size_t len
= strlen(table
->data
), copied
;
2312 /* This shouldn't trigger for a well-formed sysctl */
2313 if (len
> table
->maxlen
)
2314 len
= table
->maxlen
;
2316 /* Copy up to a max of bufsize-1 bytes of the string */
2317 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2319 if (copy_to_user(oldval
, table
->data
, copied
) ||
2320 put_user(0, (char __user
*)(oldval
+ copied
)))
2322 if (put_user(len
, oldlenp
))
2326 if (newval
&& newlen
) {
2327 size_t len
= newlen
;
2328 if (len
> table
->maxlen
)
2329 len
= table
->maxlen
;
2330 if(copy_from_user(table
->data
, newval
, len
))
2332 if (len
== table
->maxlen
)
2334 ((char *) table
->data
)[len
] = 0;
2340 * This function makes sure that all of the integers in the vector
2341 * are between the minimum and maximum values given in the arrays
2342 * table->extra1 and table->extra2, respectively.
2344 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2345 void __user
*oldval
, size_t __user
*oldlenp
,
2346 void __user
*newval
, size_t newlen
)
2349 if (newval
&& newlen
) {
2350 int __user
*vec
= (int __user
*) newval
;
2351 int *min
= (int *) table
->extra1
;
2352 int *max
= (int *) table
->extra2
;
2356 if (newlen
% sizeof(int) != 0)
2359 if (!table
->extra1
&& !table
->extra2
)
2362 if (newlen
> table
->maxlen
)
2363 newlen
= table
->maxlen
;
2364 length
= newlen
/ sizeof(int);
2366 for (i
= 0; i
< length
; i
++) {
2368 if (get_user(value
, vec
+ i
))
2370 if (min
&& value
< min
[i
])
2372 if (max
&& value
> max
[i
])
2379 /* Strategy function to convert jiffies to seconds */
2380 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2381 void __user
*oldval
, size_t __user
*oldlenp
,
2382 void __user
*newval
, size_t newlen
)
2384 if (oldval
&& oldlenp
) {
2387 if (get_user(olen
, oldlenp
))
2392 if (olen
< sizeof(int))
2395 val
= *(int *)(table
->data
) / HZ
;
2396 if (put_user(val
, (int __user
*)oldval
))
2398 if (put_user(sizeof(int), oldlenp
))
2402 if (newval
&& newlen
) {
2404 if (newlen
!= sizeof(int))
2406 if (get_user(new, (int __user
*)newval
))
2408 *(int *)(table
->data
) = new*HZ
;
2413 /* Strategy function to convert jiffies to seconds */
2414 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2415 void __user
*oldval
, size_t __user
*oldlenp
,
2416 void __user
*newval
, size_t newlen
)
2418 if (oldval
&& oldlenp
) {
2421 if (get_user(olen
, oldlenp
))
2426 if (olen
< sizeof(int))
2429 val
= jiffies_to_msecs(*(int *)(table
->data
));
2430 if (put_user(val
, (int __user
*)oldval
))
2432 if (put_user(sizeof(int), oldlenp
))
2436 if (newval
&& newlen
) {
2438 if (newlen
!= sizeof(int))
2440 if (get_user(new, (int __user
*)newval
))
2442 *(int *)(table
->data
) = msecs_to_jiffies(new);
2449 #else /* CONFIG_SYSCTL_SYSCALL */
2452 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2454 static int msg_count
;
2455 struct __sysctl_args tmp
;
2456 int name
[CTL_MAXNAME
];
2459 /* Read in the sysctl name for better debug message logging */
2460 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
2462 if (tmp
.nlen
<= 0 || tmp
.nlen
>= CTL_MAXNAME
)
2464 for (i
= 0; i
< tmp
.nlen
; i
++)
2465 if (get_user(name
[i
], tmp
.name
+ i
))
2468 /* Ignore accesses to kernel.version */
2469 if ((tmp
.nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
2472 if (msg_count
< 5) {
2475 "warning: process `%s' used the removed sysctl "
2476 "system call with ", current
->comm
);
2477 for (i
= 0; i
< tmp
.nlen
; i
++)
2478 printk("%d.", name
[i
]);
2485 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2486 void __user
*oldval
, size_t __user
*oldlenp
,
2487 void __user
*newval
, size_t newlen
)
2492 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2493 void __user
*oldval
, size_t __user
*oldlenp
,
2494 void __user
*newval
, size_t newlen
)
2499 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2500 void __user
*oldval
, size_t __user
*oldlenp
,
2501 void __user
*newval
, size_t newlen
)
2506 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2507 void __user
*oldval
, size_t __user
*oldlenp
,
2508 void __user
*newval
, size_t newlen
)
2513 #endif /* CONFIG_SYSCTL_SYSCALL */
2516 * No sense putting this after each symbol definition, twice,
2517 * exception granted :-)
2519 EXPORT_SYMBOL(proc_dointvec
);
2520 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2521 EXPORT_SYMBOL(proc_dointvec_minmax
);
2522 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2523 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2524 EXPORT_SYMBOL(proc_dostring
);
2525 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2526 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2527 EXPORT_SYMBOL(register_sysctl_table
);
2528 EXPORT_SYMBOL(sysctl_intvec
);
2529 EXPORT_SYMBOL(sysctl_jiffies
);
2530 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2531 EXPORT_SYMBOL(sysctl_string
);
2532 EXPORT_SYMBOL(unregister_sysctl_table
);