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>
52 #include <linux/perf_counter.h>
54 #include <asm/uaccess.h>
55 #include <asm/processor.h>
59 #include <asm/stacktrace.h>
63 static int deprecated_sysctl_warning(struct __sysctl_args
*args
);
65 #if defined(CONFIG_SYSCTL)
67 /* External variables not in a header file. */
69 extern int print_fatal_signals
;
70 extern int sysctl_overcommit_memory
;
71 extern int sysctl_overcommit_ratio
;
72 extern int sysctl_panic_on_oom
;
73 extern int sysctl_oom_kill_allocating_task
;
74 extern int sysctl_oom_dump_tasks
;
75 extern int max_threads
;
76 extern int core_uses_pid
;
77 extern int suid_dumpable
;
78 extern char core_pattern
[];
80 extern int min_free_kbytes
;
81 extern int pid_max_min
, pid_max_max
;
82 extern int sysctl_drop_caches
;
83 extern int percpu_pagelist_fraction
;
84 extern int compat_log
;
85 extern int latencytop_enabled
;
86 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
88 extern int sysctl_nr_trim_pages
;
90 #ifdef CONFIG_RCU_TORTURE_TEST
91 extern int rcutorture_runnable
;
92 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
94 /* Constants used for minimum and maximum */
95 #ifdef CONFIG_DETECT_SOFTLOCKUP
96 static int sixty
= 60;
97 static int neg_one
= -1;
101 static int __maybe_unused one
= 1;
102 static int __maybe_unused two
= 2;
103 static unsigned long one_ul
= 1;
104 static int one_hundred
= 100;
105 static int one_thousand
= 1000;
107 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
108 static int maxolduid
= 65535;
109 static int minolduid
;
110 static int min_percpu_pagelist_fract
= 8;
112 static int ngroups_max
= NGROUPS_MAX
;
114 #ifdef CONFIG_MODULES
115 extern char modprobe_path
[];
117 #ifdef CONFIG_CHR_DEV_SG
118 extern int sg_big_buff
;
122 #include <asm/system.h>
125 #ifdef CONFIG_SPARC64
126 extern int sysctl_tsb_ratio
;
130 extern int pwrsw_enabled
;
131 extern int unaligned_enabled
;
135 #ifdef CONFIG_MATHEMU
136 extern int sysctl_ieee_emulation_warnings
;
138 extern int sysctl_userprocess_debug
;
139 extern int spin_retry
;
142 #ifdef CONFIG_BSD_PROCESS_ACCT
143 extern int acct_parm
[];
147 extern int no_unaligned_warning
;
148 extern int unaligned_dump_stack
;
151 #ifdef CONFIG_RT_MUTEXES
152 extern int max_lock_depth
;
155 #ifdef CONFIG_PROC_SYSCTL
156 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
157 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
158 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
159 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
162 static struct ctl_table root_table
[];
163 static struct ctl_table_root sysctl_table_root
;
164 static struct ctl_table_header root_table_header
= {
166 .ctl_table
= root_table
,
167 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),
168 .root
= &sysctl_table_root
,
169 .set
= &sysctl_table_root
.default_set
,
171 static struct ctl_table_root sysctl_table_root
= {
172 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
173 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
176 static struct ctl_table kern_table
[];
177 static struct ctl_table vm_table
[];
178 static struct ctl_table fs_table
[];
179 static struct ctl_table debug_table
[];
180 static struct ctl_table dev_table
[];
181 extern struct ctl_table random_table
[];
182 #ifdef CONFIG_INOTIFY_USER
183 extern struct ctl_table inotify_table
[];
186 extern struct ctl_table epoll_table
[];
189 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
190 int sysctl_legacy_va_layout
;
193 extern int prove_locking
;
194 extern int lock_stat
;
196 /* The default sysctl tables: */
198 static struct ctl_table root_table
[] = {
200 .ctl_name
= CTL_KERN
,
201 .procname
= "kernel",
218 .ctl_name
= CTL_DEBUG
,
221 .child
= debug_table
,
230 * NOTE: do not add new entries to this table unless you have read
231 * Documentation/sysctl/ctl_unnumbered.txt
236 #ifdef CONFIG_SCHED_DEBUG
237 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
238 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
239 static int min_wakeup_granularity_ns
; /* 0 usecs */
240 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
243 static struct ctl_table kern_table
[] = {
244 #ifdef CONFIG_SCHED_DEBUG
246 .ctl_name
= CTL_UNNUMBERED
,
247 .procname
= "sched_min_granularity_ns",
248 .data
= &sysctl_sched_min_granularity
,
249 .maxlen
= sizeof(unsigned int),
251 .proc_handler
= &sched_nr_latency_handler
,
252 .strategy
= &sysctl_intvec
,
253 .extra1
= &min_sched_granularity_ns
,
254 .extra2
= &max_sched_granularity_ns
,
257 .ctl_name
= CTL_UNNUMBERED
,
258 .procname
= "sched_latency_ns",
259 .data
= &sysctl_sched_latency
,
260 .maxlen
= sizeof(unsigned int),
262 .proc_handler
= &sched_nr_latency_handler
,
263 .strategy
= &sysctl_intvec
,
264 .extra1
= &min_sched_granularity_ns
,
265 .extra2
= &max_sched_granularity_ns
,
268 .ctl_name
= CTL_UNNUMBERED
,
269 .procname
= "sched_wakeup_granularity_ns",
270 .data
= &sysctl_sched_wakeup_granularity
,
271 .maxlen
= sizeof(unsigned int),
273 .proc_handler
= &proc_dointvec_minmax
,
274 .strategy
= &sysctl_intvec
,
275 .extra1
= &min_wakeup_granularity_ns
,
276 .extra2
= &max_wakeup_granularity_ns
,
279 .ctl_name
= CTL_UNNUMBERED
,
280 .procname
= "sched_shares_ratelimit",
281 .data
= &sysctl_sched_shares_ratelimit
,
282 .maxlen
= sizeof(unsigned int),
284 .proc_handler
= &proc_dointvec
,
287 .ctl_name
= CTL_UNNUMBERED
,
288 .procname
= "sched_shares_thresh",
289 .data
= &sysctl_sched_shares_thresh
,
290 .maxlen
= sizeof(unsigned int),
292 .proc_handler
= &proc_dointvec_minmax
,
293 .strategy
= &sysctl_intvec
,
297 .ctl_name
= CTL_UNNUMBERED
,
298 .procname
= "sched_child_runs_first",
299 .data
= &sysctl_sched_child_runs_first
,
300 .maxlen
= sizeof(unsigned int),
302 .proc_handler
= &proc_dointvec
,
305 .ctl_name
= CTL_UNNUMBERED
,
306 .procname
= "sched_features",
307 .data
= &sysctl_sched_features
,
308 .maxlen
= sizeof(unsigned int),
310 .proc_handler
= &proc_dointvec
,
313 .ctl_name
= CTL_UNNUMBERED
,
314 .procname
= "sched_migration_cost",
315 .data
= &sysctl_sched_migration_cost
,
316 .maxlen
= sizeof(unsigned int),
318 .proc_handler
= &proc_dointvec
,
321 .ctl_name
= CTL_UNNUMBERED
,
322 .procname
= "sched_nr_migrate",
323 .data
= &sysctl_sched_nr_migrate
,
324 .maxlen
= sizeof(unsigned int),
326 .proc_handler
= &proc_dointvec
,
330 .ctl_name
= CTL_UNNUMBERED
,
331 .procname
= "sched_rt_period_us",
332 .data
= &sysctl_sched_rt_period
,
333 .maxlen
= sizeof(unsigned int),
335 .proc_handler
= &sched_rt_handler
,
338 .ctl_name
= CTL_UNNUMBERED
,
339 .procname
= "sched_rt_runtime_us",
340 .data
= &sysctl_sched_rt_runtime
,
341 .maxlen
= sizeof(int),
343 .proc_handler
= &sched_rt_handler
,
346 .ctl_name
= CTL_UNNUMBERED
,
347 .procname
= "sched_compat_yield",
348 .data
= &sysctl_sched_compat_yield
,
349 .maxlen
= sizeof(unsigned int),
351 .proc_handler
= &proc_dointvec
,
353 #ifdef CONFIG_PROVE_LOCKING
355 .ctl_name
= CTL_UNNUMBERED
,
356 .procname
= "prove_locking",
357 .data
= &prove_locking
,
358 .maxlen
= sizeof(int),
360 .proc_handler
= &proc_dointvec
,
363 #ifdef CONFIG_LOCK_STAT
365 .ctl_name
= CTL_UNNUMBERED
,
366 .procname
= "lock_stat",
368 .maxlen
= sizeof(int),
370 .proc_handler
= &proc_dointvec
,
374 .ctl_name
= KERN_PANIC
,
376 .data
= &panic_timeout
,
377 .maxlen
= sizeof(int),
379 .proc_handler
= &proc_dointvec
,
382 .ctl_name
= KERN_CORE_USES_PID
,
383 .procname
= "core_uses_pid",
384 .data
= &core_uses_pid
,
385 .maxlen
= sizeof(int),
387 .proc_handler
= &proc_dointvec
,
390 .ctl_name
= KERN_CORE_PATTERN
,
391 .procname
= "core_pattern",
392 .data
= core_pattern
,
393 .maxlen
= CORENAME_MAX_SIZE
,
395 .proc_handler
= &proc_dostring
,
396 .strategy
= &sysctl_string
,
398 #ifdef CONFIG_PROC_SYSCTL
400 .procname
= "tainted",
401 .maxlen
= sizeof(long),
403 .proc_handler
= &proc_taint
,
406 #ifdef CONFIG_LATENCYTOP
408 .procname
= "latencytop",
409 .data
= &latencytop_enabled
,
410 .maxlen
= sizeof(int),
412 .proc_handler
= &proc_dointvec
,
415 #ifdef CONFIG_BLK_DEV_INITRD
417 .ctl_name
= KERN_REALROOTDEV
,
418 .procname
= "real-root-dev",
419 .data
= &real_root_dev
,
420 .maxlen
= sizeof(int),
422 .proc_handler
= &proc_dointvec
,
426 .ctl_name
= CTL_UNNUMBERED
,
427 .procname
= "print-fatal-signals",
428 .data
= &print_fatal_signals
,
429 .maxlen
= sizeof(int),
431 .proc_handler
= &proc_dointvec
,
435 .ctl_name
= KERN_SPARC_REBOOT
,
436 .procname
= "reboot-cmd",
437 .data
= reboot_command
,
440 .proc_handler
= &proc_dostring
,
441 .strategy
= &sysctl_string
,
444 .ctl_name
= KERN_SPARC_STOP_A
,
445 .procname
= "stop-a",
446 .data
= &stop_a_enabled
,
447 .maxlen
= sizeof (int),
449 .proc_handler
= &proc_dointvec
,
452 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
453 .procname
= "scons-poweroff",
454 .data
= &scons_pwroff
,
455 .maxlen
= sizeof (int),
457 .proc_handler
= &proc_dointvec
,
460 #ifdef CONFIG_SPARC64
462 .ctl_name
= CTL_UNNUMBERED
,
463 .procname
= "tsb-ratio",
464 .data
= &sysctl_tsb_ratio
,
465 .maxlen
= sizeof (int),
467 .proc_handler
= &proc_dointvec
,
472 .ctl_name
= KERN_HPPA_PWRSW
,
473 .procname
= "soft-power",
474 .data
= &pwrsw_enabled
,
475 .maxlen
= sizeof (int),
477 .proc_handler
= &proc_dointvec
,
480 .ctl_name
= KERN_HPPA_UNALIGNED
,
481 .procname
= "unaligned-trap",
482 .data
= &unaligned_enabled
,
483 .maxlen
= sizeof (int),
485 .proc_handler
= &proc_dointvec
,
489 .ctl_name
= KERN_CTLALTDEL
,
490 .procname
= "ctrl-alt-del",
492 .maxlen
= sizeof(int),
494 .proc_handler
= &proc_dointvec
,
496 #ifdef CONFIG_FUNCTION_TRACER
498 .ctl_name
= CTL_UNNUMBERED
,
499 .procname
= "ftrace_enabled",
500 .data
= &ftrace_enabled
,
501 .maxlen
= sizeof(int),
503 .proc_handler
= &ftrace_enable_sysctl
,
506 #ifdef CONFIG_STACK_TRACER
508 .ctl_name
= CTL_UNNUMBERED
,
509 .procname
= "stack_tracer_enabled",
510 .data
= &stack_tracer_enabled
,
511 .maxlen
= sizeof(int),
513 .proc_handler
= &stack_trace_sysctl
,
516 #ifdef CONFIG_TRACING
518 .ctl_name
= CTL_UNNUMBERED
,
519 .procname
= "ftrace_dump_on_oops",
520 .data
= &ftrace_dump_on_oops
,
521 .maxlen
= sizeof(int),
523 .proc_handler
= &proc_dointvec
,
526 #ifdef CONFIG_MODULES
528 .ctl_name
= KERN_MODPROBE
,
529 .procname
= "modprobe",
530 .data
= &modprobe_path
,
531 .maxlen
= KMOD_PATH_LEN
,
533 .proc_handler
= &proc_dostring
,
534 .strategy
= &sysctl_string
,
537 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
539 .ctl_name
= KERN_HOTPLUG
,
540 .procname
= "hotplug",
541 .data
= &uevent_helper
,
542 .maxlen
= UEVENT_HELPER_PATH_LEN
,
544 .proc_handler
= &proc_dostring
,
545 .strategy
= &sysctl_string
,
548 #ifdef CONFIG_CHR_DEV_SG
550 .ctl_name
= KERN_SG_BIG_BUFF
,
551 .procname
= "sg-big-buff",
552 .data
= &sg_big_buff
,
553 .maxlen
= sizeof (int),
555 .proc_handler
= &proc_dointvec
,
558 #ifdef CONFIG_BSD_PROCESS_ACCT
560 .ctl_name
= KERN_ACCT
,
563 .maxlen
= 3*sizeof(int),
565 .proc_handler
= &proc_dointvec
,
568 #ifdef CONFIG_MAGIC_SYSRQ
570 .ctl_name
= KERN_SYSRQ
,
572 .data
= &__sysrq_enabled
,
573 .maxlen
= sizeof (int),
575 .proc_handler
= &proc_dointvec
,
578 #ifdef CONFIG_PROC_SYSCTL
580 .procname
= "cad_pid",
582 .maxlen
= sizeof (int),
584 .proc_handler
= &proc_do_cad_pid
,
588 .ctl_name
= KERN_MAX_THREADS
,
589 .procname
= "threads-max",
590 .data
= &max_threads
,
591 .maxlen
= sizeof(int),
593 .proc_handler
= &proc_dointvec
,
596 .ctl_name
= KERN_RANDOM
,
597 .procname
= "random",
599 .child
= random_table
,
602 .ctl_name
= KERN_OVERFLOWUID
,
603 .procname
= "overflowuid",
604 .data
= &overflowuid
,
605 .maxlen
= sizeof(int),
607 .proc_handler
= &proc_dointvec_minmax
,
608 .strategy
= &sysctl_intvec
,
609 .extra1
= &minolduid
,
610 .extra2
= &maxolduid
,
613 .ctl_name
= KERN_OVERFLOWGID
,
614 .procname
= "overflowgid",
615 .data
= &overflowgid
,
616 .maxlen
= sizeof(int),
618 .proc_handler
= &proc_dointvec_minmax
,
619 .strategy
= &sysctl_intvec
,
620 .extra1
= &minolduid
,
621 .extra2
= &maxolduid
,
624 #ifdef CONFIG_MATHEMU
626 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
627 .procname
= "ieee_emulation_warnings",
628 .data
= &sysctl_ieee_emulation_warnings
,
629 .maxlen
= sizeof(int),
631 .proc_handler
= &proc_dointvec
,
635 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
636 .procname
= "userprocess_debug",
637 .data
= &sysctl_userprocess_debug
,
638 .maxlen
= sizeof(int),
640 .proc_handler
= &proc_dointvec
,
644 .ctl_name
= KERN_PIDMAX
,
645 .procname
= "pid_max",
647 .maxlen
= sizeof (int),
649 .proc_handler
= &proc_dointvec_minmax
,
650 .strategy
= sysctl_intvec
,
651 .extra1
= &pid_max_min
,
652 .extra2
= &pid_max_max
,
655 .ctl_name
= KERN_PANIC_ON_OOPS
,
656 .procname
= "panic_on_oops",
657 .data
= &panic_on_oops
,
658 .maxlen
= sizeof(int),
660 .proc_handler
= &proc_dointvec
,
662 #if defined CONFIG_PRINTK
664 .ctl_name
= KERN_PRINTK
,
665 .procname
= "printk",
666 .data
= &console_loglevel
,
667 .maxlen
= 4*sizeof(int),
669 .proc_handler
= &proc_dointvec
,
672 .ctl_name
= KERN_PRINTK_RATELIMIT
,
673 .procname
= "printk_ratelimit",
674 .data
= &printk_ratelimit_state
.interval
,
675 .maxlen
= sizeof(int),
677 .proc_handler
= &proc_dointvec_jiffies
,
678 .strategy
= &sysctl_jiffies
,
681 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
682 .procname
= "printk_ratelimit_burst",
683 .data
= &printk_ratelimit_state
.burst
,
684 .maxlen
= sizeof(int),
686 .proc_handler
= &proc_dointvec
,
690 .ctl_name
= KERN_NGROUPS_MAX
,
691 .procname
= "ngroups_max",
692 .data
= &ngroups_max
,
693 .maxlen
= sizeof (int),
695 .proc_handler
= &proc_dointvec
,
697 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
699 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
700 .procname
= "unknown_nmi_panic",
701 .data
= &unknown_nmi_panic
,
702 .maxlen
= sizeof (int),
704 .proc_handler
= &proc_dointvec
,
707 .procname
= "nmi_watchdog",
708 .data
= &nmi_watchdog_enabled
,
709 .maxlen
= sizeof (int),
711 .proc_handler
= &proc_nmi_enabled
,
714 #if defined(CONFIG_X86)
716 .ctl_name
= KERN_PANIC_ON_NMI
,
717 .procname
= "panic_on_unrecovered_nmi",
718 .data
= &panic_on_unrecovered_nmi
,
719 .maxlen
= sizeof(int),
721 .proc_handler
= &proc_dointvec
,
724 .ctl_name
= KERN_BOOTLOADER_TYPE
,
725 .procname
= "bootloader_type",
726 .data
= &bootloader_type
,
727 .maxlen
= sizeof (int),
729 .proc_handler
= &proc_dointvec
,
732 .ctl_name
= CTL_UNNUMBERED
,
733 .procname
= "kstack_depth_to_print",
734 .data
= &kstack_depth_to_print
,
735 .maxlen
= sizeof(int),
737 .proc_handler
= &proc_dointvec
,
740 .ctl_name
= CTL_UNNUMBERED
,
741 .procname
= "io_delay_type",
742 .data
= &io_delay_type
,
743 .maxlen
= sizeof(int),
745 .proc_handler
= &proc_dointvec
,
748 #if defined(CONFIG_MMU)
750 .ctl_name
= KERN_RANDOMIZE
,
751 .procname
= "randomize_va_space",
752 .data
= &randomize_va_space
,
753 .maxlen
= sizeof(int),
755 .proc_handler
= &proc_dointvec
,
758 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
760 .ctl_name
= KERN_SPIN_RETRY
,
761 .procname
= "spin_retry",
763 .maxlen
= sizeof (int),
765 .proc_handler
= &proc_dointvec
,
768 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
770 .procname
= "acpi_video_flags",
771 .data
= &acpi_realmode_flags
,
772 .maxlen
= sizeof (unsigned long),
774 .proc_handler
= &proc_doulongvec_minmax
,
779 .ctl_name
= KERN_IA64_UNALIGNED
,
780 .procname
= "ignore-unaligned-usertrap",
781 .data
= &no_unaligned_warning
,
782 .maxlen
= sizeof (int),
784 .proc_handler
= &proc_dointvec
,
787 .ctl_name
= CTL_UNNUMBERED
,
788 .procname
= "unaligned-dump-stack",
789 .data
= &unaligned_dump_stack
,
790 .maxlen
= sizeof (int),
792 .proc_handler
= &proc_dointvec
,
795 #ifdef CONFIG_DETECT_SOFTLOCKUP
797 .ctl_name
= CTL_UNNUMBERED
,
798 .procname
= "softlockup_panic",
799 .data
= &softlockup_panic
,
800 .maxlen
= sizeof(int),
802 .proc_handler
= &proc_dointvec_minmax
,
803 .strategy
= &sysctl_intvec
,
808 .ctl_name
= CTL_UNNUMBERED
,
809 .procname
= "softlockup_thresh",
810 .data
= &softlockup_thresh
,
811 .maxlen
= sizeof(int),
813 .proc_handler
= &proc_dosoftlockup_thresh
,
814 .strategy
= &sysctl_intvec
,
819 #ifdef CONFIG_DETECT_HUNG_TASK
821 .ctl_name
= CTL_UNNUMBERED
,
822 .procname
= "hung_task_panic",
823 .data
= &sysctl_hung_task_panic
,
824 .maxlen
= sizeof(int),
826 .proc_handler
= &proc_dointvec_minmax
,
827 .strategy
= &sysctl_intvec
,
832 .ctl_name
= CTL_UNNUMBERED
,
833 .procname
= "hung_task_check_count",
834 .data
= &sysctl_hung_task_check_count
,
835 .maxlen
= sizeof(unsigned long),
837 .proc_handler
= &proc_doulongvec_minmax
,
838 .strategy
= &sysctl_intvec
,
841 .ctl_name
= CTL_UNNUMBERED
,
842 .procname
= "hung_task_timeout_secs",
843 .data
= &sysctl_hung_task_timeout_secs
,
844 .maxlen
= sizeof(unsigned long),
846 .proc_handler
= &proc_dohung_task_timeout_secs
,
847 .strategy
= &sysctl_intvec
,
850 .ctl_name
= CTL_UNNUMBERED
,
851 .procname
= "hung_task_warnings",
852 .data
= &sysctl_hung_task_warnings
,
853 .maxlen
= sizeof(unsigned long),
855 .proc_handler
= &proc_doulongvec_minmax
,
856 .strategy
= &sysctl_intvec
,
861 .ctl_name
= KERN_COMPAT_LOG
,
862 .procname
= "compat-log",
864 .maxlen
= sizeof (int),
866 .proc_handler
= &proc_dointvec
,
869 #ifdef CONFIG_RT_MUTEXES
871 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
872 .procname
= "max_lock_depth",
873 .data
= &max_lock_depth
,
874 .maxlen
= sizeof(int),
876 .proc_handler
= &proc_dointvec
,
880 .ctl_name
= CTL_UNNUMBERED
,
881 .procname
= "poweroff_cmd",
882 .data
= &poweroff_cmd
,
883 .maxlen
= POWEROFF_CMD_PATH_LEN
,
885 .proc_handler
= &proc_dostring
,
886 .strategy
= &sysctl_string
,
890 .ctl_name
= CTL_UNNUMBERED
,
893 .child
= key_sysctls
,
896 #ifdef CONFIG_RCU_TORTURE_TEST
898 .ctl_name
= CTL_UNNUMBERED
,
899 .procname
= "rcutorture_runnable",
900 .data
= &rcutorture_runnable
,
901 .maxlen
= sizeof(int),
903 .proc_handler
= &proc_dointvec
,
906 #ifdef CONFIG_SLOW_WORK
908 .ctl_name
= CTL_UNNUMBERED
,
909 .procname
= "slow-work",
911 .child
= slow_work_sysctls
,
914 #ifdef CONFIG_PERF_COUNTERS
916 .ctl_name
= CTL_UNNUMBERED
,
917 .procname
= "perf_counter_privileged",
918 .data
= &sysctl_perf_counter_priv
,
919 .maxlen
= sizeof(sysctl_perf_counter_priv
),
921 .proc_handler
= &proc_dointvec
,
924 .ctl_name
= CTL_UNNUMBERED
,
925 .procname
= "perf_counter_mlock_kb",
926 .data
= &sysctl_perf_counter_mlock
,
927 .maxlen
= sizeof(sysctl_perf_counter_mlock
),
929 .proc_handler
= &proc_dointvec
,
933 * NOTE: do not add new entries to this table unless you have read
934 * Documentation/sysctl/ctl_unnumbered.txt
939 static struct ctl_table vm_table
[] = {
941 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
942 .procname
= "overcommit_memory",
943 .data
= &sysctl_overcommit_memory
,
944 .maxlen
= sizeof(sysctl_overcommit_memory
),
946 .proc_handler
= &proc_dointvec
,
949 .ctl_name
= VM_PANIC_ON_OOM
,
950 .procname
= "panic_on_oom",
951 .data
= &sysctl_panic_on_oom
,
952 .maxlen
= sizeof(sysctl_panic_on_oom
),
954 .proc_handler
= &proc_dointvec
,
957 .ctl_name
= CTL_UNNUMBERED
,
958 .procname
= "oom_kill_allocating_task",
959 .data
= &sysctl_oom_kill_allocating_task
,
960 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
962 .proc_handler
= &proc_dointvec
,
965 .ctl_name
= CTL_UNNUMBERED
,
966 .procname
= "oom_dump_tasks",
967 .data
= &sysctl_oom_dump_tasks
,
968 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
970 .proc_handler
= &proc_dointvec
,
973 .ctl_name
= VM_OVERCOMMIT_RATIO
,
974 .procname
= "overcommit_ratio",
975 .data
= &sysctl_overcommit_ratio
,
976 .maxlen
= sizeof(sysctl_overcommit_ratio
),
978 .proc_handler
= &proc_dointvec
,
981 .ctl_name
= VM_PAGE_CLUSTER
,
982 .procname
= "page-cluster",
983 .data
= &page_cluster
,
984 .maxlen
= sizeof(int),
986 .proc_handler
= &proc_dointvec
,
989 .ctl_name
= VM_DIRTY_BACKGROUND
,
990 .procname
= "dirty_background_ratio",
991 .data
= &dirty_background_ratio
,
992 .maxlen
= sizeof(dirty_background_ratio
),
994 .proc_handler
= &dirty_background_ratio_handler
,
995 .strategy
= &sysctl_intvec
,
997 .extra2
= &one_hundred
,
1000 .ctl_name
= CTL_UNNUMBERED
,
1001 .procname
= "dirty_background_bytes",
1002 .data
= &dirty_background_bytes
,
1003 .maxlen
= sizeof(dirty_background_bytes
),
1005 .proc_handler
= &dirty_background_bytes_handler
,
1006 .strategy
= &sysctl_intvec
,
1010 .ctl_name
= VM_DIRTY_RATIO
,
1011 .procname
= "dirty_ratio",
1012 .data
= &vm_dirty_ratio
,
1013 .maxlen
= sizeof(vm_dirty_ratio
),
1015 .proc_handler
= &dirty_ratio_handler
,
1016 .strategy
= &sysctl_intvec
,
1018 .extra2
= &one_hundred
,
1021 .ctl_name
= CTL_UNNUMBERED
,
1022 .procname
= "dirty_bytes",
1023 .data
= &vm_dirty_bytes
,
1024 .maxlen
= sizeof(vm_dirty_bytes
),
1026 .proc_handler
= &dirty_bytes_handler
,
1027 .strategy
= &sysctl_intvec
,
1031 .procname
= "dirty_writeback_centisecs",
1032 .data
= &dirty_writeback_interval
,
1033 .maxlen
= sizeof(dirty_writeback_interval
),
1035 .proc_handler
= &dirty_writeback_centisecs_handler
,
1038 .procname
= "dirty_expire_centisecs",
1039 .data
= &dirty_expire_interval
,
1040 .maxlen
= sizeof(dirty_expire_interval
),
1042 .proc_handler
= &proc_dointvec
,
1045 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
1046 .procname
= "nr_pdflush_threads",
1047 .data
= &nr_pdflush_threads
,
1048 .maxlen
= sizeof nr_pdflush_threads
,
1049 .mode
= 0444 /* read-only*/,
1050 .proc_handler
= &proc_dointvec
,
1053 .ctl_name
= CTL_UNNUMBERED
,
1054 .procname
= "nr_pdflush_threads_min",
1055 .data
= &nr_pdflush_threads_min
,
1056 .maxlen
= sizeof nr_pdflush_threads_min
,
1057 .mode
= 0644 /* read-write */,
1058 .proc_handler
= &proc_dointvec_minmax
,
1059 .strategy
= &sysctl_intvec
,
1061 .extra2
= &nr_pdflush_threads_max
,
1064 .ctl_name
= CTL_UNNUMBERED
,
1065 .procname
= "nr_pdflush_threads_max",
1066 .data
= &nr_pdflush_threads_max
,
1067 .maxlen
= sizeof nr_pdflush_threads_max
,
1068 .mode
= 0644 /* read-write */,
1069 .proc_handler
= &proc_dointvec_minmax
,
1070 .strategy
= &sysctl_intvec
,
1071 .extra1
= &nr_pdflush_threads_min
,
1072 .extra2
= &one_thousand
,
1075 .ctl_name
= VM_SWAPPINESS
,
1076 .procname
= "swappiness",
1077 .data
= &vm_swappiness
,
1078 .maxlen
= sizeof(vm_swappiness
),
1080 .proc_handler
= &proc_dointvec_minmax
,
1081 .strategy
= &sysctl_intvec
,
1083 .extra2
= &one_hundred
,
1085 #ifdef CONFIG_HUGETLB_PAGE
1087 .procname
= "nr_hugepages",
1089 .maxlen
= sizeof(unsigned long),
1091 .proc_handler
= &hugetlb_sysctl_handler
,
1092 .extra1
= (void *)&hugetlb_zero
,
1093 .extra2
= (void *)&hugetlb_infinity
,
1096 .ctl_name
= VM_HUGETLB_GROUP
,
1097 .procname
= "hugetlb_shm_group",
1098 .data
= &sysctl_hugetlb_shm_group
,
1099 .maxlen
= sizeof(gid_t
),
1101 .proc_handler
= &proc_dointvec
,
1104 .ctl_name
= CTL_UNNUMBERED
,
1105 .procname
= "hugepages_treat_as_movable",
1106 .data
= &hugepages_treat_as_movable
,
1107 .maxlen
= sizeof(int),
1109 .proc_handler
= &hugetlb_treat_movable_handler
,
1112 .ctl_name
= CTL_UNNUMBERED
,
1113 .procname
= "nr_overcommit_hugepages",
1115 .maxlen
= sizeof(unsigned long),
1117 .proc_handler
= &hugetlb_overcommit_handler
,
1118 .extra1
= (void *)&hugetlb_zero
,
1119 .extra2
= (void *)&hugetlb_infinity
,
1123 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
1124 .procname
= "lowmem_reserve_ratio",
1125 .data
= &sysctl_lowmem_reserve_ratio
,
1126 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1128 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
1129 .strategy
= &sysctl_intvec
,
1132 .ctl_name
= VM_DROP_PAGECACHE
,
1133 .procname
= "drop_caches",
1134 .data
= &sysctl_drop_caches
,
1135 .maxlen
= sizeof(int),
1137 .proc_handler
= drop_caches_sysctl_handler
,
1138 .strategy
= &sysctl_intvec
,
1141 .ctl_name
= VM_MIN_FREE_KBYTES
,
1142 .procname
= "min_free_kbytes",
1143 .data
= &min_free_kbytes
,
1144 .maxlen
= sizeof(min_free_kbytes
),
1146 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1147 .strategy
= &sysctl_intvec
,
1151 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1152 .procname
= "percpu_pagelist_fraction",
1153 .data
= &percpu_pagelist_fraction
,
1154 .maxlen
= sizeof(percpu_pagelist_fraction
),
1156 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1157 .strategy
= &sysctl_intvec
,
1158 .extra1
= &min_percpu_pagelist_fract
,
1162 .ctl_name
= VM_MAX_MAP_COUNT
,
1163 .procname
= "max_map_count",
1164 .data
= &sysctl_max_map_count
,
1165 .maxlen
= sizeof(sysctl_max_map_count
),
1167 .proc_handler
= &proc_dointvec
1171 .ctl_name
= CTL_UNNUMBERED
,
1172 .procname
= "nr_trim_pages",
1173 .data
= &sysctl_nr_trim_pages
,
1174 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1176 .proc_handler
= &proc_dointvec_minmax
,
1177 .strategy
= &sysctl_intvec
,
1182 .ctl_name
= VM_LAPTOP_MODE
,
1183 .procname
= "laptop_mode",
1184 .data
= &laptop_mode
,
1185 .maxlen
= sizeof(laptop_mode
),
1187 .proc_handler
= &proc_dointvec_jiffies
,
1188 .strategy
= &sysctl_jiffies
,
1191 .ctl_name
= VM_BLOCK_DUMP
,
1192 .procname
= "block_dump",
1193 .data
= &block_dump
,
1194 .maxlen
= sizeof(block_dump
),
1196 .proc_handler
= &proc_dointvec
,
1197 .strategy
= &sysctl_intvec
,
1201 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1202 .procname
= "vfs_cache_pressure",
1203 .data
= &sysctl_vfs_cache_pressure
,
1204 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1206 .proc_handler
= &proc_dointvec
,
1207 .strategy
= &sysctl_intvec
,
1210 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1212 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1213 .procname
= "legacy_va_layout",
1214 .data
= &sysctl_legacy_va_layout
,
1215 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1217 .proc_handler
= &proc_dointvec
,
1218 .strategy
= &sysctl_intvec
,
1224 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1225 .procname
= "zone_reclaim_mode",
1226 .data
= &zone_reclaim_mode
,
1227 .maxlen
= sizeof(zone_reclaim_mode
),
1229 .proc_handler
= &proc_dointvec
,
1230 .strategy
= &sysctl_intvec
,
1234 .ctl_name
= VM_MIN_UNMAPPED
,
1235 .procname
= "min_unmapped_ratio",
1236 .data
= &sysctl_min_unmapped_ratio
,
1237 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1239 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1240 .strategy
= &sysctl_intvec
,
1242 .extra2
= &one_hundred
,
1245 .ctl_name
= VM_MIN_SLAB
,
1246 .procname
= "min_slab_ratio",
1247 .data
= &sysctl_min_slab_ratio
,
1248 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1250 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1251 .strategy
= &sysctl_intvec
,
1253 .extra2
= &one_hundred
,
1258 .ctl_name
= CTL_UNNUMBERED
,
1259 .procname
= "stat_interval",
1260 .data
= &sysctl_stat_interval
,
1261 .maxlen
= sizeof(sysctl_stat_interval
),
1263 .proc_handler
= &proc_dointvec_jiffies
,
1264 .strategy
= &sysctl_jiffies
,
1267 #ifdef CONFIG_SECURITY
1269 .ctl_name
= CTL_UNNUMBERED
,
1270 .procname
= "mmap_min_addr",
1271 .data
= &mmap_min_addr
,
1272 .maxlen
= sizeof(unsigned long),
1274 .proc_handler
= &proc_doulongvec_minmax
,
1279 .ctl_name
= CTL_UNNUMBERED
,
1280 .procname
= "numa_zonelist_order",
1281 .data
= &numa_zonelist_order
,
1282 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1284 .proc_handler
= &numa_zonelist_order_handler
,
1285 .strategy
= &sysctl_string
,
1288 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1289 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1291 .ctl_name
= VM_VDSO_ENABLED
,
1292 .procname
= "vdso_enabled",
1293 .data
= &vdso_enabled
,
1294 .maxlen
= sizeof(vdso_enabled
),
1296 .proc_handler
= &proc_dointvec
,
1297 .strategy
= &sysctl_intvec
,
1301 #ifdef CONFIG_HIGHMEM
1303 .ctl_name
= CTL_UNNUMBERED
,
1304 .procname
= "highmem_is_dirtyable",
1305 .data
= &vm_highmem_is_dirtyable
,
1306 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1308 .proc_handler
= &proc_dointvec_minmax
,
1309 .strategy
= &sysctl_intvec
,
1314 #ifdef CONFIG_UNEVICTABLE_LRU
1316 .ctl_name
= CTL_UNNUMBERED
,
1317 .procname
= "scan_unevictable_pages",
1318 .data
= &scan_unevictable_pages
,
1319 .maxlen
= sizeof(scan_unevictable_pages
),
1321 .proc_handler
= &scan_unevictable_handler
,
1325 * NOTE: do not add new entries to this table unless you have read
1326 * Documentation/sysctl/ctl_unnumbered.txt
1331 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1332 static struct ctl_table binfmt_misc_table
[] = {
1337 static struct ctl_table fs_table
[] = {
1339 .ctl_name
= FS_NRINODE
,
1340 .procname
= "inode-nr",
1341 .data
= &inodes_stat
,
1342 .maxlen
= 2*sizeof(int),
1344 .proc_handler
= &proc_dointvec
,
1347 .ctl_name
= FS_STATINODE
,
1348 .procname
= "inode-state",
1349 .data
= &inodes_stat
,
1350 .maxlen
= 7*sizeof(int),
1352 .proc_handler
= &proc_dointvec
,
1355 .procname
= "file-nr",
1356 .data
= &files_stat
,
1357 .maxlen
= 3*sizeof(int),
1359 .proc_handler
= &proc_nr_files
,
1362 .ctl_name
= FS_MAXFILE
,
1363 .procname
= "file-max",
1364 .data
= &files_stat
.max_files
,
1365 .maxlen
= sizeof(int),
1367 .proc_handler
= &proc_dointvec
,
1370 .ctl_name
= CTL_UNNUMBERED
,
1371 .procname
= "nr_open",
1372 .data
= &sysctl_nr_open
,
1373 .maxlen
= sizeof(int),
1375 .proc_handler
= &proc_dointvec_minmax
,
1376 .extra1
= &sysctl_nr_open_min
,
1377 .extra2
= &sysctl_nr_open_max
,
1380 .ctl_name
= FS_DENTRY
,
1381 .procname
= "dentry-state",
1382 .data
= &dentry_stat
,
1383 .maxlen
= 6*sizeof(int),
1385 .proc_handler
= &proc_dointvec
,
1388 .ctl_name
= FS_OVERFLOWUID
,
1389 .procname
= "overflowuid",
1390 .data
= &fs_overflowuid
,
1391 .maxlen
= sizeof(int),
1393 .proc_handler
= &proc_dointvec_minmax
,
1394 .strategy
= &sysctl_intvec
,
1395 .extra1
= &minolduid
,
1396 .extra2
= &maxolduid
,
1399 .ctl_name
= FS_OVERFLOWGID
,
1400 .procname
= "overflowgid",
1401 .data
= &fs_overflowgid
,
1402 .maxlen
= sizeof(int),
1404 .proc_handler
= &proc_dointvec_minmax
,
1405 .strategy
= &sysctl_intvec
,
1406 .extra1
= &minolduid
,
1407 .extra2
= &maxolduid
,
1409 #ifdef CONFIG_FILE_LOCKING
1411 .ctl_name
= FS_LEASES
,
1412 .procname
= "leases-enable",
1413 .data
= &leases_enable
,
1414 .maxlen
= sizeof(int),
1416 .proc_handler
= &proc_dointvec
,
1419 #ifdef CONFIG_DNOTIFY
1421 .ctl_name
= FS_DIR_NOTIFY
,
1422 .procname
= "dir-notify-enable",
1423 .data
= &dir_notify_enable
,
1424 .maxlen
= sizeof(int),
1426 .proc_handler
= &proc_dointvec
,
1430 #ifdef CONFIG_FILE_LOCKING
1432 .ctl_name
= FS_LEASE_TIME
,
1433 .procname
= "lease-break-time",
1434 .data
= &lease_break_time
,
1435 .maxlen
= sizeof(int),
1437 .proc_handler
= &proc_dointvec
,
1442 .procname
= "aio-nr",
1444 .maxlen
= sizeof(aio_nr
),
1446 .proc_handler
= &proc_doulongvec_minmax
,
1449 .procname
= "aio-max-nr",
1450 .data
= &aio_max_nr
,
1451 .maxlen
= sizeof(aio_max_nr
),
1453 .proc_handler
= &proc_doulongvec_minmax
,
1455 #endif /* CONFIG_AIO */
1456 #ifdef CONFIG_INOTIFY_USER
1458 .ctl_name
= FS_INOTIFY
,
1459 .procname
= "inotify",
1461 .child
= inotify_table
,
1466 .procname
= "epoll",
1468 .child
= epoll_table
,
1473 .ctl_name
= KERN_SETUID_DUMPABLE
,
1474 .procname
= "suid_dumpable",
1475 .data
= &suid_dumpable
,
1476 .maxlen
= sizeof(int),
1478 .proc_handler
= &proc_dointvec_minmax
,
1479 .strategy
= &sysctl_intvec
,
1483 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1485 .ctl_name
= CTL_UNNUMBERED
,
1486 .procname
= "binfmt_misc",
1488 .child
= binfmt_misc_table
,
1492 * NOTE: do not add new entries to this table unless you have read
1493 * Documentation/sysctl/ctl_unnumbered.txt
1498 static struct ctl_table debug_table
[] = {
1499 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1501 .ctl_name
= CTL_UNNUMBERED
,
1502 .procname
= "exception-trace",
1503 .data
= &show_unhandled_signals
,
1504 .maxlen
= sizeof(int),
1506 .proc_handler
= proc_dointvec
1512 static struct ctl_table dev_table
[] = {
1516 static DEFINE_SPINLOCK(sysctl_lock
);
1518 /* called under sysctl_lock */
1519 static int use_table(struct ctl_table_header
*p
)
1521 if (unlikely(p
->unregistering
))
1527 /* called under sysctl_lock */
1528 static void unuse_table(struct ctl_table_header
*p
)
1531 if (unlikely(p
->unregistering
))
1532 complete(p
->unregistering
);
1535 /* called under sysctl_lock, will reacquire if has to wait */
1536 static void start_unregistering(struct ctl_table_header
*p
)
1539 * if p->used is 0, nobody will ever touch that entry again;
1540 * we'll eliminate all paths to it before dropping sysctl_lock
1542 if (unlikely(p
->used
)) {
1543 struct completion wait
;
1544 init_completion(&wait
);
1545 p
->unregistering
= &wait
;
1546 spin_unlock(&sysctl_lock
);
1547 wait_for_completion(&wait
);
1548 spin_lock(&sysctl_lock
);
1550 /* anything non-NULL; we'll never dereference it */
1551 p
->unregistering
= ERR_PTR(-EINVAL
);
1554 * do not remove from the list until nobody holds it; walking the
1555 * list in do_sysctl() relies on that.
1557 list_del_init(&p
->ctl_entry
);
1560 void sysctl_head_get(struct ctl_table_header
*head
)
1562 spin_lock(&sysctl_lock
);
1564 spin_unlock(&sysctl_lock
);
1567 void sysctl_head_put(struct ctl_table_header
*head
)
1569 spin_lock(&sysctl_lock
);
1572 spin_unlock(&sysctl_lock
);
1575 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1579 spin_lock(&sysctl_lock
);
1580 if (!use_table(head
))
1581 head
= ERR_PTR(-ENOENT
);
1582 spin_unlock(&sysctl_lock
);
1586 void sysctl_head_finish(struct ctl_table_header
*head
)
1590 spin_lock(&sysctl_lock
);
1592 spin_unlock(&sysctl_lock
);
1595 static struct ctl_table_set
*
1596 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1598 struct ctl_table_set
*set
= &root
->default_set
;
1600 set
= root
->lookup(root
, namespaces
);
1604 static struct list_head
*
1605 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1607 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1611 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1612 struct ctl_table_header
*prev
)
1614 struct ctl_table_root
*root
;
1615 struct list_head
*header_list
;
1616 struct ctl_table_header
*head
;
1617 struct list_head
*tmp
;
1619 spin_lock(&sysctl_lock
);
1622 tmp
= &prev
->ctl_entry
;
1626 tmp
= &root_table_header
.ctl_entry
;
1628 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1630 if (!use_table(head
))
1632 spin_unlock(&sysctl_lock
);
1637 header_list
= lookup_header_list(root
, namespaces
);
1638 if (tmp
!= header_list
)
1642 root
= list_entry(root
->root_list
.next
,
1643 struct ctl_table_root
, root_list
);
1644 if (root
== &sysctl_table_root
)
1646 header_list
= lookup_header_list(root
, namespaces
);
1647 } while (list_empty(header_list
));
1648 tmp
= header_list
->next
;
1651 spin_unlock(&sysctl_lock
);
1655 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1657 return __sysctl_head_next(current
->nsproxy
, prev
);
1660 void register_sysctl_root(struct ctl_table_root
*root
)
1662 spin_lock(&sysctl_lock
);
1663 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1664 spin_unlock(&sysctl_lock
);
1667 #ifdef CONFIG_SYSCTL_SYSCALL
1668 /* Perform the actual read/write of a sysctl table entry. */
1669 static int do_sysctl_strategy(struct ctl_table_root
*root
,
1670 struct ctl_table
*table
,
1671 void __user
*oldval
, size_t __user
*oldlenp
,
1672 void __user
*newval
, size_t newlen
)
1680 if (sysctl_perm(root
, table
, op
))
1683 if (table
->strategy
) {
1684 rc
= table
->strategy(table
, oldval
, oldlenp
, newval
, newlen
);
1691 /* If there is no strategy routine, or if the strategy returns
1692 * zero, proceed with automatic r/w */
1693 if (table
->data
&& table
->maxlen
) {
1694 rc
= sysctl_data(table
, oldval
, oldlenp
, newval
, newlen
);
1701 static int parse_table(int __user
*name
, int nlen
,
1702 void __user
*oldval
, size_t __user
*oldlenp
,
1703 void __user
*newval
, size_t newlen
,
1704 struct ctl_table_root
*root
,
1705 struct ctl_table
*table
)
1711 if (get_user(n
, name
))
1713 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1714 if (!table
->ctl_name
)
1716 if (n
== table
->ctl_name
) {
1719 if (sysctl_perm(root
, table
, MAY_EXEC
))
1723 table
= table
->child
;
1726 error
= do_sysctl_strategy(root
, table
,
1735 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1736 void __user
*newval
, size_t newlen
)
1738 struct ctl_table_header
*head
;
1739 int error
= -ENOTDIR
;
1741 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1745 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1749 for (head
= sysctl_head_next(NULL
); head
;
1750 head
= sysctl_head_next(head
)) {
1751 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1753 head
->root
, head
->ctl_table
);
1754 if (error
!= -ENOTDIR
) {
1755 sysctl_head_finish(head
);
1762 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
1764 struct __sysctl_args tmp
;
1767 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1770 error
= deprecated_sysctl_warning(&tmp
);
1775 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1776 tmp
.newval
, tmp
.newlen
);
1781 #endif /* CONFIG_SYSCTL_SYSCALL */
1784 * sysctl_perm does NOT grant the superuser all rights automatically, because
1785 * some sysctl variables are readonly even to root.
1788 static int test_perm(int mode
, int op
)
1790 if (!current_euid())
1792 else if (in_egroup_p(0))
1794 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1799 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1804 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1808 if (root
->permissions
)
1809 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1813 return test_perm(mode
, op
);
1816 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1818 for (; table
->ctl_name
|| table
->procname
; table
++) {
1819 table
->parent
= parent
;
1821 sysctl_set_parent(table
, table
->child
);
1825 static __init
int sysctl_init(void)
1827 sysctl_set_parent(NULL
, root_table
);
1828 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1831 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1837 core_initcall(sysctl_init
);
1839 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1840 struct ctl_table
*table
)
1842 struct ctl_table
*p
;
1843 const char *s
= branch
->procname
;
1845 /* branch should have named subdirectory as its first element */
1846 if (!s
|| !branch
->child
)
1849 /* ... and nothing else */
1850 if (branch
[1].procname
|| branch
[1].ctl_name
)
1853 /* table should contain subdirectory with the same name */
1854 for (p
= table
; p
->procname
|| p
->ctl_name
; p
++) {
1857 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1863 /* see if attaching q to p would be an improvement */
1864 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1866 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1867 struct ctl_table
*next
;
1869 int not_in_parent
= !p
->attached_by
;
1871 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1872 if (by
== q
->attached_by
)
1874 if (to
== p
->attached_by
)
1880 if (is_better
&& not_in_parent
) {
1881 q
->attached_by
= by
;
1882 q
->attached_to
= to
;
1888 * __register_sysctl_paths - register a sysctl hierarchy
1889 * @root: List of sysctl headers to register on
1890 * @namespaces: Data to compute which lists of sysctl entries are visible
1891 * @path: The path to the directory the sysctl table is in.
1892 * @table: the top-level table structure
1894 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1895 * array. A completely 0 filled entry terminates the table.
1897 * The members of the &struct ctl_table structure are used as follows:
1899 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1900 * must be unique within that level of sysctl
1902 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1903 * enter a sysctl file
1905 * data - a pointer to data for use by proc_handler
1907 * maxlen - the maximum size in bytes of the data
1909 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1911 * child - a pointer to the child sysctl table if this entry is a directory, or
1914 * proc_handler - the text handler routine (described below)
1916 * strategy - the strategy routine (described below)
1918 * de - for internal use by the sysctl routines
1920 * extra1, extra2 - extra pointers usable by the proc handler routines
1922 * Leaf nodes in the sysctl tree will be represented by a single file
1923 * under /proc; non-leaf nodes will be represented by directories.
1925 * sysctl(2) can automatically manage read and write requests through
1926 * the sysctl table. The data and maxlen fields of the ctl_table
1927 * struct enable minimal validation of the values being written to be
1928 * performed, and the mode field allows minimal authentication.
1930 * More sophisticated management can be enabled by the provision of a
1931 * strategy routine with the table entry. This will be called before
1932 * any automatic read or write of the data is performed.
1934 * The strategy routine may return
1936 * < 0 - Error occurred (error is passed to user process)
1938 * 0 - OK - proceed with automatic read or write.
1940 * > 0 - OK - read or write has been done by the strategy routine, so
1941 * return immediately.
1943 * There must be a proc_handler routine for any terminal nodes
1944 * mirrored under /proc/sys (non-terminals are handled by a built-in
1945 * directory handler). Several default handlers are available to
1946 * cover common cases -
1948 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1949 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1950 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1952 * It is the handler's job to read the input buffer from user memory
1953 * and process it. The handler should return 0 on success.
1955 * This routine returns %NULL on a failure to register, and a pointer
1956 * to the table header on success.
1958 struct ctl_table_header
*__register_sysctl_paths(
1959 struct ctl_table_root
*root
,
1960 struct nsproxy
*namespaces
,
1961 const struct ctl_path
*path
, struct ctl_table
*table
)
1963 struct ctl_table_header
*header
;
1964 struct ctl_table
*new, **prevp
;
1965 unsigned int n
, npath
;
1966 struct ctl_table_set
*set
;
1968 /* Count the path components */
1969 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
1973 * For each path component, allocate a 2-element ctl_table array.
1974 * The first array element will be filled with the sysctl entry
1975 * for this, the second will be the sentinel (ctl_name == 0).
1977 * We allocate everything in one go so that we don't have to
1978 * worry about freeing additional memory in unregister_sysctl_table.
1980 header
= kzalloc(sizeof(struct ctl_table_header
) +
1981 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1985 new = (struct ctl_table
*) (header
+ 1);
1987 /* Now connect the dots */
1988 prevp
= &header
->ctl_table
;
1989 for (n
= 0; n
< npath
; ++n
, ++path
) {
1990 /* Copy the procname */
1991 new->procname
= path
->procname
;
1992 new->ctl_name
= path
->ctl_name
;
1996 prevp
= &new->child
;
2001 header
->ctl_table_arg
= table
;
2003 INIT_LIST_HEAD(&header
->ctl_entry
);
2005 header
->unregistering
= NULL
;
2006 header
->root
= root
;
2007 sysctl_set_parent(NULL
, header
->ctl_table
);
2009 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
2010 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
2015 spin_lock(&sysctl_lock
);
2016 header
->set
= lookup_header_set(root
, namespaces
);
2017 header
->attached_by
= header
->ctl_table
;
2018 header
->attached_to
= root_table
;
2019 header
->parent
= &root_table_header
;
2020 for (set
= header
->set
; set
; set
= set
->parent
) {
2021 struct ctl_table_header
*p
;
2022 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
2023 if (p
->unregistering
)
2025 try_attach(p
, header
);
2028 header
->parent
->count
++;
2029 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
2030 spin_unlock(&sysctl_lock
);
2036 * register_sysctl_table_path - register a sysctl table hierarchy
2037 * @path: The path to the directory the sysctl table is in.
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_paths(const struct ctl_path
*path
,
2046 struct ctl_table
*table
)
2048 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
2053 * register_sysctl_table - register a sysctl table hierarchy
2054 * @table: the top-level table structure
2056 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2057 * array. A completely 0 filled entry terminates the table.
2059 * See register_sysctl_paths for more details.
2061 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
2063 static const struct ctl_path null_path
[] = { {} };
2065 return register_sysctl_paths(null_path
, table
);
2069 * unregister_sysctl_table - unregister a sysctl table hierarchy
2070 * @header: the header returned from register_sysctl_table
2072 * Unregisters the sysctl table and all children. proc entries may not
2073 * actually be removed until they are no longer used by anyone.
2075 void unregister_sysctl_table(struct ctl_table_header
* header
)
2082 spin_lock(&sysctl_lock
);
2083 start_unregistering(header
);
2084 if (!--header
->parent
->count
) {
2086 kfree(header
->parent
);
2088 if (!--header
->count
)
2090 spin_unlock(&sysctl_lock
);
2093 int sysctl_is_seen(struct ctl_table_header
*p
)
2095 struct ctl_table_set
*set
= p
->set
;
2097 spin_lock(&sysctl_lock
);
2098 if (p
->unregistering
)
2100 else if (!set
->is_seen
)
2103 res
= set
->is_seen(set
);
2104 spin_unlock(&sysctl_lock
);
2108 void setup_sysctl_set(struct ctl_table_set
*p
,
2109 struct ctl_table_set
*parent
,
2110 int (*is_seen
)(struct ctl_table_set
*))
2112 INIT_LIST_HEAD(&p
->list
);
2113 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
2114 p
->is_seen
= is_seen
;
2117 #else /* !CONFIG_SYSCTL */
2118 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
2123 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2124 struct ctl_table
*table
)
2129 void unregister_sysctl_table(struct ctl_table_header
* table
)
2133 void setup_sysctl_set(struct ctl_table_set
*p
,
2134 struct ctl_table_set
*parent
,
2135 int (*is_seen
)(struct ctl_table_set
*))
2139 void sysctl_head_put(struct ctl_table_header
*head
)
2143 #endif /* CONFIG_SYSCTL */
2149 #ifdef CONFIG_PROC_SYSCTL
2151 static int _proc_do_string(void* data
, int maxlen
, int write
,
2152 struct file
*filp
, void __user
*buffer
,
2153 size_t *lenp
, loff_t
*ppos
)
2159 if (!data
|| !maxlen
|| !*lenp
) {
2167 while (len
< *lenp
) {
2168 if (get_user(c
, p
++))
2170 if (c
== 0 || c
== '\n')
2176 if(copy_from_user(data
, buffer
, len
))
2178 ((char *) data
)[len
] = 0;
2196 if(copy_to_user(buffer
, data
, len
))
2199 if(put_user('\n', ((char __user
*) buffer
) + len
))
2210 * proc_dostring - read a string sysctl
2211 * @table: the sysctl table
2212 * @write: %TRUE if this is a write to the sysctl file
2213 * @filp: the file structure
2214 * @buffer: the user buffer
2215 * @lenp: the size of the user buffer
2216 * @ppos: file position
2218 * Reads/writes a string from/to the user buffer. If the kernel
2219 * buffer provided is not large enough to hold the string, the
2220 * string is truncated. The copied string is %NULL-terminated.
2221 * If the string is being read by the user process, it is copied
2222 * and a newline '\n' is added. It is truncated if the buffer is
2225 * Returns 0 on success.
2227 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2228 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2230 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
2231 buffer
, lenp
, ppos
);
2235 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
2237 int write
, void *data
)
2240 *valp
= *negp
? -*lvalp
: *lvalp
;
2245 *lvalp
= (unsigned long)-val
;
2248 *lvalp
= (unsigned long)val
;
2254 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2255 int write
, struct file
*filp
, void __user
*buffer
,
2256 size_t *lenp
, loff_t
*ppos
,
2257 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2258 int write
, void *data
),
2261 #define TMPBUFLEN 21
2262 int *i
, vleft
, first
=1, neg
, val
;
2266 char buf
[TMPBUFLEN
], *p
;
2267 char __user
*s
= buffer
;
2269 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
2270 (*ppos
&& !write
)) {
2275 i
= (int *) tbl_data
;
2276 vleft
= table
->maxlen
/ sizeof(*i
);
2280 conv
= do_proc_dointvec_conv
;
2282 for (; left
&& vleft
--; i
++, first
=0) {
2297 if (len
> sizeof(buf
) - 1)
2298 len
= sizeof(buf
) - 1;
2299 if (copy_from_user(buf
, s
, len
))
2303 if (*p
== '-' && left
> 1) {
2307 if (*p
< '0' || *p
> '9')
2310 lval
= simple_strtoul(p
, &p
, 0);
2313 if ((len
< left
) && *p
&& !isspace(*p
))
2320 if (conv(&neg
, &lval
, i
, 1, data
))
2327 if (conv(&neg
, &lval
, i
, 0, data
))
2330 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2334 if(copy_to_user(s
, buf
, len
))
2341 if (!write
&& !first
&& left
) {
2342 if(put_user('\n', s
))
2349 if (get_user(c
, s
++))
2364 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2365 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2366 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2367 int write
, void *data
),
2370 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2371 buffer
, lenp
, ppos
, conv
, data
);
2375 * proc_dointvec - read a vector of integers
2376 * @table: the sysctl table
2377 * @write: %TRUE if this is a write to the sysctl file
2378 * @filp: the file structure
2379 * @buffer: the user buffer
2380 * @lenp: the size of the user buffer
2381 * @ppos: file position
2383 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2384 * values from/to the user buffer, treated as an ASCII string.
2386 * Returns 0 on success.
2388 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2389 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2391 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2396 * Taint values can only be increased
2397 * This means we can safely use a temporary.
2399 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2400 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2403 unsigned long tmptaint
= get_taint();
2406 if (write
&& !capable(CAP_SYS_ADMIN
))
2411 err
= proc_doulongvec_minmax(&t
, write
, filp
, buffer
, lenp
, ppos
);
2417 * Poor man's atomic or. Not worth adding a primitive
2418 * to everyone's atomic.h for this
2421 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2422 if ((tmptaint
>> i
) & 1)
2430 struct do_proc_dointvec_minmax_conv_param
{
2435 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2437 int write
, void *data
)
2439 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2441 int val
= *negp
? -*lvalp
: *lvalp
;
2442 if ((param
->min
&& *param
->min
> val
) ||
2443 (param
->max
&& *param
->max
< val
))
2450 *lvalp
= (unsigned long)-val
;
2453 *lvalp
= (unsigned long)val
;
2460 * proc_dointvec_minmax - read a vector of integers with min/max values
2461 * @table: the sysctl table
2462 * @write: %TRUE if this is a write to the sysctl file
2463 * @filp: the file structure
2464 * @buffer: the user buffer
2465 * @lenp: the size of the user buffer
2466 * @ppos: file position
2468 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2469 * values from/to the user buffer, treated as an ASCII string.
2471 * This routine will ensure the values are within the range specified by
2472 * table->extra1 (min) and table->extra2 (max).
2474 * Returns 0 on success.
2476 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2477 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2479 struct do_proc_dointvec_minmax_conv_param param
= {
2480 .min
= (int *) table
->extra1
,
2481 .max
= (int *) table
->extra2
,
2483 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2484 do_proc_dointvec_minmax_conv
, ¶m
);
2487 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2489 void __user
*buffer
,
2490 size_t *lenp
, loff_t
*ppos
,
2491 unsigned long convmul
,
2492 unsigned long convdiv
)
2494 #define TMPBUFLEN 21
2495 unsigned long *i
, *min
, *max
, val
;
2496 int vleft
, first
=1, neg
;
2498 char buf
[TMPBUFLEN
], *p
;
2499 char __user
*s
= buffer
;
2501 if (!data
|| !table
->maxlen
|| !*lenp
||
2502 (*ppos
&& !write
)) {
2507 i
= (unsigned long *) data
;
2508 min
= (unsigned long *) table
->extra1
;
2509 max
= (unsigned long *) table
->extra2
;
2510 vleft
= table
->maxlen
/ sizeof(unsigned long);
2513 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2528 if (len
> TMPBUFLEN
-1)
2530 if (copy_from_user(buf
, s
, len
))
2534 if (*p
== '-' && left
> 1) {
2538 if (*p
< '0' || *p
> '9')
2540 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2542 if ((len
< left
) && *p
&& !isspace(*p
))
2551 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2558 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2562 if(copy_to_user(s
, buf
, len
))
2569 if (!write
&& !first
&& left
) {
2570 if(put_user('\n', s
))
2577 if (get_user(c
, s
++))
2592 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2594 void __user
*buffer
,
2595 size_t *lenp
, loff_t
*ppos
,
2596 unsigned long convmul
,
2597 unsigned long convdiv
)
2599 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2600 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2604 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2605 * @table: the sysctl table
2606 * @write: %TRUE if this is a write to the sysctl file
2607 * @filp: the file structure
2608 * @buffer: the user buffer
2609 * @lenp: the size of the user buffer
2610 * @ppos: file position
2612 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2613 * values from/to the user buffer, treated as an ASCII string.
2615 * This routine will ensure the values are within the range specified by
2616 * table->extra1 (min) and table->extra2 (max).
2618 * Returns 0 on success.
2620 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2621 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2623 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2627 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2628 * @table: the sysctl table
2629 * @write: %TRUE if this is a write to the sysctl file
2630 * @filp: the file structure
2631 * @buffer: the user buffer
2632 * @lenp: the size of the user buffer
2633 * @ppos: file position
2635 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2636 * values from/to the user buffer, treated as an ASCII string. The values
2637 * are treated as milliseconds, and converted to jiffies when they are stored.
2639 * This routine will ensure the values are within the range specified by
2640 * table->extra1 (min) and table->extra2 (max).
2642 * Returns 0 on success.
2644 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2646 void __user
*buffer
,
2647 size_t *lenp
, loff_t
*ppos
)
2649 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2650 lenp
, ppos
, HZ
, 1000l);
2654 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2656 int write
, void *data
)
2659 if (*lvalp
> LONG_MAX
/ HZ
)
2661 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2667 lval
= (unsigned long)-val
;
2670 lval
= (unsigned long)val
;
2677 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2679 int write
, void *data
)
2682 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2684 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2690 lval
= (unsigned long)-val
;
2693 lval
= (unsigned long)val
;
2695 *lvalp
= jiffies_to_clock_t(lval
);
2700 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2702 int write
, void *data
)
2705 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2711 lval
= (unsigned long)-val
;
2714 lval
= (unsigned long)val
;
2716 *lvalp
= jiffies_to_msecs(lval
);
2722 * proc_dointvec_jiffies - read a vector of integers as seconds
2723 * @table: the sysctl table
2724 * @write: %TRUE if this is a write to the sysctl file
2725 * @filp: the file structure
2726 * @buffer: the user buffer
2727 * @lenp: the size of the user buffer
2728 * @ppos: file position
2730 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2731 * values from/to the user buffer, treated as an ASCII string.
2732 * The values read are assumed to be in seconds, and are converted into
2735 * Returns 0 on success.
2737 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2738 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2740 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2741 do_proc_dointvec_jiffies_conv
,NULL
);
2745 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2746 * @table: the sysctl table
2747 * @write: %TRUE if this is a write to the sysctl file
2748 * @filp: the file structure
2749 * @buffer: the user buffer
2750 * @lenp: the size of the user buffer
2751 * @ppos: pointer to the file position
2753 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2754 * values from/to the user buffer, treated as an ASCII string.
2755 * The values read are assumed to be in 1/USER_HZ seconds, and
2756 * are converted into jiffies.
2758 * Returns 0 on success.
2760 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2761 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2763 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2764 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2768 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2769 * @table: the sysctl table
2770 * @write: %TRUE if this is a write to the sysctl file
2771 * @filp: the file structure
2772 * @buffer: the user buffer
2773 * @lenp: the size of the user buffer
2774 * @ppos: file position
2775 * @ppos: the current position in the file
2777 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2778 * values from/to the user buffer, treated as an ASCII string.
2779 * The values read are assumed to be in 1/1000 seconds, and
2780 * are converted into jiffies.
2782 * Returns 0 on success.
2784 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2785 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2787 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2788 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2791 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2792 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2794 struct pid
*new_pid
;
2798 tmp
= pid_vnr(cad_pid
);
2800 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2801 lenp
, ppos
, NULL
, NULL
);
2805 new_pid
= find_get_pid(tmp
);
2809 put_pid(xchg(&cad_pid
, new_pid
));
2813 #else /* CONFIG_PROC_FS */
2815 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2816 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2821 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2822 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2827 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2828 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2833 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2834 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2839 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2840 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2845 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2846 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2851 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2852 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2857 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2859 void __user
*buffer
,
2860 size_t *lenp
, loff_t
*ppos
)
2866 #endif /* CONFIG_PROC_FS */
2869 #ifdef CONFIG_SYSCTL_SYSCALL
2871 * General sysctl support routines
2874 /* The generic sysctl data routine (used if no strategy routine supplied) */
2875 int sysctl_data(struct ctl_table
*table
,
2876 void __user
*oldval
, size_t __user
*oldlenp
,
2877 void __user
*newval
, size_t newlen
)
2881 /* Get out of I don't have a variable */
2882 if (!table
->data
|| !table
->maxlen
)
2885 if (oldval
&& oldlenp
) {
2886 if (get_user(len
, oldlenp
))
2889 if (len
> table
->maxlen
)
2890 len
= table
->maxlen
;
2891 if (copy_to_user(oldval
, table
->data
, len
))
2893 if (put_user(len
, oldlenp
))
2898 if (newval
&& newlen
) {
2899 if (newlen
> table
->maxlen
)
2900 newlen
= table
->maxlen
;
2902 if (copy_from_user(table
->data
, newval
, newlen
))
2908 /* The generic string strategy routine: */
2909 int sysctl_string(struct ctl_table
*table
,
2910 void __user
*oldval
, size_t __user
*oldlenp
,
2911 void __user
*newval
, size_t newlen
)
2913 if (!table
->data
|| !table
->maxlen
)
2916 if (oldval
&& oldlenp
) {
2918 if (get_user(bufsize
, oldlenp
))
2921 size_t len
= strlen(table
->data
), copied
;
2923 /* This shouldn't trigger for a well-formed sysctl */
2924 if (len
> table
->maxlen
)
2925 len
= table
->maxlen
;
2927 /* Copy up to a max of bufsize-1 bytes of the string */
2928 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2930 if (copy_to_user(oldval
, table
->data
, copied
) ||
2931 put_user(0, (char __user
*)(oldval
+ copied
)))
2933 if (put_user(len
, oldlenp
))
2937 if (newval
&& newlen
) {
2938 size_t len
= newlen
;
2939 if (len
> table
->maxlen
)
2940 len
= table
->maxlen
;
2941 if(copy_from_user(table
->data
, newval
, len
))
2943 if (len
== table
->maxlen
)
2945 ((char *) table
->data
)[len
] = 0;
2951 * This function makes sure that all of the integers in the vector
2952 * are between the minimum and maximum values given in the arrays
2953 * table->extra1 and table->extra2, respectively.
2955 int sysctl_intvec(struct ctl_table
*table
,
2956 void __user
*oldval
, size_t __user
*oldlenp
,
2957 void __user
*newval
, size_t newlen
)
2960 if (newval
&& newlen
) {
2961 int __user
*vec
= (int __user
*) newval
;
2962 int *min
= (int *) table
->extra1
;
2963 int *max
= (int *) table
->extra2
;
2967 if (newlen
% sizeof(int) != 0)
2970 if (!table
->extra1
&& !table
->extra2
)
2973 if (newlen
> table
->maxlen
)
2974 newlen
= table
->maxlen
;
2975 length
= newlen
/ sizeof(int);
2977 for (i
= 0; i
< length
; i
++) {
2979 if (get_user(value
, vec
+ i
))
2981 if (min
&& value
< min
[i
])
2983 if (max
&& value
> max
[i
])
2990 /* Strategy function to convert jiffies to seconds */
2991 int sysctl_jiffies(struct ctl_table
*table
,
2992 void __user
*oldval
, size_t __user
*oldlenp
,
2993 void __user
*newval
, size_t newlen
)
2995 if (oldval
&& oldlenp
) {
2998 if (get_user(olen
, oldlenp
))
3003 if (olen
< sizeof(int))
3006 val
= *(int *)(table
->data
) / HZ
;
3007 if (put_user(val
, (int __user
*)oldval
))
3009 if (put_user(sizeof(int), oldlenp
))
3013 if (newval
&& newlen
) {
3015 if (newlen
!= sizeof(int))
3017 if (get_user(new, (int __user
*)newval
))
3019 *(int *)(table
->data
) = new*HZ
;
3024 /* Strategy function to convert jiffies to seconds */
3025 int sysctl_ms_jiffies(struct ctl_table
*table
,
3026 void __user
*oldval
, size_t __user
*oldlenp
,
3027 void __user
*newval
, size_t newlen
)
3029 if (oldval
&& oldlenp
) {
3032 if (get_user(olen
, oldlenp
))
3037 if (olen
< sizeof(int))
3040 val
= jiffies_to_msecs(*(int *)(table
->data
));
3041 if (put_user(val
, (int __user
*)oldval
))
3043 if (put_user(sizeof(int), oldlenp
))
3047 if (newval
&& newlen
) {
3049 if (newlen
!= sizeof(int))
3051 if (get_user(new, (int __user
*)newval
))
3053 *(int *)(table
->data
) = msecs_to_jiffies(new);
3060 #else /* CONFIG_SYSCTL_SYSCALL */
3063 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
3065 struct __sysctl_args tmp
;
3068 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
3071 error
= deprecated_sysctl_warning(&tmp
);
3073 /* If no error reading the parameters then just -ENOSYS ... */
3080 int sysctl_data(struct ctl_table
*table
,
3081 void __user
*oldval
, size_t __user
*oldlenp
,
3082 void __user
*newval
, size_t newlen
)
3087 int sysctl_string(struct ctl_table
*table
,
3088 void __user
*oldval
, size_t __user
*oldlenp
,
3089 void __user
*newval
, size_t newlen
)
3094 int sysctl_intvec(struct ctl_table
*table
,
3095 void __user
*oldval
, size_t __user
*oldlenp
,
3096 void __user
*newval
, size_t newlen
)
3101 int sysctl_jiffies(struct ctl_table
*table
,
3102 void __user
*oldval
, size_t __user
*oldlenp
,
3103 void __user
*newval
, size_t newlen
)
3108 int sysctl_ms_jiffies(struct ctl_table
*table
,
3109 void __user
*oldval
, size_t __user
*oldlenp
,
3110 void __user
*newval
, size_t newlen
)
3115 #endif /* CONFIG_SYSCTL_SYSCALL */
3117 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
3119 static int msg_count
;
3120 int name
[CTL_MAXNAME
];
3123 /* Check args->nlen. */
3124 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
3127 /* Read in the sysctl name for better debug message logging */
3128 for (i
= 0; i
< args
->nlen
; i
++)
3129 if (get_user(name
[i
], args
->name
+ i
))
3132 /* Ignore accesses to kernel.version */
3133 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
3136 if (msg_count
< 5) {
3139 "warning: process `%s' used the deprecated sysctl "
3140 "system call with ", current
->comm
);
3141 for (i
= 0; i
< args
->nlen
; i
++)
3142 printk("%d.", name
[i
]);
3149 * No sense putting this after each symbol definition, twice,
3150 * exception granted :-)
3152 EXPORT_SYMBOL(proc_dointvec
);
3153 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3154 EXPORT_SYMBOL(proc_dointvec_minmax
);
3155 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3156 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3157 EXPORT_SYMBOL(proc_dostring
);
3158 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3159 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
3160 EXPORT_SYMBOL(register_sysctl_table
);
3161 EXPORT_SYMBOL(register_sysctl_paths
);
3162 EXPORT_SYMBOL(sysctl_intvec
);
3163 EXPORT_SYMBOL(sysctl_jiffies
);
3164 EXPORT_SYMBOL(sysctl_ms_jiffies
);
3165 EXPORT_SYMBOL(sysctl_string
);
3166 EXPORT_SYMBOL(sysctl_data
);
3167 EXPORT_SYMBOL(unregister_sysctl_table
);