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 #ifdef CONFIG_DETECT_HUNG_TASK
820 .ctl_name
= CTL_UNNUMBERED
,
821 .procname
= "hung_task_panic",
822 .data
= &sysctl_hung_task_panic
,
823 .maxlen
= sizeof(int),
825 .proc_handler
= &proc_dointvec_minmax
,
826 .strategy
= &sysctl_intvec
,
831 .ctl_name
= CTL_UNNUMBERED
,
832 .procname
= "hung_task_check_count",
833 .data
= &sysctl_hung_task_check_count
,
834 .maxlen
= sizeof(unsigned long),
836 .proc_handler
= &proc_doulongvec_minmax
,
837 .strategy
= &sysctl_intvec
,
840 .ctl_name
= CTL_UNNUMBERED
,
841 .procname
= "hung_task_timeout_secs",
842 .data
= &sysctl_hung_task_timeout_secs
,
843 .maxlen
= sizeof(unsigned long),
845 .proc_handler
= &proc_dohung_task_timeout_secs
,
846 .strategy
= &sysctl_intvec
,
849 .ctl_name
= CTL_UNNUMBERED
,
850 .procname
= "hung_task_warnings",
851 .data
= &sysctl_hung_task_warnings
,
852 .maxlen
= sizeof(unsigned long),
854 .proc_handler
= &proc_doulongvec_minmax
,
855 .strategy
= &sysctl_intvec
,
860 .ctl_name
= KERN_COMPAT_LOG
,
861 .procname
= "compat-log",
863 .maxlen
= sizeof (int),
865 .proc_handler
= &proc_dointvec
,
868 #ifdef CONFIG_RT_MUTEXES
870 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
871 .procname
= "max_lock_depth",
872 .data
= &max_lock_depth
,
873 .maxlen
= sizeof(int),
875 .proc_handler
= &proc_dointvec
,
879 .ctl_name
= CTL_UNNUMBERED
,
880 .procname
= "poweroff_cmd",
881 .data
= &poweroff_cmd
,
882 .maxlen
= POWEROFF_CMD_PATH_LEN
,
884 .proc_handler
= &proc_dostring
,
885 .strategy
= &sysctl_string
,
889 .ctl_name
= CTL_UNNUMBERED
,
892 .child
= key_sysctls
,
895 #ifdef CONFIG_RCU_TORTURE_TEST
897 .ctl_name
= CTL_UNNUMBERED
,
898 .procname
= "rcutorture_runnable",
899 .data
= &rcutorture_runnable
,
900 .maxlen
= sizeof(int),
902 .proc_handler
= &proc_dointvec
,
905 #ifdef CONFIG_UNEVICTABLE_LRU
907 .ctl_name
= CTL_UNNUMBERED
,
908 .procname
= "scan_unevictable_pages",
909 .data
= &scan_unevictable_pages
,
910 .maxlen
= sizeof(scan_unevictable_pages
),
912 .proc_handler
= &scan_unevictable_handler
,
915 #ifdef CONFIG_SLOW_WORK
917 .ctl_name
= CTL_UNNUMBERED
,
918 .procname
= "slow-work",
920 .child
= slow_work_sysctls
,
924 * NOTE: do not add new entries to this table unless you have read
925 * Documentation/sysctl/ctl_unnumbered.txt
930 static struct ctl_table vm_table
[] = {
932 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
933 .procname
= "overcommit_memory",
934 .data
= &sysctl_overcommit_memory
,
935 .maxlen
= sizeof(sysctl_overcommit_memory
),
937 .proc_handler
= &proc_dointvec
,
940 .ctl_name
= VM_PANIC_ON_OOM
,
941 .procname
= "panic_on_oom",
942 .data
= &sysctl_panic_on_oom
,
943 .maxlen
= sizeof(sysctl_panic_on_oom
),
945 .proc_handler
= &proc_dointvec
,
948 .ctl_name
= CTL_UNNUMBERED
,
949 .procname
= "oom_kill_allocating_task",
950 .data
= &sysctl_oom_kill_allocating_task
,
951 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
953 .proc_handler
= &proc_dointvec
,
956 .ctl_name
= CTL_UNNUMBERED
,
957 .procname
= "oom_dump_tasks",
958 .data
= &sysctl_oom_dump_tasks
,
959 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
961 .proc_handler
= &proc_dointvec
,
964 .ctl_name
= VM_OVERCOMMIT_RATIO
,
965 .procname
= "overcommit_ratio",
966 .data
= &sysctl_overcommit_ratio
,
967 .maxlen
= sizeof(sysctl_overcommit_ratio
),
969 .proc_handler
= &proc_dointvec
,
972 .ctl_name
= VM_PAGE_CLUSTER
,
973 .procname
= "page-cluster",
974 .data
= &page_cluster
,
975 .maxlen
= sizeof(int),
977 .proc_handler
= &proc_dointvec
,
980 .ctl_name
= VM_DIRTY_BACKGROUND
,
981 .procname
= "dirty_background_ratio",
982 .data
= &dirty_background_ratio
,
983 .maxlen
= sizeof(dirty_background_ratio
),
985 .proc_handler
= &dirty_background_ratio_handler
,
986 .strategy
= &sysctl_intvec
,
988 .extra2
= &one_hundred
,
991 .ctl_name
= CTL_UNNUMBERED
,
992 .procname
= "dirty_background_bytes",
993 .data
= &dirty_background_bytes
,
994 .maxlen
= sizeof(dirty_background_bytes
),
996 .proc_handler
= &dirty_background_bytes_handler
,
997 .strategy
= &sysctl_intvec
,
1001 .ctl_name
= VM_DIRTY_RATIO
,
1002 .procname
= "dirty_ratio",
1003 .data
= &vm_dirty_ratio
,
1004 .maxlen
= sizeof(vm_dirty_ratio
),
1006 .proc_handler
= &dirty_ratio_handler
,
1007 .strategy
= &sysctl_intvec
,
1009 .extra2
= &one_hundred
,
1012 .ctl_name
= CTL_UNNUMBERED
,
1013 .procname
= "dirty_bytes",
1014 .data
= &vm_dirty_bytes
,
1015 .maxlen
= sizeof(vm_dirty_bytes
),
1017 .proc_handler
= &dirty_bytes_handler
,
1018 .strategy
= &sysctl_intvec
,
1022 .procname
= "dirty_writeback_centisecs",
1023 .data
= &dirty_writeback_interval
,
1024 .maxlen
= sizeof(dirty_writeback_interval
),
1026 .proc_handler
= &dirty_writeback_centisecs_handler
,
1029 .procname
= "dirty_expire_centisecs",
1030 .data
= &dirty_expire_interval
,
1031 .maxlen
= sizeof(dirty_expire_interval
),
1033 .proc_handler
= &proc_dointvec
,
1036 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
1037 .procname
= "nr_pdflush_threads",
1038 .data
= &nr_pdflush_threads
,
1039 .maxlen
= sizeof nr_pdflush_threads
,
1040 .mode
= 0444 /* read-only*/,
1041 .proc_handler
= &proc_dointvec
,
1044 .ctl_name
= CTL_UNNUMBERED
,
1045 .procname
= "nr_pdflush_threads_min",
1046 .data
= &nr_pdflush_threads_min
,
1047 .maxlen
= sizeof nr_pdflush_threads_min
,
1048 .mode
= 0644 /* read-write */,
1049 .proc_handler
= &proc_dointvec_minmax
,
1050 .strategy
= &sysctl_intvec
,
1052 .extra2
= &nr_pdflush_threads_max
,
1055 .ctl_name
= CTL_UNNUMBERED
,
1056 .procname
= "nr_pdflush_threads_max",
1057 .data
= &nr_pdflush_threads_max
,
1058 .maxlen
= sizeof nr_pdflush_threads_max
,
1059 .mode
= 0644 /* read-write */,
1060 .proc_handler
= &proc_dointvec_minmax
,
1061 .strategy
= &sysctl_intvec
,
1062 .extra1
= &nr_pdflush_threads_min
,
1063 .extra2
= &one_thousand
,
1066 .ctl_name
= VM_SWAPPINESS
,
1067 .procname
= "swappiness",
1068 .data
= &vm_swappiness
,
1069 .maxlen
= sizeof(vm_swappiness
),
1071 .proc_handler
= &proc_dointvec_minmax
,
1072 .strategy
= &sysctl_intvec
,
1074 .extra2
= &one_hundred
,
1076 #ifdef CONFIG_HUGETLB_PAGE
1078 .procname
= "nr_hugepages",
1080 .maxlen
= sizeof(unsigned long),
1082 .proc_handler
= &hugetlb_sysctl_handler
,
1083 .extra1
= (void *)&hugetlb_zero
,
1084 .extra2
= (void *)&hugetlb_infinity
,
1087 .ctl_name
= VM_HUGETLB_GROUP
,
1088 .procname
= "hugetlb_shm_group",
1089 .data
= &sysctl_hugetlb_shm_group
,
1090 .maxlen
= sizeof(gid_t
),
1092 .proc_handler
= &proc_dointvec
,
1095 .ctl_name
= CTL_UNNUMBERED
,
1096 .procname
= "hugepages_treat_as_movable",
1097 .data
= &hugepages_treat_as_movable
,
1098 .maxlen
= sizeof(int),
1100 .proc_handler
= &hugetlb_treat_movable_handler
,
1103 .ctl_name
= CTL_UNNUMBERED
,
1104 .procname
= "nr_overcommit_hugepages",
1106 .maxlen
= sizeof(unsigned long),
1108 .proc_handler
= &hugetlb_overcommit_handler
,
1109 .extra1
= (void *)&hugetlb_zero
,
1110 .extra2
= (void *)&hugetlb_infinity
,
1114 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
1115 .procname
= "lowmem_reserve_ratio",
1116 .data
= &sysctl_lowmem_reserve_ratio
,
1117 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1119 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
1120 .strategy
= &sysctl_intvec
,
1123 .ctl_name
= VM_DROP_PAGECACHE
,
1124 .procname
= "drop_caches",
1125 .data
= &sysctl_drop_caches
,
1126 .maxlen
= sizeof(int),
1128 .proc_handler
= drop_caches_sysctl_handler
,
1129 .strategy
= &sysctl_intvec
,
1132 .ctl_name
= VM_MIN_FREE_KBYTES
,
1133 .procname
= "min_free_kbytes",
1134 .data
= &min_free_kbytes
,
1135 .maxlen
= sizeof(min_free_kbytes
),
1137 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1138 .strategy
= &sysctl_intvec
,
1142 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1143 .procname
= "percpu_pagelist_fraction",
1144 .data
= &percpu_pagelist_fraction
,
1145 .maxlen
= sizeof(percpu_pagelist_fraction
),
1147 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1148 .strategy
= &sysctl_intvec
,
1149 .extra1
= &min_percpu_pagelist_fract
,
1153 .ctl_name
= VM_MAX_MAP_COUNT
,
1154 .procname
= "max_map_count",
1155 .data
= &sysctl_max_map_count
,
1156 .maxlen
= sizeof(sysctl_max_map_count
),
1158 .proc_handler
= &proc_dointvec
1162 .ctl_name
= CTL_UNNUMBERED
,
1163 .procname
= "nr_trim_pages",
1164 .data
= &sysctl_nr_trim_pages
,
1165 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1167 .proc_handler
= &proc_dointvec_minmax
,
1168 .strategy
= &sysctl_intvec
,
1173 .ctl_name
= VM_LAPTOP_MODE
,
1174 .procname
= "laptop_mode",
1175 .data
= &laptop_mode
,
1176 .maxlen
= sizeof(laptop_mode
),
1178 .proc_handler
= &proc_dointvec_jiffies
,
1179 .strategy
= &sysctl_jiffies
,
1182 .ctl_name
= VM_BLOCK_DUMP
,
1183 .procname
= "block_dump",
1184 .data
= &block_dump
,
1185 .maxlen
= sizeof(block_dump
),
1187 .proc_handler
= &proc_dointvec
,
1188 .strategy
= &sysctl_intvec
,
1192 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1193 .procname
= "vfs_cache_pressure",
1194 .data
= &sysctl_vfs_cache_pressure
,
1195 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1197 .proc_handler
= &proc_dointvec
,
1198 .strategy
= &sysctl_intvec
,
1201 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1203 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1204 .procname
= "legacy_va_layout",
1205 .data
= &sysctl_legacy_va_layout
,
1206 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1208 .proc_handler
= &proc_dointvec
,
1209 .strategy
= &sysctl_intvec
,
1215 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1216 .procname
= "zone_reclaim_mode",
1217 .data
= &zone_reclaim_mode
,
1218 .maxlen
= sizeof(zone_reclaim_mode
),
1220 .proc_handler
= &proc_dointvec
,
1221 .strategy
= &sysctl_intvec
,
1225 .ctl_name
= VM_MIN_UNMAPPED
,
1226 .procname
= "min_unmapped_ratio",
1227 .data
= &sysctl_min_unmapped_ratio
,
1228 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1230 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1231 .strategy
= &sysctl_intvec
,
1233 .extra2
= &one_hundred
,
1236 .ctl_name
= VM_MIN_SLAB
,
1237 .procname
= "min_slab_ratio",
1238 .data
= &sysctl_min_slab_ratio
,
1239 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1241 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1242 .strategy
= &sysctl_intvec
,
1244 .extra2
= &one_hundred
,
1249 .ctl_name
= CTL_UNNUMBERED
,
1250 .procname
= "stat_interval",
1251 .data
= &sysctl_stat_interval
,
1252 .maxlen
= sizeof(sysctl_stat_interval
),
1254 .proc_handler
= &proc_dointvec_jiffies
,
1255 .strategy
= &sysctl_jiffies
,
1258 #ifdef CONFIG_SECURITY
1260 .ctl_name
= CTL_UNNUMBERED
,
1261 .procname
= "mmap_min_addr",
1262 .data
= &mmap_min_addr
,
1263 .maxlen
= sizeof(unsigned long),
1265 .proc_handler
= &proc_doulongvec_minmax
,
1270 .ctl_name
= CTL_UNNUMBERED
,
1271 .procname
= "numa_zonelist_order",
1272 .data
= &numa_zonelist_order
,
1273 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1275 .proc_handler
= &numa_zonelist_order_handler
,
1276 .strategy
= &sysctl_string
,
1279 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1280 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1282 .ctl_name
= VM_VDSO_ENABLED
,
1283 .procname
= "vdso_enabled",
1284 .data
= &vdso_enabled
,
1285 .maxlen
= sizeof(vdso_enabled
),
1287 .proc_handler
= &proc_dointvec
,
1288 .strategy
= &sysctl_intvec
,
1292 #ifdef CONFIG_HIGHMEM
1294 .ctl_name
= CTL_UNNUMBERED
,
1295 .procname
= "highmem_is_dirtyable",
1296 .data
= &vm_highmem_is_dirtyable
,
1297 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1299 .proc_handler
= &proc_dointvec_minmax
,
1300 .strategy
= &sysctl_intvec
,
1306 * NOTE: do not add new entries to this table unless you have read
1307 * Documentation/sysctl/ctl_unnumbered.txt
1312 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1313 static struct ctl_table binfmt_misc_table
[] = {
1318 static struct ctl_table fs_table
[] = {
1320 .ctl_name
= FS_NRINODE
,
1321 .procname
= "inode-nr",
1322 .data
= &inodes_stat
,
1323 .maxlen
= 2*sizeof(int),
1325 .proc_handler
= &proc_dointvec
,
1328 .ctl_name
= FS_STATINODE
,
1329 .procname
= "inode-state",
1330 .data
= &inodes_stat
,
1331 .maxlen
= 7*sizeof(int),
1333 .proc_handler
= &proc_dointvec
,
1336 .procname
= "file-nr",
1337 .data
= &files_stat
,
1338 .maxlen
= 3*sizeof(int),
1340 .proc_handler
= &proc_nr_files
,
1343 .ctl_name
= FS_MAXFILE
,
1344 .procname
= "file-max",
1345 .data
= &files_stat
.max_files
,
1346 .maxlen
= sizeof(int),
1348 .proc_handler
= &proc_dointvec
,
1351 .ctl_name
= CTL_UNNUMBERED
,
1352 .procname
= "nr_open",
1353 .data
= &sysctl_nr_open
,
1354 .maxlen
= sizeof(int),
1356 .proc_handler
= &proc_dointvec_minmax
,
1357 .extra1
= &sysctl_nr_open_min
,
1358 .extra2
= &sysctl_nr_open_max
,
1361 .ctl_name
= FS_DENTRY
,
1362 .procname
= "dentry-state",
1363 .data
= &dentry_stat
,
1364 .maxlen
= 6*sizeof(int),
1366 .proc_handler
= &proc_dointvec
,
1369 .ctl_name
= FS_OVERFLOWUID
,
1370 .procname
= "overflowuid",
1371 .data
= &fs_overflowuid
,
1372 .maxlen
= sizeof(int),
1374 .proc_handler
= &proc_dointvec_minmax
,
1375 .strategy
= &sysctl_intvec
,
1376 .extra1
= &minolduid
,
1377 .extra2
= &maxolduid
,
1380 .ctl_name
= FS_OVERFLOWGID
,
1381 .procname
= "overflowgid",
1382 .data
= &fs_overflowgid
,
1383 .maxlen
= sizeof(int),
1385 .proc_handler
= &proc_dointvec_minmax
,
1386 .strategy
= &sysctl_intvec
,
1387 .extra1
= &minolduid
,
1388 .extra2
= &maxolduid
,
1390 #ifdef CONFIG_FILE_LOCKING
1392 .ctl_name
= FS_LEASES
,
1393 .procname
= "leases-enable",
1394 .data
= &leases_enable
,
1395 .maxlen
= sizeof(int),
1397 .proc_handler
= &proc_dointvec
,
1400 #ifdef CONFIG_DNOTIFY
1402 .ctl_name
= FS_DIR_NOTIFY
,
1403 .procname
= "dir-notify-enable",
1404 .data
= &dir_notify_enable
,
1405 .maxlen
= sizeof(int),
1407 .proc_handler
= &proc_dointvec
,
1411 #ifdef CONFIG_FILE_LOCKING
1413 .ctl_name
= FS_LEASE_TIME
,
1414 .procname
= "lease-break-time",
1415 .data
= &lease_break_time
,
1416 .maxlen
= sizeof(int),
1418 .proc_handler
= &proc_dointvec
,
1423 .procname
= "aio-nr",
1425 .maxlen
= sizeof(aio_nr
),
1427 .proc_handler
= &proc_doulongvec_minmax
,
1430 .procname
= "aio-max-nr",
1431 .data
= &aio_max_nr
,
1432 .maxlen
= sizeof(aio_max_nr
),
1434 .proc_handler
= &proc_doulongvec_minmax
,
1436 #endif /* CONFIG_AIO */
1437 #ifdef CONFIG_INOTIFY_USER
1439 .ctl_name
= FS_INOTIFY
,
1440 .procname
= "inotify",
1442 .child
= inotify_table
,
1447 .procname
= "epoll",
1449 .child
= epoll_table
,
1454 .ctl_name
= KERN_SETUID_DUMPABLE
,
1455 .procname
= "suid_dumpable",
1456 .data
= &suid_dumpable
,
1457 .maxlen
= sizeof(int),
1459 .proc_handler
= &proc_dointvec_minmax
,
1460 .strategy
= &sysctl_intvec
,
1464 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1466 .ctl_name
= CTL_UNNUMBERED
,
1467 .procname
= "binfmt_misc",
1469 .child
= binfmt_misc_table
,
1473 * NOTE: do not add new entries to this table unless you have read
1474 * Documentation/sysctl/ctl_unnumbered.txt
1479 static struct ctl_table debug_table
[] = {
1480 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1482 .ctl_name
= CTL_UNNUMBERED
,
1483 .procname
= "exception-trace",
1484 .data
= &show_unhandled_signals
,
1485 .maxlen
= sizeof(int),
1487 .proc_handler
= proc_dointvec
1493 static struct ctl_table dev_table
[] = {
1497 static DEFINE_SPINLOCK(sysctl_lock
);
1499 /* called under sysctl_lock */
1500 static int use_table(struct ctl_table_header
*p
)
1502 if (unlikely(p
->unregistering
))
1508 /* called under sysctl_lock */
1509 static void unuse_table(struct ctl_table_header
*p
)
1512 if (unlikely(p
->unregistering
))
1513 complete(p
->unregistering
);
1516 /* called under sysctl_lock, will reacquire if has to wait */
1517 static void start_unregistering(struct ctl_table_header
*p
)
1520 * if p->used is 0, nobody will ever touch that entry again;
1521 * we'll eliminate all paths to it before dropping sysctl_lock
1523 if (unlikely(p
->used
)) {
1524 struct completion wait
;
1525 init_completion(&wait
);
1526 p
->unregistering
= &wait
;
1527 spin_unlock(&sysctl_lock
);
1528 wait_for_completion(&wait
);
1529 spin_lock(&sysctl_lock
);
1531 /* anything non-NULL; we'll never dereference it */
1532 p
->unregistering
= ERR_PTR(-EINVAL
);
1535 * do not remove from the list until nobody holds it; walking the
1536 * list in do_sysctl() relies on that.
1538 list_del_init(&p
->ctl_entry
);
1541 void sysctl_head_get(struct ctl_table_header
*head
)
1543 spin_lock(&sysctl_lock
);
1545 spin_unlock(&sysctl_lock
);
1548 void sysctl_head_put(struct ctl_table_header
*head
)
1550 spin_lock(&sysctl_lock
);
1553 spin_unlock(&sysctl_lock
);
1556 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1560 spin_lock(&sysctl_lock
);
1561 if (!use_table(head
))
1562 head
= ERR_PTR(-ENOENT
);
1563 spin_unlock(&sysctl_lock
);
1567 void sysctl_head_finish(struct ctl_table_header
*head
)
1571 spin_lock(&sysctl_lock
);
1573 spin_unlock(&sysctl_lock
);
1576 static struct ctl_table_set
*
1577 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1579 struct ctl_table_set
*set
= &root
->default_set
;
1581 set
= root
->lookup(root
, namespaces
);
1585 static struct list_head
*
1586 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1588 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1592 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1593 struct ctl_table_header
*prev
)
1595 struct ctl_table_root
*root
;
1596 struct list_head
*header_list
;
1597 struct ctl_table_header
*head
;
1598 struct list_head
*tmp
;
1600 spin_lock(&sysctl_lock
);
1603 tmp
= &prev
->ctl_entry
;
1607 tmp
= &root_table_header
.ctl_entry
;
1609 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1611 if (!use_table(head
))
1613 spin_unlock(&sysctl_lock
);
1618 header_list
= lookup_header_list(root
, namespaces
);
1619 if (tmp
!= header_list
)
1623 root
= list_entry(root
->root_list
.next
,
1624 struct ctl_table_root
, root_list
);
1625 if (root
== &sysctl_table_root
)
1627 header_list
= lookup_header_list(root
, namespaces
);
1628 } while (list_empty(header_list
));
1629 tmp
= header_list
->next
;
1632 spin_unlock(&sysctl_lock
);
1636 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1638 return __sysctl_head_next(current
->nsproxy
, prev
);
1641 void register_sysctl_root(struct ctl_table_root
*root
)
1643 spin_lock(&sysctl_lock
);
1644 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1645 spin_unlock(&sysctl_lock
);
1648 #ifdef CONFIG_SYSCTL_SYSCALL
1649 /* Perform the actual read/write of a sysctl table entry. */
1650 static int do_sysctl_strategy(struct ctl_table_root
*root
,
1651 struct ctl_table
*table
,
1652 void __user
*oldval
, size_t __user
*oldlenp
,
1653 void __user
*newval
, size_t newlen
)
1661 if (sysctl_perm(root
, table
, op
))
1664 if (table
->strategy
) {
1665 rc
= table
->strategy(table
, oldval
, oldlenp
, newval
, newlen
);
1672 /* If there is no strategy routine, or if the strategy returns
1673 * zero, proceed with automatic r/w */
1674 if (table
->data
&& table
->maxlen
) {
1675 rc
= sysctl_data(table
, oldval
, oldlenp
, newval
, newlen
);
1682 static int parse_table(int __user
*name
, int nlen
,
1683 void __user
*oldval
, size_t __user
*oldlenp
,
1684 void __user
*newval
, size_t newlen
,
1685 struct ctl_table_root
*root
,
1686 struct ctl_table
*table
)
1692 if (get_user(n
, name
))
1694 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1695 if (!table
->ctl_name
)
1697 if (n
== table
->ctl_name
) {
1700 if (sysctl_perm(root
, table
, MAY_EXEC
))
1704 table
= table
->child
;
1707 error
= do_sysctl_strategy(root
, table
,
1716 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1717 void __user
*newval
, size_t newlen
)
1719 struct ctl_table_header
*head
;
1720 int error
= -ENOTDIR
;
1722 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1726 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1730 for (head
= sysctl_head_next(NULL
); head
;
1731 head
= sysctl_head_next(head
)) {
1732 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1734 head
->root
, head
->ctl_table
);
1735 if (error
!= -ENOTDIR
) {
1736 sysctl_head_finish(head
);
1743 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
1745 struct __sysctl_args tmp
;
1748 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1751 error
= deprecated_sysctl_warning(&tmp
);
1756 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1757 tmp
.newval
, tmp
.newlen
);
1762 #endif /* CONFIG_SYSCTL_SYSCALL */
1765 * sysctl_perm does NOT grant the superuser all rights automatically, because
1766 * some sysctl variables are readonly even to root.
1769 static int test_perm(int mode
, int op
)
1771 if (!current_euid())
1773 else if (in_egroup_p(0))
1775 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1780 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1785 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1789 if (root
->permissions
)
1790 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1794 return test_perm(mode
, op
);
1797 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1799 for (; table
->ctl_name
|| table
->procname
; table
++) {
1800 table
->parent
= parent
;
1802 sysctl_set_parent(table
, table
->child
);
1806 static __init
int sysctl_init(void)
1808 sysctl_set_parent(NULL
, root_table
);
1809 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1812 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1818 core_initcall(sysctl_init
);
1820 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1821 struct ctl_table
*table
)
1823 struct ctl_table
*p
;
1824 const char *s
= branch
->procname
;
1826 /* branch should have named subdirectory as its first element */
1827 if (!s
|| !branch
->child
)
1830 /* ... and nothing else */
1831 if (branch
[1].procname
|| branch
[1].ctl_name
)
1834 /* table should contain subdirectory with the same name */
1835 for (p
= table
; p
->procname
|| p
->ctl_name
; p
++) {
1838 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1844 /* see if attaching q to p would be an improvement */
1845 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1847 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1848 struct ctl_table
*next
;
1850 int not_in_parent
= !p
->attached_by
;
1852 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1853 if (by
== q
->attached_by
)
1855 if (to
== p
->attached_by
)
1861 if (is_better
&& not_in_parent
) {
1862 q
->attached_by
= by
;
1863 q
->attached_to
= to
;
1869 * __register_sysctl_paths - register a sysctl hierarchy
1870 * @root: List of sysctl headers to register on
1871 * @namespaces: Data to compute which lists of sysctl entries are visible
1872 * @path: The path to the directory the sysctl table is in.
1873 * @table: the top-level table structure
1875 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1876 * array. A completely 0 filled entry terminates the table.
1878 * The members of the &struct ctl_table structure are used as follows:
1880 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1881 * must be unique within that level of sysctl
1883 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1884 * enter a sysctl file
1886 * data - a pointer to data for use by proc_handler
1888 * maxlen - the maximum size in bytes of the data
1890 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1892 * child - a pointer to the child sysctl table if this entry is a directory, or
1895 * proc_handler - the text handler routine (described below)
1897 * strategy - the strategy routine (described below)
1899 * de - for internal use by the sysctl routines
1901 * extra1, extra2 - extra pointers usable by the proc handler routines
1903 * Leaf nodes in the sysctl tree will be represented by a single file
1904 * under /proc; non-leaf nodes will be represented by directories.
1906 * sysctl(2) can automatically manage read and write requests through
1907 * the sysctl table. The data and maxlen fields of the ctl_table
1908 * struct enable minimal validation of the values being written to be
1909 * performed, and the mode field allows minimal authentication.
1911 * More sophisticated management can be enabled by the provision of a
1912 * strategy routine with the table entry. This will be called before
1913 * any automatic read or write of the data is performed.
1915 * The strategy routine may return
1917 * < 0 - Error occurred (error is passed to user process)
1919 * 0 - OK - proceed with automatic read or write.
1921 * > 0 - OK - read or write has been done by the strategy routine, so
1922 * return immediately.
1924 * There must be a proc_handler routine for any terminal nodes
1925 * mirrored under /proc/sys (non-terminals are handled by a built-in
1926 * directory handler). Several default handlers are available to
1927 * cover common cases -
1929 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1930 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1931 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1933 * It is the handler's job to read the input buffer from user memory
1934 * and process it. The handler should return 0 on success.
1936 * This routine returns %NULL on a failure to register, and a pointer
1937 * to the table header on success.
1939 struct ctl_table_header
*__register_sysctl_paths(
1940 struct ctl_table_root
*root
,
1941 struct nsproxy
*namespaces
,
1942 const struct ctl_path
*path
, struct ctl_table
*table
)
1944 struct ctl_table_header
*header
;
1945 struct ctl_table
*new, **prevp
;
1946 unsigned int n
, npath
;
1947 struct ctl_table_set
*set
;
1949 /* Count the path components */
1950 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
1954 * For each path component, allocate a 2-element ctl_table array.
1955 * The first array element will be filled with the sysctl entry
1956 * for this, the second will be the sentinel (ctl_name == 0).
1958 * We allocate everything in one go so that we don't have to
1959 * worry about freeing additional memory in unregister_sysctl_table.
1961 header
= kzalloc(sizeof(struct ctl_table_header
) +
1962 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1966 new = (struct ctl_table
*) (header
+ 1);
1968 /* Now connect the dots */
1969 prevp
= &header
->ctl_table
;
1970 for (n
= 0; n
< npath
; ++n
, ++path
) {
1971 /* Copy the procname */
1972 new->procname
= path
->procname
;
1973 new->ctl_name
= path
->ctl_name
;
1977 prevp
= &new->child
;
1982 header
->ctl_table_arg
= table
;
1984 INIT_LIST_HEAD(&header
->ctl_entry
);
1986 header
->unregistering
= NULL
;
1987 header
->root
= root
;
1988 sysctl_set_parent(NULL
, header
->ctl_table
);
1990 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1991 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1996 spin_lock(&sysctl_lock
);
1997 header
->set
= lookup_header_set(root
, namespaces
);
1998 header
->attached_by
= header
->ctl_table
;
1999 header
->attached_to
= root_table
;
2000 header
->parent
= &root_table_header
;
2001 for (set
= header
->set
; set
; set
= set
->parent
) {
2002 struct ctl_table_header
*p
;
2003 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
2004 if (p
->unregistering
)
2006 try_attach(p
, header
);
2009 header
->parent
->count
++;
2010 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
2011 spin_unlock(&sysctl_lock
);
2017 * register_sysctl_table_path - register a sysctl table hierarchy
2018 * @path: The path to the directory the sysctl table is in.
2019 * @table: the top-level table structure
2021 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2022 * array. A completely 0 filled entry terminates the table.
2024 * See __register_sysctl_paths for more details.
2026 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2027 struct ctl_table
*table
)
2029 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
2034 * register_sysctl_table - register a sysctl table hierarchy
2035 * @table: the top-level table structure
2037 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2038 * array. A completely 0 filled entry terminates the table.
2040 * See register_sysctl_paths for more details.
2042 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
2044 static const struct ctl_path null_path
[] = { {} };
2046 return register_sysctl_paths(null_path
, table
);
2050 * unregister_sysctl_table - unregister a sysctl table hierarchy
2051 * @header: the header returned from register_sysctl_table
2053 * Unregisters the sysctl table and all children. proc entries may not
2054 * actually be removed until they are no longer used by anyone.
2056 void unregister_sysctl_table(struct ctl_table_header
* header
)
2063 spin_lock(&sysctl_lock
);
2064 start_unregistering(header
);
2065 if (!--header
->parent
->count
) {
2067 kfree(header
->parent
);
2069 if (!--header
->count
)
2071 spin_unlock(&sysctl_lock
);
2074 int sysctl_is_seen(struct ctl_table_header
*p
)
2076 struct ctl_table_set
*set
= p
->set
;
2078 spin_lock(&sysctl_lock
);
2079 if (p
->unregistering
)
2081 else if (!set
->is_seen
)
2084 res
= set
->is_seen(set
);
2085 spin_unlock(&sysctl_lock
);
2089 void setup_sysctl_set(struct ctl_table_set
*p
,
2090 struct ctl_table_set
*parent
,
2091 int (*is_seen
)(struct ctl_table_set
*))
2093 INIT_LIST_HEAD(&p
->list
);
2094 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
2095 p
->is_seen
= is_seen
;
2098 #else /* !CONFIG_SYSCTL */
2099 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
2104 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2105 struct ctl_table
*table
)
2110 void unregister_sysctl_table(struct ctl_table_header
* table
)
2114 void setup_sysctl_set(struct ctl_table_set
*p
,
2115 struct ctl_table_set
*parent
,
2116 int (*is_seen
)(struct ctl_table_set
*))
2120 void sysctl_head_put(struct ctl_table_header
*head
)
2124 #endif /* CONFIG_SYSCTL */
2130 #ifdef CONFIG_PROC_SYSCTL
2132 static int _proc_do_string(void* data
, int maxlen
, int write
,
2133 struct file
*filp
, void __user
*buffer
,
2134 size_t *lenp
, loff_t
*ppos
)
2140 if (!data
|| !maxlen
|| !*lenp
) {
2148 while (len
< *lenp
) {
2149 if (get_user(c
, p
++))
2151 if (c
== 0 || c
== '\n')
2157 if(copy_from_user(data
, buffer
, len
))
2159 ((char *) data
)[len
] = 0;
2177 if(copy_to_user(buffer
, data
, len
))
2180 if(put_user('\n', ((char __user
*) buffer
) + len
))
2191 * proc_dostring - read a string sysctl
2192 * @table: the sysctl table
2193 * @write: %TRUE if this is a write to the sysctl file
2194 * @filp: the file structure
2195 * @buffer: the user buffer
2196 * @lenp: the size of the user buffer
2197 * @ppos: file position
2199 * Reads/writes a string from/to the user buffer. If the kernel
2200 * buffer provided is not large enough to hold the string, the
2201 * string is truncated. The copied string is %NULL-terminated.
2202 * If the string is being read by the user process, it is copied
2203 * and a newline '\n' is added. It is truncated if the buffer is
2206 * Returns 0 on success.
2208 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2209 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2211 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
2212 buffer
, lenp
, ppos
);
2216 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
2218 int write
, void *data
)
2221 *valp
= *negp
? -*lvalp
: *lvalp
;
2226 *lvalp
= (unsigned long)-val
;
2229 *lvalp
= (unsigned long)val
;
2235 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2236 int write
, struct file
*filp
, void __user
*buffer
,
2237 size_t *lenp
, loff_t
*ppos
,
2238 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2239 int write
, void *data
),
2242 #define TMPBUFLEN 21
2243 int *i
, vleft
, first
=1, neg
, val
;
2247 char buf
[TMPBUFLEN
], *p
;
2248 char __user
*s
= buffer
;
2250 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
2251 (*ppos
&& !write
)) {
2256 i
= (int *) tbl_data
;
2257 vleft
= table
->maxlen
/ sizeof(*i
);
2261 conv
= do_proc_dointvec_conv
;
2263 for (; left
&& vleft
--; i
++, first
=0) {
2278 if (len
> sizeof(buf
) - 1)
2279 len
= sizeof(buf
) - 1;
2280 if (copy_from_user(buf
, s
, len
))
2284 if (*p
== '-' && left
> 1) {
2288 if (*p
< '0' || *p
> '9')
2291 lval
= simple_strtoul(p
, &p
, 0);
2294 if ((len
< left
) && *p
&& !isspace(*p
))
2301 if (conv(&neg
, &lval
, i
, 1, data
))
2308 if (conv(&neg
, &lval
, i
, 0, data
))
2311 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2315 if(copy_to_user(s
, buf
, len
))
2322 if (!write
&& !first
&& left
) {
2323 if(put_user('\n', s
))
2330 if (get_user(c
, s
++))
2345 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2346 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2347 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2348 int write
, void *data
),
2351 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2352 buffer
, lenp
, ppos
, conv
, data
);
2356 * proc_dointvec - read a vector of integers
2357 * @table: the sysctl table
2358 * @write: %TRUE if this is a write to the sysctl file
2359 * @filp: the file structure
2360 * @buffer: the user buffer
2361 * @lenp: the size of the user buffer
2362 * @ppos: file position
2364 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2365 * values from/to the user buffer, treated as an ASCII string.
2367 * Returns 0 on success.
2369 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2370 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2372 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2377 * Taint values can only be increased
2378 * This means we can safely use a temporary.
2380 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2381 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2384 unsigned long tmptaint
= get_taint();
2387 if (write
&& !capable(CAP_SYS_ADMIN
))
2392 err
= proc_doulongvec_minmax(&t
, write
, filp
, buffer
, lenp
, ppos
);
2398 * Poor man's atomic or. Not worth adding a primitive
2399 * to everyone's atomic.h for this
2402 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2403 if ((tmptaint
>> i
) & 1)
2411 struct do_proc_dointvec_minmax_conv_param
{
2416 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2418 int write
, void *data
)
2420 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2422 int val
= *negp
? -*lvalp
: *lvalp
;
2423 if ((param
->min
&& *param
->min
> val
) ||
2424 (param
->max
&& *param
->max
< val
))
2431 *lvalp
= (unsigned long)-val
;
2434 *lvalp
= (unsigned long)val
;
2441 * proc_dointvec_minmax - read a vector of integers with min/max values
2442 * @table: the sysctl table
2443 * @write: %TRUE if this is a write to the sysctl file
2444 * @filp: the file structure
2445 * @buffer: the user buffer
2446 * @lenp: the size of the user buffer
2447 * @ppos: file position
2449 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2450 * values from/to the user buffer, treated as an ASCII string.
2452 * This routine will ensure the values are within the range specified by
2453 * table->extra1 (min) and table->extra2 (max).
2455 * Returns 0 on success.
2457 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2458 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2460 struct do_proc_dointvec_minmax_conv_param param
= {
2461 .min
= (int *) table
->extra1
,
2462 .max
= (int *) table
->extra2
,
2464 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2465 do_proc_dointvec_minmax_conv
, ¶m
);
2468 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2470 void __user
*buffer
,
2471 size_t *lenp
, loff_t
*ppos
,
2472 unsigned long convmul
,
2473 unsigned long convdiv
)
2475 #define TMPBUFLEN 21
2476 unsigned long *i
, *min
, *max
, val
;
2477 int vleft
, first
=1, neg
;
2479 char buf
[TMPBUFLEN
], *p
;
2480 char __user
*s
= buffer
;
2482 if (!data
|| !table
->maxlen
|| !*lenp
||
2483 (*ppos
&& !write
)) {
2488 i
= (unsigned long *) data
;
2489 min
= (unsigned long *) table
->extra1
;
2490 max
= (unsigned long *) table
->extra2
;
2491 vleft
= table
->maxlen
/ sizeof(unsigned long);
2494 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2509 if (len
> TMPBUFLEN
-1)
2511 if (copy_from_user(buf
, s
, len
))
2515 if (*p
== '-' && left
> 1) {
2519 if (*p
< '0' || *p
> '9')
2521 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2523 if ((len
< left
) && *p
&& !isspace(*p
))
2532 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2539 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2543 if(copy_to_user(s
, buf
, len
))
2550 if (!write
&& !first
&& left
) {
2551 if(put_user('\n', s
))
2558 if (get_user(c
, s
++))
2573 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2575 void __user
*buffer
,
2576 size_t *lenp
, loff_t
*ppos
,
2577 unsigned long convmul
,
2578 unsigned long convdiv
)
2580 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2581 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2585 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2586 * @table: the sysctl table
2587 * @write: %TRUE if this is a write to the sysctl file
2588 * @filp: the file structure
2589 * @buffer: the user buffer
2590 * @lenp: the size of the user buffer
2591 * @ppos: file position
2593 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2594 * values from/to the user buffer, treated as an ASCII string.
2596 * This routine will ensure the values are within the range specified by
2597 * table->extra1 (min) and table->extra2 (max).
2599 * Returns 0 on success.
2601 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2602 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2604 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2608 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2609 * @table: the sysctl table
2610 * @write: %TRUE if this is a write to the sysctl file
2611 * @filp: the file structure
2612 * @buffer: the user buffer
2613 * @lenp: the size of the user buffer
2614 * @ppos: file position
2616 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2617 * values from/to the user buffer, treated as an ASCII string. The values
2618 * are treated as milliseconds, and converted to jiffies when they are stored.
2620 * This routine will ensure the values are within the range specified by
2621 * table->extra1 (min) and table->extra2 (max).
2623 * Returns 0 on success.
2625 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2627 void __user
*buffer
,
2628 size_t *lenp
, loff_t
*ppos
)
2630 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2631 lenp
, ppos
, HZ
, 1000l);
2635 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2637 int write
, void *data
)
2640 if (*lvalp
> LONG_MAX
/ HZ
)
2642 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2648 lval
= (unsigned long)-val
;
2651 lval
= (unsigned long)val
;
2658 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2660 int write
, void *data
)
2663 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2665 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2671 lval
= (unsigned long)-val
;
2674 lval
= (unsigned long)val
;
2676 *lvalp
= jiffies_to_clock_t(lval
);
2681 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2683 int write
, void *data
)
2686 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2692 lval
= (unsigned long)-val
;
2695 lval
= (unsigned long)val
;
2697 *lvalp
= jiffies_to_msecs(lval
);
2703 * proc_dointvec_jiffies - read a vector of integers as seconds
2704 * @table: the sysctl table
2705 * @write: %TRUE if this is a write to the sysctl file
2706 * @filp: the file structure
2707 * @buffer: the user buffer
2708 * @lenp: the size of the user buffer
2709 * @ppos: file position
2711 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2712 * values from/to the user buffer, treated as an ASCII string.
2713 * The values read are assumed to be in seconds, and are converted into
2716 * Returns 0 on success.
2718 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2719 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2721 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2722 do_proc_dointvec_jiffies_conv
,NULL
);
2726 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2727 * @table: the sysctl table
2728 * @write: %TRUE if this is a write to the sysctl file
2729 * @filp: the file structure
2730 * @buffer: the user buffer
2731 * @lenp: the size of the user buffer
2732 * @ppos: pointer to the file position
2734 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2735 * values from/to the user buffer, treated as an ASCII string.
2736 * The values read are assumed to be in 1/USER_HZ seconds, and
2737 * are converted into jiffies.
2739 * Returns 0 on success.
2741 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2742 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2744 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2745 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2749 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2750 * @table: the sysctl table
2751 * @write: %TRUE if this is a write to the sysctl file
2752 * @filp: the file structure
2753 * @buffer: the user buffer
2754 * @lenp: the size of the user buffer
2755 * @ppos: file position
2756 * @ppos: the current position in the file
2758 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2759 * values from/to the user buffer, treated as an ASCII string.
2760 * The values read are assumed to be in 1/1000 seconds, and
2761 * are converted into jiffies.
2763 * Returns 0 on success.
2765 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2766 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2768 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2769 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2772 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2773 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2775 struct pid
*new_pid
;
2779 tmp
= pid_vnr(cad_pid
);
2781 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2782 lenp
, ppos
, NULL
, NULL
);
2786 new_pid
= find_get_pid(tmp
);
2790 put_pid(xchg(&cad_pid
, new_pid
));
2794 #else /* CONFIG_PROC_FS */
2796 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2797 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2802 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2803 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2808 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2809 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2814 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2815 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2820 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2821 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2826 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2827 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2832 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2833 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2838 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2840 void __user
*buffer
,
2841 size_t *lenp
, loff_t
*ppos
)
2847 #endif /* CONFIG_PROC_FS */
2850 #ifdef CONFIG_SYSCTL_SYSCALL
2852 * General sysctl support routines
2855 /* The generic sysctl data routine (used if no strategy routine supplied) */
2856 int sysctl_data(struct ctl_table
*table
,
2857 void __user
*oldval
, size_t __user
*oldlenp
,
2858 void __user
*newval
, size_t newlen
)
2862 /* Get out of I don't have a variable */
2863 if (!table
->data
|| !table
->maxlen
)
2866 if (oldval
&& oldlenp
) {
2867 if (get_user(len
, oldlenp
))
2870 if (len
> table
->maxlen
)
2871 len
= table
->maxlen
;
2872 if (copy_to_user(oldval
, table
->data
, len
))
2874 if (put_user(len
, oldlenp
))
2879 if (newval
&& newlen
) {
2880 if (newlen
> table
->maxlen
)
2881 newlen
= table
->maxlen
;
2883 if (copy_from_user(table
->data
, newval
, newlen
))
2889 /* The generic string strategy routine: */
2890 int sysctl_string(struct ctl_table
*table
,
2891 void __user
*oldval
, size_t __user
*oldlenp
,
2892 void __user
*newval
, size_t newlen
)
2894 if (!table
->data
|| !table
->maxlen
)
2897 if (oldval
&& oldlenp
) {
2899 if (get_user(bufsize
, oldlenp
))
2902 size_t len
= strlen(table
->data
), copied
;
2904 /* This shouldn't trigger for a well-formed sysctl */
2905 if (len
> table
->maxlen
)
2906 len
= table
->maxlen
;
2908 /* Copy up to a max of bufsize-1 bytes of the string */
2909 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2911 if (copy_to_user(oldval
, table
->data
, copied
) ||
2912 put_user(0, (char __user
*)(oldval
+ copied
)))
2914 if (put_user(len
, oldlenp
))
2918 if (newval
&& newlen
) {
2919 size_t len
= newlen
;
2920 if (len
> table
->maxlen
)
2921 len
= table
->maxlen
;
2922 if(copy_from_user(table
->data
, newval
, len
))
2924 if (len
== table
->maxlen
)
2926 ((char *) table
->data
)[len
] = 0;
2932 * This function makes sure that all of the integers in the vector
2933 * are between the minimum and maximum values given in the arrays
2934 * table->extra1 and table->extra2, respectively.
2936 int sysctl_intvec(struct ctl_table
*table
,
2937 void __user
*oldval
, size_t __user
*oldlenp
,
2938 void __user
*newval
, size_t newlen
)
2941 if (newval
&& newlen
) {
2942 int __user
*vec
= (int __user
*) newval
;
2943 int *min
= (int *) table
->extra1
;
2944 int *max
= (int *) table
->extra2
;
2948 if (newlen
% sizeof(int) != 0)
2951 if (!table
->extra1
&& !table
->extra2
)
2954 if (newlen
> table
->maxlen
)
2955 newlen
= table
->maxlen
;
2956 length
= newlen
/ sizeof(int);
2958 for (i
= 0; i
< length
; i
++) {
2960 if (get_user(value
, vec
+ i
))
2962 if (min
&& value
< min
[i
])
2964 if (max
&& value
> max
[i
])
2971 /* Strategy function to convert jiffies to seconds */
2972 int sysctl_jiffies(struct ctl_table
*table
,
2973 void __user
*oldval
, size_t __user
*oldlenp
,
2974 void __user
*newval
, size_t newlen
)
2976 if (oldval
&& oldlenp
) {
2979 if (get_user(olen
, oldlenp
))
2984 if (olen
< sizeof(int))
2987 val
= *(int *)(table
->data
) / HZ
;
2988 if (put_user(val
, (int __user
*)oldval
))
2990 if (put_user(sizeof(int), oldlenp
))
2994 if (newval
&& newlen
) {
2996 if (newlen
!= sizeof(int))
2998 if (get_user(new, (int __user
*)newval
))
3000 *(int *)(table
->data
) = new*HZ
;
3005 /* Strategy function to convert jiffies to seconds */
3006 int sysctl_ms_jiffies(struct ctl_table
*table
,
3007 void __user
*oldval
, size_t __user
*oldlenp
,
3008 void __user
*newval
, size_t newlen
)
3010 if (oldval
&& oldlenp
) {
3013 if (get_user(olen
, oldlenp
))
3018 if (olen
< sizeof(int))
3021 val
= jiffies_to_msecs(*(int *)(table
->data
));
3022 if (put_user(val
, (int __user
*)oldval
))
3024 if (put_user(sizeof(int), oldlenp
))
3028 if (newval
&& newlen
) {
3030 if (newlen
!= sizeof(int))
3032 if (get_user(new, (int __user
*)newval
))
3034 *(int *)(table
->data
) = msecs_to_jiffies(new);
3041 #else /* CONFIG_SYSCTL_SYSCALL */
3044 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
3046 struct __sysctl_args tmp
;
3049 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
3052 error
= deprecated_sysctl_warning(&tmp
);
3054 /* If no error reading the parameters then just -ENOSYS ... */
3061 int sysctl_data(struct ctl_table
*table
,
3062 void __user
*oldval
, size_t __user
*oldlenp
,
3063 void __user
*newval
, size_t newlen
)
3068 int sysctl_string(struct ctl_table
*table
,
3069 void __user
*oldval
, size_t __user
*oldlenp
,
3070 void __user
*newval
, size_t newlen
)
3075 int sysctl_intvec(struct ctl_table
*table
,
3076 void __user
*oldval
, size_t __user
*oldlenp
,
3077 void __user
*newval
, size_t newlen
)
3082 int sysctl_jiffies(struct ctl_table
*table
,
3083 void __user
*oldval
, size_t __user
*oldlenp
,
3084 void __user
*newval
, size_t newlen
)
3089 int sysctl_ms_jiffies(struct ctl_table
*table
,
3090 void __user
*oldval
, size_t __user
*oldlenp
,
3091 void __user
*newval
, size_t newlen
)
3096 #endif /* CONFIG_SYSCTL_SYSCALL */
3098 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
3100 static int msg_count
;
3101 int name
[CTL_MAXNAME
];
3104 /* Check args->nlen. */
3105 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
3108 /* Read in the sysctl name for better debug message logging */
3109 for (i
= 0; i
< args
->nlen
; i
++)
3110 if (get_user(name
[i
], args
->name
+ i
))
3113 /* Ignore accesses to kernel.version */
3114 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
3117 if (msg_count
< 5) {
3120 "warning: process `%s' used the deprecated sysctl "
3121 "system call with ", current
->comm
);
3122 for (i
= 0; i
< args
->nlen
; i
++)
3123 printk("%d.", name
[i
]);
3130 * No sense putting this after each symbol definition, twice,
3131 * exception granted :-)
3133 EXPORT_SYMBOL(proc_dointvec
);
3134 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3135 EXPORT_SYMBOL(proc_dointvec_minmax
);
3136 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3137 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3138 EXPORT_SYMBOL(proc_dostring
);
3139 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3140 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
3141 EXPORT_SYMBOL(register_sysctl_table
);
3142 EXPORT_SYMBOL(register_sysctl_paths
);
3143 EXPORT_SYMBOL(sysctl_intvec
);
3144 EXPORT_SYMBOL(sysctl_jiffies
);
3145 EXPORT_SYMBOL(sysctl_ms_jiffies
);
3146 EXPORT_SYMBOL(sysctl_string
);
3147 EXPORT_SYMBOL(sysctl_data
);
3148 EXPORT_SYMBOL(unregister_sysctl_table
);