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/security.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/initrd.h>
41 #include <linux/key.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/vmstat.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/acpi.h>
49 #include <linux/reboot.h>
50 #include <linux/ftrace.h>
51 #include <linux/slow-work.h>
53 #include <asm/uaccess.h>
54 #include <asm/processor.h>
58 #include <asm/stacktrace.h>
62 static int deprecated_sysctl_warning(struct __sysctl_args
*args
);
64 #if defined(CONFIG_SYSCTL)
66 /* External variables not in a header file. */
68 extern int print_fatal_signals
;
69 extern int sysctl_overcommit_memory
;
70 extern int sysctl_overcommit_ratio
;
71 extern int sysctl_panic_on_oom
;
72 extern int sysctl_oom_kill_allocating_task
;
73 extern int sysctl_oom_dump_tasks
;
74 extern int max_threads
;
75 extern int core_uses_pid
;
76 extern int suid_dumpable
;
77 extern char core_pattern
[];
79 extern int min_free_kbytes
;
80 extern int pid_max_min
, pid_max_max
;
81 extern int sysctl_drop_caches
;
82 extern int percpu_pagelist_fraction
;
83 extern int compat_log
;
84 extern int latencytop_enabled
;
85 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
87 extern int sysctl_nr_trim_pages
;
89 #ifdef CONFIG_RCU_TORTURE_TEST
90 extern int rcutorture_runnable
;
91 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
93 /* Constants used for minimum and maximum */
94 #ifdef CONFIG_DETECT_SOFTLOCKUP
95 static int sixty
= 60;
96 static int neg_one
= -1;
100 static int __maybe_unused one
= 1;
101 static int __maybe_unused two
= 2;
102 static unsigned long one_ul
= 1;
103 static int one_hundred
= 100;
104 static int one_thousand
= 1000;
106 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
107 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
109 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
110 static int maxolduid
= 65535;
111 static int minolduid
;
112 static int min_percpu_pagelist_fract
= 8;
114 static int ngroups_max
= NGROUPS_MAX
;
116 #ifdef CONFIG_MODULES
117 extern char modprobe_path
[];
119 #ifdef CONFIG_CHR_DEV_SG
120 extern int sg_big_buff
;
124 #include <asm/system.h>
127 #ifdef CONFIG_SPARC64
128 extern int sysctl_tsb_ratio
;
132 extern int pwrsw_enabled
;
133 extern int unaligned_enabled
;
137 #ifdef CONFIG_MATHEMU
138 extern int sysctl_ieee_emulation_warnings
;
140 extern int sysctl_userprocess_debug
;
141 extern int spin_retry
;
144 #ifdef CONFIG_BSD_PROCESS_ACCT
145 extern int acct_parm
[];
149 extern int no_unaligned_warning
;
150 extern int unaligned_dump_stack
;
153 #ifdef CONFIG_RT_MUTEXES
154 extern int max_lock_depth
;
157 #ifdef CONFIG_PROC_SYSCTL
158 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
159 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
160 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
161 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
164 static struct ctl_table root_table
[];
165 static struct ctl_table_root sysctl_table_root
;
166 static struct ctl_table_header root_table_header
= {
168 .ctl_table
= root_table
,
169 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),
170 .root
= &sysctl_table_root
,
171 .set
= &sysctl_table_root
.default_set
,
173 static struct ctl_table_root sysctl_table_root
= {
174 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
175 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
178 static struct ctl_table kern_table
[];
179 static struct ctl_table vm_table
[];
180 static struct ctl_table fs_table
[];
181 static struct ctl_table debug_table
[];
182 static struct ctl_table dev_table
[];
183 extern struct ctl_table random_table
[];
184 #ifdef CONFIG_INOTIFY_USER
185 extern struct ctl_table inotify_table
[];
188 extern struct ctl_table epoll_table
[];
191 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
192 int sysctl_legacy_va_layout
;
195 extern int prove_locking
;
196 extern int lock_stat
;
198 /* The default sysctl tables: */
200 static struct ctl_table root_table
[] = {
202 .ctl_name
= CTL_KERN
,
203 .procname
= "kernel",
220 .ctl_name
= CTL_DEBUG
,
223 .child
= debug_table
,
232 * NOTE: do not add new entries to this table unless you have read
233 * Documentation/sysctl/ctl_unnumbered.txt
238 #ifdef CONFIG_SCHED_DEBUG
239 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
240 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
241 static int min_wakeup_granularity_ns
; /* 0 usecs */
242 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
245 static struct ctl_table kern_table
[] = {
246 #ifdef CONFIG_SCHED_DEBUG
248 .ctl_name
= CTL_UNNUMBERED
,
249 .procname
= "sched_min_granularity_ns",
250 .data
= &sysctl_sched_min_granularity
,
251 .maxlen
= sizeof(unsigned int),
253 .proc_handler
= &sched_nr_latency_handler
,
254 .strategy
= &sysctl_intvec
,
255 .extra1
= &min_sched_granularity_ns
,
256 .extra2
= &max_sched_granularity_ns
,
259 .ctl_name
= CTL_UNNUMBERED
,
260 .procname
= "sched_latency_ns",
261 .data
= &sysctl_sched_latency
,
262 .maxlen
= sizeof(unsigned int),
264 .proc_handler
= &sched_nr_latency_handler
,
265 .strategy
= &sysctl_intvec
,
266 .extra1
= &min_sched_granularity_ns
,
267 .extra2
= &max_sched_granularity_ns
,
270 .ctl_name
= CTL_UNNUMBERED
,
271 .procname
= "sched_wakeup_granularity_ns",
272 .data
= &sysctl_sched_wakeup_granularity
,
273 .maxlen
= sizeof(unsigned int),
275 .proc_handler
= &proc_dointvec_minmax
,
276 .strategy
= &sysctl_intvec
,
277 .extra1
= &min_wakeup_granularity_ns
,
278 .extra2
= &max_wakeup_granularity_ns
,
281 .ctl_name
= CTL_UNNUMBERED
,
282 .procname
= "sched_shares_ratelimit",
283 .data
= &sysctl_sched_shares_ratelimit
,
284 .maxlen
= sizeof(unsigned int),
286 .proc_handler
= &proc_dointvec
,
289 .ctl_name
= CTL_UNNUMBERED
,
290 .procname
= "sched_shares_thresh",
291 .data
= &sysctl_sched_shares_thresh
,
292 .maxlen
= sizeof(unsigned int),
294 .proc_handler
= &proc_dointvec_minmax
,
295 .strategy
= &sysctl_intvec
,
299 .ctl_name
= CTL_UNNUMBERED
,
300 .procname
= "sched_child_runs_first",
301 .data
= &sysctl_sched_child_runs_first
,
302 .maxlen
= sizeof(unsigned int),
304 .proc_handler
= &proc_dointvec
,
307 .ctl_name
= CTL_UNNUMBERED
,
308 .procname
= "sched_features",
309 .data
= &sysctl_sched_features
,
310 .maxlen
= sizeof(unsigned int),
312 .proc_handler
= &proc_dointvec
,
315 .ctl_name
= CTL_UNNUMBERED
,
316 .procname
= "sched_migration_cost",
317 .data
= &sysctl_sched_migration_cost
,
318 .maxlen
= sizeof(unsigned int),
320 .proc_handler
= &proc_dointvec
,
323 .ctl_name
= CTL_UNNUMBERED
,
324 .procname
= "sched_nr_migrate",
325 .data
= &sysctl_sched_nr_migrate
,
326 .maxlen
= sizeof(unsigned int),
328 .proc_handler
= &proc_dointvec
,
332 .ctl_name
= CTL_UNNUMBERED
,
333 .procname
= "sched_rt_period_us",
334 .data
= &sysctl_sched_rt_period
,
335 .maxlen
= sizeof(unsigned int),
337 .proc_handler
= &sched_rt_handler
,
340 .ctl_name
= CTL_UNNUMBERED
,
341 .procname
= "sched_rt_runtime_us",
342 .data
= &sysctl_sched_rt_runtime
,
343 .maxlen
= sizeof(int),
345 .proc_handler
= &sched_rt_handler
,
348 .ctl_name
= CTL_UNNUMBERED
,
349 .procname
= "sched_compat_yield",
350 .data
= &sysctl_sched_compat_yield
,
351 .maxlen
= sizeof(unsigned int),
353 .proc_handler
= &proc_dointvec
,
355 #ifdef CONFIG_PROVE_LOCKING
357 .ctl_name
= CTL_UNNUMBERED
,
358 .procname
= "prove_locking",
359 .data
= &prove_locking
,
360 .maxlen
= sizeof(int),
362 .proc_handler
= &proc_dointvec
,
365 #ifdef CONFIG_LOCK_STAT
367 .ctl_name
= CTL_UNNUMBERED
,
368 .procname
= "lock_stat",
370 .maxlen
= sizeof(int),
372 .proc_handler
= &proc_dointvec
,
376 .ctl_name
= KERN_PANIC
,
378 .data
= &panic_timeout
,
379 .maxlen
= sizeof(int),
381 .proc_handler
= &proc_dointvec
,
384 .ctl_name
= KERN_CORE_USES_PID
,
385 .procname
= "core_uses_pid",
386 .data
= &core_uses_pid
,
387 .maxlen
= sizeof(int),
389 .proc_handler
= &proc_dointvec
,
392 .ctl_name
= KERN_CORE_PATTERN
,
393 .procname
= "core_pattern",
394 .data
= core_pattern
,
395 .maxlen
= CORENAME_MAX_SIZE
,
397 .proc_handler
= &proc_dostring
,
398 .strategy
= &sysctl_string
,
400 #ifdef CONFIG_PROC_SYSCTL
402 .procname
= "tainted",
403 .maxlen
= sizeof(long),
405 .proc_handler
= &proc_taint
,
408 #ifdef CONFIG_LATENCYTOP
410 .procname
= "latencytop",
411 .data
= &latencytop_enabled
,
412 .maxlen
= sizeof(int),
414 .proc_handler
= &proc_dointvec
,
417 #ifdef CONFIG_BLK_DEV_INITRD
419 .ctl_name
= KERN_REALROOTDEV
,
420 .procname
= "real-root-dev",
421 .data
= &real_root_dev
,
422 .maxlen
= sizeof(int),
424 .proc_handler
= &proc_dointvec
,
428 .ctl_name
= CTL_UNNUMBERED
,
429 .procname
= "print-fatal-signals",
430 .data
= &print_fatal_signals
,
431 .maxlen
= sizeof(int),
433 .proc_handler
= &proc_dointvec
,
437 .ctl_name
= KERN_SPARC_REBOOT
,
438 .procname
= "reboot-cmd",
439 .data
= reboot_command
,
442 .proc_handler
= &proc_dostring
,
443 .strategy
= &sysctl_string
,
446 .ctl_name
= KERN_SPARC_STOP_A
,
447 .procname
= "stop-a",
448 .data
= &stop_a_enabled
,
449 .maxlen
= sizeof (int),
451 .proc_handler
= &proc_dointvec
,
454 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
455 .procname
= "scons-poweroff",
456 .data
= &scons_pwroff
,
457 .maxlen
= sizeof (int),
459 .proc_handler
= &proc_dointvec
,
462 #ifdef CONFIG_SPARC64
464 .ctl_name
= CTL_UNNUMBERED
,
465 .procname
= "tsb-ratio",
466 .data
= &sysctl_tsb_ratio
,
467 .maxlen
= sizeof (int),
469 .proc_handler
= &proc_dointvec
,
474 .ctl_name
= KERN_HPPA_PWRSW
,
475 .procname
= "soft-power",
476 .data
= &pwrsw_enabled
,
477 .maxlen
= sizeof (int),
479 .proc_handler
= &proc_dointvec
,
482 .ctl_name
= KERN_HPPA_UNALIGNED
,
483 .procname
= "unaligned-trap",
484 .data
= &unaligned_enabled
,
485 .maxlen
= sizeof (int),
487 .proc_handler
= &proc_dointvec
,
491 .ctl_name
= KERN_CTLALTDEL
,
492 .procname
= "ctrl-alt-del",
494 .maxlen
= sizeof(int),
496 .proc_handler
= &proc_dointvec
,
498 #ifdef CONFIG_FUNCTION_TRACER
500 .ctl_name
= CTL_UNNUMBERED
,
501 .procname
= "ftrace_enabled",
502 .data
= &ftrace_enabled
,
503 .maxlen
= sizeof(int),
505 .proc_handler
= &ftrace_enable_sysctl
,
508 #ifdef CONFIG_STACK_TRACER
510 .ctl_name
= CTL_UNNUMBERED
,
511 .procname
= "stack_tracer_enabled",
512 .data
= &stack_tracer_enabled
,
513 .maxlen
= sizeof(int),
515 .proc_handler
= &stack_trace_sysctl
,
518 #ifdef CONFIG_TRACING
520 .ctl_name
= CTL_UNNUMBERED
,
521 .procname
= "ftrace_dump_on_oops",
522 .data
= &ftrace_dump_on_oops
,
523 .maxlen
= sizeof(int),
525 .proc_handler
= &proc_dointvec
,
528 #ifdef CONFIG_MODULES
530 .ctl_name
= KERN_MODPROBE
,
531 .procname
= "modprobe",
532 .data
= &modprobe_path
,
533 .maxlen
= KMOD_PATH_LEN
,
535 .proc_handler
= &proc_dostring
,
536 .strategy
= &sysctl_string
,
539 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
541 .ctl_name
= KERN_HOTPLUG
,
542 .procname
= "hotplug",
543 .data
= &uevent_helper
,
544 .maxlen
= UEVENT_HELPER_PATH_LEN
,
546 .proc_handler
= &proc_dostring
,
547 .strategy
= &sysctl_string
,
550 #ifdef CONFIG_CHR_DEV_SG
552 .ctl_name
= KERN_SG_BIG_BUFF
,
553 .procname
= "sg-big-buff",
554 .data
= &sg_big_buff
,
555 .maxlen
= sizeof (int),
557 .proc_handler
= &proc_dointvec
,
560 #ifdef CONFIG_BSD_PROCESS_ACCT
562 .ctl_name
= KERN_ACCT
,
565 .maxlen
= 3*sizeof(int),
567 .proc_handler
= &proc_dointvec
,
570 #ifdef CONFIG_MAGIC_SYSRQ
572 .ctl_name
= KERN_SYSRQ
,
574 .data
= &__sysrq_enabled
,
575 .maxlen
= sizeof (int),
577 .proc_handler
= &proc_dointvec
,
580 #ifdef CONFIG_PROC_SYSCTL
582 .procname
= "cad_pid",
584 .maxlen
= sizeof (int),
586 .proc_handler
= &proc_do_cad_pid
,
590 .ctl_name
= KERN_MAX_THREADS
,
591 .procname
= "threads-max",
592 .data
= &max_threads
,
593 .maxlen
= sizeof(int),
595 .proc_handler
= &proc_dointvec
,
598 .ctl_name
= KERN_RANDOM
,
599 .procname
= "random",
601 .child
= random_table
,
604 .ctl_name
= KERN_OVERFLOWUID
,
605 .procname
= "overflowuid",
606 .data
= &overflowuid
,
607 .maxlen
= sizeof(int),
609 .proc_handler
= &proc_dointvec_minmax
,
610 .strategy
= &sysctl_intvec
,
611 .extra1
= &minolduid
,
612 .extra2
= &maxolduid
,
615 .ctl_name
= KERN_OVERFLOWGID
,
616 .procname
= "overflowgid",
617 .data
= &overflowgid
,
618 .maxlen
= sizeof(int),
620 .proc_handler
= &proc_dointvec_minmax
,
621 .strategy
= &sysctl_intvec
,
622 .extra1
= &minolduid
,
623 .extra2
= &maxolduid
,
626 #ifdef CONFIG_MATHEMU
628 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
629 .procname
= "ieee_emulation_warnings",
630 .data
= &sysctl_ieee_emulation_warnings
,
631 .maxlen
= sizeof(int),
633 .proc_handler
= &proc_dointvec
,
637 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
638 .procname
= "userprocess_debug",
639 .data
= &sysctl_userprocess_debug
,
640 .maxlen
= sizeof(int),
642 .proc_handler
= &proc_dointvec
,
646 .ctl_name
= KERN_PIDMAX
,
647 .procname
= "pid_max",
649 .maxlen
= sizeof (int),
651 .proc_handler
= &proc_dointvec_minmax
,
652 .strategy
= sysctl_intvec
,
653 .extra1
= &pid_max_min
,
654 .extra2
= &pid_max_max
,
657 .ctl_name
= KERN_PANIC_ON_OOPS
,
658 .procname
= "panic_on_oops",
659 .data
= &panic_on_oops
,
660 .maxlen
= sizeof(int),
662 .proc_handler
= &proc_dointvec
,
664 #if defined CONFIG_PRINTK
666 .ctl_name
= KERN_PRINTK
,
667 .procname
= "printk",
668 .data
= &console_loglevel
,
669 .maxlen
= 4*sizeof(int),
671 .proc_handler
= &proc_dointvec
,
674 .ctl_name
= KERN_PRINTK_RATELIMIT
,
675 .procname
= "printk_ratelimit",
676 .data
= &printk_ratelimit_state
.interval
,
677 .maxlen
= sizeof(int),
679 .proc_handler
= &proc_dointvec_jiffies
,
680 .strategy
= &sysctl_jiffies
,
683 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
684 .procname
= "printk_ratelimit_burst",
685 .data
= &printk_ratelimit_state
.burst
,
686 .maxlen
= sizeof(int),
688 .proc_handler
= &proc_dointvec
,
692 .ctl_name
= KERN_NGROUPS_MAX
,
693 .procname
= "ngroups_max",
694 .data
= &ngroups_max
,
695 .maxlen
= sizeof (int),
697 .proc_handler
= &proc_dointvec
,
699 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
701 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
702 .procname
= "unknown_nmi_panic",
703 .data
= &unknown_nmi_panic
,
704 .maxlen
= sizeof (int),
706 .proc_handler
= &proc_dointvec
,
709 .procname
= "nmi_watchdog",
710 .data
= &nmi_watchdog_enabled
,
711 .maxlen
= sizeof (int),
713 .proc_handler
= &proc_nmi_enabled
,
716 #if defined(CONFIG_X86)
718 .ctl_name
= KERN_PANIC_ON_NMI
,
719 .procname
= "panic_on_unrecovered_nmi",
720 .data
= &panic_on_unrecovered_nmi
,
721 .maxlen
= sizeof(int),
723 .proc_handler
= &proc_dointvec
,
726 .ctl_name
= KERN_BOOTLOADER_TYPE
,
727 .procname
= "bootloader_type",
728 .data
= &bootloader_type
,
729 .maxlen
= sizeof (int),
731 .proc_handler
= &proc_dointvec
,
734 .ctl_name
= CTL_UNNUMBERED
,
735 .procname
= "kstack_depth_to_print",
736 .data
= &kstack_depth_to_print
,
737 .maxlen
= sizeof(int),
739 .proc_handler
= &proc_dointvec
,
742 .ctl_name
= CTL_UNNUMBERED
,
743 .procname
= "io_delay_type",
744 .data
= &io_delay_type
,
745 .maxlen
= sizeof(int),
747 .proc_handler
= &proc_dointvec
,
750 #if defined(CONFIG_MMU)
752 .ctl_name
= KERN_RANDOMIZE
,
753 .procname
= "randomize_va_space",
754 .data
= &randomize_va_space
,
755 .maxlen
= sizeof(int),
757 .proc_handler
= &proc_dointvec
,
760 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
762 .ctl_name
= KERN_SPIN_RETRY
,
763 .procname
= "spin_retry",
765 .maxlen
= sizeof (int),
767 .proc_handler
= &proc_dointvec
,
770 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
772 .procname
= "acpi_video_flags",
773 .data
= &acpi_realmode_flags
,
774 .maxlen
= sizeof (unsigned long),
776 .proc_handler
= &proc_doulongvec_minmax
,
781 .ctl_name
= KERN_IA64_UNALIGNED
,
782 .procname
= "ignore-unaligned-usertrap",
783 .data
= &no_unaligned_warning
,
784 .maxlen
= sizeof (int),
786 .proc_handler
= &proc_dointvec
,
789 .ctl_name
= CTL_UNNUMBERED
,
790 .procname
= "unaligned-dump-stack",
791 .data
= &unaligned_dump_stack
,
792 .maxlen
= sizeof (int),
794 .proc_handler
= &proc_dointvec
,
797 #ifdef CONFIG_DETECT_SOFTLOCKUP
799 .ctl_name
= CTL_UNNUMBERED
,
800 .procname
= "softlockup_panic",
801 .data
= &softlockup_panic
,
802 .maxlen
= sizeof(int),
804 .proc_handler
= &proc_dointvec_minmax
,
805 .strategy
= &sysctl_intvec
,
810 .ctl_name
= CTL_UNNUMBERED
,
811 .procname
= "softlockup_thresh",
812 .data
= &softlockup_thresh
,
813 .maxlen
= sizeof(int),
815 .proc_handler
= &proc_dosoftlockup_thresh
,
816 .strategy
= &sysctl_intvec
,
821 #ifdef CONFIG_DETECT_HUNG_TASK
823 .ctl_name
= CTL_UNNUMBERED
,
824 .procname
= "hung_task_panic",
825 .data
= &sysctl_hung_task_panic
,
826 .maxlen
= sizeof(int),
828 .proc_handler
= &proc_dointvec_minmax
,
829 .strategy
= &sysctl_intvec
,
834 .ctl_name
= CTL_UNNUMBERED
,
835 .procname
= "hung_task_check_count",
836 .data
= &sysctl_hung_task_check_count
,
837 .maxlen
= sizeof(unsigned long),
839 .proc_handler
= &proc_doulongvec_minmax
,
840 .strategy
= &sysctl_intvec
,
843 .ctl_name
= CTL_UNNUMBERED
,
844 .procname
= "hung_task_timeout_secs",
845 .data
= &sysctl_hung_task_timeout_secs
,
846 .maxlen
= sizeof(unsigned long),
848 .proc_handler
= &proc_dohung_task_timeout_secs
,
849 .strategy
= &sysctl_intvec
,
852 .ctl_name
= CTL_UNNUMBERED
,
853 .procname
= "hung_task_warnings",
854 .data
= &sysctl_hung_task_warnings
,
855 .maxlen
= sizeof(unsigned long),
857 .proc_handler
= &proc_doulongvec_minmax
,
858 .strategy
= &sysctl_intvec
,
863 .ctl_name
= KERN_COMPAT_LOG
,
864 .procname
= "compat-log",
866 .maxlen
= sizeof (int),
868 .proc_handler
= &proc_dointvec
,
871 #ifdef CONFIG_RT_MUTEXES
873 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
874 .procname
= "max_lock_depth",
875 .data
= &max_lock_depth
,
876 .maxlen
= sizeof(int),
878 .proc_handler
= &proc_dointvec
,
882 .ctl_name
= CTL_UNNUMBERED
,
883 .procname
= "poweroff_cmd",
884 .data
= &poweroff_cmd
,
885 .maxlen
= POWEROFF_CMD_PATH_LEN
,
887 .proc_handler
= &proc_dostring
,
888 .strategy
= &sysctl_string
,
892 .ctl_name
= CTL_UNNUMBERED
,
895 .child
= key_sysctls
,
898 #ifdef CONFIG_RCU_TORTURE_TEST
900 .ctl_name
= CTL_UNNUMBERED
,
901 .procname
= "rcutorture_runnable",
902 .data
= &rcutorture_runnable
,
903 .maxlen
= sizeof(int),
905 .proc_handler
= &proc_dointvec
,
908 #ifdef CONFIG_SLOW_WORK
910 .ctl_name
= CTL_UNNUMBERED
,
911 .procname
= "slow-work",
913 .child
= slow_work_sysctls
,
917 * NOTE: do not add new entries to this table unless you have read
918 * Documentation/sysctl/ctl_unnumbered.txt
923 static struct ctl_table vm_table
[] = {
925 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
926 .procname
= "overcommit_memory",
927 .data
= &sysctl_overcommit_memory
,
928 .maxlen
= sizeof(sysctl_overcommit_memory
),
930 .proc_handler
= &proc_dointvec
,
933 .ctl_name
= VM_PANIC_ON_OOM
,
934 .procname
= "panic_on_oom",
935 .data
= &sysctl_panic_on_oom
,
936 .maxlen
= sizeof(sysctl_panic_on_oom
),
938 .proc_handler
= &proc_dointvec
,
941 .ctl_name
= CTL_UNNUMBERED
,
942 .procname
= "oom_kill_allocating_task",
943 .data
= &sysctl_oom_kill_allocating_task
,
944 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
946 .proc_handler
= &proc_dointvec
,
949 .ctl_name
= CTL_UNNUMBERED
,
950 .procname
= "oom_dump_tasks",
951 .data
= &sysctl_oom_dump_tasks
,
952 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
954 .proc_handler
= &proc_dointvec
,
957 .ctl_name
= VM_OVERCOMMIT_RATIO
,
958 .procname
= "overcommit_ratio",
959 .data
= &sysctl_overcommit_ratio
,
960 .maxlen
= sizeof(sysctl_overcommit_ratio
),
962 .proc_handler
= &proc_dointvec
,
965 .ctl_name
= VM_PAGE_CLUSTER
,
966 .procname
= "page-cluster",
967 .data
= &page_cluster
,
968 .maxlen
= sizeof(int),
970 .proc_handler
= &proc_dointvec
,
973 .ctl_name
= VM_DIRTY_BACKGROUND
,
974 .procname
= "dirty_background_ratio",
975 .data
= &dirty_background_ratio
,
976 .maxlen
= sizeof(dirty_background_ratio
),
978 .proc_handler
= &dirty_background_ratio_handler
,
979 .strategy
= &sysctl_intvec
,
981 .extra2
= &one_hundred
,
984 .ctl_name
= CTL_UNNUMBERED
,
985 .procname
= "dirty_background_bytes",
986 .data
= &dirty_background_bytes
,
987 .maxlen
= sizeof(dirty_background_bytes
),
989 .proc_handler
= &dirty_background_bytes_handler
,
990 .strategy
= &sysctl_intvec
,
994 .ctl_name
= VM_DIRTY_RATIO
,
995 .procname
= "dirty_ratio",
996 .data
= &vm_dirty_ratio
,
997 .maxlen
= sizeof(vm_dirty_ratio
),
999 .proc_handler
= &dirty_ratio_handler
,
1000 .strategy
= &sysctl_intvec
,
1002 .extra2
= &one_hundred
,
1005 .ctl_name
= CTL_UNNUMBERED
,
1006 .procname
= "dirty_bytes",
1007 .data
= &vm_dirty_bytes
,
1008 .maxlen
= sizeof(vm_dirty_bytes
),
1010 .proc_handler
= &dirty_bytes_handler
,
1011 .strategy
= &sysctl_intvec
,
1012 .extra1
= &dirty_bytes_min
,
1015 .procname
= "dirty_writeback_centisecs",
1016 .data
= &dirty_writeback_interval
,
1017 .maxlen
= sizeof(dirty_writeback_interval
),
1019 .proc_handler
= &dirty_writeback_centisecs_handler
,
1022 .procname
= "dirty_expire_centisecs",
1023 .data
= &dirty_expire_interval
,
1024 .maxlen
= sizeof(dirty_expire_interval
),
1026 .proc_handler
= &proc_dointvec
,
1029 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
1030 .procname
= "nr_pdflush_threads",
1031 .data
= &nr_pdflush_threads
,
1032 .maxlen
= sizeof nr_pdflush_threads
,
1033 .mode
= 0444 /* read-only*/,
1034 .proc_handler
= &proc_dointvec
,
1037 .ctl_name
= CTL_UNNUMBERED
,
1038 .procname
= "nr_pdflush_threads_min",
1039 .data
= &nr_pdflush_threads_min
,
1040 .maxlen
= sizeof nr_pdflush_threads_min
,
1041 .mode
= 0644 /* read-write */,
1042 .proc_handler
= &proc_dointvec_minmax
,
1043 .strategy
= &sysctl_intvec
,
1045 .extra2
= &nr_pdflush_threads_max
,
1048 .ctl_name
= CTL_UNNUMBERED
,
1049 .procname
= "nr_pdflush_threads_max",
1050 .data
= &nr_pdflush_threads_max
,
1051 .maxlen
= sizeof nr_pdflush_threads_max
,
1052 .mode
= 0644 /* read-write */,
1053 .proc_handler
= &proc_dointvec_minmax
,
1054 .strategy
= &sysctl_intvec
,
1055 .extra1
= &nr_pdflush_threads_min
,
1056 .extra2
= &one_thousand
,
1059 .ctl_name
= VM_SWAPPINESS
,
1060 .procname
= "swappiness",
1061 .data
= &vm_swappiness
,
1062 .maxlen
= sizeof(vm_swappiness
),
1064 .proc_handler
= &proc_dointvec_minmax
,
1065 .strategy
= &sysctl_intvec
,
1067 .extra2
= &one_hundred
,
1069 #ifdef CONFIG_HUGETLB_PAGE
1071 .procname
= "nr_hugepages",
1073 .maxlen
= sizeof(unsigned long),
1075 .proc_handler
= &hugetlb_sysctl_handler
,
1076 .extra1
= (void *)&hugetlb_zero
,
1077 .extra2
= (void *)&hugetlb_infinity
,
1080 .ctl_name
= VM_HUGETLB_GROUP
,
1081 .procname
= "hugetlb_shm_group",
1082 .data
= &sysctl_hugetlb_shm_group
,
1083 .maxlen
= sizeof(gid_t
),
1085 .proc_handler
= &proc_dointvec
,
1088 .ctl_name
= CTL_UNNUMBERED
,
1089 .procname
= "hugepages_treat_as_movable",
1090 .data
= &hugepages_treat_as_movable
,
1091 .maxlen
= sizeof(int),
1093 .proc_handler
= &hugetlb_treat_movable_handler
,
1096 .ctl_name
= CTL_UNNUMBERED
,
1097 .procname
= "nr_overcommit_hugepages",
1099 .maxlen
= sizeof(unsigned long),
1101 .proc_handler
= &hugetlb_overcommit_handler
,
1102 .extra1
= (void *)&hugetlb_zero
,
1103 .extra2
= (void *)&hugetlb_infinity
,
1107 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
1108 .procname
= "lowmem_reserve_ratio",
1109 .data
= &sysctl_lowmem_reserve_ratio
,
1110 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1112 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
1113 .strategy
= &sysctl_intvec
,
1116 .ctl_name
= VM_DROP_PAGECACHE
,
1117 .procname
= "drop_caches",
1118 .data
= &sysctl_drop_caches
,
1119 .maxlen
= sizeof(int),
1121 .proc_handler
= drop_caches_sysctl_handler
,
1122 .strategy
= &sysctl_intvec
,
1125 .ctl_name
= VM_MIN_FREE_KBYTES
,
1126 .procname
= "min_free_kbytes",
1127 .data
= &min_free_kbytes
,
1128 .maxlen
= sizeof(min_free_kbytes
),
1130 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1131 .strategy
= &sysctl_intvec
,
1135 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1136 .procname
= "percpu_pagelist_fraction",
1137 .data
= &percpu_pagelist_fraction
,
1138 .maxlen
= sizeof(percpu_pagelist_fraction
),
1140 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1141 .strategy
= &sysctl_intvec
,
1142 .extra1
= &min_percpu_pagelist_fract
,
1146 .ctl_name
= VM_MAX_MAP_COUNT
,
1147 .procname
= "max_map_count",
1148 .data
= &sysctl_max_map_count
,
1149 .maxlen
= sizeof(sysctl_max_map_count
),
1151 .proc_handler
= &proc_dointvec
1155 .ctl_name
= CTL_UNNUMBERED
,
1156 .procname
= "nr_trim_pages",
1157 .data
= &sysctl_nr_trim_pages
,
1158 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1160 .proc_handler
= &proc_dointvec_minmax
,
1161 .strategy
= &sysctl_intvec
,
1166 .ctl_name
= VM_LAPTOP_MODE
,
1167 .procname
= "laptop_mode",
1168 .data
= &laptop_mode
,
1169 .maxlen
= sizeof(laptop_mode
),
1171 .proc_handler
= &proc_dointvec_jiffies
,
1172 .strategy
= &sysctl_jiffies
,
1175 .ctl_name
= VM_BLOCK_DUMP
,
1176 .procname
= "block_dump",
1177 .data
= &block_dump
,
1178 .maxlen
= sizeof(block_dump
),
1180 .proc_handler
= &proc_dointvec
,
1181 .strategy
= &sysctl_intvec
,
1185 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1186 .procname
= "vfs_cache_pressure",
1187 .data
= &sysctl_vfs_cache_pressure
,
1188 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1190 .proc_handler
= &proc_dointvec
,
1191 .strategy
= &sysctl_intvec
,
1194 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1196 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1197 .procname
= "legacy_va_layout",
1198 .data
= &sysctl_legacy_va_layout
,
1199 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1201 .proc_handler
= &proc_dointvec
,
1202 .strategy
= &sysctl_intvec
,
1208 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1209 .procname
= "zone_reclaim_mode",
1210 .data
= &zone_reclaim_mode
,
1211 .maxlen
= sizeof(zone_reclaim_mode
),
1213 .proc_handler
= &proc_dointvec
,
1214 .strategy
= &sysctl_intvec
,
1218 .ctl_name
= VM_MIN_UNMAPPED
,
1219 .procname
= "min_unmapped_ratio",
1220 .data
= &sysctl_min_unmapped_ratio
,
1221 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1223 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1224 .strategy
= &sysctl_intvec
,
1226 .extra2
= &one_hundred
,
1229 .ctl_name
= VM_MIN_SLAB
,
1230 .procname
= "min_slab_ratio",
1231 .data
= &sysctl_min_slab_ratio
,
1232 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1234 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1235 .strategy
= &sysctl_intvec
,
1237 .extra2
= &one_hundred
,
1242 .ctl_name
= CTL_UNNUMBERED
,
1243 .procname
= "stat_interval",
1244 .data
= &sysctl_stat_interval
,
1245 .maxlen
= sizeof(sysctl_stat_interval
),
1247 .proc_handler
= &proc_dointvec_jiffies
,
1248 .strategy
= &sysctl_jiffies
,
1251 #ifdef CONFIG_SECURITY
1253 .ctl_name
= CTL_UNNUMBERED
,
1254 .procname
= "mmap_min_addr",
1255 .data
= &mmap_min_addr
,
1256 .maxlen
= sizeof(unsigned long),
1258 .proc_handler
= &proc_doulongvec_minmax
,
1263 .ctl_name
= CTL_UNNUMBERED
,
1264 .procname
= "numa_zonelist_order",
1265 .data
= &numa_zonelist_order
,
1266 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1268 .proc_handler
= &numa_zonelist_order_handler
,
1269 .strategy
= &sysctl_string
,
1272 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1273 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1275 .ctl_name
= VM_VDSO_ENABLED
,
1276 .procname
= "vdso_enabled",
1277 .data
= &vdso_enabled
,
1278 .maxlen
= sizeof(vdso_enabled
),
1280 .proc_handler
= &proc_dointvec
,
1281 .strategy
= &sysctl_intvec
,
1285 #ifdef CONFIG_HIGHMEM
1287 .ctl_name
= CTL_UNNUMBERED
,
1288 .procname
= "highmem_is_dirtyable",
1289 .data
= &vm_highmem_is_dirtyable
,
1290 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1292 .proc_handler
= &proc_dointvec_minmax
,
1293 .strategy
= &sysctl_intvec
,
1298 #ifdef CONFIG_UNEVICTABLE_LRU
1300 .ctl_name
= CTL_UNNUMBERED
,
1301 .procname
= "scan_unevictable_pages",
1302 .data
= &scan_unevictable_pages
,
1303 .maxlen
= sizeof(scan_unevictable_pages
),
1305 .proc_handler
= &scan_unevictable_handler
,
1309 * NOTE: do not add new entries to this table unless you have read
1310 * Documentation/sysctl/ctl_unnumbered.txt
1315 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1316 static struct ctl_table binfmt_misc_table
[] = {
1321 static struct ctl_table fs_table
[] = {
1323 .ctl_name
= FS_NRINODE
,
1324 .procname
= "inode-nr",
1325 .data
= &inodes_stat
,
1326 .maxlen
= 2*sizeof(int),
1328 .proc_handler
= &proc_dointvec
,
1331 .ctl_name
= FS_STATINODE
,
1332 .procname
= "inode-state",
1333 .data
= &inodes_stat
,
1334 .maxlen
= 7*sizeof(int),
1336 .proc_handler
= &proc_dointvec
,
1339 .procname
= "file-nr",
1340 .data
= &files_stat
,
1341 .maxlen
= 3*sizeof(int),
1343 .proc_handler
= &proc_nr_files
,
1346 .ctl_name
= FS_MAXFILE
,
1347 .procname
= "file-max",
1348 .data
= &files_stat
.max_files
,
1349 .maxlen
= sizeof(int),
1351 .proc_handler
= &proc_dointvec
,
1354 .ctl_name
= CTL_UNNUMBERED
,
1355 .procname
= "nr_open",
1356 .data
= &sysctl_nr_open
,
1357 .maxlen
= sizeof(int),
1359 .proc_handler
= &proc_dointvec_minmax
,
1360 .extra1
= &sysctl_nr_open_min
,
1361 .extra2
= &sysctl_nr_open_max
,
1364 .ctl_name
= FS_DENTRY
,
1365 .procname
= "dentry-state",
1366 .data
= &dentry_stat
,
1367 .maxlen
= 6*sizeof(int),
1369 .proc_handler
= &proc_dointvec
,
1372 .ctl_name
= FS_OVERFLOWUID
,
1373 .procname
= "overflowuid",
1374 .data
= &fs_overflowuid
,
1375 .maxlen
= sizeof(int),
1377 .proc_handler
= &proc_dointvec_minmax
,
1378 .strategy
= &sysctl_intvec
,
1379 .extra1
= &minolduid
,
1380 .extra2
= &maxolduid
,
1383 .ctl_name
= FS_OVERFLOWGID
,
1384 .procname
= "overflowgid",
1385 .data
= &fs_overflowgid
,
1386 .maxlen
= sizeof(int),
1388 .proc_handler
= &proc_dointvec_minmax
,
1389 .strategy
= &sysctl_intvec
,
1390 .extra1
= &minolduid
,
1391 .extra2
= &maxolduid
,
1393 #ifdef CONFIG_FILE_LOCKING
1395 .ctl_name
= FS_LEASES
,
1396 .procname
= "leases-enable",
1397 .data
= &leases_enable
,
1398 .maxlen
= sizeof(int),
1400 .proc_handler
= &proc_dointvec
,
1403 #ifdef CONFIG_DNOTIFY
1405 .ctl_name
= FS_DIR_NOTIFY
,
1406 .procname
= "dir-notify-enable",
1407 .data
= &dir_notify_enable
,
1408 .maxlen
= sizeof(int),
1410 .proc_handler
= &proc_dointvec
,
1414 #ifdef CONFIG_FILE_LOCKING
1416 .ctl_name
= FS_LEASE_TIME
,
1417 .procname
= "lease-break-time",
1418 .data
= &lease_break_time
,
1419 .maxlen
= sizeof(int),
1421 .proc_handler
= &proc_dointvec
,
1426 .procname
= "aio-nr",
1428 .maxlen
= sizeof(aio_nr
),
1430 .proc_handler
= &proc_doulongvec_minmax
,
1433 .procname
= "aio-max-nr",
1434 .data
= &aio_max_nr
,
1435 .maxlen
= sizeof(aio_max_nr
),
1437 .proc_handler
= &proc_doulongvec_minmax
,
1439 #endif /* CONFIG_AIO */
1440 #ifdef CONFIG_INOTIFY_USER
1442 .ctl_name
= FS_INOTIFY
,
1443 .procname
= "inotify",
1445 .child
= inotify_table
,
1450 .procname
= "epoll",
1452 .child
= epoll_table
,
1457 .ctl_name
= KERN_SETUID_DUMPABLE
,
1458 .procname
= "suid_dumpable",
1459 .data
= &suid_dumpable
,
1460 .maxlen
= sizeof(int),
1462 .proc_handler
= &proc_dointvec_minmax
,
1463 .strategy
= &sysctl_intvec
,
1467 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1469 .ctl_name
= CTL_UNNUMBERED
,
1470 .procname
= "binfmt_misc",
1472 .child
= binfmt_misc_table
,
1476 * NOTE: do not add new entries to this table unless you have read
1477 * Documentation/sysctl/ctl_unnumbered.txt
1482 static struct ctl_table debug_table
[] = {
1483 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1485 .ctl_name
= CTL_UNNUMBERED
,
1486 .procname
= "exception-trace",
1487 .data
= &show_unhandled_signals
,
1488 .maxlen
= sizeof(int),
1490 .proc_handler
= proc_dointvec
1496 static struct ctl_table dev_table
[] = {
1500 static DEFINE_SPINLOCK(sysctl_lock
);
1502 /* called under sysctl_lock */
1503 static int use_table(struct ctl_table_header
*p
)
1505 if (unlikely(p
->unregistering
))
1511 /* called under sysctl_lock */
1512 static void unuse_table(struct ctl_table_header
*p
)
1515 if (unlikely(p
->unregistering
))
1516 complete(p
->unregistering
);
1519 /* called under sysctl_lock, will reacquire if has to wait */
1520 static void start_unregistering(struct ctl_table_header
*p
)
1523 * if p->used is 0, nobody will ever touch that entry again;
1524 * we'll eliminate all paths to it before dropping sysctl_lock
1526 if (unlikely(p
->used
)) {
1527 struct completion wait
;
1528 init_completion(&wait
);
1529 p
->unregistering
= &wait
;
1530 spin_unlock(&sysctl_lock
);
1531 wait_for_completion(&wait
);
1532 spin_lock(&sysctl_lock
);
1534 /* anything non-NULL; we'll never dereference it */
1535 p
->unregistering
= ERR_PTR(-EINVAL
);
1538 * do not remove from the list until nobody holds it; walking the
1539 * list in do_sysctl() relies on that.
1541 list_del_init(&p
->ctl_entry
);
1544 void sysctl_head_get(struct ctl_table_header
*head
)
1546 spin_lock(&sysctl_lock
);
1548 spin_unlock(&sysctl_lock
);
1551 void sysctl_head_put(struct ctl_table_header
*head
)
1553 spin_lock(&sysctl_lock
);
1556 spin_unlock(&sysctl_lock
);
1559 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1563 spin_lock(&sysctl_lock
);
1564 if (!use_table(head
))
1565 head
= ERR_PTR(-ENOENT
);
1566 spin_unlock(&sysctl_lock
);
1570 void sysctl_head_finish(struct ctl_table_header
*head
)
1574 spin_lock(&sysctl_lock
);
1576 spin_unlock(&sysctl_lock
);
1579 static struct ctl_table_set
*
1580 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1582 struct ctl_table_set
*set
= &root
->default_set
;
1584 set
= root
->lookup(root
, namespaces
);
1588 static struct list_head
*
1589 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1591 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1595 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1596 struct ctl_table_header
*prev
)
1598 struct ctl_table_root
*root
;
1599 struct list_head
*header_list
;
1600 struct ctl_table_header
*head
;
1601 struct list_head
*tmp
;
1603 spin_lock(&sysctl_lock
);
1606 tmp
= &prev
->ctl_entry
;
1610 tmp
= &root_table_header
.ctl_entry
;
1612 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1614 if (!use_table(head
))
1616 spin_unlock(&sysctl_lock
);
1621 header_list
= lookup_header_list(root
, namespaces
);
1622 if (tmp
!= header_list
)
1626 root
= list_entry(root
->root_list
.next
,
1627 struct ctl_table_root
, root_list
);
1628 if (root
== &sysctl_table_root
)
1630 header_list
= lookup_header_list(root
, namespaces
);
1631 } while (list_empty(header_list
));
1632 tmp
= header_list
->next
;
1635 spin_unlock(&sysctl_lock
);
1639 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1641 return __sysctl_head_next(current
->nsproxy
, prev
);
1644 void register_sysctl_root(struct ctl_table_root
*root
)
1646 spin_lock(&sysctl_lock
);
1647 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1648 spin_unlock(&sysctl_lock
);
1651 #ifdef CONFIG_SYSCTL_SYSCALL
1652 /* Perform the actual read/write of a sysctl table entry. */
1653 static int do_sysctl_strategy(struct ctl_table_root
*root
,
1654 struct ctl_table
*table
,
1655 void __user
*oldval
, size_t __user
*oldlenp
,
1656 void __user
*newval
, size_t newlen
)
1664 if (sysctl_perm(root
, table
, op
))
1667 if (table
->strategy
) {
1668 rc
= table
->strategy(table
, oldval
, oldlenp
, newval
, newlen
);
1675 /* If there is no strategy routine, or if the strategy returns
1676 * zero, proceed with automatic r/w */
1677 if (table
->data
&& table
->maxlen
) {
1678 rc
= sysctl_data(table
, oldval
, oldlenp
, newval
, newlen
);
1685 static int parse_table(int __user
*name
, int nlen
,
1686 void __user
*oldval
, size_t __user
*oldlenp
,
1687 void __user
*newval
, size_t newlen
,
1688 struct ctl_table_root
*root
,
1689 struct ctl_table
*table
)
1695 if (get_user(n
, name
))
1697 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1698 if (!table
->ctl_name
)
1700 if (n
== table
->ctl_name
) {
1703 if (sysctl_perm(root
, table
, MAY_EXEC
))
1707 table
= table
->child
;
1710 error
= do_sysctl_strategy(root
, table
,
1719 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1720 void __user
*newval
, size_t newlen
)
1722 struct ctl_table_header
*head
;
1723 int error
= -ENOTDIR
;
1725 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1729 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1733 for (head
= sysctl_head_next(NULL
); head
;
1734 head
= sysctl_head_next(head
)) {
1735 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1737 head
->root
, head
->ctl_table
);
1738 if (error
!= -ENOTDIR
) {
1739 sysctl_head_finish(head
);
1746 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
1748 struct __sysctl_args tmp
;
1751 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1754 error
= deprecated_sysctl_warning(&tmp
);
1759 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1760 tmp
.newval
, tmp
.newlen
);
1765 #endif /* CONFIG_SYSCTL_SYSCALL */
1768 * sysctl_perm does NOT grant the superuser all rights automatically, because
1769 * some sysctl variables are readonly even to root.
1772 static int test_perm(int mode
, int op
)
1774 if (!current_euid())
1776 else if (in_egroup_p(0))
1778 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1783 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1788 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1792 if (root
->permissions
)
1793 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1797 return test_perm(mode
, op
);
1800 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1802 for (; table
->ctl_name
|| table
->procname
; table
++) {
1803 table
->parent
= parent
;
1805 sysctl_set_parent(table
, table
->child
);
1809 static __init
int sysctl_init(void)
1811 sysctl_set_parent(NULL
, root_table
);
1812 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1815 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1821 core_initcall(sysctl_init
);
1823 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1824 struct ctl_table
*table
)
1826 struct ctl_table
*p
;
1827 const char *s
= branch
->procname
;
1829 /* branch should have named subdirectory as its first element */
1830 if (!s
|| !branch
->child
)
1833 /* ... and nothing else */
1834 if (branch
[1].procname
|| branch
[1].ctl_name
)
1837 /* table should contain subdirectory with the same name */
1838 for (p
= table
; p
->procname
|| p
->ctl_name
; p
++) {
1841 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1847 /* see if attaching q to p would be an improvement */
1848 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1850 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1851 struct ctl_table
*next
;
1853 int not_in_parent
= !p
->attached_by
;
1855 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1856 if (by
== q
->attached_by
)
1858 if (to
== p
->attached_by
)
1864 if (is_better
&& not_in_parent
) {
1865 q
->attached_by
= by
;
1866 q
->attached_to
= to
;
1872 * __register_sysctl_paths - register a sysctl hierarchy
1873 * @root: List of sysctl headers to register on
1874 * @namespaces: Data to compute which lists of sysctl entries are visible
1875 * @path: The path to the directory the sysctl table is in.
1876 * @table: the top-level table structure
1878 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1879 * array. A completely 0 filled entry terminates the table.
1881 * The members of the &struct ctl_table structure are used as follows:
1883 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1884 * must be unique within that level of sysctl
1886 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1887 * enter a sysctl file
1889 * data - a pointer to data for use by proc_handler
1891 * maxlen - the maximum size in bytes of the data
1893 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1895 * child - a pointer to the child sysctl table if this entry is a directory, or
1898 * proc_handler - the text handler routine (described below)
1900 * strategy - the strategy routine (described below)
1902 * de - for internal use by the sysctl routines
1904 * extra1, extra2 - extra pointers usable by the proc handler routines
1906 * Leaf nodes in the sysctl tree will be represented by a single file
1907 * under /proc; non-leaf nodes will be represented by directories.
1909 * sysctl(2) can automatically manage read and write requests through
1910 * the sysctl table. The data and maxlen fields of the ctl_table
1911 * struct enable minimal validation of the values being written to be
1912 * performed, and the mode field allows minimal authentication.
1914 * More sophisticated management can be enabled by the provision of a
1915 * strategy routine with the table entry. This will be called before
1916 * any automatic read or write of the data is performed.
1918 * The strategy routine may return
1920 * < 0 - Error occurred (error is passed to user process)
1922 * 0 - OK - proceed with automatic read or write.
1924 * > 0 - OK - read or write has been done by the strategy routine, so
1925 * return immediately.
1927 * There must be a proc_handler routine for any terminal nodes
1928 * mirrored under /proc/sys (non-terminals are handled by a built-in
1929 * directory handler). Several default handlers are available to
1930 * cover common cases -
1932 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1933 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1934 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1936 * It is the handler's job to read the input buffer from user memory
1937 * and process it. The handler should return 0 on success.
1939 * This routine returns %NULL on a failure to register, and a pointer
1940 * to the table header on success.
1942 struct ctl_table_header
*__register_sysctl_paths(
1943 struct ctl_table_root
*root
,
1944 struct nsproxy
*namespaces
,
1945 const struct ctl_path
*path
, struct ctl_table
*table
)
1947 struct ctl_table_header
*header
;
1948 struct ctl_table
*new, **prevp
;
1949 unsigned int n
, npath
;
1950 struct ctl_table_set
*set
;
1952 /* Count the path components */
1953 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
1957 * For each path component, allocate a 2-element ctl_table array.
1958 * The first array element will be filled with the sysctl entry
1959 * for this, the second will be the sentinel (ctl_name == 0).
1961 * We allocate everything in one go so that we don't have to
1962 * worry about freeing additional memory in unregister_sysctl_table.
1964 header
= kzalloc(sizeof(struct ctl_table_header
) +
1965 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1969 new = (struct ctl_table
*) (header
+ 1);
1971 /* Now connect the dots */
1972 prevp
= &header
->ctl_table
;
1973 for (n
= 0; n
< npath
; ++n
, ++path
) {
1974 /* Copy the procname */
1975 new->procname
= path
->procname
;
1976 new->ctl_name
= path
->ctl_name
;
1980 prevp
= &new->child
;
1985 header
->ctl_table_arg
= table
;
1987 INIT_LIST_HEAD(&header
->ctl_entry
);
1989 header
->unregistering
= NULL
;
1990 header
->root
= root
;
1991 sysctl_set_parent(NULL
, header
->ctl_table
);
1993 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1994 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1999 spin_lock(&sysctl_lock
);
2000 header
->set
= lookup_header_set(root
, namespaces
);
2001 header
->attached_by
= header
->ctl_table
;
2002 header
->attached_to
= root_table
;
2003 header
->parent
= &root_table_header
;
2004 for (set
= header
->set
; set
; set
= set
->parent
) {
2005 struct ctl_table_header
*p
;
2006 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
2007 if (p
->unregistering
)
2009 try_attach(p
, header
);
2012 header
->parent
->count
++;
2013 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
2014 spin_unlock(&sysctl_lock
);
2020 * register_sysctl_table_path - register a sysctl table hierarchy
2021 * @path: The path to the directory the sysctl table is in.
2022 * @table: the top-level table structure
2024 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2025 * array. A completely 0 filled entry terminates the table.
2027 * See __register_sysctl_paths for more details.
2029 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2030 struct ctl_table
*table
)
2032 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
2037 * register_sysctl_table - register a sysctl table hierarchy
2038 * @table: the top-level table structure
2040 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2041 * array. A completely 0 filled entry terminates the table.
2043 * See register_sysctl_paths for more details.
2045 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
2047 static const struct ctl_path null_path
[] = { {} };
2049 return register_sysctl_paths(null_path
, table
);
2053 * unregister_sysctl_table - unregister a sysctl table hierarchy
2054 * @header: the header returned from register_sysctl_table
2056 * Unregisters the sysctl table and all children. proc entries may not
2057 * actually be removed until they are no longer used by anyone.
2059 void unregister_sysctl_table(struct ctl_table_header
* header
)
2066 spin_lock(&sysctl_lock
);
2067 start_unregistering(header
);
2068 if (!--header
->parent
->count
) {
2070 kfree(header
->parent
);
2072 if (!--header
->count
)
2074 spin_unlock(&sysctl_lock
);
2077 int sysctl_is_seen(struct ctl_table_header
*p
)
2079 struct ctl_table_set
*set
= p
->set
;
2081 spin_lock(&sysctl_lock
);
2082 if (p
->unregistering
)
2084 else if (!set
->is_seen
)
2087 res
= set
->is_seen(set
);
2088 spin_unlock(&sysctl_lock
);
2092 void setup_sysctl_set(struct ctl_table_set
*p
,
2093 struct ctl_table_set
*parent
,
2094 int (*is_seen
)(struct ctl_table_set
*))
2096 INIT_LIST_HEAD(&p
->list
);
2097 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
2098 p
->is_seen
= is_seen
;
2101 #else /* !CONFIG_SYSCTL */
2102 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
2107 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2108 struct ctl_table
*table
)
2113 void unregister_sysctl_table(struct ctl_table_header
* table
)
2117 void setup_sysctl_set(struct ctl_table_set
*p
,
2118 struct ctl_table_set
*parent
,
2119 int (*is_seen
)(struct ctl_table_set
*))
2123 void sysctl_head_put(struct ctl_table_header
*head
)
2127 #endif /* CONFIG_SYSCTL */
2133 #ifdef CONFIG_PROC_SYSCTL
2135 static int _proc_do_string(void* data
, int maxlen
, int write
,
2136 struct file
*filp
, void __user
*buffer
,
2137 size_t *lenp
, loff_t
*ppos
)
2143 if (!data
|| !maxlen
|| !*lenp
) {
2151 while (len
< *lenp
) {
2152 if (get_user(c
, p
++))
2154 if (c
== 0 || c
== '\n')
2160 if(copy_from_user(data
, buffer
, len
))
2162 ((char *) data
)[len
] = 0;
2180 if(copy_to_user(buffer
, data
, len
))
2183 if(put_user('\n', ((char __user
*) buffer
) + len
))
2194 * proc_dostring - read a string sysctl
2195 * @table: the sysctl table
2196 * @write: %TRUE if this is a write to the sysctl file
2197 * @filp: the file structure
2198 * @buffer: the user buffer
2199 * @lenp: the size of the user buffer
2200 * @ppos: file position
2202 * Reads/writes a string from/to the user buffer. If the kernel
2203 * buffer provided is not large enough to hold the string, the
2204 * string is truncated. The copied string is %NULL-terminated.
2205 * If the string is being read by the user process, it is copied
2206 * and a newline '\n' is added. It is truncated if the buffer is
2209 * Returns 0 on success.
2211 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2212 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2214 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
2215 buffer
, lenp
, ppos
);
2219 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
2221 int write
, void *data
)
2224 *valp
= *negp
? -*lvalp
: *lvalp
;
2229 *lvalp
= (unsigned long)-val
;
2232 *lvalp
= (unsigned long)val
;
2238 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2239 int write
, struct file
*filp
, void __user
*buffer
,
2240 size_t *lenp
, loff_t
*ppos
,
2241 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2242 int write
, void *data
),
2245 #define TMPBUFLEN 21
2246 int *i
, vleft
, first
=1, neg
, val
;
2250 char buf
[TMPBUFLEN
], *p
;
2251 char __user
*s
= buffer
;
2253 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
2254 (*ppos
&& !write
)) {
2259 i
= (int *) tbl_data
;
2260 vleft
= table
->maxlen
/ sizeof(*i
);
2264 conv
= do_proc_dointvec_conv
;
2266 for (; left
&& vleft
--; i
++, first
=0) {
2281 if (len
> sizeof(buf
) - 1)
2282 len
= sizeof(buf
) - 1;
2283 if (copy_from_user(buf
, s
, len
))
2287 if (*p
== '-' && left
> 1) {
2291 if (*p
< '0' || *p
> '9')
2294 lval
= simple_strtoul(p
, &p
, 0);
2297 if ((len
< left
) && *p
&& !isspace(*p
))
2304 if (conv(&neg
, &lval
, i
, 1, data
))
2311 if (conv(&neg
, &lval
, i
, 0, data
))
2314 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2318 if(copy_to_user(s
, buf
, len
))
2325 if (!write
&& !first
&& left
) {
2326 if(put_user('\n', s
))
2333 if (get_user(c
, s
++))
2348 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2349 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2350 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2351 int write
, void *data
),
2354 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2355 buffer
, lenp
, ppos
, conv
, data
);
2359 * proc_dointvec - read a vector of integers
2360 * @table: the sysctl table
2361 * @write: %TRUE if this is a write to the sysctl file
2362 * @filp: the file structure
2363 * @buffer: the user buffer
2364 * @lenp: the size of the user buffer
2365 * @ppos: file position
2367 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2368 * values from/to the user buffer, treated as an ASCII string.
2370 * Returns 0 on success.
2372 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2373 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2375 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2380 * Taint values can only be increased
2381 * This means we can safely use a temporary.
2383 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2384 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2387 unsigned long tmptaint
= get_taint();
2390 if (write
&& !capable(CAP_SYS_ADMIN
))
2395 err
= proc_doulongvec_minmax(&t
, write
, filp
, buffer
, lenp
, ppos
);
2401 * Poor man's atomic or. Not worth adding a primitive
2402 * to everyone's atomic.h for this
2405 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2406 if ((tmptaint
>> i
) & 1)
2414 struct do_proc_dointvec_minmax_conv_param
{
2419 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2421 int write
, void *data
)
2423 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2425 int val
= *negp
? -*lvalp
: *lvalp
;
2426 if ((param
->min
&& *param
->min
> val
) ||
2427 (param
->max
&& *param
->max
< val
))
2434 *lvalp
= (unsigned long)-val
;
2437 *lvalp
= (unsigned long)val
;
2444 * proc_dointvec_minmax - read a vector of integers with min/max values
2445 * @table: the sysctl table
2446 * @write: %TRUE if this is a write to the sysctl file
2447 * @filp: the file structure
2448 * @buffer: the user buffer
2449 * @lenp: the size of the user buffer
2450 * @ppos: file position
2452 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2453 * values from/to the user buffer, treated as an ASCII string.
2455 * This routine will ensure the values are within the range specified by
2456 * table->extra1 (min) and table->extra2 (max).
2458 * Returns 0 on success.
2460 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2461 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2463 struct do_proc_dointvec_minmax_conv_param param
= {
2464 .min
= (int *) table
->extra1
,
2465 .max
= (int *) table
->extra2
,
2467 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2468 do_proc_dointvec_minmax_conv
, ¶m
);
2471 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2473 void __user
*buffer
,
2474 size_t *lenp
, loff_t
*ppos
,
2475 unsigned long convmul
,
2476 unsigned long convdiv
)
2478 #define TMPBUFLEN 21
2479 unsigned long *i
, *min
, *max
, val
;
2480 int vleft
, first
=1, neg
;
2482 char buf
[TMPBUFLEN
], *p
;
2483 char __user
*s
= buffer
;
2485 if (!data
|| !table
->maxlen
|| !*lenp
||
2486 (*ppos
&& !write
)) {
2491 i
= (unsigned long *) data
;
2492 min
= (unsigned long *) table
->extra1
;
2493 max
= (unsigned long *) table
->extra2
;
2494 vleft
= table
->maxlen
/ sizeof(unsigned long);
2497 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2512 if (len
> TMPBUFLEN
-1)
2514 if (copy_from_user(buf
, s
, len
))
2518 if (*p
== '-' && left
> 1) {
2522 if (*p
< '0' || *p
> '9')
2524 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2526 if ((len
< left
) && *p
&& !isspace(*p
))
2535 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2542 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2546 if(copy_to_user(s
, buf
, len
))
2553 if (!write
&& !first
&& left
) {
2554 if(put_user('\n', s
))
2561 if (get_user(c
, s
++))
2576 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2578 void __user
*buffer
,
2579 size_t *lenp
, loff_t
*ppos
,
2580 unsigned long convmul
,
2581 unsigned long convdiv
)
2583 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2584 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2588 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2589 * @table: the sysctl table
2590 * @write: %TRUE if this is a write to the sysctl file
2591 * @filp: the file structure
2592 * @buffer: the user buffer
2593 * @lenp: the size of the user buffer
2594 * @ppos: file position
2596 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2597 * values from/to the user buffer, treated as an ASCII string.
2599 * This routine will ensure the values are within the range specified by
2600 * table->extra1 (min) and table->extra2 (max).
2602 * Returns 0 on success.
2604 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2605 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2607 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2611 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2612 * @table: the sysctl table
2613 * @write: %TRUE if this is a write to the sysctl file
2614 * @filp: the file structure
2615 * @buffer: the user buffer
2616 * @lenp: the size of the user buffer
2617 * @ppos: file position
2619 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2620 * values from/to the user buffer, treated as an ASCII string. The values
2621 * are treated as milliseconds, and converted to jiffies when they are stored.
2623 * This routine will ensure the values are within the range specified by
2624 * table->extra1 (min) and table->extra2 (max).
2626 * Returns 0 on success.
2628 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2630 void __user
*buffer
,
2631 size_t *lenp
, loff_t
*ppos
)
2633 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2634 lenp
, ppos
, HZ
, 1000l);
2638 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2640 int write
, void *data
)
2643 if (*lvalp
> LONG_MAX
/ HZ
)
2645 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2651 lval
= (unsigned long)-val
;
2654 lval
= (unsigned long)val
;
2661 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2663 int write
, void *data
)
2666 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2668 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2674 lval
= (unsigned long)-val
;
2677 lval
= (unsigned long)val
;
2679 *lvalp
= jiffies_to_clock_t(lval
);
2684 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2686 int write
, void *data
)
2689 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2695 lval
= (unsigned long)-val
;
2698 lval
= (unsigned long)val
;
2700 *lvalp
= jiffies_to_msecs(lval
);
2706 * proc_dointvec_jiffies - read a vector of integers as seconds
2707 * @table: the sysctl table
2708 * @write: %TRUE if this is a write to the sysctl file
2709 * @filp: the file structure
2710 * @buffer: the user buffer
2711 * @lenp: the size of the user buffer
2712 * @ppos: file position
2714 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2715 * values from/to the user buffer, treated as an ASCII string.
2716 * The values read are assumed to be in seconds, and are converted into
2719 * Returns 0 on success.
2721 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2722 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2724 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2725 do_proc_dointvec_jiffies_conv
,NULL
);
2729 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2730 * @table: the sysctl table
2731 * @write: %TRUE if this is a write to the sysctl file
2732 * @filp: the file structure
2733 * @buffer: the user buffer
2734 * @lenp: the size of the user buffer
2735 * @ppos: pointer to the file position
2737 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2738 * values from/to the user buffer, treated as an ASCII string.
2739 * The values read are assumed to be in 1/USER_HZ seconds, and
2740 * are converted into jiffies.
2742 * Returns 0 on success.
2744 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2745 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2747 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2748 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2752 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2753 * @table: the sysctl table
2754 * @write: %TRUE if this is a write to the sysctl file
2755 * @filp: the file structure
2756 * @buffer: the user buffer
2757 * @lenp: the size of the user buffer
2758 * @ppos: file position
2759 * @ppos: the current position in the file
2761 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2762 * values from/to the user buffer, treated as an ASCII string.
2763 * The values read are assumed to be in 1/1000 seconds, and
2764 * are converted into jiffies.
2766 * Returns 0 on success.
2768 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2769 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2771 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2772 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2775 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2776 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2778 struct pid
*new_pid
;
2782 tmp
= pid_vnr(cad_pid
);
2784 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2785 lenp
, ppos
, NULL
, NULL
);
2789 new_pid
= find_get_pid(tmp
);
2793 put_pid(xchg(&cad_pid
, new_pid
));
2797 #else /* CONFIG_PROC_FS */
2799 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2800 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2805 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2806 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2811 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2812 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2817 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2818 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2823 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2824 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2829 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2830 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2835 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2836 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2841 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2843 void __user
*buffer
,
2844 size_t *lenp
, loff_t
*ppos
)
2850 #endif /* CONFIG_PROC_FS */
2853 #ifdef CONFIG_SYSCTL_SYSCALL
2855 * General sysctl support routines
2858 /* The generic sysctl data routine (used if no strategy routine supplied) */
2859 int sysctl_data(struct ctl_table
*table
,
2860 void __user
*oldval
, size_t __user
*oldlenp
,
2861 void __user
*newval
, size_t newlen
)
2865 /* Get out of I don't have a variable */
2866 if (!table
->data
|| !table
->maxlen
)
2869 if (oldval
&& oldlenp
) {
2870 if (get_user(len
, oldlenp
))
2873 if (len
> table
->maxlen
)
2874 len
= table
->maxlen
;
2875 if (copy_to_user(oldval
, table
->data
, len
))
2877 if (put_user(len
, oldlenp
))
2882 if (newval
&& newlen
) {
2883 if (newlen
> table
->maxlen
)
2884 newlen
= table
->maxlen
;
2886 if (copy_from_user(table
->data
, newval
, newlen
))
2892 /* The generic string strategy routine: */
2893 int sysctl_string(struct ctl_table
*table
,
2894 void __user
*oldval
, size_t __user
*oldlenp
,
2895 void __user
*newval
, size_t newlen
)
2897 if (!table
->data
|| !table
->maxlen
)
2900 if (oldval
&& oldlenp
) {
2902 if (get_user(bufsize
, oldlenp
))
2905 size_t len
= strlen(table
->data
), copied
;
2907 /* This shouldn't trigger for a well-formed sysctl */
2908 if (len
> table
->maxlen
)
2909 len
= table
->maxlen
;
2911 /* Copy up to a max of bufsize-1 bytes of the string */
2912 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2914 if (copy_to_user(oldval
, table
->data
, copied
) ||
2915 put_user(0, (char __user
*)(oldval
+ copied
)))
2917 if (put_user(len
, oldlenp
))
2921 if (newval
&& newlen
) {
2922 size_t len
= newlen
;
2923 if (len
> table
->maxlen
)
2924 len
= table
->maxlen
;
2925 if(copy_from_user(table
->data
, newval
, len
))
2927 if (len
== table
->maxlen
)
2929 ((char *) table
->data
)[len
] = 0;
2935 * This function makes sure that all of the integers in the vector
2936 * are between the minimum and maximum values given in the arrays
2937 * table->extra1 and table->extra2, respectively.
2939 int sysctl_intvec(struct ctl_table
*table
,
2940 void __user
*oldval
, size_t __user
*oldlenp
,
2941 void __user
*newval
, size_t newlen
)
2944 if (newval
&& newlen
) {
2945 int __user
*vec
= (int __user
*) newval
;
2946 int *min
= (int *) table
->extra1
;
2947 int *max
= (int *) table
->extra2
;
2951 if (newlen
% sizeof(int) != 0)
2954 if (!table
->extra1
&& !table
->extra2
)
2957 if (newlen
> table
->maxlen
)
2958 newlen
= table
->maxlen
;
2959 length
= newlen
/ sizeof(int);
2961 for (i
= 0; i
< length
; i
++) {
2963 if (get_user(value
, vec
+ i
))
2965 if (min
&& value
< min
[i
])
2967 if (max
&& value
> max
[i
])
2974 /* Strategy function to convert jiffies to seconds */
2975 int sysctl_jiffies(struct ctl_table
*table
,
2976 void __user
*oldval
, size_t __user
*oldlenp
,
2977 void __user
*newval
, size_t newlen
)
2979 if (oldval
&& oldlenp
) {
2982 if (get_user(olen
, oldlenp
))
2987 if (olen
< sizeof(int))
2990 val
= *(int *)(table
->data
) / HZ
;
2991 if (put_user(val
, (int __user
*)oldval
))
2993 if (put_user(sizeof(int), oldlenp
))
2997 if (newval
&& newlen
) {
2999 if (newlen
!= sizeof(int))
3001 if (get_user(new, (int __user
*)newval
))
3003 *(int *)(table
->data
) = new*HZ
;
3008 /* Strategy function to convert jiffies to seconds */
3009 int sysctl_ms_jiffies(struct ctl_table
*table
,
3010 void __user
*oldval
, size_t __user
*oldlenp
,
3011 void __user
*newval
, size_t newlen
)
3013 if (oldval
&& oldlenp
) {
3016 if (get_user(olen
, oldlenp
))
3021 if (olen
< sizeof(int))
3024 val
= jiffies_to_msecs(*(int *)(table
->data
));
3025 if (put_user(val
, (int __user
*)oldval
))
3027 if (put_user(sizeof(int), oldlenp
))
3031 if (newval
&& newlen
) {
3033 if (newlen
!= sizeof(int))
3035 if (get_user(new, (int __user
*)newval
))
3037 *(int *)(table
->data
) = msecs_to_jiffies(new);
3044 #else /* CONFIG_SYSCTL_SYSCALL */
3047 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
3049 struct __sysctl_args tmp
;
3052 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
3055 error
= deprecated_sysctl_warning(&tmp
);
3057 /* If no error reading the parameters then just -ENOSYS ... */
3064 int sysctl_data(struct ctl_table
*table
,
3065 void __user
*oldval
, size_t __user
*oldlenp
,
3066 void __user
*newval
, size_t newlen
)
3071 int sysctl_string(struct ctl_table
*table
,
3072 void __user
*oldval
, size_t __user
*oldlenp
,
3073 void __user
*newval
, size_t newlen
)
3078 int sysctl_intvec(struct ctl_table
*table
,
3079 void __user
*oldval
, size_t __user
*oldlenp
,
3080 void __user
*newval
, size_t newlen
)
3085 int sysctl_jiffies(struct ctl_table
*table
,
3086 void __user
*oldval
, size_t __user
*oldlenp
,
3087 void __user
*newval
, size_t newlen
)
3092 int sysctl_ms_jiffies(struct ctl_table
*table
,
3093 void __user
*oldval
, size_t __user
*oldlenp
,
3094 void __user
*newval
, size_t newlen
)
3099 #endif /* CONFIG_SYSCTL_SYSCALL */
3101 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
3103 static int msg_count
;
3104 int name
[CTL_MAXNAME
];
3107 /* Check args->nlen. */
3108 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
3111 /* Read in the sysctl name for better debug message logging */
3112 for (i
= 0; i
< args
->nlen
; i
++)
3113 if (get_user(name
[i
], args
->name
+ i
))
3116 /* Ignore accesses to kernel.version */
3117 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
3120 if (msg_count
< 5) {
3123 "warning: process `%s' used the deprecated sysctl "
3124 "system call with ", current
->comm
);
3125 for (i
= 0; i
< args
->nlen
; i
++)
3126 printk("%d.", name
[i
]);
3133 * No sense putting this after each symbol definition, twice,
3134 * exception granted :-)
3136 EXPORT_SYMBOL(proc_dointvec
);
3137 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3138 EXPORT_SYMBOL(proc_dointvec_minmax
);
3139 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3140 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3141 EXPORT_SYMBOL(proc_dostring
);
3142 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3143 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
3144 EXPORT_SYMBOL(register_sysctl_table
);
3145 EXPORT_SYMBOL(register_sysctl_paths
);
3146 EXPORT_SYMBOL(sysctl_intvec
);
3147 EXPORT_SYMBOL(sysctl_jiffies
);
3148 EXPORT_SYMBOL(sysctl_ms_jiffies
);
3149 EXPORT_SYMBOL(sysctl_string
);
3150 EXPORT_SYMBOL(sysctl_data
);
3151 EXPORT_SYMBOL(unregister_sysctl_table
);