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 max_threads
;
67 extern int core_uses_pid
;
68 extern int suid_dumpable
;
69 extern char core_pattern
[];
71 extern int min_free_kbytes
;
72 extern int printk_ratelimit_jiffies
;
73 extern int printk_ratelimit_burst
;
74 extern int pid_max_min
, pid_max_max
;
75 extern int sysctl_drop_caches
;
76 extern int percpu_pagelist_fraction
;
77 extern int compat_log
;
78 extern int maps_protect
;
79 extern int sysctl_stat_interval
;
80 extern int audit_argv_kb
;
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
;
163 extern int prove_locking
;
164 extern int lock_stat
;
166 /* The default sysctl tables: */
168 static ctl_table root_table
[] = {
170 .ctl_name
= CTL_KERN
,
171 .procname
= "kernel",
196 .ctl_name
= CTL_DEBUG
,
199 .child
= debug_table
,
208 * NOTE: do not add new entries to this table unless you have read
209 * Documentation/sysctl/ctl_unnumbered.txt
214 #ifdef CONFIG_SCHED_DEBUG
215 static unsigned long min_sched_granularity_ns
= 100000; /* 100 usecs */
216 static unsigned long max_sched_granularity_ns
= 1000000000; /* 1 second */
217 static unsigned long min_wakeup_granularity_ns
; /* 0 usecs */
218 static unsigned long max_wakeup_granularity_ns
= 1000000000; /* 1 second */
221 static ctl_table kern_table
[] = {
222 #ifdef CONFIG_SCHED_DEBUG
224 .ctl_name
= CTL_UNNUMBERED
,
225 .procname
= "sched_nr_latency",
226 .data
= &sysctl_sched_nr_latency
,
227 .maxlen
= sizeof(unsigned int),
229 .proc_handler
= &proc_dointvec
,
232 .ctl_name
= CTL_UNNUMBERED
,
233 .procname
= "sched_latency_ns",
234 .data
= &sysctl_sched_latency
,
235 .maxlen
= sizeof(unsigned int),
237 .proc_handler
= &proc_dointvec_minmax
,
238 .strategy
= &sysctl_intvec
,
239 .extra1
= &min_sched_granularity_ns
,
240 .extra2
= &max_sched_granularity_ns
,
243 .ctl_name
= CTL_UNNUMBERED
,
244 .procname
= "sched_wakeup_granularity_ns",
245 .data
= &sysctl_sched_wakeup_granularity
,
246 .maxlen
= sizeof(unsigned int),
248 .proc_handler
= &proc_dointvec_minmax
,
249 .strategy
= &sysctl_intvec
,
250 .extra1
= &min_wakeup_granularity_ns
,
251 .extra2
= &max_wakeup_granularity_ns
,
254 .ctl_name
= CTL_UNNUMBERED
,
255 .procname
= "sched_batch_wakeup_granularity_ns",
256 .data
= &sysctl_sched_batch_wakeup_granularity
,
257 .maxlen
= sizeof(unsigned int),
259 .proc_handler
= &proc_dointvec_minmax
,
260 .strategy
= &sysctl_intvec
,
261 .extra1
= &min_wakeup_granularity_ns
,
262 .extra2
= &max_wakeup_granularity_ns
,
265 .ctl_name
= CTL_UNNUMBERED
,
266 .procname
= "sched_child_runs_first",
267 .data
= &sysctl_sched_child_runs_first
,
268 .maxlen
= sizeof(unsigned int),
270 .proc_handler
= &proc_dointvec
,
273 .ctl_name
= CTL_UNNUMBERED
,
274 .procname
= "sched_features",
275 .data
= &sysctl_sched_features
,
276 .maxlen
= sizeof(unsigned int),
278 .proc_handler
= &proc_dointvec
,
282 .ctl_name
= CTL_UNNUMBERED
,
283 .procname
= "sched_compat_yield",
284 .data
= &sysctl_sched_compat_yield
,
285 .maxlen
= sizeof(unsigned int),
287 .proc_handler
= &proc_dointvec
,
289 #ifdef CONFIG_PROVE_LOCKING
291 .ctl_name
= CTL_UNNUMBERED
,
292 .procname
= "prove_locking",
293 .data
= &prove_locking
,
294 .maxlen
= sizeof(int),
296 .proc_handler
= &proc_dointvec
,
299 #ifdef CONFIG_LOCK_STAT
301 .ctl_name
= CTL_UNNUMBERED
,
302 .procname
= "lock_stat",
304 .maxlen
= sizeof(int),
306 .proc_handler
= &proc_dointvec
,
310 .ctl_name
= KERN_PANIC
,
312 .data
= &panic_timeout
,
313 .maxlen
= sizeof(int),
315 .proc_handler
= &proc_dointvec
,
318 .ctl_name
= KERN_CORE_USES_PID
,
319 .procname
= "core_uses_pid",
320 .data
= &core_uses_pid
,
321 .maxlen
= sizeof(int),
323 .proc_handler
= &proc_dointvec
,
325 #ifdef CONFIG_AUDITSYSCALL
327 .ctl_name
= CTL_UNNUMBERED
,
328 .procname
= "audit_argv_kb",
329 .data
= &audit_argv_kb
,
330 .maxlen
= sizeof(int),
332 .proc_handler
= &proc_dointvec
,
336 .ctl_name
= KERN_CORE_PATTERN
,
337 .procname
= "core_pattern",
338 .data
= core_pattern
,
339 .maxlen
= CORENAME_MAX_SIZE
,
341 .proc_handler
= &proc_dostring
,
342 .strategy
= &sysctl_string
,
344 #ifdef CONFIG_PROC_SYSCTL
346 .ctl_name
= KERN_TAINTED
,
347 .procname
= "tainted",
349 .maxlen
= sizeof(int),
351 .proc_handler
= &proc_dointvec_taint
,
355 .ctl_name
= KERN_CAP_BSET
,
356 .procname
= "cap-bound",
358 .maxlen
= sizeof(kernel_cap_t
),
360 .proc_handler
= &proc_dointvec_bset
,
362 #ifdef CONFIG_BLK_DEV_INITRD
364 .ctl_name
= KERN_REALROOTDEV
,
365 .procname
= "real-root-dev",
366 .data
= &real_root_dev
,
367 .maxlen
= sizeof(int),
369 .proc_handler
= &proc_dointvec
,
373 .ctl_name
= CTL_UNNUMBERED
,
374 .procname
= "print-fatal-signals",
375 .data
= &print_fatal_signals
,
376 .maxlen
= sizeof(int),
378 .proc_handler
= &proc_dointvec
,
382 .ctl_name
= KERN_SPARC_REBOOT
,
383 .procname
= "reboot-cmd",
384 .data
= reboot_command
,
387 .proc_handler
= &proc_dostring
,
388 .strategy
= &sysctl_string
,
391 .ctl_name
= KERN_SPARC_STOP_A
,
392 .procname
= "stop-a",
393 .data
= &stop_a_enabled
,
394 .maxlen
= sizeof (int),
396 .proc_handler
= &proc_dointvec
,
399 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
400 .procname
= "scons-poweroff",
401 .data
= &scons_pwroff
,
402 .maxlen
= sizeof (int),
404 .proc_handler
= &proc_dointvec
,
409 .ctl_name
= KERN_HPPA_PWRSW
,
410 .procname
= "soft-power",
411 .data
= &pwrsw_enabled
,
412 .maxlen
= sizeof (int),
414 .proc_handler
= &proc_dointvec
,
417 .ctl_name
= KERN_HPPA_UNALIGNED
,
418 .procname
= "unaligned-trap",
419 .data
= &unaligned_enabled
,
420 .maxlen
= sizeof (int),
422 .proc_handler
= &proc_dointvec
,
426 .ctl_name
= KERN_CTLALTDEL
,
427 .procname
= "ctrl-alt-del",
429 .maxlen
= sizeof(int),
431 .proc_handler
= &proc_dointvec
,
434 .ctl_name
= KERN_PRINTK
,
435 .procname
= "printk",
436 .data
= &console_loglevel
,
437 .maxlen
= 4*sizeof(int),
439 .proc_handler
= &proc_dointvec
,
443 .ctl_name
= KERN_MODPROBE
,
444 .procname
= "modprobe",
445 .data
= &modprobe_path
,
446 .maxlen
= KMOD_PATH_LEN
,
448 .proc_handler
= &proc_dostring
,
449 .strategy
= &sysctl_string
,
452 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
454 .ctl_name
= KERN_HOTPLUG
,
455 .procname
= "hotplug",
456 .data
= &uevent_helper
,
457 .maxlen
= UEVENT_HELPER_PATH_LEN
,
459 .proc_handler
= &proc_dostring
,
460 .strategy
= &sysctl_string
,
463 #ifdef CONFIG_CHR_DEV_SG
465 .ctl_name
= KERN_SG_BIG_BUFF
,
466 .procname
= "sg-big-buff",
467 .data
= &sg_big_buff
,
468 .maxlen
= sizeof (int),
470 .proc_handler
= &proc_dointvec
,
473 #ifdef CONFIG_BSD_PROCESS_ACCT
475 .ctl_name
= KERN_ACCT
,
478 .maxlen
= 3*sizeof(int),
480 .proc_handler
= &proc_dointvec
,
483 #ifdef CONFIG_MAGIC_SYSRQ
485 .ctl_name
= KERN_SYSRQ
,
487 .data
= &__sysrq_enabled
,
488 .maxlen
= sizeof (int),
490 .proc_handler
= &proc_dointvec
,
493 #ifdef CONFIG_PROC_SYSCTL
495 .ctl_name
= KERN_CADPID
,
496 .procname
= "cad_pid",
498 .maxlen
= sizeof (int),
500 .proc_handler
= &proc_do_cad_pid
,
504 .ctl_name
= KERN_MAX_THREADS
,
505 .procname
= "threads-max",
506 .data
= &max_threads
,
507 .maxlen
= sizeof(int),
509 .proc_handler
= &proc_dointvec
,
512 .ctl_name
= KERN_RANDOM
,
513 .procname
= "random",
515 .child
= random_table
,
517 #ifdef CONFIG_UNIX98_PTYS
519 .ctl_name
= KERN_PTY
,
526 .ctl_name
= KERN_OVERFLOWUID
,
527 .procname
= "overflowuid",
528 .data
= &overflowuid
,
529 .maxlen
= sizeof(int),
531 .proc_handler
= &proc_dointvec_minmax
,
532 .strategy
= &sysctl_intvec
,
533 .extra1
= &minolduid
,
534 .extra2
= &maxolduid
,
537 .ctl_name
= KERN_OVERFLOWGID
,
538 .procname
= "overflowgid",
539 .data
= &overflowgid
,
540 .maxlen
= sizeof(int),
542 .proc_handler
= &proc_dointvec_minmax
,
543 .strategy
= &sysctl_intvec
,
544 .extra1
= &minolduid
,
545 .extra2
= &maxolduid
,
548 #ifdef CONFIG_MATHEMU
550 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
551 .procname
= "ieee_emulation_warnings",
552 .data
= &sysctl_ieee_emulation_warnings
,
553 .maxlen
= sizeof(int),
555 .proc_handler
= &proc_dointvec
,
558 #ifdef CONFIG_NO_IDLE_HZ
560 .ctl_name
= KERN_HZ_TIMER
,
561 .procname
= "hz_timer",
562 .data
= &sysctl_hz_timer
,
563 .maxlen
= sizeof(int),
565 .proc_handler
= &proc_dointvec
,
569 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
570 .procname
= "userprocess_debug",
571 .data
= &sysctl_userprocess_debug
,
572 .maxlen
= sizeof(int),
574 .proc_handler
= &proc_dointvec
,
578 .ctl_name
= KERN_PIDMAX
,
579 .procname
= "pid_max",
581 .maxlen
= sizeof (int),
583 .proc_handler
= &proc_dointvec_minmax
,
584 .strategy
= sysctl_intvec
,
585 .extra1
= &pid_max_min
,
586 .extra2
= &pid_max_max
,
589 .ctl_name
= KERN_PANIC_ON_OOPS
,
590 .procname
= "panic_on_oops",
591 .data
= &panic_on_oops
,
592 .maxlen
= sizeof(int),
594 .proc_handler
= &proc_dointvec
,
597 .ctl_name
= KERN_PRINTK_RATELIMIT
,
598 .procname
= "printk_ratelimit",
599 .data
= &printk_ratelimit_jiffies
,
600 .maxlen
= sizeof(int),
602 .proc_handler
= &proc_dointvec_jiffies
,
603 .strategy
= &sysctl_jiffies
,
606 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
607 .procname
= "printk_ratelimit_burst",
608 .data
= &printk_ratelimit_burst
,
609 .maxlen
= sizeof(int),
611 .proc_handler
= &proc_dointvec
,
614 .ctl_name
= KERN_NGROUPS_MAX
,
615 .procname
= "ngroups_max",
616 .data
= &ngroups_max
,
617 .maxlen
= sizeof (int),
619 .proc_handler
= &proc_dointvec
,
621 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
623 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
624 .procname
= "unknown_nmi_panic",
625 .data
= &unknown_nmi_panic
,
626 .maxlen
= sizeof (int),
628 .proc_handler
= &proc_dointvec
,
631 .ctl_name
= KERN_NMI_WATCHDOG
,
632 .procname
= "nmi_watchdog",
633 .data
= &nmi_watchdog_enabled
,
634 .maxlen
= sizeof (int),
636 .proc_handler
= &proc_nmi_enabled
,
639 #if defined(CONFIG_X86)
641 .ctl_name
= KERN_PANIC_ON_NMI
,
642 .procname
= "panic_on_unrecovered_nmi",
643 .data
= &panic_on_unrecovered_nmi
,
644 .maxlen
= sizeof(int),
646 .proc_handler
= &proc_dointvec
,
649 .ctl_name
= KERN_BOOTLOADER_TYPE
,
650 .procname
= "bootloader_type",
651 .data
= &bootloader_type
,
652 .maxlen
= sizeof (int),
654 .proc_handler
= &proc_dointvec
,
657 .ctl_name
= CTL_UNNUMBERED
,
658 .procname
= "kstack_depth_to_print",
659 .data
= &kstack_depth_to_print
,
660 .maxlen
= sizeof(int),
662 .proc_handler
= &proc_dointvec
,
665 #if defined(CONFIG_MMU)
667 .ctl_name
= KERN_RANDOMIZE
,
668 .procname
= "randomize_va_space",
669 .data
= &randomize_va_space
,
670 .maxlen
= sizeof(int),
672 .proc_handler
= &proc_dointvec
,
675 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
677 .ctl_name
= KERN_SPIN_RETRY
,
678 .procname
= "spin_retry",
680 .maxlen
= sizeof (int),
682 .proc_handler
= &proc_dointvec
,
685 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
687 .ctl_name
= KERN_ACPI_VIDEO_FLAGS
,
688 .procname
= "acpi_video_flags",
689 .data
= &acpi_realmode_flags
,
690 .maxlen
= sizeof (unsigned long),
692 .proc_handler
= &proc_doulongvec_minmax
,
697 .ctl_name
= KERN_IA64_UNALIGNED
,
698 .procname
= "ignore-unaligned-usertrap",
699 .data
= &no_unaligned_warning
,
700 .maxlen
= sizeof (int),
702 .proc_handler
= &proc_dointvec
,
707 .ctl_name
= KERN_COMPAT_LOG
,
708 .procname
= "compat-log",
710 .maxlen
= sizeof (int),
712 .proc_handler
= &proc_dointvec
,
715 #ifdef CONFIG_RT_MUTEXES
717 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
718 .procname
= "max_lock_depth",
719 .data
= &max_lock_depth
,
720 .maxlen
= sizeof(int),
722 .proc_handler
= &proc_dointvec
,
725 #ifdef CONFIG_PROC_FS
727 .ctl_name
= CTL_UNNUMBERED
,
728 .procname
= "maps_protect",
729 .data
= &maps_protect
,
730 .maxlen
= sizeof(int),
732 .proc_handler
= &proc_dointvec
,
736 .ctl_name
= CTL_UNNUMBERED
,
737 .procname
= "poweroff_cmd",
738 .data
= &poweroff_cmd
,
739 .maxlen
= POWEROFF_CMD_PATH_LEN
,
741 .proc_handler
= &proc_dostring
,
742 .strategy
= &sysctl_string
,
745 * NOTE: do not add new entries to this table unless you have read
746 * Documentation/sysctl/ctl_unnumbered.txt
751 /* Constants for minimum and maximum testing in vm_table.
752 We use these as one-element integer vectors. */
755 static int one_hundred
= 100;
758 static ctl_table vm_table
[] = {
760 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
761 .procname
= "overcommit_memory",
762 .data
= &sysctl_overcommit_memory
,
763 .maxlen
= sizeof(sysctl_overcommit_memory
),
765 .proc_handler
= &proc_dointvec
,
768 .ctl_name
= VM_PANIC_ON_OOM
,
769 .procname
= "panic_on_oom",
770 .data
= &sysctl_panic_on_oom
,
771 .maxlen
= sizeof(sysctl_panic_on_oom
),
773 .proc_handler
= &proc_dointvec
,
776 .ctl_name
= VM_OVERCOMMIT_RATIO
,
777 .procname
= "overcommit_ratio",
778 .data
= &sysctl_overcommit_ratio
,
779 .maxlen
= sizeof(sysctl_overcommit_ratio
),
781 .proc_handler
= &proc_dointvec
,
784 .ctl_name
= VM_PAGE_CLUSTER
,
785 .procname
= "page-cluster",
786 .data
= &page_cluster
,
787 .maxlen
= sizeof(int),
789 .proc_handler
= &proc_dointvec
,
792 .ctl_name
= VM_DIRTY_BACKGROUND
,
793 .procname
= "dirty_background_ratio",
794 .data
= &dirty_background_ratio
,
795 .maxlen
= sizeof(dirty_background_ratio
),
797 .proc_handler
= &proc_dointvec_minmax
,
798 .strategy
= &sysctl_intvec
,
800 .extra2
= &one_hundred
,
803 .ctl_name
= VM_DIRTY_RATIO
,
804 .procname
= "dirty_ratio",
805 .data
= &vm_dirty_ratio
,
806 .maxlen
= sizeof(vm_dirty_ratio
),
808 .proc_handler
= &proc_dointvec_minmax
,
809 .strategy
= &sysctl_intvec
,
811 .extra2
= &one_hundred
,
814 .ctl_name
= VM_DIRTY_WB_CS
,
815 .procname
= "dirty_writeback_centisecs",
816 .data
= &dirty_writeback_interval
,
817 .maxlen
= sizeof(dirty_writeback_interval
),
819 .proc_handler
= &dirty_writeback_centisecs_handler
,
822 .ctl_name
= VM_DIRTY_EXPIRE_CS
,
823 .procname
= "dirty_expire_centisecs",
824 .data
= &dirty_expire_interval
,
825 .maxlen
= sizeof(dirty_expire_interval
),
827 .proc_handler
= &proc_dointvec_userhz_jiffies
,
830 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
831 .procname
= "nr_pdflush_threads",
832 .data
= &nr_pdflush_threads
,
833 .maxlen
= sizeof nr_pdflush_threads
,
834 .mode
= 0444 /* read-only*/,
835 .proc_handler
= &proc_dointvec
,
838 .ctl_name
= VM_SWAPPINESS
,
839 .procname
= "swappiness",
840 .data
= &vm_swappiness
,
841 .maxlen
= sizeof(vm_swappiness
),
843 .proc_handler
= &proc_dointvec_minmax
,
844 .strategy
= &sysctl_intvec
,
846 .extra2
= &one_hundred
,
848 #ifdef CONFIG_HUGETLB_PAGE
850 .ctl_name
= VM_HUGETLB_PAGES
,
851 .procname
= "nr_hugepages",
852 .data
= &max_huge_pages
,
853 .maxlen
= sizeof(unsigned long),
855 .proc_handler
= &hugetlb_sysctl_handler
,
856 .extra1
= (void *)&hugetlb_zero
,
857 .extra2
= (void *)&hugetlb_infinity
,
860 .ctl_name
= VM_HUGETLB_GROUP
,
861 .procname
= "hugetlb_shm_group",
862 .data
= &sysctl_hugetlb_shm_group
,
863 .maxlen
= sizeof(gid_t
),
865 .proc_handler
= &proc_dointvec
,
868 .ctl_name
= CTL_UNNUMBERED
,
869 .procname
= "hugepages_treat_as_movable",
870 .data
= &hugepages_treat_as_movable
,
871 .maxlen
= sizeof(int),
873 .proc_handler
= &hugetlb_treat_movable_handler
,
877 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
878 .procname
= "lowmem_reserve_ratio",
879 .data
= &sysctl_lowmem_reserve_ratio
,
880 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
882 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
883 .strategy
= &sysctl_intvec
,
886 .ctl_name
= VM_DROP_PAGECACHE
,
887 .procname
= "drop_caches",
888 .data
= &sysctl_drop_caches
,
889 .maxlen
= sizeof(int),
891 .proc_handler
= drop_caches_sysctl_handler
,
892 .strategy
= &sysctl_intvec
,
895 .ctl_name
= VM_MIN_FREE_KBYTES
,
896 .procname
= "min_free_kbytes",
897 .data
= &min_free_kbytes
,
898 .maxlen
= sizeof(min_free_kbytes
),
900 .proc_handler
= &min_free_kbytes_sysctl_handler
,
901 .strategy
= &sysctl_intvec
,
905 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
906 .procname
= "percpu_pagelist_fraction",
907 .data
= &percpu_pagelist_fraction
,
908 .maxlen
= sizeof(percpu_pagelist_fraction
),
910 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
911 .strategy
= &sysctl_intvec
,
912 .extra1
= &min_percpu_pagelist_fract
,
916 .ctl_name
= VM_MAX_MAP_COUNT
,
917 .procname
= "max_map_count",
918 .data
= &sysctl_max_map_count
,
919 .maxlen
= sizeof(sysctl_max_map_count
),
921 .proc_handler
= &proc_dointvec
925 .ctl_name
= VM_LAPTOP_MODE
,
926 .procname
= "laptop_mode",
927 .data
= &laptop_mode
,
928 .maxlen
= sizeof(laptop_mode
),
930 .proc_handler
= &proc_dointvec_jiffies
,
931 .strategy
= &sysctl_jiffies
,
934 .ctl_name
= VM_BLOCK_DUMP
,
935 .procname
= "block_dump",
937 .maxlen
= sizeof(block_dump
),
939 .proc_handler
= &proc_dointvec
,
940 .strategy
= &sysctl_intvec
,
944 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
945 .procname
= "vfs_cache_pressure",
946 .data
= &sysctl_vfs_cache_pressure
,
947 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
949 .proc_handler
= &proc_dointvec
,
950 .strategy
= &sysctl_intvec
,
953 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
955 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
956 .procname
= "legacy_va_layout",
957 .data
= &sysctl_legacy_va_layout
,
958 .maxlen
= sizeof(sysctl_legacy_va_layout
),
960 .proc_handler
= &proc_dointvec
,
961 .strategy
= &sysctl_intvec
,
967 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
968 .procname
= "zone_reclaim_mode",
969 .data
= &zone_reclaim_mode
,
970 .maxlen
= sizeof(zone_reclaim_mode
),
972 .proc_handler
= &proc_dointvec
,
973 .strategy
= &sysctl_intvec
,
977 .ctl_name
= VM_MIN_UNMAPPED
,
978 .procname
= "min_unmapped_ratio",
979 .data
= &sysctl_min_unmapped_ratio
,
980 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
982 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
983 .strategy
= &sysctl_intvec
,
985 .extra2
= &one_hundred
,
988 .ctl_name
= VM_MIN_SLAB
,
989 .procname
= "min_slab_ratio",
990 .data
= &sysctl_min_slab_ratio
,
991 .maxlen
= sizeof(sysctl_min_slab_ratio
),
993 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
994 .strategy
= &sysctl_intvec
,
996 .extra2
= &one_hundred
,
1001 .ctl_name
= CTL_UNNUMBERED
,
1002 .procname
= "stat_interval",
1003 .data
= &sysctl_stat_interval
,
1004 .maxlen
= sizeof(sysctl_stat_interval
),
1006 .proc_handler
= &proc_dointvec_jiffies
,
1007 .strategy
= &sysctl_jiffies
,
1010 #ifdef CONFIG_SECURITY
1012 .ctl_name
= CTL_UNNUMBERED
,
1013 .procname
= "mmap_min_addr",
1014 .data
= &mmap_min_addr
,
1015 .maxlen
= sizeof(unsigned long),
1017 .proc_handler
= &proc_doulongvec_minmax
,
1022 .ctl_name
= CTL_UNNUMBERED
,
1023 .procname
= "numa_zonelist_order",
1024 .data
= &numa_zonelist_order
,
1025 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1027 .proc_handler
= &numa_zonelist_order_handler
,
1028 .strategy
= &sysctl_string
,
1031 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1032 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1034 .ctl_name
= VM_VDSO_ENABLED
,
1035 .procname
= "vdso_enabled",
1036 .data
= &vdso_enabled
,
1037 .maxlen
= sizeof(vdso_enabled
),
1039 .proc_handler
= &proc_dointvec
,
1040 .strategy
= &sysctl_intvec
,
1045 * NOTE: do not add new entries to this table unless you have read
1046 * Documentation/sysctl/ctl_unnumbered.txt
1051 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1052 static ctl_table binfmt_misc_table
[] = {
1057 static ctl_table fs_table
[] = {
1059 .ctl_name
= FS_NRINODE
,
1060 .procname
= "inode-nr",
1061 .data
= &inodes_stat
,
1062 .maxlen
= 2*sizeof(int),
1064 .proc_handler
= &proc_dointvec
,
1067 .ctl_name
= FS_STATINODE
,
1068 .procname
= "inode-state",
1069 .data
= &inodes_stat
,
1070 .maxlen
= 7*sizeof(int),
1072 .proc_handler
= &proc_dointvec
,
1075 .ctl_name
= FS_NRFILE
,
1076 .procname
= "file-nr",
1077 .data
= &files_stat
,
1078 .maxlen
= 3*sizeof(int),
1080 .proc_handler
= &proc_nr_files
,
1083 .ctl_name
= FS_MAXFILE
,
1084 .procname
= "file-max",
1085 .data
= &files_stat
.max_files
,
1086 .maxlen
= sizeof(int),
1088 .proc_handler
= &proc_dointvec
,
1091 .ctl_name
= FS_DENTRY
,
1092 .procname
= "dentry-state",
1093 .data
= &dentry_stat
,
1094 .maxlen
= 6*sizeof(int),
1096 .proc_handler
= &proc_dointvec
,
1099 .ctl_name
= FS_OVERFLOWUID
,
1100 .procname
= "overflowuid",
1101 .data
= &fs_overflowuid
,
1102 .maxlen
= sizeof(int),
1104 .proc_handler
= &proc_dointvec_minmax
,
1105 .strategy
= &sysctl_intvec
,
1106 .extra1
= &minolduid
,
1107 .extra2
= &maxolduid
,
1110 .ctl_name
= FS_OVERFLOWGID
,
1111 .procname
= "overflowgid",
1112 .data
= &fs_overflowgid
,
1113 .maxlen
= sizeof(int),
1115 .proc_handler
= &proc_dointvec_minmax
,
1116 .strategy
= &sysctl_intvec
,
1117 .extra1
= &minolduid
,
1118 .extra2
= &maxolduid
,
1121 .ctl_name
= FS_LEASES
,
1122 .procname
= "leases-enable",
1123 .data
= &leases_enable
,
1124 .maxlen
= sizeof(int),
1126 .proc_handler
= &proc_dointvec
,
1128 #ifdef CONFIG_DNOTIFY
1130 .ctl_name
= FS_DIR_NOTIFY
,
1131 .procname
= "dir-notify-enable",
1132 .data
= &dir_notify_enable
,
1133 .maxlen
= sizeof(int),
1135 .proc_handler
= &proc_dointvec
,
1140 .ctl_name
= FS_LEASE_TIME
,
1141 .procname
= "lease-break-time",
1142 .data
= &lease_break_time
,
1143 .maxlen
= sizeof(int),
1145 .proc_handler
= &proc_dointvec_minmax
,
1146 .strategy
= &sysctl_intvec
,
1151 .ctl_name
= FS_AIO_NR
,
1152 .procname
= "aio-nr",
1154 .maxlen
= sizeof(aio_nr
),
1156 .proc_handler
= &proc_doulongvec_minmax
,
1159 .ctl_name
= FS_AIO_MAX_NR
,
1160 .procname
= "aio-max-nr",
1161 .data
= &aio_max_nr
,
1162 .maxlen
= sizeof(aio_max_nr
),
1164 .proc_handler
= &proc_doulongvec_minmax
,
1166 #ifdef CONFIG_INOTIFY_USER
1168 .ctl_name
= FS_INOTIFY
,
1169 .procname
= "inotify",
1171 .child
= inotify_table
,
1176 .ctl_name
= KERN_SETUID_DUMPABLE
,
1177 .procname
= "suid_dumpable",
1178 .data
= &suid_dumpable
,
1179 .maxlen
= sizeof(int),
1181 .proc_handler
= &proc_dointvec
,
1183 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1185 .ctl_name
= CTL_UNNUMBERED
,
1186 .procname
= "binfmt_misc",
1188 .child
= binfmt_misc_table
,
1192 * NOTE: do not add new entries to this table unless you have read
1193 * Documentation/sysctl/ctl_unnumbered.txt
1198 static ctl_table debug_table
[] = {
1199 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1201 .ctl_name
= CTL_UNNUMBERED
,
1202 .procname
= "exception-trace",
1203 .data
= &show_unhandled_signals
,
1204 .maxlen
= sizeof(int),
1206 .proc_handler
= proc_dointvec
1212 static ctl_table dev_table
[] = {
1216 static DEFINE_SPINLOCK(sysctl_lock
);
1218 /* called under sysctl_lock */
1219 static int use_table(struct ctl_table_header
*p
)
1221 if (unlikely(p
->unregistering
))
1227 /* called under sysctl_lock */
1228 static void unuse_table(struct ctl_table_header
*p
)
1231 if (unlikely(p
->unregistering
))
1232 complete(p
->unregistering
);
1235 /* called under sysctl_lock, will reacquire if has to wait */
1236 static void start_unregistering(struct ctl_table_header
*p
)
1239 * if p->used is 0, nobody will ever touch that entry again;
1240 * we'll eliminate all paths to it before dropping sysctl_lock
1242 if (unlikely(p
->used
)) {
1243 struct completion wait
;
1244 init_completion(&wait
);
1245 p
->unregistering
= &wait
;
1246 spin_unlock(&sysctl_lock
);
1247 wait_for_completion(&wait
);
1248 spin_lock(&sysctl_lock
);
1251 * do not remove from the list until nobody holds it; walking the
1252 * list in do_sysctl() relies on that.
1254 list_del_init(&p
->ctl_entry
);
1257 void sysctl_head_finish(struct ctl_table_header
*head
)
1261 spin_lock(&sysctl_lock
);
1263 spin_unlock(&sysctl_lock
);
1266 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1268 struct ctl_table_header
*head
;
1269 struct list_head
*tmp
;
1270 spin_lock(&sysctl_lock
);
1272 tmp
= &prev
->ctl_entry
;
1276 tmp
= &root_table_header
.ctl_entry
;
1278 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1280 if (!use_table(head
))
1282 spin_unlock(&sysctl_lock
);
1286 if (tmp
== &root_table_header
.ctl_entry
)
1289 spin_unlock(&sysctl_lock
);
1293 #ifdef CONFIG_SYSCTL_SYSCALL
1294 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1295 void __user
*newval
, size_t newlen
)
1297 struct ctl_table_header
*head
;
1298 int error
= -ENOTDIR
;
1300 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1304 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1308 for (head
= sysctl_head_next(NULL
); head
;
1309 head
= sysctl_head_next(head
)) {
1310 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1311 newval
, newlen
, head
->ctl_table
);
1312 if (error
!= -ENOTDIR
) {
1313 sysctl_head_finish(head
);
1320 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1322 struct __sysctl_args tmp
;
1325 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1329 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1330 tmp
.newval
, tmp
.newlen
);
1334 #endif /* CONFIG_SYSCTL_SYSCALL */
1337 * sysctl_perm does NOT grant the superuser all rights automatically, because
1338 * some sysctl variables are readonly even to root.
1341 static int test_perm(int mode
, int op
)
1345 else if (in_egroup_p(0))
1347 if ((mode
& op
& 0007) == op
)
1352 int sysctl_perm(ctl_table
*table
, int op
)
1355 error
= security_sysctl(table
, op
);
1358 return test_perm(table
->mode
, op
);
1361 #ifdef CONFIG_SYSCTL_SYSCALL
1362 static int parse_table(int __user
*name
, int nlen
,
1363 void __user
*oldval
, size_t __user
*oldlenp
,
1364 void __user
*newval
, size_t newlen
,
1371 if (get_user(n
, name
))
1373 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1374 if (!table
->ctl_name
)
1376 if (n
== table
->ctl_name
) {
1379 if (sysctl_perm(table
, 001))
1383 table
= table
->child
;
1386 error
= do_sysctl_strategy(table
, name
, nlen
,
1395 /* Perform the actual read/write of a sysctl table entry. */
1396 int do_sysctl_strategy (ctl_table
*table
,
1397 int __user
*name
, int nlen
,
1398 void __user
*oldval
, size_t __user
*oldlenp
,
1399 void __user
*newval
, size_t newlen
)
1408 if (sysctl_perm(table
, op
))
1411 if (table
->strategy
) {
1412 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1420 /* If there is no strategy routine, or if the strategy returns
1421 * zero, proceed with automatic r/w */
1422 if (table
->data
&& table
->maxlen
) {
1423 if (oldval
&& oldlenp
) {
1424 if (get_user(len
, oldlenp
))
1427 if (len
> table
->maxlen
)
1428 len
= table
->maxlen
;
1429 if(copy_to_user(oldval
, table
->data
, len
))
1431 if(put_user(len
, oldlenp
))
1435 if (newval
&& newlen
) {
1437 if (len
> table
->maxlen
)
1438 len
= table
->maxlen
;
1439 if(copy_from_user(table
->data
, newval
, len
))
1445 #endif /* CONFIG_SYSCTL_SYSCALL */
1447 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1449 for (; table
->ctl_name
|| table
->procname
; table
++) {
1450 table
->parent
= parent
;
1452 sysctl_set_parent(table
, table
->child
);
1456 static __init
int sysctl_init(void)
1458 sysctl_set_parent(NULL
, root_table
);
1462 core_initcall(sysctl_init
);
1465 * register_sysctl_table - register a sysctl hierarchy
1466 * @table: the top-level table structure
1468 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1469 * array. An entry with a ctl_name of 0 terminates the table.
1471 * The members of the &ctl_table structure are used as follows:
1473 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1474 * must be unique within that level of sysctl
1476 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1477 * enter a sysctl file
1479 * data - a pointer to data for use by proc_handler
1481 * maxlen - the maximum size in bytes of the data
1483 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1485 * child - a pointer to the child sysctl table if this entry is a directory, or
1488 * proc_handler - the text handler routine (described below)
1490 * strategy - the strategy routine (described below)
1492 * de - for internal use by the sysctl routines
1494 * extra1, extra2 - extra pointers usable by the proc handler routines
1496 * Leaf nodes in the sysctl tree will be represented by a single file
1497 * under /proc; non-leaf nodes will be represented by directories.
1499 * sysctl(2) can automatically manage read and write requests through
1500 * the sysctl table. The data and maxlen fields of the ctl_table
1501 * struct enable minimal validation of the values being written to be
1502 * performed, and the mode field allows minimal authentication.
1504 * More sophisticated management can be enabled by the provision of a
1505 * strategy routine with the table entry. This will be called before
1506 * any automatic read or write of the data is performed.
1508 * The strategy routine may return
1510 * < 0 - Error occurred (error is passed to user process)
1512 * 0 - OK - proceed with automatic read or write.
1514 * > 0 - OK - read or write has been done by the strategy routine, so
1515 * return immediately.
1517 * There must be a proc_handler routine for any terminal nodes
1518 * mirrored under /proc/sys (non-terminals are handled by a built-in
1519 * directory handler). Several default handlers are available to
1520 * cover common cases -
1522 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1523 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1524 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1526 * It is the handler's job to read the input buffer from user memory
1527 * and process it. The handler should return 0 on success.
1529 * This routine returns %NULL on a failure to register, and a pointer
1530 * to the table header on success.
1532 struct ctl_table_header
*register_sysctl_table(ctl_table
* table
)
1534 struct ctl_table_header
*tmp
;
1535 tmp
= kmalloc(sizeof(struct ctl_table_header
), GFP_KERNEL
);
1538 tmp
->ctl_table
= table
;
1539 INIT_LIST_HEAD(&tmp
->ctl_entry
);
1541 tmp
->unregistering
= NULL
;
1542 sysctl_set_parent(NULL
, table
);
1543 spin_lock(&sysctl_lock
);
1544 list_add_tail(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1545 spin_unlock(&sysctl_lock
);
1550 * unregister_sysctl_table - unregister a sysctl table hierarchy
1551 * @header: the header returned from register_sysctl_table
1553 * Unregisters the sysctl table and all children. proc entries may not
1554 * actually be removed until they are no longer used by anyone.
1556 void unregister_sysctl_table(struct ctl_table_header
* header
)
1559 spin_lock(&sysctl_lock
);
1560 start_unregistering(header
);
1561 spin_unlock(&sysctl_lock
);
1565 #else /* !CONFIG_SYSCTL */
1566 struct ctl_table_header
*register_sysctl_table(ctl_table
* table
)
1571 void unregister_sysctl_table(struct ctl_table_header
* table
)
1575 #endif /* CONFIG_SYSCTL */
1581 #ifdef CONFIG_PROC_SYSCTL
1583 static int _proc_do_string(void* data
, int maxlen
, int write
,
1584 struct file
*filp
, void __user
*buffer
,
1585 size_t *lenp
, loff_t
*ppos
)
1591 if (!data
|| !maxlen
|| !*lenp
) {
1599 while (len
< *lenp
) {
1600 if (get_user(c
, p
++))
1602 if (c
== 0 || c
== '\n')
1608 if(copy_from_user(data
, buffer
, len
))
1610 ((char *) data
)[len
] = 0;
1628 if(copy_to_user(buffer
, data
, len
))
1631 if(put_user('\n', ((char __user
*) buffer
) + len
))
1642 * proc_dostring - read a string sysctl
1643 * @table: the sysctl table
1644 * @write: %TRUE if this is a write to the sysctl file
1645 * @filp: the file structure
1646 * @buffer: the user buffer
1647 * @lenp: the size of the user buffer
1648 * @ppos: file position
1650 * Reads/writes a string from/to the user buffer. If the kernel
1651 * buffer provided is not large enough to hold the string, the
1652 * string is truncated. The copied string is %NULL-terminated.
1653 * If the string is being read by the user process, it is copied
1654 * and a newline '\n' is added. It is truncated if the buffer is
1657 * Returns 0 on success.
1659 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1660 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1662 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
1663 buffer
, lenp
, ppos
);
1667 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1669 int write
, void *data
)
1672 *valp
= *negp
? -*lvalp
: *lvalp
;
1677 *lvalp
= (unsigned long)-val
;
1680 *lvalp
= (unsigned long)val
;
1686 static int __do_proc_dointvec(void *tbl_data
, ctl_table
*table
,
1687 int write
, struct file
*filp
, void __user
*buffer
,
1688 size_t *lenp
, loff_t
*ppos
,
1689 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1690 int write
, void *data
),
1693 #define TMPBUFLEN 21
1694 int *i
, vleft
, first
=1, neg
, val
;
1698 char buf
[TMPBUFLEN
], *p
;
1699 char __user
*s
= buffer
;
1701 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
1702 (*ppos
&& !write
)) {
1707 i
= (int *) tbl_data
;
1708 vleft
= table
->maxlen
/ sizeof(*i
);
1712 conv
= do_proc_dointvec_conv
;
1714 for (; left
&& vleft
--; i
++, first
=0) {
1729 if (len
> sizeof(buf
) - 1)
1730 len
= sizeof(buf
) - 1;
1731 if (copy_from_user(buf
, s
, len
))
1735 if (*p
== '-' && left
> 1) {
1739 if (*p
< '0' || *p
> '9')
1742 lval
= simple_strtoul(p
, &p
, 0);
1745 if ((len
< left
) && *p
&& !isspace(*p
))
1752 if (conv(&neg
, &lval
, i
, 1, data
))
1759 if (conv(&neg
, &lval
, i
, 0, data
))
1762 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
1766 if(copy_to_user(s
, buf
, len
))
1773 if (!write
&& !first
&& left
) {
1774 if(put_user('\n', s
))
1781 if (get_user(c
, s
++))
1796 static int do_proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1797 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1798 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1799 int write
, void *data
),
1802 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
1803 buffer
, lenp
, ppos
, conv
, data
);
1807 * proc_dointvec - read a vector of integers
1808 * @table: the sysctl table
1809 * @write: %TRUE if this is a write to the sysctl file
1810 * @filp: the file structure
1811 * @buffer: the user buffer
1812 * @lenp: the size of the user buffer
1813 * @ppos: file position
1815 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1816 * values from/to the user buffer, treated as an ASCII string.
1818 * Returns 0 on success.
1820 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1821 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1823 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1831 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
1833 int write
, void *data
)
1835 int op
= *(int *)data
;
1837 int val
= *negp
? -*lvalp
: *lvalp
;
1839 case OP_SET
: *valp
= val
; break;
1840 case OP_AND
: *valp
&= val
; break;
1841 case OP_OR
: *valp
|= val
; break;
1847 *lvalp
= (unsigned long)-val
;
1850 *lvalp
= (unsigned long)val
;
1857 * init may raise the set.
1860 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1861 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1865 if (write
&& !capable(CAP_SYS_MODULE
)) {
1869 op
= is_init(current
) ? OP_SET
: OP_AND
;
1870 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1871 do_proc_dointvec_bset_conv
,&op
);
1875 * Taint values can only be increased
1877 static int proc_dointvec_taint(ctl_table
*table
, int write
, struct file
*filp
,
1878 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1882 if (write
&& !capable(CAP_SYS_ADMIN
))
1886 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1887 do_proc_dointvec_bset_conv
,&op
);
1890 struct do_proc_dointvec_minmax_conv_param
{
1895 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
1897 int write
, void *data
)
1899 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
1901 int val
= *negp
? -*lvalp
: *lvalp
;
1902 if ((param
->min
&& *param
->min
> val
) ||
1903 (param
->max
&& *param
->max
< val
))
1910 *lvalp
= (unsigned long)-val
;
1913 *lvalp
= (unsigned long)val
;
1920 * proc_dointvec_minmax - read a vector of integers with min/max values
1921 * @table: the sysctl table
1922 * @write: %TRUE if this is a write to the sysctl file
1923 * @filp: the file structure
1924 * @buffer: the user buffer
1925 * @lenp: the size of the user buffer
1926 * @ppos: file position
1928 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1929 * values from/to the user buffer, treated as an ASCII string.
1931 * This routine will ensure the values are within the range specified by
1932 * table->extra1 (min) and table->extra2 (max).
1934 * Returns 0 on success.
1936 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1937 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1939 struct do_proc_dointvec_minmax_conv_param param
= {
1940 .min
= (int *) table
->extra1
,
1941 .max
= (int *) table
->extra2
,
1943 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
1944 do_proc_dointvec_minmax_conv
, ¶m
);
1947 static int __do_proc_doulongvec_minmax(void *data
, ctl_table
*table
, int write
,
1949 void __user
*buffer
,
1950 size_t *lenp
, loff_t
*ppos
,
1951 unsigned long convmul
,
1952 unsigned long convdiv
)
1954 #define TMPBUFLEN 21
1955 unsigned long *i
, *min
, *max
, val
;
1956 int vleft
, first
=1, neg
;
1958 char buf
[TMPBUFLEN
], *p
;
1959 char __user
*s
= buffer
;
1961 if (!data
|| !table
->maxlen
|| !*lenp
||
1962 (*ppos
&& !write
)) {
1967 i
= (unsigned long *) data
;
1968 min
= (unsigned long *) table
->extra1
;
1969 max
= (unsigned long *) table
->extra2
;
1970 vleft
= table
->maxlen
/ sizeof(unsigned long);
1973 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
1988 if (len
> TMPBUFLEN
-1)
1990 if (copy_from_user(buf
, s
, len
))
1994 if (*p
== '-' && left
> 1) {
1998 if (*p
< '0' || *p
> '9')
2000 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2002 if ((len
< left
) && *p
&& !isspace(*p
))
2011 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2018 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2022 if(copy_to_user(s
, buf
, len
))
2029 if (!write
&& !first
&& left
) {
2030 if(put_user('\n', s
))
2037 if (get_user(c
, s
++))
2052 static int do_proc_doulongvec_minmax(ctl_table
*table
, int write
,
2054 void __user
*buffer
,
2055 size_t *lenp
, loff_t
*ppos
,
2056 unsigned long convmul
,
2057 unsigned long convdiv
)
2059 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2060 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2064 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2065 * @table: the sysctl table
2066 * @write: %TRUE if this is a write to the sysctl file
2067 * @filp: the file structure
2068 * @buffer: the user buffer
2069 * @lenp: the size of the user buffer
2070 * @ppos: file position
2072 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2073 * values from/to the user buffer, treated as an ASCII string.
2075 * This routine will ensure the values are within the range specified by
2076 * table->extra1 (min) and table->extra2 (max).
2078 * Returns 0 on success.
2080 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2081 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2083 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2087 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2088 * @table: the sysctl table
2089 * @write: %TRUE if this is a write to the sysctl file
2090 * @filp: the file structure
2091 * @buffer: the user buffer
2092 * @lenp: the size of the user buffer
2093 * @ppos: file position
2095 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2096 * values from/to the user buffer, treated as an ASCII string. The values
2097 * are treated as milliseconds, and converted to jiffies when they are stored.
2099 * This routine will ensure the values are within the range specified by
2100 * table->extra1 (min) and table->extra2 (max).
2102 * Returns 0 on success.
2104 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2106 void __user
*buffer
,
2107 size_t *lenp
, loff_t
*ppos
)
2109 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2110 lenp
, ppos
, HZ
, 1000l);
2114 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2116 int write
, void *data
)
2119 if (*lvalp
> LONG_MAX
/ HZ
)
2121 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2127 lval
= (unsigned long)-val
;
2130 lval
= (unsigned long)val
;
2137 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2139 int write
, void *data
)
2142 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2144 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2150 lval
= (unsigned long)-val
;
2153 lval
= (unsigned long)val
;
2155 *lvalp
= jiffies_to_clock_t(lval
);
2160 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2162 int write
, void *data
)
2165 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2171 lval
= (unsigned long)-val
;
2174 lval
= (unsigned long)val
;
2176 *lvalp
= jiffies_to_msecs(lval
);
2182 * proc_dointvec_jiffies - read a vector of integers as seconds
2183 * @table: the sysctl table
2184 * @write: %TRUE if this is a write to the sysctl file
2185 * @filp: the file structure
2186 * @buffer: the user buffer
2187 * @lenp: the size of the user buffer
2188 * @ppos: file position
2190 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2191 * values from/to the user buffer, treated as an ASCII string.
2192 * The values read are assumed to be in seconds, and are converted into
2195 * Returns 0 on success.
2197 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2198 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2200 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2201 do_proc_dointvec_jiffies_conv
,NULL
);
2205 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2206 * @table: the sysctl table
2207 * @write: %TRUE if this is a write to the sysctl file
2208 * @filp: the file structure
2209 * @buffer: the user buffer
2210 * @lenp: the size of the user buffer
2211 * @ppos: pointer to the file position
2213 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2214 * values from/to the user buffer, treated as an ASCII string.
2215 * The values read are assumed to be in 1/USER_HZ seconds, and
2216 * are converted into jiffies.
2218 * Returns 0 on success.
2220 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2221 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2223 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2224 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2228 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2229 * @table: the sysctl table
2230 * @write: %TRUE if this is a write to the sysctl file
2231 * @filp: the file structure
2232 * @buffer: the user buffer
2233 * @lenp: the size of the user buffer
2234 * @ppos: file position
2235 * @ppos: the current position in the file
2237 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2238 * values from/to the user buffer, treated as an ASCII string.
2239 * The values read are assumed to be in 1/1000 seconds, and
2240 * are converted into jiffies.
2242 * Returns 0 on success.
2244 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2245 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2247 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2248 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2251 static int proc_do_cad_pid(ctl_table
*table
, int write
, struct file
*filp
,
2252 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2254 struct pid
*new_pid
;
2258 tmp
= pid_nr(cad_pid
);
2260 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2261 lenp
, ppos
, NULL
, NULL
);
2265 new_pid
= find_get_pid(tmp
);
2269 put_pid(xchg(&cad_pid
, new_pid
));
2273 #else /* CONFIG_PROC_FS */
2275 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2276 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2281 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2282 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2287 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2288 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2293 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2294 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2299 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2300 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2305 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2306 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2311 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2312 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2317 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2318 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2323 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2325 void __user
*buffer
,
2326 size_t *lenp
, loff_t
*ppos
)
2332 #endif /* CONFIG_PROC_FS */
2335 #ifdef CONFIG_SYSCTL_SYSCALL
2337 * General sysctl support routines
2340 /* The generic string strategy routine: */
2341 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2342 void __user
*oldval
, size_t __user
*oldlenp
,
2343 void __user
*newval
, size_t newlen
)
2345 if (!table
->data
|| !table
->maxlen
)
2348 if (oldval
&& oldlenp
) {
2350 if (get_user(bufsize
, oldlenp
))
2353 size_t len
= strlen(table
->data
), copied
;
2355 /* This shouldn't trigger for a well-formed sysctl */
2356 if (len
> table
->maxlen
)
2357 len
= table
->maxlen
;
2359 /* Copy up to a max of bufsize-1 bytes of the string */
2360 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2362 if (copy_to_user(oldval
, table
->data
, copied
) ||
2363 put_user(0, (char __user
*)(oldval
+ copied
)))
2365 if (put_user(len
, oldlenp
))
2369 if (newval
&& newlen
) {
2370 size_t len
= newlen
;
2371 if (len
> table
->maxlen
)
2372 len
= table
->maxlen
;
2373 if(copy_from_user(table
->data
, newval
, len
))
2375 if (len
== table
->maxlen
)
2377 ((char *) table
->data
)[len
] = 0;
2383 * This function makes sure that all of the integers in the vector
2384 * are between the minimum and maximum values given in the arrays
2385 * table->extra1 and table->extra2, respectively.
2387 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2388 void __user
*oldval
, size_t __user
*oldlenp
,
2389 void __user
*newval
, size_t newlen
)
2392 if (newval
&& newlen
) {
2393 int __user
*vec
= (int __user
*) newval
;
2394 int *min
= (int *) table
->extra1
;
2395 int *max
= (int *) table
->extra2
;
2399 if (newlen
% sizeof(int) != 0)
2402 if (!table
->extra1
&& !table
->extra2
)
2405 if (newlen
> table
->maxlen
)
2406 newlen
= table
->maxlen
;
2407 length
= newlen
/ sizeof(int);
2409 for (i
= 0; i
< length
; i
++) {
2411 if (get_user(value
, vec
+ i
))
2413 if (min
&& value
< min
[i
])
2415 if (max
&& value
> max
[i
])
2422 /* Strategy function to convert jiffies to seconds */
2423 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2424 void __user
*oldval
, size_t __user
*oldlenp
,
2425 void __user
*newval
, size_t newlen
)
2427 if (oldval
&& oldlenp
) {
2430 if (get_user(olen
, oldlenp
))
2435 if (olen
< sizeof(int))
2438 val
= *(int *)(table
->data
) / HZ
;
2439 if (put_user(val
, (int __user
*)oldval
))
2441 if (put_user(sizeof(int), oldlenp
))
2445 if (newval
&& newlen
) {
2447 if (newlen
!= sizeof(int))
2449 if (get_user(new, (int __user
*)newval
))
2451 *(int *)(table
->data
) = new*HZ
;
2456 /* Strategy function to convert jiffies to seconds */
2457 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2458 void __user
*oldval
, size_t __user
*oldlenp
,
2459 void __user
*newval
, size_t newlen
)
2461 if (oldval
&& oldlenp
) {
2464 if (get_user(olen
, oldlenp
))
2469 if (olen
< sizeof(int))
2472 val
= jiffies_to_msecs(*(int *)(table
->data
));
2473 if (put_user(val
, (int __user
*)oldval
))
2475 if (put_user(sizeof(int), oldlenp
))
2479 if (newval
&& newlen
) {
2481 if (newlen
!= sizeof(int))
2483 if (get_user(new, (int __user
*)newval
))
2485 *(int *)(table
->data
) = msecs_to_jiffies(new);
2492 #else /* CONFIG_SYSCTL_SYSCALL */
2495 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2497 static int msg_count
;
2498 struct __sysctl_args tmp
;
2499 int name
[CTL_MAXNAME
];
2502 /* Read in the sysctl name for better debug message logging */
2503 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
2505 if (tmp
.nlen
<= 0 || tmp
.nlen
>= CTL_MAXNAME
)
2507 for (i
= 0; i
< tmp
.nlen
; i
++)
2508 if (get_user(name
[i
], tmp
.name
+ i
))
2511 /* Ignore accesses to kernel.version */
2512 if ((tmp
.nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
2515 if (msg_count
< 5) {
2518 "warning: process `%s' used the removed sysctl "
2519 "system call with ", current
->comm
);
2520 for (i
= 0; i
< tmp
.nlen
; i
++)
2521 printk("%d.", name
[i
]);
2528 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2529 void __user
*oldval
, size_t __user
*oldlenp
,
2530 void __user
*newval
, size_t newlen
)
2535 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2536 void __user
*oldval
, size_t __user
*oldlenp
,
2537 void __user
*newval
, size_t newlen
)
2542 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2543 void __user
*oldval
, size_t __user
*oldlenp
,
2544 void __user
*newval
, size_t newlen
)
2549 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2550 void __user
*oldval
, size_t __user
*oldlenp
,
2551 void __user
*newval
, size_t newlen
)
2556 #endif /* CONFIG_SYSCTL_SYSCALL */
2559 * No sense putting this after each symbol definition, twice,
2560 * exception granted :-)
2562 EXPORT_SYMBOL(proc_dointvec
);
2563 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2564 EXPORT_SYMBOL(proc_dointvec_minmax
);
2565 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2566 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2567 EXPORT_SYMBOL(proc_dostring
);
2568 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2569 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2570 EXPORT_SYMBOL(register_sysctl_table
);
2571 EXPORT_SYMBOL(sysctl_intvec
);
2572 EXPORT_SYMBOL(sysctl_jiffies
);
2573 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2574 EXPORT_SYMBOL(sysctl_string
);
2575 EXPORT_SYMBOL(unregister_sysctl_table
);