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
[] = {
248 #ifdef CONFIG_SCHED_DEBUG
250 .ctl_name
= CTL_UNNUMBERED
,
251 .procname
= "sched_min_granularity_ns",
252 .data
= &sysctl_sched_min_granularity
,
253 .maxlen
= sizeof(unsigned int),
255 .proc_handler
= &sched_nr_latency_handler
,
256 .strategy
= &sysctl_intvec
,
257 .extra1
= &min_sched_granularity_ns
,
258 .extra2
= &max_sched_granularity_ns
,
261 .ctl_name
= CTL_UNNUMBERED
,
262 .procname
= "sched_latency_ns",
263 .data
= &sysctl_sched_latency
,
264 .maxlen
= sizeof(unsigned int),
266 .proc_handler
= &sched_nr_latency_handler
,
267 .strategy
= &sysctl_intvec
,
268 .extra1
= &min_sched_granularity_ns
,
269 .extra2
= &max_sched_granularity_ns
,
272 .ctl_name
= CTL_UNNUMBERED
,
273 .procname
= "sched_wakeup_granularity_ns",
274 .data
= &sysctl_sched_wakeup_granularity
,
275 .maxlen
= sizeof(unsigned int),
277 .proc_handler
= &proc_dointvec_minmax
,
278 .strategy
= &sysctl_intvec
,
279 .extra1
= &min_wakeup_granularity_ns
,
280 .extra2
= &max_wakeup_granularity_ns
,
283 .ctl_name
= CTL_UNNUMBERED
,
284 .procname
= "sched_shares_ratelimit",
285 .data
= &sysctl_sched_shares_ratelimit
,
286 .maxlen
= sizeof(unsigned int),
288 .proc_handler
= &proc_dointvec
,
291 .ctl_name
= CTL_UNNUMBERED
,
292 .procname
= "sched_shares_thresh",
293 .data
= &sysctl_sched_shares_thresh
,
294 .maxlen
= sizeof(unsigned int),
296 .proc_handler
= &proc_dointvec_minmax
,
297 .strategy
= &sysctl_intvec
,
301 .ctl_name
= CTL_UNNUMBERED
,
302 .procname
= "sched_child_runs_first",
303 .data
= &sysctl_sched_child_runs_first
,
304 .maxlen
= sizeof(unsigned int),
306 .proc_handler
= &proc_dointvec
,
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
,
334 .ctl_name
= CTL_UNNUMBERED
,
335 .procname
= "sched_rt_period_us",
336 .data
= &sysctl_sched_rt_period
,
337 .maxlen
= sizeof(unsigned int),
339 .proc_handler
= &sched_rt_handler
,
342 .ctl_name
= CTL_UNNUMBERED
,
343 .procname
= "sched_rt_runtime_us",
344 .data
= &sysctl_sched_rt_runtime
,
345 .maxlen
= sizeof(int),
347 .proc_handler
= &sched_rt_handler
,
350 .ctl_name
= CTL_UNNUMBERED
,
351 .procname
= "sched_compat_yield",
352 .data
= &sysctl_sched_compat_yield
,
353 .maxlen
= sizeof(unsigned int),
355 .proc_handler
= &proc_dointvec
,
357 #ifdef CONFIG_PROVE_LOCKING
359 .ctl_name
= CTL_UNNUMBERED
,
360 .procname
= "prove_locking",
361 .data
= &prove_locking
,
362 .maxlen
= sizeof(int),
364 .proc_handler
= &proc_dointvec
,
367 #ifdef CONFIG_LOCK_STAT
369 .ctl_name
= CTL_UNNUMBERED
,
370 .procname
= "lock_stat",
372 .maxlen
= sizeof(int),
374 .proc_handler
= &proc_dointvec
,
378 .ctl_name
= KERN_PANIC
,
380 .data
= &panic_timeout
,
381 .maxlen
= sizeof(int),
383 .proc_handler
= &proc_dointvec
,
386 .ctl_name
= KERN_CORE_USES_PID
,
387 .procname
= "core_uses_pid",
388 .data
= &core_uses_pid
,
389 .maxlen
= sizeof(int),
391 .proc_handler
= &proc_dointvec
,
394 .ctl_name
= KERN_CORE_PATTERN
,
395 .procname
= "core_pattern",
396 .data
= core_pattern
,
397 .maxlen
= CORENAME_MAX_SIZE
,
399 .proc_handler
= &proc_dostring
,
400 .strategy
= &sysctl_string
,
402 #ifdef CONFIG_PROC_SYSCTL
404 .procname
= "tainted",
405 .maxlen
= sizeof(long),
407 .proc_handler
= &proc_taint
,
410 #ifdef CONFIG_LATENCYTOP
412 .procname
= "latencytop",
413 .data
= &latencytop_enabled
,
414 .maxlen
= sizeof(int),
416 .proc_handler
= &proc_dointvec
,
419 #ifdef CONFIG_BLK_DEV_INITRD
421 .ctl_name
= KERN_REALROOTDEV
,
422 .procname
= "real-root-dev",
423 .data
= &real_root_dev
,
424 .maxlen
= sizeof(int),
426 .proc_handler
= &proc_dointvec
,
430 .ctl_name
= CTL_UNNUMBERED
,
431 .procname
= "print-fatal-signals",
432 .data
= &print_fatal_signals
,
433 .maxlen
= sizeof(int),
435 .proc_handler
= &proc_dointvec
,
439 .ctl_name
= KERN_SPARC_REBOOT
,
440 .procname
= "reboot-cmd",
441 .data
= reboot_command
,
444 .proc_handler
= &proc_dostring
,
445 .strategy
= &sysctl_string
,
448 .ctl_name
= KERN_SPARC_STOP_A
,
449 .procname
= "stop-a",
450 .data
= &stop_a_enabled
,
451 .maxlen
= sizeof (int),
453 .proc_handler
= &proc_dointvec
,
456 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
457 .procname
= "scons-poweroff",
458 .data
= &scons_pwroff
,
459 .maxlen
= sizeof (int),
461 .proc_handler
= &proc_dointvec
,
464 #ifdef CONFIG_SPARC64
466 .ctl_name
= CTL_UNNUMBERED
,
467 .procname
= "tsb-ratio",
468 .data
= &sysctl_tsb_ratio
,
469 .maxlen
= sizeof (int),
471 .proc_handler
= &proc_dointvec
,
476 .ctl_name
= KERN_HPPA_PWRSW
,
477 .procname
= "soft-power",
478 .data
= &pwrsw_enabled
,
479 .maxlen
= sizeof (int),
481 .proc_handler
= &proc_dointvec
,
484 .ctl_name
= KERN_HPPA_UNALIGNED
,
485 .procname
= "unaligned-trap",
486 .data
= &unaligned_enabled
,
487 .maxlen
= sizeof (int),
489 .proc_handler
= &proc_dointvec
,
493 .ctl_name
= KERN_CTLALTDEL
,
494 .procname
= "ctrl-alt-del",
496 .maxlen
= sizeof(int),
498 .proc_handler
= &proc_dointvec
,
500 #ifdef CONFIG_FUNCTION_TRACER
502 .ctl_name
= CTL_UNNUMBERED
,
503 .procname
= "ftrace_enabled",
504 .data
= &ftrace_enabled
,
505 .maxlen
= sizeof(int),
507 .proc_handler
= &ftrace_enable_sysctl
,
510 #ifdef CONFIG_STACK_TRACER
512 .ctl_name
= CTL_UNNUMBERED
,
513 .procname
= "stack_tracer_enabled",
514 .data
= &stack_tracer_enabled
,
515 .maxlen
= sizeof(int),
517 .proc_handler
= &stack_trace_sysctl
,
520 #ifdef CONFIG_TRACING
522 .ctl_name
= CTL_UNNUMBERED
,
523 .procname
= "ftrace_dump_on_oops",
524 .data
= &ftrace_dump_on_oops
,
525 .maxlen
= sizeof(int),
527 .proc_handler
= &proc_dointvec
,
530 #ifdef CONFIG_MODULES
532 .ctl_name
= KERN_MODPROBE
,
533 .procname
= "modprobe",
534 .data
= &modprobe_path
,
535 .maxlen
= KMOD_PATH_LEN
,
537 .proc_handler
= &proc_dostring
,
538 .strategy
= &sysctl_string
,
541 .ctl_name
= CTL_UNNUMBERED
,
542 .procname
= "modules_disabled",
543 .data
= &modules_disabled
,
544 .maxlen
= sizeof(int),
546 /* only handle a transition from default "0" to "1" */
547 .proc_handler
= &proc_dointvec_minmax
,
552 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
554 .ctl_name
= KERN_HOTPLUG
,
555 .procname
= "hotplug",
556 .data
= &uevent_helper
,
557 .maxlen
= UEVENT_HELPER_PATH_LEN
,
559 .proc_handler
= &proc_dostring
,
560 .strategy
= &sysctl_string
,
563 #ifdef CONFIG_CHR_DEV_SG
565 .ctl_name
= KERN_SG_BIG_BUFF
,
566 .procname
= "sg-big-buff",
567 .data
= &sg_big_buff
,
568 .maxlen
= sizeof (int),
570 .proc_handler
= &proc_dointvec
,
573 #ifdef CONFIG_BSD_PROCESS_ACCT
575 .ctl_name
= KERN_ACCT
,
578 .maxlen
= 3*sizeof(int),
580 .proc_handler
= &proc_dointvec
,
583 #ifdef CONFIG_MAGIC_SYSRQ
585 .ctl_name
= KERN_SYSRQ
,
587 .data
= &__sysrq_enabled
,
588 .maxlen
= sizeof (int),
590 .proc_handler
= &proc_dointvec
,
593 #ifdef CONFIG_PROC_SYSCTL
595 .procname
= "cad_pid",
597 .maxlen
= sizeof (int),
599 .proc_handler
= &proc_do_cad_pid
,
603 .ctl_name
= KERN_MAX_THREADS
,
604 .procname
= "threads-max",
605 .data
= &max_threads
,
606 .maxlen
= sizeof(int),
608 .proc_handler
= &proc_dointvec
,
611 .ctl_name
= KERN_RANDOM
,
612 .procname
= "random",
614 .child
= random_table
,
617 .ctl_name
= KERN_OVERFLOWUID
,
618 .procname
= "overflowuid",
619 .data
= &overflowuid
,
620 .maxlen
= sizeof(int),
622 .proc_handler
= &proc_dointvec_minmax
,
623 .strategy
= &sysctl_intvec
,
624 .extra1
= &minolduid
,
625 .extra2
= &maxolduid
,
628 .ctl_name
= KERN_OVERFLOWGID
,
629 .procname
= "overflowgid",
630 .data
= &overflowgid
,
631 .maxlen
= sizeof(int),
633 .proc_handler
= &proc_dointvec_minmax
,
634 .strategy
= &sysctl_intvec
,
635 .extra1
= &minolduid
,
636 .extra2
= &maxolduid
,
639 #ifdef CONFIG_MATHEMU
641 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
642 .procname
= "ieee_emulation_warnings",
643 .data
= &sysctl_ieee_emulation_warnings
,
644 .maxlen
= sizeof(int),
646 .proc_handler
= &proc_dointvec
,
650 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
651 .procname
= "userprocess_debug",
652 .data
= &sysctl_userprocess_debug
,
653 .maxlen
= sizeof(int),
655 .proc_handler
= &proc_dointvec
,
659 .ctl_name
= KERN_PIDMAX
,
660 .procname
= "pid_max",
662 .maxlen
= sizeof (int),
664 .proc_handler
= &proc_dointvec_minmax
,
665 .strategy
= sysctl_intvec
,
666 .extra1
= &pid_max_min
,
667 .extra2
= &pid_max_max
,
670 .ctl_name
= KERN_PANIC_ON_OOPS
,
671 .procname
= "panic_on_oops",
672 .data
= &panic_on_oops
,
673 .maxlen
= sizeof(int),
675 .proc_handler
= &proc_dointvec
,
677 #if defined CONFIG_PRINTK
679 .ctl_name
= KERN_PRINTK
,
680 .procname
= "printk",
681 .data
= &console_loglevel
,
682 .maxlen
= 4*sizeof(int),
684 .proc_handler
= &proc_dointvec
,
687 .ctl_name
= KERN_PRINTK_RATELIMIT
,
688 .procname
= "printk_ratelimit",
689 .data
= &printk_ratelimit_state
.interval
,
690 .maxlen
= sizeof(int),
692 .proc_handler
= &proc_dointvec_jiffies
,
693 .strategy
= &sysctl_jiffies
,
696 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
697 .procname
= "printk_ratelimit_burst",
698 .data
= &printk_ratelimit_state
.burst
,
699 .maxlen
= sizeof(int),
701 .proc_handler
= &proc_dointvec
,
705 .ctl_name
= KERN_NGROUPS_MAX
,
706 .procname
= "ngroups_max",
707 .data
= &ngroups_max
,
708 .maxlen
= sizeof (int),
710 .proc_handler
= &proc_dointvec
,
712 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
714 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
715 .procname
= "unknown_nmi_panic",
716 .data
= &unknown_nmi_panic
,
717 .maxlen
= sizeof (int),
719 .proc_handler
= &proc_dointvec
,
722 .procname
= "nmi_watchdog",
723 .data
= &nmi_watchdog_enabled
,
724 .maxlen
= sizeof (int),
726 .proc_handler
= &proc_nmi_enabled
,
729 #if defined(CONFIG_X86)
731 .ctl_name
= KERN_PANIC_ON_NMI
,
732 .procname
= "panic_on_unrecovered_nmi",
733 .data
= &panic_on_unrecovered_nmi
,
734 .maxlen
= sizeof(int),
736 .proc_handler
= &proc_dointvec
,
739 .ctl_name
= KERN_BOOTLOADER_TYPE
,
740 .procname
= "bootloader_type",
741 .data
= &bootloader_type
,
742 .maxlen
= sizeof (int),
744 .proc_handler
= &proc_dointvec
,
747 .ctl_name
= CTL_UNNUMBERED
,
748 .procname
= "bootloader_version",
749 .data
= &bootloader_version
,
750 .maxlen
= sizeof (int),
752 .proc_handler
= &proc_dointvec
,
755 .ctl_name
= CTL_UNNUMBERED
,
756 .procname
= "kstack_depth_to_print",
757 .data
= &kstack_depth_to_print
,
758 .maxlen
= sizeof(int),
760 .proc_handler
= &proc_dointvec
,
763 .ctl_name
= CTL_UNNUMBERED
,
764 .procname
= "io_delay_type",
765 .data
= &io_delay_type
,
766 .maxlen
= sizeof(int),
768 .proc_handler
= &proc_dointvec
,
771 #if defined(CONFIG_MMU)
773 .ctl_name
= KERN_RANDOMIZE
,
774 .procname
= "randomize_va_space",
775 .data
= &randomize_va_space
,
776 .maxlen
= sizeof(int),
778 .proc_handler
= &proc_dointvec
,
781 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
783 .ctl_name
= KERN_SPIN_RETRY
,
784 .procname
= "spin_retry",
786 .maxlen
= sizeof (int),
788 .proc_handler
= &proc_dointvec
,
791 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
793 .procname
= "acpi_video_flags",
794 .data
= &acpi_realmode_flags
,
795 .maxlen
= sizeof (unsigned long),
797 .proc_handler
= &proc_doulongvec_minmax
,
802 .ctl_name
= KERN_IA64_UNALIGNED
,
803 .procname
= "ignore-unaligned-usertrap",
804 .data
= &no_unaligned_warning
,
805 .maxlen
= sizeof (int),
807 .proc_handler
= &proc_dointvec
,
810 .ctl_name
= CTL_UNNUMBERED
,
811 .procname
= "unaligned-dump-stack",
812 .data
= &unaligned_dump_stack
,
813 .maxlen
= sizeof (int),
815 .proc_handler
= &proc_dointvec
,
818 #ifdef CONFIG_DETECT_SOFTLOCKUP
820 .ctl_name
= CTL_UNNUMBERED
,
821 .procname
= "softlockup_panic",
822 .data
= &softlockup_panic
,
823 .maxlen
= sizeof(int),
825 .proc_handler
= &proc_dointvec_minmax
,
826 .strategy
= &sysctl_intvec
,
831 .ctl_name
= CTL_UNNUMBERED
,
832 .procname
= "softlockup_thresh",
833 .data
= &softlockup_thresh
,
834 .maxlen
= sizeof(int),
836 .proc_handler
= &proc_dosoftlockup_thresh
,
837 .strategy
= &sysctl_intvec
,
842 #ifdef CONFIG_DETECT_HUNG_TASK
844 .ctl_name
= CTL_UNNUMBERED
,
845 .procname
= "hung_task_panic",
846 .data
= &sysctl_hung_task_panic
,
847 .maxlen
= sizeof(int),
849 .proc_handler
= &proc_dointvec_minmax
,
850 .strategy
= &sysctl_intvec
,
855 .ctl_name
= CTL_UNNUMBERED
,
856 .procname
= "hung_task_check_count",
857 .data
= &sysctl_hung_task_check_count
,
858 .maxlen
= sizeof(unsigned long),
860 .proc_handler
= &proc_doulongvec_minmax
,
861 .strategy
= &sysctl_intvec
,
864 .ctl_name
= CTL_UNNUMBERED
,
865 .procname
= "hung_task_timeout_secs",
866 .data
= &sysctl_hung_task_timeout_secs
,
867 .maxlen
= sizeof(unsigned long),
869 .proc_handler
= &proc_dohung_task_timeout_secs
,
870 .strategy
= &sysctl_intvec
,
873 .ctl_name
= CTL_UNNUMBERED
,
874 .procname
= "hung_task_warnings",
875 .data
= &sysctl_hung_task_warnings
,
876 .maxlen
= sizeof(unsigned long),
878 .proc_handler
= &proc_doulongvec_minmax
,
879 .strategy
= &sysctl_intvec
,
884 .ctl_name
= KERN_COMPAT_LOG
,
885 .procname
= "compat-log",
887 .maxlen
= sizeof (int),
889 .proc_handler
= &proc_dointvec
,
892 #ifdef CONFIG_RT_MUTEXES
894 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
895 .procname
= "max_lock_depth",
896 .data
= &max_lock_depth
,
897 .maxlen
= sizeof(int),
899 .proc_handler
= &proc_dointvec
,
903 .ctl_name
= CTL_UNNUMBERED
,
904 .procname
= "poweroff_cmd",
905 .data
= &poweroff_cmd
,
906 .maxlen
= POWEROFF_CMD_PATH_LEN
,
908 .proc_handler
= &proc_dostring
,
909 .strategy
= &sysctl_string
,
913 .ctl_name
= CTL_UNNUMBERED
,
916 .child
= key_sysctls
,
919 #ifdef CONFIG_RCU_TORTURE_TEST
921 .ctl_name
= CTL_UNNUMBERED
,
922 .procname
= "rcutorture_runnable",
923 .data
= &rcutorture_runnable
,
924 .maxlen
= sizeof(int),
926 .proc_handler
= &proc_dointvec
,
929 #ifdef CONFIG_SLOW_WORK
931 .ctl_name
= CTL_UNNUMBERED
,
932 .procname
= "slow-work",
934 .child
= slow_work_sysctls
,
937 #ifdef CONFIG_PERF_COUNTERS
939 .ctl_name
= CTL_UNNUMBERED
,
940 .procname
= "perf_counter_paranoid",
941 .data
= &sysctl_perf_counter_paranoid
,
942 .maxlen
= sizeof(sysctl_perf_counter_paranoid
),
944 .proc_handler
= &proc_dointvec
,
947 .ctl_name
= CTL_UNNUMBERED
,
948 .procname
= "perf_counter_mlock_kb",
949 .data
= &sysctl_perf_counter_mlock
,
950 .maxlen
= sizeof(sysctl_perf_counter_mlock
),
952 .proc_handler
= &proc_dointvec
,
955 .ctl_name
= CTL_UNNUMBERED
,
956 .procname
= "perf_counter_max_sample_rate",
957 .data
= &sysctl_perf_counter_sample_rate
,
958 .maxlen
= sizeof(sysctl_perf_counter_sample_rate
),
960 .proc_handler
= &proc_dointvec
,
963 #ifdef CONFIG_KMEMCHECK
965 .ctl_name
= CTL_UNNUMBERED
,
966 .procname
= "kmemcheck",
967 .data
= &kmemcheck_enabled
,
968 .maxlen
= sizeof(int),
970 .proc_handler
= &proc_dointvec
,
975 * NOTE: do not add new entries to this table unless you have read
976 * Documentation/sysctl/ctl_unnumbered.txt
981 static struct ctl_table vm_table
[] = {
983 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
984 .procname
= "overcommit_memory",
985 .data
= &sysctl_overcommit_memory
,
986 .maxlen
= sizeof(sysctl_overcommit_memory
),
988 .proc_handler
= &proc_dointvec
,
991 .ctl_name
= VM_PANIC_ON_OOM
,
992 .procname
= "panic_on_oom",
993 .data
= &sysctl_panic_on_oom
,
994 .maxlen
= sizeof(sysctl_panic_on_oom
),
996 .proc_handler
= &proc_dointvec
,
999 .ctl_name
= CTL_UNNUMBERED
,
1000 .procname
= "oom_kill_allocating_task",
1001 .data
= &sysctl_oom_kill_allocating_task
,
1002 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1004 .proc_handler
= &proc_dointvec
,
1007 .ctl_name
= CTL_UNNUMBERED
,
1008 .procname
= "oom_dump_tasks",
1009 .data
= &sysctl_oom_dump_tasks
,
1010 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1012 .proc_handler
= &proc_dointvec
,
1015 .ctl_name
= VM_OVERCOMMIT_RATIO
,
1016 .procname
= "overcommit_ratio",
1017 .data
= &sysctl_overcommit_ratio
,
1018 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1020 .proc_handler
= &proc_dointvec
,
1023 .ctl_name
= VM_PAGE_CLUSTER
,
1024 .procname
= "page-cluster",
1025 .data
= &page_cluster
,
1026 .maxlen
= sizeof(int),
1028 .proc_handler
= &proc_dointvec
,
1031 .ctl_name
= VM_DIRTY_BACKGROUND
,
1032 .procname
= "dirty_background_ratio",
1033 .data
= &dirty_background_ratio
,
1034 .maxlen
= sizeof(dirty_background_ratio
),
1036 .proc_handler
= &dirty_background_ratio_handler
,
1037 .strategy
= &sysctl_intvec
,
1039 .extra2
= &one_hundred
,
1042 .ctl_name
= CTL_UNNUMBERED
,
1043 .procname
= "dirty_background_bytes",
1044 .data
= &dirty_background_bytes
,
1045 .maxlen
= sizeof(dirty_background_bytes
),
1047 .proc_handler
= &dirty_background_bytes_handler
,
1048 .strategy
= &sysctl_intvec
,
1052 .ctl_name
= VM_DIRTY_RATIO
,
1053 .procname
= "dirty_ratio",
1054 .data
= &vm_dirty_ratio
,
1055 .maxlen
= sizeof(vm_dirty_ratio
),
1057 .proc_handler
= &dirty_ratio_handler
,
1058 .strategy
= &sysctl_intvec
,
1060 .extra2
= &one_hundred
,
1063 .ctl_name
= CTL_UNNUMBERED
,
1064 .procname
= "dirty_bytes",
1065 .data
= &vm_dirty_bytes
,
1066 .maxlen
= sizeof(vm_dirty_bytes
),
1068 .proc_handler
= &dirty_bytes_handler
,
1069 .strategy
= &sysctl_intvec
,
1070 .extra1
= &dirty_bytes_min
,
1073 .procname
= "dirty_writeback_centisecs",
1074 .data
= &dirty_writeback_interval
,
1075 .maxlen
= sizeof(dirty_writeback_interval
),
1077 .proc_handler
= &dirty_writeback_centisecs_handler
,
1080 .procname
= "dirty_expire_centisecs",
1081 .data
= &dirty_expire_interval
,
1082 .maxlen
= sizeof(dirty_expire_interval
),
1084 .proc_handler
= &proc_dointvec
,
1087 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
1088 .procname
= "nr_pdflush_threads",
1089 .data
= &nr_pdflush_threads
,
1090 .maxlen
= sizeof nr_pdflush_threads
,
1091 .mode
= 0444 /* read-only*/,
1092 .proc_handler
= &proc_dointvec
,
1095 .ctl_name
= VM_SWAPPINESS
,
1096 .procname
= "swappiness",
1097 .data
= &vm_swappiness
,
1098 .maxlen
= sizeof(vm_swappiness
),
1100 .proc_handler
= &proc_dointvec_minmax
,
1101 .strategy
= &sysctl_intvec
,
1103 .extra2
= &one_hundred
,
1105 #ifdef CONFIG_HUGETLB_PAGE
1107 .procname
= "nr_hugepages",
1109 .maxlen
= sizeof(unsigned long),
1111 .proc_handler
= &hugetlb_sysctl_handler
,
1112 .extra1
= (void *)&hugetlb_zero
,
1113 .extra2
= (void *)&hugetlb_infinity
,
1116 .ctl_name
= VM_HUGETLB_GROUP
,
1117 .procname
= "hugetlb_shm_group",
1118 .data
= &sysctl_hugetlb_shm_group
,
1119 .maxlen
= sizeof(gid_t
),
1121 .proc_handler
= &proc_dointvec
,
1124 .ctl_name
= CTL_UNNUMBERED
,
1125 .procname
= "hugepages_treat_as_movable",
1126 .data
= &hugepages_treat_as_movable
,
1127 .maxlen
= sizeof(int),
1129 .proc_handler
= &hugetlb_treat_movable_handler
,
1132 .ctl_name
= CTL_UNNUMBERED
,
1133 .procname
= "nr_overcommit_hugepages",
1135 .maxlen
= sizeof(unsigned long),
1137 .proc_handler
= &hugetlb_overcommit_handler
,
1138 .extra1
= (void *)&hugetlb_zero
,
1139 .extra2
= (void *)&hugetlb_infinity
,
1143 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
1144 .procname
= "lowmem_reserve_ratio",
1145 .data
= &sysctl_lowmem_reserve_ratio
,
1146 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1148 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
1149 .strategy
= &sysctl_intvec
,
1152 .ctl_name
= VM_DROP_PAGECACHE
,
1153 .procname
= "drop_caches",
1154 .data
= &sysctl_drop_caches
,
1155 .maxlen
= sizeof(int),
1157 .proc_handler
= drop_caches_sysctl_handler
,
1158 .strategy
= &sysctl_intvec
,
1161 .ctl_name
= VM_MIN_FREE_KBYTES
,
1162 .procname
= "min_free_kbytes",
1163 .data
= &min_free_kbytes
,
1164 .maxlen
= sizeof(min_free_kbytes
),
1166 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1167 .strategy
= &sysctl_intvec
,
1171 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1172 .procname
= "percpu_pagelist_fraction",
1173 .data
= &percpu_pagelist_fraction
,
1174 .maxlen
= sizeof(percpu_pagelist_fraction
),
1176 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1177 .strategy
= &sysctl_intvec
,
1178 .extra1
= &min_percpu_pagelist_fract
,
1182 .ctl_name
= VM_MAX_MAP_COUNT
,
1183 .procname
= "max_map_count",
1184 .data
= &sysctl_max_map_count
,
1185 .maxlen
= sizeof(sysctl_max_map_count
),
1187 .proc_handler
= &proc_dointvec
1191 .ctl_name
= CTL_UNNUMBERED
,
1192 .procname
= "nr_trim_pages",
1193 .data
= &sysctl_nr_trim_pages
,
1194 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1196 .proc_handler
= &proc_dointvec_minmax
,
1197 .strategy
= &sysctl_intvec
,
1202 .ctl_name
= VM_LAPTOP_MODE
,
1203 .procname
= "laptop_mode",
1204 .data
= &laptop_mode
,
1205 .maxlen
= sizeof(laptop_mode
),
1207 .proc_handler
= &proc_dointvec_jiffies
,
1208 .strategy
= &sysctl_jiffies
,
1211 .ctl_name
= VM_BLOCK_DUMP
,
1212 .procname
= "block_dump",
1213 .data
= &block_dump
,
1214 .maxlen
= sizeof(block_dump
),
1216 .proc_handler
= &proc_dointvec
,
1217 .strategy
= &sysctl_intvec
,
1221 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1222 .procname
= "vfs_cache_pressure",
1223 .data
= &sysctl_vfs_cache_pressure
,
1224 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1226 .proc_handler
= &proc_dointvec
,
1227 .strategy
= &sysctl_intvec
,
1230 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1232 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1233 .procname
= "legacy_va_layout",
1234 .data
= &sysctl_legacy_va_layout
,
1235 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1237 .proc_handler
= &proc_dointvec
,
1238 .strategy
= &sysctl_intvec
,
1244 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1245 .procname
= "zone_reclaim_mode",
1246 .data
= &zone_reclaim_mode
,
1247 .maxlen
= sizeof(zone_reclaim_mode
),
1249 .proc_handler
= &proc_dointvec
,
1250 .strategy
= &sysctl_intvec
,
1254 .ctl_name
= VM_MIN_UNMAPPED
,
1255 .procname
= "min_unmapped_ratio",
1256 .data
= &sysctl_min_unmapped_ratio
,
1257 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1259 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1260 .strategy
= &sysctl_intvec
,
1262 .extra2
= &one_hundred
,
1265 .ctl_name
= VM_MIN_SLAB
,
1266 .procname
= "min_slab_ratio",
1267 .data
= &sysctl_min_slab_ratio
,
1268 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1270 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1271 .strategy
= &sysctl_intvec
,
1273 .extra2
= &one_hundred
,
1278 .ctl_name
= CTL_UNNUMBERED
,
1279 .procname
= "stat_interval",
1280 .data
= &sysctl_stat_interval
,
1281 .maxlen
= sizeof(sysctl_stat_interval
),
1283 .proc_handler
= &proc_dointvec_jiffies
,
1284 .strategy
= &sysctl_jiffies
,
1288 .ctl_name
= CTL_UNNUMBERED
,
1289 .procname
= "mmap_min_addr",
1290 .data
= &mmap_min_addr
,
1291 .maxlen
= sizeof(unsigned long),
1293 .proc_handler
= &proc_doulongvec_minmax
,
1297 .ctl_name
= CTL_UNNUMBERED
,
1298 .procname
= "numa_zonelist_order",
1299 .data
= &numa_zonelist_order
,
1300 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1302 .proc_handler
= &numa_zonelist_order_handler
,
1303 .strategy
= &sysctl_string
,
1306 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1307 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1309 .ctl_name
= VM_VDSO_ENABLED
,
1310 .procname
= "vdso_enabled",
1311 .data
= &vdso_enabled
,
1312 .maxlen
= sizeof(vdso_enabled
),
1314 .proc_handler
= &proc_dointvec
,
1315 .strategy
= &sysctl_intvec
,
1319 #ifdef CONFIG_HIGHMEM
1321 .ctl_name
= CTL_UNNUMBERED
,
1322 .procname
= "highmem_is_dirtyable",
1323 .data
= &vm_highmem_is_dirtyable
,
1324 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1326 .proc_handler
= &proc_dointvec_minmax
,
1327 .strategy
= &sysctl_intvec
,
1332 #ifdef CONFIG_UNEVICTABLE_LRU
1334 .ctl_name
= CTL_UNNUMBERED
,
1335 .procname
= "scan_unevictable_pages",
1336 .data
= &scan_unevictable_pages
,
1337 .maxlen
= sizeof(scan_unevictable_pages
),
1339 .proc_handler
= &scan_unevictable_handler
,
1343 * NOTE: do not add new entries to this table unless you have read
1344 * Documentation/sysctl/ctl_unnumbered.txt
1349 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1350 static struct ctl_table binfmt_misc_table
[] = {
1355 static struct ctl_table fs_table
[] = {
1357 .ctl_name
= FS_NRINODE
,
1358 .procname
= "inode-nr",
1359 .data
= &inodes_stat
,
1360 .maxlen
= 2*sizeof(int),
1362 .proc_handler
= &proc_dointvec
,
1365 .ctl_name
= FS_STATINODE
,
1366 .procname
= "inode-state",
1367 .data
= &inodes_stat
,
1368 .maxlen
= 7*sizeof(int),
1370 .proc_handler
= &proc_dointvec
,
1373 .procname
= "file-nr",
1374 .data
= &files_stat
,
1375 .maxlen
= 3*sizeof(int),
1377 .proc_handler
= &proc_nr_files
,
1380 .ctl_name
= FS_MAXFILE
,
1381 .procname
= "file-max",
1382 .data
= &files_stat
.max_files
,
1383 .maxlen
= sizeof(int),
1385 .proc_handler
= &proc_dointvec
,
1388 .ctl_name
= CTL_UNNUMBERED
,
1389 .procname
= "nr_open",
1390 .data
= &sysctl_nr_open
,
1391 .maxlen
= sizeof(int),
1393 .proc_handler
= &proc_dointvec_minmax
,
1394 .extra1
= &sysctl_nr_open_min
,
1395 .extra2
= &sysctl_nr_open_max
,
1398 .ctl_name
= FS_DENTRY
,
1399 .procname
= "dentry-state",
1400 .data
= &dentry_stat
,
1401 .maxlen
= 6*sizeof(int),
1403 .proc_handler
= &proc_dointvec
,
1406 .ctl_name
= FS_OVERFLOWUID
,
1407 .procname
= "overflowuid",
1408 .data
= &fs_overflowuid
,
1409 .maxlen
= sizeof(int),
1411 .proc_handler
= &proc_dointvec_minmax
,
1412 .strategy
= &sysctl_intvec
,
1413 .extra1
= &minolduid
,
1414 .extra2
= &maxolduid
,
1417 .ctl_name
= FS_OVERFLOWGID
,
1418 .procname
= "overflowgid",
1419 .data
= &fs_overflowgid
,
1420 .maxlen
= sizeof(int),
1422 .proc_handler
= &proc_dointvec_minmax
,
1423 .strategy
= &sysctl_intvec
,
1424 .extra1
= &minolduid
,
1425 .extra2
= &maxolduid
,
1427 #ifdef CONFIG_FILE_LOCKING
1429 .ctl_name
= FS_LEASES
,
1430 .procname
= "leases-enable",
1431 .data
= &leases_enable
,
1432 .maxlen
= sizeof(int),
1434 .proc_handler
= &proc_dointvec
,
1437 #ifdef CONFIG_DNOTIFY
1439 .ctl_name
= FS_DIR_NOTIFY
,
1440 .procname
= "dir-notify-enable",
1441 .data
= &dir_notify_enable
,
1442 .maxlen
= sizeof(int),
1444 .proc_handler
= &proc_dointvec
,
1448 #ifdef CONFIG_FILE_LOCKING
1450 .ctl_name
= FS_LEASE_TIME
,
1451 .procname
= "lease-break-time",
1452 .data
= &lease_break_time
,
1453 .maxlen
= sizeof(int),
1455 .proc_handler
= &proc_dointvec
,
1460 .procname
= "aio-nr",
1462 .maxlen
= sizeof(aio_nr
),
1464 .proc_handler
= &proc_doulongvec_minmax
,
1467 .procname
= "aio-max-nr",
1468 .data
= &aio_max_nr
,
1469 .maxlen
= sizeof(aio_max_nr
),
1471 .proc_handler
= &proc_doulongvec_minmax
,
1473 #endif /* CONFIG_AIO */
1474 #ifdef CONFIG_INOTIFY_USER
1476 .ctl_name
= FS_INOTIFY
,
1477 .procname
= "inotify",
1479 .child
= inotify_table
,
1484 .procname
= "epoll",
1486 .child
= epoll_table
,
1491 .ctl_name
= KERN_SETUID_DUMPABLE
,
1492 .procname
= "suid_dumpable",
1493 .data
= &suid_dumpable
,
1494 .maxlen
= sizeof(int),
1496 .proc_handler
= &proc_dointvec_minmax
,
1497 .strategy
= &sysctl_intvec
,
1501 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1503 .ctl_name
= CTL_UNNUMBERED
,
1504 .procname
= "binfmt_misc",
1506 .child
= binfmt_misc_table
,
1510 * NOTE: do not add new entries to this table unless you have read
1511 * Documentation/sysctl/ctl_unnumbered.txt
1516 static struct ctl_table debug_table
[] = {
1517 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1519 .ctl_name
= CTL_UNNUMBERED
,
1520 .procname
= "exception-trace",
1521 .data
= &show_unhandled_signals
,
1522 .maxlen
= sizeof(int),
1524 .proc_handler
= proc_dointvec
1530 static struct ctl_table dev_table
[] = {
1534 static DEFINE_SPINLOCK(sysctl_lock
);
1536 /* called under sysctl_lock */
1537 static int use_table(struct ctl_table_header
*p
)
1539 if (unlikely(p
->unregistering
))
1545 /* called under sysctl_lock */
1546 static void unuse_table(struct ctl_table_header
*p
)
1549 if (unlikely(p
->unregistering
))
1550 complete(p
->unregistering
);
1553 /* called under sysctl_lock, will reacquire if has to wait */
1554 static void start_unregistering(struct ctl_table_header
*p
)
1557 * if p->used is 0, nobody will ever touch that entry again;
1558 * we'll eliminate all paths to it before dropping sysctl_lock
1560 if (unlikely(p
->used
)) {
1561 struct completion wait
;
1562 init_completion(&wait
);
1563 p
->unregistering
= &wait
;
1564 spin_unlock(&sysctl_lock
);
1565 wait_for_completion(&wait
);
1566 spin_lock(&sysctl_lock
);
1568 /* anything non-NULL; we'll never dereference it */
1569 p
->unregistering
= ERR_PTR(-EINVAL
);
1572 * do not remove from the list until nobody holds it; walking the
1573 * list in do_sysctl() relies on that.
1575 list_del_init(&p
->ctl_entry
);
1578 void sysctl_head_get(struct ctl_table_header
*head
)
1580 spin_lock(&sysctl_lock
);
1582 spin_unlock(&sysctl_lock
);
1585 void sysctl_head_put(struct ctl_table_header
*head
)
1587 spin_lock(&sysctl_lock
);
1590 spin_unlock(&sysctl_lock
);
1593 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1597 spin_lock(&sysctl_lock
);
1598 if (!use_table(head
))
1599 head
= ERR_PTR(-ENOENT
);
1600 spin_unlock(&sysctl_lock
);
1604 void sysctl_head_finish(struct ctl_table_header
*head
)
1608 spin_lock(&sysctl_lock
);
1610 spin_unlock(&sysctl_lock
);
1613 static struct ctl_table_set
*
1614 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1616 struct ctl_table_set
*set
= &root
->default_set
;
1618 set
= root
->lookup(root
, namespaces
);
1622 static struct list_head
*
1623 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1625 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1629 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1630 struct ctl_table_header
*prev
)
1632 struct ctl_table_root
*root
;
1633 struct list_head
*header_list
;
1634 struct ctl_table_header
*head
;
1635 struct list_head
*tmp
;
1637 spin_lock(&sysctl_lock
);
1640 tmp
= &prev
->ctl_entry
;
1644 tmp
= &root_table_header
.ctl_entry
;
1646 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1648 if (!use_table(head
))
1650 spin_unlock(&sysctl_lock
);
1655 header_list
= lookup_header_list(root
, namespaces
);
1656 if (tmp
!= header_list
)
1660 root
= list_entry(root
->root_list
.next
,
1661 struct ctl_table_root
, root_list
);
1662 if (root
== &sysctl_table_root
)
1664 header_list
= lookup_header_list(root
, namespaces
);
1665 } while (list_empty(header_list
));
1666 tmp
= header_list
->next
;
1669 spin_unlock(&sysctl_lock
);
1673 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1675 return __sysctl_head_next(current
->nsproxy
, prev
);
1678 void register_sysctl_root(struct ctl_table_root
*root
)
1680 spin_lock(&sysctl_lock
);
1681 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1682 spin_unlock(&sysctl_lock
);
1685 #ifdef CONFIG_SYSCTL_SYSCALL
1686 /* Perform the actual read/write of a sysctl table entry. */
1687 static int do_sysctl_strategy(struct ctl_table_root
*root
,
1688 struct ctl_table
*table
,
1689 void __user
*oldval
, size_t __user
*oldlenp
,
1690 void __user
*newval
, size_t newlen
)
1698 if (sysctl_perm(root
, table
, op
))
1701 if (table
->strategy
) {
1702 rc
= table
->strategy(table
, oldval
, oldlenp
, newval
, newlen
);
1709 /* If there is no strategy routine, or if the strategy returns
1710 * zero, proceed with automatic r/w */
1711 if (table
->data
&& table
->maxlen
) {
1712 rc
= sysctl_data(table
, oldval
, oldlenp
, newval
, newlen
);
1719 static int parse_table(int __user
*name
, int nlen
,
1720 void __user
*oldval
, size_t __user
*oldlenp
,
1721 void __user
*newval
, size_t newlen
,
1722 struct ctl_table_root
*root
,
1723 struct ctl_table
*table
)
1729 if (get_user(n
, name
))
1731 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1732 if (!table
->ctl_name
)
1734 if (n
== table
->ctl_name
) {
1737 if (sysctl_perm(root
, table
, MAY_EXEC
))
1741 table
= table
->child
;
1744 error
= do_sysctl_strategy(root
, table
,
1753 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1754 void __user
*newval
, size_t newlen
)
1756 struct ctl_table_header
*head
;
1757 int error
= -ENOTDIR
;
1759 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1763 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1767 for (head
= sysctl_head_next(NULL
); head
;
1768 head
= sysctl_head_next(head
)) {
1769 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1771 head
->root
, head
->ctl_table
);
1772 if (error
!= -ENOTDIR
) {
1773 sysctl_head_finish(head
);
1780 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
1782 struct __sysctl_args tmp
;
1785 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1788 error
= deprecated_sysctl_warning(&tmp
);
1793 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1794 tmp
.newval
, tmp
.newlen
);
1799 #endif /* CONFIG_SYSCTL_SYSCALL */
1802 * sysctl_perm does NOT grant the superuser all rights automatically, because
1803 * some sysctl variables are readonly even to root.
1806 static int test_perm(int mode
, int op
)
1808 if (!current_euid())
1810 else if (in_egroup_p(0))
1812 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1817 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1822 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1826 if (root
->permissions
)
1827 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1831 return test_perm(mode
, op
);
1834 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1836 for (; table
->ctl_name
|| table
->procname
; table
++) {
1837 table
->parent
= parent
;
1839 sysctl_set_parent(table
, table
->child
);
1843 static __init
int sysctl_init(void)
1845 sysctl_set_parent(NULL
, root_table
);
1846 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1849 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1855 core_initcall(sysctl_init
);
1857 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1858 struct ctl_table
*table
)
1860 struct ctl_table
*p
;
1861 const char *s
= branch
->procname
;
1863 /* branch should have named subdirectory as its first element */
1864 if (!s
|| !branch
->child
)
1867 /* ... and nothing else */
1868 if (branch
[1].procname
|| branch
[1].ctl_name
)
1871 /* table should contain subdirectory with the same name */
1872 for (p
= table
; p
->procname
|| p
->ctl_name
; p
++) {
1875 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1881 /* see if attaching q to p would be an improvement */
1882 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1884 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1885 struct ctl_table
*next
;
1887 int not_in_parent
= !p
->attached_by
;
1889 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1890 if (by
== q
->attached_by
)
1892 if (to
== p
->attached_by
)
1898 if (is_better
&& not_in_parent
) {
1899 q
->attached_by
= by
;
1900 q
->attached_to
= to
;
1906 * __register_sysctl_paths - register a sysctl hierarchy
1907 * @root: List of sysctl headers to register on
1908 * @namespaces: Data to compute which lists of sysctl entries are visible
1909 * @path: The path to the directory the sysctl table is in.
1910 * @table: the top-level table structure
1912 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1913 * array. A completely 0 filled entry terminates the table.
1915 * The members of the &struct ctl_table structure are used as follows:
1917 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1918 * must be unique within that level of sysctl
1920 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1921 * enter a sysctl file
1923 * data - a pointer to data for use by proc_handler
1925 * maxlen - the maximum size in bytes of the data
1927 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1929 * child - a pointer to the child sysctl table if this entry is a directory, or
1932 * proc_handler - the text handler routine (described below)
1934 * strategy - the strategy routine (described below)
1936 * de - for internal use by the sysctl routines
1938 * extra1, extra2 - extra pointers usable by the proc handler routines
1940 * Leaf nodes in the sysctl tree will be represented by a single file
1941 * under /proc; non-leaf nodes will be represented by directories.
1943 * sysctl(2) can automatically manage read and write requests through
1944 * the sysctl table. The data and maxlen fields of the ctl_table
1945 * struct enable minimal validation of the values being written to be
1946 * performed, and the mode field allows minimal authentication.
1948 * More sophisticated management can be enabled by the provision of a
1949 * strategy routine with the table entry. This will be called before
1950 * any automatic read or write of the data is performed.
1952 * The strategy routine may return
1954 * < 0 - Error occurred (error is passed to user process)
1956 * 0 - OK - proceed with automatic read or write.
1958 * > 0 - OK - read or write has been done by the strategy routine, so
1959 * return immediately.
1961 * There must be a proc_handler routine for any terminal nodes
1962 * mirrored under /proc/sys (non-terminals are handled by a built-in
1963 * directory handler). Several default handlers are available to
1964 * cover common cases -
1966 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1967 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1968 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1970 * It is the handler's job to read the input buffer from user memory
1971 * and process it. The handler should return 0 on success.
1973 * This routine returns %NULL on a failure to register, and a pointer
1974 * to the table header on success.
1976 struct ctl_table_header
*__register_sysctl_paths(
1977 struct ctl_table_root
*root
,
1978 struct nsproxy
*namespaces
,
1979 const struct ctl_path
*path
, struct ctl_table
*table
)
1981 struct ctl_table_header
*header
;
1982 struct ctl_table
*new, **prevp
;
1983 unsigned int n
, npath
;
1984 struct ctl_table_set
*set
;
1986 /* Count the path components */
1987 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
1991 * For each path component, allocate a 2-element ctl_table array.
1992 * The first array element will be filled with the sysctl entry
1993 * for this, the second will be the sentinel (ctl_name == 0).
1995 * We allocate everything in one go so that we don't have to
1996 * worry about freeing additional memory in unregister_sysctl_table.
1998 header
= kzalloc(sizeof(struct ctl_table_header
) +
1999 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
2003 new = (struct ctl_table
*) (header
+ 1);
2005 /* Now connect the dots */
2006 prevp
= &header
->ctl_table
;
2007 for (n
= 0; n
< npath
; ++n
, ++path
) {
2008 /* Copy the procname */
2009 new->procname
= path
->procname
;
2010 new->ctl_name
= path
->ctl_name
;
2014 prevp
= &new->child
;
2019 header
->ctl_table_arg
= table
;
2021 INIT_LIST_HEAD(&header
->ctl_entry
);
2023 header
->unregistering
= NULL
;
2024 header
->root
= root
;
2025 sysctl_set_parent(NULL
, header
->ctl_table
);
2027 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
2028 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
2033 spin_lock(&sysctl_lock
);
2034 header
->set
= lookup_header_set(root
, namespaces
);
2035 header
->attached_by
= header
->ctl_table
;
2036 header
->attached_to
= root_table
;
2037 header
->parent
= &root_table_header
;
2038 for (set
= header
->set
; set
; set
= set
->parent
) {
2039 struct ctl_table_header
*p
;
2040 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
2041 if (p
->unregistering
)
2043 try_attach(p
, header
);
2046 header
->parent
->count
++;
2047 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
2048 spin_unlock(&sysctl_lock
);
2054 * register_sysctl_table_path - register a sysctl table hierarchy
2055 * @path: The path to the directory the sysctl table is in.
2056 * @table: the top-level table structure
2058 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2059 * array. A completely 0 filled entry terminates the table.
2061 * See __register_sysctl_paths for more details.
2063 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2064 struct ctl_table
*table
)
2066 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
2071 * register_sysctl_table - register a sysctl table hierarchy
2072 * @table: the top-level table structure
2074 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2075 * array. A completely 0 filled entry terminates the table.
2077 * See register_sysctl_paths for more details.
2079 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
2081 static const struct ctl_path null_path
[] = { {} };
2083 return register_sysctl_paths(null_path
, table
);
2087 * unregister_sysctl_table - unregister a sysctl table hierarchy
2088 * @header: the header returned from register_sysctl_table
2090 * Unregisters the sysctl table and all children. proc entries may not
2091 * actually be removed until they are no longer used by anyone.
2093 void unregister_sysctl_table(struct ctl_table_header
* header
)
2100 spin_lock(&sysctl_lock
);
2101 start_unregistering(header
);
2102 if (!--header
->parent
->count
) {
2104 kfree(header
->parent
);
2106 if (!--header
->count
)
2108 spin_unlock(&sysctl_lock
);
2111 int sysctl_is_seen(struct ctl_table_header
*p
)
2113 struct ctl_table_set
*set
= p
->set
;
2115 spin_lock(&sysctl_lock
);
2116 if (p
->unregistering
)
2118 else if (!set
->is_seen
)
2121 res
= set
->is_seen(set
);
2122 spin_unlock(&sysctl_lock
);
2126 void setup_sysctl_set(struct ctl_table_set
*p
,
2127 struct ctl_table_set
*parent
,
2128 int (*is_seen
)(struct ctl_table_set
*))
2130 INIT_LIST_HEAD(&p
->list
);
2131 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
2132 p
->is_seen
= is_seen
;
2135 #else /* !CONFIG_SYSCTL */
2136 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
2141 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2142 struct ctl_table
*table
)
2147 void unregister_sysctl_table(struct ctl_table_header
* table
)
2151 void setup_sysctl_set(struct ctl_table_set
*p
,
2152 struct ctl_table_set
*parent
,
2153 int (*is_seen
)(struct ctl_table_set
*))
2157 void sysctl_head_put(struct ctl_table_header
*head
)
2161 #endif /* CONFIG_SYSCTL */
2167 #ifdef CONFIG_PROC_SYSCTL
2169 static int _proc_do_string(void* data
, int maxlen
, int write
,
2170 struct file
*filp
, void __user
*buffer
,
2171 size_t *lenp
, loff_t
*ppos
)
2177 if (!data
|| !maxlen
|| !*lenp
) {
2185 while (len
< *lenp
) {
2186 if (get_user(c
, p
++))
2188 if (c
== 0 || c
== '\n')
2194 if(copy_from_user(data
, buffer
, len
))
2196 ((char *) data
)[len
] = 0;
2214 if(copy_to_user(buffer
, data
, len
))
2217 if(put_user('\n', ((char __user
*) buffer
) + len
))
2228 * proc_dostring - read a string sysctl
2229 * @table: the sysctl table
2230 * @write: %TRUE if this is a write to the sysctl file
2231 * @filp: the file structure
2232 * @buffer: the user buffer
2233 * @lenp: the size of the user buffer
2234 * @ppos: file position
2236 * Reads/writes a string from/to the user buffer. If the kernel
2237 * buffer provided is not large enough to hold the string, the
2238 * string is truncated. The copied string is %NULL-terminated.
2239 * If the string is being read by the user process, it is copied
2240 * and a newline '\n' is added. It is truncated if the buffer is
2243 * Returns 0 on success.
2245 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2246 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2248 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
2249 buffer
, lenp
, ppos
);
2253 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
2255 int write
, void *data
)
2258 *valp
= *negp
? -*lvalp
: *lvalp
;
2263 *lvalp
= (unsigned long)-val
;
2266 *lvalp
= (unsigned long)val
;
2272 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2273 int write
, struct file
*filp
, void __user
*buffer
,
2274 size_t *lenp
, loff_t
*ppos
,
2275 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2276 int write
, void *data
),
2279 #define TMPBUFLEN 21
2280 int *i
, vleft
, first
=1, neg
, val
;
2284 char buf
[TMPBUFLEN
], *p
;
2285 char __user
*s
= buffer
;
2287 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
2288 (*ppos
&& !write
)) {
2293 i
= (int *) tbl_data
;
2294 vleft
= table
->maxlen
/ sizeof(*i
);
2298 conv
= do_proc_dointvec_conv
;
2300 for (; left
&& vleft
--; i
++, first
=0) {
2315 if (len
> sizeof(buf
) - 1)
2316 len
= sizeof(buf
) - 1;
2317 if (copy_from_user(buf
, s
, len
))
2321 if (*p
== '-' && left
> 1) {
2325 if (*p
< '0' || *p
> '9')
2328 lval
= simple_strtoul(p
, &p
, 0);
2331 if ((len
< left
) && *p
&& !isspace(*p
))
2338 if (conv(&neg
, &lval
, i
, 1, data
))
2345 if (conv(&neg
, &lval
, i
, 0, data
))
2348 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2352 if(copy_to_user(s
, buf
, len
))
2359 if (!write
&& !first
&& left
) {
2360 if(put_user('\n', s
))
2367 if (get_user(c
, s
++))
2382 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2383 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2384 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2385 int write
, void *data
),
2388 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2389 buffer
, lenp
, ppos
, conv
, data
);
2393 * proc_dointvec - read a vector of integers
2394 * @table: the sysctl table
2395 * @write: %TRUE if this is a write to the sysctl file
2396 * @filp: the file structure
2397 * @buffer: the user buffer
2398 * @lenp: the size of the user buffer
2399 * @ppos: file position
2401 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2402 * values from/to the user buffer, treated as an ASCII string.
2404 * Returns 0 on success.
2406 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2407 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2409 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2414 * Taint values can only be increased
2415 * This means we can safely use a temporary.
2417 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2418 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2421 unsigned long tmptaint
= get_taint();
2424 if (write
&& !capable(CAP_SYS_ADMIN
))
2429 err
= proc_doulongvec_minmax(&t
, write
, filp
, buffer
, lenp
, ppos
);
2435 * Poor man's atomic or. Not worth adding a primitive
2436 * to everyone's atomic.h for this
2439 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2440 if ((tmptaint
>> i
) & 1)
2448 struct do_proc_dointvec_minmax_conv_param
{
2453 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2455 int write
, void *data
)
2457 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2459 int val
= *negp
? -*lvalp
: *lvalp
;
2460 if ((param
->min
&& *param
->min
> val
) ||
2461 (param
->max
&& *param
->max
< val
))
2468 *lvalp
= (unsigned long)-val
;
2471 *lvalp
= (unsigned long)val
;
2478 * proc_dointvec_minmax - read a vector of integers with min/max values
2479 * @table: the sysctl table
2480 * @write: %TRUE if this is a write to the sysctl file
2481 * @filp: the file structure
2482 * @buffer: the user buffer
2483 * @lenp: the size of the user buffer
2484 * @ppos: file position
2486 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2487 * values from/to the user buffer, treated as an ASCII string.
2489 * This routine will ensure the values are within the range specified by
2490 * table->extra1 (min) and table->extra2 (max).
2492 * Returns 0 on success.
2494 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2495 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2497 struct do_proc_dointvec_minmax_conv_param param
= {
2498 .min
= (int *) table
->extra1
,
2499 .max
= (int *) table
->extra2
,
2501 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2502 do_proc_dointvec_minmax_conv
, ¶m
);
2505 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2507 void __user
*buffer
,
2508 size_t *lenp
, loff_t
*ppos
,
2509 unsigned long convmul
,
2510 unsigned long convdiv
)
2512 #define TMPBUFLEN 21
2513 unsigned long *i
, *min
, *max
, val
;
2514 int vleft
, first
=1, neg
;
2516 char buf
[TMPBUFLEN
], *p
;
2517 char __user
*s
= buffer
;
2519 if (!data
|| !table
->maxlen
|| !*lenp
||
2520 (*ppos
&& !write
)) {
2525 i
= (unsigned long *) data
;
2526 min
= (unsigned long *) table
->extra1
;
2527 max
= (unsigned long *) table
->extra2
;
2528 vleft
= table
->maxlen
/ sizeof(unsigned long);
2531 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2546 if (len
> TMPBUFLEN
-1)
2548 if (copy_from_user(buf
, s
, len
))
2552 if (*p
== '-' && left
> 1) {
2556 if (*p
< '0' || *p
> '9')
2558 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2560 if ((len
< left
) && *p
&& !isspace(*p
))
2569 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2576 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2580 if(copy_to_user(s
, buf
, len
))
2587 if (!write
&& !first
&& left
) {
2588 if(put_user('\n', s
))
2595 if (get_user(c
, s
++))
2610 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2612 void __user
*buffer
,
2613 size_t *lenp
, loff_t
*ppos
,
2614 unsigned long convmul
,
2615 unsigned long convdiv
)
2617 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2618 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2622 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2623 * @table: the sysctl table
2624 * @write: %TRUE if this is a write to the sysctl file
2625 * @filp: the file structure
2626 * @buffer: the user buffer
2627 * @lenp: the size of the user buffer
2628 * @ppos: file position
2630 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2631 * values from/to the user buffer, treated as an ASCII string.
2633 * This routine will ensure the values are within the range specified by
2634 * table->extra1 (min) and table->extra2 (max).
2636 * Returns 0 on success.
2638 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2639 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2641 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2645 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values 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. The values
2655 * are treated as milliseconds, and converted to jiffies when they are stored.
2657 * This routine will ensure the values are within the range specified by
2658 * table->extra1 (min) and table->extra2 (max).
2660 * Returns 0 on success.
2662 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2664 void __user
*buffer
,
2665 size_t *lenp
, loff_t
*ppos
)
2667 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2668 lenp
, ppos
, HZ
, 1000l);
2672 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2674 int write
, void *data
)
2677 if (*lvalp
> LONG_MAX
/ HZ
)
2679 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2685 lval
= (unsigned long)-val
;
2688 lval
= (unsigned long)val
;
2695 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2697 int write
, void *data
)
2700 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2702 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2708 lval
= (unsigned long)-val
;
2711 lval
= (unsigned long)val
;
2713 *lvalp
= jiffies_to_clock_t(lval
);
2718 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2720 int write
, void *data
)
2723 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2729 lval
= (unsigned long)-val
;
2732 lval
= (unsigned long)val
;
2734 *lvalp
= jiffies_to_msecs(lval
);
2740 * proc_dointvec_jiffies - read a vector of integers as seconds
2741 * @table: the sysctl table
2742 * @write: %TRUE if this is a write to the sysctl file
2743 * @filp: the file structure
2744 * @buffer: the user buffer
2745 * @lenp: the size of the user buffer
2746 * @ppos: file position
2748 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2749 * values from/to the user buffer, treated as an ASCII string.
2750 * The values read are assumed to be in seconds, and are converted into
2753 * Returns 0 on success.
2755 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2756 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2758 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2759 do_proc_dointvec_jiffies_conv
,NULL
);
2763 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ 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: pointer to the 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 1/USER_HZ seconds, and
2774 * are converted into jiffies.
2776 * Returns 0 on success.
2778 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2779 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2781 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2782 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2786 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
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: file position
2793 * @ppos: the current position in the file
2795 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2796 * values from/to the user buffer, treated as an ASCII string.
2797 * The values read are assumed to be in 1/1000 seconds, and
2798 * are converted into jiffies.
2800 * Returns 0 on success.
2802 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2803 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2805 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2806 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2809 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2810 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2812 struct pid
*new_pid
;
2816 tmp
= pid_vnr(cad_pid
);
2818 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2819 lenp
, ppos
, NULL
, NULL
);
2823 new_pid
= find_get_pid(tmp
);
2827 put_pid(xchg(&cad_pid
, new_pid
));
2831 #else /* CONFIG_PROC_FS */
2833 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2834 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2839 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2840 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2845 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2846 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2851 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2852 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2857 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2858 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2863 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2864 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2869 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2870 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2875 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2877 void __user
*buffer
,
2878 size_t *lenp
, loff_t
*ppos
)
2884 #endif /* CONFIG_PROC_FS */
2887 #ifdef CONFIG_SYSCTL_SYSCALL
2889 * General sysctl support routines
2892 /* The generic sysctl data routine (used if no strategy routine supplied) */
2893 int sysctl_data(struct ctl_table
*table
,
2894 void __user
*oldval
, size_t __user
*oldlenp
,
2895 void __user
*newval
, size_t newlen
)
2899 /* Get out of I don't have a variable */
2900 if (!table
->data
|| !table
->maxlen
)
2903 if (oldval
&& oldlenp
) {
2904 if (get_user(len
, oldlenp
))
2907 if (len
> table
->maxlen
)
2908 len
= table
->maxlen
;
2909 if (copy_to_user(oldval
, table
->data
, len
))
2911 if (put_user(len
, oldlenp
))
2916 if (newval
&& newlen
) {
2917 if (newlen
> table
->maxlen
)
2918 newlen
= table
->maxlen
;
2920 if (copy_from_user(table
->data
, newval
, newlen
))
2926 /* The generic string strategy routine: */
2927 int sysctl_string(struct ctl_table
*table
,
2928 void __user
*oldval
, size_t __user
*oldlenp
,
2929 void __user
*newval
, size_t newlen
)
2931 if (!table
->data
|| !table
->maxlen
)
2934 if (oldval
&& oldlenp
) {
2936 if (get_user(bufsize
, oldlenp
))
2939 size_t len
= strlen(table
->data
), copied
;
2941 /* This shouldn't trigger for a well-formed sysctl */
2942 if (len
> table
->maxlen
)
2943 len
= table
->maxlen
;
2945 /* Copy up to a max of bufsize-1 bytes of the string */
2946 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2948 if (copy_to_user(oldval
, table
->data
, copied
) ||
2949 put_user(0, (char __user
*)(oldval
+ copied
)))
2951 if (put_user(len
, oldlenp
))
2955 if (newval
&& newlen
) {
2956 size_t len
= newlen
;
2957 if (len
> table
->maxlen
)
2958 len
= table
->maxlen
;
2959 if(copy_from_user(table
->data
, newval
, len
))
2961 if (len
== table
->maxlen
)
2963 ((char *) table
->data
)[len
] = 0;
2969 * This function makes sure that all of the integers in the vector
2970 * are between the minimum and maximum values given in the arrays
2971 * table->extra1 and table->extra2, respectively.
2973 int sysctl_intvec(struct ctl_table
*table
,
2974 void __user
*oldval
, size_t __user
*oldlenp
,
2975 void __user
*newval
, size_t newlen
)
2978 if (newval
&& newlen
) {
2979 int __user
*vec
= (int __user
*) newval
;
2980 int *min
= (int *) table
->extra1
;
2981 int *max
= (int *) table
->extra2
;
2985 if (newlen
% sizeof(int) != 0)
2988 if (!table
->extra1
&& !table
->extra2
)
2991 if (newlen
> table
->maxlen
)
2992 newlen
= table
->maxlen
;
2993 length
= newlen
/ sizeof(int);
2995 for (i
= 0; i
< length
; i
++) {
2997 if (get_user(value
, vec
+ i
))
2999 if (min
&& value
< min
[i
])
3001 if (max
&& value
> max
[i
])
3008 /* Strategy function to convert jiffies to seconds */
3009 int sysctl_jiffies(struct ctl_table
*table
,
3010 void __user
*oldval
, size_t __user
*oldlenp
,
3011 void __user
*newval
, size_t newlen
)
3013 if (oldval
&& oldlenp
) {
3016 if (get_user(olen
, oldlenp
))
3021 if (olen
< sizeof(int))
3024 val
= *(int *)(table
->data
) / HZ
;
3025 if (put_user(val
, (int __user
*)oldval
))
3027 if (put_user(sizeof(int), oldlenp
))
3031 if (newval
&& newlen
) {
3033 if (newlen
!= sizeof(int))
3035 if (get_user(new, (int __user
*)newval
))
3037 *(int *)(table
->data
) = new*HZ
;
3042 /* Strategy function to convert jiffies to seconds */
3043 int sysctl_ms_jiffies(struct ctl_table
*table
,
3044 void __user
*oldval
, size_t __user
*oldlenp
,
3045 void __user
*newval
, size_t newlen
)
3047 if (oldval
&& oldlenp
) {
3050 if (get_user(olen
, oldlenp
))
3055 if (olen
< sizeof(int))
3058 val
= jiffies_to_msecs(*(int *)(table
->data
));
3059 if (put_user(val
, (int __user
*)oldval
))
3061 if (put_user(sizeof(int), oldlenp
))
3065 if (newval
&& newlen
) {
3067 if (newlen
!= sizeof(int))
3069 if (get_user(new, (int __user
*)newval
))
3071 *(int *)(table
->data
) = msecs_to_jiffies(new);
3078 #else /* CONFIG_SYSCTL_SYSCALL */
3081 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
3083 struct __sysctl_args tmp
;
3086 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
3089 error
= deprecated_sysctl_warning(&tmp
);
3091 /* If no error reading the parameters then just -ENOSYS ... */
3098 int sysctl_data(struct ctl_table
*table
,
3099 void __user
*oldval
, size_t __user
*oldlenp
,
3100 void __user
*newval
, size_t newlen
)
3105 int sysctl_string(struct ctl_table
*table
,
3106 void __user
*oldval
, size_t __user
*oldlenp
,
3107 void __user
*newval
, size_t newlen
)
3112 int sysctl_intvec(struct ctl_table
*table
,
3113 void __user
*oldval
, size_t __user
*oldlenp
,
3114 void __user
*newval
, size_t newlen
)
3119 int sysctl_jiffies(struct ctl_table
*table
,
3120 void __user
*oldval
, size_t __user
*oldlenp
,
3121 void __user
*newval
, size_t newlen
)
3126 int sysctl_ms_jiffies(struct ctl_table
*table
,
3127 void __user
*oldval
, size_t __user
*oldlenp
,
3128 void __user
*newval
, size_t newlen
)
3133 #endif /* CONFIG_SYSCTL_SYSCALL */
3135 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
3137 static int msg_count
;
3138 int name
[CTL_MAXNAME
];
3141 /* Check args->nlen. */
3142 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
3145 /* Read in the sysctl name for better debug message logging */
3146 for (i
= 0; i
< args
->nlen
; i
++)
3147 if (get_user(name
[i
], args
->name
+ i
))
3150 /* Ignore accesses to kernel.version */
3151 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
3154 if (msg_count
< 5) {
3157 "warning: process `%s' used the deprecated sysctl "
3158 "system call with ", current
->comm
);
3159 for (i
= 0; i
< args
->nlen
; i
++)
3160 printk("%d.", name
[i
]);
3167 * No sense putting this after each symbol definition, twice,
3168 * exception granted :-)
3170 EXPORT_SYMBOL(proc_dointvec
);
3171 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3172 EXPORT_SYMBOL(proc_dointvec_minmax
);
3173 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3174 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3175 EXPORT_SYMBOL(proc_dostring
);
3176 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3177 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
3178 EXPORT_SYMBOL(register_sysctl_table
);
3179 EXPORT_SYMBOL(register_sysctl_paths
);
3180 EXPORT_SYMBOL(sysctl_intvec
);
3181 EXPORT_SYMBOL(sysctl_jiffies
);
3182 EXPORT_SYMBOL(sysctl_ms_jiffies
);
3183 EXPORT_SYMBOL(sysctl_string
);
3184 EXPORT_SYMBOL(sysctl_data
);
3185 EXPORT_SYMBOL(unregister_sysctl_table
);