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_counter.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 */
94 extern int blk_iopoll_enabled
;
96 /* Constants used for minimum and maximum */
97 #ifdef CONFIG_DETECT_SOFTLOCKUP
98 static int sixty
= 60;
99 static int neg_one
= -1;
103 static int __maybe_unused one
= 1;
104 static int __maybe_unused two
= 2;
105 static unsigned long one_ul
= 1;
106 static int one_hundred
= 100;
108 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
109 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
111 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
112 static int maxolduid
= 65535;
113 static int minolduid
;
114 static int min_percpu_pagelist_fract
= 8;
116 static int ngroups_max
= NGROUPS_MAX
;
118 #ifdef CONFIG_MODULES
119 extern char modprobe_path
[];
120 extern int modules_disabled
;
122 #ifdef CONFIG_CHR_DEV_SG
123 extern int sg_big_buff
;
127 #include <asm/system.h>
130 #ifdef CONFIG_SPARC64
131 extern int sysctl_tsb_ratio
;
135 extern int pwrsw_enabled
;
136 extern int unaligned_enabled
;
140 #ifdef CONFIG_MATHEMU
141 extern int sysctl_ieee_emulation_warnings
;
143 extern int sysctl_userprocess_debug
;
144 extern int spin_retry
;
147 #ifdef CONFIG_BSD_PROCESS_ACCT
148 extern int acct_parm
[];
152 extern int no_unaligned_warning
;
153 extern int unaligned_dump_stack
;
156 #ifdef CONFIG_RT_MUTEXES
157 extern int max_lock_depth
;
160 #ifdef CONFIG_PROC_SYSCTL
161 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
162 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
163 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
164 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
167 static struct ctl_table root_table
[];
168 static struct ctl_table_root sysctl_table_root
;
169 static struct ctl_table_header root_table_header
= {
171 .ctl_table
= root_table
,
172 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),
173 .root
= &sysctl_table_root
,
174 .set
= &sysctl_table_root
.default_set
,
176 static struct ctl_table_root sysctl_table_root
= {
177 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
178 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
181 static struct ctl_table kern_table
[];
182 static struct ctl_table vm_table
[];
183 static struct ctl_table fs_table
[];
184 static struct ctl_table debug_table
[];
185 static struct ctl_table dev_table
[];
186 extern struct ctl_table random_table
[];
187 #ifdef CONFIG_INOTIFY_USER
188 extern struct ctl_table inotify_table
[];
191 extern struct ctl_table epoll_table
[];
194 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
195 int sysctl_legacy_va_layout
;
198 extern int prove_locking
;
199 extern int lock_stat
;
201 /* The default sysctl tables: */
203 static struct ctl_table root_table
[] = {
205 .ctl_name
= CTL_KERN
,
206 .procname
= "kernel",
223 .ctl_name
= CTL_DEBUG
,
226 .child
= debug_table
,
235 * NOTE: do not add new entries to this table unless you have read
236 * Documentation/sysctl/ctl_unnumbered.txt
241 #ifdef CONFIG_SCHED_DEBUG
242 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
243 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
244 static int min_wakeup_granularity_ns
; /* 0 usecs */
245 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
248 static struct ctl_table kern_table
[] = {
250 .ctl_name
= CTL_UNNUMBERED
,
251 .procname
= "sched_child_runs_first",
252 .data
= &sysctl_sched_child_runs_first
,
253 .maxlen
= sizeof(unsigned int),
255 .proc_handler
= &proc_dointvec
,
257 #ifdef CONFIG_SCHED_DEBUG
259 .ctl_name
= CTL_UNNUMBERED
,
260 .procname
= "sched_min_granularity_ns",
261 .data
= &sysctl_sched_min_granularity
,
262 .maxlen
= sizeof(unsigned int),
264 .proc_handler
= &sched_nr_latency_handler
,
265 .strategy
= &sysctl_intvec
,
266 .extra1
= &min_sched_granularity_ns
,
267 .extra2
= &max_sched_granularity_ns
,
270 .ctl_name
= CTL_UNNUMBERED
,
271 .procname
= "sched_latency_ns",
272 .data
= &sysctl_sched_latency
,
273 .maxlen
= sizeof(unsigned int),
275 .proc_handler
= &sched_nr_latency_handler
,
276 .strategy
= &sysctl_intvec
,
277 .extra1
= &min_sched_granularity_ns
,
278 .extra2
= &max_sched_granularity_ns
,
281 .ctl_name
= CTL_UNNUMBERED
,
282 .procname
= "sched_wakeup_granularity_ns",
283 .data
= &sysctl_sched_wakeup_granularity
,
284 .maxlen
= sizeof(unsigned int),
286 .proc_handler
= &proc_dointvec_minmax
,
287 .strategy
= &sysctl_intvec
,
288 .extra1
= &min_wakeup_granularity_ns
,
289 .extra2
= &max_wakeup_granularity_ns
,
292 .ctl_name
= CTL_UNNUMBERED
,
293 .procname
= "sched_shares_ratelimit",
294 .data
= &sysctl_sched_shares_ratelimit
,
295 .maxlen
= sizeof(unsigned int),
297 .proc_handler
= &proc_dointvec
,
300 .ctl_name
= CTL_UNNUMBERED
,
301 .procname
= "sched_shares_thresh",
302 .data
= &sysctl_sched_shares_thresh
,
303 .maxlen
= sizeof(unsigned int),
305 .proc_handler
= &proc_dointvec_minmax
,
306 .strategy
= &sysctl_intvec
,
310 .ctl_name
= CTL_UNNUMBERED
,
311 .procname
= "sched_features",
312 .data
= &sysctl_sched_features
,
313 .maxlen
= sizeof(unsigned int),
315 .proc_handler
= &proc_dointvec
,
318 .ctl_name
= CTL_UNNUMBERED
,
319 .procname
= "sched_migration_cost",
320 .data
= &sysctl_sched_migration_cost
,
321 .maxlen
= sizeof(unsigned int),
323 .proc_handler
= &proc_dointvec
,
326 .ctl_name
= CTL_UNNUMBERED
,
327 .procname
= "sched_nr_migrate",
328 .data
= &sysctl_sched_nr_migrate
,
329 .maxlen
= sizeof(unsigned int),
331 .proc_handler
= &proc_dointvec
,
334 .ctl_name
= CTL_UNNUMBERED
,
335 .procname
= "sched_time_avg",
336 .data
= &sysctl_sched_time_avg
,
337 .maxlen
= sizeof(unsigned int),
339 .proc_handler
= &proc_dointvec
,
342 .ctl_name
= CTL_UNNUMBERED
,
343 .procname
= "timer_migration",
344 .data
= &sysctl_timer_migration
,
345 .maxlen
= sizeof(unsigned int),
347 .proc_handler
= &proc_dointvec_minmax
,
348 .strategy
= &sysctl_intvec
,
354 .ctl_name
= CTL_UNNUMBERED
,
355 .procname
= "sched_rt_period_us",
356 .data
= &sysctl_sched_rt_period
,
357 .maxlen
= sizeof(unsigned int),
359 .proc_handler
= &sched_rt_handler
,
362 .ctl_name
= CTL_UNNUMBERED
,
363 .procname
= "sched_rt_runtime_us",
364 .data
= &sysctl_sched_rt_runtime
,
365 .maxlen
= sizeof(int),
367 .proc_handler
= &sched_rt_handler
,
370 .ctl_name
= CTL_UNNUMBERED
,
371 .procname
= "sched_compat_yield",
372 .data
= &sysctl_sched_compat_yield
,
373 .maxlen
= sizeof(unsigned int),
375 .proc_handler
= &proc_dointvec
,
377 #ifdef CONFIG_PROVE_LOCKING
379 .ctl_name
= CTL_UNNUMBERED
,
380 .procname
= "prove_locking",
381 .data
= &prove_locking
,
382 .maxlen
= sizeof(int),
384 .proc_handler
= &proc_dointvec
,
387 #ifdef CONFIG_LOCK_STAT
389 .ctl_name
= CTL_UNNUMBERED
,
390 .procname
= "lock_stat",
392 .maxlen
= sizeof(int),
394 .proc_handler
= &proc_dointvec
,
398 .ctl_name
= KERN_PANIC
,
400 .data
= &panic_timeout
,
401 .maxlen
= sizeof(int),
403 .proc_handler
= &proc_dointvec
,
406 .ctl_name
= KERN_CORE_USES_PID
,
407 .procname
= "core_uses_pid",
408 .data
= &core_uses_pid
,
409 .maxlen
= sizeof(int),
411 .proc_handler
= &proc_dointvec
,
414 .ctl_name
= KERN_CORE_PATTERN
,
415 .procname
= "core_pattern",
416 .data
= core_pattern
,
417 .maxlen
= CORENAME_MAX_SIZE
,
419 .proc_handler
= &proc_dostring
,
420 .strategy
= &sysctl_string
,
422 #ifdef CONFIG_PROC_SYSCTL
424 .procname
= "tainted",
425 .maxlen
= sizeof(long),
427 .proc_handler
= &proc_taint
,
430 #ifdef CONFIG_LATENCYTOP
432 .procname
= "latencytop",
433 .data
= &latencytop_enabled
,
434 .maxlen
= sizeof(int),
436 .proc_handler
= &proc_dointvec
,
439 #ifdef CONFIG_BLK_DEV_INITRD
441 .ctl_name
= KERN_REALROOTDEV
,
442 .procname
= "real-root-dev",
443 .data
= &real_root_dev
,
444 .maxlen
= sizeof(int),
446 .proc_handler
= &proc_dointvec
,
450 .ctl_name
= CTL_UNNUMBERED
,
451 .procname
= "print-fatal-signals",
452 .data
= &print_fatal_signals
,
453 .maxlen
= sizeof(int),
455 .proc_handler
= &proc_dointvec
,
459 .ctl_name
= KERN_SPARC_REBOOT
,
460 .procname
= "reboot-cmd",
461 .data
= reboot_command
,
464 .proc_handler
= &proc_dostring
,
465 .strategy
= &sysctl_string
,
468 .ctl_name
= KERN_SPARC_STOP_A
,
469 .procname
= "stop-a",
470 .data
= &stop_a_enabled
,
471 .maxlen
= sizeof (int),
473 .proc_handler
= &proc_dointvec
,
476 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
477 .procname
= "scons-poweroff",
478 .data
= &scons_pwroff
,
479 .maxlen
= sizeof (int),
481 .proc_handler
= &proc_dointvec
,
484 #ifdef CONFIG_SPARC64
486 .ctl_name
= CTL_UNNUMBERED
,
487 .procname
= "tsb-ratio",
488 .data
= &sysctl_tsb_ratio
,
489 .maxlen
= sizeof (int),
491 .proc_handler
= &proc_dointvec
,
496 .ctl_name
= KERN_HPPA_PWRSW
,
497 .procname
= "soft-power",
498 .data
= &pwrsw_enabled
,
499 .maxlen
= sizeof (int),
501 .proc_handler
= &proc_dointvec
,
504 .ctl_name
= KERN_HPPA_UNALIGNED
,
505 .procname
= "unaligned-trap",
506 .data
= &unaligned_enabled
,
507 .maxlen
= sizeof (int),
509 .proc_handler
= &proc_dointvec
,
513 .ctl_name
= KERN_CTLALTDEL
,
514 .procname
= "ctrl-alt-del",
516 .maxlen
= sizeof(int),
518 .proc_handler
= &proc_dointvec
,
520 #ifdef CONFIG_FUNCTION_TRACER
522 .ctl_name
= CTL_UNNUMBERED
,
523 .procname
= "ftrace_enabled",
524 .data
= &ftrace_enabled
,
525 .maxlen
= sizeof(int),
527 .proc_handler
= &ftrace_enable_sysctl
,
530 #ifdef CONFIG_STACK_TRACER
532 .ctl_name
= CTL_UNNUMBERED
,
533 .procname
= "stack_tracer_enabled",
534 .data
= &stack_tracer_enabled
,
535 .maxlen
= sizeof(int),
537 .proc_handler
= &stack_trace_sysctl
,
540 #ifdef CONFIG_TRACING
542 .ctl_name
= CTL_UNNUMBERED
,
543 .procname
= "ftrace_dump_on_oops",
544 .data
= &ftrace_dump_on_oops
,
545 .maxlen
= sizeof(int),
547 .proc_handler
= &proc_dointvec
,
550 #ifdef CONFIG_MODULES
552 .ctl_name
= KERN_MODPROBE
,
553 .procname
= "modprobe",
554 .data
= &modprobe_path
,
555 .maxlen
= KMOD_PATH_LEN
,
557 .proc_handler
= &proc_dostring
,
558 .strategy
= &sysctl_string
,
561 .ctl_name
= CTL_UNNUMBERED
,
562 .procname
= "modules_disabled",
563 .data
= &modules_disabled
,
564 .maxlen
= sizeof(int),
566 /* only handle a transition from default "0" to "1" */
567 .proc_handler
= &proc_dointvec_minmax
,
572 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
574 .ctl_name
= KERN_HOTPLUG
,
575 .procname
= "hotplug",
576 .data
= &uevent_helper
,
577 .maxlen
= UEVENT_HELPER_PATH_LEN
,
579 .proc_handler
= &proc_dostring
,
580 .strategy
= &sysctl_string
,
583 #ifdef CONFIG_CHR_DEV_SG
585 .ctl_name
= KERN_SG_BIG_BUFF
,
586 .procname
= "sg-big-buff",
587 .data
= &sg_big_buff
,
588 .maxlen
= sizeof (int),
590 .proc_handler
= &proc_dointvec
,
593 #ifdef CONFIG_BSD_PROCESS_ACCT
595 .ctl_name
= KERN_ACCT
,
598 .maxlen
= 3*sizeof(int),
600 .proc_handler
= &proc_dointvec
,
603 #ifdef CONFIG_MAGIC_SYSRQ
605 .ctl_name
= KERN_SYSRQ
,
607 .data
= &__sysrq_enabled
,
608 .maxlen
= sizeof (int),
610 .proc_handler
= &proc_dointvec
,
613 #ifdef CONFIG_PROC_SYSCTL
615 .procname
= "cad_pid",
617 .maxlen
= sizeof (int),
619 .proc_handler
= &proc_do_cad_pid
,
623 .ctl_name
= KERN_MAX_THREADS
,
624 .procname
= "threads-max",
625 .data
= &max_threads
,
626 .maxlen
= sizeof(int),
628 .proc_handler
= &proc_dointvec
,
631 .ctl_name
= KERN_RANDOM
,
632 .procname
= "random",
634 .child
= random_table
,
637 .ctl_name
= KERN_OVERFLOWUID
,
638 .procname
= "overflowuid",
639 .data
= &overflowuid
,
640 .maxlen
= sizeof(int),
642 .proc_handler
= &proc_dointvec_minmax
,
643 .strategy
= &sysctl_intvec
,
644 .extra1
= &minolduid
,
645 .extra2
= &maxolduid
,
648 .ctl_name
= KERN_OVERFLOWGID
,
649 .procname
= "overflowgid",
650 .data
= &overflowgid
,
651 .maxlen
= sizeof(int),
653 .proc_handler
= &proc_dointvec_minmax
,
654 .strategy
= &sysctl_intvec
,
655 .extra1
= &minolduid
,
656 .extra2
= &maxolduid
,
659 #ifdef CONFIG_MATHEMU
661 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
662 .procname
= "ieee_emulation_warnings",
663 .data
= &sysctl_ieee_emulation_warnings
,
664 .maxlen
= sizeof(int),
666 .proc_handler
= &proc_dointvec
,
670 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
671 .procname
= "userprocess_debug",
672 .data
= &sysctl_userprocess_debug
,
673 .maxlen
= sizeof(int),
675 .proc_handler
= &proc_dointvec
,
679 .ctl_name
= KERN_PIDMAX
,
680 .procname
= "pid_max",
682 .maxlen
= sizeof (int),
684 .proc_handler
= &proc_dointvec_minmax
,
685 .strategy
= sysctl_intvec
,
686 .extra1
= &pid_max_min
,
687 .extra2
= &pid_max_max
,
690 .ctl_name
= KERN_PANIC_ON_OOPS
,
691 .procname
= "panic_on_oops",
692 .data
= &panic_on_oops
,
693 .maxlen
= sizeof(int),
695 .proc_handler
= &proc_dointvec
,
697 #if defined CONFIG_PRINTK
699 .ctl_name
= KERN_PRINTK
,
700 .procname
= "printk",
701 .data
= &console_loglevel
,
702 .maxlen
= 4*sizeof(int),
704 .proc_handler
= &proc_dointvec
,
707 .ctl_name
= KERN_PRINTK_RATELIMIT
,
708 .procname
= "printk_ratelimit",
709 .data
= &printk_ratelimit_state
.interval
,
710 .maxlen
= sizeof(int),
712 .proc_handler
= &proc_dointvec_jiffies
,
713 .strategy
= &sysctl_jiffies
,
716 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
717 .procname
= "printk_ratelimit_burst",
718 .data
= &printk_ratelimit_state
.burst
,
719 .maxlen
= sizeof(int),
721 .proc_handler
= &proc_dointvec
,
725 .ctl_name
= KERN_NGROUPS_MAX
,
726 .procname
= "ngroups_max",
727 .data
= &ngroups_max
,
728 .maxlen
= sizeof (int),
730 .proc_handler
= &proc_dointvec
,
732 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
734 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
735 .procname
= "unknown_nmi_panic",
736 .data
= &unknown_nmi_panic
,
737 .maxlen
= sizeof (int),
739 .proc_handler
= &proc_dointvec
,
742 .procname
= "nmi_watchdog",
743 .data
= &nmi_watchdog_enabled
,
744 .maxlen
= sizeof (int),
746 .proc_handler
= &proc_nmi_enabled
,
749 #if defined(CONFIG_X86)
751 .ctl_name
= KERN_PANIC_ON_NMI
,
752 .procname
= "panic_on_unrecovered_nmi",
753 .data
= &panic_on_unrecovered_nmi
,
754 .maxlen
= sizeof(int),
756 .proc_handler
= &proc_dointvec
,
759 .ctl_name
= CTL_UNNUMBERED
,
760 .procname
= "panic_on_io_nmi",
761 .data
= &panic_on_io_nmi
,
762 .maxlen
= sizeof(int),
764 .proc_handler
= &proc_dointvec
,
767 .ctl_name
= KERN_BOOTLOADER_TYPE
,
768 .procname
= "bootloader_type",
769 .data
= &bootloader_type
,
770 .maxlen
= sizeof (int),
772 .proc_handler
= &proc_dointvec
,
775 .ctl_name
= CTL_UNNUMBERED
,
776 .procname
= "bootloader_version",
777 .data
= &bootloader_version
,
778 .maxlen
= sizeof (int),
780 .proc_handler
= &proc_dointvec
,
783 .ctl_name
= CTL_UNNUMBERED
,
784 .procname
= "kstack_depth_to_print",
785 .data
= &kstack_depth_to_print
,
786 .maxlen
= sizeof(int),
788 .proc_handler
= &proc_dointvec
,
791 .ctl_name
= CTL_UNNUMBERED
,
792 .procname
= "io_delay_type",
793 .data
= &io_delay_type
,
794 .maxlen
= sizeof(int),
796 .proc_handler
= &proc_dointvec
,
799 #if defined(CONFIG_MMU)
801 .ctl_name
= KERN_RANDOMIZE
,
802 .procname
= "randomize_va_space",
803 .data
= &randomize_va_space
,
804 .maxlen
= sizeof(int),
806 .proc_handler
= &proc_dointvec
,
809 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
811 .ctl_name
= KERN_SPIN_RETRY
,
812 .procname
= "spin_retry",
814 .maxlen
= sizeof (int),
816 .proc_handler
= &proc_dointvec
,
819 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
821 .procname
= "acpi_video_flags",
822 .data
= &acpi_realmode_flags
,
823 .maxlen
= sizeof (unsigned long),
825 .proc_handler
= &proc_doulongvec_minmax
,
830 .ctl_name
= KERN_IA64_UNALIGNED
,
831 .procname
= "ignore-unaligned-usertrap",
832 .data
= &no_unaligned_warning
,
833 .maxlen
= sizeof (int),
835 .proc_handler
= &proc_dointvec
,
838 .ctl_name
= CTL_UNNUMBERED
,
839 .procname
= "unaligned-dump-stack",
840 .data
= &unaligned_dump_stack
,
841 .maxlen
= sizeof (int),
843 .proc_handler
= &proc_dointvec
,
846 #ifdef CONFIG_DETECT_SOFTLOCKUP
848 .ctl_name
= CTL_UNNUMBERED
,
849 .procname
= "softlockup_panic",
850 .data
= &softlockup_panic
,
851 .maxlen
= sizeof(int),
853 .proc_handler
= &proc_dointvec_minmax
,
854 .strategy
= &sysctl_intvec
,
859 .ctl_name
= CTL_UNNUMBERED
,
860 .procname
= "softlockup_thresh",
861 .data
= &softlockup_thresh
,
862 .maxlen
= sizeof(int),
864 .proc_handler
= &proc_dosoftlockup_thresh
,
865 .strategy
= &sysctl_intvec
,
870 #ifdef CONFIG_DETECT_HUNG_TASK
872 .ctl_name
= CTL_UNNUMBERED
,
873 .procname
= "hung_task_panic",
874 .data
= &sysctl_hung_task_panic
,
875 .maxlen
= sizeof(int),
877 .proc_handler
= &proc_dointvec_minmax
,
878 .strategy
= &sysctl_intvec
,
883 .ctl_name
= CTL_UNNUMBERED
,
884 .procname
= "hung_task_check_count",
885 .data
= &sysctl_hung_task_check_count
,
886 .maxlen
= sizeof(unsigned long),
888 .proc_handler
= &proc_doulongvec_minmax
,
889 .strategy
= &sysctl_intvec
,
892 .ctl_name
= CTL_UNNUMBERED
,
893 .procname
= "hung_task_timeout_secs",
894 .data
= &sysctl_hung_task_timeout_secs
,
895 .maxlen
= sizeof(unsigned long),
897 .proc_handler
= &proc_dohung_task_timeout_secs
,
898 .strategy
= &sysctl_intvec
,
901 .ctl_name
= CTL_UNNUMBERED
,
902 .procname
= "hung_task_warnings",
903 .data
= &sysctl_hung_task_warnings
,
904 .maxlen
= sizeof(unsigned long),
906 .proc_handler
= &proc_doulongvec_minmax
,
907 .strategy
= &sysctl_intvec
,
912 .ctl_name
= KERN_COMPAT_LOG
,
913 .procname
= "compat-log",
915 .maxlen
= sizeof (int),
917 .proc_handler
= &proc_dointvec
,
920 #ifdef CONFIG_RT_MUTEXES
922 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
923 .procname
= "max_lock_depth",
924 .data
= &max_lock_depth
,
925 .maxlen
= sizeof(int),
927 .proc_handler
= &proc_dointvec
,
931 .ctl_name
= CTL_UNNUMBERED
,
932 .procname
= "poweroff_cmd",
933 .data
= &poweroff_cmd
,
934 .maxlen
= POWEROFF_CMD_PATH_LEN
,
936 .proc_handler
= &proc_dostring
,
937 .strategy
= &sysctl_string
,
941 .ctl_name
= CTL_UNNUMBERED
,
944 .child
= key_sysctls
,
947 #ifdef CONFIG_RCU_TORTURE_TEST
949 .ctl_name
= CTL_UNNUMBERED
,
950 .procname
= "rcutorture_runnable",
951 .data
= &rcutorture_runnable
,
952 .maxlen
= sizeof(int),
954 .proc_handler
= &proc_dointvec
,
957 #ifdef CONFIG_SLOW_WORK
959 .ctl_name
= CTL_UNNUMBERED
,
960 .procname
= "slow-work",
962 .child
= slow_work_sysctls
,
965 #ifdef CONFIG_PERF_COUNTERS
967 .ctl_name
= CTL_UNNUMBERED
,
968 .procname
= "perf_counter_paranoid",
969 .data
= &sysctl_perf_counter_paranoid
,
970 .maxlen
= sizeof(sysctl_perf_counter_paranoid
),
972 .proc_handler
= &proc_dointvec
,
975 .ctl_name
= CTL_UNNUMBERED
,
976 .procname
= "perf_counter_mlock_kb",
977 .data
= &sysctl_perf_counter_mlock
,
978 .maxlen
= sizeof(sysctl_perf_counter_mlock
),
980 .proc_handler
= &proc_dointvec
,
983 .ctl_name
= CTL_UNNUMBERED
,
984 .procname
= "perf_counter_max_sample_rate",
985 .data
= &sysctl_perf_counter_sample_rate
,
986 .maxlen
= sizeof(sysctl_perf_counter_sample_rate
),
988 .proc_handler
= &proc_dointvec
,
991 #ifdef CONFIG_KMEMCHECK
993 .ctl_name
= CTL_UNNUMBERED
,
994 .procname
= "kmemcheck",
995 .data
= &kmemcheck_enabled
,
996 .maxlen
= sizeof(int),
998 .proc_handler
= &proc_dointvec
,
1002 .ctl_name
= CTL_UNNUMBERED
,
1003 .procname
= "blk_iopoll",
1004 .data
= &blk_iopoll_enabled
,
1005 .maxlen
= sizeof(int),
1007 .proc_handler
= &proc_dointvec
,
1010 * NOTE: do not add new entries to this table unless you have read
1011 * Documentation/sysctl/ctl_unnumbered.txt
1016 static struct ctl_table vm_table
[] = {
1018 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
1019 .procname
= "overcommit_memory",
1020 .data
= &sysctl_overcommit_memory
,
1021 .maxlen
= sizeof(sysctl_overcommit_memory
),
1023 .proc_handler
= &proc_dointvec
,
1026 .ctl_name
= VM_PANIC_ON_OOM
,
1027 .procname
= "panic_on_oom",
1028 .data
= &sysctl_panic_on_oom
,
1029 .maxlen
= sizeof(sysctl_panic_on_oom
),
1031 .proc_handler
= &proc_dointvec
,
1034 .ctl_name
= CTL_UNNUMBERED
,
1035 .procname
= "oom_kill_allocating_task",
1036 .data
= &sysctl_oom_kill_allocating_task
,
1037 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1039 .proc_handler
= &proc_dointvec
,
1042 .ctl_name
= CTL_UNNUMBERED
,
1043 .procname
= "oom_dump_tasks",
1044 .data
= &sysctl_oom_dump_tasks
,
1045 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1047 .proc_handler
= &proc_dointvec
,
1050 .ctl_name
= VM_OVERCOMMIT_RATIO
,
1051 .procname
= "overcommit_ratio",
1052 .data
= &sysctl_overcommit_ratio
,
1053 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1055 .proc_handler
= &proc_dointvec
,
1058 .ctl_name
= VM_PAGE_CLUSTER
,
1059 .procname
= "page-cluster",
1060 .data
= &page_cluster
,
1061 .maxlen
= sizeof(int),
1063 .proc_handler
= &proc_dointvec
,
1066 .ctl_name
= VM_DIRTY_BACKGROUND
,
1067 .procname
= "dirty_background_ratio",
1068 .data
= &dirty_background_ratio
,
1069 .maxlen
= sizeof(dirty_background_ratio
),
1071 .proc_handler
= &dirty_background_ratio_handler
,
1072 .strategy
= &sysctl_intvec
,
1074 .extra2
= &one_hundred
,
1077 .ctl_name
= CTL_UNNUMBERED
,
1078 .procname
= "dirty_background_bytes",
1079 .data
= &dirty_background_bytes
,
1080 .maxlen
= sizeof(dirty_background_bytes
),
1082 .proc_handler
= &dirty_background_bytes_handler
,
1083 .strategy
= &sysctl_intvec
,
1087 .ctl_name
= VM_DIRTY_RATIO
,
1088 .procname
= "dirty_ratio",
1089 .data
= &vm_dirty_ratio
,
1090 .maxlen
= sizeof(vm_dirty_ratio
),
1092 .proc_handler
= &dirty_ratio_handler
,
1093 .strategy
= &sysctl_intvec
,
1095 .extra2
= &one_hundred
,
1098 .ctl_name
= CTL_UNNUMBERED
,
1099 .procname
= "dirty_bytes",
1100 .data
= &vm_dirty_bytes
,
1101 .maxlen
= sizeof(vm_dirty_bytes
),
1103 .proc_handler
= &dirty_bytes_handler
,
1104 .strategy
= &sysctl_intvec
,
1105 .extra1
= &dirty_bytes_min
,
1108 .procname
= "dirty_writeback_centisecs",
1109 .data
= &dirty_writeback_interval
,
1110 .maxlen
= sizeof(dirty_writeback_interval
),
1112 .proc_handler
= &dirty_writeback_centisecs_handler
,
1115 .procname
= "dirty_expire_centisecs",
1116 .data
= &dirty_expire_interval
,
1117 .maxlen
= sizeof(dirty_expire_interval
),
1119 .proc_handler
= &proc_dointvec
,
1122 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
1123 .procname
= "nr_pdflush_threads",
1124 .data
= &nr_pdflush_threads
,
1125 .maxlen
= sizeof nr_pdflush_threads
,
1126 .mode
= 0444 /* read-only*/,
1127 .proc_handler
= &proc_dointvec
,
1130 .ctl_name
= VM_SWAPPINESS
,
1131 .procname
= "swappiness",
1132 .data
= &vm_swappiness
,
1133 .maxlen
= sizeof(vm_swappiness
),
1135 .proc_handler
= &proc_dointvec_minmax
,
1136 .strategy
= &sysctl_intvec
,
1138 .extra2
= &one_hundred
,
1140 #ifdef CONFIG_HUGETLB_PAGE
1142 .procname
= "nr_hugepages",
1144 .maxlen
= sizeof(unsigned long),
1146 .proc_handler
= &hugetlb_sysctl_handler
,
1147 .extra1
= (void *)&hugetlb_zero
,
1148 .extra2
= (void *)&hugetlb_infinity
,
1151 .ctl_name
= VM_HUGETLB_GROUP
,
1152 .procname
= "hugetlb_shm_group",
1153 .data
= &sysctl_hugetlb_shm_group
,
1154 .maxlen
= sizeof(gid_t
),
1156 .proc_handler
= &proc_dointvec
,
1159 .ctl_name
= CTL_UNNUMBERED
,
1160 .procname
= "hugepages_treat_as_movable",
1161 .data
= &hugepages_treat_as_movable
,
1162 .maxlen
= sizeof(int),
1164 .proc_handler
= &hugetlb_treat_movable_handler
,
1167 .ctl_name
= CTL_UNNUMBERED
,
1168 .procname
= "nr_overcommit_hugepages",
1170 .maxlen
= sizeof(unsigned long),
1172 .proc_handler
= &hugetlb_overcommit_handler
,
1173 .extra1
= (void *)&hugetlb_zero
,
1174 .extra2
= (void *)&hugetlb_infinity
,
1178 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
1179 .procname
= "lowmem_reserve_ratio",
1180 .data
= &sysctl_lowmem_reserve_ratio
,
1181 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1183 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
1184 .strategy
= &sysctl_intvec
,
1187 .ctl_name
= VM_DROP_PAGECACHE
,
1188 .procname
= "drop_caches",
1189 .data
= &sysctl_drop_caches
,
1190 .maxlen
= sizeof(int),
1192 .proc_handler
= drop_caches_sysctl_handler
,
1193 .strategy
= &sysctl_intvec
,
1196 .ctl_name
= VM_MIN_FREE_KBYTES
,
1197 .procname
= "min_free_kbytes",
1198 .data
= &min_free_kbytes
,
1199 .maxlen
= sizeof(min_free_kbytes
),
1201 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1202 .strategy
= &sysctl_intvec
,
1206 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1207 .procname
= "percpu_pagelist_fraction",
1208 .data
= &percpu_pagelist_fraction
,
1209 .maxlen
= sizeof(percpu_pagelist_fraction
),
1211 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1212 .strategy
= &sysctl_intvec
,
1213 .extra1
= &min_percpu_pagelist_fract
,
1217 .ctl_name
= VM_MAX_MAP_COUNT
,
1218 .procname
= "max_map_count",
1219 .data
= &sysctl_max_map_count
,
1220 .maxlen
= sizeof(sysctl_max_map_count
),
1222 .proc_handler
= &proc_dointvec
1226 .ctl_name
= CTL_UNNUMBERED
,
1227 .procname
= "nr_trim_pages",
1228 .data
= &sysctl_nr_trim_pages
,
1229 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1231 .proc_handler
= &proc_dointvec_minmax
,
1232 .strategy
= &sysctl_intvec
,
1237 .ctl_name
= VM_LAPTOP_MODE
,
1238 .procname
= "laptop_mode",
1239 .data
= &laptop_mode
,
1240 .maxlen
= sizeof(laptop_mode
),
1242 .proc_handler
= &proc_dointvec_jiffies
,
1243 .strategy
= &sysctl_jiffies
,
1246 .ctl_name
= VM_BLOCK_DUMP
,
1247 .procname
= "block_dump",
1248 .data
= &block_dump
,
1249 .maxlen
= sizeof(block_dump
),
1251 .proc_handler
= &proc_dointvec
,
1252 .strategy
= &sysctl_intvec
,
1256 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1257 .procname
= "vfs_cache_pressure",
1258 .data
= &sysctl_vfs_cache_pressure
,
1259 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1261 .proc_handler
= &proc_dointvec
,
1262 .strategy
= &sysctl_intvec
,
1265 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1267 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1268 .procname
= "legacy_va_layout",
1269 .data
= &sysctl_legacy_va_layout
,
1270 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1272 .proc_handler
= &proc_dointvec
,
1273 .strategy
= &sysctl_intvec
,
1279 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1280 .procname
= "zone_reclaim_mode",
1281 .data
= &zone_reclaim_mode
,
1282 .maxlen
= sizeof(zone_reclaim_mode
),
1284 .proc_handler
= &proc_dointvec
,
1285 .strategy
= &sysctl_intvec
,
1289 .ctl_name
= VM_MIN_UNMAPPED
,
1290 .procname
= "min_unmapped_ratio",
1291 .data
= &sysctl_min_unmapped_ratio
,
1292 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1294 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1295 .strategy
= &sysctl_intvec
,
1297 .extra2
= &one_hundred
,
1300 .ctl_name
= VM_MIN_SLAB
,
1301 .procname
= "min_slab_ratio",
1302 .data
= &sysctl_min_slab_ratio
,
1303 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1305 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1306 .strategy
= &sysctl_intvec
,
1308 .extra2
= &one_hundred
,
1313 .ctl_name
= CTL_UNNUMBERED
,
1314 .procname
= "stat_interval",
1315 .data
= &sysctl_stat_interval
,
1316 .maxlen
= sizeof(sysctl_stat_interval
),
1318 .proc_handler
= &proc_dointvec_jiffies
,
1319 .strategy
= &sysctl_jiffies
,
1323 .ctl_name
= CTL_UNNUMBERED
,
1324 .procname
= "mmap_min_addr",
1325 .data
= &dac_mmap_min_addr
,
1326 .maxlen
= sizeof(unsigned long),
1328 .proc_handler
= &mmap_min_addr_handler
,
1332 .ctl_name
= CTL_UNNUMBERED
,
1333 .procname
= "numa_zonelist_order",
1334 .data
= &numa_zonelist_order
,
1335 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1337 .proc_handler
= &numa_zonelist_order_handler
,
1338 .strategy
= &sysctl_string
,
1341 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1342 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1344 .ctl_name
= VM_VDSO_ENABLED
,
1345 .procname
= "vdso_enabled",
1346 .data
= &vdso_enabled
,
1347 .maxlen
= sizeof(vdso_enabled
),
1349 .proc_handler
= &proc_dointvec
,
1350 .strategy
= &sysctl_intvec
,
1354 #ifdef CONFIG_HIGHMEM
1356 .ctl_name
= CTL_UNNUMBERED
,
1357 .procname
= "highmem_is_dirtyable",
1358 .data
= &vm_highmem_is_dirtyable
,
1359 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1361 .proc_handler
= &proc_dointvec_minmax
,
1362 .strategy
= &sysctl_intvec
,
1368 .ctl_name
= CTL_UNNUMBERED
,
1369 .procname
= "scan_unevictable_pages",
1370 .data
= &scan_unevictable_pages
,
1371 .maxlen
= sizeof(scan_unevictable_pages
),
1373 .proc_handler
= &scan_unevictable_handler
,
1376 * NOTE: do not add new entries to this table unless you have read
1377 * Documentation/sysctl/ctl_unnumbered.txt
1382 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1383 static struct ctl_table binfmt_misc_table
[] = {
1388 static struct ctl_table fs_table
[] = {
1390 .ctl_name
= FS_NRINODE
,
1391 .procname
= "inode-nr",
1392 .data
= &inodes_stat
,
1393 .maxlen
= 2*sizeof(int),
1395 .proc_handler
= &proc_dointvec
,
1398 .ctl_name
= FS_STATINODE
,
1399 .procname
= "inode-state",
1400 .data
= &inodes_stat
,
1401 .maxlen
= 7*sizeof(int),
1403 .proc_handler
= &proc_dointvec
,
1406 .procname
= "file-nr",
1407 .data
= &files_stat
,
1408 .maxlen
= 3*sizeof(int),
1410 .proc_handler
= &proc_nr_files
,
1413 .ctl_name
= FS_MAXFILE
,
1414 .procname
= "file-max",
1415 .data
= &files_stat
.max_files
,
1416 .maxlen
= sizeof(int),
1418 .proc_handler
= &proc_dointvec
,
1421 .ctl_name
= CTL_UNNUMBERED
,
1422 .procname
= "nr_open",
1423 .data
= &sysctl_nr_open
,
1424 .maxlen
= sizeof(int),
1426 .proc_handler
= &proc_dointvec_minmax
,
1427 .extra1
= &sysctl_nr_open_min
,
1428 .extra2
= &sysctl_nr_open_max
,
1431 .ctl_name
= FS_DENTRY
,
1432 .procname
= "dentry-state",
1433 .data
= &dentry_stat
,
1434 .maxlen
= 6*sizeof(int),
1436 .proc_handler
= &proc_dointvec
,
1439 .ctl_name
= FS_OVERFLOWUID
,
1440 .procname
= "overflowuid",
1441 .data
= &fs_overflowuid
,
1442 .maxlen
= sizeof(int),
1444 .proc_handler
= &proc_dointvec_minmax
,
1445 .strategy
= &sysctl_intvec
,
1446 .extra1
= &minolduid
,
1447 .extra2
= &maxolduid
,
1450 .ctl_name
= FS_OVERFLOWGID
,
1451 .procname
= "overflowgid",
1452 .data
= &fs_overflowgid
,
1453 .maxlen
= sizeof(int),
1455 .proc_handler
= &proc_dointvec_minmax
,
1456 .strategy
= &sysctl_intvec
,
1457 .extra1
= &minolduid
,
1458 .extra2
= &maxolduid
,
1460 #ifdef CONFIG_FILE_LOCKING
1462 .ctl_name
= FS_LEASES
,
1463 .procname
= "leases-enable",
1464 .data
= &leases_enable
,
1465 .maxlen
= sizeof(int),
1467 .proc_handler
= &proc_dointvec
,
1470 #ifdef CONFIG_DNOTIFY
1472 .ctl_name
= FS_DIR_NOTIFY
,
1473 .procname
= "dir-notify-enable",
1474 .data
= &dir_notify_enable
,
1475 .maxlen
= sizeof(int),
1477 .proc_handler
= &proc_dointvec
,
1481 #ifdef CONFIG_FILE_LOCKING
1483 .ctl_name
= FS_LEASE_TIME
,
1484 .procname
= "lease-break-time",
1485 .data
= &lease_break_time
,
1486 .maxlen
= sizeof(int),
1488 .proc_handler
= &proc_dointvec
,
1493 .procname
= "aio-nr",
1495 .maxlen
= sizeof(aio_nr
),
1497 .proc_handler
= &proc_doulongvec_minmax
,
1500 .procname
= "aio-max-nr",
1501 .data
= &aio_max_nr
,
1502 .maxlen
= sizeof(aio_max_nr
),
1504 .proc_handler
= &proc_doulongvec_minmax
,
1506 #endif /* CONFIG_AIO */
1507 #ifdef CONFIG_INOTIFY_USER
1509 .ctl_name
= FS_INOTIFY
,
1510 .procname
= "inotify",
1512 .child
= inotify_table
,
1517 .procname
= "epoll",
1519 .child
= epoll_table
,
1524 .ctl_name
= KERN_SETUID_DUMPABLE
,
1525 .procname
= "suid_dumpable",
1526 .data
= &suid_dumpable
,
1527 .maxlen
= sizeof(int),
1529 .proc_handler
= &proc_dointvec_minmax
,
1530 .strategy
= &sysctl_intvec
,
1534 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1536 .ctl_name
= CTL_UNNUMBERED
,
1537 .procname
= "binfmt_misc",
1539 .child
= binfmt_misc_table
,
1543 * NOTE: do not add new entries to this table unless you have read
1544 * Documentation/sysctl/ctl_unnumbered.txt
1549 static struct ctl_table debug_table
[] = {
1550 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1552 .ctl_name
= CTL_UNNUMBERED
,
1553 .procname
= "exception-trace",
1554 .data
= &show_unhandled_signals
,
1555 .maxlen
= sizeof(int),
1557 .proc_handler
= proc_dointvec
1563 static struct ctl_table dev_table
[] = {
1567 static DEFINE_SPINLOCK(sysctl_lock
);
1569 /* called under sysctl_lock */
1570 static int use_table(struct ctl_table_header
*p
)
1572 if (unlikely(p
->unregistering
))
1578 /* called under sysctl_lock */
1579 static void unuse_table(struct ctl_table_header
*p
)
1582 if (unlikely(p
->unregistering
))
1583 complete(p
->unregistering
);
1586 /* called under sysctl_lock, will reacquire if has to wait */
1587 static void start_unregistering(struct ctl_table_header
*p
)
1590 * if p->used is 0, nobody will ever touch that entry again;
1591 * we'll eliminate all paths to it before dropping sysctl_lock
1593 if (unlikely(p
->used
)) {
1594 struct completion wait
;
1595 init_completion(&wait
);
1596 p
->unregistering
= &wait
;
1597 spin_unlock(&sysctl_lock
);
1598 wait_for_completion(&wait
);
1599 spin_lock(&sysctl_lock
);
1601 /* anything non-NULL; we'll never dereference it */
1602 p
->unregistering
= ERR_PTR(-EINVAL
);
1605 * do not remove from the list until nobody holds it; walking the
1606 * list in do_sysctl() relies on that.
1608 list_del_init(&p
->ctl_entry
);
1611 void sysctl_head_get(struct ctl_table_header
*head
)
1613 spin_lock(&sysctl_lock
);
1615 spin_unlock(&sysctl_lock
);
1618 void sysctl_head_put(struct ctl_table_header
*head
)
1620 spin_lock(&sysctl_lock
);
1623 spin_unlock(&sysctl_lock
);
1626 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1630 spin_lock(&sysctl_lock
);
1631 if (!use_table(head
))
1632 head
= ERR_PTR(-ENOENT
);
1633 spin_unlock(&sysctl_lock
);
1637 void sysctl_head_finish(struct ctl_table_header
*head
)
1641 spin_lock(&sysctl_lock
);
1643 spin_unlock(&sysctl_lock
);
1646 static struct ctl_table_set
*
1647 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1649 struct ctl_table_set
*set
= &root
->default_set
;
1651 set
= root
->lookup(root
, namespaces
);
1655 static struct list_head
*
1656 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1658 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1662 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1663 struct ctl_table_header
*prev
)
1665 struct ctl_table_root
*root
;
1666 struct list_head
*header_list
;
1667 struct ctl_table_header
*head
;
1668 struct list_head
*tmp
;
1670 spin_lock(&sysctl_lock
);
1673 tmp
= &prev
->ctl_entry
;
1677 tmp
= &root_table_header
.ctl_entry
;
1679 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1681 if (!use_table(head
))
1683 spin_unlock(&sysctl_lock
);
1688 header_list
= lookup_header_list(root
, namespaces
);
1689 if (tmp
!= header_list
)
1693 root
= list_entry(root
->root_list
.next
,
1694 struct ctl_table_root
, root_list
);
1695 if (root
== &sysctl_table_root
)
1697 header_list
= lookup_header_list(root
, namespaces
);
1698 } while (list_empty(header_list
));
1699 tmp
= header_list
->next
;
1702 spin_unlock(&sysctl_lock
);
1706 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1708 return __sysctl_head_next(current
->nsproxy
, prev
);
1711 void register_sysctl_root(struct ctl_table_root
*root
)
1713 spin_lock(&sysctl_lock
);
1714 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1715 spin_unlock(&sysctl_lock
);
1718 #ifdef CONFIG_SYSCTL_SYSCALL
1719 /* Perform the actual read/write of a sysctl table entry. */
1720 static int do_sysctl_strategy(struct ctl_table_root
*root
,
1721 struct ctl_table
*table
,
1722 void __user
*oldval
, size_t __user
*oldlenp
,
1723 void __user
*newval
, size_t newlen
)
1731 if (sysctl_perm(root
, table
, op
))
1734 if (table
->strategy
) {
1735 rc
= table
->strategy(table
, oldval
, oldlenp
, newval
, newlen
);
1742 /* If there is no strategy routine, or if the strategy returns
1743 * zero, proceed with automatic r/w */
1744 if (table
->data
&& table
->maxlen
) {
1745 rc
= sysctl_data(table
, oldval
, oldlenp
, newval
, newlen
);
1752 static int parse_table(int __user
*name
, int nlen
,
1753 void __user
*oldval
, size_t __user
*oldlenp
,
1754 void __user
*newval
, size_t newlen
,
1755 struct ctl_table_root
*root
,
1756 struct ctl_table
*table
)
1762 if (get_user(n
, name
))
1764 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1765 if (!table
->ctl_name
)
1767 if (n
== table
->ctl_name
) {
1770 if (sysctl_perm(root
, table
, MAY_EXEC
))
1774 table
= table
->child
;
1777 error
= do_sysctl_strategy(root
, table
,
1786 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1787 void __user
*newval
, size_t newlen
)
1789 struct ctl_table_header
*head
;
1790 int error
= -ENOTDIR
;
1792 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1796 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1800 for (head
= sysctl_head_next(NULL
); head
;
1801 head
= sysctl_head_next(head
)) {
1802 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1804 head
->root
, head
->ctl_table
);
1805 if (error
!= -ENOTDIR
) {
1806 sysctl_head_finish(head
);
1813 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
1815 struct __sysctl_args tmp
;
1818 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1821 error
= deprecated_sysctl_warning(&tmp
);
1826 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1827 tmp
.newval
, tmp
.newlen
);
1832 #endif /* CONFIG_SYSCTL_SYSCALL */
1835 * sysctl_perm does NOT grant the superuser all rights automatically, because
1836 * some sysctl variables are readonly even to root.
1839 static int test_perm(int mode
, int op
)
1841 if (!current_euid())
1843 else if (in_egroup_p(0))
1845 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1850 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1855 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1859 if (root
->permissions
)
1860 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1864 return test_perm(mode
, op
);
1867 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1869 for (; table
->ctl_name
|| table
->procname
; table
++) {
1870 table
->parent
= parent
;
1872 sysctl_set_parent(table
, table
->child
);
1876 static __init
int sysctl_init(void)
1878 sysctl_set_parent(NULL
, root_table
);
1879 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1882 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1888 core_initcall(sysctl_init
);
1890 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1891 struct ctl_table
*table
)
1893 struct ctl_table
*p
;
1894 const char *s
= branch
->procname
;
1896 /* branch should have named subdirectory as its first element */
1897 if (!s
|| !branch
->child
)
1900 /* ... and nothing else */
1901 if (branch
[1].procname
|| branch
[1].ctl_name
)
1904 /* table should contain subdirectory with the same name */
1905 for (p
= table
; p
->procname
|| p
->ctl_name
; p
++) {
1908 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1914 /* see if attaching q to p would be an improvement */
1915 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1917 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1918 struct ctl_table
*next
;
1920 int not_in_parent
= !p
->attached_by
;
1922 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1923 if (by
== q
->attached_by
)
1925 if (to
== p
->attached_by
)
1931 if (is_better
&& not_in_parent
) {
1932 q
->attached_by
= by
;
1933 q
->attached_to
= to
;
1939 * __register_sysctl_paths - register a sysctl hierarchy
1940 * @root: List of sysctl headers to register on
1941 * @namespaces: Data to compute which lists of sysctl entries are visible
1942 * @path: The path to the directory the sysctl table is in.
1943 * @table: the top-level table structure
1945 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1946 * array. A completely 0 filled entry terminates the table.
1948 * The members of the &struct ctl_table structure are used as follows:
1950 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1951 * must be unique within that level of sysctl
1953 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1954 * enter a sysctl file
1956 * data - a pointer to data for use by proc_handler
1958 * maxlen - the maximum size in bytes of the data
1960 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1962 * child - a pointer to the child sysctl table if this entry is a directory, or
1965 * proc_handler - the text handler routine (described below)
1967 * strategy - the strategy routine (described below)
1969 * de - for internal use by the sysctl routines
1971 * extra1, extra2 - extra pointers usable by the proc handler routines
1973 * Leaf nodes in the sysctl tree will be represented by a single file
1974 * under /proc; non-leaf nodes will be represented by directories.
1976 * sysctl(2) can automatically manage read and write requests through
1977 * the sysctl table. The data and maxlen fields of the ctl_table
1978 * struct enable minimal validation of the values being written to be
1979 * performed, and the mode field allows minimal authentication.
1981 * More sophisticated management can be enabled by the provision of a
1982 * strategy routine with the table entry. This will be called before
1983 * any automatic read or write of the data is performed.
1985 * The strategy routine may return
1987 * < 0 - Error occurred (error is passed to user process)
1989 * 0 - OK - proceed with automatic read or write.
1991 * > 0 - OK - read or write has been done by the strategy routine, so
1992 * return immediately.
1994 * There must be a proc_handler routine for any terminal nodes
1995 * mirrored under /proc/sys (non-terminals are handled by a built-in
1996 * directory handler). Several default handlers are available to
1997 * cover common cases -
1999 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
2000 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
2001 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
2003 * It is the handler's job to read the input buffer from user memory
2004 * and process it. The handler should return 0 on success.
2006 * This routine returns %NULL on a failure to register, and a pointer
2007 * to the table header on success.
2009 struct ctl_table_header
*__register_sysctl_paths(
2010 struct ctl_table_root
*root
,
2011 struct nsproxy
*namespaces
,
2012 const struct ctl_path
*path
, struct ctl_table
*table
)
2014 struct ctl_table_header
*header
;
2015 struct ctl_table
*new, **prevp
;
2016 unsigned int n
, npath
;
2017 struct ctl_table_set
*set
;
2019 /* Count the path components */
2020 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
2024 * For each path component, allocate a 2-element ctl_table array.
2025 * The first array element will be filled with the sysctl entry
2026 * for this, the second will be the sentinel (ctl_name == 0).
2028 * We allocate everything in one go so that we don't have to
2029 * worry about freeing additional memory in unregister_sysctl_table.
2031 header
= kzalloc(sizeof(struct ctl_table_header
) +
2032 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
2036 new = (struct ctl_table
*) (header
+ 1);
2038 /* Now connect the dots */
2039 prevp
= &header
->ctl_table
;
2040 for (n
= 0; n
< npath
; ++n
, ++path
) {
2041 /* Copy the procname */
2042 new->procname
= path
->procname
;
2043 new->ctl_name
= path
->ctl_name
;
2047 prevp
= &new->child
;
2052 header
->ctl_table_arg
= table
;
2054 INIT_LIST_HEAD(&header
->ctl_entry
);
2056 header
->unregistering
= NULL
;
2057 header
->root
= root
;
2058 sysctl_set_parent(NULL
, header
->ctl_table
);
2060 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
2061 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
2066 spin_lock(&sysctl_lock
);
2067 header
->set
= lookup_header_set(root
, namespaces
);
2068 header
->attached_by
= header
->ctl_table
;
2069 header
->attached_to
= root_table
;
2070 header
->parent
= &root_table_header
;
2071 for (set
= header
->set
; set
; set
= set
->parent
) {
2072 struct ctl_table_header
*p
;
2073 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
2074 if (p
->unregistering
)
2076 try_attach(p
, header
);
2079 header
->parent
->count
++;
2080 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
2081 spin_unlock(&sysctl_lock
);
2087 * register_sysctl_table_path - register a sysctl table hierarchy
2088 * @path: The path to the directory the sysctl table is in.
2089 * @table: the top-level table structure
2091 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2092 * array. A completely 0 filled entry terminates the table.
2094 * See __register_sysctl_paths for more details.
2096 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2097 struct ctl_table
*table
)
2099 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
2104 * register_sysctl_table - register a sysctl table hierarchy
2105 * @table: the top-level table structure
2107 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2108 * array. A completely 0 filled entry terminates the table.
2110 * See register_sysctl_paths for more details.
2112 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
2114 static const struct ctl_path null_path
[] = { {} };
2116 return register_sysctl_paths(null_path
, table
);
2120 * unregister_sysctl_table - unregister a sysctl table hierarchy
2121 * @header: the header returned from register_sysctl_table
2123 * Unregisters the sysctl table and all children. proc entries may not
2124 * actually be removed until they are no longer used by anyone.
2126 void unregister_sysctl_table(struct ctl_table_header
* header
)
2133 spin_lock(&sysctl_lock
);
2134 start_unregistering(header
);
2135 if (!--header
->parent
->count
) {
2137 kfree(header
->parent
);
2139 if (!--header
->count
)
2141 spin_unlock(&sysctl_lock
);
2144 int sysctl_is_seen(struct ctl_table_header
*p
)
2146 struct ctl_table_set
*set
= p
->set
;
2148 spin_lock(&sysctl_lock
);
2149 if (p
->unregistering
)
2151 else if (!set
->is_seen
)
2154 res
= set
->is_seen(set
);
2155 spin_unlock(&sysctl_lock
);
2159 void setup_sysctl_set(struct ctl_table_set
*p
,
2160 struct ctl_table_set
*parent
,
2161 int (*is_seen
)(struct ctl_table_set
*))
2163 INIT_LIST_HEAD(&p
->list
);
2164 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
2165 p
->is_seen
= is_seen
;
2168 #else /* !CONFIG_SYSCTL */
2169 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
2174 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2175 struct ctl_table
*table
)
2180 void unregister_sysctl_table(struct ctl_table_header
* table
)
2184 void setup_sysctl_set(struct ctl_table_set
*p
,
2185 struct ctl_table_set
*parent
,
2186 int (*is_seen
)(struct ctl_table_set
*))
2190 void sysctl_head_put(struct ctl_table_header
*head
)
2194 #endif /* CONFIG_SYSCTL */
2200 #ifdef CONFIG_PROC_SYSCTL
2202 static int _proc_do_string(void* data
, int maxlen
, int write
,
2203 struct file
*filp
, void __user
*buffer
,
2204 size_t *lenp
, loff_t
*ppos
)
2210 if (!data
|| !maxlen
|| !*lenp
) {
2218 while (len
< *lenp
) {
2219 if (get_user(c
, p
++))
2221 if (c
== 0 || c
== '\n')
2227 if(copy_from_user(data
, buffer
, len
))
2229 ((char *) data
)[len
] = 0;
2247 if(copy_to_user(buffer
, data
, len
))
2250 if(put_user('\n', ((char __user
*) buffer
) + len
))
2261 * proc_dostring - read a string sysctl
2262 * @table: the sysctl table
2263 * @write: %TRUE if this is a write to the sysctl file
2264 * @filp: the file structure
2265 * @buffer: the user buffer
2266 * @lenp: the size of the user buffer
2267 * @ppos: file position
2269 * Reads/writes a string from/to the user buffer. If the kernel
2270 * buffer provided is not large enough to hold the string, the
2271 * string is truncated. The copied string is %NULL-terminated.
2272 * If the string is being read by the user process, it is copied
2273 * and a newline '\n' is added. It is truncated if the buffer is
2276 * Returns 0 on success.
2278 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2279 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2281 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
2282 buffer
, lenp
, ppos
);
2286 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
2288 int write
, void *data
)
2291 *valp
= *negp
? -*lvalp
: *lvalp
;
2296 *lvalp
= (unsigned long)-val
;
2299 *lvalp
= (unsigned long)val
;
2305 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2306 int write
, struct file
*filp
, void __user
*buffer
,
2307 size_t *lenp
, loff_t
*ppos
,
2308 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2309 int write
, void *data
),
2312 #define TMPBUFLEN 21
2313 int *i
, vleft
, first
= 1, neg
;
2317 char buf
[TMPBUFLEN
], *p
;
2318 char __user
*s
= buffer
;
2320 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
2321 (*ppos
&& !write
)) {
2326 i
= (int *) tbl_data
;
2327 vleft
= table
->maxlen
/ sizeof(*i
);
2331 conv
= do_proc_dointvec_conv
;
2333 for (; left
&& vleft
--; i
++, first
=0) {
2348 if (len
> sizeof(buf
) - 1)
2349 len
= sizeof(buf
) - 1;
2350 if (copy_from_user(buf
, s
, len
))
2354 if (*p
== '-' && left
> 1) {
2358 if (*p
< '0' || *p
> '9')
2361 lval
= simple_strtoul(p
, &p
, 0);
2364 if ((len
< left
) && *p
&& !isspace(*p
))
2369 if (conv(&neg
, &lval
, i
, 1, data
))
2376 if (conv(&neg
, &lval
, i
, 0, data
))
2379 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2383 if(copy_to_user(s
, buf
, len
))
2390 if (!write
&& !first
&& left
) {
2391 if(put_user('\n', s
))
2398 if (get_user(c
, s
++))
2413 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2414 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2415 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2416 int write
, void *data
),
2419 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2420 buffer
, lenp
, ppos
, conv
, data
);
2424 * proc_dointvec - read a vector of integers
2425 * @table: the sysctl table
2426 * @write: %TRUE if this is a write to the sysctl file
2427 * @filp: the file structure
2428 * @buffer: the user buffer
2429 * @lenp: the size of the user buffer
2430 * @ppos: file position
2432 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2433 * values from/to the user buffer, treated as an ASCII string.
2435 * Returns 0 on success.
2437 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2438 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2440 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2445 * Taint values can only be increased
2446 * This means we can safely use a temporary.
2448 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2449 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2452 unsigned long tmptaint
= get_taint();
2455 if (write
&& !capable(CAP_SYS_ADMIN
))
2460 err
= proc_doulongvec_minmax(&t
, write
, filp
, buffer
, lenp
, ppos
);
2466 * Poor man's atomic or. Not worth adding a primitive
2467 * to everyone's atomic.h for this
2470 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2471 if ((tmptaint
>> i
) & 1)
2479 struct do_proc_dointvec_minmax_conv_param
{
2484 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2486 int write
, void *data
)
2488 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2490 int val
= *negp
? -*lvalp
: *lvalp
;
2491 if ((param
->min
&& *param
->min
> val
) ||
2492 (param
->max
&& *param
->max
< val
))
2499 *lvalp
= (unsigned long)-val
;
2502 *lvalp
= (unsigned long)val
;
2509 * proc_dointvec_minmax - read a vector of integers with min/max values
2510 * @table: the sysctl table
2511 * @write: %TRUE if this is a write to the sysctl file
2512 * @filp: the file structure
2513 * @buffer: the user buffer
2514 * @lenp: the size of the user buffer
2515 * @ppos: file position
2517 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2518 * values from/to the user buffer, treated as an ASCII string.
2520 * This routine will ensure the values are within the range specified by
2521 * table->extra1 (min) and table->extra2 (max).
2523 * Returns 0 on success.
2525 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2526 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2528 struct do_proc_dointvec_minmax_conv_param param
= {
2529 .min
= (int *) table
->extra1
,
2530 .max
= (int *) table
->extra2
,
2532 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2533 do_proc_dointvec_minmax_conv
, ¶m
);
2536 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2538 void __user
*buffer
,
2539 size_t *lenp
, loff_t
*ppos
,
2540 unsigned long convmul
,
2541 unsigned long convdiv
)
2543 #define TMPBUFLEN 21
2544 unsigned long *i
, *min
, *max
, val
;
2545 int vleft
, first
=1, neg
;
2547 char buf
[TMPBUFLEN
], *p
;
2548 char __user
*s
= buffer
;
2550 if (!data
|| !table
->maxlen
|| !*lenp
||
2551 (*ppos
&& !write
)) {
2556 i
= (unsigned long *) data
;
2557 min
= (unsigned long *) table
->extra1
;
2558 max
= (unsigned long *) table
->extra2
;
2559 vleft
= table
->maxlen
/ sizeof(unsigned long);
2562 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2577 if (len
> TMPBUFLEN
-1)
2579 if (copy_from_user(buf
, s
, len
))
2583 if (*p
== '-' && left
> 1) {
2587 if (*p
< '0' || *p
> '9')
2589 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2591 if ((len
< left
) && *p
&& !isspace(*p
))
2600 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2607 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2611 if(copy_to_user(s
, buf
, len
))
2618 if (!write
&& !first
&& left
) {
2619 if(put_user('\n', s
))
2626 if (get_user(c
, s
++))
2641 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2643 void __user
*buffer
,
2644 size_t *lenp
, loff_t
*ppos
,
2645 unsigned long convmul
,
2646 unsigned long convdiv
)
2648 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2649 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2653 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2654 * @table: the sysctl table
2655 * @write: %TRUE if this is a write to the sysctl file
2656 * @filp: the file structure
2657 * @buffer: the user buffer
2658 * @lenp: the size of the user buffer
2659 * @ppos: file position
2661 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2662 * values from/to the user buffer, treated as an ASCII string.
2664 * This routine will ensure the values are within the range specified by
2665 * table->extra1 (min) and table->extra2 (max).
2667 * Returns 0 on success.
2669 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2670 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2672 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2676 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2677 * @table: the sysctl table
2678 * @write: %TRUE if this is a write to the sysctl file
2679 * @filp: the file structure
2680 * @buffer: the user buffer
2681 * @lenp: the size of the user buffer
2682 * @ppos: file position
2684 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2685 * values from/to the user buffer, treated as an ASCII string. The values
2686 * are treated as milliseconds, and converted to jiffies when they are stored.
2688 * This routine will ensure the values are within the range specified by
2689 * table->extra1 (min) and table->extra2 (max).
2691 * Returns 0 on success.
2693 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2695 void __user
*buffer
,
2696 size_t *lenp
, loff_t
*ppos
)
2698 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2699 lenp
, ppos
, HZ
, 1000l);
2703 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2705 int write
, void *data
)
2708 if (*lvalp
> LONG_MAX
/ HZ
)
2710 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2716 lval
= (unsigned long)-val
;
2719 lval
= (unsigned long)val
;
2726 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2728 int write
, void *data
)
2731 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2733 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2739 lval
= (unsigned long)-val
;
2742 lval
= (unsigned long)val
;
2744 *lvalp
= jiffies_to_clock_t(lval
);
2749 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2751 int write
, void *data
)
2754 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2760 lval
= (unsigned long)-val
;
2763 lval
= (unsigned long)val
;
2765 *lvalp
= jiffies_to_msecs(lval
);
2771 * proc_dointvec_jiffies - read a vector of integers as seconds
2772 * @table: the sysctl table
2773 * @write: %TRUE if this is a write to the sysctl file
2774 * @filp: the file structure
2775 * @buffer: the user buffer
2776 * @lenp: the size of the user buffer
2777 * @ppos: file position
2779 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2780 * values from/to the user buffer, treated as an ASCII string.
2781 * The values read are assumed to be in seconds, and are converted into
2784 * Returns 0 on success.
2786 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2787 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2789 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2790 do_proc_dointvec_jiffies_conv
,NULL
);
2794 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2795 * @table: the sysctl table
2796 * @write: %TRUE if this is a write to the sysctl file
2797 * @filp: the file structure
2798 * @buffer: the user buffer
2799 * @lenp: the size of the user buffer
2800 * @ppos: pointer to the file position
2802 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2803 * values from/to the user buffer, treated as an ASCII string.
2804 * The values read are assumed to be in 1/USER_HZ seconds, and
2805 * are converted into jiffies.
2807 * Returns 0 on success.
2809 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2810 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2812 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2813 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2817 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2818 * @table: the sysctl table
2819 * @write: %TRUE if this is a write to the sysctl file
2820 * @filp: the file structure
2821 * @buffer: the user buffer
2822 * @lenp: the size of the user buffer
2823 * @ppos: file position
2824 * @ppos: the current position in the file
2826 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2827 * values from/to the user buffer, treated as an ASCII string.
2828 * The values read are assumed to be in 1/1000 seconds, and
2829 * are converted into jiffies.
2831 * Returns 0 on success.
2833 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2834 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2836 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2837 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2840 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2841 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2843 struct pid
*new_pid
;
2847 tmp
= pid_vnr(cad_pid
);
2849 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2850 lenp
, ppos
, NULL
, NULL
);
2854 new_pid
= find_get_pid(tmp
);
2858 put_pid(xchg(&cad_pid
, new_pid
));
2862 #else /* CONFIG_PROC_FS */
2864 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2865 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2870 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2871 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2876 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2877 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2882 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2883 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2888 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2889 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2894 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2895 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2900 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2901 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2906 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2908 void __user
*buffer
,
2909 size_t *lenp
, loff_t
*ppos
)
2915 #endif /* CONFIG_PROC_FS */
2918 #ifdef CONFIG_SYSCTL_SYSCALL
2920 * General sysctl support routines
2923 /* The generic sysctl data routine (used if no strategy routine supplied) */
2924 int sysctl_data(struct ctl_table
*table
,
2925 void __user
*oldval
, size_t __user
*oldlenp
,
2926 void __user
*newval
, size_t newlen
)
2930 /* Get out of I don't have a variable */
2931 if (!table
->data
|| !table
->maxlen
)
2934 if (oldval
&& oldlenp
) {
2935 if (get_user(len
, oldlenp
))
2938 if (len
> table
->maxlen
)
2939 len
= table
->maxlen
;
2940 if (copy_to_user(oldval
, table
->data
, len
))
2942 if (put_user(len
, oldlenp
))
2947 if (newval
&& newlen
) {
2948 if (newlen
> table
->maxlen
)
2949 newlen
= table
->maxlen
;
2951 if (copy_from_user(table
->data
, newval
, newlen
))
2957 /* The generic string strategy routine: */
2958 int sysctl_string(struct ctl_table
*table
,
2959 void __user
*oldval
, size_t __user
*oldlenp
,
2960 void __user
*newval
, size_t newlen
)
2962 if (!table
->data
|| !table
->maxlen
)
2965 if (oldval
&& oldlenp
) {
2967 if (get_user(bufsize
, oldlenp
))
2970 size_t len
= strlen(table
->data
), copied
;
2972 /* This shouldn't trigger for a well-formed sysctl */
2973 if (len
> table
->maxlen
)
2974 len
= table
->maxlen
;
2976 /* Copy up to a max of bufsize-1 bytes of the string */
2977 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2979 if (copy_to_user(oldval
, table
->data
, copied
) ||
2980 put_user(0, (char __user
*)(oldval
+ copied
)))
2982 if (put_user(len
, oldlenp
))
2986 if (newval
&& newlen
) {
2987 size_t len
= newlen
;
2988 if (len
> table
->maxlen
)
2989 len
= table
->maxlen
;
2990 if(copy_from_user(table
->data
, newval
, len
))
2992 if (len
== table
->maxlen
)
2994 ((char *) table
->data
)[len
] = 0;
3000 * This function makes sure that all of the integers in the vector
3001 * are between the minimum and maximum values given in the arrays
3002 * table->extra1 and table->extra2, respectively.
3004 int sysctl_intvec(struct ctl_table
*table
,
3005 void __user
*oldval
, size_t __user
*oldlenp
,
3006 void __user
*newval
, size_t newlen
)
3009 if (newval
&& newlen
) {
3010 int __user
*vec
= (int __user
*) newval
;
3011 int *min
= (int *) table
->extra1
;
3012 int *max
= (int *) table
->extra2
;
3016 if (newlen
% sizeof(int) != 0)
3019 if (!table
->extra1
&& !table
->extra2
)
3022 if (newlen
> table
->maxlen
)
3023 newlen
= table
->maxlen
;
3024 length
= newlen
/ sizeof(int);
3026 for (i
= 0; i
< length
; i
++) {
3028 if (get_user(value
, vec
+ i
))
3030 if (min
&& value
< min
[i
])
3032 if (max
&& value
> max
[i
])
3039 /* Strategy function to convert jiffies to seconds */
3040 int sysctl_jiffies(struct ctl_table
*table
,
3041 void __user
*oldval
, size_t __user
*oldlenp
,
3042 void __user
*newval
, size_t newlen
)
3044 if (oldval
&& oldlenp
) {
3047 if (get_user(olen
, oldlenp
))
3052 if (olen
< sizeof(int))
3055 val
= *(int *)(table
->data
) / HZ
;
3056 if (put_user(val
, (int __user
*)oldval
))
3058 if (put_user(sizeof(int), oldlenp
))
3062 if (newval
&& newlen
) {
3064 if (newlen
!= sizeof(int))
3066 if (get_user(new, (int __user
*)newval
))
3068 *(int *)(table
->data
) = new*HZ
;
3073 /* Strategy function to convert jiffies to seconds */
3074 int sysctl_ms_jiffies(struct ctl_table
*table
,
3075 void __user
*oldval
, size_t __user
*oldlenp
,
3076 void __user
*newval
, size_t newlen
)
3078 if (oldval
&& oldlenp
) {
3081 if (get_user(olen
, oldlenp
))
3086 if (olen
< sizeof(int))
3089 val
= jiffies_to_msecs(*(int *)(table
->data
));
3090 if (put_user(val
, (int __user
*)oldval
))
3092 if (put_user(sizeof(int), oldlenp
))
3096 if (newval
&& newlen
) {
3098 if (newlen
!= sizeof(int))
3100 if (get_user(new, (int __user
*)newval
))
3102 *(int *)(table
->data
) = msecs_to_jiffies(new);
3109 #else /* CONFIG_SYSCTL_SYSCALL */
3112 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
3114 struct __sysctl_args tmp
;
3117 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
3120 error
= deprecated_sysctl_warning(&tmp
);
3122 /* If no error reading the parameters then just -ENOSYS ... */
3129 int sysctl_data(struct ctl_table
*table
,
3130 void __user
*oldval
, size_t __user
*oldlenp
,
3131 void __user
*newval
, size_t newlen
)
3136 int sysctl_string(struct ctl_table
*table
,
3137 void __user
*oldval
, size_t __user
*oldlenp
,
3138 void __user
*newval
, size_t newlen
)
3143 int sysctl_intvec(struct ctl_table
*table
,
3144 void __user
*oldval
, size_t __user
*oldlenp
,
3145 void __user
*newval
, size_t newlen
)
3150 int sysctl_jiffies(struct ctl_table
*table
,
3151 void __user
*oldval
, size_t __user
*oldlenp
,
3152 void __user
*newval
, size_t newlen
)
3157 int sysctl_ms_jiffies(struct ctl_table
*table
,
3158 void __user
*oldval
, size_t __user
*oldlenp
,
3159 void __user
*newval
, size_t newlen
)
3164 #endif /* CONFIG_SYSCTL_SYSCALL */
3166 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
3168 static int msg_count
;
3169 int name
[CTL_MAXNAME
];
3172 /* Check args->nlen. */
3173 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
3176 /* Read in the sysctl name for better debug message logging */
3177 for (i
= 0; i
< args
->nlen
; i
++)
3178 if (get_user(name
[i
], args
->name
+ i
))
3181 /* Ignore accesses to kernel.version */
3182 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
3185 if (msg_count
< 5) {
3188 "warning: process `%s' used the deprecated sysctl "
3189 "system call with ", current
->comm
);
3190 for (i
= 0; i
< args
->nlen
; i
++)
3191 printk("%d.", name
[i
]);
3198 * No sense putting this after each symbol definition, twice,
3199 * exception granted :-)
3201 EXPORT_SYMBOL(proc_dointvec
);
3202 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3203 EXPORT_SYMBOL(proc_dointvec_minmax
);
3204 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3205 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3206 EXPORT_SYMBOL(proc_dostring
);
3207 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3208 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
3209 EXPORT_SYMBOL(register_sysctl_table
);
3210 EXPORT_SYMBOL(register_sysctl_paths
);
3211 EXPORT_SYMBOL(sysctl_intvec
);
3212 EXPORT_SYMBOL(sysctl_jiffies
);
3213 EXPORT_SYMBOL(sysctl_ms_jiffies
);
3214 EXPORT_SYMBOL(sysctl_string
);
3215 EXPORT_SYMBOL(sysctl_data
);
3216 EXPORT_SYMBOL(unregister_sysctl_table
);