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 */
95 /* Constants used for minimum and maximum */
96 #ifdef CONFIG_DETECT_SOFTLOCKUP
97 static int sixty
= 60;
98 static int neg_one
= -1;
102 static int __maybe_unused one
= 1;
103 static int __maybe_unused two
= 2;
104 static unsigned long one_ul
= 1;
105 static int one_hundred
= 100;
107 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
108 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
110 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
111 static int maxolduid
= 65535;
112 static int minolduid
;
113 static int min_percpu_pagelist_fract
= 8;
115 static int ngroups_max
= NGROUPS_MAX
;
117 #ifdef CONFIG_MODULES
118 extern char modprobe_path
[];
119 extern int modules_disabled
;
121 #ifdef CONFIG_CHR_DEV_SG
122 extern int sg_big_buff
;
126 #include <asm/system.h>
129 #ifdef CONFIG_SPARC64
130 extern int sysctl_tsb_ratio
;
134 extern int pwrsw_enabled
;
135 extern int unaligned_enabled
;
139 #ifdef CONFIG_MATHEMU
140 extern int sysctl_ieee_emulation_warnings
;
142 extern int sysctl_userprocess_debug
;
143 extern int spin_retry
;
146 #ifdef CONFIG_BSD_PROCESS_ACCT
147 extern int acct_parm
[];
151 extern int no_unaligned_warning
;
152 extern int unaligned_dump_stack
;
155 #ifdef CONFIG_RT_MUTEXES
156 extern int max_lock_depth
;
159 #ifdef CONFIG_PROC_SYSCTL
160 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
161 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
162 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
163 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
166 static struct ctl_table root_table
[];
167 static struct ctl_table_root sysctl_table_root
;
168 static struct ctl_table_header root_table_header
= {
170 .ctl_table
= root_table
,
171 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),
172 .root
= &sysctl_table_root
,
173 .set
= &sysctl_table_root
.default_set
,
175 static struct ctl_table_root sysctl_table_root
= {
176 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
177 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
180 static struct ctl_table kern_table
[];
181 static struct ctl_table vm_table
[];
182 static struct ctl_table fs_table
[];
183 static struct ctl_table debug_table
[];
184 static struct ctl_table dev_table
[];
185 extern struct ctl_table random_table
[];
186 #ifdef CONFIG_INOTIFY_USER
187 extern struct ctl_table inotify_table
[];
190 extern struct ctl_table epoll_table
[];
193 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
194 int sysctl_legacy_va_layout
;
197 extern int prove_locking
;
198 extern int lock_stat
;
200 /* The default sysctl tables: */
202 static struct ctl_table root_table
[] = {
204 .ctl_name
= CTL_KERN
,
205 .procname
= "kernel",
222 .ctl_name
= CTL_DEBUG
,
225 .child
= debug_table
,
234 * NOTE: do not add new entries to this table unless you have read
235 * Documentation/sysctl/ctl_unnumbered.txt
240 #ifdef CONFIG_SCHED_DEBUG
241 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
242 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
243 static int min_wakeup_granularity_ns
; /* 0 usecs */
244 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
247 static struct ctl_table kern_table
[] = {
249 .ctl_name
= CTL_UNNUMBERED
,
250 .procname
= "sched_child_runs_first",
251 .data
= &sysctl_sched_child_runs_first
,
252 .maxlen
= sizeof(unsigned int),
254 .proc_handler
= &proc_dointvec
,
256 #ifdef CONFIG_SCHED_DEBUG
258 .ctl_name
= CTL_UNNUMBERED
,
259 .procname
= "sched_min_granularity_ns",
260 .data
= &sysctl_sched_min_granularity
,
261 .maxlen
= sizeof(unsigned int),
263 .proc_handler
= &sched_nr_latency_handler
,
264 .strategy
= &sysctl_intvec
,
265 .extra1
= &min_sched_granularity_ns
,
266 .extra2
= &max_sched_granularity_ns
,
269 .ctl_name
= CTL_UNNUMBERED
,
270 .procname
= "sched_latency_ns",
271 .data
= &sysctl_sched_latency
,
272 .maxlen
= sizeof(unsigned int),
274 .proc_handler
= &sched_nr_latency_handler
,
275 .strategy
= &sysctl_intvec
,
276 .extra1
= &min_sched_granularity_ns
,
277 .extra2
= &max_sched_granularity_ns
,
280 .ctl_name
= CTL_UNNUMBERED
,
281 .procname
= "sched_wakeup_granularity_ns",
282 .data
= &sysctl_sched_wakeup_granularity
,
283 .maxlen
= sizeof(unsigned int),
285 .proc_handler
= &proc_dointvec_minmax
,
286 .strategy
= &sysctl_intvec
,
287 .extra1
= &min_wakeup_granularity_ns
,
288 .extra2
= &max_wakeup_granularity_ns
,
291 .ctl_name
= CTL_UNNUMBERED
,
292 .procname
= "sched_shares_ratelimit",
293 .data
= &sysctl_sched_shares_ratelimit
,
294 .maxlen
= sizeof(unsigned int),
296 .proc_handler
= &proc_dointvec
,
299 .ctl_name
= CTL_UNNUMBERED
,
300 .procname
= "sched_shares_thresh",
301 .data
= &sysctl_sched_shares_thresh
,
302 .maxlen
= sizeof(unsigned int),
304 .proc_handler
= &proc_dointvec_minmax
,
305 .strategy
= &sysctl_intvec
,
309 .ctl_name
= CTL_UNNUMBERED
,
310 .procname
= "sched_features",
311 .data
= &sysctl_sched_features
,
312 .maxlen
= sizeof(unsigned int),
314 .proc_handler
= &proc_dointvec
,
317 .ctl_name
= CTL_UNNUMBERED
,
318 .procname
= "sched_migration_cost",
319 .data
= &sysctl_sched_migration_cost
,
320 .maxlen
= sizeof(unsigned int),
322 .proc_handler
= &proc_dointvec
,
325 .ctl_name
= CTL_UNNUMBERED
,
326 .procname
= "sched_nr_migrate",
327 .data
= &sysctl_sched_nr_migrate
,
328 .maxlen
= sizeof(unsigned int),
330 .proc_handler
= &proc_dointvec
,
333 .ctl_name
= CTL_UNNUMBERED
,
334 .procname
= "sched_time_avg",
335 .data
= &sysctl_sched_time_avg
,
336 .maxlen
= sizeof(unsigned int),
338 .proc_handler
= &proc_dointvec
,
341 .ctl_name
= CTL_UNNUMBERED
,
342 .procname
= "timer_migration",
343 .data
= &sysctl_timer_migration
,
344 .maxlen
= sizeof(unsigned int),
346 .proc_handler
= &proc_dointvec_minmax
,
347 .strategy
= &sysctl_intvec
,
353 .ctl_name
= CTL_UNNUMBERED
,
354 .procname
= "sched_rt_period_us",
355 .data
= &sysctl_sched_rt_period
,
356 .maxlen
= sizeof(unsigned int),
358 .proc_handler
= &sched_rt_handler
,
361 .ctl_name
= CTL_UNNUMBERED
,
362 .procname
= "sched_rt_runtime_us",
363 .data
= &sysctl_sched_rt_runtime
,
364 .maxlen
= sizeof(int),
366 .proc_handler
= &sched_rt_handler
,
369 .ctl_name
= CTL_UNNUMBERED
,
370 .procname
= "sched_compat_yield",
371 .data
= &sysctl_sched_compat_yield
,
372 .maxlen
= sizeof(unsigned int),
374 .proc_handler
= &proc_dointvec
,
376 #ifdef CONFIG_PROVE_LOCKING
378 .ctl_name
= CTL_UNNUMBERED
,
379 .procname
= "prove_locking",
380 .data
= &prove_locking
,
381 .maxlen
= sizeof(int),
383 .proc_handler
= &proc_dointvec
,
386 #ifdef CONFIG_LOCK_STAT
388 .ctl_name
= CTL_UNNUMBERED
,
389 .procname
= "lock_stat",
391 .maxlen
= sizeof(int),
393 .proc_handler
= &proc_dointvec
,
397 .ctl_name
= KERN_PANIC
,
399 .data
= &panic_timeout
,
400 .maxlen
= sizeof(int),
402 .proc_handler
= &proc_dointvec
,
405 .ctl_name
= KERN_CORE_USES_PID
,
406 .procname
= "core_uses_pid",
407 .data
= &core_uses_pid
,
408 .maxlen
= sizeof(int),
410 .proc_handler
= &proc_dointvec
,
413 .ctl_name
= KERN_CORE_PATTERN
,
414 .procname
= "core_pattern",
415 .data
= core_pattern
,
416 .maxlen
= CORENAME_MAX_SIZE
,
418 .proc_handler
= &proc_dostring
,
419 .strategy
= &sysctl_string
,
421 #ifdef CONFIG_PROC_SYSCTL
423 .procname
= "tainted",
424 .maxlen
= sizeof(long),
426 .proc_handler
= &proc_taint
,
429 #ifdef CONFIG_LATENCYTOP
431 .procname
= "latencytop",
432 .data
= &latencytop_enabled
,
433 .maxlen
= sizeof(int),
435 .proc_handler
= &proc_dointvec
,
438 #ifdef CONFIG_BLK_DEV_INITRD
440 .ctl_name
= KERN_REALROOTDEV
,
441 .procname
= "real-root-dev",
442 .data
= &real_root_dev
,
443 .maxlen
= sizeof(int),
445 .proc_handler
= &proc_dointvec
,
449 .ctl_name
= CTL_UNNUMBERED
,
450 .procname
= "print-fatal-signals",
451 .data
= &print_fatal_signals
,
452 .maxlen
= sizeof(int),
454 .proc_handler
= &proc_dointvec
,
458 .ctl_name
= KERN_SPARC_REBOOT
,
459 .procname
= "reboot-cmd",
460 .data
= reboot_command
,
463 .proc_handler
= &proc_dostring
,
464 .strategy
= &sysctl_string
,
467 .ctl_name
= KERN_SPARC_STOP_A
,
468 .procname
= "stop-a",
469 .data
= &stop_a_enabled
,
470 .maxlen
= sizeof (int),
472 .proc_handler
= &proc_dointvec
,
475 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
476 .procname
= "scons-poweroff",
477 .data
= &scons_pwroff
,
478 .maxlen
= sizeof (int),
480 .proc_handler
= &proc_dointvec
,
483 #ifdef CONFIG_SPARC64
485 .ctl_name
= CTL_UNNUMBERED
,
486 .procname
= "tsb-ratio",
487 .data
= &sysctl_tsb_ratio
,
488 .maxlen
= sizeof (int),
490 .proc_handler
= &proc_dointvec
,
495 .ctl_name
= KERN_HPPA_PWRSW
,
496 .procname
= "soft-power",
497 .data
= &pwrsw_enabled
,
498 .maxlen
= sizeof (int),
500 .proc_handler
= &proc_dointvec
,
503 .ctl_name
= KERN_HPPA_UNALIGNED
,
504 .procname
= "unaligned-trap",
505 .data
= &unaligned_enabled
,
506 .maxlen
= sizeof (int),
508 .proc_handler
= &proc_dointvec
,
512 .ctl_name
= KERN_CTLALTDEL
,
513 .procname
= "ctrl-alt-del",
515 .maxlen
= sizeof(int),
517 .proc_handler
= &proc_dointvec
,
519 #ifdef CONFIG_FUNCTION_TRACER
521 .ctl_name
= CTL_UNNUMBERED
,
522 .procname
= "ftrace_enabled",
523 .data
= &ftrace_enabled
,
524 .maxlen
= sizeof(int),
526 .proc_handler
= &ftrace_enable_sysctl
,
529 #ifdef CONFIG_STACK_TRACER
531 .ctl_name
= CTL_UNNUMBERED
,
532 .procname
= "stack_tracer_enabled",
533 .data
= &stack_tracer_enabled
,
534 .maxlen
= sizeof(int),
536 .proc_handler
= &stack_trace_sysctl
,
539 #ifdef CONFIG_TRACING
541 .ctl_name
= CTL_UNNUMBERED
,
542 .procname
= "ftrace_dump_on_oops",
543 .data
= &ftrace_dump_on_oops
,
544 .maxlen
= sizeof(int),
546 .proc_handler
= &proc_dointvec
,
549 #ifdef CONFIG_MODULES
551 .ctl_name
= KERN_MODPROBE
,
552 .procname
= "modprobe",
553 .data
= &modprobe_path
,
554 .maxlen
= KMOD_PATH_LEN
,
556 .proc_handler
= &proc_dostring
,
557 .strategy
= &sysctl_string
,
560 .ctl_name
= CTL_UNNUMBERED
,
561 .procname
= "modules_disabled",
562 .data
= &modules_disabled
,
563 .maxlen
= sizeof(int),
565 /* only handle a transition from default "0" to "1" */
566 .proc_handler
= &proc_dointvec_minmax
,
571 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
573 .ctl_name
= KERN_HOTPLUG
,
574 .procname
= "hotplug",
575 .data
= &uevent_helper
,
576 .maxlen
= UEVENT_HELPER_PATH_LEN
,
578 .proc_handler
= &proc_dostring
,
579 .strategy
= &sysctl_string
,
582 #ifdef CONFIG_CHR_DEV_SG
584 .ctl_name
= KERN_SG_BIG_BUFF
,
585 .procname
= "sg-big-buff",
586 .data
= &sg_big_buff
,
587 .maxlen
= sizeof (int),
589 .proc_handler
= &proc_dointvec
,
592 #ifdef CONFIG_BSD_PROCESS_ACCT
594 .ctl_name
= KERN_ACCT
,
597 .maxlen
= 3*sizeof(int),
599 .proc_handler
= &proc_dointvec
,
602 #ifdef CONFIG_MAGIC_SYSRQ
604 .ctl_name
= KERN_SYSRQ
,
606 .data
= &__sysrq_enabled
,
607 .maxlen
= sizeof (int),
609 .proc_handler
= &proc_dointvec
,
612 #ifdef CONFIG_PROC_SYSCTL
614 .procname
= "cad_pid",
616 .maxlen
= sizeof (int),
618 .proc_handler
= &proc_do_cad_pid
,
622 .ctl_name
= KERN_MAX_THREADS
,
623 .procname
= "threads-max",
624 .data
= &max_threads
,
625 .maxlen
= sizeof(int),
627 .proc_handler
= &proc_dointvec
,
630 .ctl_name
= KERN_RANDOM
,
631 .procname
= "random",
633 .child
= random_table
,
636 .ctl_name
= KERN_OVERFLOWUID
,
637 .procname
= "overflowuid",
638 .data
= &overflowuid
,
639 .maxlen
= sizeof(int),
641 .proc_handler
= &proc_dointvec_minmax
,
642 .strategy
= &sysctl_intvec
,
643 .extra1
= &minolduid
,
644 .extra2
= &maxolduid
,
647 .ctl_name
= KERN_OVERFLOWGID
,
648 .procname
= "overflowgid",
649 .data
= &overflowgid
,
650 .maxlen
= sizeof(int),
652 .proc_handler
= &proc_dointvec_minmax
,
653 .strategy
= &sysctl_intvec
,
654 .extra1
= &minolduid
,
655 .extra2
= &maxolduid
,
658 #ifdef CONFIG_MATHEMU
660 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
661 .procname
= "ieee_emulation_warnings",
662 .data
= &sysctl_ieee_emulation_warnings
,
663 .maxlen
= sizeof(int),
665 .proc_handler
= &proc_dointvec
,
669 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
670 .procname
= "userprocess_debug",
671 .data
= &sysctl_userprocess_debug
,
672 .maxlen
= sizeof(int),
674 .proc_handler
= &proc_dointvec
,
678 .ctl_name
= KERN_PIDMAX
,
679 .procname
= "pid_max",
681 .maxlen
= sizeof (int),
683 .proc_handler
= &proc_dointvec_minmax
,
684 .strategy
= sysctl_intvec
,
685 .extra1
= &pid_max_min
,
686 .extra2
= &pid_max_max
,
689 .ctl_name
= KERN_PANIC_ON_OOPS
,
690 .procname
= "panic_on_oops",
691 .data
= &panic_on_oops
,
692 .maxlen
= sizeof(int),
694 .proc_handler
= &proc_dointvec
,
696 #if defined CONFIG_PRINTK
698 .ctl_name
= KERN_PRINTK
,
699 .procname
= "printk",
700 .data
= &console_loglevel
,
701 .maxlen
= 4*sizeof(int),
703 .proc_handler
= &proc_dointvec
,
706 .ctl_name
= KERN_PRINTK_RATELIMIT
,
707 .procname
= "printk_ratelimit",
708 .data
= &printk_ratelimit_state
.interval
,
709 .maxlen
= sizeof(int),
711 .proc_handler
= &proc_dointvec_jiffies
,
712 .strategy
= &sysctl_jiffies
,
715 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
716 .procname
= "printk_ratelimit_burst",
717 .data
= &printk_ratelimit_state
.burst
,
718 .maxlen
= sizeof(int),
720 .proc_handler
= &proc_dointvec
,
724 .ctl_name
= KERN_NGROUPS_MAX
,
725 .procname
= "ngroups_max",
726 .data
= &ngroups_max
,
727 .maxlen
= sizeof (int),
729 .proc_handler
= &proc_dointvec
,
731 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
733 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
734 .procname
= "unknown_nmi_panic",
735 .data
= &unknown_nmi_panic
,
736 .maxlen
= sizeof (int),
738 .proc_handler
= &proc_dointvec
,
741 .procname
= "nmi_watchdog",
742 .data
= &nmi_watchdog_enabled
,
743 .maxlen
= sizeof (int),
745 .proc_handler
= &proc_nmi_enabled
,
748 #if defined(CONFIG_X86)
750 .ctl_name
= KERN_PANIC_ON_NMI
,
751 .procname
= "panic_on_unrecovered_nmi",
752 .data
= &panic_on_unrecovered_nmi
,
753 .maxlen
= sizeof(int),
755 .proc_handler
= &proc_dointvec
,
758 .ctl_name
= CTL_UNNUMBERED
,
759 .procname
= "panic_on_io_nmi",
760 .data
= &panic_on_io_nmi
,
761 .maxlen
= sizeof(int),
763 .proc_handler
= &proc_dointvec
,
766 .ctl_name
= KERN_BOOTLOADER_TYPE
,
767 .procname
= "bootloader_type",
768 .data
= &bootloader_type
,
769 .maxlen
= sizeof (int),
771 .proc_handler
= &proc_dointvec
,
774 .ctl_name
= CTL_UNNUMBERED
,
775 .procname
= "bootloader_version",
776 .data
= &bootloader_version
,
777 .maxlen
= sizeof (int),
779 .proc_handler
= &proc_dointvec
,
782 .ctl_name
= CTL_UNNUMBERED
,
783 .procname
= "kstack_depth_to_print",
784 .data
= &kstack_depth_to_print
,
785 .maxlen
= sizeof(int),
787 .proc_handler
= &proc_dointvec
,
790 .ctl_name
= CTL_UNNUMBERED
,
791 .procname
= "io_delay_type",
792 .data
= &io_delay_type
,
793 .maxlen
= sizeof(int),
795 .proc_handler
= &proc_dointvec
,
798 #if defined(CONFIG_MMU)
800 .ctl_name
= KERN_RANDOMIZE
,
801 .procname
= "randomize_va_space",
802 .data
= &randomize_va_space
,
803 .maxlen
= sizeof(int),
805 .proc_handler
= &proc_dointvec
,
808 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
810 .ctl_name
= KERN_SPIN_RETRY
,
811 .procname
= "spin_retry",
813 .maxlen
= sizeof (int),
815 .proc_handler
= &proc_dointvec
,
818 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
820 .procname
= "acpi_video_flags",
821 .data
= &acpi_realmode_flags
,
822 .maxlen
= sizeof (unsigned long),
824 .proc_handler
= &proc_doulongvec_minmax
,
829 .ctl_name
= KERN_IA64_UNALIGNED
,
830 .procname
= "ignore-unaligned-usertrap",
831 .data
= &no_unaligned_warning
,
832 .maxlen
= sizeof (int),
834 .proc_handler
= &proc_dointvec
,
837 .ctl_name
= CTL_UNNUMBERED
,
838 .procname
= "unaligned-dump-stack",
839 .data
= &unaligned_dump_stack
,
840 .maxlen
= sizeof (int),
842 .proc_handler
= &proc_dointvec
,
845 #ifdef CONFIG_DETECT_SOFTLOCKUP
847 .ctl_name
= CTL_UNNUMBERED
,
848 .procname
= "softlockup_panic",
849 .data
= &softlockup_panic
,
850 .maxlen
= sizeof(int),
852 .proc_handler
= &proc_dointvec_minmax
,
853 .strategy
= &sysctl_intvec
,
858 .ctl_name
= CTL_UNNUMBERED
,
859 .procname
= "softlockup_thresh",
860 .data
= &softlockup_thresh
,
861 .maxlen
= sizeof(int),
863 .proc_handler
= &proc_dosoftlockup_thresh
,
864 .strategy
= &sysctl_intvec
,
869 #ifdef CONFIG_DETECT_HUNG_TASK
871 .ctl_name
= CTL_UNNUMBERED
,
872 .procname
= "hung_task_panic",
873 .data
= &sysctl_hung_task_panic
,
874 .maxlen
= sizeof(int),
876 .proc_handler
= &proc_dointvec_minmax
,
877 .strategy
= &sysctl_intvec
,
882 .ctl_name
= CTL_UNNUMBERED
,
883 .procname
= "hung_task_check_count",
884 .data
= &sysctl_hung_task_check_count
,
885 .maxlen
= sizeof(unsigned long),
887 .proc_handler
= &proc_doulongvec_minmax
,
888 .strategy
= &sysctl_intvec
,
891 .ctl_name
= CTL_UNNUMBERED
,
892 .procname
= "hung_task_timeout_secs",
893 .data
= &sysctl_hung_task_timeout_secs
,
894 .maxlen
= sizeof(unsigned long),
896 .proc_handler
= &proc_dohung_task_timeout_secs
,
897 .strategy
= &sysctl_intvec
,
900 .ctl_name
= CTL_UNNUMBERED
,
901 .procname
= "hung_task_warnings",
902 .data
= &sysctl_hung_task_warnings
,
903 .maxlen
= sizeof(unsigned long),
905 .proc_handler
= &proc_doulongvec_minmax
,
906 .strategy
= &sysctl_intvec
,
911 .ctl_name
= KERN_COMPAT_LOG
,
912 .procname
= "compat-log",
914 .maxlen
= sizeof (int),
916 .proc_handler
= &proc_dointvec
,
919 #ifdef CONFIG_RT_MUTEXES
921 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
922 .procname
= "max_lock_depth",
923 .data
= &max_lock_depth
,
924 .maxlen
= sizeof(int),
926 .proc_handler
= &proc_dointvec
,
930 .ctl_name
= CTL_UNNUMBERED
,
931 .procname
= "poweroff_cmd",
932 .data
= &poweroff_cmd
,
933 .maxlen
= POWEROFF_CMD_PATH_LEN
,
935 .proc_handler
= &proc_dostring
,
936 .strategy
= &sysctl_string
,
940 .ctl_name
= CTL_UNNUMBERED
,
943 .child
= key_sysctls
,
946 #ifdef CONFIG_RCU_TORTURE_TEST
948 .ctl_name
= CTL_UNNUMBERED
,
949 .procname
= "rcutorture_runnable",
950 .data
= &rcutorture_runnable
,
951 .maxlen
= sizeof(int),
953 .proc_handler
= &proc_dointvec
,
956 #ifdef CONFIG_SLOW_WORK
958 .ctl_name
= CTL_UNNUMBERED
,
959 .procname
= "slow-work",
961 .child
= slow_work_sysctls
,
964 #ifdef CONFIG_PERF_COUNTERS
966 .ctl_name
= CTL_UNNUMBERED
,
967 .procname
= "perf_counter_paranoid",
968 .data
= &sysctl_perf_counter_paranoid
,
969 .maxlen
= sizeof(sysctl_perf_counter_paranoid
),
971 .proc_handler
= &proc_dointvec
,
974 .ctl_name
= CTL_UNNUMBERED
,
975 .procname
= "perf_counter_mlock_kb",
976 .data
= &sysctl_perf_counter_mlock
,
977 .maxlen
= sizeof(sysctl_perf_counter_mlock
),
979 .proc_handler
= &proc_dointvec
,
982 .ctl_name
= CTL_UNNUMBERED
,
983 .procname
= "perf_counter_max_sample_rate",
984 .data
= &sysctl_perf_counter_sample_rate
,
985 .maxlen
= sizeof(sysctl_perf_counter_sample_rate
),
987 .proc_handler
= &proc_dointvec
,
990 #ifdef CONFIG_KMEMCHECK
992 .ctl_name
= CTL_UNNUMBERED
,
993 .procname
= "kmemcheck",
994 .data
= &kmemcheck_enabled
,
995 .maxlen
= sizeof(int),
997 .proc_handler
= &proc_dointvec
,
1002 * NOTE: do not add new entries to this table unless you have read
1003 * Documentation/sysctl/ctl_unnumbered.txt
1008 static struct ctl_table vm_table
[] = {
1010 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
1011 .procname
= "overcommit_memory",
1012 .data
= &sysctl_overcommit_memory
,
1013 .maxlen
= sizeof(sysctl_overcommit_memory
),
1015 .proc_handler
= &proc_dointvec
,
1018 .ctl_name
= VM_PANIC_ON_OOM
,
1019 .procname
= "panic_on_oom",
1020 .data
= &sysctl_panic_on_oom
,
1021 .maxlen
= sizeof(sysctl_panic_on_oom
),
1023 .proc_handler
= &proc_dointvec
,
1026 .ctl_name
= CTL_UNNUMBERED
,
1027 .procname
= "oom_kill_allocating_task",
1028 .data
= &sysctl_oom_kill_allocating_task
,
1029 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1031 .proc_handler
= &proc_dointvec
,
1034 .ctl_name
= CTL_UNNUMBERED
,
1035 .procname
= "oom_dump_tasks",
1036 .data
= &sysctl_oom_dump_tasks
,
1037 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1039 .proc_handler
= &proc_dointvec
,
1042 .ctl_name
= VM_OVERCOMMIT_RATIO
,
1043 .procname
= "overcommit_ratio",
1044 .data
= &sysctl_overcommit_ratio
,
1045 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1047 .proc_handler
= &proc_dointvec
,
1050 .ctl_name
= VM_PAGE_CLUSTER
,
1051 .procname
= "page-cluster",
1052 .data
= &page_cluster
,
1053 .maxlen
= sizeof(int),
1055 .proc_handler
= &proc_dointvec
,
1058 .ctl_name
= VM_DIRTY_BACKGROUND
,
1059 .procname
= "dirty_background_ratio",
1060 .data
= &dirty_background_ratio
,
1061 .maxlen
= sizeof(dirty_background_ratio
),
1063 .proc_handler
= &dirty_background_ratio_handler
,
1064 .strategy
= &sysctl_intvec
,
1066 .extra2
= &one_hundred
,
1069 .ctl_name
= CTL_UNNUMBERED
,
1070 .procname
= "dirty_background_bytes",
1071 .data
= &dirty_background_bytes
,
1072 .maxlen
= sizeof(dirty_background_bytes
),
1074 .proc_handler
= &dirty_background_bytes_handler
,
1075 .strategy
= &sysctl_intvec
,
1079 .ctl_name
= VM_DIRTY_RATIO
,
1080 .procname
= "dirty_ratio",
1081 .data
= &vm_dirty_ratio
,
1082 .maxlen
= sizeof(vm_dirty_ratio
),
1084 .proc_handler
= &dirty_ratio_handler
,
1085 .strategy
= &sysctl_intvec
,
1087 .extra2
= &one_hundred
,
1090 .ctl_name
= CTL_UNNUMBERED
,
1091 .procname
= "dirty_bytes",
1092 .data
= &vm_dirty_bytes
,
1093 .maxlen
= sizeof(vm_dirty_bytes
),
1095 .proc_handler
= &dirty_bytes_handler
,
1096 .strategy
= &sysctl_intvec
,
1097 .extra1
= &dirty_bytes_min
,
1100 .procname
= "dirty_writeback_centisecs",
1101 .data
= &dirty_writeback_interval
,
1102 .maxlen
= sizeof(dirty_writeback_interval
),
1104 .proc_handler
= &dirty_writeback_centisecs_handler
,
1107 .procname
= "dirty_expire_centisecs",
1108 .data
= &dirty_expire_interval
,
1109 .maxlen
= sizeof(dirty_expire_interval
),
1111 .proc_handler
= &proc_dointvec
,
1114 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
1115 .procname
= "nr_pdflush_threads",
1116 .data
= &nr_pdflush_threads
,
1117 .maxlen
= sizeof nr_pdflush_threads
,
1118 .mode
= 0444 /* read-only*/,
1119 .proc_handler
= &proc_dointvec
,
1122 .ctl_name
= VM_SWAPPINESS
,
1123 .procname
= "swappiness",
1124 .data
= &vm_swappiness
,
1125 .maxlen
= sizeof(vm_swappiness
),
1127 .proc_handler
= &proc_dointvec_minmax
,
1128 .strategy
= &sysctl_intvec
,
1130 .extra2
= &one_hundred
,
1132 #ifdef CONFIG_HUGETLB_PAGE
1134 .procname
= "nr_hugepages",
1136 .maxlen
= sizeof(unsigned long),
1138 .proc_handler
= &hugetlb_sysctl_handler
,
1139 .extra1
= (void *)&hugetlb_zero
,
1140 .extra2
= (void *)&hugetlb_infinity
,
1143 .ctl_name
= VM_HUGETLB_GROUP
,
1144 .procname
= "hugetlb_shm_group",
1145 .data
= &sysctl_hugetlb_shm_group
,
1146 .maxlen
= sizeof(gid_t
),
1148 .proc_handler
= &proc_dointvec
,
1151 .ctl_name
= CTL_UNNUMBERED
,
1152 .procname
= "hugepages_treat_as_movable",
1153 .data
= &hugepages_treat_as_movable
,
1154 .maxlen
= sizeof(int),
1156 .proc_handler
= &hugetlb_treat_movable_handler
,
1159 .ctl_name
= CTL_UNNUMBERED
,
1160 .procname
= "nr_overcommit_hugepages",
1162 .maxlen
= sizeof(unsigned long),
1164 .proc_handler
= &hugetlb_overcommit_handler
,
1165 .extra1
= (void *)&hugetlb_zero
,
1166 .extra2
= (void *)&hugetlb_infinity
,
1170 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
1171 .procname
= "lowmem_reserve_ratio",
1172 .data
= &sysctl_lowmem_reserve_ratio
,
1173 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1175 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
1176 .strategy
= &sysctl_intvec
,
1179 .ctl_name
= VM_DROP_PAGECACHE
,
1180 .procname
= "drop_caches",
1181 .data
= &sysctl_drop_caches
,
1182 .maxlen
= sizeof(int),
1184 .proc_handler
= drop_caches_sysctl_handler
,
1185 .strategy
= &sysctl_intvec
,
1188 .ctl_name
= VM_MIN_FREE_KBYTES
,
1189 .procname
= "min_free_kbytes",
1190 .data
= &min_free_kbytes
,
1191 .maxlen
= sizeof(min_free_kbytes
),
1193 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1194 .strategy
= &sysctl_intvec
,
1198 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1199 .procname
= "percpu_pagelist_fraction",
1200 .data
= &percpu_pagelist_fraction
,
1201 .maxlen
= sizeof(percpu_pagelist_fraction
),
1203 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1204 .strategy
= &sysctl_intvec
,
1205 .extra1
= &min_percpu_pagelist_fract
,
1209 .ctl_name
= VM_MAX_MAP_COUNT
,
1210 .procname
= "max_map_count",
1211 .data
= &sysctl_max_map_count
,
1212 .maxlen
= sizeof(sysctl_max_map_count
),
1214 .proc_handler
= &proc_dointvec
1218 .ctl_name
= CTL_UNNUMBERED
,
1219 .procname
= "nr_trim_pages",
1220 .data
= &sysctl_nr_trim_pages
,
1221 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1223 .proc_handler
= &proc_dointvec_minmax
,
1224 .strategy
= &sysctl_intvec
,
1229 .ctl_name
= VM_LAPTOP_MODE
,
1230 .procname
= "laptop_mode",
1231 .data
= &laptop_mode
,
1232 .maxlen
= sizeof(laptop_mode
),
1234 .proc_handler
= &proc_dointvec_jiffies
,
1235 .strategy
= &sysctl_jiffies
,
1238 .ctl_name
= VM_BLOCK_DUMP
,
1239 .procname
= "block_dump",
1240 .data
= &block_dump
,
1241 .maxlen
= sizeof(block_dump
),
1243 .proc_handler
= &proc_dointvec
,
1244 .strategy
= &sysctl_intvec
,
1248 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1249 .procname
= "vfs_cache_pressure",
1250 .data
= &sysctl_vfs_cache_pressure
,
1251 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1253 .proc_handler
= &proc_dointvec
,
1254 .strategy
= &sysctl_intvec
,
1257 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1259 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1260 .procname
= "legacy_va_layout",
1261 .data
= &sysctl_legacy_va_layout
,
1262 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1264 .proc_handler
= &proc_dointvec
,
1265 .strategy
= &sysctl_intvec
,
1271 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1272 .procname
= "zone_reclaim_mode",
1273 .data
= &zone_reclaim_mode
,
1274 .maxlen
= sizeof(zone_reclaim_mode
),
1276 .proc_handler
= &proc_dointvec
,
1277 .strategy
= &sysctl_intvec
,
1281 .ctl_name
= VM_MIN_UNMAPPED
,
1282 .procname
= "min_unmapped_ratio",
1283 .data
= &sysctl_min_unmapped_ratio
,
1284 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1286 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1287 .strategy
= &sysctl_intvec
,
1289 .extra2
= &one_hundred
,
1292 .ctl_name
= VM_MIN_SLAB
,
1293 .procname
= "min_slab_ratio",
1294 .data
= &sysctl_min_slab_ratio
,
1295 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1297 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1298 .strategy
= &sysctl_intvec
,
1300 .extra2
= &one_hundred
,
1305 .ctl_name
= CTL_UNNUMBERED
,
1306 .procname
= "stat_interval",
1307 .data
= &sysctl_stat_interval
,
1308 .maxlen
= sizeof(sysctl_stat_interval
),
1310 .proc_handler
= &proc_dointvec_jiffies
,
1311 .strategy
= &sysctl_jiffies
,
1315 .ctl_name
= CTL_UNNUMBERED
,
1316 .procname
= "mmap_min_addr",
1317 .data
= &dac_mmap_min_addr
,
1318 .maxlen
= sizeof(unsigned long),
1320 .proc_handler
= &mmap_min_addr_handler
,
1324 .ctl_name
= CTL_UNNUMBERED
,
1325 .procname
= "numa_zonelist_order",
1326 .data
= &numa_zonelist_order
,
1327 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1329 .proc_handler
= &numa_zonelist_order_handler
,
1330 .strategy
= &sysctl_string
,
1333 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1334 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1336 .ctl_name
= VM_VDSO_ENABLED
,
1337 .procname
= "vdso_enabled",
1338 .data
= &vdso_enabled
,
1339 .maxlen
= sizeof(vdso_enabled
),
1341 .proc_handler
= &proc_dointvec
,
1342 .strategy
= &sysctl_intvec
,
1346 #ifdef CONFIG_HIGHMEM
1348 .ctl_name
= CTL_UNNUMBERED
,
1349 .procname
= "highmem_is_dirtyable",
1350 .data
= &vm_highmem_is_dirtyable
,
1351 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1353 .proc_handler
= &proc_dointvec_minmax
,
1354 .strategy
= &sysctl_intvec
,
1360 .ctl_name
= CTL_UNNUMBERED
,
1361 .procname
= "scan_unevictable_pages",
1362 .data
= &scan_unevictable_pages
,
1363 .maxlen
= sizeof(scan_unevictable_pages
),
1365 .proc_handler
= &scan_unevictable_handler
,
1368 * NOTE: do not add new entries to this table unless you have read
1369 * Documentation/sysctl/ctl_unnumbered.txt
1374 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1375 static struct ctl_table binfmt_misc_table
[] = {
1380 static struct ctl_table fs_table
[] = {
1382 .ctl_name
= FS_NRINODE
,
1383 .procname
= "inode-nr",
1384 .data
= &inodes_stat
,
1385 .maxlen
= 2*sizeof(int),
1387 .proc_handler
= &proc_dointvec
,
1390 .ctl_name
= FS_STATINODE
,
1391 .procname
= "inode-state",
1392 .data
= &inodes_stat
,
1393 .maxlen
= 7*sizeof(int),
1395 .proc_handler
= &proc_dointvec
,
1398 .procname
= "file-nr",
1399 .data
= &files_stat
,
1400 .maxlen
= 3*sizeof(int),
1402 .proc_handler
= &proc_nr_files
,
1405 .ctl_name
= FS_MAXFILE
,
1406 .procname
= "file-max",
1407 .data
= &files_stat
.max_files
,
1408 .maxlen
= sizeof(int),
1410 .proc_handler
= &proc_dointvec
,
1413 .ctl_name
= CTL_UNNUMBERED
,
1414 .procname
= "nr_open",
1415 .data
= &sysctl_nr_open
,
1416 .maxlen
= sizeof(int),
1418 .proc_handler
= &proc_dointvec_minmax
,
1419 .extra1
= &sysctl_nr_open_min
,
1420 .extra2
= &sysctl_nr_open_max
,
1423 .ctl_name
= FS_DENTRY
,
1424 .procname
= "dentry-state",
1425 .data
= &dentry_stat
,
1426 .maxlen
= 6*sizeof(int),
1428 .proc_handler
= &proc_dointvec
,
1431 .ctl_name
= FS_OVERFLOWUID
,
1432 .procname
= "overflowuid",
1433 .data
= &fs_overflowuid
,
1434 .maxlen
= sizeof(int),
1436 .proc_handler
= &proc_dointvec_minmax
,
1437 .strategy
= &sysctl_intvec
,
1438 .extra1
= &minolduid
,
1439 .extra2
= &maxolduid
,
1442 .ctl_name
= FS_OVERFLOWGID
,
1443 .procname
= "overflowgid",
1444 .data
= &fs_overflowgid
,
1445 .maxlen
= sizeof(int),
1447 .proc_handler
= &proc_dointvec_minmax
,
1448 .strategy
= &sysctl_intvec
,
1449 .extra1
= &minolduid
,
1450 .extra2
= &maxolduid
,
1452 #ifdef CONFIG_FILE_LOCKING
1454 .ctl_name
= FS_LEASES
,
1455 .procname
= "leases-enable",
1456 .data
= &leases_enable
,
1457 .maxlen
= sizeof(int),
1459 .proc_handler
= &proc_dointvec
,
1462 #ifdef CONFIG_DNOTIFY
1464 .ctl_name
= FS_DIR_NOTIFY
,
1465 .procname
= "dir-notify-enable",
1466 .data
= &dir_notify_enable
,
1467 .maxlen
= sizeof(int),
1469 .proc_handler
= &proc_dointvec
,
1473 #ifdef CONFIG_FILE_LOCKING
1475 .ctl_name
= FS_LEASE_TIME
,
1476 .procname
= "lease-break-time",
1477 .data
= &lease_break_time
,
1478 .maxlen
= sizeof(int),
1480 .proc_handler
= &proc_dointvec
,
1485 .procname
= "aio-nr",
1487 .maxlen
= sizeof(aio_nr
),
1489 .proc_handler
= &proc_doulongvec_minmax
,
1492 .procname
= "aio-max-nr",
1493 .data
= &aio_max_nr
,
1494 .maxlen
= sizeof(aio_max_nr
),
1496 .proc_handler
= &proc_doulongvec_minmax
,
1498 #endif /* CONFIG_AIO */
1499 #ifdef CONFIG_INOTIFY_USER
1501 .ctl_name
= FS_INOTIFY
,
1502 .procname
= "inotify",
1504 .child
= inotify_table
,
1509 .procname
= "epoll",
1511 .child
= epoll_table
,
1516 .ctl_name
= KERN_SETUID_DUMPABLE
,
1517 .procname
= "suid_dumpable",
1518 .data
= &suid_dumpable
,
1519 .maxlen
= sizeof(int),
1521 .proc_handler
= &proc_dointvec_minmax
,
1522 .strategy
= &sysctl_intvec
,
1526 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1528 .ctl_name
= CTL_UNNUMBERED
,
1529 .procname
= "binfmt_misc",
1531 .child
= binfmt_misc_table
,
1535 * NOTE: do not add new entries to this table unless you have read
1536 * Documentation/sysctl/ctl_unnumbered.txt
1541 static struct ctl_table debug_table
[] = {
1542 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1544 .ctl_name
= CTL_UNNUMBERED
,
1545 .procname
= "exception-trace",
1546 .data
= &show_unhandled_signals
,
1547 .maxlen
= sizeof(int),
1549 .proc_handler
= proc_dointvec
1555 static struct ctl_table dev_table
[] = {
1559 static DEFINE_SPINLOCK(sysctl_lock
);
1561 /* called under sysctl_lock */
1562 static int use_table(struct ctl_table_header
*p
)
1564 if (unlikely(p
->unregistering
))
1570 /* called under sysctl_lock */
1571 static void unuse_table(struct ctl_table_header
*p
)
1574 if (unlikely(p
->unregistering
))
1575 complete(p
->unregistering
);
1578 /* called under sysctl_lock, will reacquire if has to wait */
1579 static void start_unregistering(struct ctl_table_header
*p
)
1582 * if p->used is 0, nobody will ever touch that entry again;
1583 * we'll eliminate all paths to it before dropping sysctl_lock
1585 if (unlikely(p
->used
)) {
1586 struct completion wait
;
1587 init_completion(&wait
);
1588 p
->unregistering
= &wait
;
1589 spin_unlock(&sysctl_lock
);
1590 wait_for_completion(&wait
);
1591 spin_lock(&sysctl_lock
);
1593 /* anything non-NULL; we'll never dereference it */
1594 p
->unregistering
= ERR_PTR(-EINVAL
);
1597 * do not remove from the list until nobody holds it; walking the
1598 * list in do_sysctl() relies on that.
1600 list_del_init(&p
->ctl_entry
);
1603 void sysctl_head_get(struct ctl_table_header
*head
)
1605 spin_lock(&sysctl_lock
);
1607 spin_unlock(&sysctl_lock
);
1610 void sysctl_head_put(struct ctl_table_header
*head
)
1612 spin_lock(&sysctl_lock
);
1615 spin_unlock(&sysctl_lock
);
1618 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1622 spin_lock(&sysctl_lock
);
1623 if (!use_table(head
))
1624 head
= ERR_PTR(-ENOENT
);
1625 spin_unlock(&sysctl_lock
);
1629 void sysctl_head_finish(struct ctl_table_header
*head
)
1633 spin_lock(&sysctl_lock
);
1635 spin_unlock(&sysctl_lock
);
1638 static struct ctl_table_set
*
1639 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1641 struct ctl_table_set
*set
= &root
->default_set
;
1643 set
= root
->lookup(root
, namespaces
);
1647 static struct list_head
*
1648 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1650 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1654 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1655 struct ctl_table_header
*prev
)
1657 struct ctl_table_root
*root
;
1658 struct list_head
*header_list
;
1659 struct ctl_table_header
*head
;
1660 struct list_head
*tmp
;
1662 spin_lock(&sysctl_lock
);
1665 tmp
= &prev
->ctl_entry
;
1669 tmp
= &root_table_header
.ctl_entry
;
1671 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1673 if (!use_table(head
))
1675 spin_unlock(&sysctl_lock
);
1680 header_list
= lookup_header_list(root
, namespaces
);
1681 if (tmp
!= header_list
)
1685 root
= list_entry(root
->root_list
.next
,
1686 struct ctl_table_root
, root_list
);
1687 if (root
== &sysctl_table_root
)
1689 header_list
= lookup_header_list(root
, namespaces
);
1690 } while (list_empty(header_list
));
1691 tmp
= header_list
->next
;
1694 spin_unlock(&sysctl_lock
);
1698 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1700 return __sysctl_head_next(current
->nsproxy
, prev
);
1703 void register_sysctl_root(struct ctl_table_root
*root
)
1705 spin_lock(&sysctl_lock
);
1706 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1707 spin_unlock(&sysctl_lock
);
1710 #ifdef CONFIG_SYSCTL_SYSCALL
1711 /* Perform the actual read/write of a sysctl table entry. */
1712 static int do_sysctl_strategy(struct ctl_table_root
*root
,
1713 struct ctl_table
*table
,
1714 void __user
*oldval
, size_t __user
*oldlenp
,
1715 void __user
*newval
, size_t newlen
)
1723 if (sysctl_perm(root
, table
, op
))
1726 if (table
->strategy
) {
1727 rc
= table
->strategy(table
, oldval
, oldlenp
, newval
, newlen
);
1734 /* If there is no strategy routine, or if the strategy returns
1735 * zero, proceed with automatic r/w */
1736 if (table
->data
&& table
->maxlen
) {
1737 rc
= sysctl_data(table
, oldval
, oldlenp
, newval
, newlen
);
1744 static int parse_table(int __user
*name
, int nlen
,
1745 void __user
*oldval
, size_t __user
*oldlenp
,
1746 void __user
*newval
, size_t newlen
,
1747 struct ctl_table_root
*root
,
1748 struct ctl_table
*table
)
1754 if (get_user(n
, name
))
1756 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1757 if (!table
->ctl_name
)
1759 if (n
== table
->ctl_name
) {
1762 if (sysctl_perm(root
, table
, MAY_EXEC
))
1766 table
= table
->child
;
1769 error
= do_sysctl_strategy(root
, table
,
1778 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1779 void __user
*newval
, size_t newlen
)
1781 struct ctl_table_header
*head
;
1782 int error
= -ENOTDIR
;
1784 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1788 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1792 for (head
= sysctl_head_next(NULL
); head
;
1793 head
= sysctl_head_next(head
)) {
1794 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1796 head
->root
, head
->ctl_table
);
1797 if (error
!= -ENOTDIR
) {
1798 sysctl_head_finish(head
);
1805 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
1807 struct __sysctl_args tmp
;
1810 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1813 error
= deprecated_sysctl_warning(&tmp
);
1818 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1819 tmp
.newval
, tmp
.newlen
);
1824 #endif /* CONFIG_SYSCTL_SYSCALL */
1827 * sysctl_perm does NOT grant the superuser all rights automatically, because
1828 * some sysctl variables are readonly even to root.
1831 static int test_perm(int mode
, int op
)
1833 if (!current_euid())
1835 else if (in_egroup_p(0))
1837 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1842 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1847 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1851 if (root
->permissions
)
1852 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1856 return test_perm(mode
, op
);
1859 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1861 for (; table
->ctl_name
|| table
->procname
; table
++) {
1862 table
->parent
= parent
;
1864 sysctl_set_parent(table
, table
->child
);
1868 static __init
int sysctl_init(void)
1870 sysctl_set_parent(NULL
, root_table
);
1871 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1874 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1880 core_initcall(sysctl_init
);
1882 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1883 struct ctl_table
*table
)
1885 struct ctl_table
*p
;
1886 const char *s
= branch
->procname
;
1888 /* branch should have named subdirectory as its first element */
1889 if (!s
|| !branch
->child
)
1892 /* ... and nothing else */
1893 if (branch
[1].procname
|| branch
[1].ctl_name
)
1896 /* table should contain subdirectory with the same name */
1897 for (p
= table
; p
->procname
|| p
->ctl_name
; p
++) {
1900 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1906 /* see if attaching q to p would be an improvement */
1907 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1909 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1910 struct ctl_table
*next
;
1912 int not_in_parent
= !p
->attached_by
;
1914 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1915 if (by
== q
->attached_by
)
1917 if (to
== p
->attached_by
)
1923 if (is_better
&& not_in_parent
) {
1924 q
->attached_by
= by
;
1925 q
->attached_to
= to
;
1931 * __register_sysctl_paths - register a sysctl hierarchy
1932 * @root: List of sysctl headers to register on
1933 * @namespaces: Data to compute which lists of sysctl entries are visible
1934 * @path: The path to the directory the sysctl table is in.
1935 * @table: the top-level table structure
1937 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1938 * array. A completely 0 filled entry terminates the table.
1940 * The members of the &struct ctl_table structure are used as follows:
1942 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1943 * must be unique within that level of sysctl
1945 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1946 * enter a sysctl file
1948 * data - a pointer to data for use by proc_handler
1950 * maxlen - the maximum size in bytes of the data
1952 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1954 * child - a pointer to the child sysctl table if this entry is a directory, or
1957 * proc_handler - the text handler routine (described below)
1959 * strategy - the strategy routine (described below)
1961 * de - for internal use by the sysctl routines
1963 * extra1, extra2 - extra pointers usable by the proc handler routines
1965 * Leaf nodes in the sysctl tree will be represented by a single file
1966 * under /proc; non-leaf nodes will be represented by directories.
1968 * sysctl(2) can automatically manage read and write requests through
1969 * the sysctl table. The data and maxlen fields of the ctl_table
1970 * struct enable minimal validation of the values being written to be
1971 * performed, and the mode field allows minimal authentication.
1973 * More sophisticated management can be enabled by the provision of a
1974 * strategy routine with the table entry. This will be called before
1975 * any automatic read or write of the data is performed.
1977 * The strategy routine may return
1979 * < 0 - Error occurred (error is passed to user process)
1981 * 0 - OK - proceed with automatic read or write.
1983 * > 0 - OK - read or write has been done by the strategy routine, so
1984 * return immediately.
1986 * There must be a proc_handler routine for any terminal nodes
1987 * mirrored under /proc/sys (non-terminals are handled by a built-in
1988 * directory handler). Several default handlers are available to
1989 * cover common cases -
1991 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1992 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1993 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1995 * It is the handler's job to read the input buffer from user memory
1996 * and process it. The handler should return 0 on success.
1998 * This routine returns %NULL on a failure to register, and a pointer
1999 * to the table header on success.
2001 struct ctl_table_header
*__register_sysctl_paths(
2002 struct ctl_table_root
*root
,
2003 struct nsproxy
*namespaces
,
2004 const struct ctl_path
*path
, struct ctl_table
*table
)
2006 struct ctl_table_header
*header
;
2007 struct ctl_table
*new, **prevp
;
2008 unsigned int n
, npath
;
2009 struct ctl_table_set
*set
;
2011 /* Count the path components */
2012 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
2016 * For each path component, allocate a 2-element ctl_table array.
2017 * The first array element will be filled with the sysctl entry
2018 * for this, the second will be the sentinel (ctl_name == 0).
2020 * We allocate everything in one go so that we don't have to
2021 * worry about freeing additional memory in unregister_sysctl_table.
2023 header
= kzalloc(sizeof(struct ctl_table_header
) +
2024 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
2028 new = (struct ctl_table
*) (header
+ 1);
2030 /* Now connect the dots */
2031 prevp
= &header
->ctl_table
;
2032 for (n
= 0; n
< npath
; ++n
, ++path
) {
2033 /* Copy the procname */
2034 new->procname
= path
->procname
;
2035 new->ctl_name
= path
->ctl_name
;
2039 prevp
= &new->child
;
2044 header
->ctl_table_arg
= table
;
2046 INIT_LIST_HEAD(&header
->ctl_entry
);
2048 header
->unregistering
= NULL
;
2049 header
->root
= root
;
2050 sysctl_set_parent(NULL
, header
->ctl_table
);
2052 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
2053 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
2058 spin_lock(&sysctl_lock
);
2059 header
->set
= lookup_header_set(root
, namespaces
);
2060 header
->attached_by
= header
->ctl_table
;
2061 header
->attached_to
= root_table
;
2062 header
->parent
= &root_table_header
;
2063 for (set
= header
->set
; set
; set
= set
->parent
) {
2064 struct ctl_table_header
*p
;
2065 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
2066 if (p
->unregistering
)
2068 try_attach(p
, header
);
2071 header
->parent
->count
++;
2072 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
2073 spin_unlock(&sysctl_lock
);
2079 * register_sysctl_table_path - register a sysctl table hierarchy
2080 * @path: The path to the directory the sysctl table is in.
2081 * @table: the top-level table structure
2083 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2084 * array. A completely 0 filled entry terminates the table.
2086 * See __register_sysctl_paths for more details.
2088 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2089 struct ctl_table
*table
)
2091 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
2096 * register_sysctl_table - register a sysctl table hierarchy
2097 * @table: the top-level table structure
2099 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2100 * array. A completely 0 filled entry terminates the table.
2102 * See register_sysctl_paths for more details.
2104 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
2106 static const struct ctl_path null_path
[] = { {} };
2108 return register_sysctl_paths(null_path
, table
);
2112 * unregister_sysctl_table - unregister a sysctl table hierarchy
2113 * @header: the header returned from register_sysctl_table
2115 * Unregisters the sysctl table and all children. proc entries may not
2116 * actually be removed until they are no longer used by anyone.
2118 void unregister_sysctl_table(struct ctl_table_header
* header
)
2125 spin_lock(&sysctl_lock
);
2126 start_unregistering(header
);
2127 if (!--header
->parent
->count
) {
2129 kfree(header
->parent
);
2131 if (!--header
->count
)
2133 spin_unlock(&sysctl_lock
);
2136 int sysctl_is_seen(struct ctl_table_header
*p
)
2138 struct ctl_table_set
*set
= p
->set
;
2140 spin_lock(&sysctl_lock
);
2141 if (p
->unregistering
)
2143 else if (!set
->is_seen
)
2146 res
= set
->is_seen(set
);
2147 spin_unlock(&sysctl_lock
);
2151 void setup_sysctl_set(struct ctl_table_set
*p
,
2152 struct ctl_table_set
*parent
,
2153 int (*is_seen
)(struct ctl_table_set
*))
2155 INIT_LIST_HEAD(&p
->list
);
2156 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
2157 p
->is_seen
= is_seen
;
2160 #else /* !CONFIG_SYSCTL */
2161 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
2166 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2167 struct ctl_table
*table
)
2172 void unregister_sysctl_table(struct ctl_table_header
* table
)
2176 void setup_sysctl_set(struct ctl_table_set
*p
,
2177 struct ctl_table_set
*parent
,
2178 int (*is_seen
)(struct ctl_table_set
*))
2182 void sysctl_head_put(struct ctl_table_header
*head
)
2186 #endif /* CONFIG_SYSCTL */
2192 #ifdef CONFIG_PROC_SYSCTL
2194 static int _proc_do_string(void* data
, int maxlen
, int write
,
2195 struct file
*filp
, void __user
*buffer
,
2196 size_t *lenp
, loff_t
*ppos
)
2202 if (!data
|| !maxlen
|| !*lenp
) {
2210 while (len
< *lenp
) {
2211 if (get_user(c
, p
++))
2213 if (c
== 0 || c
== '\n')
2219 if(copy_from_user(data
, buffer
, len
))
2221 ((char *) data
)[len
] = 0;
2239 if(copy_to_user(buffer
, data
, len
))
2242 if(put_user('\n', ((char __user
*) buffer
) + len
))
2253 * proc_dostring - read a string sysctl
2254 * @table: the sysctl table
2255 * @write: %TRUE if this is a write to the sysctl file
2256 * @filp: the file structure
2257 * @buffer: the user buffer
2258 * @lenp: the size of the user buffer
2259 * @ppos: file position
2261 * Reads/writes a string from/to the user buffer. If the kernel
2262 * buffer provided is not large enough to hold the string, the
2263 * string is truncated. The copied string is %NULL-terminated.
2264 * If the string is being read by the user process, it is copied
2265 * and a newline '\n' is added. It is truncated if the buffer is
2268 * Returns 0 on success.
2270 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2271 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2273 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
2274 buffer
, lenp
, ppos
);
2278 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
2280 int write
, void *data
)
2283 *valp
= *negp
? -*lvalp
: *lvalp
;
2288 *lvalp
= (unsigned long)-val
;
2291 *lvalp
= (unsigned long)val
;
2297 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2298 int write
, struct file
*filp
, void __user
*buffer
,
2299 size_t *lenp
, loff_t
*ppos
,
2300 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2301 int write
, void *data
),
2304 #define TMPBUFLEN 21
2305 int *i
, vleft
, first
= 1, neg
;
2309 char buf
[TMPBUFLEN
], *p
;
2310 char __user
*s
= buffer
;
2312 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
2313 (*ppos
&& !write
)) {
2318 i
= (int *) tbl_data
;
2319 vleft
= table
->maxlen
/ sizeof(*i
);
2323 conv
= do_proc_dointvec_conv
;
2325 for (; left
&& vleft
--; i
++, first
=0) {
2340 if (len
> sizeof(buf
) - 1)
2341 len
= sizeof(buf
) - 1;
2342 if (copy_from_user(buf
, s
, len
))
2346 if (*p
== '-' && left
> 1) {
2350 if (*p
< '0' || *p
> '9')
2353 lval
= simple_strtoul(p
, &p
, 0);
2356 if ((len
< left
) && *p
&& !isspace(*p
))
2361 if (conv(&neg
, &lval
, i
, 1, data
))
2368 if (conv(&neg
, &lval
, i
, 0, data
))
2371 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2375 if(copy_to_user(s
, buf
, len
))
2382 if (!write
&& !first
&& left
) {
2383 if(put_user('\n', s
))
2390 if (get_user(c
, s
++))
2405 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2406 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2407 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2408 int write
, void *data
),
2411 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2412 buffer
, lenp
, ppos
, conv
, data
);
2416 * proc_dointvec - read a vector of integers
2417 * @table: the sysctl table
2418 * @write: %TRUE if this is a write to the sysctl file
2419 * @filp: the file structure
2420 * @buffer: the user buffer
2421 * @lenp: the size of the user buffer
2422 * @ppos: file position
2424 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2425 * values from/to the user buffer, treated as an ASCII string.
2427 * Returns 0 on success.
2429 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2430 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2432 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2437 * Taint values can only be increased
2438 * This means we can safely use a temporary.
2440 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2441 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2444 unsigned long tmptaint
= get_taint();
2447 if (write
&& !capable(CAP_SYS_ADMIN
))
2452 err
= proc_doulongvec_minmax(&t
, write
, filp
, buffer
, lenp
, ppos
);
2458 * Poor man's atomic or. Not worth adding a primitive
2459 * to everyone's atomic.h for this
2462 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2463 if ((tmptaint
>> i
) & 1)
2471 struct do_proc_dointvec_minmax_conv_param
{
2476 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2478 int write
, void *data
)
2480 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2482 int val
= *negp
? -*lvalp
: *lvalp
;
2483 if ((param
->min
&& *param
->min
> val
) ||
2484 (param
->max
&& *param
->max
< val
))
2491 *lvalp
= (unsigned long)-val
;
2494 *lvalp
= (unsigned long)val
;
2501 * proc_dointvec_minmax - read a vector of integers with min/max values
2502 * @table: the sysctl table
2503 * @write: %TRUE if this is a write to the sysctl file
2504 * @filp: the file structure
2505 * @buffer: the user buffer
2506 * @lenp: the size of the user buffer
2507 * @ppos: file position
2509 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2510 * values from/to the user buffer, treated as an ASCII string.
2512 * This routine will ensure the values are within the range specified by
2513 * table->extra1 (min) and table->extra2 (max).
2515 * Returns 0 on success.
2517 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2518 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2520 struct do_proc_dointvec_minmax_conv_param param
= {
2521 .min
= (int *) table
->extra1
,
2522 .max
= (int *) table
->extra2
,
2524 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2525 do_proc_dointvec_minmax_conv
, ¶m
);
2528 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2530 void __user
*buffer
,
2531 size_t *lenp
, loff_t
*ppos
,
2532 unsigned long convmul
,
2533 unsigned long convdiv
)
2535 #define TMPBUFLEN 21
2536 unsigned long *i
, *min
, *max
, val
;
2537 int vleft
, first
=1, neg
;
2539 char buf
[TMPBUFLEN
], *p
;
2540 char __user
*s
= buffer
;
2542 if (!data
|| !table
->maxlen
|| !*lenp
||
2543 (*ppos
&& !write
)) {
2548 i
= (unsigned long *) data
;
2549 min
= (unsigned long *) table
->extra1
;
2550 max
= (unsigned long *) table
->extra2
;
2551 vleft
= table
->maxlen
/ sizeof(unsigned long);
2554 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2569 if (len
> TMPBUFLEN
-1)
2571 if (copy_from_user(buf
, s
, len
))
2575 if (*p
== '-' && left
> 1) {
2579 if (*p
< '0' || *p
> '9')
2581 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2583 if ((len
< left
) && *p
&& !isspace(*p
))
2592 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2599 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2603 if(copy_to_user(s
, buf
, len
))
2610 if (!write
&& !first
&& left
) {
2611 if(put_user('\n', s
))
2618 if (get_user(c
, s
++))
2633 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2635 void __user
*buffer
,
2636 size_t *lenp
, loff_t
*ppos
,
2637 unsigned long convmul
,
2638 unsigned long convdiv
)
2640 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2641 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2645 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2646 * @table: the sysctl table
2647 * @write: %TRUE if this is a write to the sysctl file
2648 * @filp: the file structure
2649 * @buffer: the user buffer
2650 * @lenp: the size of the user buffer
2651 * @ppos: file position
2653 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2654 * values from/to the user buffer, treated as an ASCII string.
2656 * This routine will ensure the values are within the range specified by
2657 * table->extra1 (min) and table->extra2 (max).
2659 * Returns 0 on success.
2661 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2662 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2664 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2668 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2669 * @table: the sysctl table
2670 * @write: %TRUE if this is a write to the sysctl file
2671 * @filp: the file structure
2672 * @buffer: the user buffer
2673 * @lenp: the size of the user buffer
2674 * @ppos: file position
2676 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2677 * values from/to the user buffer, treated as an ASCII string. The values
2678 * are treated as milliseconds, and converted to jiffies when they are stored.
2680 * This routine will ensure the values are within the range specified by
2681 * table->extra1 (min) and table->extra2 (max).
2683 * Returns 0 on success.
2685 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2687 void __user
*buffer
,
2688 size_t *lenp
, loff_t
*ppos
)
2690 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2691 lenp
, ppos
, HZ
, 1000l);
2695 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2697 int write
, void *data
)
2700 if (*lvalp
> LONG_MAX
/ HZ
)
2702 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2708 lval
= (unsigned long)-val
;
2711 lval
= (unsigned long)val
;
2718 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2720 int write
, void *data
)
2723 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2725 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2731 lval
= (unsigned long)-val
;
2734 lval
= (unsigned long)val
;
2736 *lvalp
= jiffies_to_clock_t(lval
);
2741 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2743 int write
, void *data
)
2746 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2752 lval
= (unsigned long)-val
;
2755 lval
= (unsigned long)val
;
2757 *lvalp
= jiffies_to_msecs(lval
);
2763 * proc_dointvec_jiffies - read a vector of integers as seconds
2764 * @table: the sysctl table
2765 * @write: %TRUE if this is a write to the sysctl file
2766 * @filp: the file structure
2767 * @buffer: the user buffer
2768 * @lenp: the size of the user buffer
2769 * @ppos: file position
2771 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2772 * values from/to the user buffer, treated as an ASCII string.
2773 * The values read are assumed to be in seconds, and are converted into
2776 * Returns 0 on success.
2778 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2779 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2781 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2782 do_proc_dointvec_jiffies_conv
,NULL
);
2786 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2787 * @table: the sysctl table
2788 * @write: %TRUE if this is a write to the sysctl file
2789 * @filp: the file structure
2790 * @buffer: the user buffer
2791 * @lenp: the size of the user buffer
2792 * @ppos: pointer to the file position
2794 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2795 * values from/to the user buffer, treated as an ASCII string.
2796 * The values read are assumed to be in 1/USER_HZ seconds, and
2797 * are converted into jiffies.
2799 * Returns 0 on success.
2801 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2802 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2804 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2805 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2809 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2810 * @table: the sysctl table
2811 * @write: %TRUE if this is a write to the sysctl file
2812 * @filp: the file structure
2813 * @buffer: the user buffer
2814 * @lenp: the size of the user buffer
2815 * @ppos: file position
2816 * @ppos: the current position in the file
2818 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2819 * values from/to the user buffer, treated as an ASCII string.
2820 * The values read are assumed to be in 1/1000 seconds, and
2821 * are converted into jiffies.
2823 * Returns 0 on success.
2825 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2826 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2828 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2829 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2832 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2833 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2835 struct pid
*new_pid
;
2839 tmp
= pid_vnr(cad_pid
);
2841 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2842 lenp
, ppos
, NULL
, NULL
);
2846 new_pid
= find_get_pid(tmp
);
2850 put_pid(xchg(&cad_pid
, new_pid
));
2854 #else /* CONFIG_PROC_FS */
2856 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2857 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2862 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2863 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2868 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2869 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2874 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2875 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2880 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2881 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2886 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2887 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2892 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2893 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2898 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2900 void __user
*buffer
,
2901 size_t *lenp
, loff_t
*ppos
)
2907 #endif /* CONFIG_PROC_FS */
2910 #ifdef CONFIG_SYSCTL_SYSCALL
2912 * General sysctl support routines
2915 /* The generic sysctl data routine (used if no strategy routine supplied) */
2916 int sysctl_data(struct ctl_table
*table
,
2917 void __user
*oldval
, size_t __user
*oldlenp
,
2918 void __user
*newval
, size_t newlen
)
2922 /* Get out of I don't have a variable */
2923 if (!table
->data
|| !table
->maxlen
)
2926 if (oldval
&& oldlenp
) {
2927 if (get_user(len
, oldlenp
))
2930 if (len
> table
->maxlen
)
2931 len
= table
->maxlen
;
2932 if (copy_to_user(oldval
, table
->data
, len
))
2934 if (put_user(len
, oldlenp
))
2939 if (newval
&& newlen
) {
2940 if (newlen
> table
->maxlen
)
2941 newlen
= table
->maxlen
;
2943 if (copy_from_user(table
->data
, newval
, newlen
))
2949 /* The generic string strategy routine: */
2950 int sysctl_string(struct ctl_table
*table
,
2951 void __user
*oldval
, size_t __user
*oldlenp
,
2952 void __user
*newval
, size_t newlen
)
2954 if (!table
->data
|| !table
->maxlen
)
2957 if (oldval
&& oldlenp
) {
2959 if (get_user(bufsize
, oldlenp
))
2962 size_t len
= strlen(table
->data
), copied
;
2964 /* This shouldn't trigger for a well-formed sysctl */
2965 if (len
> table
->maxlen
)
2966 len
= table
->maxlen
;
2968 /* Copy up to a max of bufsize-1 bytes of the string */
2969 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2971 if (copy_to_user(oldval
, table
->data
, copied
) ||
2972 put_user(0, (char __user
*)(oldval
+ copied
)))
2974 if (put_user(len
, oldlenp
))
2978 if (newval
&& newlen
) {
2979 size_t len
= newlen
;
2980 if (len
> table
->maxlen
)
2981 len
= table
->maxlen
;
2982 if(copy_from_user(table
->data
, newval
, len
))
2984 if (len
== table
->maxlen
)
2986 ((char *) table
->data
)[len
] = 0;
2992 * This function makes sure that all of the integers in the vector
2993 * are between the minimum and maximum values given in the arrays
2994 * table->extra1 and table->extra2, respectively.
2996 int sysctl_intvec(struct ctl_table
*table
,
2997 void __user
*oldval
, size_t __user
*oldlenp
,
2998 void __user
*newval
, size_t newlen
)
3001 if (newval
&& newlen
) {
3002 int __user
*vec
= (int __user
*) newval
;
3003 int *min
= (int *) table
->extra1
;
3004 int *max
= (int *) table
->extra2
;
3008 if (newlen
% sizeof(int) != 0)
3011 if (!table
->extra1
&& !table
->extra2
)
3014 if (newlen
> table
->maxlen
)
3015 newlen
= table
->maxlen
;
3016 length
= newlen
/ sizeof(int);
3018 for (i
= 0; i
< length
; i
++) {
3020 if (get_user(value
, vec
+ i
))
3022 if (min
&& value
< min
[i
])
3024 if (max
&& value
> max
[i
])
3031 /* Strategy function to convert jiffies to seconds */
3032 int sysctl_jiffies(struct ctl_table
*table
,
3033 void __user
*oldval
, size_t __user
*oldlenp
,
3034 void __user
*newval
, size_t newlen
)
3036 if (oldval
&& oldlenp
) {
3039 if (get_user(olen
, oldlenp
))
3044 if (olen
< sizeof(int))
3047 val
= *(int *)(table
->data
) / HZ
;
3048 if (put_user(val
, (int __user
*)oldval
))
3050 if (put_user(sizeof(int), oldlenp
))
3054 if (newval
&& newlen
) {
3056 if (newlen
!= sizeof(int))
3058 if (get_user(new, (int __user
*)newval
))
3060 *(int *)(table
->data
) = new*HZ
;
3065 /* Strategy function to convert jiffies to seconds */
3066 int sysctl_ms_jiffies(struct ctl_table
*table
,
3067 void __user
*oldval
, size_t __user
*oldlenp
,
3068 void __user
*newval
, size_t newlen
)
3070 if (oldval
&& oldlenp
) {
3073 if (get_user(olen
, oldlenp
))
3078 if (olen
< sizeof(int))
3081 val
= jiffies_to_msecs(*(int *)(table
->data
));
3082 if (put_user(val
, (int __user
*)oldval
))
3084 if (put_user(sizeof(int), oldlenp
))
3088 if (newval
&& newlen
) {
3090 if (newlen
!= sizeof(int))
3092 if (get_user(new, (int __user
*)newval
))
3094 *(int *)(table
->data
) = msecs_to_jiffies(new);
3101 #else /* CONFIG_SYSCTL_SYSCALL */
3104 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
3106 struct __sysctl_args tmp
;
3109 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
3112 error
= deprecated_sysctl_warning(&tmp
);
3114 /* If no error reading the parameters then just -ENOSYS ... */
3121 int sysctl_data(struct ctl_table
*table
,
3122 void __user
*oldval
, size_t __user
*oldlenp
,
3123 void __user
*newval
, size_t newlen
)
3128 int sysctl_string(struct ctl_table
*table
,
3129 void __user
*oldval
, size_t __user
*oldlenp
,
3130 void __user
*newval
, size_t newlen
)
3135 int sysctl_intvec(struct ctl_table
*table
,
3136 void __user
*oldval
, size_t __user
*oldlenp
,
3137 void __user
*newval
, size_t newlen
)
3142 int sysctl_jiffies(struct ctl_table
*table
,
3143 void __user
*oldval
, size_t __user
*oldlenp
,
3144 void __user
*newval
, size_t newlen
)
3149 int sysctl_ms_jiffies(struct ctl_table
*table
,
3150 void __user
*oldval
, size_t __user
*oldlenp
,
3151 void __user
*newval
, size_t newlen
)
3156 #endif /* CONFIG_SYSCTL_SYSCALL */
3158 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
3160 static int msg_count
;
3161 int name
[CTL_MAXNAME
];
3164 /* Check args->nlen. */
3165 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
3168 /* Read in the sysctl name for better debug message logging */
3169 for (i
= 0; i
< args
->nlen
; i
++)
3170 if (get_user(name
[i
], args
->name
+ i
))
3173 /* Ignore accesses to kernel.version */
3174 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
3177 if (msg_count
< 5) {
3180 "warning: process `%s' used the deprecated sysctl "
3181 "system call with ", current
->comm
);
3182 for (i
= 0; i
< args
->nlen
; i
++)
3183 printk("%d.", name
[i
]);
3190 * No sense putting this after each symbol definition, twice,
3191 * exception granted :-)
3193 EXPORT_SYMBOL(proc_dointvec
);
3194 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3195 EXPORT_SYMBOL(proc_dointvec_minmax
);
3196 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3197 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3198 EXPORT_SYMBOL(proc_dostring
);
3199 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3200 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
3201 EXPORT_SYMBOL(register_sysctl_table
);
3202 EXPORT_SYMBOL(register_sysctl_paths
);
3203 EXPORT_SYMBOL(sysctl_intvec
);
3204 EXPORT_SYMBOL(sysctl_jiffies
);
3205 EXPORT_SYMBOL(sysctl_ms_jiffies
);
3206 EXPORT_SYMBOL(sysctl_string
);
3207 EXPORT_SYMBOL(sysctl_data
);
3208 EXPORT_SYMBOL(unregister_sysctl_table
);