2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/proc_fs.h>
27 #include <linux/security.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/hugetlb.h>
40 #include <linux/initrd.h>
41 #include <linux/key.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/vmstat.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/acpi.h>
49 #include <linux/reboot.h>
50 #include <linux/ftrace.h>
51 #include <linux/slow-work.h>
53 #include <asm/uaccess.h>
54 #include <asm/processor.h>
58 #include <asm/stacktrace.h>
62 static int deprecated_sysctl_warning(struct __sysctl_args
*args
);
64 #if defined(CONFIG_SYSCTL)
66 /* External variables not in a header file. */
68 extern int print_fatal_signals
;
69 extern int sysctl_overcommit_memory
;
70 extern int sysctl_overcommit_ratio
;
71 extern int sysctl_panic_on_oom
;
72 extern int sysctl_oom_kill_allocating_task
;
73 extern int sysctl_oom_dump_tasks
;
74 extern int max_threads
;
75 extern int core_uses_pid
;
76 extern int suid_dumpable
;
77 extern char core_pattern
[];
79 extern int min_free_kbytes
;
80 extern int pid_max_min
, pid_max_max
;
81 extern int sysctl_drop_caches
;
82 extern int percpu_pagelist_fraction
;
83 extern int compat_log
;
84 extern int latencytop_enabled
;
85 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
87 extern int sysctl_nr_trim_pages
;
89 #ifdef CONFIG_RCU_TORTURE_TEST
90 extern int rcutorture_runnable
;
91 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
93 /* Constants used for minimum and maximum */
94 #ifdef CONFIG_DETECT_SOFTLOCKUP
95 static int sixty
= 60;
96 static int neg_one
= -1;
100 static int __maybe_unused one
= 1;
101 static int __maybe_unused two
= 2;
102 static unsigned long one_ul
= 1;
103 static int one_hundred
= 100;
104 static int one_thousand
= 1000;
106 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
107 static int maxolduid
= 65535;
108 static int minolduid
;
109 static int min_percpu_pagelist_fract
= 8;
111 static int ngroups_max
= NGROUPS_MAX
;
113 #ifdef CONFIG_MODULES
114 extern char modprobe_path
[];
116 #ifdef CONFIG_CHR_DEV_SG
117 extern int sg_big_buff
;
121 #include <asm/system.h>
124 #ifdef CONFIG_SPARC64
125 extern int sysctl_tsb_ratio
;
129 extern int pwrsw_enabled
;
130 extern int unaligned_enabled
;
134 #ifdef CONFIG_MATHEMU
135 extern int sysctl_ieee_emulation_warnings
;
137 extern int sysctl_userprocess_debug
;
138 extern int spin_retry
;
141 #ifdef CONFIG_BSD_PROCESS_ACCT
142 extern int acct_parm
[];
146 extern int no_unaligned_warning
;
147 extern int unaligned_dump_stack
;
150 #ifdef CONFIG_RT_MUTEXES
151 extern int max_lock_depth
;
154 #ifdef CONFIG_PROC_SYSCTL
155 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
156 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
157 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
158 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
161 static struct ctl_table root_table
[];
162 static struct ctl_table_root sysctl_table_root
;
163 static struct ctl_table_header root_table_header
= {
165 .ctl_table
= root_table
,
166 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),
167 .root
= &sysctl_table_root
,
168 .set
= &sysctl_table_root
.default_set
,
170 static struct ctl_table_root sysctl_table_root
= {
171 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
172 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
175 static struct ctl_table kern_table
[];
176 static struct ctl_table vm_table
[];
177 static struct ctl_table fs_table
[];
178 static struct ctl_table debug_table
[];
179 static struct ctl_table dev_table
[];
180 extern struct ctl_table random_table
[];
181 #ifdef CONFIG_INOTIFY_USER
182 extern struct ctl_table inotify_table
[];
185 extern struct ctl_table epoll_table
[];
188 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
189 int sysctl_legacy_va_layout
;
192 extern int prove_locking
;
193 extern int lock_stat
;
195 /* The default sysctl tables: */
197 static struct ctl_table root_table
[] = {
199 .ctl_name
= CTL_KERN
,
200 .procname
= "kernel",
217 .ctl_name
= CTL_DEBUG
,
220 .child
= debug_table
,
229 * NOTE: do not add new entries to this table unless you have read
230 * Documentation/sysctl/ctl_unnumbered.txt
235 #ifdef CONFIG_SCHED_DEBUG
236 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
237 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
238 static int min_wakeup_granularity_ns
; /* 0 usecs */
239 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
242 static struct ctl_table kern_table
[] = {
243 #ifdef CONFIG_SCHED_DEBUG
245 .ctl_name
= CTL_UNNUMBERED
,
246 .procname
= "sched_min_granularity_ns",
247 .data
= &sysctl_sched_min_granularity
,
248 .maxlen
= sizeof(unsigned int),
250 .proc_handler
= &sched_nr_latency_handler
,
251 .strategy
= &sysctl_intvec
,
252 .extra1
= &min_sched_granularity_ns
,
253 .extra2
= &max_sched_granularity_ns
,
256 .ctl_name
= CTL_UNNUMBERED
,
257 .procname
= "sched_latency_ns",
258 .data
= &sysctl_sched_latency
,
259 .maxlen
= sizeof(unsigned int),
261 .proc_handler
= &sched_nr_latency_handler
,
262 .strategy
= &sysctl_intvec
,
263 .extra1
= &min_sched_granularity_ns
,
264 .extra2
= &max_sched_granularity_ns
,
267 .ctl_name
= CTL_UNNUMBERED
,
268 .procname
= "sched_wakeup_granularity_ns",
269 .data
= &sysctl_sched_wakeup_granularity
,
270 .maxlen
= sizeof(unsigned int),
272 .proc_handler
= &proc_dointvec_minmax
,
273 .strategy
= &sysctl_intvec
,
274 .extra1
= &min_wakeup_granularity_ns
,
275 .extra2
= &max_wakeup_granularity_ns
,
278 .ctl_name
= CTL_UNNUMBERED
,
279 .procname
= "sched_shares_ratelimit",
280 .data
= &sysctl_sched_shares_ratelimit
,
281 .maxlen
= sizeof(unsigned int),
283 .proc_handler
= &proc_dointvec
,
286 .ctl_name
= CTL_UNNUMBERED
,
287 .procname
= "sched_shares_thresh",
288 .data
= &sysctl_sched_shares_thresh
,
289 .maxlen
= sizeof(unsigned int),
291 .proc_handler
= &proc_dointvec_minmax
,
292 .strategy
= &sysctl_intvec
,
296 .ctl_name
= CTL_UNNUMBERED
,
297 .procname
= "sched_child_runs_first",
298 .data
= &sysctl_sched_child_runs_first
,
299 .maxlen
= sizeof(unsigned int),
301 .proc_handler
= &proc_dointvec
,
304 .ctl_name
= CTL_UNNUMBERED
,
305 .procname
= "sched_features",
306 .data
= &sysctl_sched_features
,
307 .maxlen
= sizeof(unsigned int),
309 .proc_handler
= &proc_dointvec
,
312 .ctl_name
= CTL_UNNUMBERED
,
313 .procname
= "sched_migration_cost",
314 .data
= &sysctl_sched_migration_cost
,
315 .maxlen
= sizeof(unsigned int),
317 .proc_handler
= &proc_dointvec
,
320 .ctl_name
= CTL_UNNUMBERED
,
321 .procname
= "sched_nr_migrate",
322 .data
= &sysctl_sched_nr_migrate
,
323 .maxlen
= sizeof(unsigned int),
325 .proc_handler
= &proc_dointvec
,
329 .ctl_name
= CTL_UNNUMBERED
,
330 .procname
= "sched_rt_period_us",
331 .data
= &sysctl_sched_rt_period
,
332 .maxlen
= sizeof(unsigned int),
334 .proc_handler
= &sched_rt_handler
,
337 .ctl_name
= CTL_UNNUMBERED
,
338 .procname
= "sched_rt_runtime_us",
339 .data
= &sysctl_sched_rt_runtime
,
340 .maxlen
= sizeof(int),
342 .proc_handler
= &sched_rt_handler
,
345 .ctl_name
= CTL_UNNUMBERED
,
346 .procname
= "sched_compat_yield",
347 .data
= &sysctl_sched_compat_yield
,
348 .maxlen
= sizeof(unsigned int),
350 .proc_handler
= &proc_dointvec
,
352 #ifdef CONFIG_PROVE_LOCKING
354 .ctl_name
= CTL_UNNUMBERED
,
355 .procname
= "prove_locking",
356 .data
= &prove_locking
,
357 .maxlen
= sizeof(int),
359 .proc_handler
= &proc_dointvec
,
362 #ifdef CONFIG_LOCK_STAT
364 .ctl_name
= CTL_UNNUMBERED
,
365 .procname
= "lock_stat",
367 .maxlen
= sizeof(int),
369 .proc_handler
= &proc_dointvec
,
373 .ctl_name
= KERN_PANIC
,
375 .data
= &panic_timeout
,
376 .maxlen
= sizeof(int),
378 .proc_handler
= &proc_dointvec
,
381 .ctl_name
= KERN_CORE_USES_PID
,
382 .procname
= "core_uses_pid",
383 .data
= &core_uses_pid
,
384 .maxlen
= sizeof(int),
386 .proc_handler
= &proc_dointvec
,
389 .ctl_name
= KERN_CORE_PATTERN
,
390 .procname
= "core_pattern",
391 .data
= core_pattern
,
392 .maxlen
= CORENAME_MAX_SIZE
,
394 .proc_handler
= &proc_dostring
,
395 .strategy
= &sysctl_string
,
397 #ifdef CONFIG_PROC_SYSCTL
399 .procname
= "tainted",
400 .maxlen
= sizeof(long),
402 .proc_handler
= &proc_taint
,
405 #ifdef CONFIG_LATENCYTOP
407 .procname
= "latencytop",
408 .data
= &latencytop_enabled
,
409 .maxlen
= sizeof(int),
411 .proc_handler
= &proc_dointvec
,
414 #ifdef CONFIG_BLK_DEV_INITRD
416 .ctl_name
= KERN_REALROOTDEV
,
417 .procname
= "real-root-dev",
418 .data
= &real_root_dev
,
419 .maxlen
= sizeof(int),
421 .proc_handler
= &proc_dointvec
,
425 .ctl_name
= CTL_UNNUMBERED
,
426 .procname
= "print-fatal-signals",
427 .data
= &print_fatal_signals
,
428 .maxlen
= sizeof(int),
430 .proc_handler
= &proc_dointvec
,
434 .ctl_name
= KERN_SPARC_REBOOT
,
435 .procname
= "reboot-cmd",
436 .data
= reboot_command
,
439 .proc_handler
= &proc_dostring
,
440 .strategy
= &sysctl_string
,
443 .ctl_name
= KERN_SPARC_STOP_A
,
444 .procname
= "stop-a",
445 .data
= &stop_a_enabled
,
446 .maxlen
= sizeof (int),
448 .proc_handler
= &proc_dointvec
,
451 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
452 .procname
= "scons-poweroff",
453 .data
= &scons_pwroff
,
454 .maxlen
= sizeof (int),
456 .proc_handler
= &proc_dointvec
,
459 #ifdef CONFIG_SPARC64
461 .ctl_name
= CTL_UNNUMBERED
,
462 .procname
= "tsb-ratio",
463 .data
= &sysctl_tsb_ratio
,
464 .maxlen
= sizeof (int),
466 .proc_handler
= &proc_dointvec
,
471 .ctl_name
= KERN_HPPA_PWRSW
,
472 .procname
= "soft-power",
473 .data
= &pwrsw_enabled
,
474 .maxlen
= sizeof (int),
476 .proc_handler
= &proc_dointvec
,
479 .ctl_name
= KERN_HPPA_UNALIGNED
,
480 .procname
= "unaligned-trap",
481 .data
= &unaligned_enabled
,
482 .maxlen
= sizeof (int),
484 .proc_handler
= &proc_dointvec
,
488 .ctl_name
= KERN_CTLALTDEL
,
489 .procname
= "ctrl-alt-del",
491 .maxlen
= sizeof(int),
493 .proc_handler
= &proc_dointvec
,
495 #ifdef CONFIG_FUNCTION_TRACER
497 .ctl_name
= CTL_UNNUMBERED
,
498 .procname
= "ftrace_enabled",
499 .data
= &ftrace_enabled
,
500 .maxlen
= sizeof(int),
502 .proc_handler
= &ftrace_enable_sysctl
,
505 #ifdef CONFIG_STACK_TRACER
507 .ctl_name
= CTL_UNNUMBERED
,
508 .procname
= "stack_tracer_enabled",
509 .data
= &stack_tracer_enabled
,
510 .maxlen
= sizeof(int),
512 .proc_handler
= &stack_trace_sysctl
,
515 #ifdef CONFIG_TRACING
517 .ctl_name
= CTL_UNNUMBERED
,
518 .procname
= "ftrace_dump_on_oops",
519 .data
= &ftrace_dump_on_oops
,
520 .maxlen
= sizeof(int),
522 .proc_handler
= &proc_dointvec
,
525 #ifdef CONFIG_MODULES
527 .ctl_name
= KERN_MODPROBE
,
528 .procname
= "modprobe",
529 .data
= &modprobe_path
,
530 .maxlen
= KMOD_PATH_LEN
,
532 .proc_handler
= &proc_dostring
,
533 .strategy
= &sysctl_string
,
536 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
538 .ctl_name
= KERN_HOTPLUG
,
539 .procname
= "hotplug",
540 .data
= &uevent_helper
,
541 .maxlen
= UEVENT_HELPER_PATH_LEN
,
543 .proc_handler
= &proc_dostring
,
544 .strategy
= &sysctl_string
,
547 #ifdef CONFIG_CHR_DEV_SG
549 .ctl_name
= KERN_SG_BIG_BUFF
,
550 .procname
= "sg-big-buff",
551 .data
= &sg_big_buff
,
552 .maxlen
= sizeof (int),
554 .proc_handler
= &proc_dointvec
,
557 #ifdef CONFIG_BSD_PROCESS_ACCT
559 .ctl_name
= KERN_ACCT
,
562 .maxlen
= 3*sizeof(int),
564 .proc_handler
= &proc_dointvec
,
567 #ifdef CONFIG_MAGIC_SYSRQ
569 .ctl_name
= KERN_SYSRQ
,
571 .data
= &__sysrq_enabled
,
572 .maxlen
= sizeof (int),
574 .proc_handler
= &proc_dointvec
,
577 #ifdef CONFIG_PROC_SYSCTL
579 .procname
= "cad_pid",
581 .maxlen
= sizeof (int),
583 .proc_handler
= &proc_do_cad_pid
,
587 .ctl_name
= KERN_MAX_THREADS
,
588 .procname
= "threads-max",
589 .data
= &max_threads
,
590 .maxlen
= sizeof(int),
592 .proc_handler
= &proc_dointvec
,
595 .ctl_name
= KERN_RANDOM
,
596 .procname
= "random",
598 .child
= random_table
,
601 .ctl_name
= KERN_OVERFLOWUID
,
602 .procname
= "overflowuid",
603 .data
= &overflowuid
,
604 .maxlen
= sizeof(int),
606 .proc_handler
= &proc_dointvec_minmax
,
607 .strategy
= &sysctl_intvec
,
608 .extra1
= &minolduid
,
609 .extra2
= &maxolduid
,
612 .ctl_name
= KERN_OVERFLOWGID
,
613 .procname
= "overflowgid",
614 .data
= &overflowgid
,
615 .maxlen
= sizeof(int),
617 .proc_handler
= &proc_dointvec_minmax
,
618 .strategy
= &sysctl_intvec
,
619 .extra1
= &minolduid
,
620 .extra2
= &maxolduid
,
623 #ifdef CONFIG_MATHEMU
625 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
626 .procname
= "ieee_emulation_warnings",
627 .data
= &sysctl_ieee_emulation_warnings
,
628 .maxlen
= sizeof(int),
630 .proc_handler
= &proc_dointvec
,
634 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
635 .procname
= "userprocess_debug",
636 .data
= &sysctl_userprocess_debug
,
637 .maxlen
= sizeof(int),
639 .proc_handler
= &proc_dointvec
,
643 .ctl_name
= KERN_PIDMAX
,
644 .procname
= "pid_max",
646 .maxlen
= sizeof (int),
648 .proc_handler
= &proc_dointvec_minmax
,
649 .strategy
= sysctl_intvec
,
650 .extra1
= &pid_max_min
,
651 .extra2
= &pid_max_max
,
654 .ctl_name
= KERN_PANIC_ON_OOPS
,
655 .procname
= "panic_on_oops",
656 .data
= &panic_on_oops
,
657 .maxlen
= sizeof(int),
659 .proc_handler
= &proc_dointvec
,
661 #if defined CONFIG_PRINTK
663 .ctl_name
= KERN_PRINTK
,
664 .procname
= "printk",
665 .data
= &console_loglevel
,
666 .maxlen
= 4*sizeof(int),
668 .proc_handler
= &proc_dointvec
,
671 .ctl_name
= KERN_PRINTK_RATELIMIT
,
672 .procname
= "printk_ratelimit",
673 .data
= &printk_ratelimit_state
.interval
,
674 .maxlen
= sizeof(int),
676 .proc_handler
= &proc_dointvec_jiffies
,
677 .strategy
= &sysctl_jiffies
,
680 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
681 .procname
= "printk_ratelimit_burst",
682 .data
= &printk_ratelimit_state
.burst
,
683 .maxlen
= sizeof(int),
685 .proc_handler
= &proc_dointvec
,
689 .ctl_name
= KERN_NGROUPS_MAX
,
690 .procname
= "ngroups_max",
691 .data
= &ngroups_max
,
692 .maxlen
= sizeof (int),
694 .proc_handler
= &proc_dointvec
,
696 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
698 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
699 .procname
= "unknown_nmi_panic",
700 .data
= &unknown_nmi_panic
,
701 .maxlen
= sizeof (int),
703 .proc_handler
= &proc_dointvec
,
706 .procname
= "nmi_watchdog",
707 .data
= &nmi_watchdog_enabled
,
708 .maxlen
= sizeof (int),
710 .proc_handler
= &proc_nmi_enabled
,
713 #if defined(CONFIG_X86)
715 .ctl_name
= KERN_PANIC_ON_NMI
,
716 .procname
= "panic_on_unrecovered_nmi",
717 .data
= &panic_on_unrecovered_nmi
,
718 .maxlen
= sizeof(int),
720 .proc_handler
= &proc_dointvec
,
723 .ctl_name
= KERN_BOOTLOADER_TYPE
,
724 .procname
= "bootloader_type",
725 .data
= &bootloader_type
,
726 .maxlen
= sizeof (int),
728 .proc_handler
= &proc_dointvec
,
731 .ctl_name
= CTL_UNNUMBERED
,
732 .procname
= "kstack_depth_to_print",
733 .data
= &kstack_depth_to_print
,
734 .maxlen
= sizeof(int),
736 .proc_handler
= &proc_dointvec
,
739 .ctl_name
= CTL_UNNUMBERED
,
740 .procname
= "io_delay_type",
741 .data
= &io_delay_type
,
742 .maxlen
= sizeof(int),
744 .proc_handler
= &proc_dointvec
,
747 #if defined(CONFIG_MMU)
749 .ctl_name
= KERN_RANDOMIZE
,
750 .procname
= "randomize_va_space",
751 .data
= &randomize_va_space
,
752 .maxlen
= sizeof(int),
754 .proc_handler
= &proc_dointvec
,
757 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
759 .ctl_name
= KERN_SPIN_RETRY
,
760 .procname
= "spin_retry",
762 .maxlen
= sizeof (int),
764 .proc_handler
= &proc_dointvec
,
767 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
769 .procname
= "acpi_video_flags",
770 .data
= &acpi_realmode_flags
,
771 .maxlen
= sizeof (unsigned long),
773 .proc_handler
= &proc_doulongvec_minmax
,
778 .ctl_name
= KERN_IA64_UNALIGNED
,
779 .procname
= "ignore-unaligned-usertrap",
780 .data
= &no_unaligned_warning
,
781 .maxlen
= sizeof (int),
783 .proc_handler
= &proc_dointvec
,
786 .ctl_name
= CTL_UNNUMBERED
,
787 .procname
= "unaligned-dump-stack",
788 .data
= &unaligned_dump_stack
,
789 .maxlen
= sizeof (int),
791 .proc_handler
= &proc_dointvec
,
794 #ifdef CONFIG_DETECT_SOFTLOCKUP
796 .ctl_name
= CTL_UNNUMBERED
,
797 .procname
= "softlockup_panic",
798 .data
= &softlockup_panic
,
799 .maxlen
= sizeof(int),
801 .proc_handler
= &proc_dointvec_minmax
,
802 .strategy
= &sysctl_intvec
,
807 .ctl_name
= CTL_UNNUMBERED
,
808 .procname
= "softlockup_thresh",
809 .data
= &softlockup_thresh
,
810 .maxlen
= sizeof(int),
812 .proc_handler
= &proc_dosoftlockup_thresh
,
813 .strategy
= &sysctl_intvec
,
818 .ctl_name
= CTL_UNNUMBERED
,
819 .procname
= "hung_task_check_count",
820 .data
= &sysctl_hung_task_check_count
,
821 .maxlen
= sizeof(unsigned long),
823 .proc_handler
= &proc_doulongvec_minmax
,
824 .strategy
= &sysctl_intvec
,
827 .ctl_name
= CTL_UNNUMBERED
,
828 .procname
= "hung_task_timeout_secs",
829 .data
= &sysctl_hung_task_timeout_secs
,
830 .maxlen
= sizeof(unsigned long),
832 .proc_handler
= &proc_doulongvec_minmax
,
833 .strategy
= &sysctl_intvec
,
836 .ctl_name
= CTL_UNNUMBERED
,
837 .procname
= "hung_task_warnings",
838 .data
= &sysctl_hung_task_warnings
,
839 .maxlen
= sizeof(unsigned long),
841 .proc_handler
= &proc_doulongvec_minmax
,
842 .strategy
= &sysctl_intvec
,
847 .ctl_name
= KERN_COMPAT_LOG
,
848 .procname
= "compat-log",
850 .maxlen
= sizeof (int),
852 .proc_handler
= &proc_dointvec
,
855 #ifdef CONFIG_RT_MUTEXES
857 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
858 .procname
= "max_lock_depth",
859 .data
= &max_lock_depth
,
860 .maxlen
= sizeof(int),
862 .proc_handler
= &proc_dointvec
,
866 .ctl_name
= CTL_UNNUMBERED
,
867 .procname
= "poweroff_cmd",
868 .data
= &poweroff_cmd
,
869 .maxlen
= POWEROFF_CMD_PATH_LEN
,
871 .proc_handler
= &proc_dostring
,
872 .strategy
= &sysctl_string
,
876 .ctl_name
= CTL_UNNUMBERED
,
879 .child
= key_sysctls
,
882 #ifdef CONFIG_RCU_TORTURE_TEST
884 .ctl_name
= CTL_UNNUMBERED
,
885 .procname
= "rcutorture_runnable",
886 .data
= &rcutorture_runnable
,
887 .maxlen
= sizeof(int),
889 .proc_handler
= &proc_dointvec
,
892 #ifdef CONFIG_UNEVICTABLE_LRU
894 .ctl_name
= CTL_UNNUMBERED
,
895 .procname
= "scan_unevictable_pages",
896 .data
= &scan_unevictable_pages
,
897 .maxlen
= sizeof(scan_unevictable_pages
),
899 .proc_handler
= &scan_unevictable_handler
,
902 #ifdef CONFIG_SLOW_WORK
904 .ctl_name
= CTL_UNNUMBERED
,
905 .procname
= "slow-work",
907 .child
= slow_work_sysctls
,
911 * NOTE: do not add new entries to this table unless you have read
912 * Documentation/sysctl/ctl_unnumbered.txt
917 static struct ctl_table vm_table
[] = {
919 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
920 .procname
= "overcommit_memory",
921 .data
= &sysctl_overcommit_memory
,
922 .maxlen
= sizeof(sysctl_overcommit_memory
),
924 .proc_handler
= &proc_dointvec
,
927 .ctl_name
= VM_PANIC_ON_OOM
,
928 .procname
= "panic_on_oom",
929 .data
= &sysctl_panic_on_oom
,
930 .maxlen
= sizeof(sysctl_panic_on_oom
),
932 .proc_handler
= &proc_dointvec
,
935 .ctl_name
= CTL_UNNUMBERED
,
936 .procname
= "oom_kill_allocating_task",
937 .data
= &sysctl_oom_kill_allocating_task
,
938 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
940 .proc_handler
= &proc_dointvec
,
943 .ctl_name
= CTL_UNNUMBERED
,
944 .procname
= "oom_dump_tasks",
945 .data
= &sysctl_oom_dump_tasks
,
946 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
948 .proc_handler
= &proc_dointvec
,
951 .ctl_name
= VM_OVERCOMMIT_RATIO
,
952 .procname
= "overcommit_ratio",
953 .data
= &sysctl_overcommit_ratio
,
954 .maxlen
= sizeof(sysctl_overcommit_ratio
),
956 .proc_handler
= &proc_dointvec
,
959 .ctl_name
= VM_PAGE_CLUSTER
,
960 .procname
= "page-cluster",
961 .data
= &page_cluster
,
962 .maxlen
= sizeof(int),
964 .proc_handler
= &proc_dointvec
,
967 .ctl_name
= VM_DIRTY_BACKGROUND
,
968 .procname
= "dirty_background_ratio",
969 .data
= &dirty_background_ratio
,
970 .maxlen
= sizeof(dirty_background_ratio
),
972 .proc_handler
= &dirty_background_ratio_handler
,
973 .strategy
= &sysctl_intvec
,
975 .extra2
= &one_hundred
,
978 .ctl_name
= CTL_UNNUMBERED
,
979 .procname
= "dirty_background_bytes",
980 .data
= &dirty_background_bytes
,
981 .maxlen
= sizeof(dirty_background_bytes
),
983 .proc_handler
= &dirty_background_bytes_handler
,
984 .strategy
= &sysctl_intvec
,
988 .ctl_name
= VM_DIRTY_RATIO
,
989 .procname
= "dirty_ratio",
990 .data
= &vm_dirty_ratio
,
991 .maxlen
= sizeof(vm_dirty_ratio
),
993 .proc_handler
= &dirty_ratio_handler
,
994 .strategy
= &sysctl_intvec
,
996 .extra2
= &one_hundred
,
999 .ctl_name
= CTL_UNNUMBERED
,
1000 .procname
= "dirty_bytes",
1001 .data
= &vm_dirty_bytes
,
1002 .maxlen
= sizeof(vm_dirty_bytes
),
1004 .proc_handler
= &dirty_bytes_handler
,
1005 .strategy
= &sysctl_intvec
,
1009 .procname
= "dirty_writeback_centisecs",
1010 .data
= &dirty_writeback_interval
,
1011 .maxlen
= sizeof(dirty_writeback_interval
),
1013 .proc_handler
= &dirty_writeback_centisecs_handler
,
1016 .procname
= "dirty_expire_centisecs",
1017 .data
= &dirty_expire_interval
,
1018 .maxlen
= sizeof(dirty_expire_interval
),
1020 .proc_handler
= &proc_dointvec
,
1023 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
1024 .procname
= "nr_pdflush_threads",
1025 .data
= &nr_pdflush_threads
,
1026 .maxlen
= sizeof nr_pdflush_threads
,
1027 .mode
= 0444 /* read-only*/,
1028 .proc_handler
= &proc_dointvec
,
1031 .ctl_name
= CTL_UNNUMBERED
,
1032 .procname
= "nr_pdflush_threads_min",
1033 .data
= &nr_pdflush_threads_min
,
1034 .maxlen
= sizeof nr_pdflush_threads_min
,
1035 .mode
= 0644 /* read-write */,
1036 .proc_handler
= &proc_dointvec_minmax
,
1037 .strategy
= &sysctl_intvec
,
1039 .extra2
= &nr_pdflush_threads_max
,
1042 .ctl_name
= CTL_UNNUMBERED
,
1043 .procname
= "nr_pdflush_threads_max",
1044 .data
= &nr_pdflush_threads_max
,
1045 .maxlen
= sizeof nr_pdflush_threads_max
,
1046 .mode
= 0644 /* read-write */,
1047 .proc_handler
= &proc_dointvec_minmax
,
1048 .strategy
= &sysctl_intvec
,
1049 .extra1
= &nr_pdflush_threads_min
,
1050 .extra2
= &one_thousand
,
1053 .ctl_name
= VM_SWAPPINESS
,
1054 .procname
= "swappiness",
1055 .data
= &vm_swappiness
,
1056 .maxlen
= sizeof(vm_swappiness
),
1058 .proc_handler
= &proc_dointvec_minmax
,
1059 .strategy
= &sysctl_intvec
,
1061 .extra2
= &one_hundred
,
1063 #ifdef CONFIG_HUGETLB_PAGE
1065 .procname
= "nr_hugepages",
1067 .maxlen
= sizeof(unsigned long),
1069 .proc_handler
= &hugetlb_sysctl_handler
,
1070 .extra1
= (void *)&hugetlb_zero
,
1071 .extra2
= (void *)&hugetlb_infinity
,
1074 .ctl_name
= VM_HUGETLB_GROUP
,
1075 .procname
= "hugetlb_shm_group",
1076 .data
= &sysctl_hugetlb_shm_group
,
1077 .maxlen
= sizeof(gid_t
),
1079 .proc_handler
= &proc_dointvec
,
1082 .ctl_name
= CTL_UNNUMBERED
,
1083 .procname
= "hugepages_treat_as_movable",
1084 .data
= &hugepages_treat_as_movable
,
1085 .maxlen
= sizeof(int),
1087 .proc_handler
= &hugetlb_treat_movable_handler
,
1090 .ctl_name
= CTL_UNNUMBERED
,
1091 .procname
= "nr_overcommit_hugepages",
1093 .maxlen
= sizeof(unsigned long),
1095 .proc_handler
= &hugetlb_overcommit_handler
,
1096 .extra1
= (void *)&hugetlb_zero
,
1097 .extra2
= (void *)&hugetlb_infinity
,
1101 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
1102 .procname
= "lowmem_reserve_ratio",
1103 .data
= &sysctl_lowmem_reserve_ratio
,
1104 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1106 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
1107 .strategy
= &sysctl_intvec
,
1110 .ctl_name
= VM_DROP_PAGECACHE
,
1111 .procname
= "drop_caches",
1112 .data
= &sysctl_drop_caches
,
1113 .maxlen
= sizeof(int),
1115 .proc_handler
= drop_caches_sysctl_handler
,
1116 .strategy
= &sysctl_intvec
,
1119 .ctl_name
= VM_MIN_FREE_KBYTES
,
1120 .procname
= "min_free_kbytes",
1121 .data
= &min_free_kbytes
,
1122 .maxlen
= sizeof(min_free_kbytes
),
1124 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1125 .strategy
= &sysctl_intvec
,
1129 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1130 .procname
= "percpu_pagelist_fraction",
1131 .data
= &percpu_pagelist_fraction
,
1132 .maxlen
= sizeof(percpu_pagelist_fraction
),
1134 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1135 .strategy
= &sysctl_intvec
,
1136 .extra1
= &min_percpu_pagelist_fract
,
1140 .ctl_name
= VM_MAX_MAP_COUNT
,
1141 .procname
= "max_map_count",
1142 .data
= &sysctl_max_map_count
,
1143 .maxlen
= sizeof(sysctl_max_map_count
),
1145 .proc_handler
= &proc_dointvec
1149 .ctl_name
= CTL_UNNUMBERED
,
1150 .procname
= "nr_trim_pages",
1151 .data
= &sysctl_nr_trim_pages
,
1152 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1154 .proc_handler
= &proc_dointvec_minmax
,
1155 .strategy
= &sysctl_intvec
,
1160 .ctl_name
= VM_LAPTOP_MODE
,
1161 .procname
= "laptop_mode",
1162 .data
= &laptop_mode
,
1163 .maxlen
= sizeof(laptop_mode
),
1165 .proc_handler
= &proc_dointvec_jiffies
,
1166 .strategy
= &sysctl_jiffies
,
1169 .ctl_name
= VM_BLOCK_DUMP
,
1170 .procname
= "block_dump",
1171 .data
= &block_dump
,
1172 .maxlen
= sizeof(block_dump
),
1174 .proc_handler
= &proc_dointvec
,
1175 .strategy
= &sysctl_intvec
,
1179 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1180 .procname
= "vfs_cache_pressure",
1181 .data
= &sysctl_vfs_cache_pressure
,
1182 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1184 .proc_handler
= &proc_dointvec
,
1185 .strategy
= &sysctl_intvec
,
1188 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1190 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1191 .procname
= "legacy_va_layout",
1192 .data
= &sysctl_legacy_va_layout
,
1193 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1195 .proc_handler
= &proc_dointvec
,
1196 .strategy
= &sysctl_intvec
,
1202 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1203 .procname
= "zone_reclaim_mode",
1204 .data
= &zone_reclaim_mode
,
1205 .maxlen
= sizeof(zone_reclaim_mode
),
1207 .proc_handler
= &proc_dointvec
,
1208 .strategy
= &sysctl_intvec
,
1212 .ctl_name
= VM_MIN_UNMAPPED
,
1213 .procname
= "min_unmapped_ratio",
1214 .data
= &sysctl_min_unmapped_ratio
,
1215 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1217 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1218 .strategy
= &sysctl_intvec
,
1220 .extra2
= &one_hundred
,
1223 .ctl_name
= VM_MIN_SLAB
,
1224 .procname
= "min_slab_ratio",
1225 .data
= &sysctl_min_slab_ratio
,
1226 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1228 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1229 .strategy
= &sysctl_intvec
,
1231 .extra2
= &one_hundred
,
1236 .ctl_name
= CTL_UNNUMBERED
,
1237 .procname
= "stat_interval",
1238 .data
= &sysctl_stat_interval
,
1239 .maxlen
= sizeof(sysctl_stat_interval
),
1241 .proc_handler
= &proc_dointvec_jiffies
,
1242 .strategy
= &sysctl_jiffies
,
1245 #ifdef CONFIG_SECURITY
1247 .ctl_name
= CTL_UNNUMBERED
,
1248 .procname
= "mmap_min_addr",
1249 .data
= &mmap_min_addr
,
1250 .maxlen
= sizeof(unsigned long),
1252 .proc_handler
= &proc_doulongvec_minmax
,
1257 .ctl_name
= CTL_UNNUMBERED
,
1258 .procname
= "numa_zonelist_order",
1259 .data
= &numa_zonelist_order
,
1260 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1262 .proc_handler
= &numa_zonelist_order_handler
,
1263 .strategy
= &sysctl_string
,
1266 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1267 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1269 .ctl_name
= VM_VDSO_ENABLED
,
1270 .procname
= "vdso_enabled",
1271 .data
= &vdso_enabled
,
1272 .maxlen
= sizeof(vdso_enabled
),
1274 .proc_handler
= &proc_dointvec
,
1275 .strategy
= &sysctl_intvec
,
1279 #ifdef CONFIG_HIGHMEM
1281 .ctl_name
= CTL_UNNUMBERED
,
1282 .procname
= "highmem_is_dirtyable",
1283 .data
= &vm_highmem_is_dirtyable
,
1284 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1286 .proc_handler
= &proc_dointvec_minmax
,
1287 .strategy
= &sysctl_intvec
,
1293 * NOTE: do not add new entries to this table unless you have read
1294 * Documentation/sysctl/ctl_unnumbered.txt
1299 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1300 static struct ctl_table binfmt_misc_table
[] = {
1305 static struct ctl_table fs_table
[] = {
1307 .ctl_name
= FS_NRINODE
,
1308 .procname
= "inode-nr",
1309 .data
= &inodes_stat
,
1310 .maxlen
= 2*sizeof(int),
1312 .proc_handler
= &proc_dointvec
,
1315 .ctl_name
= FS_STATINODE
,
1316 .procname
= "inode-state",
1317 .data
= &inodes_stat
,
1318 .maxlen
= 7*sizeof(int),
1320 .proc_handler
= &proc_dointvec
,
1323 .procname
= "file-nr",
1324 .data
= &files_stat
,
1325 .maxlen
= 3*sizeof(int),
1327 .proc_handler
= &proc_nr_files
,
1330 .ctl_name
= FS_MAXFILE
,
1331 .procname
= "file-max",
1332 .data
= &files_stat
.max_files
,
1333 .maxlen
= sizeof(int),
1335 .proc_handler
= &proc_dointvec
,
1338 .ctl_name
= CTL_UNNUMBERED
,
1339 .procname
= "nr_open",
1340 .data
= &sysctl_nr_open
,
1341 .maxlen
= sizeof(int),
1343 .proc_handler
= &proc_dointvec_minmax
,
1344 .extra1
= &sysctl_nr_open_min
,
1345 .extra2
= &sysctl_nr_open_max
,
1348 .ctl_name
= FS_DENTRY
,
1349 .procname
= "dentry-state",
1350 .data
= &dentry_stat
,
1351 .maxlen
= 6*sizeof(int),
1353 .proc_handler
= &proc_dointvec
,
1356 .ctl_name
= FS_OVERFLOWUID
,
1357 .procname
= "overflowuid",
1358 .data
= &fs_overflowuid
,
1359 .maxlen
= sizeof(int),
1361 .proc_handler
= &proc_dointvec_minmax
,
1362 .strategy
= &sysctl_intvec
,
1363 .extra1
= &minolduid
,
1364 .extra2
= &maxolduid
,
1367 .ctl_name
= FS_OVERFLOWGID
,
1368 .procname
= "overflowgid",
1369 .data
= &fs_overflowgid
,
1370 .maxlen
= sizeof(int),
1372 .proc_handler
= &proc_dointvec_minmax
,
1373 .strategy
= &sysctl_intvec
,
1374 .extra1
= &minolduid
,
1375 .extra2
= &maxolduid
,
1377 #ifdef CONFIG_FILE_LOCKING
1379 .ctl_name
= FS_LEASES
,
1380 .procname
= "leases-enable",
1381 .data
= &leases_enable
,
1382 .maxlen
= sizeof(int),
1384 .proc_handler
= &proc_dointvec
,
1387 #ifdef CONFIG_DNOTIFY
1389 .ctl_name
= FS_DIR_NOTIFY
,
1390 .procname
= "dir-notify-enable",
1391 .data
= &dir_notify_enable
,
1392 .maxlen
= sizeof(int),
1394 .proc_handler
= &proc_dointvec
,
1398 #ifdef CONFIG_FILE_LOCKING
1400 .ctl_name
= FS_LEASE_TIME
,
1401 .procname
= "lease-break-time",
1402 .data
= &lease_break_time
,
1403 .maxlen
= sizeof(int),
1405 .proc_handler
= &proc_dointvec
,
1410 .procname
= "aio-nr",
1412 .maxlen
= sizeof(aio_nr
),
1414 .proc_handler
= &proc_doulongvec_minmax
,
1417 .procname
= "aio-max-nr",
1418 .data
= &aio_max_nr
,
1419 .maxlen
= sizeof(aio_max_nr
),
1421 .proc_handler
= &proc_doulongvec_minmax
,
1423 #endif /* CONFIG_AIO */
1424 #ifdef CONFIG_INOTIFY_USER
1426 .ctl_name
= FS_INOTIFY
,
1427 .procname
= "inotify",
1429 .child
= inotify_table
,
1434 .procname
= "epoll",
1436 .child
= epoll_table
,
1441 .ctl_name
= KERN_SETUID_DUMPABLE
,
1442 .procname
= "suid_dumpable",
1443 .data
= &suid_dumpable
,
1444 .maxlen
= sizeof(int),
1446 .proc_handler
= &proc_dointvec_minmax
,
1447 .strategy
= &sysctl_intvec
,
1451 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1453 .ctl_name
= CTL_UNNUMBERED
,
1454 .procname
= "binfmt_misc",
1456 .child
= binfmt_misc_table
,
1460 * NOTE: do not add new entries to this table unless you have read
1461 * Documentation/sysctl/ctl_unnumbered.txt
1466 static struct ctl_table debug_table
[] = {
1467 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1469 .ctl_name
= CTL_UNNUMBERED
,
1470 .procname
= "exception-trace",
1471 .data
= &show_unhandled_signals
,
1472 .maxlen
= sizeof(int),
1474 .proc_handler
= proc_dointvec
1480 static struct ctl_table dev_table
[] = {
1484 static DEFINE_SPINLOCK(sysctl_lock
);
1486 /* called under sysctl_lock */
1487 static int use_table(struct ctl_table_header
*p
)
1489 if (unlikely(p
->unregistering
))
1495 /* called under sysctl_lock */
1496 static void unuse_table(struct ctl_table_header
*p
)
1499 if (unlikely(p
->unregistering
))
1500 complete(p
->unregistering
);
1503 /* called under sysctl_lock, will reacquire if has to wait */
1504 static void start_unregistering(struct ctl_table_header
*p
)
1507 * if p->used is 0, nobody will ever touch that entry again;
1508 * we'll eliminate all paths to it before dropping sysctl_lock
1510 if (unlikely(p
->used
)) {
1511 struct completion wait
;
1512 init_completion(&wait
);
1513 p
->unregistering
= &wait
;
1514 spin_unlock(&sysctl_lock
);
1515 wait_for_completion(&wait
);
1516 spin_lock(&sysctl_lock
);
1518 /* anything non-NULL; we'll never dereference it */
1519 p
->unregistering
= ERR_PTR(-EINVAL
);
1522 * do not remove from the list until nobody holds it; walking the
1523 * list in do_sysctl() relies on that.
1525 list_del_init(&p
->ctl_entry
);
1528 void sysctl_head_get(struct ctl_table_header
*head
)
1530 spin_lock(&sysctl_lock
);
1532 spin_unlock(&sysctl_lock
);
1535 void sysctl_head_put(struct ctl_table_header
*head
)
1537 spin_lock(&sysctl_lock
);
1540 spin_unlock(&sysctl_lock
);
1543 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1547 spin_lock(&sysctl_lock
);
1548 if (!use_table(head
))
1549 head
= ERR_PTR(-ENOENT
);
1550 spin_unlock(&sysctl_lock
);
1554 void sysctl_head_finish(struct ctl_table_header
*head
)
1558 spin_lock(&sysctl_lock
);
1560 spin_unlock(&sysctl_lock
);
1563 static struct ctl_table_set
*
1564 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1566 struct ctl_table_set
*set
= &root
->default_set
;
1568 set
= root
->lookup(root
, namespaces
);
1572 static struct list_head
*
1573 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1575 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1579 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1580 struct ctl_table_header
*prev
)
1582 struct ctl_table_root
*root
;
1583 struct list_head
*header_list
;
1584 struct ctl_table_header
*head
;
1585 struct list_head
*tmp
;
1587 spin_lock(&sysctl_lock
);
1590 tmp
= &prev
->ctl_entry
;
1594 tmp
= &root_table_header
.ctl_entry
;
1596 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1598 if (!use_table(head
))
1600 spin_unlock(&sysctl_lock
);
1605 header_list
= lookup_header_list(root
, namespaces
);
1606 if (tmp
!= header_list
)
1610 root
= list_entry(root
->root_list
.next
,
1611 struct ctl_table_root
, root_list
);
1612 if (root
== &sysctl_table_root
)
1614 header_list
= lookup_header_list(root
, namespaces
);
1615 } while (list_empty(header_list
));
1616 tmp
= header_list
->next
;
1619 spin_unlock(&sysctl_lock
);
1623 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1625 return __sysctl_head_next(current
->nsproxy
, prev
);
1628 void register_sysctl_root(struct ctl_table_root
*root
)
1630 spin_lock(&sysctl_lock
);
1631 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1632 spin_unlock(&sysctl_lock
);
1635 #ifdef CONFIG_SYSCTL_SYSCALL
1636 /* Perform the actual read/write of a sysctl table entry. */
1637 static int do_sysctl_strategy(struct ctl_table_root
*root
,
1638 struct ctl_table
*table
,
1639 void __user
*oldval
, size_t __user
*oldlenp
,
1640 void __user
*newval
, size_t newlen
)
1648 if (sysctl_perm(root
, table
, op
))
1651 if (table
->strategy
) {
1652 rc
= table
->strategy(table
, oldval
, oldlenp
, newval
, newlen
);
1659 /* If there is no strategy routine, or if the strategy returns
1660 * zero, proceed with automatic r/w */
1661 if (table
->data
&& table
->maxlen
) {
1662 rc
= sysctl_data(table
, oldval
, oldlenp
, newval
, newlen
);
1669 static int parse_table(int __user
*name
, int nlen
,
1670 void __user
*oldval
, size_t __user
*oldlenp
,
1671 void __user
*newval
, size_t newlen
,
1672 struct ctl_table_root
*root
,
1673 struct ctl_table
*table
)
1679 if (get_user(n
, name
))
1681 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1682 if (!table
->ctl_name
)
1684 if (n
== table
->ctl_name
) {
1687 if (sysctl_perm(root
, table
, MAY_EXEC
))
1691 table
= table
->child
;
1694 error
= do_sysctl_strategy(root
, table
,
1703 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1704 void __user
*newval
, size_t newlen
)
1706 struct ctl_table_header
*head
;
1707 int error
= -ENOTDIR
;
1709 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1713 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1717 for (head
= sysctl_head_next(NULL
); head
;
1718 head
= sysctl_head_next(head
)) {
1719 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1721 head
->root
, head
->ctl_table
);
1722 if (error
!= -ENOTDIR
) {
1723 sysctl_head_finish(head
);
1730 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
1732 struct __sysctl_args tmp
;
1735 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1738 error
= deprecated_sysctl_warning(&tmp
);
1743 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1744 tmp
.newval
, tmp
.newlen
);
1749 #endif /* CONFIG_SYSCTL_SYSCALL */
1752 * sysctl_perm does NOT grant the superuser all rights automatically, because
1753 * some sysctl variables are readonly even to root.
1756 static int test_perm(int mode
, int op
)
1758 if (!current_euid())
1760 else if (in_egroup_p(0))
1762 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1767 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1772 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1776 if (root
->permissions
)
1777 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1781 return test_perm(mode
, op
);
1784 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1786 for (; table
->ctl_name
|| table
->procname
; table
++) {
1787 table
->parent
= parent
;
1789 sysctl_set_parent(table
, table
->child
);
1793 static __init
int sysctl_init(void)
1795 sysctl_set_parent(NULL
, root_table
);
1796 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1799 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1805 core_initcall(sysctl_init
);
1807 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1808 struct ctl_table
*table
)
1810 struct ctl_table
*p
;
1811 const char *s
= branch
->procname
;
1813 /* branch should have named subdirectory as its first element */
1814 if (!s
|| !branch
->child
)
1817 /* ... and nothing else */
1818 if (branch
[1].procname
|| branch
[1].ctl_name
)
1821 /* table should contain subdirectory with the same name */
1822 for (p
= table
; p
->procname
|| p
->ctl_name
; p
++) {
1825 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1831 /* see if attaching q to p would be an improvement */
1832 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1834 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1835 struct ctl_table
*next
;
1837 int not_in_parent
= !p
->attached_by
;
1839 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1840 if (by
== q
->attached_by
)
1842 if (to
== p
->attached_by
)
1848 if (is_better
&& not_in_parent
) {
1849 q
->attached_by
= by
;
1850 q
->attached_to
= to
;
1856 * __register_sysctl_paths - register a sysctl hierarchy
1857 * @root: List of sysctl headers to register on
1858 * @namespaces: Data to compute which lists of sysctl entries are visible
1859 * @path: The path to the directory the sysctl table is in.
1860 * @table: the top-level table structure
1862 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1863 * array. A completely 0 filled entry terminates the table.
1865 * The members of the &struct ctl_table structure are used as follows:
1867 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1868 * must be unique within that level of sysctl
1870 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1871 * enter a sysctl file
1873 * data - a pointer to data for use by proc_handler
1875 * maxlen - the maximum size in bytes of the data
1877 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1879 * child - a pointer to the child sysctl table if this entry is a directory, or
1882 * proc_handler - the text handler routine (described below)
1884 * strategy - the strategy routine (described below)
1886 * de - for internal use by the sysctl routines
1888 * extra1, extra2 - extra pointers usable by the proc handler routines
1890 * Leaf nodes in the sysctl tree will be represented by a single file
1891 * under /proc; non-leaf nodes will be represented by directories.
1893 * sysctl(2) can automatically manage read and write requests through
1894 * the sysctl table. The data and maxlen fields of the ctl_table
1895 * struct enable minimal validation of the values being written to be
1896 * performed, and the mode field allows minimal authentication.
1898 * More sophisticated management can be enabled by the provision of a
1899 * strategy routine with the table entry. This will be called before
1900 * any automatic read or write of the data is performed.
1902 * The strategy routine may return
1904 * < 0 - Error occurred (error is passed to user process)
1906 * 0 - OK - proceed with automatic read or write.
1908 * > 0 - OK - read or write has been done by the strategy routine, so
1909 * return immediately.
1911 * There must be a proc_handler routine for any terminal nodes
1912 * mirrored under /proc/sys (non-terminals are handled by a built-in
1913 * directory handler). Several default handlers are available to
1914 * cover common cases -
1916 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1917 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1918 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1920 * It is the handler's job to read the input buffer from user memory
1921 * and process it. The handler should return 0 on success.
1923 * This routine returns %NULL on a failure to register, and a pointer
1924 * to the table header on success.
1926 struct ctl_table_header
*__register_sysctl_paths(
1927 struct ctl_table_root
*root
,
1928 struct nsproxy
*namespaces
,
1929 const struct ctl_path
*path
, struct ctl_table
*table
)
1931 struct ctl_table_header
*header
;
1932 struct ctl_table
*new, **prevp
;
1933 unsigned int n
, npath
;
1934 struct ctl_table_set
*set
;
1936 /* Count the path components */
1937 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
1941 * For each path component, allocate a 2-element ctl_table array.
1942 * The first array element will be filled with the sysctl entry
1943 * for this, the second will be the sentinel (ctl_name == 0).
1945 * We allocate everything in one go so that we don't have to
1946 * worry about freeing additional memory in unregister_sysctl_table.
1948 header
= kzalloc(sizeof(struct ctl_table_header
) +
1949 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1953 new = (struct ctl_table
*) (header
+ 1);
1955 /* Now connect the dots */
1956 prevp
= &header
->ctl_table
;
1957 for (n
= 0; n
< npath
; ++n
, ++path
) {
1958 /* Copy the procname */
1959 new->procname
= path
->procname
;
1960 new->ctl_name
= path
->ctl_name
;
1964 prevp
= &new->child
;
1969 header
->ctl_table_arg
= table
;
1971 INIT_LIST_HEAD(&header
->ctl_entry
);
1973 header
->unregistering
= NULL
;
1974 header
->root
= root
;
1975 sysctl_set_parent(NULL
, header
->ctl_table
);
1977 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1978 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1983 spin_lock(&sysctl_lock
);
1984 header
->set
= lookup_header_set(root
, namespaces
);
1985 header
->attached_by
= header
->ctl_table
;
1986 header
->attached_to
= root_table
;
1987 header
->parent
= &root_table_header
;
1988 for (set
= header
->set
; set
; set
= set
->parent
) {
1989 struct ctl_table_header
*p
;
1990 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
1991 if (p
->unregistering
)
1993 try_attach(p
, header
);
1996 header
->parent
->count
++;
1997 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
1998 spin_unlock(&sysctl_lock
);
2004 * register_sysctl_table_path - register a sysctl table hierarchy
2005 * @path: The path to the directory the sysctl table is in.
2006 * @table: the top-level table structure
2008 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2009 * array. A completely 0 filled entry terminates the table.
2011 * See __register_sysctl_paths for more details.
2013 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2014 struct ctl_table
*table
)
2016 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
2021 * register_sysctl_table - register a sysctl table hierarchy
2022 * @table: the top-level table structure
2024 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2025 * array. A completely 0 filled entry terminates the table.
2027 * See register_sysctl_paths for more details.
2029 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
2031 static const struct ctl_path null_path
[] = { {} };
2033 return register_sysctl_paths(null_path
, table
);
2037 * unregister_sysctl_table - unregister a sysctl table hierarchy
2038 * @header: the header returned from register_sysctl_table
2040 * Unregisters the sysctl table and all children. proc entries may not
2041 * actually be removed until they are no longer used by anyone.
2043 void unregister_sysctl_table(struct ctl_table_header
* header
)
2050 spin_lock(&sysctl_lock
);
2051 start_unregistering(header
);
2052 if (!--header
->parent
->count
) {
2054 kfree(header
->parent
);
2056 if (!--header
->count
)
2058 spin_unlock(&sysctl_lock
);
2061 int sysctl_is_seen(struct ctl_table_header
*p
)
2063 struct ctl_table_set
*set
= p
->set
;
2065 spin_lock(&sysctl_lock
);
2066 if (p
->unregistering
)
2068 else if (!set
->is_seen
)
2071 res
= set
->is_seen(set
);
2072 spin_unlock(&sysctl_lock
);
2076 void setup_sysctl_set(struct ctl_table_set
*p
,
2077 struct ctl_table_set
*parent
,
2078 int (*is_seen
)(struct ctl_table_set
*))
2080 INIT_LIST_HEAD(&p
->list
);
2081 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
2082 p
->is_seen
= is_seen
;
2085 #else /* !CONFIG_SYSCTL */
2086 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
2091 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2092 struct ctl_table
*table
)
2097 void unregister_sysctl_table(struct ctl_table_header
* table
)
2101 void setup_sysctl_set(struct ctl_table_set
*p
,
2102 struct ctl_table_set
*parent
,
2103 int (*is_seen
)(struct ctl_table_set
*))
2107 void sysctl_head_put(struct ctl_table_header
*head
)
2111 #endif /* CONFIG_SYSCTL */
2117 #ifdef CONFIG_PROC_SYSCTL
2119 static int _proc_do_string(void* data
, int maxlen
, int write
,
2120 struct file
*filp
, void __user
*buffer
,
2121 size_t *lenp
, loff_t
*ppos
)
2127 if (!data
|| !maxlen
|| !*lenp
) {
2135 while (len
< *lenp
) {
2136 if (get_user(c
, p
++))
2138 if (c
== 0 || c
== '\n')
2144 if(copy_from_user(data
, buffer
, len
))
2146 ((char *) data
)[len
] = 0;
2164 if(copy_to_user(buffer
, data
, len
))
2167 if(put_user('\n', ((char __user
*) buffer
) + len
))
2178 * proc_dostring - read a string sysctl
2179 * @table: the sysctl table
2180 * @write: %TRUE if this is a write to the sysctl file
2181 * @filp: the file structure
2182 * @buffer: the user buffer
2183 * @lenp: the size of the user buffer
2184 * @ppos: file position
2186 * Reads/writes a string from/to the user buffer. If the kernel
2187 * buffer provided is not large enough to hold the string, the
2188 * string is truncated. The copied string is %NULL-terminated.
2189 * If the string is being read by the user process, it is copied
2190 * and a newline '\n' is added. It is truncated if the buffer is
2193 * Returns 0 on success.
2195 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2196 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2198 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
2199 buffer
, lenp
, ppos
);
2203 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
2205 int write
, void *data
)
2208 *valp
= *negp
? -*lvalp
: *lvalp
;
2213 *lvalp
= (unsigned long)-val
;
2216 *lvalp
= (unsigned long)val
;
2222 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2223 int write
, struct file
*filp
, void __user
*buffer
,
2224 size_t *lenp
, loff_t
*ppos
,
2225 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2226 int write
, void *data
),
2229 #define TMPBUFLEN 21
2230 int *i
, vleft
, first
=1, neg
, val
;
2234 char buf
[TMPBUFLEN
], *p
;
2235 char __user
*s
= buffer
;
2237 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
2238 (*ppos
&& !write
)) {
2243 i
= (int *) tbl_data
;
2244 vleft
= table
->maxlen
/ sizeof(*i
);
2248 conv
= do_proc_dointvec_conv
;
2250 for (; left
&& vleft
--; i
++, first
=0) {
2265 if (len
> sizeof(buf
) - 1)
2266 len
= sizeof(buf
) - 1;
2267 if (copy_from_user(buf
, s
, len
))
2271 if (*p
== '-' && left
> 1) {
2275 if (*p
< '0' || *p
> '9')
2278 lval
= simple_strtoul(p
, &p
, 0);
2281 if ((len
< left
) && *p
&& !isspace(*p
))
2288 if (conv(&neg
, &lval
, i
, 1, data
))
2295 if (conv(&neg
, &lval
, i
, 0, data
))
2298 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2302 if(copy_to_user(s
, buf
, len
))
2309 if (!write
&& !first
&& left
) {
2310 if(put_user('\n', s
))
2317 if (get_user(c
, s
++))
2332 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2333 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2334 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2335 int write
, void *data
),
2338 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2339 buffer
, lenp
, ppos
, conv
, data
);
2343 * proc_dointvec - read a vector of integers
2344 * @table: the sysctl table
2345 * @write: %TRUE if this is a write to the sysctl file
2346 * @filp: the file structure
2347 * @buffer: the user buffer
2348 * @lenp: the size of the user buffer
2349 * @ppos: file position
2351 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2352 * values from/to the user buffer, treated as an ASCII string.
2354 * Returns 0 on success.
2356 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2357 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2359 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2364 * Taint values can only be increased
2365 * This means we can safely use a temporary.
2367 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2368 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2371 unsigned long tmptaint
= get_taint();
2374 if (write
&& !capable(CAP_SYS_ADMIN
))
2379 err
= proc_doulongvec_minmax(&t
, write
, filp
, buffer
, lenp
, ppos
);
2385 * Poor man's atomic or. Not worth adding a primitive
2386 * to everyone's atomic.h for this
2389 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2390 if ((tmptaint
>> i
) & 1)
2398 struct do_proc_dointvec_minmax_conv_param
{
2403 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2405 int write
, void *data
)
2407 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2409 int val
= *negp
? -*lvalp
: *lvalp
;
2410 if ((param
->min
&& *param
->min
> val
) ||
2411 (param
->max
&& *param
->max
< val
))
2418 *lvalp
= (unsigned long)-val
;
2421 *lvalp
= (unsigned long)val
;
2428 * proc_dointvec_minmax - read a vector of integers with min/max values
2429 * @table: the sysctl table
2430 * @write: %TRUE if this is a write to the sysctl file
2431 * @filp: the file structure
2432 * @buffer: the user buffer
2433 * @lenp: the size of the user buffer
2434 * @ppos: file position
2436 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2437 * values from/to the user buffer, treated as an ASCII string.
2439 * This routine will ensure the values are within the range specified by
2440 * table->extra1 (min) and table->extra2 (max).
2442 * Returns 0 on success.
2444 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2445 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2447 struct do_proc_dointvec_minmax_conv_param param
= {
2448 .min
= (int *) table
->extra1
,
2449 .max
= (int *) table
->extra2
,
2451 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2452 do_proc_dointvec_minmax_conv
, ¶m
);
2455 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2457 void __user
*buffer
,
2458 size_t *lenp
, loff_t
*ppos
,
2459 unsigned long convmul
,
2460 unsigned long convdiv
)
2462 #define TMPBUFLEN 21
2463 unsigned long *i
, *min
, *max
, val
;
2464 int vleft
, first
=1, neg
;
2466 char buf
[TMPBUFLEN
], *p
;
2467 char __user
*s
= buffer
;
2469 if (!data
|| !table
->maxlen
|| !*lenp
||
2470 (*ppos
&& !write
)) {
2475 i
= (unsigned long *) data
;
2476 min
= (unsigned long *) table
->extra1
;
2477 max
= (unsigned long *) table
->extra2
;
2478 vleft
= table
->maxlen
/ sizeof(unsigned long);
2481 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2496 if (len
> TMPBUFLEN
-1)
2498 if (copy_from_user(buf
, s
, len
))
2502 if (*p
== '-' && left
> 1) {
2506 if (*p
< '0' || *p
> '9')
2508 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2510 if ((len
< left
) && *p
&& !isspace(*p
))
2519 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2526 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2530 if(copy_to_user(s
, buf
, len
))
2537 if (!write
&& !first
&& left
) {
2538 if(put_user('\n', s
))
2545 if (get_user(c
, s
++))
2560 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2562 void __user
*buffer
,
2563 size_t *lenp
, loff_t
*ppos
,
2564 unsigned long convmul
,
2565 unsigned long convdiv
)
2567 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2568 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2572 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2573 * @table: the sysctl table
2574 * @write: %TRUE if this is a write to the sysctl file
2575 * @filp: the file structure
2576 * @buffer: the user buffer
2577 * @lenp: the size of the user buffer
2578 * @ppos: file position
2580 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2581 * values from/to the user buffer, treated as an ASCII string.
2583 * This routine will ensure the values are within the range specified by
2584 * table->extra1 (min) and table->extra2 (max).
2586 * Returns 0 on success.
2588 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2589 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2591 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2595 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2596 * @table: the sysctl table
2597 * @write: %TRUE if this is a write to the sysctl file
2598 * @filp: the file structure
2599 * @buffer: the user buffer
2600 * @lenp: the size of the user buffer
2601 * @ppos: file position
2603 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2604 * values from/to the user buffer, treated as an ASCII string. The values
2605 * are treated as milliseconds, and converted to jiffies when they are stored.
2607 * This routine will ensure the values are within the range specified by
2608 * table->extra1 (min) and table->extra2 (max).
2610 * Returns 0 on success.
2612 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2614 void __user
*buffer
,
2615 size_t *lenp
, loff_t
*ppos
)
2617 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2618 lenp
, ppos
, HZ
, 1000l);
2622 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2624 int write
, void *data
)
2627 if (*lvalp
> LONG_MAX
/ HZ
)
2629 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2635 lval
= (unsigned long)-val
;
2638 lval
= (unsigned long)val
;
2645 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2647 int write
, void *data
)
2650 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2652 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2658 lval
= (unsigned long)-val
;
2661 lval
= (unsigned long)val
;
2663 *lvalp
= jiffies_to_clock_t(lval
);
2668 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2670 int write
, void *data
)
2673 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2679 lval
= (unsigned long)-val
;
2682 lval
= (unsigned long)val
;
2684 *lvalp
= jiffies_to_msecs(lval
);
2690 * proc_dointvec_jiffies - read a vector of integers as seconds
2691 * @table: the sysctl table
2692 * @write: %TRUE if this is a write to the sysctl file
2693 * @filp: the file structure
2694 * @buffer: the user buffer
2695 * @lenp: the size of the user buffer
2696 * @ppos: file position
2698 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2699 * values from/to the user buffer, treated as an ASCII string.
2700 * The values read are assumed to be in seconds, and are converted into
2703 * Returns 0 on success.
2705 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2706 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2708 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2709 do_proc_dointvec_jiffies_conv
,NULL
);
2713 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2714 * @table: the sysctl table
2715 * @write: %TRUE if this is a write to the sysctl file
2716 * @filp: the file structure
2717 * @buffer: the user buffer
2718 * @lenp: the size of the user buffer
2719 * @ppos: pointer to the file position
2721 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2722 * values from/to the user buffer, treated as an ASCII string.
2723 * The values read are assumed to be in 1/USER_HZ seconds, and
2724 * are converted into jiffies.
2726 * Returns 0 on success.
2728 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2729 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2731 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2732 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2736 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2737 * @table: the sysctl table
2738 * @write: %TRUE if this is a write to the sysctl file
2739 * @filp: the file structure
2740 * @buffer: the user buffer
2741 * @lenp: the size of the user buffer
2742 * @ppos: file position
2743 * @ppos: the current position in the file
2745 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2746 * values from/to the user buffer, treated as an ASCII string.
2747 * The values read are assumed to be in 1/1000 seconds, and
2748 * are converted into jiffies.
2750 * Returns 0 on success.
2752 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2753 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2755 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2756 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2759 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2760 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2762 struct pid
*new_pid
;
2766 tmp
= pid_vnr(cad_pid
);
2768 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2769 lenp
, ppos
, NULL
, NULL
);
2773 new_pid
= find_get_pid(tmp
);
2777 put_pid(xchg(&cad_pid
, new_pid
));
2781 #else /* CONFIG_PROC_FS */
2783 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2784 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2789 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2790 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2795 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2796 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2801 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2802 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2807 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2808 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2813 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2814 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2819 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2820 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2825 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2827 void __user
*buffer
,
2828 size_t *lenp
, loff_t
*ppos
)
2834 #endif /* CONFIG_PROC_FS */
2837 #ifdef CONFIG_SYSCTL_SYSCALL
2839 * General sysctl support routines
2842 /* The generic sysctl data routine (used if no strategy routine supplied) */
2843 int sysctl_data(struct ctl_table
*table
,
2844 void __user
*oldval
, size_t __user
*oldlenp
,
2845 void __user
*newval
, size_t newlen
)
2849 /* Get out of I don't have a variable */
2850 if (!table
->data
|| !table
->maxlen
)
2853 if (oldval
&& oldlenp
) {
2854 if (get_user(len
, oldlenp
))
2857 if (len
> table
->maxlen
)
2858 len
= table
->maxlen
;
2859 if (copy_to_user(oldval
, table
->data
, len
))
2861 if (put_user(len
, oldlenp
))
2866 if (newval
&& newlen
) {
2867 if (newlen
> table
->maxlen
)
2868 newlen
= table
->maxlen
;
2870 if (copy_from_user(table
->data
, newval
, newlen
))
2876 /* The generic string strategy routine: */
2877 int sysctl_string(struct ctl_table
*table
,
2878 void __user
*oldval
, size_t __user
*oldlenp
,
2879 void __user
*newval
, size_t newlen
)
2881 if (!table
->data
|| !table
->maxlen
)
2884 if (oldval
&& oldlenp
) {
2886 if (get_user(bufsize
, oldlenp
))
2889 size_t len
= strlen(table
->data
), copied
;
2891 /* This shouldn't trigger for a well-formed sysctl */
2892 if (len
> table
->maxlen
)
2893 len
= table
->maxlen
;
2895 /* Copy up to a max of bufsize-1 bytes of the string */
2896 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2898 if (copy_to_user(oldval
, table
->data
, copied
) ||
2899 put_user(0, (char __user
*)(oldval
+ copied
)))
2901 if (put_user(len
, oldlenp
))
2905 if (newval
&& newlen
) {
2906 size_t len
= newlen
;
2907 if (len
> table
->maxlen
)
2908 len
= table
->maxlen
;
2909 if(copy_from_user(table
->data
, newval
, len
))
2911 if (len
== table
->maxlen
)
2913 ((char *) table
->data
)[len
] = 0;
2919 * This function makes sure that all of the integers in the vector
2920 * are between the minimum and maximum values given in the arrays
2921 * table->extra1 and table->extra2, respectively.
2923 int sysctl_intvec(struct ctl_table
*table
,
2924 void __user
*oldval
, size_t __user
*oldlenp
,
2925 void __user
*newval
, size_t newlen
)
2928 if (newval
&& newlen
) {
2929 int __user
*vec
= (int __user
*) newval
;
2930 int *min
= (int *) table
->extra1
;
2931 int *max
= (int *) table
->extra2
;
2935 if (newlen
% sizeof(int) != 0)
2938 if (!table
->extra1
&& !table
->extra2
)
2941 if (newlen
> table
->maxlen
)
2942 newlen
= table
->maxlen
;
2943 length
= newlen
/ sizeof(int);
2945 for (i
= 0; i
< length
; i
++) {
2947 if (get_user(value
, vec
+ i
))
2949 if (min
&& value
< min
[i
])
2951 if (max
&& value
> max
[i
])
2958 /* Strategy function to convert jiffies to seconds */
2959 int sysctl_jiffies(struct ctl_table
*table
,
2960 void __user
*oldval
, size_t __user
*oldlenp
,
2961 void __user
*newval
, size_t newlen
)
2963 if (oldval
&& oldlenp
) {
2966 if (get_user(olen
, oldlenp
))
2971 if (olen
< sizeof(int))
2974 val
= *(int *)(table
->data
) / HZ
;
2975 if (put_user(val
, (int __user
*)oldval
))
2977 if (put_user(sizeof(int), oldlenp
))
2981 if (newval
&& newlen
) {
2983 if (newlen
!= sizeof(int))
2985 if (get_user(new, (int __user
*)newval
))
2987 *(int *)(table
->data
) = new*HZ
;
2992 /* Strategy function to convert jiffies to seconds */
2993 int sysctl_ms_jiffies(struct ctl_table
*table
,
2994 void __user
*oldval
, size_t __user
*oldlenp
,
2995 void __user
*newval
, size_t newlen
)
2997 if (oldval
&& oldlenp
) {
3000 if (get_user(olen
, oldlenp
))
3005 if (olen
< sizeof(int))
3008 val
= jiffies_to_msecs(*(int *)(table
->data
));
3009 if (put_user(val
, (int __user
*)oldval
))
3011 if (put_user(sizeof(int), oldlenp
))
3015 if (newval
&& newlen
) {
3017 if (newlen
!= sizeof(int))
3019 if (get_user(new, (int __user
*)newval
))
3021 *(int *)(table
->data
) = msecs_to_jiffies(new);
3028 #else /* CONFIG_SYSCTL_SYSCALL */
3031 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
3033 struct __sysctl_args tmp
;
3036 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
3039 error
= deprecated_sysctl_warning(&tmp
);
3041 /* If no error reading the parameters then just -ENOSYS ... */
3048 int sysctl_data(struct ctl_table
*table
,
3049 void __user
*oldval
, size_t __user
*oldlenp
,
3050 void __user
*newval
, size_t newlen
)
3055 int sysctl_string(struct ctl_table
*table
,
3056 void __user
*oldval
, size_t __user
*oldlenp
,
3057 void __user
*newval
, size_t newlen
)
3062 int sysctl_intvec(struct ctl_table
*table
,
3063 void __user
*oldval
, size_t __user
*oldlenp
,
3064 void __user
*newval
, size_t newlen
)
3069 int sysctl_jiffies(struct ctl_table
*table
,
3070 void __user
*oldval
, size_t __user
*oldlenp
,
3071 void __user
*newval
, size_t newlen
)
3076 int sysctl_ms_jiffies(struct ctl_table
*table
,
3077 void __user
*oldval
, size_t __user
*oldlenp
,
3078 void __user
*newval
, size_t newlen
)
3083 #endif /* CONFIG_SYSCTL_SYSCALL */
3085 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
3087 static int msg_count
;
3088 int name
[CTL_MAXNAME
];
3091 /* Check args->nlen. */
3092 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
3095 /* Read in the sysctl name for better debug message logging */
3096 for (i
= 0; i
< args
->nlen
; i
++)
3097 if (get_user(name
[i
], args
->name
+ i
))
3100 /* Ignore accesses to kernel.version */
3101 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
3104 if (msg_count
< 5) {
3107 "warning: process `%s' used the deprecated sysctl "
3108 "system call with ", current
->comm
);
3109 for (i
= 0; i
< args
->nlen
; i
++)
3110 printk("%d.", name
[i
]);
3117 * No sense putting this after each symbol definition, twice,
3118 * exception granted :-)
3120 EXPORT_SYMBOL(proc_dointvec
);
3121 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3122 EXPORT_SYMBOL(proc_dointvec_minmax
);
3123 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3124 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3125 EXPORT_SYMBOL(proc_dostring
);
3126 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3127 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
3128 EXPORT_SYMBOL(register_sysctl_table
);
3129 EXPORT_SYMBOL(register_sysctl_paths
);
3130 EXPORT_SYMBOL(sysctl_intvec
);
3131 EXPORT_SYMBOL(sysctl_jiffies
);
3132 EXPORT_SYMBOL(sysctl_ms_jiffies
);
3133 EXPORT_SYMBOL(sysctl_string
);
3134 EXPORT_SYMBOL(sysctl_data
);
3135 EXPORT_SYMBOL(unregister_sysctl_table
);