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>
52 #include <asm/uaccess.h>
53 #include <asm/processor.h>
57 #include <asm/stacktrace.h>
61 static int deprecated_sysctl_warning(struct __sysctl_args
*args
);
63 #if defined(CONFIG_SYSCTL)
65 /* External variables not in a header file. */
67 extern int print_fatal_signals
;
68 extern int sysctl_overcommit_memory
;
69 extern int sysctl_overcommit_ratio
;
70 extern int sysctl_panic_on_oom
;
71 extern int sysctl_oom_kill_allocating_task
;
72 extern int sysctl_oom_dump_tasks
;
73 extern int max_threads
;
74 extern int core_uses_pid
;
75 extern int suid_dumpable
;
76 extern char core_pattern
[];
78 extern int min_free_kbytes
;
79 extern int pid_max_min
, pid_max_max
;
80 extern int sysctl_drop_caches
;
81 extern int percpu_pagelist_fraction
;
82 extern int compat_log
;
83 extern int latencytop_enabled
;
84 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
86 extern int sysctl_nr_trim_pages
;
88 #ifdef CONFIG_RCU_TORTURE_TEST
89 extern int rcutorture_runnable
;
90 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
92 /* Constants used for minimum and maximum */
93 #ifdef CONFIG_DETECT_SOFTLOCKUP
94 static int sixty
= 60;
95 static int neg_one
= -1;
98 #if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING)
104 static unsigned long one_ul
= 1;
105 static int one_hundred
= 100;
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 .ctl_name
= CTL_UNNUMBERED
,
820 .procname
= "hung_task_check_count",
821 .data
= &sysctl_hung_task_check_count
,
822 .maxlen
= sizeof(unsigned long),
824 .proc_handler
= &proc_doulongvec_minmax
,
825 .strategy
= &sysctl_intvec
,
828 .ctl_name
= CTL_UNNUMBERED
,
829 .procname
= "hung_task_timeout_secs",
830 .data
= &sysctl_hung_task_timeout_secs
,
831 .maxlen
= sizeof(unsigned long),
833 .proc_handler
= &proc_doulongvec_minmax
,
834 .strategy
= &sysctl_intvec
,
837 .ctl_name
= CTL_UNNUMBERED
,
838 .procname
= "hung_task_warnings",
839 .data
= &sysctl_hung_task_warnings
,
840 .maxlen
= sizeof(unsigned long),
842 .proc_handler
= &proc_doulongvec_minmax
,
843 .strategy
= &sysctl_intvec
,
848 .ctl_name
= KERN_COMPAT_LOG
,
849 .procname
= "compat-log",
851 .maxlen
= sizeof (int),
853 .proc_handler
= &proc_dointvec
,
856 #ifdef CONFIG_RT_MUTEXES
858 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
859 .procname
= "max_lock_depth",
860 .data
= &max_lock_depth
,
861 .maxlen
= sizeof(int),
863 .proc_handler
= &proc_dointvec
,
867 .ctl_name
= CTL_UNNUMBERED
,
868 .procname
= "poweroff_cmd",
869 .data
= &poweroff_cmd
,
870 .maxlen
= POWEROFF_CMD_PATH_LEN
,
872 .proc_handler
= &proc_dostring
,
873 .strategy
= &sysctl_string
,
877 .ctl_name
= CTL_UNNUMBERED
,
880 .child
= key_sysctls
,
883 #ifdef CONFIG_RCU_TORTURE_TEST
885 .ctl_name
= CTL_UNNUMBERED
,
886 .procname
= "rcutorture_runnable",
887 .data
= &rcutorture_runnable
,
888 .maxlen
= sizeof(int),
890 .proc_handler
= &proc_dointvec
,
893 #ifdef CONFIG_UNEVICTABLE_LRU
895 .ctl_name
= CTL_UNNUMBERED
,
896 .procname
= "scan_unevictable_pages",
897 .data
= &scan_unevictable_pages
,
898 .maxlen
= sizeof(scan_unevictable_pages
),
900 .proc_handler
= &scan_unevictable_handler
,
904 * NOTE: do not add new entries to this table unless you have read
905 * Documentation/sysctl/ctl_unnumbered.txt
910 static struct ctl_table vm_table
[] = {
912 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
913 .procname
= "overcommit_memory",
914 .data
= &sysctl_overcommit_memory
,
915 .maxlen
= sizeof(sysctl_overcommit_memory
),
917 .proc_handler
= &proc_dointvec
,
920 .ctl_name
= VM_PANIC_ON_OOM
,
921 .procname
= "panic_on_oom",
922 .data
= &sysctl_panic_on_oom
,
923 .maxlen
= sizeof(sysctl_panic_on_oom
),
925 .proc_handler
= &proc_dointvec
,
928 .ctl_name
= CTL_UNNUMBERED
,
929 .procname
= "oom_kill_allocating_task",
930 .data
= &sysctl_oom_kill_allocating_task
,
931 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
933 .proc_handler
= &proc_dointvec
,
936 .ctl_name
= CTL_UNNUMBERED
,
937 .procname
= "oom_dump_tasks",
938 .data
= &sysctl_oom_dump_tasks
,
939 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
941 .proc_handler
= &proc_dointvec
,
944 .ctl_name
= VM_OVERCOMMIT_RATIO
,
945 .procname
= "overcommit_ratio",
946 .data
= &sysctl_overcommit_ratio
,
947 .maxlen
= sizeof(sysctl_overcommit_ratio
),
949 .proc_handler
= &proc_dointvec
,
952 .ctl_name
= VM_PAGE_CLUSTER
,
953 .procname
= "page-cluster",
954 .data
= &page_cluster
,
955 .maxlen
= sizeof(int),
957 .proc_handler
= &proc_dointvec
,
960 .ctl_name
= VM_DIRTY_BACKGROUND
,
961 .procname
= "dirty_background_ratio",
962 .data
= &dirty_background_ratio
,
963 .maxlen
= sizeof(dirty_background_ratio
),
965 .proc_handler
= &dirty_background_ratio_handler
,
966 .strategy
= &sysctl_intvec
,
968 .extra2
= &one_hundred
,
971 .ctl_name
= CTL_UNNUMBERED
,
972 .procname
= "dirty_background_bytes",
973 .data
= &dirty_background_bytes
,
974 .maxlen
= sizeof(dirty_background_bytes
),
976 .proc_handler
= &dirty_background_bytes_handler
,
977 .strategy
= &sysctl_intvec
,
981 .ctl_name
= VM_DIRTY_RATIO
,
982 .procname
= "dirty_ratio",
983 .data
= &vm_dirty_ratio
,
984 .maxlen
= sizeof(vm_dirty_ratio
),
986 .proc_handler
= &dirty_ratio_handler
,
987 .strategy
= &sysctl_intvec
,
989 .extra2
= &one_hundred
,
992 .ctl_name
= CTL_UNNUMBERED
,
993 .procname
= "dirty_bytes",
994 .data
= &vm_dirty_bytes
,
995 .maxlen
= sizeof(vm_dirty_bytes
),
997 .proc_handler
= &dirty_bytes_handler
,
998 .strategy
= &sysctl_intvec
,
1002 .procname
= "dirty_writeback_centisecs",
1003 .data
= &dirty_writeback_interval
,
1004 .maxlen
= sizeof(dirty_writeback_interval
),
1006 .proc_handler
= &dirty_writeback_centisecs_handler
,
1009 .procname
= "dirty_expire_centisecs",
1010 .data
= &dirty_expire_interval
,
1011 .maxlen
= sizeof(dirty_expire_interval
),
1013 .proc_handler
= &proc_dointvec_userhz_jiffies
,
1016 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
1017 .procname
= "nr_pdflush_threads",
1018 .data
= &nr_pdflush_threads
,
1019 .maxlen
= sizeof nr_pdflush_threads
,
1020 .mode
= 0444 /* read-only*/,
1021 .proc_handler
= &proc_dointvec
,
1024 .ctl_name
= VM_SWAPPINESS
,
1025 .procname
= "swappiness",
1026 .data
= &vm_swappiness
,
1027 .maxlen
= sizeof(vm_swappiness
),
1029 .proc_handler
= &proc_dointvec_minmax
,
1030 .strategy
= &sysctl_intvec
,
1032 .extra2
= &one_hundred
,
1034 #ifdef CONFIG_HUGETLB_PAGE
1036 .procname
= "nr_hugepages",
1038 .maxlen
= sizeof(unsigned long),
1040 .proc_handler
= &hugetlb_sysctl_handler
,
1041 .extra1
= (void *)&hugetlb_zero
,
1042 .extra2
= (void *)&hugetlb_infinity
,
1045 .ctl_name
= VM_HUGETLB_GROUP
,
1046 .procname
= "hugetlb_shm_group",
1047 .data
= &sysctl_hugetlb_shm_group
,
1048 .maxlen
= sizeof(gid_t
),
1050 .proc_handler
= &proc_dointvec
,
1053 .ctl_name
= CTL_UNNUMBERED
,
1054 .procname
= "hugepages_treat_as_movable",
1055 .data
= &hugepages_treat_as_movable
,
1056 .maxlen
= sizeof(int),
1058 .proc_handler
= &hugetlb_treat_movable_handler
,
1061 .ctl_name
= CTL_UNNUMBERED
,
1062 .procname
= "nr_overcommit_hugepages",
1064 .maxlen
= sizeof(unsigned long),
1066 .proc_handler
= &hugetlb_overcommit_handler
,
1067 .extra1
= (void *)&hugetlb_zero
,
1068 .extra2
= (void *)&hugetlb_infinity
,
1072 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
1073 .procname
= "lowmem_reserve_ratio",
1074 .data
= &sysctl_lowmem_reserve_ratio
,
1075 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1077 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
1078 .strategy
= &sysctl_intvec
,
1081 .ctl_name
= VM_DROP_PAGECACHE
,
1082 .procname
= "drop_caches",
1083 .data
= &sysctl_drop_caches
,
1084 .maxlen
= sizeof(int),
1086 .proc_handler
= drop_caches_sysctl_handler
,
1087 .strategy
= &sysctl_intvec
,
1090 .ctl_name
= VM_MIN_FREE_KBYTES
,
1091 .procname
= "min_free_kbytes",
1092 .data
= &min_free_kbytes
,
1093 .maxlen
= sizeof(min_free_kbytes
),
1095 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1096 .strategy
= &sysctl_intvec
,
1100 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1101 .procname
= "percpu_pagelist_fraction",
1102 .data
= &percpu_pagelist_fraction
,
1103 .maxlen
= sizeof(percpu_pagelist_fraction
),
1105 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1106 .strategy
= &sysctl_intvec
,
1107 .extra1
= &min_percpu_pagelist_fract
,
1111 .ctl_name
= VM_MAX_MAP_COUNT
,
1112 .procname
= "max_map_count",
1113 .data
= &sysctl_max_map_count
,
1114 .maxlen
= sizeof(sysctl_max_map_count
),
1116 .proc_handler
= &proc_dointvec
1120 .ctl_name
= CTL_UNNUMBERED
,
1121 .procname
= "nr_trim_pages",
1122 .data
= &sysctl_nr_trim_pages
,
1123 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1125 .proc_handler
= &proc_dointvec_minmax
,
1126 .strategy
= &sysctl_intvec
,
1131 .ctl_name
= VM_LAPTOP_MODE
,
1132 .procname
= "laptop_mode",
1133 .data
= &laptop_mode
,
1134 .maxlen
= sizeof(laptop_mode
),
1136 .proc_handler
= &proc_dointvec_jiffies
,
1137 .strategy
= &sysctl_jiffies
,
1140 .ctl_name
= VM_BLOCK_DUMP
,
1141 .procname
= "block_dump",
1142 .data
= &block_dump
,
1143 .maxlen
= sizeof(block_dump
),
1145 .proc_handler
= &proc_dointvec
,
1146 .strategy
= &sysctl_intvec
,
1150 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1151 .procname
= "vfs_cache_pressure",
1152 .data
= &sysctl_vfs_cache_pressure
,
1153 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1155 .proc_handler
= &proc_dointvec
,
1156 .strategy
= &sysctl_intvec
,
1159 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1161 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1162 .procname
= "legacy_va_layout",
1163 .data
= &sysctl_legacy_va_layout
,
1164 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1166 .proc_handler
= &proc_dointvec
,
1167 .strategy
= &sysctl_intvec
,
1173 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1174 .procname
= "zone_reclaim_mode",
1175 .data
= &zone_reclaim_mode
,
1176 .maxlen
= sizeof(zone_reclaim_mode
),
1178 .proc_handler
= &proc_dointvec
,
1179 .strategy
= &sysctl_intvec
,
1183 .ctl_name
= VM_MIN_UNMAPPED
,
1184 .procname
= "min_unmapped_ratio",
1185 .data
= &sysctl_min_unmapped_ratio
,
1186 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1188 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1189 .strategy
= &sysctl_intvec
,
1191 .extra2
= &one_hundred
,
1194 .ctl_name
= VM_MIN_SLAB
,
1195 .procname
= "min_slab_ratio",
1196 .data
= &sysctl_min_slab_ratio
,
1197 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1199 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1200 .strategy
= &sysctl_intvec
,
1202 .extra2
= &one_hundred
,
1207 .ctl_name
= CTL_UNNUMBERED
,
1208 .procname
= "stat_interval",
1209 .data
= &sysctl_stat_interval
,
1210 .maxlen
= sizeof(sysctl_stat_interval
),
1212 .proc_handler
= &proc_dointvec_jiffies
,
1213 .strategy
= &sysctl_jiffies
,
1216 #ifdef CONFIG_SECURITY
1218 .ctl_name
= CTL_UNNUMBERED
,
1219 .procname
= "mmap_min_addr",
1220 .data
= &mmap_min_addr
,
1221 .maxlen
= sizeof(unsigned long),
1223 .proc_handler
= &proc_doulongvec_minmax
,
1228 .ctl_name
= CTL_UNNUMBERED
,
1229 .procname
= "numa_zonelist_order",
1230 .data
= &numa_zonelist_order
,
1231 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1233 .proc_handler
= &numa_zonelist_order_handler
,
1234 .strategy
= &sysctl_string
,
1237 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1238 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1240 .ctl_name
= VM_VDSO_ENABLED
,
1241 .procname
= "vdso_enabled",
1242 .data
= &vdso_enabled
,
1243 .maxlen
= sizeof(vdso_enabled
),
1245 .proc_handler
= &proc_dointvec
,
1246 .strategy
= &sysctl_intvec
,
1250 #ifdef CONFIG_HIGHMEM
1252 .ctl_name
= CTL_UNNUMBERED
,
1253 .procname
= "highmem_is_dirtyable",
1254 .data
= &vm_highmem_is_dirtyable
,
1255 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1257 .proc_handler
= &proc_dointvec_minmax
,
1258 .strategy
= &sysctl_intvec
,
1264 * NOTE: do not add new entries to this table unless you have read
1265 * Documentation/sysctl/ctl_unnumbered.txt
1270 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1271 static struct ctl_table binfmt_misc_table
[] = {
1276 static struct ctl_table fs_table
[] = {
1278 .ctl_name
= FS_NRINODE
,
1279 .procname
= "inode-nr",
1280 .data
= &inodes_stat
,
1281 .maxlen
= 2*sizeof(int),
1283 .proc_handler
= &proc_dointvec
,
1286 .ctl_name
= FS_STATINODE
,
1287 .procname
= "inode-state",
1288 .data
= &inodes_stat
,
1289 .maxlen
= 7*sizeof(int),
1291 .proc_handler
= &proc_dointvec
,
1294 .procname
= "file-nr",
1295 .data
= &files_stat
,
1296 .maxlen
= 3*sizeof(int),
1298 .proc_handler
= &proc_nr_files
,
1301 .ctl_name
= FS_MAXFILE
,
1302 .procname
= "file-max",
1303 .data
= &files_stat
.max_files
,
1304 .maxlen
= sizeof(int),
1306 .proc_handler
= &proc_dointvec
,
1309 .ctl_name
= CTL_UNNUMBERED
,
1310 .procname
= "nr_open",
1311 .data
= &sysctl_nr_open
,
1312 .maxlen
= sizeof(int),
1314 .proc_handler
= &proc_dointvec_minmax
,
1315 .extra1
= &sysctl_nr_open_min
,
1316 .extra2
= &sysctl_nr_open_max
,
1319 .ctl_name
= FS_DENTRY
,
1320 .procname
= "dentry-state",
1321 .data
= &dentry_stat
,
1322 .maxlen
= 6*sizeof(int),
1324 .proc_handler
= &proc_dointvec
,
1327 .ctl_name
= FS_OVERFLOWUID
,
1328 .procname
= "overflowuid",
1329 .data
= &fs_overflowuid
,
1330 .maxlen
= sizeof(int),
1332 .proc_handler
= &proc_dointvec_minmax
,
1333 .strategy
= &sysctl_intvec
,
1334 .extra1
= &minolduid
,
1335 .extra2
= &maxolduid
,
1338 .ctl_name
= FS_OVERFLOWGID
,
1339 .procname
= "overflowgid",
1340 .data
= &fs_overflowgid
,
1341 .maxlen
= sizeof(int),
1343 .proc_handler
= &proc_dointvec_minmax
,
1344 .strategy
= &sysctl_intvec
,
1345 .extra1
= &minolduid
,
1346 .extra2
= &maxolduid
,
1348 #ifdef CONFIG_FILE_LOCKING
1350 .ctl_name
= FS_LEASES
,
1351 .procname
= "leases-enable",
1352 .data
= &leases_enable
,
1353 .maxlen
= sizeof(int),
1355 .proc_handler
= &proc_dointvec
,
1358 #ifdef CONFIG_DNOTIFY
1360 .ctl_name
= FS_DIR_NOTIFY
,
1361 .procname
= "dir-notify-enable",
1362 .data
= &dir_notify_enable
,
1363 .maxlen
= sizeof(int),
1365 .proc_handler
= &proc_dointvec
,
1369 #ifdef CONFIG_FILE_LOCKING
1371 .ctl_name
= FS_LEASE_TIME
,
1372 .procname
= "lease-break-time",
1373 .data
= &lease_break_time
,
1374 .maxlen
= sizeof(int),
1376 .proc_handler
= &proc_dointvec_minmax
,
1377 .strategy
= &sysctl_intvec
,
1384 .procname
= "aio-nr",
1386 .maxlen
= sizeof(aio_nr
),
1388 .proc_handler
= &proc_doulongvec_minmax
,
1391 .procname
= "aio-max-nr",
1392 .data
= &aio_max_nr
,
1393 .maxlen
= sizeof(aio_max_nr
),
1395 .proc_handler
= &proc_doulongvec_minmax
,
1397 #endif /* CONFIG_AIO */
1398 #ifdef CONFIG_INOTIFY_USER
1400 .ctl_name
= FS_INOTIFY
,
1401 .procname
= "inotify",
1403 .child
= inotify_table
,
1408 .procname
= "epoll",
1410 .child
= epoll_table
,
1415 .ctl_name
= KERN_SETUID_DUMPABLE
,
1416 .procname
= "suid_dumpable",
1417 .data
= &suid_dumpable
,
1418 .maxlen
= sizeof(int),
1420 .proc_handler
= &proc_dointvec
,
1422 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1424 .ctl_name
= CTL_UNNUMBERED
,
1425 .procname
= "binfmt_misc",
1427 .child
= binfmt_misc_table
,
1431 * NOTE: do not add new entries to this table unless you have read
1432 * Documentation/sysctl/ctl_unnumbered.txt
1437 static struct ctl_table debug_table
[] = {
1438 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1440 .ctl_name
= CTL_UNNUMBERED
,
1441 .procname
= "exception-trace",
1442 .data
= &show_unhandled_signals
,
1443 .maxlen
= sizeof(int),
1445 .proc_handler
= proc_dointvec
1451 static struct ctl_table dev_table
[] = {
1455 static DEFINE_SPINLOCK(sysctl_lock
);
1457 /* called under sysctl_lock */
1458 static int use_table(struct ctl_table_header
*p
)
1460 if (unlikely(p
->unregistering
))
1466 /* called under sysctl_lock */
1467 static void unuse_table(struct ctl_table_header
*p
)
1470 if (unlikely(p
->unregistering
))
1471 complete(p
->unregistering
);
1474 /* called under sysctl_lock, will reacquire if has to wait */
1475 static void start_unregistering(struct ctl_table_header
*p
)
1478 * if p->used is 0, nobody will ever touch that entry again;
1479 * we'll eliminate all paths to it before dropping sysctl_lock
1481 if (unlikely(p
->used
)) {
1482 struct completion wait
;
1483 init_completion(&wait
);
1484 p
->unregistering
= &wait
;
1485 spin_unlock(&sysctl_lock
);
1486 wait_for_completion(&wait
);
1487 spin_lock(&sysctl_lock
);
1489 /* anything non-NULL; we'll never dereference it */
1490 p
->unregistering
= ERR_PTR(-EINVAL
);
1493 * do not remove from the list until nobody holds it; walking the
1494 * list in do_sysctl() relies on that.
1496 list_del_init(&p
->ctl_entry
);
1499 void sysctl_head_get(struct ctl_table_header
*head
)
1501 spin_lock(&sysctl_lock
);
1503 spin_unlock(&sysctl_lock
);
1506 void sysctl_head_put(struct ctl_table_header
*head
)
1508 spin_lock(&sysctl_lock
);
1511 spin_unlock(&sysctl_lock
);
1514 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1518 spin_lock(&sysctl_lock
);
1519 if (!use_table(head
))
1520 head
= ERR_PTR(-ENOENT
);
1521 spin_unlock(&sysctl_lock
);
1525 void sysctl_head_finish(struct ctl_table_header
*head
)
1529 spin_lock(&sysctl_lock
);
1531 spin_unlock(&sysctl_lock
);
1534 static struct ctl_table_set
*
1535 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1537 struct ctl_table_set
*set
= &root
->default_set
;
1539 set
= root
->lookup(root
, namespaces
);
1543 static struct list_head
*
1544 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1546 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1550 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1551 struct ctl_table_header
*prev
)
1553 struct ctl_table_root
*root
;
1554 struct list_head
*header_list
;
1555 struct ctl_table_header
*head
;
1556 struct list_head
*tmp
;
1558 spin_lock(&sysctl_lock
);
1561 tmp
= &prev
->ctl_entry
;
1565 tmp
= &root_table_header
.ctl_entry
;
1567 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1569 if (!use_table(head
))
1571 spin_unlock(&sysctl_lock
);
1576 header_list
= lookup_header_list(root
, namespaces
);
1577 if (tmp
!= header_list
)
1581 root
= list_entry(root
->root_list
.next
,
1582 struct ctl_table_root
, root_list
);
1583 if (root
== &sysctl_table_root
)
1585 header_list
= lookup_header_list(root
, namespaces
);
1586 } while (list_empty(header_list
));
1587 tmp
= header_list
->next
;
1590 spin_unlock(&sysctl_lock
);
1594 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1596 return __sysctl_head_next(current
->nsproxy
, prev
);
1599 void register_sysctl_root(struct ctl_table_root
*root
)
1601 spin_lock(&sysctl_lock
);
1602 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1603 spin_unlock(&sysctl_lock
);
1606 #ifdef CONFIG_SYSCTL_SYSCALL
1607 /* Perform the actual read/write of a sysctl table entry. */
1608 static int do_sysctl_strategy(struct ctl_table_root
*root
,
1609 struct ctl_table
*table
,
1610 void __user
*oldval
, size_t __user
*oldlenp
,
1611 void __user
*newval
, size_t newlen
)
1619 if (sysctl_perm(root
, table
, op
))
1622 if (table
->strategy
) {
1623 rc
= table
->strategy(table
, oldval
, oldlenp
, newval
, newlen
);
1630 /* If there is no strategy routine, or if the strategy returns
1631 * zero, proceed with automatic r/w */
1632 if (table
->data
&& table
->maxlen
) {
1633 rc
= sysctl_data(table
, oldval
, oldlenp
, newval
, newlen
);
1640 static int parse_table(int __user
*name
, int nlen
,
1641 void __user
*oldval
, size_t __user
*oldlenp
,
1642 void __user
*newval
, size_t newlen
,
1643 struct ctl_table_root
*root
,
1644 struct ctl_table
*table
)
1650 if (get_user(n
, name
))
1652 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1653 if (!table
->ctl_name
)
1655 if (n
== table
->ctl_name
) {
1658 if (sysctl_perm(root
, table
, MAY_EXEC
))
1662 table
= table
->child
;
1665 error
= do_sysctl_strategy(root
, table
,
1674 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1675 void __user
*newval
, size_t newlen
)
1677 struct ctl_table_header
*head
;
1678 int error
= -ENOTDIR
;
1680 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1684 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1688 for (head
= sysctl_head_next(NULL
); head
;
1689 head
= sysctl_head_next(head
)) {
1690 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1692 head
->root
, head
->ctl_table
);
1693 if (error
!= -ENOTDIR
) {
1694 sysctl_head_finish(head
);
1701 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
1703 struct __sysctl_args tmp
;
1706 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1709 error
= deprecated_sysctl_warning(&tmp
);
1714 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1715 tmp
.newval
, tmp
.newlen
);
1720 #endif /* CONFIG_SYSCTL_SYSCALL */
1723 * sysctl_perm does NOT grant the superuser all rights automatically, because
1724 * some sysctl variables are readonly even to root.
1727 static int test_perm(int mode
, int op
)
1729 if (!current_euid())
1731 else if (in_egroup_p(0))
1733 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1738 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1743 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1747 if (root
->permissions
)
1748 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1752 return test_perm(mode
, op
);
1755 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1757 for (; table
->ctl_name
|| table
->procname
; table
++) {
1758 table
->parent
= parent
;
1760 sysctl_set_parent(table
, table
->child
);
1764 static __init
int sysctl_init(void)
1766 sysctl_set_parent(NULL
, root_table
);
1767 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1770 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1776 core_initcall(sysctl_init
);
1778 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1779 struct ctl_table
*table
)
1781 struct ctl_table
*p
;
1782 const char *s
= branch
->procname
;
1784 /* branch should have named subdirectory as its first element */
1785 if (!s
|| !branch
->child
)
1788 /* ... and nothing else */
1789 if (branch
[1].procname
|| branch
[1].ctl_name
)
1792 /* table should contain subdirectory with the same name */
1793 for (p
= table
; p
->procname
|| p
->ctl_name
; p
++) {
1796 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1802 /* see if attaching q to p would be an improvement */
1803 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1805 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1806 struct ctl_table
*next
;
1808 int not_in_parent
= !p
->attached_by
;
1810 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1811 if (by
== q
->attached_by
)
1813 if (to
== p
->attached_by
)
1819 if (is_better
&& not_in_parent
) {
1820 q
->attached_by
= by
;
1821 q
->attached_to
= to
;
1827 * __register_sysctl_paths - register a sysctl hierarchy
1828 * @root: List of sysctl headers to register on
1829 * @namespaces: Data to compute which lists of sysctl entries are visible
1830 * @path: The path to the directory the sysctl table is in.
1831 * @table: the top-level table structure
1833 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1834 * array. A completely 0 filled entry terminates the table.
1836 * The members of the &struct ctl_table structure are used as follows:
1838 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1839 * must be unique within that level of sysctl
1841 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1842 * enter a sysctl file
1844 * data - a pointer to data for use by proc_handler
1846 * maxlen - the maximum size in bytes of the data
1848 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1850 * child - a pointer to the child sysctl table if this entry is a directory, or
1853 * proc_handler - the text handler routine (described below)
1855 * strategy - the strategy routine (described below)
1857 * de - for internal use by the sysctl routines
1859 * extra1, extra2 - extra pointers usable by the proc handler routines
1861 * Leaf nodes in the sysctl tree will be represented by a single file
1862 * under /proc; non-leaf nodes will be represented by directories.
1864 * sysctl(2) can automatically manage read and write requests through
1865 * the sysctl table. The data and maxlen fields of the ctl_table
1866 * struct enable minimal validation of the values being written to be
1867 * performed, and the mode field allows minimal authentication.
1869 * More sophisticated management can be enabled by the provision of a
1870 * strategy routine with the table entry. This will be called before
1871 * any automatic read or write of the data is performed.
1873 * The strategy routine may return
1875 * < 0 - Error occurred (error is passed to user process)
1877 * 0 - OK - proceed with automatic read or write.
1879 * > 0 - OK - read or write has been done by the strategy routine, so
1880 * return immediately.
1882 * There must be a proc_handler routine for any terminal nodes
1883 * mirrored under /proc/sys (non-terminals are handled by a built-in
1884 * directory handler). Several default handlers are available to
1885 * cover common cases -
1887 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1888 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1889 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1891 * It is the handler's job to read the input buffer from user memory
1892 * and process it. The handler should return 0 on success.
1894 * This routine returns %NULL on a failure to register, and a pointer
1895 * to the table header on success.
1897 struct ctl_table_header
*__register_sysctl_paths(
1898 struct ctl_table_root
*root
,
1899 struct nsproxy
*namespaces
,
1900 const struct ctl_path
*path
, struct ctl_table
*table
)
1902 struct ctl_table_header
*header
;
1903 struct ctl_table
*new, **prevp
;
1904 unsigned int n
, npath
;
1905 struct ctl_table_set
*set
;
1907 /* Count the path components */
1908 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
1912 * For each path component, allocate a 2-element ctl_table array.
1913 * The first array element will be filled with the sysctl entry
1914 * for this, the second will be the sentinel (ctl_name == 0).
1916 * We allocate everything in one go so that we don't have to
1917 * worry about freeing additional memory in unregister_sysctl_table.
1919 header
= kzalloc(sizeof(struct ctl_table_header
) +
1920 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1924 new = (struct ctl_table
*) (header
+ 1);
1926 /* Now connect the dots */
1927 prevp
= &header
->ctl_table
;
1928 for (n
= 0; n
< npath
; ++n
, ++path
) {
1929 /* Copy the procname */
1930 new->procname
= path
->procname
;
1931 new->ctl_name
= path
->ctl_name
;
1935 prevp
= &new->child
;
1940 header
->ctl_table_arg
= table
;
1942 INIT_LIST_HEAD(&header
->ctl_entry
);
1944 header
->unregistering
= NULL
;
1945 header
->root
= root
;
1946 sysctl_set_parent(NULL
, header
->ctl_table
);
1948 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1949 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1954 spin_lock(&sysctl_lock
);
1955 header
->set
= lookup_header_set(root
, namespaces
);
1956 header
->attached_by
= header
->ctl_table
;
1957 header
->attached_to
= root_table
;
1958 header
->parent
= &root_table_header
;
1959 for (set
= header
->set
; set
; set
= set
->parent
) {
1960 struct ctl_table_header
*p
;
1961 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
1962 if (p
->unregistering
)
1964 try_attach(p
, header
);
1967 header
->parent
->count
++;
1968 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
1969 spin_unlock(&sysctl_lock
);
1975 * register_sysctl_table_path - register a sysctl table hierarchy
1976 * @path: The path to the directory the sysctl table is in.
1977 * @table: the top-level table structure
1979 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1980 * array. A completely 0 filled entry terminates the table.
1982 * See __register_sysctl_paths for more details.
1984 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1985 struct ctl_table
*table
)
1987 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1992 * register_sysctl_table - register a sysctl table hierarchy
1993 * @table: the top-level table structure
1995 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1996 * array. A completely 0 filled entry terminates the table.
1998 * See register_sysctl_paths for more details.
2000 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
2002 static const struct ctl_path null_path
[] = { {} };
2004 return register_sysctl_paths(null_path
, table
);
2008 * unregister_sysctl_table - unregister a sysctl table hierarchy
2009 * @header: the header returned from register_sysctl_table
2011 * Unregisters the sysctl table and all children. proc entries may not
2012 * actually be removed until they are no longer used by anyone.
2014 void unregister_sysctl_table(struct ctl_table_header
* header
)
2021 spin_lock(&sysctl_lock
);
2022 start_unregistering(header
);
2023 if (!--header
->parent
->count
) {
2025 kfree(header
->parent
);
2027 if (!--header
->count
)
2029 spin_unlock(&sysctl_lock
);
2032 int sysctl_is_seen(struct ctl_table_header
*p
)
2034 struct ctl_table_set
*set
= p
->set
;
2036 spin_lock(&sysctl_lock
);
2037 if (p
->unregistering
)
2039 else if (!set
->is_seen
)
2042 res
= set
->is_seen(set
);
2043 spin_unlock(&sysctl_lock
);
2047 void setup_sysctl_set(struct ctl_table_set
*p
,
2048 struct ctl_table_set
*parent
,
2049 int (*is_seen
)(struct ctl_table_set
*))
2051 INIT_LIST_HEAD(&p
->list
);
2052 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
2053 p
->is_seen
= is_seen
;
2056 #else /* !CONFIG_SYSCTL */
2057 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
2062 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2063 struct ctl_table
*table
)
2068 void unregister_sysctl_table(struct ctl_table_header
* table
)
2072 void setup_sysctl_set(struct ctl_table_set
*p
,
2073 struct ctl_table_set
*parent
,
2074 int (*is_seen
)(struct ctl_table_set
*))
2078 void sysctl_head_put(struct ctl_table_header
*head
)
2082 #endif /* CONFIG_SYSCTL */
2088 #ifdef CONFIG_PROC_SYSCTL
2090 static int _proc_do_string(void* data
, int maxlen
, int write
,
2091 struct file
*filp
, void __user
*buffer
,
2092 size_t *lenp
, loff_t
*ppos
)
2098 if (!data
|| !maxlen
|| !*lenp
) {
2106 while (len
< *lenp
) {
2107 if (get_user(c
, p
++))
2109 if (c
== 0 || c
== '\n')
2115 if(copy_from_user(data
, buffer
, len
))
2117 ((char *) data
)[len
] = 0;
2135 if(copy_to_user(buffer
, data
, len
))
2138 if(put_user('\n', ((char __user
*) buffer
) + len
))
2149 * proc_dostring - read a string sysctl
2150 * @table: the sysctl table
2151 * @write: %TRUE if this is a write to the sysctl file
2152 * @filp: the file structure
2153 * @buffer: the user buffer
2154 * @lenp: the size of the user buffer
2155 * @ppos: file position
2157 * Reads/writes a string from/to the user buffer. If the kernel
2158 * buffer provided is not large enough to hold the string, the
2159 * string is truncated. The copied string is %NULL-terminated.
2160 * If the string is being read by the user process, it is copied
2161 * and a newline '\n' is added. It is truncated if the buffer is
2164 * Returns 0 on success.
2166 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2167 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2169 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
2170 buffer
, lenp
, ppos
);
2174 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
2176 int write
, void *data
)
2179 *valp
= *negp
? -*lvalp
: *lvalp
;
2184 *lvalp
= (unsigned long)-val
;
2187 *lvalp
= (unsigned long)val
;
2193 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2194 int write
, struct file
*filp
, void __user
*buffer
,
2195 size_t *lenp
, loff_t
*ppos
,
2196 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2197 int write
, void *data
),
2200 #define TMPBUFLEN 21
2201 int *i
, vleft
, first
=1, neg
, val
;
2205 char buf
[TMPBUFLEN
], *p
;
2206 char __user
*s
= buffer
;
2208 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
2209 (*ppos
&& !write
)) {
2214 i
= (int *) tbl_data
;
2215 vleft
= table
->maxlen
/ sizeof(*i
);
2219 conv
= do_proc_dointvec_conv
;
2221 for (; left
&& vleft
--; i
++, first
=0) {
2236 if (len
> sizeof(buf
) - 1)
2237 len
= sizeof(buf
) - 1;
2238 if (copy_from_user(buf
, s
, len
))
2242 if (*p
== '-' && left
> 1) {
2246 if (*p
< '0' || *p
> '9')
2249 lval
= simple_strtoul(p
, &p
, 0);
2252 if ((len
< left
) && *p
&& !isspace(*p
))
2259 if (conv(&neg
, &lval
, i
, 1, data
))
2266 if (conv(&neg
, &lval
, i
, 0, data
))
2269 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2273 if(copy_to_user(s
, buf
, len
))
2280 if (!write
&& !first
&& left
) {
2281 if(put_user('\n', s
))
2288 if (get_user(c
, s
++))
2303 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2304 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2305 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2306 int write
, void *data
),
2309 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2310 buffer
, lenp
, ppos
, conv
, data
);
2314 * proc_dointvec - read a vector of integers
2315 * @table: the sysctl table
2316 * @write: %TRUE if this is a write to the sysctl file
2317 * @filp: the file structure
2318 * @buffer: the user buffer
2319 * @lenp: the size of the user buffer
2320 * @ppos: file position
2322 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2323 * values from/to the user buffer, treated as an ASCII string.
2325 * Returns 0 on success.
2327 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2328 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2330 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2335 * Taint values can only be increased
2336 * This means we can safely use a temporary.
2338 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2339 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2342 unsigned long tmptaint
= get_taint();
2345 if (write
&& !capable(CAP_SYS_ADMIN
))
2350 err
= proc_doulongvec_minmax(&t
, write
, filp
, buffer
, lenp
, ppos
);
2356 * Poor man's atomic or. Not worth adding a primitive
2357 * to everyone's atomic.h for this
2360 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2361 if ((tmptaint
>> i
) & 1)
2369 struct do_proc_dointvec_minmax_conv_param
{
2374 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2376 int write
, void *data
)
2378 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2380 int val
= *negp
? -*lvalp
: *lvalp
;
2381 if ((param
->min
&& *param
->min
> val
) ||
2382 (param
->max
&& *param
->max
< val
))
2389 *lvalp
= (unsigned long)-val
;
2392 *lvalp
= (unsigned long)val
;
2399 * proc_dointvec_minmax - read a vector of integers with min/max values
2400 * @table: the sysctl table
2401 * @write: %TRUE if this is a write to the sysctl file
2402 * @filp: the file structure
2403 * @buffer: the user buffer
2404 * @lenp: the size of the user buffer
2405 * @ppos: file position
2407 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2408 * values from/to the user buffer, treated as an ASCII string.
2410 * This routine will ensure the values are within the range specified by
2411 * table->extra1 (min) and table->extra2 (max).
2413 * Returns 0 on success.
2415 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2416 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2418 struct do_proc_dointvec_minmax_conv_param param
= {
2419 .min
= (int *) table
->extra1
,
2420 .max
= (int *) table
->extra2
,
2422 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2423 do_proc_dointvec_minmax_conv
, ¶m
);
2426 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2428 void __user
*buffer
,
2429 size_t *lenp
, loff_t
*ppos
,
2430 unsigned long convmul
,
2431 unsigned long convdiv
)
2433 #define TMPBUFLEN 21
2434 unsigned long *i
, *min
, *max
, val
;
2435 int vleft
, first
=1, neg
;
2437 char buf
[TMPBUFLEN
], *p
;
2438 char __user
*s
= buffer
;
2440 if (!data
|| !table
->maxlen
|| !*lenp
||
2441 (*ppos
&& !write
)) {
2446 i
= (unsigned long *) data
;
2447 min
= (unsigned long *) table
->extra1
;
2448 max
= (unsigned long *) table
->extra2
;
2449 vleft
= table
->maxlen
/ sizeof(unsigned long);
2452 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2467 if (len
> TMPBUFLEN
-1)
2469 if (copy_from_user(buf
, s
, len
))
2473 if (*p
== '-' && left
> 1) {
2477 if (*p
< '0' || *p
> '9')
2479 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2481 if ((len
< left
) && *p
&& !isspace(*p
))
2490 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2497 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2501 if(copy_to_user(s
, buf
, len
))
2508 if (!write
&& !first
&& left
) {
2509 if(put_user('\n', s
))
2516 if (get_user(c
, s
++))
2531 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2533 void __user
*buffer
,
2534 size_t *lenp
, loff_t
*ppos
,
2535 unsigned long convmul
,
2536 unsigned long convdiv
)
2538 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2539 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2543 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2544 * @table: the sysctl table
2545 * @write: %TRUE if this is a write to the sysctl file
2546 * @filp: the file structure
2547 * @buffer: the user buffer
2548 * @lenp: the size of the user buffer
2549 * @ppos: file position
2551 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2552 * values from/to the user buffer, treated as an ASCII string.
2554 * This routine will ensure the values are within the range specified by
2555 * table->extra1 (min) and table->extra2 (max).
2557 * Returns 0 on success.
2559 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2560 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2562 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2566 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2567 * @table: the sysctl table
2568 * @write: %TRUE if this is a write to the sysctl file
2569 * @filp: the file structure
2570 * @buffer: the user buffer
2571 * @lenp: the size of the user buffer
2572 * @ppos: file position
2574 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2575 * values from/to the user buffer, treated as an ASCII string. The values
2576 * are treated as milliseconds, and converted to jiffies when they are stored.
2578 * This routine will ensure the values are within the range specified by
2579 * table->extra1 (min) and table->extra2 (max).
2581 * Returns 0 on success.
2583 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2585 void __user
*buffer
,
2586 size_t *lenp
, loff_t
*ppos
)
2588 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2589 lenp
, ppos
, HZ
, 1000l);
2593 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2595 int write
, void *data
)
2598 if (*lvalp
> LONG_MAX
/ HZ
)
2600 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2606 lval
= (unsigned long)-val
;
2609 lval
= (unsigned long)val
;
2616 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2618 int write
, void *data
)
2621 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2623 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2629 lval
= (unsigned long)-val
;
2632 lval
= (unsigned long)val
;
2634 *lvalp
= jiffies_to_clock_t(lval
);
2639 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2641 int write
, void *data
)
2644 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2650 lval
= (unsigned long)-val
;
2653 lval
= (unsigned long)val
;
2655 *lvalp
= jiffies_to_msecs(lval
);
2661 * proc_dointvec_jiffies - read a vector of integers as seconds
2662 * @table: the sysctl table
2663 * @write: %TRUE if this is a write to the sysctl file
2664 * @filp: the file structure
2665 * @buffer: the user buffer
2666 * @lenp: the size of the user buffer
2667 * @ppos: file position
2669 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2670 * values from/to the user buffer, treated as an ASCII string.
2671 * The values read are assumed to be in seconds, and are converted into
2674 * Returns 0 on success.
2676 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2677 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2679 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2680 do_proc_dointvec_jiffies_conv
,NULL
);
2684 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2685 * @table: the sysctl table
2686 * @write: %TRUE if this is a write to the sysctl file
2687 * @filp: the file structure
2688 * @buffer: the user buffer
2689 * @lenp: the size of the user buffer
2690 * @ppos: pointer to the file position
2692 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2693 * values from/to the user buffer, treated as an ASCII string.
2694 * The values read are assumed to be in 1/USER_HZ seconds, and
2695 * are converted into jiffies.
2697 * Returns 0 on success.
2699 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2700 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2702 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2703 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2707 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2708 * @table: the sysctl table
2709 * @write: %TRUE if this is a write to the sysctl file
2710 * @filp: the file structure
2711 * @buffer: the user buffer
2712 * @lenp: the size of the user buffer
2713 * @ppos: file position
2714 * @ppos: the current position in the file
2716 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2717 * values from/to the user buffer, treated as an ASCII string.
2718 * The values read are assumed to be in 1/1000 seconds, and
2719 * are converted into jiffies.
2721 * Returns 0 on success.
2723 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2724 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2726 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2727 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2730 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2731 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2733 struct pid
*new_pid
;
2737 tmp
= pid_vnr(cad_pid
);
2739 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2740 lenp
, ppos
, NULL
, NULL
);
2744 new_pid
= find_get_pid(tmp
);
2748 put_pid(xchg(&cad_pid
, new_pid
));
2752 #else /* CONFIG_PROC_FS */
2754 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2755 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2760 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2761 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2766 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2767 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2772 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2773 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2778 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2779 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
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
)
2790 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2791 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2796 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2798 void __user
*buffer
,
2799 size_t *lenp
, loff_t
*ppos
)
2805 #endif /* CONFIG_PROC_FS */
2808 #ifdef CONFIG_SYSCTL_SYSCALL
2810 * General sysctl support routines
2813 /* The generic sysctl data routine (used if no strategy routine supplied) */
2814 int sysctl_data(struct ctl_table
*table
,
2815 void __user
*oldval
, size_t __user
*oldlenp
,
2816 void __user
*newval
, size_t newlen
)
2820 /* Get out of I don't have a variable */
2821 if (!table
->data
|| !table
->maxlen
)
2824 if (oldval
&& oldlenp
) {
2825 if (get_user(len
, oldlenp
))
2828 if (len
> table
->maxlen
)
2829 len
= table
->maxlen
;
2830 if (copy_to_user(oldval
, table
->data
, len
))
2832 if (put_user(len
, oldlenp
))
2837 if (newval
&& newlen
) {
2838 if (newlen
> table
->maxlen
)
2839 newlen
= table
->maxlen
;
2841 if (copy_from_user(table
->data
, newval
, newlen
))
2847 /* The generic string strategy routine: */
2848 int sysctl_string(struct ctl_table
*table
,
2849 void __user
*oldval
, size_t __user
*oldlenp
,
2850 void __user
*newval
, size_t newlen
)
2852 if (!table
->data
|| !table
->maxlen
)
2855 if (oldval
&& oldlenp
) {
2857 if (get_user(bufsize
, oldlenp
))
2860 size_t len
= strlen(table
->data
), copied
;
2862 /* This shouldn't trigger for a well-formed sysctl */
2863 if (len
> table
->maxlen
)
2864 len
= table
->maxlen
;
2866 /* Copy up to a max of bufsize-1 bytes of the string */
2867 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2869 if (copy_to_user(oldval
, table
->data
, copied
) ||
2870 put_user(0, (char __user
*)(oldval
+ copied
)))
2872 if (put_user(len
, oldlenp
))
2876 if (newval
&& newlen
) {
2877 size_t len
= newlen
;
2878 if (len
> table
->maxlen
)
2879 len
= table
->maxlen
;
2880 if(copy_from_user(table
->data
, newval
, len
))
2882 if (len
== table
->maxlen
)
2884 ((char *) table
->data
)[len
] = 0;
2890 * This function makes sure that all of the integers in the vector
2891 * are between the minimum and maximum values given in the arrays
2892 * table->extra1 and table->extra2, respectively.
2894 int sysctl_intvec(struct ctl_table
*table
,
2895 void __user
*oldval
, size_t __user
*oldlenp
,
2896 void __user
*newval
, size_t newlen
)
2899 if (newval
&& newlen
) {
2900 int __user
*vec
= (int __user
*) newval
;
2901 int *min
= (int *) table
->extra1
;
2902 int *max
= (int *) table
->extra2
;
2906 if (newlen
% sizeof(int) != 0)
2909 if (!table
->extra1
&& !table
->extra2
)
2912 if (newlen
> table
->maxlen
)
2913 newlen
= table
->maxlen
;
2914 length
= newlen
/ sizeof(int);
2916 for (i
= 0; i
< length
; i
++) {
2918 if (get_user(value
, vec
+ i
))
2920 if (min
&& value
< min
[i
])
2922 if (max
&& value
> max
[i
])
2929 /* Strategy function to convert jiffies to seconds */
2930 int sysctl_jiffies(struct ctl_table
*table
,
2931 void __user
*oldval
, size_t __user
*oldlenp
,
2932 void __user
*newval
, size_t newlen
)
2934 if (oldval
&& oldlenp
) {
2937 if (get_user(olen
, oldlenp
))
2942 if (olen
< sizeof(int))
2945 val
= *(int *)(table
->data
) / HZ
;
2946 if (put_user(val
, (int __user
*)oldval
))
2948 if (put_user(sizeof(int), oldlenp
))
2952 if (newval
&& newlen
) {
2954 if (newlen
!= sizeof(int))
2956 if (get_user(new, (int __user
*)newval
))
2958 *(int *)(table
->data
) = new*HZ
;
2963 /* Strategy function to convert jiffies to seconds */
2964 int sysctl_ms_jiffies(struct ctl_table
*table
,
2965 void __user
*oldval
, size_t __user
*oldlenp
,
2966 void __user
*newval
, size_t newlen
)
2968 if (oldval
&& oldlenp
) {
2971 if (get_user(olen
, oldlenp
))
2976 if (olen
< sizeof(int))
2979 val
= jiffies_to_msecs(*(int *)(table
->data
));
2980 if (put_user(val
, (int __user
*)oldval
))
2982 if (put_user(sizeof(int), oldlenp
))
2986 if (newval
&& newlen
) {
2988 if (newlen
!= sizeof(int))
2990 if (get_user(new, (int __user
*)newval
))
2992 *(int *)(table
->data
) = msecs_to_jiffies(new);
2999 #else /* CONFIG_SYSCTL_SYSCALL */
3002 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
3004 struct __sysctl_args tmp
;
3007 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
3010 error
= deprecated_sysctl_warning(&tmp
);
3012 /* If no error reading the parameters then just -ENOSYS ... */
3019 int sysctl_data(struct ctl_table
*table
,
3020 void __user
*oldval
, size_t __user
*oldlenp
,
3021 void __user
*newval
, size_t newlen
)
3026 int sysctl_string(struct ctl_table
*table
,
3027 void __user
*oldval
, size_t __user
*oldlenp
,
3028 void __user
*newval
, size_t newlen
)
3033 int sysctl_intvec(struct ctl_table
*table
,
3034 void __user
*oldval
, size_t __user
*oldlenp
,
3035 void __user
*newval
, size_t newlen
)
3040 int sysctl_jiffies(struct ctl_table
*table
,
3041 void __user
*oldval
, size_t __user
*oldlenp
,
3042 void __user
*newval
, size_t newlen
)
3047 int sysctl_ms_jiffies(struct ctl_table
*table
,
3048 void __user
*oldval
, size_t __user
*oldlenp
,
3049 void __user
*newval
, size_t newlen
)
3054 #endif /* CONFIG_SYSCTL_SYSCALL */
3056 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
3058 static int msg_count
;
3059 int name
[CTL_MAXNAME
];
3062 /* Check args->nlen. */
3063 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
3066 /* Read in the sysctl name for better debug message logging */
3067 for (i
= 0; i
< args
->nlen
; i
++)
3068 if (get_user(name
[i
], args
->name
+ i
))
3071 /* Ignore accesses to kernel.version */
3072 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
3075 if (msg_count
< 5) {
3078 "warning: process `%s' used the deprecated sysctl "
3079 "system call with ", current
->comm
);
3080 for (i
= 0; i
< args
->nlen
; i
++)
3081 printk("%d.", name
[i
]);
3088 * No sense putting this after each symbol definition, twice,
3089 * exception granted :-)
3091 EXPORT_SYMBOL(proc_dointvec
);
3092 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3093 EXPORT_SYMBOL(proc_dointvec_minmax
);
3094 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3095 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3096 EXPORT_SYMBOL(proc_dostring
);
3097 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3098 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
3099 EXPORT_SYMBOL(register_sysctl_table
);
3100 EXPORT_SYMBOL(register_sysctl_paths
);
3101 EXPORT_SYMBOL(sysctl_intvec
);
3102 EXPORT_SYMBOL(sysctl_jiffies
);
3103 EXPORT_SYMBOL(sysctl_ms_jiffies
);
3104 EXPORT_SYMBOL(sysctl_string
);
3105 EXPORT_SYMBOL(sysctl_data
);
3106 EXPORT_SYMBOL(unregister_sysctl_table
);