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/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>
48 #include <linux/reboot.h>
50 #include <asm/uaccess.h>
51 #include <asm/processor.h>
55 #include <asm/stacktrace.h>
58 #if defined(CONFIG_SYSCTL)
60 /* External variables not in a header file. */
62 extern int print_fatal_signals
;
63 extern int sysctl_overcommit_memory
;
64 extern int sysctl_overcommit_ratio
;
65 extern int sysctl_panic_on_oom
;
66 extern int sysctl_oom_kill_allocating_task
;
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
;
81 extern int audit_argv_kb
;
83 /* Constants used for minimum and maximum */
84 #ifdef CONFIG_DETECT_SOFTLOCKUP
86 static int sixty
= 60;
94 static int one_hundred
= 100;
96 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
97 static int maxolduid
= 65535;
99 static int min_percpu_pagelist_fract
= 8;
101 static int ngroups_max
= NGROUPS_MAX
;
104 extern char modprobe_path
[];
106 #ifdef CONFIG_CHR_DEV_SG
107 extern int sg_big_buff
;
111 extern char reboot_command
[];
112 extern int stop_a_enabled
;
113 extern int scons_pwroff
;
117 extern int pwrsw_enabled
;
118 extern int unaligned_enabled
;
122 #ifdef CONFIG_MATHEMU
123 extern int sysctl_ieee_emulation_warnings
;
125 extern int sysctl_userprocess_debug
;
126 extern int spin_retry
;
129 extern int sysctl_hz_timer
;
131 #ifdef CONFIG_BSD_PROCESS_ACCT
132 extern int acct_parm
[];
136 extern int no_unaligned_warning
;
139 #ifdef CONFIG_RT_MUTEXES
140 extern int max_lock_depth
;
143 #ifdef CONFIG_SYSCTL_SYSCALL
144 static int parse_table(int __user
*, int, void __user
*, size_t __user
*,
145 void __user
*, size_t, struct ctl_table
*);
149 #ifdef CONFIG_PROC_SYSCTL
150 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
151 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
152 static int proc_dointvec_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
153 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
156 static struct ctl_table root_table
[];
157 static struct ctl_table_header root_table_header
=
158 { root_table
, LIST_HEAD_INIT(root_table_header
.ctl_entry
) };
160 static struct ctl_table kern_table
[];
161 static struct ctl_table vm_table
[];
162 static struct ctl_table fs_table
[];
163 static struct ctl_table debug_table
[];
164 static struct ctl_table dev_table
[];
165 extern struct ctl_table random_table
[];
166 #ifdef CONFIG_UNIX98_PTYS
167 extern struct ctl_table pty_table
[];
169 #ifdef CONFIG_INOTIFY_USER
170 extern struct ctl_table inotify_table
[];
173 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
174 int sysctl_legacy_va_layout
;
177 extern int prove_locking
;
178 extern int lock_stat
;
180 /* The default sysctl tables: */
182 static struct ctl_table root_table
[] = {
184 .ctl_name
= CTL_KERN
,
185 .procname
= "kernel",
210 .ctl_name
= CTL_DEBUG
,
213 .child
= debug_table
,
222 * NOTE: do not add new entries to this table unless you have read
223 * Documentation/sysctl/ctl_unnumbered.txt
228 #ifdef CONFIG_SCHED_DEBUG
229 static unsigned long min_sched_granularity_ns
= 100000; /* 100 usecs */
230 static unsigned long max_sched_granularity_ns
= 1000000000; /* 1 second */
231 static unsigned long min_wakeup_granularity_ns
; /* 0 usecs */
232 static unsigned long max_wakeup_granularity_ns
= 1000000000; /* 1 second */
235 static struct ctl_table kern_table
[] = {
236 #ifdef CONFIG_SCHED_DEBUG
238 .ctl_name
= CTL_UNNUMBERED
,
239 .procname
= "sched_nr_latency",
240 .data
= &sysctl_sched_nr_latency
,
241 .maxlen
= sizeof(unsigned int),
243 .proc_handler
= &proc_dointvec
,
246 .ctl_name
= CTL_UNNUMBERED
,
247 .procname
= "sched_latency_ns",
248 .data
= &sysctl_sched_latency
,
249 .maxlen
= sizeof(unsigned int),
251 .proc_handler
= &proc_dointvec_minmax
,
252 .strategy
= &sysctl_intvec
,
253 .extra1
= &min_sched_granularity_ns
,
254 .extra2
= &max_sched_granularity_ns
,
257 .ctl_name
= CTL_UNNUMBERED
,
258 .procname
= "sched_wakeup_granularity_ns",
259 .data
= &sysctl_sched_wakeup_granularity
,
260 .maxlen
= sizeof(unsigned int),
262 .proc_handler
= &proc_dointvec_minmax
,
263 .strategy
= &sysctl_intvec
,
264 .extra1
= &min_wakeup_granularity_ns
,
265 .extra2
= &max_wakeup_granularity_ns
,
268 .ctl_name
= CTL_UNNUMBERED
,
269 .procname
= "sched_batch_wakeup_granularity_ns",
270 .data
= &sysctl_sched_batch_wakeup_granularity
,
271 .maxlen
= sizeof(unsigned int),
273 .proc_handler
= &proc_dointvec_minmax
,
274 .strategy
= &sysctl_intvec
,
275 .extra1
= &min_wakeup_granularity_ns
,
276 .extra2
= &max_wakeup_granularity_ns
,
279 .ctl_name
= CTL_UNNUMBERED
,
280 .procname
= "sched_child_runs_first",
281 .data
= &sysctl_sched_child_runs_first
,
282 .maxlen
= sizeof(unsigned int),
284 .proc_handler
= &proc_dointvec
,
287 .ctl_name
= CTL_UNNUMBERED
,
288 .procname
= "sched_features",
289 .data
= &sysctl_sched_features
,
290 .maxlen
= sizeof(unsigned int),
292 .proc_handler
= &proc_dointvec
,
295 .ctl_name
= CTL_UNNUMBERED
,
296 .procname
= "sched_migration_cost",
297 .data
= &sysctl_sched_migration_cost
,
298 .maxlen
= sizeof(unsigned int),
300 .proc_handler
= &proc_dointvec
,
304 .ctl_name
= CTL_UNNUMBERED
,
305 .procname
= "sched_compat_yield",
306 .data
= &sysctl_sched_compat_yield
,
307 .maxlen
= sizeof(unsigned int),
309 .proc_handler
= &proc_dointvec
,
311 #ifdef CONFIG_PROVE_LOCKING
313 .ctl_name
= CTL_UNNUMBERED
,
314 .procname
= "prove_locking",
315 .data
= &prove_locking
,
316 .maxlen
= sizeof(int),
318 .proc_handler
= &proc_dointvec
,
321 #ifdef CONFIG_LOCK_STAT
323 .ctl_name
= CTL_UNNUMBERED
,
324 .procname
= "lock_stat",
326 .maxlen
= sizeof(int),
328 .proc_handler
= &proc_dointvec
,
332 .ctl_name
= KERN_PANIC
,
334 .data
= &panic_timeout
,
335 .maxlen
= sizeof(int),
337 .proc_handler
= &proc_dointvec
,
340 .ctl_name
= KERN_CORE_USES_PID
,
341 .procname
= "core_uses_pid",
342 .data
= &core_uses_pid
,
343 .maxlen
= sizeof(int),
345 .proc_handler
= &proc_dointvec
,
347 #ifdef CONFIG_AUDITSYSCALL
349 .ctl_name
= CTL_UNNUMBERED
,
350 .procname
= "audit_argv_kb",
351 .data
= &audit_argv_kb
,
352 .maxlen
= sizeof(int),
354 .proc_handler
= &proc_dointvec
,
358 .ctl_name
= KERN_CORE_PATTERN
,
359 .procname
= "core_pattern",
360 .data
= core_pattern
,
361 .maxlen
= CORENAME_MAX_SIZE
,
363 .proc_handler
= &proc_dostring
,
364 .strategy
= &sysctl_string
,
366 #ifdef CONFIG_PROC_SYSCTL
368 .ctl_name
= KERN_TAINTED
,
369 .procname
= "tainted",
371 .maxlen
= sizeof(int),
373 .proc_handler
= &proc_dointvec_taint
,
377 .ctl_name
= KERN_CAP_BSET
,
378 .procname
= "cap-bound",
380 .maxlen
= sizeof(kernel_cap_t
),
382 .proc_handler
= &proc_dointvec_bset
,
384 #ifdef CONFIG_BLK_DEV_INITRD
386 .ctl_name
= KERN_REALROOTDEV
,
387 .procname
= "real-root-dev",
388 .data
= &real_root_dev
,
389 .maxlen
= sizeof(int),
391 .proc_handler
= &proc_dointvec
,
395 .ctl_name
= CTL_UNNUMBERED
,
396 .procname
= "print-fatal-signals",
397 .data
= &print_fatal_signals
,
398 .maxlen
= sizeof(int),
400 .proc_handler
= &proc_dointvec
,
404 .ctl_name
= KERN_SPARC_REBOOT
,
405 .procname
= "reboot-cmd",
406 .data
= reboot_command
,
409 .proc_handler
= &proc_dostring
,
410 .strategy
= &sysctl_string
,
413 .ctl_name
= KERN_SPARC_STOP_A
,
414 .procname
= "stop-a",
415 .data
= &stop_a_enabled
,
416 .maxlen
= sizeof (int),
418 .proc_handler
= &proc_dointvec
,
421 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
422 .procname
= "scons-poweroff",
423 .data
= &scons_pwroff
,
424 .maxlen
= sizeof (int),
426 .proc_handler
= &proc_dointvec
,
431 .ctl_name
= KERN_HPPA_PWRSW
,
432 .procname
= "soft-power",
433 .data
= &pwrsw_enabled
,
434 .maxlen
= sizeof (int),
436 .proc_handler
= &proc_dointvec
,
439 .ctl_name
= KERN_HPPA_UNALIGNED
,
440 .procname
= "unaligned-trap",
441 .data
= &unaligned_enabled
,
442 .maxlen
= sizeof (int),
444 .proc_handler
= &proc_dointvec
,
448 .ctl_name
= KERN_CTLALTDEL
,
449 .procname
= "ctrl-alt-del",
451 .maxlen
= sizeof(int),
453 .proc_handler
= &proc_dointvec
,
456 .ctl_name
= KERN_PRINTK
,
457 .procname
= "printk",
458 .data
= &console_loglevel
,
459 .maxlen
= 4*sizeof(int),
461 .proc_handler
= &proc_dointvec
,
465 .ctl_name
= KERN_MODPROBE
,
466 .procname
= "modprobe",
467 .data
= &modprobe_path
,
468 .maxlen
= KMOD_PATH_LEN
,
470 .proc_handler
= &proc_dostring
,
471 .strategy
= &sysctl_string
,
474 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
476 .ctl_name
= KERN_HOTPLUG
,
477 .procname
= "hotplug",
478 .data
= &uevent_helper
,
479 .maxlen
= UEVENT_HELPER_PATH_LEN
,
481 .proc_handler
= &proc_dostring
,
482 .strategy
= &sysctl_string
,
485 #ifdef CONFIG_CHR_DEV_SG
487 .ctl_name
= KERN_SG_BIG_BUFF
,
488 .procname
= "sg-big-buff",
489 .data
= &sg_big_buff
,
490 .maxlen
= sizeof (int),
492 .proc_handler
= &proc_dointvec
,
495 #ifdef CONFIG_BSD_PROCESS_ACCT
497 .ctl_name
= KERN_ACCT
,
500 .maxlen
= 3*sizeof(int),
502 .proc_handler
= &proc_dointvec
,
505 #ifdef CONFIG_MAGIC_SYSRQ
507 .ctl_name
= KERN_SYSRQ
,
509 .data
= &__sysrq_enabled
,
510 .maxlen
= sizeof (int),
512 .proc_handler
= &proc_dointvec
,
515 #ifdef CONFIG_PROC_SYSCTL
517 .ctl_name
= KERN_CADPID
,
518 .procname
= "cad_pid",
520 .maxlen
= sizeof (int),
522 .proc_handler
= &proc_do_cad_pid
,
526 .ctl_name
= KERN_MAX_THREADS
,
527 .procname
= "threads-max",
528 .data
= &max_threads
,
529 .maxlen
= sizeof(int),
531 .proc_handler
= &proc_dointvec
,
534 .ctl_name
= KERN_RANDOM
,
535 .procname
= "random",
537 .child
= random_table
,
539 #ifdef CONFIG_UNIX98_PTYS
541 .ctl_name
= KERN_PTY
,
548 .ctl_name
= KERN_OVERFLOWUID
,
549 .procname
= "overflowuid",
550 .data
= &overflowuid
,
551 .maxlen
= sizeof(int),
553 .proc_handler
= &proc_dointvec_minmax
,
554 .strategy
= &sysctl_intvec
,
555 .extra1
= &minolduid
,
556 .extra2
= &maxolduid
,
559 .ctl_name
= KERN_OVERFLOWGID
,
560 .procname
= "overflowgid",
561 .data
= &overflowgid
,
562 .maxlen
= sizeof(int),
564 .proc_handler
= &proc_dointvec_minmax
,
565 .strategy
= &sysctl_intvec
,
566 .extra1
= &minolduid
,
567 .extra2
= &maxolduid
,
570 #ifdef CONFIG_MATHEMU
572 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
573 .procname
= "ieee_emulation_warnings",
574 .data
= &sysctl_ieee_emulation_warnings
,
575 .maxlen
= sizeof(int),
577 .proc_handler
= &proc_dointvec
,
580 #ifdef CONFIG_NO_IDLE_HZ
582 .ctl_name
= KERN_HZ_TIMER
,
583 .procname
= "hz_timer",
584 .data
= &sysctl_hz_timer
,
585 .maxlen
= sizeof(int),
587 .proc_handler
= &proc_dointvec
,
591 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
592 .procname
= "userprocess_debug",
593 .data
= &sysctl_userprocess_debug
,
594 .maxlen
= sizeof(int),
596 .proc_handler
= &proc_dointvec
,
600 .ctl_name
= KERN_PIDMAX
,
601 .procname
= "pid_max",
603 .maxlen
= sizeof (int),
605 .proc_handler
= &proc_dointvec_minmax
,
606 .strategy
= sysctl_intvec
,
607 .extra1
= &pid_max_min
,
608 .extra2
= &pid_max_max
,
611 .ctl_name
= KERN_PANIC_ON_OOPS
,
612 .procname
= "panic_on_oops",
613 .data
= &panic_on_oops
,
614 .maxlen
= sizeof(int),
616 .proc_handler
= &proc_dointvec
,
619 .ctl_name
= KERN_PRINTK_RATELIMIT
,
620 .procname
= "printk_ratelimit",
621 .data
= &printk_ratelimit_jiffies
,
622 .maxlen
= sizeof(int),
624 .proc_handler
= &proc_dointvec_jiffies
,
625 .strategy
= &sysctl_jiffies
,
628 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
629 .procname
= "printk_ratelimit_burst",
630 .data
= &printk_ratelimit_burst
,
631 .maxlen
= sizeof(int),
633 .proc_handler
= &proc_dointvec
,
636 .ctl_name
= KERN_NGROUPS_MAX
,
637 .procname
= "ngroups_max",
638 .data
= &ngroups_max
,
639 .maxlen
= sizeof (int),
641 .proc_handler
= &proc_dointvec
,
643 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
645 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
646 .procname
= "unknown_nmi_panic",
647 .data
= &unknown_nmi_panic
,
648 .maxlen
= sizeof (int),
650 .proc_handler
= &proc_dointvec
,
653 .ctl_name
= KERN_NMI_WATCHDOG
,
654 .procname
= "nmi_watchdog",
655 .data
= &nmi_watchdog_enabled
,
656 .maxlen
= sizeof (int),
658 .proc_handler
= &proc_nmi_enabled
,
661 #if defined(CONFIG_X86)
663 .ctl_name
= KERN_PANIC_ON_NMI
,
664 .procname
= "panic_on_unrecovered_nmi",
665 .data
= &panic_on_unrecovered_nmi
,
666 .maxlen
= sizeof(int),
668 .proc_handler
= &proc_dointvec
,
671 .ctl_name
= KERN_BOOTLOADER_TYPE
,
672 .procname
= "bootloader_type",
673 .data
= &bootloader_type
,
674 .maxlen
= sizeof (int),
676 .proc_handler
= &proc_dointvec
,
679 .ctl_name
= CTL_UNNUMBERED
,
680 .procname
= "kstack_depth_to_print",
681 .data
= &kstack_depth_to_print
,
682 .maxlen
= sizeof(int),
684 .proc_handler
= &proc_dointvec
,
687 #if defined(CONFIG_MMU)
689 .ctl_name
= KERN_RANDOMIZE
,
690 .procname
= "randomize_va_space",
691 .data
= &randomize_va_space
,
692 .maxlen
= sizeof(int),
694 .proc_handler
= &proc_dointvec
,
697 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
699 .ctl_name
= KERN_SPIN_RETRY
,
700 .procname
= "spin_retry",
702 .maxlen
= sizeof (int),
704 .proc_handler
= &proc_dointvec
,
707 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
709 .ctl_name
= KERN_ACPI_VIDEO_FLAGS
,
710 .procname
= "acpi_video_flags",
711 .data
= &acpi_realmode_flags
,
712 .maxlen
= sizeof (unsigned long),
714 .proc_handler
= &proc_doulongvec_minmax
,
719 .ctl_name
= KERN_IA64_UNALIGNED
,
720 .procname
= "ignore-unaligned-usertrap",
721 .data
= &no_unaligned_warning
,
722 .maxlen
= sizeof (int),
724 .proc_handler
= &proc_dointvec
,
727 #ifdef CONFIG_DETECT_SOFTLOCKUP
729 .ctl_name
= CTL_UNNUMBERED
,
730 .procname
= "softlockup_thresh",
731 .data
= &softlockup_thresh
,
732 .maxlen
= sizeof(int),
734 .proc_handler
= &proc_dointvec_minmax
,
735 .strategy
= &sysctl_intvec
,
742 .ctl_name
= KERN_COMPAT_LOG
,
743 .procname
= "compat-log",
745 .maxlen
= sizeof (int),
747 .proc_handler
= &proc_dointvec
,
750 #ifdef CONFIG_RT_MUTEXES
752 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
753 .procname
= "max_lock_depth",
754 .data
= &max_lock_depth
,
755 .maxlen
= sizeof(int),
757 .proc_handler
= &proc_dointvec
,
760 #ifdef CONFIG_PROC_FS
762 .ctl_name
= CTL_UNNUMBERED
,
763 .procname
= "maps_protect",
764 .data
= &maps_protect
,
765 .maxlen
= sizeof(int),
767 .proc_handler
= &proc_dointvec
,
771 .ctl_name
= CTL_UNNUMBERED
,
772 .procname
= "poweroff_cmd",
773 .data
= &poweroff_cmd
,
774 .maxlen
= POWEROFF_CMD_PATH_LEN
,
776 .proc_handler
= &proc_dostring
,
777 .strategy
= &sysctl_string
,
780 * NOTE: do not add new entries to this table unless you have read
781 * Documentation/sysctl/ctl_unnumbered.txt
786 static struct ctl_table vm_table
[] = {
788 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
789 .procname
= "overcommit_memory",
790 .data
= &sysctl_overcommit_memory
,
791 .maxlen
= sizeof(sysctl_overcommit_memory
),
793 .proc_handler
= &proc_dointvec
,
796 .ctl_name
= VM_PANIC_ON_OOM
,
797 .procname
= "panic_on_oom",
798 .data
= &sysctl_panic_on_oom
,
799 .maxlen
= sizeof(sysctl_panic_on_oom
),
801 .proc_handler
= &proc_dointvec
,
804 .ctl_name
= CTL_UNNUMBERED
,
805 .procname
= "oom_kill_allocating_task",
806 .data
= &sysctl_oom_kill_allocating_task
,
807 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
809 .proc_handler
= &proc_dointvec
,
812 .ctl_name
= VM_OVERCOMMIT_RATIO
,
813 .procname
= "overcommit_ratio",
814 .data
= &sysctl_overcommit_ratio
,
815 .maxlen
= sizeof(sysctl_overcommit_ratio
),
817 .proc_handler
= &proc_dointvec
,
820 .ctl_name
= VM_PAGE_CLUSTER
,
821 .procname
= "page-cluster",
822 .data
= &page_cluster
,
823 .maxlen
= sizeof(int),
825 .proc_handler
= &proc_dointvec
,
828 .ctl_name
= VM_DIRTY_BACKGROUND
,
829 .procname
= "dirty_background_ratio",
830 .data
= &dirty_background_ratio
,
831 .maxlen
= sizeof(dirty_background_ratio
),
833 .proc_handler
= &proc_dointvec_minmax
,
834 .strategy
= &sysctl_intvec
,
836 .extra2
= &one_hundred
,
839 .ctl_name
= VM_DIRTY_RATIO
,
840 .procname
= "dirty_ratio",
841 .data
= &vm_dirty_ratio
,
842 .maxlen
= sizeof(vm_dirty_ratio
),
844 .proc_handler
= &dirty_ratio_handler
,
845 .strategy
= &sysctl_intvec
,
847 .extra2
= &one_hundred
,
850 .ctl_name
= VM_DIRTY_WB_CS
,
851 .procname
= "dirty_writeback_centisecs",
852 .data
= &dirty_writeback_interval
,
853 .maxlen
= sizeof(dirty_writeback_interval
),
855 .proc_handler
= &dirty_writeback_centisecs_handler
,
858 .ctl_name
= VM_DIRTY_EXPIRE_CS
,
859 .procname
= "dirty_expire_centisecs",
860 .data
= &dirty_expire_interval
,
861 .maxlen
= sizeof(dirty_expire_interval
),
863 .proc_handler
= &proc_dointvec_userhz_jiffies
,
866 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
867 .procname
= "nr_pdflush_threads",
868 .data
= &nr_pdflush_threads
,
869 .maxlen
= sizeof nr_pdflush_threads
,
870 .mode
= 0444 /* read-only*/,
871 .proc_handler
= &proc_dointvec
,
874 .ctl_name
= VM_SWAPPINESS
,
875 .procname
= "swappiness",
876 .data
= &vm_swappiness
,
877 .maxlen
= sizeof(vm_swappiness
),
879 .proc_handler
= &proc_dointvec_minmax
,
880 .strategy
= &sysctl_intvec
,
882 .extra2
= &one_hundred
,
884 #ifdef CONFIG_HUGETLB_PAGE
886 .ctl_name
= VM_HUGETLB_PAGES
,
887 .procname
= "nr_hugepages",
888 .data
= &max_huge_pages
,
889 .maxlen
= sizeof(unsigned long),
891 .proc_handler
= &hugetlb_sysctl_handler
,
892 .extra1
= (void *)&hugetlb_zero
,
893 .extra2
= (void *)&hugetlb_infinity
,
896 .ctl_name
= VM_HUGETLB_GROUP
,
897 .procname
= "hugetlb_shm_group",
898 .data
= &sysctl_hugetlb_shm_group
,
899 .maxlen
= sizeof(gid_t
),
901 .proc_handler
= &proc_dointvec
,
904 .ctl_name
= CTL_UNNUMBERED
,
905 .procname
= "hugepages_treat_as_movable",
906 .data
= &hugepages_treat_as_movable
,
907 .maxlen
= sizeof(int),
909 .proc_handler
= &hugetlb_treat_movable_handler
,
912 .ctl_name
= CTL_UNNUMBERED
,
913 .procname
= "hugetlb_dynamic_pool",
914 .data
= &hugetlb_dynamic_pool
,
915 .maxlen
= sizeof(hugetlb_dynamic_pool
),
917 .proc_handler
= &proc_dointvec
,
921 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
922 .procname
= "lowmem_reserve_ratio",
923 .data
= &sysctl_lowmem_reserve_ratio
,
924 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
926 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
927 .strategy
= &sysctl_intvec
,
930 .ctl_name
= VM_DROP_PAGECACHE
,
931 .procname
= "drop_caches",
932 .data
= &sysctl_drop_caches
,
933 .maxlen
= sizeof(int),
935 .proc_handler
= drop_caches_sysctl_handler
,
936 .strategy
= &sysctl_intvec
,
939 .ctl_name
= VM_MIN_FREE_KBYTES
,
940 .procname
= "min_free_kbytes",
941 .data
= &min_free_kbytes
,
942 .maxlen
= sizeof(min_free_kbytes
),
944 .proc_handler
= &min_free_kbytes_sysctl_handler
,
945 .strategy
= &sysctl_intvec
,
949 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
950 .procname
= "percpu_pagelist_fraction",
951 .data
= &percpu_pagelist_fraction
,
952 .maxlen
= sizeof(percpu_pagelist_fraction
),
954 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
955 .strategy
= &sysctl_intvec
,
956 .extra1
= &min_percpu_pagelist_fract
,
960 .ctl_name
= VM_MAX_MAP_COUNT
,
961 .procname
= "max_map_count",
962 .data
= &sysctl_max_map_count
,
963 .maxlen
= sizeof(sysctl_max_map_count
),
965 .proc_handler
= &proc_dointvec
969 .ctl_name
= VM_LAPTOP_MODE
,
970 .procname
= "laptop_mode",
971 .data
= &laptop_mode
,
972 .maxlen
= sizeof(laptop_mode
),
974 .proc_handler
= &proc_dointvec_jiffies
,
975 .strategy
= &sysctl_jiffies
,
978 .ctl_name
= VM_BLOCK_DUMP
,
979 .procname
= "block_dump",
981 .maxlen
= sizeof(block_dump
),
983 .proc_handler
= &proc_dointvec
,
984 .strategy
= &sysctl_intvec
,
988 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
989 .procname
= "vfs_cache_pressure",
990 .data
= &sysctl_vfs_cache_pressure
,
991 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
993 .proc_handler
= &proc_dointvec
,
994 .strategy
= &sysctl_intvec
,
997 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
999 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1000 .procname
= "legacy_va_layout",
1001 .data
= &sysctl_legacy_va_layout
,
1002 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1004 .proc_handler
= &proc_dointvec
,
1005 .strategy
= &sysctl_intvec
,
1011 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1012 .procname
= "zone_reclaim_mode",
1013 .data
= &zone_reclaim_mode
,
1014 .maxlen
= sizeof(zone_reclaim_mode
),
1016 .proc_handler
= &proc_dointvec
,
1017 .strategy
= &sysctl_intvec
,
1021 .ctl_name
= VM_MIN_UNMAPPED
,
1022 .procname
= "min_unmapped_ratio",
1023 .data
= &sysctl_min_unmapped_ratio
,
1024 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1026 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1027 .strategy
= &sysctl_intvec
,
1029 .extra2
= &one_hundred
,
1032 .ctl_name
= VM_MIN_SLAB
,
1033 .procname
= "min_slab_ratio",
1034 .data
= &sysctl_min_slab_ratio
,
1035 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1037 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1038 .strategy
= &sysctl_intvec
,
1040 .extra2
= &one_hundred
,
1045 .ctl_name
= CTL_UNNUMBERED
,
1046 .procname
= "stat_interval",
1047 .data
= &sysctl_stat_interval
,
1048 .maxlen
= sizeof(sysctl_stat_interval
),
1050 .proc_handler
= &proc_dointvec_jiffies
,
1051 .strategy
= &sysctl_jiffies
,
1054 #ifdef CONFIG_SECURITY
1056 .ctl_name
= CTL_UNNUMBERED
,
1057 .procname
= "mmap_min_addr",
1058 .data
= &mmap_min_addr
,
1059 .maxlen
= sizeof(unsigned long),
1061 .proc_handler
= &proc_doulongvec_minmax
,
1066 .ctl_name
= CTL_UNNUMBERED
,
1067 .procname
= "numa_zonelist_order",
1068 .data
= &numa_zonelist_order
,
1069 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1071 .proc_handler
= &numa_zonelist_order_handler
,
1072 .strategy
= &sysctl_string
,
1075 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1076 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1078 .ctl_name
= VM_VDSO_ENABLED
,
1079 .procname
= "vdso_enabled",
1080 .data
= &vdso_enabled
,
1081 .maxlen
= sizeof(vdso_enabled
),
1083 .proc_handler
= &proc_dointvec
,
1084 .strategy
= &sysctl_intvec
,
1089 * NOTE: do not add new entries to this table unless you have read
1090 * Documentation/sysctl/ctl_unnumbered.txt
1095 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1096 static struct ctl_table binfmt_misc_table
[] = {
1101 static struct ctl_table fs_table
[] = {
1103 .ctl_name
= FS_NRINODE
,
1104 .procname
= "inode-nr",
1105 .data
= &inodes_stat
,
1106 .maxlen
= 2*sizeof(int),
1108 .proc_handler
= &proc_dointvec
,
1111 .ctl_name
= FS_STATINODE
,
1112 .procname
= "inode-state",
1113 .data
= &inodes_stat
,
1114 .maxlen
= 7*sizeof(int),
1116 .proc_handler
= &proc_dointvec
,
1119 .ctl_name
= FS_NRFILE
,
1120 .procname
= "file-nr",
1121 .data
= &files_stat
,
1122 .maxlen
= 3*sizeof(int),
1124 .proc_handler
= &proc_nr_files
,
1127 .ctl_name
= FS_MAXFILE
,
1128 .procname
= "file-max",
1129 .data
= &files_stat
.max_files
,
1130 .maxlen
= sizeof(int),
1132 .proc_handler
= &proc_dointvec
,
1135 .ctl_name
= FS_DENTRY
,
1136 .procname
= "dentry-state",
1137 .data
= &dentry_stat
,
1138 .maxlen
= 6*sizeof(int),
1140 .proc_handler
= &proc_dointvec
,
1143 .ctl_name
= FS_OVERFLOWUID
,
1144 .procname
= "overflowuid",
1145 .data
= &fs_overflowuid
,
1146 .maxlen
= sizeof(int),
1148 .proc_handler
= &proc_dointvec_minmax
,
1149 .strategy
= &sysctl_intvec
,
1150 .extra1
= &minolduid
,
1151 .extra2
= &maxolduid
,
1154 .ctl_name
= FS_OVERFLOWGID
,
1155 .procname
= "overflowgid",
1156 .data
= &fs_overflowgid
,
1157 .maxlen
= sizeof(int),
1159 .proc_handler
= &proc_dointvec_minmax
,
1160 .strategy
= &sysctl_intvec
,
1161 .extra1
= &minolduid
,
1162 .extra2
= &maxolduid
,
1165 .ctl_name
= FS_LEASES
,
1166 .procname
= "leases-enable",
1167 .data
= &leases_enable
,
1168 .maxlen
= sizeof(int),
1170 .proc_handler
= &proc_dointvec
,
1172 #ifdef CONFIG_DNOTIFY
1174 .ctl_name
= FS_DIR_NOTIFY
,
1175 .procname
= "dir-notify-enable",
1176 .data
= &dir_notify_enable
,
1177 .maxlen
= sizeof(int),
1179 .proc_handler
= &proc_dointvec
,
1184 .ctl_name
= FS_LEASE_TIME
,
1185 .procname
= "lease-break-time",
1186 .data
= &lease_break_time
,
1187 .maxlen
= sizeof(int),
1189 .proc_handler
= &proc_dointvec_minmax
,
1190 .strategy
= &sysctl_intvec
,
1195 .ctl_name
= FS_AIO_NR
,
1196 .procname
= "aio-nr",
1198 .maxlen
= sizeof(aio_nr
),
1200 .proc_handler
= &proc_doulongvec_minmax
,
1203 .ctl_name
= FS_AIO_MAX_NR
,
1204 .procname
= "aio-max-nr",
1205 .data
= &aio_max_nr
,
1206 .maxlen
= sizeof(aio_max_nr
),
1208 .proc_handler
= &proc_doulongvec_minmax
,
1210 #ifdef CONFIG_INOTIFY_USER
1212 .ctl_name
= FS_INOTIFY
,
1213 .procname
= "inotify",
1215 .child
= inotify_table
,
1220 .ctl_name
= KERN_SETUID_DUMPABLE
,
1221 .procname
= "suid_dumpable",
1222 .data
= &suid_dumpable
,
1223 .maxlen
= sizeof(int),
1225 .proc_handler
= &proc_dointvec
,
1227 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1229 .ctl_name
= CTL_UNNUMBERED
,
1230 .procname
= "binfmt_misc",
1232 .child
= binfmt_misc_table
,
1236 * NOTE: do not add new entries to this table unless you have read
1237 * Documentation/sysctl/ctl_unnumbered.txt
1242 static struct ctl_table debug_table
[] = {
1243 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1245 .ctl_name
= CTL_UNNUMBERED
,
1246 .procname
= "exception-trace",
1247 .data
= &show_unhandled_signals
,
1248 .maxlen
= sizeof(int),
1250 .proc_handler
= proc_dointvec
1256 static struct ctl_table dev_table
[] = {
1260 static DEFINE_SPINLOCK(sysctl_lock
);
1262 /* called under sysctl_lock */
1263 static int use_table(struct ctl_table_header
*p
)
1265 if (unlikely(p
->unregistering
))
1271 /* called under sysctl_lock */
1272 static void unuse_table(struct ctl_table_header
*p
)
1275 if (unlikely(p
->unregistering
))
1276 complete(p
->unregistering
);
1279 /* called under sysctl_lock, will reacquire if has to wait */
1280 static void start_unregistering(struct ctl_table_header
*p
)
1283 * if p->used is 0, nobody will ever touch that entry again;
1284 * we'll eliminate all paths to it before dropping sysctl_lock
1286 if (unlikely(p
->used
)) {
1287 struct completion wait
;
1288 init_completion(&wait
);
1289 p
->unregistering
= &wait
;
1290 spin_unlock(&sysctl_lock
);
1291 wait_for_completion(&wait
);
1292 spin_lock(&sysctl_lock
);
1295 * do not remove from the list until nobody holds it; walking the
1296 * list in do_sysctl() relies on that.
1298 list_del_init(&p
->ctl_entry
);
1301 void sysctl_head_finish(struct ctl_table_header
*head
)
1305 spin_lock(&sysctl_lock
);
1307 spin_unlock(&sysctl_lock
);
1310 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1312 struct ctl_table_header
*head
;
1313 struct list_head
*tmp
;
1314 spin_lock(&sysctl_lock
);
1316 tmp
= &prev
->ctl_entry
;
1320 tmp
= &root_table_header
.ctl_entry
;
1322 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1324 if (!use_table(head
))
1326 spin_unlock(&sysctl_lock
);
1330 if (tmp
== &root_table_header
.ctl_entry
)
1333 spin_unlock(&sysctl_lock
);
1337 #ifdef CONFIG_SYSCTL_SYSCALL
1338 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1339 void __user
*newval
, size_t newlen
)
1341 struct ctl_table_header
*head
;
1342 int error
= -ENOTDIR
;
1344 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1348 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1352 for (head
= sysctl_head_next(NULL
); head
;
1353 head
= sysctl_head_next(head
)) {
1354 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1355 newval
, newlen
, head
->ctl_table
);
1356 if (error
!= -ENOTDIR
) {
1357 sysctl_head_finish(head
);
1364 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1366 struct __sysctl_args tmp
;
1369 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1373 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1374 tmp
.newval
, tmp
.newlen
);
1378 #endif /* CONFIG_SYSCTL_SYSCALL */
1381 * sysctl_perm does NOT grant the superuser all rights automatically, because
1382 * some sysctl variables are readonly even to root.
1385 static int test_perm(int mode
, int op
)
1389 else if (in_egroup_p(0))
1391 if ((mode
& op
& 0007) == op
)
1396 int sysctl_perm(struct ctl_table
*table
, int op
)
1399 error
= security_sysctl(table
, op
);
1402 return test_perm(table
->mode
, op
);
1405 #ifdef CONFIG_SYSCTL_SYSCALL
1406 static int parse_table(int __user
*name
, int nlen
,
1407 void __user
*oldval
, size_t __user
*oldlenp
,
1408 void __user
*newval
, size_t newlen
,
1409 struct ctl_table
*table
)
1415 if (get_user(n
, name
))
1417 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1418 if (!table
->ctl_name
)
1420 if (n
== table
->ctl_name
) {
1423 if (sysctl_perm(table
, 001))
1427 table
= table
->child
;
1430 error
= do_sysctl_strategy(table
, name
, nlen
,
1439 /* Perform the actual read/write of a sysctl table entry. */
1440 int do_sysctl_strategy (struct ctl_table
*table
,
1441 int __user
*name
, int nlen
,
1442 void __user
*oldval
, size_t __user
*oldlenp
,
1443 void __user
*newval
, size_t newlen
)
1451 if (sysctl_perm(table
, op
))
1454 if (table
->strategy
) {
1455 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1463 /* If there is no strategy routine, or if the strategy returns
1464 * zero, proceed with automatic r/w */
1465 if (table
->data
&& table
->maxlen
) {
1466 rc
= sysctl_data(table
, name
, nlen
, oldval
, oldlenp
,
1473 #endif /* CONFIG_SYSCTL_SYSCALL */
1475 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1477 for (; table
->ctl_name
|| table
->procname
; table
++) {
1478 table
->parent
= parent
;
1480 sysctl_set_parent(table
, table
->child
);
1484 static __init
int sysctl_init(void)
1486 sysctl_set_parent(NULL
, root_table
);
1490 core_initcall(sysctl_init
);
1493 * register_sysctl_table - register a sysctl hierarchy
1494 * @table: the top-level table structure
1496 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1497 * array. An entry with a ctl_name of 0 terminates the table.
1499 * The members of the &struct ctl_table structure are used as follows:
1501 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1502 * must be unique within that level of sysctl
1504 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1505 * enter a sysctl file
1507 * data - a pointer to data for use by proc_handler
1509 * maxlen - the maximum size in bytes of the data
1511 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1513 * child - a pointer to the child sysctl table if this entry is a directory, or
1516 * proc_handler - the text handler routine (described below)
1518 * strategy - the strategy routine (described below)
1520 * de - for internal use by the sysctl routines
1522 * extra1, extra2 - extra pointers usable by the proc handler routines
1524 * Leaf nodes in the sysctl tree will be represented by a single file
1525 * under /proc; non-leaf nodes will be represented by directories.
1527 * sysctl(2) can automatically manage read and write requests through
1528 * the sysctl table. The data and maxlen fields of the ctl_table
1529 * struct enable minimal validation of the values being written to be
1530 * performed, and the mode field allows minimal authentication.
1532 * More sophisticated management can be enabled by the provision of a
1533 * strategy routine with the table entry. This will be called before
1534 * any automatic read or write of the data is performed.
1536 * The strategy routine may return
1538 * < 0 - Error occurred (error is passed to user process)
1540 * 0 - OK - proceed with automatic read or write.
1542 * > 0 - OK - read or write has been done by the strategy routine, so
1543 * return immediately.
1545 * There must be a proc_handler routine for any terminal nodes
1546 * mirrored under /proc/sys (non-terminals are handled by a built-in
1547 * directory handler). Several default handlers are available to
1548 * cover common cases -
1550 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1551 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1552 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1554 * It is the handler's job to read the input buffer from user memory
1555 * and process it. The handler should return 0 on success.
1557 * This routine returns %NULL on a failure to register, and a pointer
1558 * to the table header on success.
1560 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1562 struct ctl_table_header
*tmp
;
1563 tmp
= kmalloc(sizeof(struct ctl_table_header
), GFP_KERNEL
);
1566 tmp
->ctl_table
= table
;
1567 INIT_LIST_HEAD(&tmp
->ctl_entry
);
1569 tmp
->unregistering
= NULL
;
1570 sysctl_set_parent(NULL
, table
);
1571 spin_lock(&sysctl_lock
);
1572 list_add_tail(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1573 spin_unlock(&sysctl_lock
);
1578 * unregister_sysctl_table - unregister a sysctl table hierarchy
1579 * @header: the header returned from register_sysctl_table
1581 * Unregisters the sysctl table and all children. proc entries may not
1582 * actually be removed until they are no longer used by anyone.
1584 void unregister_sysctl_table(struct ctl_table_header
* header
)
1587 spin_lock(&sysctl_lock
);
1588 start_unregistering(header
);
1589 spin_unlock(&sysctl_lock
);
1593 #else /* !CONFIG_SYSCTL */
1594 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1599 void unregister_sysctl_table(struct ctl_table_header
* table
)
1603 #endif /* CONFIG_SYSCTL */
1609 #ifdef CONFIG_PROC_SYSCTL
1611 static int _proc_do_string(void* data
, int maxlen
, int write
,
1612 struct file
*filp
, void __user
*buffer
,
1613 size_t *lenp
, loff_t
*ppos
)
1619 if (!data
|| !maxlen
|| !*lenp
) {
1627 while (len
< *lenp
) {
1628 if (get_user(c
, p
++))
1630 if (c
== 0 || c
== '\n')
1636 if(copy_from_user(data
, buffer
, len
))
1638 ((char *) data
)[len
] = 0;
1656 if(copy_to_user(buffer
, data
, len
))
1659 if(put_user('\n', ((char __user
*) buffer
) + len
))
1670 * proc_dostring - read a string sysctl
1671 * @table: the sysctl table
1672 * @write: %TRUE if this is a write to the sysctl file
1673 * @filp: the file structure
1674 * @buffer: the user buffer
1675 * @lenp: the size of the user buffer
1676 * @ppos: file position
1678 * Reads/writes a string from/to the user buffer. If the kernel
1679 * buffer provided is not large enough to hold the string, the
1680 * string is truncated. The copied string is %NULL-terminated.
1681 * If the string is being read by the user process, it is copied
1682 * and a newline '\n' is added. It is truncated if the buffer is
1685 * Returns 0 on success.
1687 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
1688 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1690 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
1691 buffer
, lenp
, ppos
);
1695 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1697 int write
, void *data
)
1700 *valp
= *negp
? -*lvalp
: *lvalp
;
1705 *lvalp
= (unsigned long)-val
;
1708 *lvalp
= (unsigned long)val
;
1714 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1715 int write
, struct file
*filp
, void __user
*buffer
,
1716 size_t *lenp
, loff_t
*ppos
,
1717 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1718 int write
, void *data
),
1721 #define TMPBUFLEN 21
1722 int *i
, vleft
, first
=1, neg
, val
;
1726 char buf
[TMPBUFLEN
], *p
;
1727 char __user
*s
= buffer
;
1729 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
1730 (*ppos
&& !write
)) {
1735 i
= (int *) tbl_data
;
1736 vleft
= table
->maxlen
/ sizeof(*i
);
1740 conv
= do_proc_dointvec_conv
;
1742 for (; left
&& vleft
--; i
++, first
=0) {
1757 if (len
> sizeof(buf
) - 1)
1758 len
= sizeof(buf
) - 1;
1759 if (copy_from_user(buf
, s
, len
))
1763 if (*p
== '-' && left
> 1) {
1767 if (*p
< '0' || *p
> '9')
1770 lval
= simple_strtoul(p
, &p
, 0);
1773 if ((len
< left
) && *p
&& !isspace(*p
))
1780 if (conv(&neg
, &lval
, i
, 1, data
))
1787 if (conv(&neg
, &lval
, i
, 0, data
))
1790 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
1794 if(copy_to_user(s
, buf
, len
))
1801 if (!write
&& !first
&& left
) {
1802 if(put_user('\n', s
))
1809 if (get_user(c
, s
++))
1824 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
1825 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1826 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1827 int write
, void *data
),
1830 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
1831 buffer
, lenp
, ppos
, conv
, data
);
1835 * proc_dointvec - read a vector of integers
1836 * @table: the sysctl table
1837 * @write: %TRUE if this is a write to the sysctl file
1838 * @filp: the file structure
1839 * @buffer: the user buffer
1840 * @lenp: the size of the user buffer
1841 * @ppos: file position
1843 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1844 * values from/to the user buffer, treated as an ASCII string.
1846 * Returns 0 on success.
1848 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
1849 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1851 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1859 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
1861 int write
, void *data
)
1863 int op
= *(int *)data
;
1865 int val
= *negp
? -*lvalp
: *lvalp
;
1867 case OP_SET
: *valp
= val
; break;
1868 case OP_AND
: *valp
&= val
; break;
1869 case OP_OR
: *valp
|= val
; break;
1875 *lvalp
= (unsigned long)-val
;
1878 *lvalp
= (unsigned long)val
;
1885 * init may raise the set.
1888 int proc_dointvec_bset(struct ctl_table
*table
, int write
, struct file
*filp
,
1889 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1893 if (write
&& !capable(CAP_SYS_MODULE
)) {
1897 op
= is_init(current
) ? OP_SET
: OP_AND
;
1898 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1899 do_proc_dointvec_bset_conv
,&op
);
1903 * Taint values can only be increased
1905 static int proc_dointvec_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
1906 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1910 if (write
&& !capable(CAP_SYS_ADMIN
))
1914 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1915 do_proc_dointvec_bset_conv
,&op
);
1918 struct do_proc_dointvec_minmax_conv_param
{
1923 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
1925 int write
, void *data
)
1927 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
1929 int val
= *negp
? -*lvalp
: *lvalp
;
1930 if ((param
->min
&& *param
->min
> val
) ||
1931 (param
->max
&& *param
->max
< val
))
1938 *lvalp
= (unsigned long)-val
;
1941 *lvalp
= (unsigned long)val
;
1948 * proc_dointvec_minmax - read a vector of integers with min/max values
1949 * @table: the sysctl table
1950 * @write: %TRUE if this is a write to the sysctl file
1951 * @filp: the file structure
1952 * @buffer: the user buffer
1953 * @lenp: the size of the user buffer
1954 * @ppos: file position
1956 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1957 * values from/to the user buffer, treated as an ASCII string.
1959 * This routine will ensure the values are within the range specified by
1960 * table->extra1 (min) and table->extra2 (max).
1962 * Returns 0 on success.
1964 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
1965 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1967 struct do_proc_dointvec_minmax_conv_param param
= {
1968 .min
= (int *) table
->extra1
,
1969 .max
= (int *) table
->extra2
,
1971 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
1972 do_proc_dointvec_minmax_conv
, ¶m
);
1975 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
1977 void __user
*buffer
,
1978 size_t *lenp
, loff_t
*ppos
,
1979 unsigned long convmul
,
1980 unsigned long convdiv
)
1982 #define TMPBUFLEN 21
1983 unsigned long *i
, *min
, *max
, val
;
1984 int vleft
, first
=1, neg
;
1986 char buf
[TMPBUFLEN
], *p
;
1987 char __user
*s
= buffer
;
1989 if (!data
|| !table
->maxlen
|| !*lenp
||
1990 (*ppos
&& !write
)) {
1995 i
= (unsigned long *) data
;
1996 min
= (unsigned long *) table
->extra1
;
1997 max
= (unsigned long *) table
->extra2
;
1998 vleft
= table
->maxlen
/ sizeof(unsigned long);
2001 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2016 if (len
> TMPBUFLEN
-1)
2018 if (copy_from_user(buf
, s
, len
))
2022 if (*p
== '-' && left
> 1) {
2026 if (*p
< '0' || *p
> '9')
2028 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2030 if ((len
< left
) && *p
&& !isspace(*p
))
2039 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2046 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2050 if(copy_to_user(s
, buf
, len
))
2057 if (!write
&& !first
&& left
) {
2058 if(put_user('\n', s
))
2065 if (get_user(c
, s
++))
2080 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2082 void __user
*buffer
,
2083 size_t *lenp
, loff_t
*ppos
,
2084 unsigned long convmul
,
2085 unsigned long convdiv
)
2087 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2088 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2092 * proc_doulongvec_minmax - read a vector of long integers with min/max values
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 long) unsigned long
2101 * values from/to the user buffer, treated as an ASCII string.
2103 * This routine will ensure the values are within the range specified by
2104 * table->extra1 (min) and table->extra2 (max).
2106 * Returns 0 on success.
2108 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2109 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2111 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2115 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
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: file position
2123 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2124 * values from/to the user buffer, treated as an ASCII string. The values
2125 * are treated as milliseconds, and converted to jiffies when they are stored.
2127 * This routine will ensure the values are within the range specified by
2128 * table->extra1 (min) and table->extra2 (max).
2130 * Returns 0 on success.
2132 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2134 void __user
*buffer
,
2135 size_t *lenp
, loff_t
*ppos
)
2137 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2138 lenp
, ppos
, HZ
, 1000l);
2142 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2144 int write
, void *data
)
2147 if (*lvalp
> LONG_MAX
/ HZ
)
2149 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2155 lval
= (unsigned long)-val
;
2158 lval
= (unsigned long)val
;
2165 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2167 int write
, void *data
)
2170 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2172 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2178 lval
= (unsigned long)-val
;
2181 lval
= (unsigned long)val
;
2183 *lvalp
= jiffies_to_clock_t(lval
);
2188 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2190 int write
, void *data
)
2193 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2199 lval
= (unsigned long)-val
;
2202 lval
= (unsigned long)val
;
2204 *lvalp
= jiffies_to_msecs(lval
);
2210 * proc_dointvec_jiffies - read a vector of integers as seconds
2211 * @table: the sysctl table
2212 * @write: %TRUE if this is a write to the sysctl file
2213 * @filp: the file structure
2214 * @buffer: the user buffer
2215 * @lenp: the size of the user buffer
2216 * @ppos: file position
2218 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2219 * values from/to the user buffer, treated as an ASCII string.
2220 * The values read are assumed to be in seconds, and are converted into
2223 * Returns 0 on success.
2225 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2226 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2228 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2229 do_proc_dointvec_jiffies_conv
,NULL
);
2233 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2234 * @table: the sysctl table
2235 * @write: %TRUE if this is a write to the sysctl file
2236 * @filp: the file structure
2237 * @buffer: the user buffer
2238 * @lenp: the size of the user buffer
2239 * @ppos: pointer to the file position
2241 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2242 * values from/to the user buffer, treated as an ASCII string.
2243 * The values read are assumed to be in 1/USER_HZ seconds, and
2244 * are converted into jiffies.
2246 * Returns 0 on success.
2248 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2249 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2251 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2252 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2256 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2257 * @table: the sysctl table
2258 * @write: %TRUE if this is a write to the sysctl file
2259 * @filp: the file structure
2260 * @buffer: the user buffer
2261 * @lenp: the size of the user buffer
2262 * @ppos: file position
2263 * @ppos: the current position in the file
2265 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2266 * values from/to the user buffer, treated as an ASCII string.
2267 * The values read are assumed to be in 1/1000 seconds, and
2268 * are converted into jiffies.
2270 * Returns 0 on success.
2272 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2273 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2275 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2276 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2279 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2280 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2282 struct pid
*new_pid
;
2286 tmp
= pid_nr(cad_pid
);
2288 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2289 lenp
, ppos
, NULL
, NULL
);
2293 new_pid
= find_get_pid(tmp
);
2297 put_pid(xchg(&cad_pid
, new_pid
));
2301 #else /* CONFIG_PROC_FS */
2303 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2304 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2309 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2310 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2315 int proc_dointvec_bset(struct ctl_table
*table
, int write
, struct file
*filp
,
2316 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2321 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2322 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2327 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2328 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2333 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2334 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2339 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2340 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2345 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2346 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2351 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2353 void __user
*buffer
,
2354 size_t *lenp
, loff_t
*ppos
)
2360 #endif /* CONFIG_PROC_FS */
2363 #ifdef CONFIG_SYSCTL_SYSCALL
2365 * General sysctl support routines
2368 /* The generic sysctl data routine (used if no strategy routine supplied) */
2369 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2370 void __user
*oldval
, size_t __user
*oldlenp
,
2371 void __user
*newval
, size_t newlen
)
2375 /* Get out of I don't have a variable */
2376 if (!table
->data
|| !table
->maxlen
)
2379 if (oldval
&& oldlenp
) {
2380 if (get_user(len
, oldlenp
))
2383 if (len
> table
->maxlen
)
2384 len
= table
->maxlen
;
2385 if (copy_to_user(oldval
, table
->data
, len
))
2387 if (put_user(len
, oldlenp
))
2392 if (newval
&& newlen
) {
2393 if (newlen
> table
->maxlen
)
2394 newlen
= table
->maxlen
;
2396 if (copy_from_user(table
->data
, newval
, newlen
))
2402 /* The generic string strategy routine: */
2403 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2404 void __user
*oldval
, size_t __user
*oldlenp
,
2405 void __user
*newval
, size_t newlen
)
2407 if (!table
->data
|| !table
->maxlen
)
2410 if (oldval
&& oldlenp
) {
2412 if (get_user(bufsize
, oldlenp
))
2415 size_t len
= strlen(table
->data
), copied
;
2417 /* This shouldn't trigger for a well-formed sysctl */
2418 if (len
> table
->maxlen
)
2419 len
= table
->maxlen
;
2421 /* Copy up to a max of bufsize-1 bytes of the string */
2422 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2424 if (copy_to_user(oldval
, table
->data
, copied
) ||
2425 put_user(0, (char __user
*)(oldval
+ copied
)))
2427 if (put_user(len
, oldlenp
))
2431 if (newval
&& newlen
) {
2432 size_t len
= newlen
;
2433 if (len
> table
->maxlen
)
2434 len
= table
->maxlen
;
2435 if(copy_from_user(table
->data
, newval
, len
))
2437 if (len
== table
->maxlen
)
2439 ((char *) table
->data
)[len
] = 0;
2445 * This function makes sure that all of the integers in the vector
2446 * are between the minimum and maximum values given in the arrays
2447 * table->extra1 and table->extra2, respectively.
2449 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2450 void __user
*oldval
, size_t __user
*oldlenp
,
2451 void __user
*newval
, size_t newlen
)
2454 if (newval
&& newlen
) {
2455 int __user
*vec
= (int __user
*) newval
;
2456 int *min
= (int *) table
->extra1
;
2457 int *max
= (int *) table
->extra2
;
2461 if (newlen
% sizeof(int) != 0)
2464 if (!table
->extra1
&& !table
->extra2
)
2467 if (newlen
> table
->maxlen
)
2468 newlen
= table
->maxlen
;
2469 length
= newlen
/ sizeof(int);
2471 for (i
= 0; i
< length
; i
++) {
2473 if (get_user(value
, vec
+ i
))
2475 if (min
&& value
< min
[i
])
2477 if (max
&& value
> max
[i
])
2484 /* Strategy function to convert jiffies to seconds */
2485 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2486 void __user
*oldval
, size_t __user
*oldlenp
,
2487 void __user
*newval
, size_t newlen
)
2489 if (oldval
&& oldlenp
) {
2492 if (get_user(olen
, oldlenp
))
2497 if (olen
< sizeof(int))
2500 val
= *(int *)(table
->data
) / HZ
;
2501 if (put_user(val
, (int __user
*)oldval
))
2503 if (put_user(sizeof(int), oldlenp
))
2507 if (newval
&& newlen
) {
2509 if (newlen
!= sizeof(int))
2511 if (get_user(new, (int __user
*)newval
))
2513 *(int *)(table
->data
) = new*HZ
;
2518 /* Strategy function to convert jiffies to seconds */
2519 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2520 void __user
*oldval
, size_t __user
*oldlenp
,
2521 void __user
*newval
, size_t newlen
)
2523 if (oldval
&& oldlenp
) {
2526 if (get_user(olen
, oldlenp
))
2531 if (olen
< sizeof(int))
2534 val
= jiffies_to_msecs(*(int *)(table
->data
));
2535 if (put_user(val
, (int __user
*)oldval
))
2537 if (put_user(sizeof(int), oldlenp
))
2541 if (newval
&& newlen
) {
2543 if (newlen
!= sizeof(int))
2545 if (get_user(new, (int __user
*)newval
))
2547 *(int *)(table
->data
) = msecs_to_jiffies(new);
2554 #else /* CONFIG_SYSCTL_SYSCALL */
2557 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2559 static int msg_count
;
2560 struct __sysctl_args tmp
;
2561 int name
[CTL_MAXNAME
];
2564 /* Read in the sysctl name for better debug message logging */
2565 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
2567 if (tmp
.nlen
<= 0 || tmp
.nlen
>= CTL_MAXNAME
)
2569 for (i
= 0; i
< tmp
.nlen
; i
++)
2570 if (get_user(name
[i
], tmp
.name
+ i
))
2573 /* Ignore accesses to kernel.version */
2574 if ((tmp
.nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
2577 if (msg_count
< 5) {
2580 "warning: process `%s' used the removed sysctl "
2581 "system call with ", current
->comm
);
2582 for (i
= 0; i
< tmp
.nlen
; i
++)
2583 printk("%d.", name
[i
]);
2590 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2591 void __user
*oldval
, size_t __user
*oldlenp
,
2592 void __user
*newval
, size_t newlen
)
2597 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2598 void __user
*oldval
, size_t __user
*oldlenp
,
2599 void __user
*newval
, size_t newlen
)
2604 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2605 void __user
*oldval
, size_t __user
*oldlenp
,
2606 void __user
*newval
, size_t newlen
)
2611 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2612 void __user
*oldval
, size_t __user
*oldlenp
,
2613 void __user
*newval
, size_t newlen
)
2618 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2619 void __user
*oldval
, size_t __user
*oldlenp
,
2620 void __user
*newval
, size_t newlen
)
2625 #endif /* CONFIG_SYSCTL_SYSCALL */
2628 * No sense putting this after each symbol definition, twice,
2629 * exception granted :-)
2631 EXPORT_SYMBOL(proc_dointvec
);
2632 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2633 EXPORT_SYMBOL(proc_dointvec_minmax
);
2634 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2635 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2636 EXPORT_SYMBOL(proc_dostring
);
2637 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2638 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2639 EXPORT_SYMBOL(register_sysctl_table
);
2640 EXPORT_SYMBOL(sysctl_intvec
);
2641 EXPORT_SYMBOL(sysctl_jiffies
);
2642 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2643 EXPORT_SYMBOL(sysctl_string
);
2644 EXPORT_SYMBOL(sysctl_data
);
2645 EXPORT_SYMBOL(unregister_sysctl_table
);