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/kmemcheck.h>
31 #include <linux/smp_lock.h>
33 #include <linux/init.h>
34 #include <linux/kernel.h>
35 #include <linux/kobject.h>
36 #include <linux/net.h>
37 #include <linux/sysrq.h>
38 #include <linux/highuid.h>
39 #include <linux/writeback.h>
40 #include <linux/hugetlb.h>
41 #include <linux/initrd.h>
42 #include <linux/key.h>
43 #include <linux/times.h>
44 #include <linux/limits.h>
45 #include <linux/dcache.h>
46 #include <linux/syscalls.h>
47 #include <linux/vmstat.h>
48 #include <linux/nfs_fs.h>
49 #include <linux/acpi.h>
50 #include <linux/reboot.h>
51 #include <linux/ftrace.h>
52 #include <linux/slow-work.h>
53 #include <linux/perf_event.h>
55 #include <asm/uaccess.h>
56 #include <asm/processor.h>
60 #include <asm/stacktrace.h>
64 static int deprecated_sysctl_warning(struct __sysctl_args
*args
);
66 #if defined(CONFIG_SYSCTL)
68 /* External variables not in a header file. */
70 extern int print_fatal_signals
;
71 extern int sysctl_overcommit_memory
;
72 extern int sysctl_overcommit_ratio
;
73 extern int sysctl_panic_on_oom
;
74 extern int sysctl_oom_kill_allocating_task
;
75 extern int sysctl_oom_dump_tasks
;
76 extern int max_threads
;
77 extern int core_uses_pid
;
78 extern int suid_dumpable
;
79 extern char core_pattern
[];
81 extern int min_free_kbytes
;
82 extern int pid_max_min
, pid_max_max
;
83 extern int sysctl_drop_caches
;
84 extern int percpu_pagelist_fraction
;
85 extern int compat_log
;
86 extern int latencytop_enabled
;
87 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
89 extern int sysctl_nr_trim_pages
;
91 #ifdef CONFIG_RCU_TORTURE_TEST
92 extern int rcutorture_runnable
;
93 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
95 extern int blk_iopoll_enabled
;
98 /* Constants used for minimum and maximum */
99 #ifdef CONFIG_DETECT_SOFTLOCKUP
100 static int sixty
= 60;
101 static int neg_one
= -1;
105 static int __maybe_unused one
= 1;
106 static int __maybe_unused two
= 2;
107 static unsigned long one_ul
= 1;
108 static int one_hundred
= 100;
110 static int ten_thousand
= 10000;
113 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
114 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
116 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
117 static int maxolduid
= 65535;
118 static int minolduid
;
119 static int min_percpu_pagelist_fract
= 8;
121 static int ngroups_max
= NGROUPS_MAX
;
123 #ifdef CONFIG_MODULES
124 extern char modprobe_path
[];
125 extern int modules_disabled
;
127 #ifdef CONFIG_CHR_DEV_SG
128 extern int sg_big_buff
;
132 #include <asm/system.h>
135 #ifdef CONFIG_SPARC64
136 extern int sysctl_tsb_ratio
;
140 extern int pwrsw_enabled
;
141 extern int unaligned_enabled
;
145 #ifdef CONFIG_MATHEMU
146 extern int sysctl_ieee_emulation_warnings
;
148 extern int sysctl_userprocess_debug
;
149 extern int spin_retry
;
152 #ifdef CONFIG_BSD_PROCESS_ACCT
153 extern int acct_parm
[];
157 extern int no_unaligned_warning
;
158 extern int unaligned_dump_stack
;
161 #ifdef CONFIG_RT_MUTEXES
162 extern int max_lock_depth
;
165 #ifdef CONFIG_PROC_SYSCTL
166 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
167 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
168 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
169 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
172 static struct ctl_table root_table
[];
173 static struct ctl_table_root sysctl_table_root
;
174 static struct ctl_table_header root_table_header
= {
176 .ctl_table
= root_table
,
177 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),
178 .root
= &sysctl_table_root
,
179 .set
= &sysctl_table_root
.default_set
,
181 static struct ctl_table_root sysctl_table_root
= {
182 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
183 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
186 static struct ctl_table kern_table
[];
187 static struct ctl_table vm_table
[];
188 static struct ctl_table fs_table
[];
189 static struct ctl_table debug_table
[];
190 static struct ctl_table dev_table
[];
191 extern struct ctl_table random_table
[];
192 #ifdef CONFIG_INOTIFY_USER
193 extern struct ctl_table inotify_table
[];
196 extern struct ctl_table epoll_table
[];
199 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
200 int sysctl_legacy_va_layout
;
203 extern int prove_locking
;
204 extern int lock_stat
;
206 /* The default sysctl tables: */
208 static struct ctl_table root_table
[] = {
210 .ctl_name
= CTL_KERN
,
211 .procname
= "kernel",
228 .ctl_name
= CTL_DEBUG
,
231 .child
= debug_table
,
240 * NOTE: do not add new entries to this table unless you have read
241 * Documentation/sysctl/ctl_unnumbered.txt
246 #ifdef CONFIG_SCHED_DEBUG
247 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
248 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
249 static int min_wakeup_granularity_ns
; /* 0 usecs */
250 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
253 static struct ctl_table kern_table
[] = {
255 .ctl_name
= CTL_UNNUMBERED
,
256 .procname
= "sched_child_runs_first",
257 .data
= &sysctl_sched_child_runs_first
,
258 .maxlen
= sizeof(unsigned int),
260 .proc_handler
= &proc_dointvec
,
262 #ifdef CONFIG_SCHED_DEBUG
264 .ctl_name
= CTL_UNNUMBERED
,
265 .procname
= "sched_min_granularity_ns",
266 .data
= &sysctl_sched_min_granularity
,
267 .maxlen
= sizeof(unsigned int),
269 .proc_handler
= &sched_nr_latency_handler
,
270 .strategy
= &sysctl_intvec
,
271 .extra1
= &min_sched_granularity_ns
,
272 .extra2
= &max_sched_granularity_ns
,
275 .ctl_name
= CTL_UNNUMBERED
,
276 .procname
= "sched_latency_ns",
277 .data
= &sysctl_sched_latency
,
278 .maxlen
= sizeof(unsigned int),
280 .proc_handler
= &sched_nr_latency_handler
,
281 .strategy
= &sysctl_intvec
,
282 .extra1
= &min_sched_granularity_ns
,
283 .extra2
= &max_sched_granularity_ns
,
286 .ctl_name
= CTL_UNNUMBERED
,
287 .procname
= "sched_wakeup_granularity_ns",
288 .data
= &sysctl_sched_wakeup_granularity
,
289 .maxlen
= sizeof(unsigned int),
291 .proc_handler
= &proc_dointvec_minmax
,
292 .strategy
= &sysctl_intvec
,
293 .extra1
= &min_wakeup_granularity_ns
,
294 .extra2
= &max_wakeup_granularity_ns
,
297 .ctl_name
= CTL_UNNUMBERED
,
298 .procname
= "sched_shares_ratelimit",
299 .data
= &sysctl_sched_shares_ratelimit
,
300 .maxlen
= sizeof(unsigned int),
302 .proc_handler
= &proc_dointvec
,
305 .ctl_name
= CTL_UNNUMBERED
,
306 .procname
= "sched_shares_thresh",
307 .data
= &sysctl_sched_shares_thresh
,
308 .maxlen
= sizeof(unsigned int),
310 .proc_handler
= &proc_dointvec_minmax
,
311 .strategy
= &sysctl_intvec
,
315 .ctl_name
= CTL_UNNUMBERED
,
316 .procname
= "sched_features",
317 .data
= &sysctl_sched_features
,
318 .maxlen
= sizeof(unsigned int),
320 .proc_handler
= &proc_dointvec
,
323 .ctl_name
= CTL_UNNUMBERED
,
324 .procname
= "sched_migration_cost",
325 .data
= &sysctl_sched_migration_cost
,
326 .maxlen
= sizeof(unsigned int),
328 .proc_handler
= &proc_dointvec
,
331 .ctl_name
= CTL_UNNUMBERED
,
332 .procname
= "sched_nr_migrate",
333 .data
= &sysctl_sched_nr_migrate
,
334 .maxlen
= sizeof(unsigned int),
336 .proc_handler
= &proc_dointvec
,
339 .ctl_name
= CTL_UNNUMBERED
,
340 .procname
= "sched_time_avg",
341 .data
= &sysctl_sched_time_avg
,
342 .maxlen
= sizeof(unsigned int),
344 .proc_handler
= &proc_dointvec
,
347 .ctl_name
= CTL_UNNUMBERED
,
348 .procname
= "timer_migration",
349 .data
= &sysctl_timer_migration
,
350 .maxlen
= sizeof(unsigned int),
352 .proc_handler
= &proc_dointvec_minmax
,
353 .strategy
= &sysctl_intvec
,
359 .ctl_name
= CTL_UNNUMBERED
,
360 .procname
= "sched_rt_period_us",
361 .data
= &sysctl_sched_rt_period
,
362 .maxlen
= sizeof(unsigned int),
364 .proc_handler
= &sched_rt_handler
,
367 .ctl_name
= CTL_UNNUMBERED
,
368 .procname
= "sched_rt_runtime_us",
369 .data
= &sysctl_sched_rt_runtime
,
370 .maxlen
= sizeof(int),
372 .proc_handler
= &sched_rt_handler
,
375 .ctl_name
= CTL_UNNUMBERED
,
376 .procname
= "sched_compat_yield",
377 .data
= &sysctl_sched_compat_yield
,
378 .maxlen
= sizeof(unsigned int),
380 .proc_handler
= &proc_dointvec
,
382 #ifdef CONFIG_PROVE_LOCKING
384 .ctl_name
= CTL_UNNUMBERED
,
385 .procname
= "prove_locking",
386 .data
= &prove_locking
,
387 .maxlen
= sizeof(int),
389 .proc_handler
= &proc_dointvec
,
392 #ifdef CONFIG_LOCK_STAT
394 .ctl_name
= CTL_UNNUMBERED
,
395 .procname
= "lock_stat",
397 .maxlen
= sizeof(int),
399 .proc_handler
= &proc_dointvec
,
403 .ctl_name
= KERN_PANIC
,
405 .data
= &panic_timeout
,
406 .maxlen
= sizeof(int),
408 .proc_handler
= &proc_dointvec
,
411 .ctl_name
= KERN_CORE_USES_PID
,
412 .procname
= "core_uses_pid",
413 .data
= &core_uses_pid
,
414 .maxlen
= sizeof(int),
416 .proc_handler
= &proc_dointvec
,
419 .ctl_name
= KERN_CORE_PATTERN
,
420 .procname
= "core_pattern",
421 .data
= core_pattern
,
422 .maxlen
= CORENAME_MAX_SIZE
,
424 .proc_handler
= &proc_dostring
,
425 .strategy
= &sysctl_string
,
427 #ifdef CONFIG_PROC_SYSCTL
429 .procname
= "tainted",
430 .maxlen
= sizeof(long),
432 .proc_handler
= &proc_taint
,
435 #ifdef CONFIG_LATENCYTOP
437 .procname
= "latencytop",
438 .data
= &latencytop_enabled
,
439 .maxlen
= sizeof(int),
441 .proc_handler
= &proc_dointvec
,
444 #ifdef CONFIG_BLK_DEV_INITRD
446 .ctl_name
= KERN_REALROOTDEV
,
447 .procname
= "real-root-dev",
448 .data
= &real_root_dev
,
449 .maxlen
= sizeof(int),
451 .proc_handler
= &proc_dointvec
,
455 .ctl_name
= CTL_UNNUMBERED
,
456 .procname
= "print-fatal-signals",
457 .data
= &print_fatal_signals
,
458 .maxlen
= sizeof(int),
460 .proc_handler
= &proc_dointvec
,
464 .ctl_name
= KERN_SPARC_REBOOT
,
465 .procname
= "reboot-cmd",
466 .data
= reboot_command
,
469 .proc_handler
= &proc_dostring
,
470 .strategy
= &sysctl_string
,
473 .ctl_name
= KERN_SPARC_STOP_A
,
474 .procname
= "stop-a",
475 .data
= &stop_a_enabled
,
476 .maxlen
= sizeof (int),
478 .proc_handler
= &proc_dointvec
,
481 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
482 .procname
= "scons-poweroff",
483 .data
= &scons_pwroff
,
484 .maxlen
= sizeof (int),
486 .proc_handler
= &proc_dointvec
,
489 #ifdef CONFIG_SPARC64
491 .ctl_name
= CTL_UNNUMBERED
,
492 .procname
= "tsb-ratio",
493 .data
= &sysctl_tsb_ratio
,
494 .maxlen
= sizeof (int),
496 .proc_handler
= &proc_dointvec
,
501 .ctl_name
= KERN_HPPA_PWRSW
,
502 .procname
= "soft-power",
503 .data
= &pwrsw_enabled
,
504 .maxlen
= sizeof (int),
506 .proc_handler
= &proc_dointvec
,
509 .ctl_name
= KERN_HPPA_UNALIGNED
,
510 .procname
= "unaligned-trap",
511 .data
= &unaligned_enabled
,
512 .maxlen
= sizeof (int),
514 .proc_handler
= &proc_dointvec
,
518 .ctl_name
= KERN_CTLALTDEL
,
519 .procname
= "ctrl-alt-del",
521 .maxlen
= sizeof(int),
523 .proc_handler
= &proc_dointvec
,
525 #ifdef CONFIG_FUNCTION_TRACER
527 .ctl_name
= CTL_UNNUMBERED
,
528 .procname
= "ftrace_enabled",
529 .data
= &ftrace_enabled
,
530 .maxlen
= sizeof(int),
532 .proc_handler
= &ftrace_enable_sysctl
,
535 #ifdef CONFIG_STACK_TRACER
537 .ctl_name
= CTL_UNNUMBERED
,
538 .procname
= "stack_tracer_enabled",
539 .data
= &stack_tracer_enabled
,
540 .maxlen
= sizeof(int),
542 .proc_handler
= &stack_trace_sysctl
,
545 #ifdef CONFIG_TRACING
547 .ctl_name
= CTL_UNNUMBERED
,
548 .procname
= "ftrace_dump_on_oops",
549 .data
= &ftrace_dump_on_oops
,
550 .maxlen
= sizeof(int),
552 .proc_handler
= &proc_dointvec
,
555 #ifdef CONFIG_MODULES
557 .ctl_name
= KERN_MODPROBE
,
558 .procname
= "modprobe",
559 .data
= &modprobe_path
,
560 .maxlen
= KMOD_PATH_LEN
,
562 .proc_handler
= &proc_dostring
,
563 .strategy
= &sysctl_string
,
566 .ctl_name
= CTL_UNNUMBERED
,
567 .procname
= "modules_disabled",
568 .data
= &modules_disabled
,
569 .maxlen
= sizeof(int),
571 /* only handle a transition from default "0" to "1" */
572 .proc_handler
= &proc_dointvec_minmax
,
577 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
579 .ctl_name
= KERN_HOTPLUG
,
580 .procname
= "hotplug",
581 .data
= &uevent_helper
,
582 .maxlen
= UEVENT_HELPER_PATH_LEN
,
584 .proc_handler
= &proc_dostring
,
585 .strategy
= &sysctl_string
,
588 #ifdef CONFIG_CHR_DEV_SG
590 .ctl_name
= KERN_SG_BIG_BUFF
,
591 .procname
= "sg-big-buff",
592 .data
= &sg_big_buff
,
593 .maxlen
= sizeof (int),
595 .proc_handler
= &proc_dointvec
,
598 #ifdef CONFIG_BSD_PROCESS_ACCT
600 .ctl_name
= KERN_ACCT
,
603 .maxlen
= 3*sizeof(int),
605 .proc_handler
= &proc_dointvec
,
608 #ifdef CONFIG_MAGIC_SYSRQ
610 .ctl_name
= KERN_SYSRQ
,
612 .data
= &__sysrq_enabled
,
613 .maxlen
= sizeof (int),
615 .proc_handler
= &proc_dointvec
,
618 #ifdef CONFIG_PROC_SYSCTL
620 .procname
= "cad_pid",
622 .maxlen
= sizeof (int),
624 .proc_handler
= &proc_do_cad_pid
,
628 .ctl_name
= KERN_MAX_THREADS
,
629 .procname
= "threads-max",
630 .data
= &max_threads
,
631 .maxlen
= sizeof(int),
633 .proc_handler
= &proc_dointvec
,
636 .ctl_name
= KERN_RANDOM
,
637 .procname
= "random",
639 .child
= random_table
,
642 .ctl_name
= KERN_OVERFLOWUID
,
643 .procname
= "overflowuid",
644 .data
= &overflowuid
,
645 .maxlen
= sizeof(int),
647 .proc_handler
= &proc_dointvec_minmax
,
648 .strategy
= &sysctl_intvec
,
649 .extra1
= &minolduid
,
650 .extra2
= &maxolduid
,
653 .ctl_name
= KERN_OVERFLOWGID
,
654 .procname
= "overflowgid",
655 .data
= &overflowgid
,
656 .maxlen
= sizeof(int),
658 .proc_handler
= &proc_dointvec_minmax
,
659 .strategy
= &sysctl_intvec
,
660 .extra1
= &minolduid
,
661 .extra2
= &maxolduid
,
664 #ifdef CONFIG_MATHEMU
666 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
667 .procname
= "ieee_emulation_warnings",
668 .data
= &sysctl_ieee_emulation_warnings
,
669 .maxlen
= sizeof(int),
671 .proc_handler
= &proc_dointvec
,
675 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
676 .procname
= "userprocess_debug",
677 .data
= &sysctl_userprocess_debug
,
678 .maxlen
= sizeof(int),
680 .proc_handler
= &proc_dointvec
,
684 .ctl_name
= KERN_PIDMAX
,
685 .procname
= "pid_max",
687 .maxlen
= sizeof (int),
689 .proc_handler
= &proc_dointvec_minmax
,
690 .strategy
= sysctl_intvec
,
691 .extra1
= &pid_max_min
,
692 .extra2
= &pid_max_max
,
695 .ctl_name
= KERN_PANIC_ON_OOPS
,
696 .procname
= "panic_on_oops",
697 .data
= &panic_on_oops
,
698 .maxlen
= sizeof(int),
700 .proc_handler
= &proc_dointvec
,
702 #if defined CONFIG_PRINTK
704 .ctl_name
= KERN_PRINTK
,
705 .procname
= "printk",
706 .data
= &console_loglevel
,
707 .maxlen
= 4*sizeof(int),
709 .proc_handler
= &proc_dointvec
,
712 .ctl_name
= KERN_PRINTK_RATELIMIT
,
713 .procname
= "printk_ratelimit",
714 .data
= &printk_ratelimit_state
.interval
,
715 .maxlen
= sizeof(int),
717 .proc_handler
= &proc_dointvec_jiffies
,
718 .strategy
= &sysctl_jiffies
,
721 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
722 .procname
= "printk_ratelimit_burst",
723 .data
= &printk_ratelimit_state
.burst
,
724 .maxlen
= sizeof(int),
726 .proc_handler
= &proc_dointvec
,
729 .ctl_name
= CTL_UNNUMBERED
,
730 .procname
= "printk_delay",
731 .data
= &printk_delay_msec
,
732 .maxlen
= sizeof(int),
734 .proc_handler
= &proc_dointvec_minmax
,
735 .strategy
= &sysctl_intvec
,
737 .extra2
= &ten_thousand
,
741 .ctl_name
= KERN_NGROUPS_MAX
,
742 .procname
= "ngroups_max",
743 .data
= &ngroups_max
,
744 .maxlen
= sizeof (int),
746 .proc_handler
= &proc_dointvec
,
748 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
750 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
751 .procname
= "unknown_nmi_panic",
752 .data
= &unknown_nmi_panic
,
753 .maxlen
= sizeof (int),
755 .proc_handler
= &proc_dointvec
,
758 .procname
= "nmi_watchdog",
759 .data
= &nmi_watchdog_enabled
,
760 .maxlen
= sizeof (int),
762 .proc_handler
= &proc_nmi_enabled
,
765 #if defined(CONFIG_X86)
767 .ctl_name
= KERN_PANIC_ON_NMI
,
768 .procname
= "panic_on_unrecovered_nmi",
769 .data
= &panic_on_unrecovered_nmi
,
770 .maxlen
= sizeof(int),
772 .proc_handler
= &proc_dointvec
,
775 .ctl_name
= CTL_UNNUMBERED
,
776 .procname
= "panic_on_io_nmi",
777 .data
= &panic_on_io_nmi
,
778 .maxlen
= sizeof(int),
780 .proc_handler
= &proc_dointvec
,
783 .ctl_name
= KERN_BOOTLOADER_TYPE
,
784 .procname
= "bootloader_type",
785 .data
= &bootloader_type
,
786 .maxlen
= sizeof (int),
788 .proc_handler
= &proc_dointvec
,
791 .ctl_name
= CTL_UNNUMBERED
,
792 .procname
= "bootloader_version",
793 .data
= &bootloader_version
,
794 .maxlen
= sizeof (int),
796 .proc_handler
= &proc_dointvec
,
799 .ctl_name
= CTL_UNNUMBERED
,
800 .procname
= "kstack_depth_to_print",
801 .data
= &kstack_depth_to_print
,
802 .maxlen
= sizeof(int),
804 .proc_handler
= &proc_dointvec
,
807 .ctl_name
= CTL_UNNUMBERED
,
808 .procname
= "io_delay_type",
809 .data
= &io_delay_type
,
810 .maxlen
= sizeof(int),
812 .proc_handler
= &proc_dointvec
,
815 #if defined(CONFIG_MMU)
817 .ctl_name
= KERN_RANDOMIZE
,
818 .procname
= "randomize_va_space",
819 .data
= &randomize_va_space
,
820 .maxlen
= sizeof(int),
822 .proc_handler
= &proc_dointvec
,
825 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
827 .ctl_name
= KERN_SPIN_RETRY
,
828 .procname
= "spin_retry",
830 .maxlen
= sizeof (int),
832 .proc_handler
= &proc_dointvec
,
835 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
837 .procname
= "acpi_video_flags",
838 .data
= &acpi_realmode_flags
,
839 .maxlen
= sizeof (unsigned long),
841 .proc_handler
= &proc_doulongvec_minmax
,
846 .ctl_name
= KERN_IA64_UNALIGNED
,
847 .procname
= "ignore-unaligned-usertrap",
848 .data
= &no_unaligned_warning
,
849 .maxlen
= sizeof (int),
851 .proc_handler
= &proc_dointvec
,
854 .ctl_name
= CTL_UNNUMBERED
,
855 .procname
= "unaligned-dump-stack",
856 .data
= &unaligned_dump_stack
,
857 .maxlen
= sizeof (int),
859 .proc_handler
= &proc_dointvec
,
862 #ifdef CONFIG_DETECT_SOFTLOCKUP
864 .ctl_name
= CTL_UNNUMBERED
,
865 .procname
= "softlockup_panic",
866 .data
= &softlockup_panic
,
867 .maxlen
= sizeof(int),
869 .proc_handler
= &proc_dointvec_minmax
,
870 .strategy
= &sysctl_intvec
,
875 .ctl_name
= CTL_UNNUMBERED
,
876 .procname
= "softlockup_thresh",
877 .data
= &softlockup_thresh
,
878 .maxlen
= sizeof(int),
880 .proc_handler
= &proc_dosoftlockup_thresh
,
881 .strategy
= &sysctl_intvec
,
886 #ifdef CONFIG_DETECT_HUNG_TASK
888 .ctl_name
= CTL_UNNUMBERED
,
889 .procname
= "hung_task_panic",
890 .data
= &sysctl_hung_task_panic
,
891 .maxlen
= sizeof(int),
893 .proc_handler
= &proc_dointvec_minmax
,
894 .strategy
= &sysctl_intvec
,
899 .ctl_name
= CTL_UNNUMBERED
,
900 .procname
= "hung_task_check_count",
901 .data
= &sysctl_hung_task_check_count
,
902 .maxlen
= sizeof(unsigned long),
904 .proc_handler
= &proc_doulongvec_minmax
,
905 .strategy
= &sysctl_intvec
,
908 .ctl_name
= CTL_UNNUMBERED
,
909 .procname
= "hung_task_timeout_secs",
910 .data
= &sysctl_hung_task_timeout_secs
,
911 .maxlen
= sizeof(unsigned long),
913 .proc_handler
= &proc_dohung_task_timeout_secs
,
914 .strategy
= &sysctl_intvec
,
917 .ctl_name
= CTL_UNNUMBERED
,
918 .procname
= "hung_task_warnings",
919 .data
= &sysctl_hung_task_warnings
,
920 .maxlen
= sizeof(unsigned long),
922 .proc_handler
= &proc_doulongvec_minmax
,
923 .strategy
= &sysctl_intvec
,
928 .ctl_name
= KERN_COMPAT_LOG
,
929 .procname
= "compat-log",
931 .maxlen
= sizeof (int),
933 .proc_handler
= &proc_dointvec
,
936 #ifdef CONFIG_RT_MUTEXES
938 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
939 .procname
= "max_lock_depth",
940 .data
= &max_lock_depth
,
941 .maxlen
= sizeof(int),
943 .proc_handler
= &proc_dointvec
,
947 .ctl_name
= CTL_UNNUMBERED
,
948 .procname
= "poweroff_cmd",
949 .data
= &poweroff_cmd
,
950 .maxlen
= POWEROFF_CMD_PATH_LEN
,
952 .proc_handler
= &proc_dostring
,
953 .strategy
= &sysctl_string
,
957 .ctl_name
= CTL_UNNUMBERED
,
960 .child
= key_sysctls
,
963 #ifdef CONFIG_RCU_TORTURE_TEST
965 .ctl_name
= CTL_UNNUMBERED
,
966 .procname
= "rcutorture_runnable",
967 .data
= &rcutorture_runnable
,
968 .maxlen
= sizeof(int),
970 .proc_handler
= &proc_dointvec
,
973 #ifdef CONFIG_SLOW_WORK
975 .ctl_name
= CTL_UNNUMBERED
,
976 .procname
= "slow-work",
978 .child
= slow_work_sysctls
,
981 #ifdef CONFIG_PERF_EVENTS
983 .ctl_name
= CTL_UNNUMBERED
,
984 .procname
= "perf_event_paranoid",
985 .data
= &sysctl_perf_event_paranoid
,
986 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
988 .proc_handler
= &proc_dointvec
,
991 .ctl_name
= CTL_UNNUMBERED
,
992 .procname
= "perf_event_mlock_kb",
993 .data
= &sysctl_perf_event_mlock
,
994 .maxlen
= sizeof(sysctl_perf_event_mlock
),
996 .proc_handler
= &proc_dointvec
,
999 .ctl_name
= CTL_UNNUMBERED
,
1000 .procname
= "perf_event_max_sample_rate",
1001 .data
= &sysctl_perf_event_sample_rate
,
1002 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1004 .proc_handler
= &proc_dointvec
,
1007 #ifdef CONFIG_KMEMCHECK
1009 .ctl_name
= CTL_UNNUMBERED
,
1010 .procname
= "kmemcheck",
1011 .data
= &kmemcheck_enabled
,
1012 .maxlen
= sizeof(int),
1014 .proc_handler
= &proc_dointvec
,
1019 .ctl_name
= CTL_UNNUMBERED
,
1020 .procname
= "blk_iopoll",
1021 .data
= &blk_iopoll_enabled
,
1022 .maxlen
= sizeof(int),
1024 .proc_handler
= &proc_dointvec
,
1028 * NOTE: do not add new entries to this table unless you have read
1029 * Documentation/sysctl/ctl_unnumbered.txt
1034 static struct ctl_table vm_table
[] = {
1036 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
1037 .procname
= "overcommit_memory",
1038 .data
= &sysctl_overcommit_memory
,
1039 .maxlen
= sizeof(sysctl_overcommit_memory
),
1041 .proc_handler
= &proc_dointvec
,
1044 .ctl_name
= VM_PANIC_ON_OOM
,
1045 .procname
= "panic_on_oom",
1046 .data
= &sysctl_panic_on_oom
,
1047 .maxlen
= sizeof(sysctl_panic_on_oom
),
1049 .proc_handler
= &proc_dointvec
,
1052 .ctl_name
= CTL_UNNUMBERED
,
1053 .procname
= "oom_kill_allocating_task",
1054 .data
= &sysctl_oom_kill_allocating_task
,
1055 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1057 .proc_handler
= &proc_dointvec
,
1060 .ctl_name
= CTL_UNNUMBERED
,
1061 .procname
= "oom_dump_tasks",
1062 .data
= &sysctl_oom_dump_tasks
,
1063 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1065 .proc_handler
= &proc_dointvec
,
1068 .ctl_name
= VM_OVERCOMMIT_RATIO
,
1069 .procname
= "overcommit_ratio",
1070 .data
= &sysctl_overcommit_ratio
,
1071 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1073 .proc_handler
= &proc_dointvec
,
1076 .ctl_name
= VM_PAGE_CLUSTER
,
1077 .procname
= "page-cluster",
1078 .data
= &page_cluster
,
1079 .maxlen
= sizeof(int),
1081 .proc_handler
= &proc_dointvec
,
1084 .ctl_name
= VM_DIRTY_BACKGROUND
,
1085 .procname
= "dirty_background_ratio",
1086 .data
= &dirty_background_ratio
,
1087 .maxlen
= sizeof(dirty_background_ratio
),
1089 .proc_handler
= &dirty_background_ratio_handler
,
1090 .strategy
= &sysctl_intvec
,
1092 .extra2
= &one_hundred
,
1095 .ctl_name
= CTL_UNNUMBERED
,
1096 .procname
= "dirty_background_bytes",
1097 .data
= &dirty_background_bytes
,
1098 .maxlen
= sizeof(dirty_background_bytes
),
1100 .proc_handler
= &dirty_background_bytes_handler
,
1101 .strategy
= &sysctl_intvec
,
1105 .ctl_name
= VM_DIRTY_RATIO
,
1106 .procname
= "dirty_ratio",
1107 .data
= &vm_dirty_ratio
,
1108 .maxlen
= sizeof(vm_dirty_ratio
),
1110 .proc_handler
= &dirty_ratio_handler
,
1111 .strategy
= &sysctl_intvec
,
1113 .extra2
= &one_hundred
,
1116 .ctl_name
= CTL_UNNUMBERED
,
1117 .procname
= "dirty_bytes",
1118 .data
= &vm_dirty_bytes
,
1119 .maxlen
= sizeof(vm_dirty_bytes
),
1121 .proc_handler
= &dirty_bytes_handler
,
1122 .strategy
= &sysctl_intvec
,
1123 .extra1
= &dirty_bytes_min
,
1126 .procname
= "dirty_writeback_centisecs",
1127 .data
= &dirty_writeback_interval
,
1128 .maxlen
= sizeof(dirty_writeback_interval
),
1130 .proc_handler
= &dirty_writeback_centisecs_handler
,
1133 .procname
= "dirty_expire_centisecs",
1134 .data
= &dirty_expire_interval
,
1135 .maxlen
= sizeof(dirty_expire_interval
),
1137 .proc_handler
= &proc_dointvec
,
1140 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
1141 .procname
= "nr_pdflush_threads",
1142 .data
= &nr_pdflush_threads
,
1143 .maxlen
= sizeof nr_pdflush_threads
,
1144 .mode
= 0444 /* read-only*/,
1145 .proc_handler
= &proc_dointvec
,
1148 .ctl_name
= VM_SWAPPINESS
,
1149 .procname
= "swappiness",
1150 .data
= &vm_swappiness
,
1151 .maxlen
= sizeof(vm_swappiness
),
1153 .proc_handler
= &proc_dointvec_minmax
,
1154 .strategy
= &sysctl_intvec
,
1156 .extra2
= &one_hundred
,
1158 #ifdef CONFIG_HUGETLB_PAGE
1160 .procname
= "nr_hugepages",
1162 .maxlen
= sizeof(unsigned long),
1164 .proc_handler
= &hugetlb_sysctl_handler
,
1165 .extra1
= (void *)&hugetlb_zero
,
1166 .extra2
= (void *)&hugetlb_infinity
,
1169 .ctl_name
= VM_HUGETLB_GROUP
,
1170 .procname
= "hugetlb_shm_group",
1171 .data
= &sysctl_hugetlb_shm_group
,
1172 .maxlen
= sizeof(gid_t
),
1174 .proc_handler
= &proc_dointvec
,
1177 .ctl_name
= CTL_UNNUMBERED
,
1178 .procname
= "hugepages_treat_as_movable",
1179 .data
= &hugepages_treat_as_movable
,
1180 .maxlen
= sizeof(int),
1182 .proc_handler
= &hugetlb_treat_movable_handler
,
1185 .ctl_name
= CTL_UNNUMBERED
,
1186 .procname
= "nr_overcommit_hugepages",
1188 .maxlen
= sizeof(unsigned long),
1190 .proc_handler
= &hugetlb_overcommit_handler
,
1191 .extra1
= (void *)&hugetlb_zero
,
1192 .extra2
= (void *)&hugetlb_infinity
,
1196 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
1197 .procname
= "lowmem_reserve_ratio",
1198 .data
= &sysctl_lowmem_reserve_ratio
,
1199 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1201 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
1202 .strategy
= &sysctl_intvec
,
1205 .ctl_name
= VM_DROP_PAGECACHE
,
1206 .procname
= "drop_caches",
1207 .data
= &sysctl_drop_caches
,
1208 .maxlen
= sizeof(int),
1210 .proc_handler
= drop_caches_sysctl_handler
,
1211 .strategy
= &sysctl_intvec
,
1214 .ctl_name
= VM_MIN_FREE_KBYTES
,
1215 .procname
= "min_free_kbytes",
1216 .data
= &min_free_kbytes
,
1217 .maxlen
= sizeof(min_free_kbytes
),
1219 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1220 .strategy
= &sysctl_intvec
,
1224 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1225 .procname
= "percpu_pagelist_fraction",
1226 .data
= &percpu_pagelist_fraction
,
1227 .maxlen
= sizeof(percpu_pagelist_fraction
),
1229 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1230 .strategy
= &sysctl_intvec
,
1231 .extra1
= &min_percpu_pagelist_fract
,
1235 .ctl_name
= VM_MAX_MAP_COUNT
,
1236 .procname
= "max_map_count",
1237 .data
= &sysctl_max_map_count
,
1238 .maxlen
= sizeof(sysctl_max_map_count
),
1240 .proc_handler
= &proc_dointvec
1244 .ctl_name
= CTL_UNNUMBERED
,
1245 .procname
= "nr_trim_pages",
1246 .data
= &sysctl_nr_trim_pages
,
1247 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1249 .proc_handler
= &proc_dointvec_minmax
,
1250 .strategy
= &sysctl_intvec
,
1255 .ctl_name
= VM_LAPTOP_MODE
,
1256 .procname
= "laptop_mode",
1257 .data
= &laptop_mode
,
1258 .maxlen
= sizeof(laptop_mode
),
1260 .proc_handler
= &proc_dointvec_jiffies
,
1261 .strategy
= &sysctl_jiffies
,
1264 .ctl_name
= VM_BLOCK_DUMP
,
1265 .procname
= "block_dump",
1266 .data
= &block_dump
,
1267 .maxlen
= sizeof(block_dump
),
1269 .proc_handler
= &proc_dointvec
,
1270 .strategy
= &sysctl_intvec
,
1274 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1275 .procname
= "vfs_cache_pressure",
1276 .data
= &sysctl_vfs_cache_pressure
,
1277 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1279 .proc_handler
= &proc_dointvec
,
1280 .strategy
= &sysctl_intvec
,
1283 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1285 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1286 .procname
= "legacy_va_layout",
1287 .data
= &sysctl_legacy_va_layout
,
1288 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1290 .proc_handler
= &proc_dointvec
,
1291 .strategy
= &sysctl_intvec
,
1297 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1298 .procname
= "zone_reclaim_mode",
1299 .data
= &zone_reclaim_mode
,
1300 .maxlen
= sizeof(zone_reclaim_mode
),
1302 .proc_handler
= &proc_dointvec
,
1303 .strategy
= &sysctl_intvec
,
1307 .ctl_name
= VM_MIN_UNMAPPED
,
1308 .procname
= "min_unmapped_ratio",
1309 .data
= &sysctl_min_unmapped_ratio
,
1310 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1312 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1313 .strategy
= &sysctl_intvec
,
1315 .extra2
= &one_hundred
,
1318 .ctl_name
= VM_MIN_SLAB
,
1319 .procname
= "min_slab_ratio",
1320 .data
= &sysctl_min_slab_ratio
,
1321 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1323 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1324 .strategy
= &sysctl_intvec
,
1326 .extra2
= &one_hundred
,
1331 .ctl_name
= CTL_UNNUMBERED
,
1332 .procname
= "stat_interval",
1333 .data
= &sysctl_stat_interval
,
1334 .maxlen
= sizeof(sysctl_stat_interval
),
1336 .proc_handler
= &proc_dointvec_jiffies
,
1337 .strategy
= &sysctl_jiffies
,
1341 .ctl_name
= CTL_UNNUMBERED
,
1342 .procname
= "mmap_min_addr",
1343 .data
= &dac_mmap_min_addr
,
1344 .maxlen
= sizeof(unsigned long),
1346 .proc_handler
= &mmap_min_addr_handler
,
1350 .ctl_name
= CTL_UNNUMBERED
,
1351 .procname
= "numa_zonelist_order",
1352 .data
= &numa_zonelist_order
,
1353 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1355 .proc_handler
= &numa_zonelist_order_handler
,
1356 .strategy
= &sysctl_string
,
1359 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1360 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1362 .ctl_name
= VM_VDSO_ENABLED
,
1363 .procname
= "vdso_enabled",
1364 .data
= &vdso_enabled
,
1365 .maxlen
= sizeof(vdso_enabled
),
1367 .proc_handler
= &proc_dointvec
,
1368 .strategy
= &sysctl_intvec
,
1372 #ifdef CONFIG_HIGHMEM
1374 .ctl_name
= CTL_UNNUMBERED
,
1375 .procname
= "highmem_is_dirtyable",
1376 .data
= &vm_highmem_is_dirtyable
,
1377 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1379 .proc_handler
= &proc_dointvec_minmax
,
1380 .strategy
= &sysctl_intvec
,
1386 .ctl_name
= CTL_UNNUMBERED
,
1387 .procname
= "scan_unevictable_pages",
1388 .data
= &scan_unevictable_pages
,
1389 .maxlen
= sizeof(scan_unevictable_pages
),
1391 .proc_handler
= &scan_unevictable_handler
,
1394 * NOTE: do not add new entries to this table unless you have read
1395 * Documentation/sysctl/ctl_unnumbered.txt
1400 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1401 static struct ctl_table binfmt_misc_table
[] = {
1406 static struct ctl_table fs_table
[] = {
1408 .ctl_name
= FS_NRINODE
,
1409 .procname
= "inode-nr",
1410 .data
= &inodes_stat
,
1411 .maxlen
= 2*sizeof(int),
1413 .proc_handler
= &proc_dointvec
,
1416 .ctl_name
= FS_STATINODE
,
1417 .procname
= "inode-state",
1418 .data
= &inodes_stat
,
1419 .maxlen
= 7*sizeof(int),
1421 .proc_handler
= &proc_dointvec
,
1424 .procname
= "file-nr",
1425 .data
= &files_stat
,
1426 .maxlen
= 3*sizeof(int),
1428 .proc_handler
= &proc_nr_files
,
1431 .ctl_name
= FS_MAXFILE
,
1432 .procname
= "file-max",
1433 .data
= &files_stat
.max_files
,
1434 .maxlen
= sizeof(int),
1436 .proc_handler
= &proc_dointvec
,
1439 .ctl_name
= CTL_UNNUMBERED
,
1440 .procname
= "nr_open",
1441 .data
= &sysctl_nr_open
,
1442 .maxlen
= sizeof(int),
1444 .proc_handler
= &proc_dointvec_minmax
,
1445 .extra1
= &sysctl_nr_open_min
,
1446 .extra2
= &sysctl_nr_open_max
,
1449 .ctl_name
= FS_DENTRY
,
1450 .procname
= "dentry-state",
1451 .data
= &dentry_stat
,
1452 .maxlen
= 6*sizeof(int),
1454 .proc_handler
= &proc_dointvec
,
1457 .ctl_name
= FS_OVERFLOWUID
,
1458 .procname
= "overflowuid",
1459 .data
= &fs_overflowuid
,
1460 .maxlen
= sizeof(int),
1462 .proc_handler
= &proc_dointvec_minmax
,
1463 .strategy
= &sysctl_intvec
,
1464 .extra1
= &minolduid
,
1465 .extra2
= &maxolduid
,
1468 .ctl_name
= FS_OVERFLOWGID
,
1469 .procname
= "overflowgid",
1470 .data
= &fs_overflowgid
,
1471 .maxlen
= sizeof(int),
1473 .proc_handler
= &proc_dointvec_minmax
,
1474 .strategy
= &sysctl_intvec
,
1475 .extra1
= &minolduid
,
1476 .extra2
= &maxolduid
,
1478 #ifdef CONFIG_FILE_LOCKING
1480 .ctl_name
= FS_LEASES
,
1481 .procname
= "leases-enable",
1482 .data
= &leases_enable
,
1483 .maxlen
= sizeof(int),
1485 .proc_handler
= &proc_dointvec
,
1488 #ifdef CONFIG_DNOTIFY
1490 .ctl_name
= FS_DIR_NOTIFY
,
1491 .procname
= "dir-notify-enable",
1492 .data
= &dir_notify_enable
,
1493 .maxlen
= sizeof(int),
1495 .proc_handler
= &proc_dointvec
,
1499 #ifdef CONFIG_FILE_LOCKING
1501 .ctl_name
= FS_LEASE_TIME
,
1502 .procname
= "lease-break-time",
1503 .data
= &lease_break_time
,
1504 .maxlen
= sizeof(int),
1506 .proc_handler
= &proc_dointvec
,
1511 .procname
= "aio-nr",
1513 .maxlen
= sizeof(aio_nr
),
1515 .proc_handler
= &proc_doulongvec_minmax
,
1518 .procname
= "aio-max-nr",
1519 .data
= &aio_max_nr
,
1520 .maxlen
= sizeof(aio_max_nr
),
1522 .proc_handler
= &proc_doulongvec_minmax
,
1524 #endif /* CONFIG_AIO */
1525 #ifdef CONFIG_INOTIFY_USER
1527 .ctl_name
= FS_INOTIFY
,
1528 .procname
= "inotify",
1530 .child
= inotify_table
,
1535 .procname
= "epoll",
1537 .child
= epoll_table
,
1542 .ctl_name
= KERN_SETUID_DUMPABLE
,
1543 .procname
= "suid_dumpable",
1544 .data
= &suid_dumpable
,
1545 .maxlen
= sizeof(int),
1547 .proc_handler
= &proc_dointvec_minmax
,
1548 .strategy
= &sysctl_intvec
,
1552 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1554 .ctl_name
= CTL_UNNUMBERED
,
1555 .procname
= "binfmt_misc",
1557 .child
= binfmt_misc_table
,
1561 * NOTE: do not add new entries to this table unless you have read
1562 * Documentation/sysctl/ctl_unnumbered.txt
1567 static struct ctl_table debug_table
[] = {
1568 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1570 .ctl_name
= CTL_UNNUMBERED
,
1571 .procname
= "exception-trace",
1572 .data
= &show_unhandled_signals
,
1573 .maxlen
= sizeof(int),
1575 .proc_handler
= proc_dointvec
1581 static struct ctl_table dev_table
[] = {
1585 static DEFINE_SPINLOCK(sysctl_lock
);
1587 /* called under sysctl_lock */
1588 static int use_table(struct ctl_table_header
*p
)
1590 if (unlikely(p
->unregistering
))
1596 /* called under sysctl_lock */
1597 static void unuse_table(struct ctl_table_header
*p
)
1600 if (unlikely(p
->unregistering
))
1601 complete(p
->unregistering
);
1604 /* called under sysctl_lock, will reacquire if has to wait */
1605 static void start_unregistering(struct ctl_table_header
*p
)
1608 * if p->used is 0, nobody will ever touch that entry again;
1609 * we'll eliminate all paths to it before dropping sysctl_lock
1611 if (unlikely(p
->used
)) {
1612 struct completion wait
;
1613 init_completion(&wait
);
1614 p
->unregistering
= &wait
;
1615 spin_unlock(&sysctl_lock
);
1616 wait_for_completion(&wait
);
1617 spin_lock(&sysctl_lock
);
1619 /* anything non-NULL; we'll never dereference it */
1620 p
->unregistering
= ERR_PTR(-EINVAL
);
1623 * do not remove from the list until nobody holds it; walking the
1624 * list in do_sysctl() relies on that.
1626 list_del_init(&p
->ctl_entry
);
1629 void sysctl_head_get(struct ctl_table_header
*head
)
1631 spin_lock(&sysctl_lock
);
1633 spin_unlock(&sysctl_lock
);
1636 void sysctl_head_put(struct ctl_table_header
*head
)
1638 spin_lock(&sysctl_lock
);
1641 spin_unlock(&sysctl_lock
);
1644 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1648 spin_lock(&sysctl_lock
);
1649 if (!use_table(head
))
1650 head
= ERR_PTR(-ENOENT
);
1651 spin_unlock(&sysctl_lock
);
1655 void sysctl_head_finish(struct ctl_table_header
*head
)
1659 spin_lock(&sysctl_lock
);
1661 spin_unlock(&sysctl_lock
);
1664 static struct ctl_table_set
*
1665 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1667 struct ctl_table_set
*set
= &root
->default_set
;
1669 set
= root
->lookup(root
, namespaces
);
1673 static struct list_head
*
1674 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1676 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1680 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1681 struct ctl_table_header
*prev
)
1683 struct ctl_table_root
*root
;
1684 struct list_head
*header_list
;
1685 struct ctl_table_header
*head
;
1686 struct list_head
*tmp
;
1688 spin_lock(&sysctl_lock
);
1691 tmp
= &prev
->ctl_entry
;
1695 tmp
= &root_table_header
.ctl_entry
;
1697 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1699 if (!use_table(head
))
1701 spin_unlock(&sysctl_lock
);
1706 header_list
= lookup_header_list(root
, namespaces
);
1707 if (tmp
!= header_list
)
1711 root
= list_entry(root
->root_list
.next
,
1712 struct ctl_table_root
, root_list
);
1713 if (root
== &sysctl_table_root
)
1715 header_list
= lookup_header_list(root
, namespaces
);
1716 } while (list_empty(header_list
));
1717 tmp
= header_list
->next
;
1720 spin_unlock(&sysctl_lock
);
1724 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1726 return __sysctl_head_next(current
->nsproxy
, prev
);
1729 void register_sysctl_root(struct ctl_table_root
*root
)
1731 spin_lock(&sysctl_lock
);
1732 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1733 spin_unlock(&sysctl_lock
);
1736 #ifdef CONFIG_SYSCTL_SYSCALL
1737 /* Perform the actual read/write of a sysctl table entry. */
1738 static int do_sysctl_strategy(struct ctl_table_root
*root
,
1739 struct ctl_table
*table
,
1740 void __user
*oldval
, size_t __user
*oldlenp
,
1741 void __user
*newval
, size_t newlen
)
1749 if (sysctl_perm(root
, table
, op
))
1752 if (table
->strategy
) {
1753 rc
= table
->strategy(table
, oldval
, oldlenp
, newval
, newlen
);
1760 /* If there is no strategy routine, or if the strategy returns
1761 * zero, proceed with automatic r/w */
1762 if (table
->data
&& table
->maxlen
) {
1763 rc
= sysctl_data(table
, oldval
, oldlenp
, newval
, newlen
);
1770 static int parse_table(int __user
*name
, int nlen
,
1771 void __user
*oldval
, size_t __user
*oldlenp
,
1772 void __user
*newval
, size_t newlen
,
1773 struct ctl_table_root
*root
,
1774 struct ctl_table
*table
)
1780 if (get_user(n
, name
))
1782 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1783 if (!table
->ctl_name
)
1785 if (n
== table
->ctl_name
) {
1788 if (sysctl_perm(root
, table
, MAY_EXEC
))
1792 table
= table
->child
;
1795 error
= do_sysctl_strategy(root
, table
,
1804 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1805 void __user
*newval
, size_t newlen
)
1807 struct ctl_table_header
*head
;
1808 int error
= -ENOTDIR
;
1810 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1814 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1818 for (head
= sysctl_head_next(NULL
); head
;
1819 head
= sysctl_head_next(head
)) {
1820 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1822 head
->root
, head
->ctl_table
);
1823 if (error
!= -ENOTDIR
) {
1824 sysctl_head_finish(head
);
1831 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
1833 struct __sysctl_args tmp
;
1836 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1839 error
= deprecated_sysctl_warning(&tmp
);
1844 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1845 tmp
.newval
, tmp
.newlen
);
1850 #endif /* CONFIG_SYSCTL_SYSCALL */
1853 * sysctl_perm does NOT grant the superuser all rights automatically, because
1854 * some sysctl variables are readonly even to root.
1857 static int test_perm(int mode
, int op
)
1859 if (!current_euid())
1861 else if (in_egroup_p(0))
1863 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1868 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1873 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1877 if (root
->permissions
)
1878 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1882 return test_perm(mode
, op
);
1885 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1887 for (; table
->ctl_name
|| table
->procname
; table
++) {
1888 table
->parent
= parent
;
1890 sysctl_set_parent(table
, table
->child
);
1894 static __init
int sysctl_init(void)
1896 sysctl_set_parent(NULL
, root_table
);
1897 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1900 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1906 core_initcall(sysctl_init
);
1908 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1909 struct ctl_table
*table
)
1911 struct ctl_table
*p
;
1912 const char *s
= branch
->procname
;
1914 /* branch should have named subdirectory as its first element */
1915 if (!s
|| !branch
->child
)
1918 /* ... and nothing else */
1919 if (branch
[1].procname
|| branch
[1].ctl_name
)
1922 /* table should contain subdirectory with the same name */
1923 for (p
= table
; p
->procname
|| p
->ctl_name
; p
++) {
1926 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1932 /* see if attaching q to p would be an improvement */
1933 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1935 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1936 struct ctl_table
*next
;
1938 int not_in_parent
= !p
->attached_by
;
1940 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1941 if (by
== q
->attached_by
)
1943 if (to
== p
->attached_by
)
1949 if (is_better
&& not_in_parent
) {
1950 q
->attached_by
= by
;
1951 q
->attached_to
= to
;
1957 * __register_sysctl_paths - register a sysctl hierarchy
1958 * @root: List of sysctl headers to register on
1959 * @namespaces: Data to compute which lists of sysctl entries are visible
1960 * @path: The path to the directory the sysctl table is in.
1961 * @table: the top-level table structure
1963 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1964 * array. A completely 0 filled entry terminates the table.
1966 * The members of the &struct ctl_table structure are used as follows:
1968 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1969 * must be unique within that level of sysctl
1971 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1972 * enter a sysctl file
1974 * data - a pointer to data for use by proc_handler
1976 * maxlen - the maximum size in bytes of the data
1978 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1980 * child - a pointer to the child sysctl table if this entry is a directory, or
1983 * proc_handler - the text handler routine (described below)
1985 * strategy - the strategy routine (described below)
1987 * de - for internal use by the sysctl routines
1989 * extra1, extra2 - extra pointers usable by the proc handler routines
1991 * Leaf nodes in the sysctl tree will be represented by a single file
1992 * under /proc; non-leaf nodes will be represented by directories.
1994 * sysctl(2) can automatically manage read and write requests through
1995 * the sysctl table. The data and maxlen fields of the ctl_table
1996 * struct enable minimal validation of the values being written to be
1997 * performed, and the mode field allows minimal authentication.
1999 * More sophisticated management can be enabled by the provision of a
2000 * strategy routine with the table entry. This will be called before
2001 * any automatic read or write of the data is performed.
2003 * The strategy routine may return
2005 * < 0 - Error occurred (error is passed to user process)
2007 * 0 - OK - proceed with automatic read or write.
2009 * > 0 - OK - read or write has been done by the strategy routine, so
2010 * return immediately.
2012 * There must be a proc_handler routine for any terminal nodes
2013 * mirrored under /proc/sys (non-terminals are handled by a built-in
2014 * directory handler). Several default handlers are available to
2015 * cover common cases -
2017 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
2018 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
2019 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
2021 * It is the handler's job to read the input buffer from user memory
2022 * and process it. The handler should return 0 on success.
2024 * This routine returns %NULL on a failure to register, and a pointer
2025 * to the table header on success.
2027 struct ctl_table_header
*__register_sysctl_paths(
2028 struct ctl_table_root
*root
,
2029 struct nsproxy
*namespaces
,
2030 const struct ctl_path
*path
, struct ctl_table
*table
)
2032 struct ctl_table_header
*header
;
2033 struct ctl_table
*new, **prevp
;
2034 unsigned int n
, npath
;
2035 struct ctl_table_set
*set
;
2037 /* Count the path components */
2038 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
2042 * For each path component, allocate a 2-element ctl_table array.
2043 * The first array element will be filled with the sysctl entry
2044 * for this, the second will be the sentinel (ctl_name == 0).
2046 * We allocate everything in one go so that we don't have to
2047 * worry about freeing additional memory in unregister_sysctl_table.
2049 header
= kzalloc(sizeof(struct ctl_table_header
) +
2050 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
2054 new = (struct ctl_table
*) (header
+ 1);
2056 /* Now connect the dots */
2057 prevp
= &header
->ctl_table
;
2058 for (n
= 0; n
< npath
; ++n
, ++path
) {
2059 /* Copy the procname */
2060 new->procname
= path
->procname
;
2061 new->ctl_name
= path
->ctl_name
;
2065 prevp
= &new->child
;
2070 header
->ctl_table_arg
= table
;
2072 INIT_LIST_HEAD(&header
->ctl_entry
);
2074 header
->unregistering
= NULL
;
2075 header
->root
= root
;
2076 sysctl_set_parent(NULL
, header
->ctl_table
);
2078 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
2079 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
2084 spin_lock(&sysctl_lock
);
2085 header
->set
= lookup_header_set(root
, namespaces
);
2086 header
->attached_by
= header
->ctl_table
;
2087 header
->attached_to
= root_table
;
2088 header
->parent
= &root_table_header
;
2089 for (set
= header
->set
; set
; set
= set
->parent
) {
2090 struct ctl_table_header
*p
;
2091 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
2092 if (p
->unregistering
)
2094 try_attach(p
, header
);
2097 header
->parent
->count
++;
2098 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
2099 spin_unlock(&sysctl_lock
);
2105 * register_sysctl_table_path - register a sysctl table hierarchy
2106 * @path: The path to the directory the sysctl table is in.
2107 * @table: the top-level table structure
2109 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2110 * array. A completely 0 filled entry terminates the table.
2112 * See __register_sysctl_paths for more details.
2114 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2115 struct ctl_table
*table
)
2117 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
2122 * register_sysctl_table - register a sysctl table hierarchy
2123 * @table: the top-level table structure
2125 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2126 * array. A completely 0 filled entry terminates the table.
2128 * See register_sysctl_paths for more details.
2130 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
2132 static const struct ctl_path null_path
[] = { {} };
2134 return register_sysctl_paths(null_path
, table
);
2138 * unregister_sysctl_table - unregister a sysctl table hierarchy
2139 * @header: the header returned from register_sysctl_table
2141 * Unregisters the sysctl table and all children. proc entries may not
2142 * actually be removed until they are no longer used by anyone.
2144 void unregister_sysctl_table(struct ctl_table_header
* header
)
2151 spin_lock(&sysctl_lock
);
2152 start_unregistering(header
);
2153 if (!--header
->parent
->count
) {
2155 kfree(header
->parent
);
2157 if (!--header
->count
)
2159 spin_unlock(&sysctl_lock
);
2162 int sysctl_is_seen(struct ctl_table_header
*p
)
2164 struct ctl_table_set
*set
= p
->set
;
2166 spin_lock(&sysctl_lock
);
2167 if (p
->unregistering
)
2169 else if (!set
->is_seen
)
2172 res
= set
->is_seen(set
);
2173 spin_unlock(&sysctl_lock
);
2177 void setup_sysctl_set(struct ctl_table_set
*p
,
2178 struct ctl_table_set
*parent
,
2179 int (*is_seen
)(struct ctl_table_set
*))
2181 INIT_LIST_HEAD(&p
->list
);
2182 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
2183 p
->is_seen
= is_seen
;
2186 #else /* !CONFIG_SYSCTL */
2187 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
2192 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2193 struct ctl_table
*table
)
2198 void unregister_sysctl_table(struct ctl_table_header
* table
)
2202 void setup_sysctl_set(struct ctl_table_set
*p
,
2203 struct ctl_table_set
*parent
,
2204 int (*is_seen
)(struct ctl_table_set
*))
2208 void sysctl_head_put(struct ctl_table_header
*head
)
2212 #endif /* CONFIG_SYSCTL */
2218 #ifdef CONFIG_PROC_SYSCTL
2220 static int _proc_do_string(void* data
, int maxlen
, int write
,
2221 struct file
*filp
, void __user
*buffer
,
2222 size_t *lenp
, loff_t
*ppos
)
2228 if (!data
|| !maxlen
|| !*lenp
) {
2236 while (len
< *lenp
) {
2237 if (get_user(c
, p
++))
2239 if (c
== 0 || c
== '\n')
2245 if(copy_from_user(data
, buffer
, len
))
2247 ((char *) data
)[len
] = 0;
2265 if(copy_to_user(buffer
, data
, len
))
2268 if(put_user('\n', ((char __user
*) buffer
) + len
))
2279 * proc_dostring - read a string sysctl
2280 * @table: the sysctl table
2281 * @write: %TRUE if this is a write to the sysctl file
2282 * @filp: the file structure
2283 * @buffer: the user buffer
2284 * @lenp: the size of the user buffer
2285 * @ppos: file position
2287 * Reads/writes a string from/to the user buffer. If the kernel
2288 * buffer provided is not large enough to hold the string, the
2289 * string is truncated. The copied string is %NULL-terminated.
2290 * If the string is being read by the user process, it is copied
2291 * and a newline '\n' is added. It is truncated if the buffer is
2294 * Returns 0 on success.
2296 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2297 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2299 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
2300 buffer
, lenp
, ppos
);
2304 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
2306 int write
, void *data
)
2309 *valp
= *negp
? -*lvalp
: *lvalp
;
2314 *lvalp
= (unsigned long)-val
;
2317 *lvalp
= (unsigned long)val
;
2323 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2324 int write
, struct file
*filp
, void __user
*buffer
,
2325 size_t *lenp
, loff_t
*ppos
,
2326 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2327 int write
, void *data
),
2330 #define TMPBUFLEN 21
2331 int *i
, vleft
, first
= 1, neg
;
2335 char buf
[TMPBUFLEN
], *p
;
2336 char __user
*s
= buffer
;
2338 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
2339 (*ppos
&& !write
)) {
2344 i
= (int *) tbl_data
;
2345 vleft
= table
->maxlen
/ sizeof(*i
);
2349 conv
= do_proc_dointvec_conv
;
2351 for (; left
&& vleft
--; i
++, first
=0) {
2366 if (len
> sizeof(buf
) - 1)
2367 len
= sizeof(buf
) - 1;
2368 if (copy_from_user(buf
, s
, len
))
2372 if (*p
== '-' && left
> 1) {
2376 if (*p
< '0' || *p
> '9')
2379 lval
= simple_strtoul(p
, &p
, 0);
2382 if ((len
< left
) && *p
&& !isspace(*p
))
2387 if (conv(&neg
, &lval
, i
, 1, data
))
2394 if (conv(&neg
, &lval
, i
, 0, data
))
2397 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2401 if(copy_to_user(s
, buf
, len
))
2408 if (!write
&& !first
&& left
) {
2409 if(put_user('\n', s
))
2416 if (get_user(c
, s
++))
2431 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2432 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2433 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2434 int write
, void *data
),
2437 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2438 buffer
, lenp
, ppos
, conv
, data
);
2442 * proc_dointvec - read a vector of integers
2443 * @table: the sysctl table
2444 * @write: %TRUE if this is a write to the sysctl file
2445 * @filp: the file structure
2446 * @buffer: the user buffer
2447 * @lenp: the size of the user buffer
2448 * @ppos: file position
2450 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2451 * values from/to the user buffer, treated as an ASCII string.
2453 * Returns 0 on success.
2455 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2456 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2458 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2463 * Taint values can only be increased
2464 * This means we can safely use a temporary.
2466 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2467 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2470 unsigned long tmptaint
= get_taint();
2473 if (write
&& !capable(CAP_SYS_ADMIN
))
2478 err
= proc_doulongvec_minmax(&t
, write
, filp
, buffer
, lenp
, ppos
);
2484 * Poor man's atomic or. Not worth adding a primitive
2485 * to everyone's atomic.h for this
2488 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2489 if ((tmptaint
>> i
) & 1)
2497 struct do_proc_dointvec_minmax_conv_param
{
2502 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2504 int write
, void *data
)
2506 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2508 int val
= *negp
? -*lvalp
: *lvalp
;
2509 if ((param
->min
&& *param
->min
> val
) ||
2510 (param
->max
&& *param
->max
< val
))
2517 *lvalp
= (unsigned long)-val
;
2520 *lvalp
= (unsigned long)val
;
2527 * proc_dointvec_minmax - read a vector of integers with min/max values
2528 * @table: the sysctl table
2529 * @write: %TRUE if this is a write to the sysctl file
2530 * @filp: the file structure
2531 * @buffer: the user buffer
2532 * @lenp: the size of the user buffer
2533 * @ppos: file position
2535 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2536 * values from/to the user buffer, treated as an ASCII string.
2538 * This routine will ensure the values are within the range specified by
2539 * table->extra1 (min) and table->extra2 (max).
2541 * Returns 0 on success.
2543 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2544 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2546 struct do_proc_dointvec_minmax_conv_param param
= {
2547 .min
= (int *) table
->extra1
,
2548 .max
= (int *) table
->extra2
,
2550 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2551 do_proc_dointvec_minmax_conv
, ¶m
);
2554 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2556 void __user
*buffer
,
2557 size_t *lenp
, loff_t
*ppos
,
2558 unsigned long convmul
,
2559 unsigned long convdiv
)
2561 #define TMPBUFLEN 21
2562 unsigned long *i
, *min
, *max
, val
;
2563 int vleft
, first
=1, neg
;
2565 char buf
[TMPBUFLEN
], *p
;
2566 char __user
*s
= buffer
;
2568 if (!data
|| !table
->maxlen
|| !*lenp
||
2569 (*ppos
&& !write
)) {
2574 i
= (unsigned long *) data
;
2575 min
= (unsigned long *) table
->extra1
;
2576 max
= (unsigned long *) table
->extra2
;
2577 vleft
= table
->maxlen
/ sizeof(unsigned long);
2580 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2595 if (len
> TMPBUFLEN
-1)
2597 if (copy_from_user(buf
, s
, len
))
2601 if (*p
== '-' && left
> 1) {
2605 if (*p
< '0' || *p
> '9')
2607 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2609 if ((len
< left
) && *p
&& !isspace(*p
))
2618 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2625 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2629 if(copy_to_user(s
, buf
, len
))
2636 if (!write
&& !first
&& left
) {
2637 if(put_user('\n', s
))
2644 if (get_user(c
, s
++))
2659 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2661 void __user
*buffer
,
2662 size_t *lenp
, loff_t
*ppos
,
2663 unsigned long convmul
,
2664 unsigned long convdiv
)
2666 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2667 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2671 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2672 * @table: the sysctl table
2673 * @write: %TRUE if this is a write to the sysctl file
2674 * @filp: the file structure
2675 * @buffer: the user buffer
2676 * @lenp: the size of the user buffer
2677 * @ppos: file position
2679 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2680 * values from/to the user buffer, treated as an ASCII string.
2682 * This routine will ensure the values are within the range specified by
2683 * table->extra1 (min) and table->extra2 (max).
2685 * Returns 0 on success.
2687 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2688 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2690 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2694 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2695 * @table: the sysctl table
2696 * @write: %TRUE if this is a write to the sysctl file
2697 * @filp: the file structure
2698 * @buffer: the user buffer
2699 * @lenp: the size of the user buffer
2700 * @ppos: file position
2702 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2703 * values from/to the user buffer, treated as an ASCII string. The values
2704 * are treated as milliseconds, and converted to jiffies when they are stored.
2706 * This routine will ensure the values are within the range specified by
2707 * table->extra1 (min) and table->extra2 (max).
2709 * Returns 0 on success.
2711 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2713 void __user
*buffer
,
2714 size_t *lenp
, loff_t
*ppos
)
2716 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2717 lenp
, ppos
, HZ
, 1000l);
2721 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2723 int write
, void *data
)
2726 if (*lvalp
> LONG_MAX
/ HZ
)
2728 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2734 lval
= (unsigned long)-val
;
2737 lval
= (unsigned long)val
;
2744 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2746 int write
, void *data
)
2749 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2751 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2757 lval
= (unsigned long)-val
;
2760 lval
= (unsigned long)val
;
2762 *lvalp
= jiffies_to_clock_t(lval
);
2767 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2769 int write
, void *data
)
2772 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2778 lval
= (unsigned long)-val
;
2781 lval
= (unsigned long)val
;
2783 *lvalp
= jiffies_to_msecs(lval
);
2789 * proc_dointvec_jiffies - read a vector of integers as seconds
2790 * @table: the sysctl table
2791 * @write: %TRUE if this is a write to the sysctl file
2792 * @filp: the file structure
2793 * @buffer: the user buffer
2794 * @lenp: the size of the user buffer
2795 * @ppos: file position
2797 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2798 * values from/to the user buffer, treated as an ASCII string.
2799 * The values read are assumed to be in seconds, and are converted into
2802 * Returns 0 on success.
2804 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2805 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2807 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2808 do_proc_dointvec_jiffies_conv
,NULL
);
2812 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2813 * @table: the sysctl table
2814 * @write: %TRUE if this is a write to the sysctl file
2815 * @filp: the file structure
2816 * @buffer: the user buffer
2817 * @lenp: the size of the user buffer
2818 * @ppos: pointer to the file position
2820 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2821 * values from/to the user buffer, treated as an ASCII string.
2822 * The values read are assumed to be in 1/USER_HZ seconds, and
2823 * are converted into jiffies.
2825 * Returns 0 on success.
2827 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2828 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2830 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2831 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2835 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2836 * @table: the sysctl table
2837 * @write: %TRUE if this is a write to the sysctl file
2838 * @filp: the file structure
2839 * @buffer: the user buffer
2840 * @lenp: the size of the user buffer
2841 * @ppos: file position
2842 * @ppos: the current position in the file
2844 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2845 * values from/to the user buffer, treated as an ASCII string.
2846 * The values read are assumed to be in 1/1000 seconds, and
2847 * are converted into jiffies.
2849 * Returns 0 on success.
2851 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2852 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2854 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2855 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2858 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2859 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2861 struct pid
*new_pid
;
2865 tmp
= pid_vnr(cad_pid
);
2867 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2868 lenp
, ppos
, NULL
, NULL
);
2872 new_pid
= find_get_pid(tmp
);
2876 put_pid(xchg(&cad_pid
, new_pid
));
2880 #else /* CONFIG_PROC_FS */
2882 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2883 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2888 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2889 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2894 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2895 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2900 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2901 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2906 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2907 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2912 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2913 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2918 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2919 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2924 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2926 void __user
*buffer
,
2927 size_t *lenp
, loff_t
*ppos
)
2933 #endif /* CONFIG_PROC_FS */
2936 #ifdef CONFIG_SYSCTL_SYSCALL
2938 * General sysctl support routines
2941 /* The generic sysctl data routine (used if no strategy routine supplied) */
2942 int sysctl_data(struct ctl_table
*table
,
2943 void __user
*oldval
, size_t __user
*oldlenp
,
2944 void __user
*newval
, size_t newlen
)
2948 /* Get out of I don't have a variable */
2949 if (!table
->data
|| !table
->maxlen
)
2952 if (oldval
&& oldlenp
) {
2953 if (get_user(len
, oldlenp
))
2956 if (len
> table
->maxlen
)
2957 len
= table
->maxlen
;
2958 if (copy_to_user(oldval
, table
->data
, len
))
2960 if (put_user(len
, oldlenp
))
2965 if (newval
&& newlen
) {
2966 if (newlen
> table
->maxlen
)
2967 newlen
= table
->maxlen
;
2969 if (copy_from_user(table
->data
, newval
, newlen
))
2975 /* The generic string strategy routine: */
2976 int sysctl_string(struct ctl_table
*table
,
2977 void __user
*oldval
, size_t __user
*oldlenp
,
2978 void __user
*newval
, size_t newlen
)
2980 if (!table
->data
|| !table
->maxlen
)
2983 if (oldval
&& oldlenp
) {
2985 if (get_user(bufsize
, oldlenp
))
2988 size_t len
= strlen(table
->data
), copied
;
2990 /* This shouldn't trigger for a well-formed sysctl */
2991 if (len
> table
->maxlen
)
2992 len
= table
->maxlen
;
2994 /* Copy up to a max of bufsize-1 bytes of the string */
2995 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2997 if (copy_to_user(oldval
, table
->data
, copied
) ||
2998 put_user(0, (char __user
*)(oldval
+ copied
)))
3000 if (put_user(len
, oldlenp
))
3004 if (newval
&& newlen
) {
3005 size_t len
= newlen
;
3006 if (len
> table
->maxlen
)
3007 len
= table
->maxlen
;
3008 if(copy_from_user(table
->data
, newval
, len
))
3010 if (len
== table
->maxlen
)
3012 ((char *) table
->data
)[len
] = 0;
3018 * This function makes sure that all of the integers in the vector
3019 * are between the minimum and maximum values given in the arrays
3020 * table->extra1 and table->extra2, respectively.
3022 int sysctl_intvec(struct ctl_table
*table
,
3023 void __user
*oldval
, size_t __user
*oldlenp
,
3024 void __user
*newval
, size_t newlen
)
3027 if (newval
&& newlen
) {
3028 int __user
*vec
= (int __user
*) newval
;
3029 int *min
= (int *) table
->extra1
;
3030 int *max
= (int *) table
->extra2
;
3034 if (newlen
% sizeof(int) != 0)
3037 if (!table
->extra1
&& !table
->extra2
)
3040 if (newlen
> table
->maxlen
)
3041 newlen
= table
->maxlen
;
3042 length
= newlen
/ sizeof(int);
3044 for (i
= 0; i
< length
; i
++) {
3046 if (get_user(value
, vec
+ i
))
3048 if (min
&& value
< min
[i
])
3050 if (max
&& value
> max
[i
])
3057 /* Strategy function to convert jiffies to seconds */
3058 int sysctl_jiffies(struct ctl_table
*table
,
3059 void __user
*oldval
, size_t __user
*oldlenp
,
3060 void __user
*newval
, size_t newlen
)
3062 if (oldval
&& oldlenp
) {
3065 if (get_user(olen
, oldlenp
))
3070 if (olen
< sizeof(int))
3073 val
= *(int *)(table
->data
) / HZ
;
3074 if (put_user(val
, (int __user
*)oldval
))
3076 if (put_user(sizeof(int), oldlenp
))
3080 if (newval
&& newlen
) {
3082 if (newlen
!= sizeof(int))
3084 if (get_user(new, (int __user
*)newval
))
3086 *(int *)(table
->data
) = new*HZ
;
3091 /* Strategy function to convert jiffies to seconds */
3092 int sysctl_ms_jiffies(struct ctl_table
*table
,
3093 void __user
*oldval
, size_t __user
*oldlenp
,
3094 void __user
*newval
, size_t newlen
)
3096 if (oldval
&& oldlenp
) {
3099 if (get_user(olen
, oldlenp
))
3104 if (olen
< sizeof(int))
3107 val
= jiffies_to_msecs(*(int *)(table
->data
));
3108 if (put_user(val
, (int __user
*)oldval
))
3110 if (put_user(sizeof(int), oldlenp
))
3114 if (newval
&& newlen
) {
3116 if (newlen
!= sizeof(int))
3118 if (get_user(new, (int __user
*)newval
))
3120 *(int *)(table
->data
) = msecs_to_jiffies(new);
3127 #else /* CONFIG_SYSCTL_SYSCALL */
3130 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
3132 struct __sysctl_args tmp
;
3135 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
3138 error
= deprecated_sysctl_warning(&tmp
);
3140 /* If no error reading the parameters then just -ENOSYS ... */
3147 int sysctl_data(struct ctl_table
*table
,
3148 void __user
*oldval
, size_t __user
*oldlenp
,
3149 void __user
*newval
, size_t newlen
)
3154 int sysctl_string(struct ctl_table
*table
,
3155 void __user
*oldval
, size_t __user
*oldlenp
,
3156 void __user
*newval
, size_t newlen
)
3161 int sysctl_intvec(struct ctl_table
*table
,
3162 void __user
*oldval
, size_t __user
*oldlenp
,
3163 void __user
*newval
, size_t newlen
)
3168 int sysctl_jiffies(struct ctl_table
*table
,
3169 void __user
*oldval
, size_t __user
*oldlenp
,
3170 void __user
*newval
, size_t newlen
)
3175 int sysctl_ms_jiffies(struct ctl_table
*table
,
3176 void __user
*oldval
, size_t __user
*oldlenp
,
3177 void __user
*newval
, size_t newlen
)
3182 #endif /* CONFIG_SYSCTL_SYSCALL */
3184 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
3186 static int msg_count
;
3187 int name
[CTL_MAXNAME
];
3190 /* Check args->nlen. */
3191 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
3194 /* Read in the sysctl name for better debug message logging */
3195 for (i
= 0; i
< args
->nlen
; i
++)
3196 if (get_user(name
[i
], args
->name
+ i
))
3199 /* Ignore accesses to kernel.version */
3200 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
3203 if (msg_count
< 5) {
3206 "warning: process `%s' used the deprecated sysctl "
3207 "system call with ", current
->comm
);
3208 for (i
= 0; i
< args
->nlen
; i
++)
3209 printk("%d.", name
[i
]);
3216 * No sense putting this after each symbol definition, twice,
3217 * exception granted :-)
3219 EXPORT_SYMBOL(proc_dointvec
);
3220 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3221 EXPORT_SYMBOL(proc_dointvec_minmax
);
3222 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3223 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3224 EXPORT_SYMBOL(proc_dostring
);
3225 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3226 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
3227 EXPORT_SYMBOL(register_sysctl_table
);
3228 EXPORT_SYMBOL(register_sysctl_paths
);
3229 EXPORT_SYMBOL(sysctl_intvec
);
3230 EXPORT_SYMBOL(sysctl_jiffies
);
3231 EXPORT_SYMBOL(sysctl_ms_jiffies
);
3232 EXPORT_SYMBOL(sysctl_string
);
3233 EXPORT_SYMBOL(sysctl_data
);
3234 EXPORT_SYMBOL(unregister_sysctl_table
);