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>
52 #include <linux/perf_counter.h>
54 #include <asm/uaccess.h>
55 #include <asm/processor.h>
59 #include <asm/stacktrace.h>
63 static int deprecated_sysctl_warning(struct __sysctl_args
*args
);
65 #if defined(CONFIG_SYSCTL)
67 /* External variables not in a header file. */
69 extern int print_fatal_signals
;
70 extern int sysctl_overcommit_memory
;
71 extern int sysctl_overcommit_ratio
;
72 extern int sysctl_panic_on_oom
;
73 extern int sysctl_oom_kill_allocating_task
;
74 extern int sysctl_oom_dump_tasks
;
75 extern int max_threads
;
76 extern int core_uses_pid
;
77 extern int suid_dumpable
;
78 extern char core_pattern
[];
80 extern int min_free_kbytes
;
81 extern int pid_max_min
, pid_max_max
;
82 extern int sysctl_drop_caches
;
83 extern int percpu_pagelist_fraction
;
84 extern int compat_log
;
85 extern int latencytop_enabled
;
86 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
88 extern int sysctl_nr_trim_pages
;
90 #ifdef CONFIG_RCU_TORTURE_TEST
91 extern int rcutorture_runnable
;
92 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
94 /* Constants used for minimum and maximum */
95 #ifdef CONFIG_DETECT_SOFTLOCKUP
96 static int sixty
= 60;
97 static int neg_one
= -1;
101 static int __maybe_unused one
= 1;
102 static int __maybe_unused two
= 2;
103 static unsigned long one_ul
= 1;
104 static int one_hundred
= 100;
106 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
107 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
109 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
110 static int maxolduid
= 65535;
111 static int minolduid
;
112 static int min_percpu_pagelist_fract
= 8;
114 static int ngroups_max
= NGROUPS_MAX
;
116 #ifdef CONFIG_MODULES
117 extern char modprobe_path
[];
118 extern int modules_disabled
;
120 #ifdef CONFIG_CHR_DEV_SG
121 extern int sg_big_buff
;
125 #include <asm/system.h>
128 #ifdef CONFIG_SPARC64
129 extern int sysctl_tsb_ratio
;
133 extern int pwrsw_enabled
;
134 extern int unaligned_enabled
;
138 #ifdef CONFIG_MATHEMU
139 extern int sysctl_ieee_emulation_warnings
;
141 extern int sysctl_userprocess_debug
;
142 extern int spin_retry
;
145 #ifdef CONFIG_BSD_PROCESS_ACCT
146 extern int acct_parm
[];
150 extern int no_unaligned_warning
;
151 extern int unaligned_dump_stack
;
154 #ifdef CONFIG_RT_MUTEXES
155 extern int max_lock_depth
;
158 #ifdef CONFIG_PROC_SYSCTL
159 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
160 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
161 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
162 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
165 static struct ctl_table root_table
[];
166 static struct ctl_table_root sysctl_table_root
;
167 static struct ctl_table_header root_table_header
= {
169 .ctl_table
= root_table
,
170 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),
171 .root
= &sysctl_table_root
,
172 .set
= &sysctl_table_root
.default_set
,
174 static struct ctl_table_root sysctl_table_root
= {
175 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
176 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
179 static struct ctl_table kern_table
[];
180 static struct ctl_table vm_table
[];
181 static struct ctl_table fs_table
[];
182 static struct ctl_table debug_table
[];
183 static struct ctl_table dev_table
[];
184 extern struct ctl_table random_table
[];
185 #ifdef CONFIG_INOTIFY_USER
186 extern struct ctl_table inotify_table
[];
189 extern struct ctl_table epoll_table
[];
192 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
193 int sysctl_legacy_va_layout
;
196 extern int prove_locking
;
197 extern int lock_stat
;
199 /* The default sysctl tables: */
201 static struct ctl_table root_table
[] = {
203 .ctl_name
= CTL_KERN
,
204 .procname
= "kernel",
221 .ctl_name
= CTL_DEBUG
,
224 .child
= debug_table
,
233 * NOTE: do not add new entries to this table unless you have read
234 * Documentation/sysctl/ctl_unnumbered.txt
239 #ifdef CONFIG_SCHED_DEBUG
240 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
241 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
242 static int min_wakeup_granularity_ns
; /* 0 usecs */
243 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
246 static struct ctl_table kern_table
[] = {
247 #ifdef CONFIG_SCHED_DEBUG
249 .ctl_name
= CTL_UNNUMBERED
,
250 .procname
= "sched_min_granularity_ns",
251 .data
= &sysctl_sched_min_granularity
,
252 .maxlen
= sizeof(unsigned int),
254 .proc_handler
= &sched_nr_latency_handler
,
255 .strategy
= &sysctl_intvec
,
256 .extra1
= &min_sched_granularity_ns
,
257 .extra2
= &max_sched_granularity_ns
,
260 .ctl_name
= CTL_UNNUMBERED
,
261 .procname
= "sched_latency_ns",
262 .data
= &sysctl_sched_latency
,
263 .maxlen
= sizeof(unsigned int),
265 .proc_handler
= &sched_nr_latency_handler
,
266 .strategy
= &sysctl_intvec
,
267 .extra1
= &min_sched_granularity_ns
,
268 .extra2
= &max_sched_granularity_ns
,
271 .ctl_name
= CTL_UNNUMBERED
,
272 .procname
= "sched_wakeup_granularity_ns",
273 .data
= &sysctl_sched_wakeup_granularity
,
274 .maxlen
= sizeof(unsigned int),
276 .proc_handler
= &proc_dointvec_minmax
,
277 .strategy
= &sysctl_intvec
,
278 .extra1
= &min_wakeup_granularity_ns
,
279 .extra2
= &max_wakeup_granularity_ns
,
282 .ctl_name
= CTL_UNNUMBERED
,
283 .procname
= "sched_shares_ratelimit",
284 .data
= &sysctl_sched_shares_ratelimit
,
285 .maxlen
= sizeof(unsigned int),
287 .proc_handler
= &proc_dointvec
,
290 .ctl_name
= CTL_UNNUMBERED
,
291 .procname
= "sched_shares_thresh",
292 .data
= &sysctl_sched_shares_thresh
,
293 .maxlen
= sizeof(unsigned int),
295 .proc_handler
= &proc_dointvec_minmax
,
296 .strategy
= &sysctl_intvec
,
300 .ctl_name
= CTL_UNNUMBERED
,
301 .procname
= "sched_child_runs_first",
302 .data
= &sysctl_sched_child_runs_first
,
303 .maxlen
= sizeof(unsigned int),
305 .proc_handler
= &proc_dointvec
,
308 .ctl_name
= CTL_UNNUMBERED
,
309 .procname
= "sched_features",
310 .data
= &sysctl_sched_features
,
311 .maxlen
= sizeof(unsigned int),
313 .proc_handler
= &proc_dointvec
,
316 .ctl_name
= CTL_UNNUMBERED
,
317 .procname
= "sched_migration_cost",
318 .data
= &sysctl_sched_migration_cost
,
319 .maxlen
= sizeof(unsigned int),
321 .proc_handler
= &proc_dointvec
,
324 .ctl_name
= CTL_UNNUMBERED
,
325 .procname
= "sched_nr_migrate",
326 .data
= &sysctl_sched_nr_migrate
,
327 .maxlen
= sizeof(unsigned int),
329 .proc_handler
= &proc_dointvec
,
333 .ctl_name
= CTL_UNNUMBERED
,
334 .procname
= "sched_rt_period_us",
335 .data
= &sysctl_sched_rt_period
,
336 .maxlen
= sizeof(unsigned int),
338 .proc_handler
= &sched_rt_handler
,
341 .ctl_name
= CTL_UNNUMBERED
,
342 .procname
= "sched_rt_runtime_us",
343 .data
= &sysctl_sched_rt_runtime
,
344 .maxlen
= sizeof(int),
346 .proc_handler
= &sched_rt_handler
,
349 .ctl_name
= CTL_UNNUMBERED
,
350 .procname
= "sched_compat_yield",
351 .data
= &sysctl_sched_compat_yield
,
352 .maxlen
= sizeof(unsigned int),
354 .proc_handler
= &proc_dointvec
,
356 #ifdef CONFIG_PROVE_LOCKING
358 .ctl_name
= CTL_UNNUMBERED
,
359 .procname
= "prove_locking",
360 .data
= &prove_locking
,
361 .maxlen
= sizeof(int),
363 .proc_handler
= &proc_dointvec
,
366 #ifdef CONFIG_LOCK_STAT
368 .ctl_name
= CTL_UNNUMBERED
,
369 .procname
= "lock_stat",
371 .maxlen
= sizeof(int),
373 .proc_handler
= &proc_dointvec
,
377 .ctl_name
= KERN_PANIC
,
379 .data
= &panic_timeout
,
380 .maxlen
= sizeof(int),
382 .proc_handler
= &proc_dointvec
,
385 .ctl_name
= KERN_CORE_USES_PID
,
386 .procname
= "core_uses_pid",
387 .data
= &core_uses_pid
,
388 .maxlen
= sizeof(int),
390 .proc_handler
= &proc_dointvec
,
393 .ctl_name
= KERN_CORE_PATTERN
,
394 .procname
= "core_pattern",
395 .data
= core_pattern
,
396 .maxlen
= CORENAME_MAX_SIZE
,
398 .proc_handler
= &proc_dostring
,
399 .strategy
= &sysctl_string
,
401 #ifdef CONFIG_PROC_SYSCTL
403 .procname
= "tainted",
404 .maxlen
= sizeof(long),
406 .proc_handler
= &proc_taint
,
409 #ifdef CONFIG_LATENCYTOP
411 .procname
= "latencytop",
412 .data
= &latencytop_enabled
,
413 .maxlen
= sizeof(int),
415 .proc_handler
= &proc_dointvec
,
418 #ifdef CONFIG_BLK_DEV_INITRD
420 .ctl_name
= KERN_REALROOTDEV
,
421 .procname
= "real-root-dev",
422 .data
= &real_root_dev
,
423 .maxlen
= sizeof(int),
425 .proc_handler
= &proc_dointvec
,
429 .ctl_name
= CTL_UNNUMBERED
,
430 .procname
= "print-fatal-signals",
431 .data
= &print_fatal_signals
,
432 .maxlen
= sizeof(int),
434 .proc_handler
= &proc_dointvec
,
438 .ctl_name
= KERN_SPARC_REBOOT
,
439 .procname
= "reboot-cmd",
440 .data
= reboot_command
,
443 .proc_handler
= &proc_dostring
,
444 .strategy
= &sysctl_string
,
447 .ctl_name
= KERN_SPARC_STOP_A
,
448 .procname
= "stop-a",
449 .data
= &stop_a_enabled
,
450 .maxlen
= sizeof (int),
452 .proc_handler
= &proc_dointvec
,
455 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
456 .procname
= "scons-poweroff",
457 .data
= &scons_pwroff
,
458 .maxlen
= sizeof (int),
460 .proc_handler
= &proc_dointvec
,
463 #ifdef CONFIG_SPARC64
465 .ctl_name
= CTL_UNNUMBERED
,
466 .procname
= "tsb-ratio",
467 .data
= &sysctl_tsb_ratio
,
468 .maxlen
= sizeof (int),
470 .proc_handler
= &proc_dointvec
,
475 .ctl_name
= KERN_HPPA_PWRSW
,
476 .procname
= "soft-power",
477 .data
= &pwrsw_enabled
,
478 .maxlen
= sizeof (int),
480 .proc_handler
= &proc_dointvec
,
483 .ctl_name
= KERN_HPPA_UNALIGNED
,
484 .procname
= "unaligned-trap",
485 .data
= &unaligned_enabled
,
486 .maxlen
= sizeof (int),
488 .proc_handler
= &proc_dointvec
,
492 .ctl_name
= KERN_CTLALTDEL
,
493 .procname
= "ctrl-alt-del",
495 .maxlen
= sizeof(int),
497 .proc_handler
= &proc_dointvec
,
499 #ifdef CONFIG_FUNCTION_TRACER
501 .ctl_name
= CTL_UNNUMBERED
,
502 .procname
= "ftrace_enabled",
503 .data
= &ftrace_enabled
,
504 .maxlen
= sizeof(int),
506 .proc_handler
= &ftrace_enable_sysctl
,
509 #ifdef CONFIG_STACK_TRACER
511 .ctl_name
= CTL_UNNUMBERED
,
512 .procname
= "stack_tracer_enabled",
513 .data
= &stack_tracer_enabled
,
514 .maxlen
= sizeof(int),
516 .proc_handler
= &stack_trace_sysctl
,
519 #ifdef CONFIG_TRACING
521 .ctl_name
= CTL_UNNUMBERED
,
522 .procname
= "ftrace_dump_on_oops",
523 .data
= &ftrace_dump_on_oops
,
524 .maxlen
= sizeof(int),
526 .proc_handler
= &proc_dointvec
,
529 #ifdef CONFIG_MODULES
531 .ctl_name
= KERN_MODPROBE
,
532 .procname
= "modprobe",
533 .data
= &modprobe_path
,
534 .maxlen
= KMOD_PATH_LEN
,
536 .proc_handler
= &proc_dostring
,
537 .strategy
= &sysctl_string
,
540 .ctl_name
= CTL_UNNUMBERED
,
541 .procname
= "modules_disabled",
542 .data
= &modules_disabled
,
543 .maxlen
= sizeof(int),
545 /* only handle a transition from default "0" to "1" */
546 .proc_handler
= &proc_dointvec_minmax
,
551 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
553 .ctl_name
= KERN_HOTPLUG
,
554 .procname
= "hotplug",
555 .data
= &uevent_helper
,
556 .maxlen
= UEVENT_HELPER_PATH_LEN
,
558 .proc_handler
= &proc_dostring
,
559 .strategy
= &sysctl_string
,
562 #ifdef CONFIG_CHR_DEV_SG
564 .ctl_name
= KERN_SG_BIG_BUFF
,
565 .procname
= "sg-big-buff",
566 .data
= &sg_big_buff
,
567 .maxlen
= sizeof (int),
569 .proc_handler
= &proc_dointvec
,
572 #ifdef CONFIG_BSD_PROCESS_ACCT
574 .ctl_name
= KERN_ACCT
,
577 .maxlen
= 3*sizeof(int),
579 .proc_handler
= &proc_dointvec
,
582 #ifdef CONFIG_MAGIC_SYSRQ
584 .ctl_name
= KERN_SYSRQ
,
586 .data
= &__sysrq_enabled
,
587 .maxlen
= sizeof (int),
589 .proc_handler
= &proc_dointvec
,
592 #ifdef CONFIG_PROC_SYSCTL
594 .procname
= "cad_pid",
596 .maxlen
= sizeof (int),
598 .proc_handler
= &proc_do_cad_pid
,
602 .ctl_name
= KERN_MAX_THREADS
,
603 .procname
= "threads-max",
604 .data
= &max_threads
,
605 .maxlen
= sizeof(int),
607 .proc_handler
= &proc_dointvec
,
610 .ctl_name
= KERN_RANDOM
,
611 .procname
= "random",
613 .child
= random_table
,
616 .ctl_name
= KERN_OVERFLOWUID
,
617 .procname
= "overflowuid",
618 .data
= &overflowuid
,
619 .maxlen
= sizeof(int),
621 .proc_handler
= &proc_dointvec_minmax
,
622 .strategy
= &sysctl_intvec
,
623 .extra1
= &minolduid
,
624 .extra2
= &maxolduid
,
627 .ctl_name
= KERN_OVERFLOWGID
,
628 .procname
= "overflowgid",
629 .data
= &overflowgid
,
630 .maxlen
= sizeof(int),
632 .proc_handler
= &proc_dointvec_minmax
,
633 .strategy
= &sysctl_intvec
,
634 .extra1
= &minolduid
,
635 .extra2
= &maxolduid
,
638 #ifdef CONFIG_MATHEMU
640 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
641 .procname
= "ieee_emulation_warnings",
642 .data
= &sysctl_ieee_emulation_warnings
,
643 .maxlen
= sizeof(int),
645 .proc_handler
= &proc_dointvec
,
649 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
650 .procname
= "userprocess_debug",
651 .data
= &sysctl_userprocess_debug
,
652 .maxlen
= sizeof(int),
654 .proc_handler
= &proc_dointvec
,
658 .ctl_name
= KERN_PIDMAX
,
659 .procname
= "pid_max",
661 .maxlen
= sizeof (int),
663 .proc_handler
= &proc_dointvec_minmax
,
664 .strategy
= sysctl_intvec
,
665 .extra1
= &pid_max_min
,
666 .extra2
= &pid_max_max
,
669 .ctl_name
= KERN_PANIC_ON_OOPS
,
670 .procname
= "panic_on_oops",
671 .data
= &panic_on_oops
,
672 .maxlen
= sizeof(int),
674 .proc_handler
= &proc_dointvec
,
676 #if defined CONFIG_PRINTK
678 .ctl_name
= KERN_PRINTK
,
679 .procname
= "printk",
680 .data
= &console_loglevel
,
681 .maxlen
= 4*sizeof(int),
683 .proc_handler
= &proc_dointvec
,
686 .ctl_name
= KERN_PRINTK_RATELIMIT
,
687 .procname
= "printk_ratelimit",
688 .data
= &printk_ratelimit_state
.interval
,
689 .maxlen
= sizeof(int),
691 .proc_handler
= &proc_dointvec_jiffies
,
692 .strategy
= &sysctl_jiffies
,
695 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
696 .procname
= "printk_ratelimit_burst",
697 .data
= &printk_ratelimit_state
.burst
,
698 .maxlen
= sizeof(int),
700 .proc_handler
= &proc_dointvec
,
704 .ctl_name
= KERN_NGROUPS_MAX
,
705 .procname
= "ngroups_max",
706 .data
= &ngroups_max
,
707 .maxlen
= sizeof (int),
709 .proc_handler
= &proc_dointvec
,
711 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
713 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
714 .procname
= "unknown_nmi_panic",
715 .data
= &unknown_nmi_panic
,
716 .maxlen
= sizeof (int),
718 .proc_handler
= &proc_dointvec
,
721 .procname
= "nmi_watchdog",
722 .data
= &nmi_watchdog_enabled
,
723 .maxlen
= sizeof (int),
725 .proc_handler
= &proc_nmi_enabled
,
728 #if defined(CONFIG_X86)
730 .ctl_name
= KERN_PANIC_ON_NMI
,
731 .procname
= "panic_on_unrecovered_nmi",
732 .data
= &panic_on_unrecovered_nmi
,
733 .maxlen
= sizeof(int),
735 .proc_handler
= &proc_dointvec
,
738 .ctl_name
= KERN_BOOTLOADER_TYPE
,
739 .procname
= "bootloader_type",
740 .data
= &bootloader_type
,
741 .maxlen
= sizeof (int),
743 .proc_handler
= &proc_dointvec
,
746 .ctl_name
= CTL_UNNUMBERED
,
747 .procname
= "bootloader_version",
748 .data
= &bootloader_version
,
749 .maxlen
= sizeof (int),
751 .proc_handler
= &proc_dointvec
,
754 .ctl_name
= CTL_UNNUMBERED
,
755 .procname
= "kstack_depth_to_print",
756 .data
= &kstack_depth_to_print
,
757 .maxlen
= sizeof(int),
759 .proc_handler
= &proc_dointvec
,
762 .ctl_name
= CTL_UNNUMBERED
,
763 .procname
= "io_delay_type",
764 .data
= &io_delay_type
,
765 .maxlen
= sizeof(int),
767 .proc_handler
= &proc_dointvec
,
770 #if defined(CONFIG_MMU)
772 .ctl_name
= KERN_RANDOMIZE
,
773 .procname
= "randomize_va_space",
774 .data
= &randomize_va_space
,
775 .maxlen
= sizeof(int),
777 .proc_handler
= &proc_dointvec
,
780 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
782 .ctl_name
= KERN_SPIN_RETRY
,
783 .procname
= "spin_retry",
785 .maxlen
= sizeof (int),
787 .proc_handler
= &proc_dointvec
,
790 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
792 .procname
= "acpi_video_flags",
793 .data
= &acpi_realmode_flags
,
794 .maxlen
= sizeof (unsigned long),
796 .proc_handler
= &proc_doulongvec_minmax
,
801 .ctl_name
= KERN_IA64_UNALIGNED
,
802 .procname
= "ignore-unaligned-usertrap",
803 .data
= &no_unaligned_warning
,
804 .maxlen
= sizeof (int),
806 .proc_handler
= &proc_dointvec
,
809 .ctl_name
= CTL_UNNUMBERED
,
810 .procname
= "unaligned-dump-stack",
811 .data
= &unaligned_dump_stack
,
812 .maxlen
= sizeof (int),
814 .proc_handler
= &proc_dointvec
,
817 #ifdef CONFIG_DETECT_SOFTLOCKUP
819 .ctl_name
= CTL_UNNUMBERED
,
820 .procname
= "softlockup_panic",
821 .data
= &softlockup_panic
,
822 .maxlen
= sizeof(int),
824 .proc_handler
= &proc_dointvec_minmax
,
825 .strategy
= &sysctl_intvec
,
830 .ctl_name
= CTL_UNNUMBERED
,
831 .procname
= "softlockup_thresh",
832 .data
= &softlockup_thresh
,
833 .maxlen
= sizeof(int),
835 .proc_handler
= &proc_dosoftlockup_thresh
,
836 .strategy
= &sysctl_intvec
,
841 #ifdef CONFIG_DETECT_HUNG_TASK
843 .ctl_name
= CTL_UNNUMBERED
,
844 .procname
= "hung_task_panic",
845 .data
= &sysctl_hung_task_panic
,
846 .maxlen
= sizeof(int),
848 .proc_handler
= &proc_dointvec_minmax
,
849 .strategy
= &sysctl_intvec
,
854 .ctl_name
= CTL_UNNUMBERED
,
855 .procname
= "hung_task_check_count",
856 .data
= &sysctl_hung_task_check_count
,
857 .maxlen
= sizeof(unsigned long),
859 .proc_handler
= &proc_doulongvec_minmax
,
860 .strategy
= &sysctl_intvec
,
863 .ctl_name
= CTL_UNNUMBERED
,
864 .procname
= "hung_task_timeout_secs",
865 .data
= &sysctl_hung_task_timeout_secs
,
866 .maxlen
= sizeof(unsigned long),
868 .proc_handler
= &proc_dohung_task_timeout_secs
,
869 .strategy
= &sysctl_intvec
,
872 .ctl_name
= CTL_UNNUMBERED
,
873 .procname
= "hung_task_warnings",
874 .data
= &sysctl_hung_task_warnings
,
875 .maxlen
= sizeof(unsigned long),
877 .proc_handler
= &proc_doulongvec_minmax
,
878 .strategy
= &sysctl_intvec
,
883 .ctl_name
= KERN_COMPAT_LOG
,
884 .procname
= "compat-log",
886 .maxlen
= sizeof (int),
888 .proc_handler
= &proc_dointvec
,
891 #ifdef CONFIG_RT_MUTEXES
893 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
894 .procname
= "max_lock_depth",
895 .data
= &max_lock_depth
,
896 .maxlen
= sizeof(int),
898 .proc_handler
= &proc_dointvec
,
902 .ctl_name
= CTL_UNNUMBERED
,
903 .procname
= "poweroff_cmd",
904 .data
= &poweroff_cmd
,
905 .maxlen
= POWEROFF_CMD_PATH_LEN
,
907 .proc_handler
= &proc_dostring
,
908 .strategy
= &sysctl_string
,
912 .ctl_name
= CTL_UNNUMBERED
,
915 .child
= key_sysctls
,
918 #ifdef CONFIG_RCU_TORTURE_TEST
920 .ctl_name
= CTL_UNNUMBERED
,
921 .procname
= "rcutorture_runnable",
922 .data
= &rcutorture_runnable
,
923 .maxlen
= sizeof(int),
925 .proc_handler
= &proc_dointvec
,
928 #ifdef CONFIG_SLOW_WORK
930 .ctl_name
= CTL_UNNUMBERED
,
931 .procname
= "slow-work",
933 .child
= slow_work_sysctls
,
936 #ifdef CONFIG_PERF_COUNTERS
938 .ctl_name
= CTL_UNNUMBERED
,
939 .procname
= "perf_counter_paranoid",
940 .data
= &sysctl_perf_counter_paranoid
,
941 .maxlen
= sizeof(sysctl_perf_counter_paranoid
),
943 .proc_handler
= &proc_dointvec
,
946 .ctl_name
= CTL_UNNUMBERED
,
947 .procname
= "perf_counter_mlock_kb",
948 .data
= &sysctl_perf_counter_mlock
,
949 .maxlen
= sizeof(sysctl_perf_counter_mlock
),
951 .proc_handler
= &proc_dointvec
,
954 .ctl_name
= CTL_UNNUMBERED
,
955 .procname
= "perf_counter_max_sample_rate",
956 .data
= &sysctl_perf_counter_sample_rate
,
957 .maxlen
= sizeof(sysctl_perf_counter_sample_rate
),
959 .proc_handler
= &proc_dointvec
,
963 * NOTE: do not add new entries to this table unless you have read
964 * Documentation/sysctl/ctl_unnumbered.txt
969 static struct ctl_table vm_table
[] = {
971 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
972 .procname
= "overcommit_memory",
973 .data
= &sysctl_overcommit_memory
,
974 .maxlen
= sizeof(sysctl_overcommit_memory
),
976 .proc_handler
= &proc_dointvec
,
979 .ctl_name
= VM_PANIC_ON_OOM
,
980 .procname
= "panic_on_oom",
981 .data
= &sysctl_panic_on_oom
,
982 .maxlen
= sizeof(sysctl_panic_on_oom
),
984 .proc_handler
= &proc_dointvec
,
987 .ctl_name
= CTL_UNNUMBERED
,
988 .procname
= "oom_kill_allocating_task",
989 .data
= &sysctl_oom_kill_allocating_task
,
990 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
992 .proc_handler
= &proc_dointvec
,
995 .ctl_name
= CTL_UNNUMBERED
,
996 .procname
= "oom_dump_tasks",
997 .data
= &sysctl_oom_dump_tasks
,
998 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1000 .proc_handler
= &proc_dointvec
,
1003 .ctl_name
= VM_OVERCOMMIT_RATIO
,
1004 .procname
= "overcommit_ratio",
1005 .data
= &sysctl_overcommit_ratio
,
1006 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1008 .proc_handler
= &proc_dointvec
,
1011 .ctl_name
= VM_PAGE_CLUSTER
,
1012 .procname
= "page-cluster",
1013 .data
= &page_cluster
,
1014 .maxlen
= sizeof(int),
1016 .proc_handler
= &proc_dointvec
,
1019 .ctl_name
= VM_DIRTY_BACKGROUND
,
1020 .procname
= "dirty_background_ratio",
1021 .data
= &dirty_background_ratio
,
1022 .maxlen
= sizeof(dirty_background_ratio
),
1024 .proc_handler
= &dirty_background_ratio_handler
,
1025 .strategy
= &sysctl_intvec
,
1027 .extra2
= &one_hundred
,
1030 .ctl_name
= CTL_UNNUMBERED
,
1031 .procname
= "dirty_background_bytes",
1032 .data
= &dirty_background_bytes
,
1033 .maxlen
= sizeof(dirty_background_bytes
),
1035 .proc_handler
= &dirty_background_bytes_handler
,
1036 .strategy
= &sysctl_intvec
,
1040 .ctl_name
= VM_DIRTY_RATIO
,
1041 .procname
= "dirty_ratio",
1042 .data
= &vm_dirty_ratio
,
1043 .maxlen
= sizeof(vm_dirty_ratio
),
1045 .proc_handler
= &dirty_ratio_handler
,
1046 .strategy
= &sysctl_intvec
,
1048 .extra2
= &one_hundred
,
1051 .ctl_name
= CTL_UNNUMBERED
,
1052 .procname
= "dirty_bytes",
1053 .data
= &vm_dirty_bytes
,
1054 .maxlen
= sizeof(vm_dirty_bytes
),
1056 .proc_handler
= &dirty_bytes_handler
,
1057 .strategy
= &sysctl_intvec
,
1058 .extra1
= &dirty_bytes_min
,
1061 .procname
= "dirty_writeback_centisecs",
1062 .data
= &dirty_writeback_interval
,
1063 .maxlen
= sizeof(dirty_writeback_interval
),
1065 .proc_handler
= &dirty_writeback_centisecs_handler
,
1068 .procname
= "dirty_expire_centisecs",
1069 .data
= &dirty_expire_interval
,
1070 .maxlen
= sizeof(dirty_expire_interval
),
1072 .proc_handler
= &proc_dointvec
,
1075 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
1076 .procname
= "nr_pdflush_threads",
1077 .data
= &nr_pdflush_threads
,
1078 .maxlen
= sizeof nr_pdflush_threads
,
1079 .mode
= 0444 /* read-only*/,
1080 .proc_handler
= &proc_dointvec
,
1083 .ctl_name
= VM_SWAPPINESS
,
1084 .procname
= "swappiness",
1085 .data
= &vm_swappiness
,
1086 .maxlen
= sizeof(vm_swappiness
),
1088 .proc_handler
= &proc_dointvec_minmax
,
1089 .strategy
= &sysctl_intvec
,
1091 .extra2
= &one_hundred
,
1093 #ifdef CONFIG_HUGETLB_PAGE
1095 .procname
= "nr_hugepages",
1097 .maxlen
= sizeof(unsigned long),
1099 .proc_handler
= &hugetlb_sysctl_handler
,
1100 .extra1
= (void *)&hugetlb_zero
,
1101 .extra2
= (void *)&hugetlb_infinity
,
1104 .ctl_name
= VM_HUGETLB_GROUP
,
1105 .procname
= "hugetlb_shm_group",
1106 .data
= &sysctl_hugetlb_shm_group
,
1107 .maxlen
= sizeof(gid_t
),
1109 .proc_handler
= &proc_dointvec
,
1112 .ctl_name
= CTL_UNNUMBERED
,
1113 .procname
= "hugepages_treat_as_movable",
1114 .data
= &hugepages_treat_as_movable
,
1115 .maxlen
= sizeof(int),
1117 .proc_handler
= &hugetlb_treat_movable_handler
,
1120 .ctl_name
= CTL_UNNUMBERED
,
1121 .procname
= "nr_overcommit_hugepages",
1123 .maxlen
= sizeof(unsigned long),
1125 .proc_handler
= &hugetlb_overcommit_handler
,
1126 .extra1
= (void *)&hugetlb_zero
,
1127 .extra2
= (void *)&hugetlb_infinity
,
1131 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
1132 .procname
= "lowmem_reserve_ratio",
1133 .data
= &sysctl_lowmem_reserve_ratio
,
1134 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1136 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
1137 .strategy
= &sysctl_intvec
,
1140 .ctl_name
= VM_DROP_PAGECACHE
,
1141 .procname
= "drop_caches",
1142 .data
= &sysctl_drop_caches
,
1143 .maxlen
= sizeof(int),
1145 .proc_handler
= drop_caches_sysctl_handler
,
1146 .strategy
= &sysctl_intvec
,
1149 .ctl_name
= VM_MIN_FREE_KBYTES
,
1150 .procname
= "min_free_kbytes",
1151 .data
= &min_free_kbytes
,
1152 .maxlen
= sizeof(min_free_kbytes
),
1154 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1155 .strategy
= &sysctl_intvec
,
1159 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1160 .procname
= "percpu_pagelist_fraction",
1161 .data
= &percpu_pagelist_fraction
,
1162 .maxlen
= sizeof(percpu_pagelist_fraction
),
1164 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1165 .strategy
= &sysctl_intvec
,
1166 .extra1
= &min_percpu_pagelist_fract
,
1170 .ctl_name
= VM_MAX_MAP_COUNT
,
1171 .procname
= "max_map_count",
1172 .data
= &sysctl_max_map_count
,
1173 .maxlen
= sizeof(sysctl_max_map_count
),
1175 .proc_handler
= &proc_dointvec
1179 .ctl_name
= CTL_UNNUMBERED
,
1180 .procname
= "nr_trim_pages",
1181 .data
= &sysctl_nr_trim_pages
,
1182 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1184 .proc_handler
= &proc_dointvec_minmax
,
1185 .strategy
= &sysctl_intvec
,
1190 .ctl_name
= VM_LAPTOP_MODE
,
1191 .procname
= "laptop_mode",
1192 .data
= &laptop_mode
,
1193 .maxlen
= sizeof(laptop_mode
),
1195 .proc_handler
= &proc_dointvec_jiffies
,
1196 .strategy
= &sysctl_jiffies
,
1199 .ctl_name
= VM_BLOCK_DUMP
,
1200 .procname
= "block_dump",
1201 .data
= &block_dump
,
1202 .maxlen
= sizeof(block_dump
),
1204 .proc_handler
= &proc_dointvec
,
1205 .strategy
= &sysctl_intvec
,
1209 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1210 .procname
= "vfs_cache_pressure",
1211 .data
= &sysctl_vfs_cache_pressure
,
1212 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1214 .proc_handler
= &proc_dointvec
,
1215 .strategy
= &sysctl_intvec
,
1218 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1220 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1221 .procname
= "legacy_va_layout",
1222 .data
= &sysctl_legacy_va_layout
,
1223 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1225 .proc_handler
= &proc_dointvec
,
1226 .strategy
= &sysctl_intvec
,
1232 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1233 .procname
= "zone_reclaim_mode",
1234 .data
= &zone_reclaim_mode
,
1235 .maxlen
= sizeof(zone_reclaim_mode
),
1237 .proc_handler
= &proc_dointvec
,
1238 .strategy
= &sysctl_intvec
,
1242 .ctl_name
= VM_MIN_UNMAPPED
,
1243 .procname
= "min_unmapped_ratio",
1244 .data
= &sysctl_min_unmapped_ratio
,
1245 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1247 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1248 .strategy
= &sysctl_intvec
,
1250 .extra2
= &one_hundred
,
1253 .ctl_name
= VM_MIN_SLAB
,
1254 .procname
= "min_slab_ratio",
1255 .data
= &sysctl_min_slab_ratio
,
1256 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1258 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1259 .strategy
= &sysctl_intvec
,
1261 .extra2
= &one_hundred
,
1266 .ctl_name
= CTL_UNNUMBERED
,
1267 .procname
= "stat_interval",
1268 .data
= &sysctl_stat_interval
,
1269 .maxlen
= sizeof(sysctl_stat_interval
),
1271 .proc_handler
= &proc_dointvec_jiffies
,
1272 .strategy
= &sysctl_jiffies
,
1276 .ctl_name
= CTL_UNNUMBERED
,
1277 .procname
= "mmap_min_addr",
1278 .data
= &mmap_min_addr
,
1279 .maxlen
= sizeof(unsigned long),
1281 .proc_handler
= &proc_doulongvec_minmax
,
1285 .ctl_name
= CTL_UNNUMBERED
,
1286 .procname
= "numa_zonelist_order",
1287 .data
= &numa_zonelist_order
,
1288 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1290 .proc_handler
= &numa_zonelist_order_handler
,
1291 .strategy
= &sysctl_string
,
1294 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1295 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1297 .ctl_name
= VM_VDSO_ENABLED
,
1298 .procname
= "vdso_enabled",
1299 .data
= &vdso_enabled
,
1300 .maxlen
= sizeof(vdso_enabled
),
1302 .proc_handler
= &proc_dointvec
,
1303 .strategy
= &sysctl_intvec
,
1307 #ifdef CONFIG_HIGHMEM
1309 .ctl_name
= CTL_UNNUMBERED
,
1310 .procname
= "highmem_is_dirtyable",
1311 .data
= &vm_highmem_is_dirtyable
,
1312 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1314 .proc_handler
= &proc_dointvec_minmax
,
1315 .strategy
= &sysctl_intvec
,
1320 #ifdef CONFIG_UNEVICTABLE_LRU
1322 .ctl_name
= CTL_UNNUMBERED
,
1323 .procname
= "scan_unevictable_pages",
1324 .data
= &scan_unevictable_pages
,
1325 .maxlen
= sizeof(scan_unevictable_pages
),
1327 .proc_handler
= &scan_unevictable_handler
,
1331 * NOTE: do not add new entries to this table unless you have read
1332 * Documentation/sysctl/ctl_unnumbered.txt
1337 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1338 static struct ctl_table binfmt_misc_table
[] = {
1343 static struct ctl_table fs_table
[] = {
1345 .ctl_name
= FS_NRINODE
,
1346 .procname
= "inode-nr",
1347 .data
= &inodes_stat
,
1348 .maxlen
= 2*sizeof(int),
1350 .proc_handler
= &proc_dointvec
,
1353 .ctl_name
= FS_STATINODE
,
1354 .procname
= "inode-state",
1355 .data
= &inodes_stat
,
1356 .maxlen
= 7*sizeof(int),
1358 .proc_handler
= &proc_dointvec
,
1361 .procname
= "file-nr",
1362 .data
= &files_stat
,
1363 .maxlen
= 3*sizeof(int),
1365 .proc_handler
= &proc_nr_files
,
1368 .ctl_name
= FS_MAXFILE
,
1369 .procname
= "file-max",
1370 .data
= &files_stat
.max_files
,
1371 .maxlen
= sizeof(int),
1373 .proc_handler
= &proc_dointvec
,
1376 .ctl_name
= CTL_UNNUMBERED
,
1377 .procname
= "nr_open",
1378 .data
= &sysctl_nr_open
,
1379 .maxlen
= sizeof(int),
1381 .proc_handler
= &proc_dointvec_minmax
,
1382 .extra1
= &sysctl_nr_open_min
,
1383 .extra2
= &sysctl_nr_open_max
,
1386 .ctl_name
= FS_DENTRY
,
1387 .procname
= "dentry-state",
1388 .data
= &dentry_stat
,
1389 .maxlen
= 6*sizeof(int),
1391 .proc_handler
= &proc_dointvec
,
1394 .ctl_name
= FS_OVERFLOWUID
,
1395 .procname
= "overflowuid",
1396 .data
= &fs_overflowuid
,
1397 .maxlen
= sizeof(int),
1399 .proc_handler
= &proc_dointvec_minmax
,
1400 .strategy
= &sysctl_intvec
,
1401 .extra1
= &minolduid
,
1402 .extra2
= &maxolduid
,
1405 .ctl_name
= FS_OVERFLOWGID
,
1406 .procname
= "overflowgid",
1407 .data
= &fs_overflowgid
,
1408 .maxlen
= sizeof(int),
1410 .proc_handler
= &proc_dointvec_minmax
,
1411 .strategy
= &sysctl_intvec
,
1412 .extra1
= &minolduid
,
1413 .extra2
= &maxolduid
,
1415 #ifdef CONFIG_FILE_LOCKING
1417 .ctl_name
= FS_LEASES
,
1418 .procname
= "leases-enable",
1419 .data
= &leases_enable
,
1420 .maxlen
= sizeof(int),
1422 .proc_handler
= &proc_dointvec
,
1425 #ifdef CONFIG_DNOTIFY
1427 .ctl_name
= FS_DIR_NOTIFY
,
1428 .procname
= "dir-notify-enable",
1429 .data
= &dir_notify_enable
,
1430 .maxlen
= sizeof(int),
1432 .proc_handler
= &proc_dointvec
,
1436 #ifdef CONFIG_FILE_LOCKING
1438 .ctl_name
= FS_LEASE_TIME
,
1439 .procname
= "lease-break-time",
1440 .data
= &lease_break_time
,
1441 .maxlen
= sizeof(int),
1443 .proc_handler
= &proc_dointvec
,
1448 .procname
= "aio-nr",
1450 .maxlen
= sizeof(aio_nr
),
1452 .proc_handler
= &proc_doulongvec_minmax
,
1455 .procname
= "aio-max-nr",
1456 .data
= &aio_max_nr
,
1457 .maxlen
= sizeof(aio_max_nr
),
1459 .proc_handler
= &proc_doulongvec_minmax
,
1461 #endif /* CONFIG_AIO */
1462 #ifdef CONFIG_INOTIFY_USER
1464 .ctl_name
= FS_INOTIFY
,
1465 .procname
= "inotify",
1467 .child
= inotify_table
,
1472 .procname
= "epoll",
1474 .child
= epoll_table
,
1479 .ctl_name
= KERN_SETUID_DUMPABLE
,
1480 .procname
= "suid_dumpable",
1481 .data
= &suid_dumpable
,
1482 .maxlen
= sizeof(int),
1484 .proc_handler
= &proc_dointvec_minmax
,
1485 .strategy
= &sysctl_intvec
,
1489 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1491 .ctl_name
= CTL_UNNUMBERED
,
1492 .procname
= "binfmt_misc",
1494 .child
= binfmt_misc_table
,
1498 * NOTE: do not add new entries to this table unless you have read
1499 * Documentation/sysctl/ctl_unnumbered.txt
1504 static struct ctl_table debug_table
[] = {
1505 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1507 .ctl_name
= CTL_UNNUMBERED
,
1508 .procname
= "exception-trace",
1509 .data
= &show_unhandled_signals
,
1510 .maxlen
= sizeof(int),
1512 .proc_handler
= proc_dointvec
1518 static struct ctl_table dev_table
[] = {
1522 static DEFINE_SPINLOCK(sysctl_lock
);
1524 /* called under sysctl_lock */
1525 static int use_table(struct ctl_table_header
*p
)
1527 if (unlikely(p
->unregistering
))
1533 /* called under sysctl_lock */
1534 static void unuse_table(struct ctl_table_header
*p
)
1537 if (unlikely(p
->unregistering
))
1538 complete(p
->unregistering
);
1541 /* called under sysctl_lock, will reacquire if has to wait */
1542 static void start_unregistering(struct ctl_table_header
*p
)
1545 * if p->used is 0, nobody will ever touch that entry again;
1546 * we'll eliminate all paths to it before dropping sysctl_lock
1548 if (unlikely(p
->used
)) {
1549 struct completion wait
;
1550 init_completion(&wait
);
1551 p
->unregistering
= &wait
;
1552 spin_unlock(&sysctl_lock
);
1553 wait_for_completion(&wait
);
1554 spin_lock(&sysctl_lock
);
1556 /* anything non-NULL; we'll never dereference it */
1557 p
->unregistering
= ERR_PTR(-EINVAL
);
1560 * do not remove from the list until nobody holds it; walking the
1561 * list in do_sysctl() relies on that.
1563 list_del_init(&p
->ctl_entry
);
1566 void sysctl_head_get(struct ctl_table_header
*head
)
1568 spin_lock(&sysctl_lock
);
1570 spin_unlock(&sysctl_lock
);
1573 void sysctl_head_put(struct ctl_table_header
*head
)
1575 spin_lock(&sysctl_lock
);
1578 spin_unlock(&sysctl_lock
);
1581 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1585 spin_lock(&sysctl_lock
);
1586 if (!use_table(head
))
1587 head
= ERR_PTR(-ENOENT
);
1588 spin_unlock(&sysctl_lock
);
1592 void sysctl_head_finish(struct ctl_table_header
*head
)
1596 spin_lock(&sysctl_lock
);
1598 spin_unlock(&sysctl_lock
);
1601 static struct ctl_table_set
*
1602 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1604 struct ctl_table_set
*set
= &root
->default_set
;
1606 set
= root
->lookup(root
, namespaces
);
1610 static struct list_head
*
1611 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1613 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1617 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1618 struct ctl_table_header
*prev
)
1620 struct ctl_table_root
*root
;
1621 struct list_head
*header_list
;
1622 struct ctl_table_header
*head
;
1623 struct list_head
*tmp
;
1625 spin_lock(&sysctl_lock
);
1628 tmp
= &prev
->ctl_entry
;
1632 tmp
= &root_table_header
.ctl_entry
;
1634 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1636 if (!use_table(head
))
1638 spin_unlock(&sysctl_lock
);
1643 header_list
= lookup_header_list(root
, namespaces
);
1644 if (tmp
!= header_list
)
1648 root
= list_entry(root
->root_list
.next
,
1649 struct ctl_table_root
, root_list
);
1650 if (root
== &sysctl_table_root
)
1652 header_list
= lookup_header_list(root
, namespaces
);
1653 } while (list_empty(header_list
));
1654 tmp
= header_list
->next
;
1657 spin_unlock(&sysctl_lock
);
1661 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1663 return __sysctl_head_next(current
->nsproxy
, prev
);
1666 void register_sysctl_root(struct ctl_table_root
*root
)
1668 spin_lock(&sysctl_lock
);
1669 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1670 spin_unlock(&sysctl_lock
);
1673 #ifdef CONFIG_SYSCTL_SYSCALL
1674 /* Perform the actual read/write of a sysctl table entry. */
1675 static int do_sysctl_strategy(struct ctl_table_root
*root
,
1676 struct ctl_table
*table
,
1677 void __user
*oldval
, size_t __user
*oldlenp
,
1678 void __user
*newval
, size_t newlen
)
1686 if (sysctl_perm(root
, table
, op
))
1689 if (table
->strategy
) {
1690 rc
= table
->strategy(table
, oldval
, oldlenp
, newval
, newlen
);
1697 /* If there is no strategy routine, or if the strategy returns
1698 * zero, proceed with automatic r/w */
1699 if (table
->data
&& table
->maxlen
) {
1700 rc
= sysctl_data(table
, oldval
, oldlenp
, newval
, newlen
);
1707 static int parse_table(int __user
*name
, int nlen
,
1708 void __user
*oldval
, size_t __user
*oldlenp
,
1709 void __user
*newval
, size_t newlen
,
1710 struct ctl_table_root
*root
,
1711 struct ctl_table
*table
)
1717 if (get_user(n
, name
))
1719 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1720 if (!table
->ctl_name
)
1722 if (n
== table
->ctl_name
) {
1725 if (sysctl_perm(root
, table
, MAY_EXEC
))
1729 table
= table
->child
;
1732 error
= do_sysctl_strategy(root
, table
,
1741 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1742 void __user
*newval
, size_t newlen
)
1744 struct ctl_table_header
*head
;
1745 int error
= -ENOTDIR
;
1747 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1751 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1755 for (head
= sysctl_head_next(NULL
); head
;
1756 head
= sysctl_head_next(head
)) {
1757 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1759 head
->root
, head
->ctl_table
);
1760 if (error
!= -ENOTDIR
) {
1761 sysctl_head_finish(head
);
1768 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
1770 struct __sysctl_args tmp
;
1773 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1776 error
= deprecated_sysctl_warning(&tmp
);
1781 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1782 tmp
.newval
, tmp
.newlen
);
1787 #endif /* CONFIG_SYSCTL_SYSCALL */
1790 * sysctl_perm does NOT grant the superuser all rights automatically, because
1791 * some sysctl variables are readonly even to root.
1794 static int test_perm(int mode
, int op
)
1796 if (!current_euid())
1798 else if (in_egroup_p(0))
1800 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1805 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1810 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1814 if (root
->permissions
)
1815 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1819 return test_perm(mode
, op
);
1822 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1824 for (; table
->ctl_name
|| table
->procname
; table
++) {
1825 table
->parent
= parent
;
1827 sysctl_set_parent(table
, table
->child
);
1831 static __init
int sysctl_init(void)
1833 sysctl_set_parent(NULL
, root_table
);
1834 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1837 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1843 core_initcall(sysctl_init
);
1845 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1846 struct ctl_table
*table
)
1848 struct ctl_table
*p
;
1849 const char *s
= branch
->procname
;
1851 /* branch should have named subdirectory as its first element */
1852 if (!s
|| !branch
->child
)
1855 /* ... and nothing else */
1856 if (branch
[1].procname
|| branch
[1].ctl_name
)
1859 /* table should contain subdirectory with the same name */
1860 for (p
= table
; p
->procname
|| p
->ctl_name
; p
++) {
1863 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1869 /* see if attaching q to p would be an improvement */
1870 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1872 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1873 struct ctl_table
*next
;
1875 int not_in_parent
= !p
->attached_by
;
1877 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1878 if (by
== q
->attached_by
)
1880 if (to
== p
->attached_by
)
1886 if (is_better
&& not_in_parent
) {
1887 q
->attached_by
= by
;
1888 q
->attached_to
= to
;
1894 * __register_sysctl_paths - register a sysctl hierarchy
1895 * @root: List of sysctl headers to register on
1896 * @namespaces: Data to compute which lists of sysctl entries are visible
1897 * @path: The path to the directory the sysctl table is in.
1898 * @table: the top-level table structure
1900 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1901 * array. A completely 0 filled entry terminates the table.
1903 * The members of the &struct ctl_table structure are used as follows:
1905 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1906 * must be unique within that level of sysctl
1908 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1909 * enter a sysctl file
1911 * data - a pointer to data for use by proc_handler
1913 * maxlen - the maximum size in bytes of the data
1915 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1917 * child - a pointer to the child sysctl table if this entry is a directory, or
1920 * proc_handler - the text handler routine (described below)
1922 * strategy - the strategy routine (described below)
1924 * de - for internal use by the sysctl routines
1926 * extra1, extra2 - extra pointers usable by the proc handler routines
1928 * Leaf nodes in the sysctl tree will be represented by a single file
1929 * under /proc; non-leaf nodes will be represented by directories.
1931 * sysctl(2) can automatically manage read and write requests through
1932 * the sysctl table. The data and maxlen fields of the ctl_table
1933 * struct enable minimal validation of the values being written to be
1934 * performed, and the mode field allows minimal authentication.
1936 * More sophisticated management can be enabled by the provision of a
1937 * strategy routine with the table entry. This will be called before
1938 * any automatic read or write of the data is performed.
1940 * The strategy routine may return
1942 * < 0 - Error occurred (error is passed to user process)
1944 * 0 - OK - proceed with automatic read or write.
1946 * > 0 - OK - read or write has been done by the strategy routine, so
1947 * return immediately.
1949 * There must be a proc_handler routine for any terminal nodes
1950 * mirrored under /proc/sys (non-terminals are handled by a built-in
1951 * directory handler). Several default handlers are available to
1952 * cover common cases -
1954 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1955 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1956 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1958 * It is the handler's job to read the input buffer from user memory
1959 * and process it. The handler should return 0 on success.
1961 * This routine returns %NULL on a failure to register, and a pointer
1962 * to the table header on success.
1964 struct ctl_table_header
*__register_sysctl_paths(
1965 struct ctl_table_root
*root
,
1966 struct nsproxy
*namespaces
,
1967 const struct ctl_path
*path
, struct ctl_table
*table
)
1969 struct ctl_table_header
*header
;
1970 struct ctl_table
*new, **prevp
;
1971 unsigned int n
, npath
;
1972 struct ctl_table_set
*set
;
1974 /* Count the path components */
1975 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
1979 * For each path component, allocate a 2-element ctl_table array.
1980 * The first array element will be filled with the sysctl entry
1981 * for this, the second will be the sentinel (ctl_name == 0).
1983 * We allocate everything in one go so that we don't have to
1984 * worry about freeing additional memory in unregister_sysctl_table.
1986 header
= kzalloc(sizeof(struct ctl_table_header
) +
1987 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1991 new = (struct ctl_table
*) (header
+ 1);
1993 /* Now connect the dots */
1994 prevp
= &header
->ctl_table
;
1995 for (n
= 0; n
< npath
; ++n
, ++path
) {
1996 /* Copy the procname */
1997 new->procname
= path
->procname
;
1998 new->ctl_name
= path
->ctl_name
;
2002 prevp
= &new->child
;
2007 header
->ctl_table_arg
= table
;
2009 INIT_LIST_HEAD(&header
->ctl_entry
);
2011 header
->unregistering
= NULL
;
2012 header
->root
= root
;
2013 sysctl_set_parent(NULL
, header
->ctl_table
);
2015 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
2016 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
2021 spin_lock(&sysctl_lock
);
2022 header
->set
= lookup_header_set(root
, namespaces
);
2023 header
->attached_by
= header
->ctl_table
;
2024 header
->attached_to
= root_table
;
2025 header
->parent
= &root_table_header
;
2026 for (set
= header
->set
; set
; set
= set
->parent
) {
2027 struct ctl_table_header
*p
;
2028 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
2029 if (p
->unregistering
)
2031 try_attach(p
, header
);
2034 header
->parent
->count
++;
2035 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
2036 spin_unlock(&sysctl_lock
);
2042 * register_sysctl_table_path - register a sysctl table hierarchy
2043 * @path: The path to the directory the sysctl table is in.
2044 * @table: the top-level table structure
2046 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2047 * array. A completely 0 filled entry terminates the table.
2049 * See __register_sysctl_paths for more details.
2051 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2052 struct ctl_table
*table
)
2054 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
2059 * register_sysctl_table - register a sysctl table hierarchy
2060 * @table: the top-level table structure
2062 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2063 * array. A completely 0 filled entry terminates the table.
2065 * See register_sysctl_paths for more details.
2067 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
2069 static const struct ctl_path null_path
[] = { {} };
2071 return register_sysctl_paths(null_path
, table
);
2075 * unregister_sysctl_table - unregister a sysctl table hierarchy
2076 * @header: the header returned from register_sysctl_table
2078 * Unregisters the sysctl table and all children. proc entries may not
2079 * actually be removed until they are no longer used by anyone.
2081 void unregister_sysctl_table(struct ctl_table_header
* header
)
2088 spin_lock(&sysctl_lock
);
2089 start_unregistering(header
);
2090 if (!--header
->parent
->count
) {
2092 kfree(header
->parent
);
2094 if (!--header
->count
)
2096 spin_unlock(&sysctl_lock
);
2099 int sysctl_is_seen(struct ctl_table_header
*p
)
2101 struct ctl_table_set
*set
= p
->set
;
2103 spin_lock(&sysctl_lock
);
2104 if (p
->unregistering
)
2106 else if (!set
->is_seen
)
2109 res
= set
->is_seen(set
);
2110 spin_unlock(&sysctl_lock
);
2114 void setup_sysctl_set(struct ctl_table_set
*p
,
2115 struct ctl_table_set
*parent
,
2116 int (*is_seen
)(struct ctl_table_set
*))
2118 INIT_LIST_HEAD(&p
->list
);
2119 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
2120 p
->is_seen
= is_seen
;
2123 #else /* !CONFIG_SYSCTL */
2124 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
2129 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2130 struct ctl_table
*table
)
2135 void unregister_sysctl_table(struct ctl_table_header
* table
)
2139 void setup_sysctl_set(struct ctl_table_set
*p
,
2140 struct ctl_table_set
*parent
,
2141 int (*is_seen
)(struct ctl_table_set
*))
2145 void sysctl_head_put(struct ctl_table_header
*head
)
2149 #endif /* CONFIG_SYSCTL */
2155 #ifdef CONFIG_PROC_SYSCTL
2157 static int _proc_do_string(void* data
, int maxlen
, int write
,
2158 struct file
*filp
, void __user
*buffer
,
2159 size_t *lenp
, loff_t
*ppos
)
2165 if (!data
|| !maxlen
|| !*lenp
) {
2173 while (len
< *lenp
) {
2174 if (get_user(c
, p
++))
2176 if (c
== 0 || c
== '\n')
2182 if(copy_from_user(data
, buffer
, len
))
2184 ((char *) data
)[len
] = 0;
2202 if(copy_to_user(buffer
, data
, len
))
2205 if(put_user('\n', ((char __user
*) buffer
) + len
))
2216 * proc_dostring - read a string sysctl
2217 * @table: the sysctl table
2218 * @write: %TRUE if this is a write to the sysctl file
2219 * @filp: the file structure
2220 * @buffer: the user buffer
2221 * @lenp: the size of the user buffer
2222 * @ppos: file position
2224 * Reads/writes a string from/to the user buffer. If the kernel
2225 * buffer provided is not large enough to hold the string, the
2226 * string is truncated. The copied string is %NULL-terminated.
2227 * If the string is being read by the user process, it is copied
2228 * and a newline '\n' is added. It is truncated if the buffer is
2231 * Returns 0 on success.
2233 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2234 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2236 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
2237 buffer
, lenp
, ppos
);
2241 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
2243 int write
, void *data
)
2246 *valp
= *negp
? -*lvalp
: *lvalp
;
2251 *lvalp
= (unsigned long)-val
;
2254 *lvalp
= (unsigned long)val
;
2260 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2261 int write
, struct file
*filp
, void __user
*buffer
,
2262 size_t *lenp
, loff_t
*ppos
,
2263 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2264 int write
, void *data
),
2267 #define TMPBUFLEN 21
2268 int *i
, vleft
, first
=1, neg
, val
;
2272 char buf
[TMPBUFLEN
], *p
;
2273 char __user
*s
= buffer
;
2275 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
2276 (*ppos
&& !write
)) {
2281 i
= (int *) tbl_data
;
2282 vleft
= table
->maxlen
/ sizeof(*i
);
2286 conv
= do_proc_dointvec_conv
;
2288 for (; left
&& vleft
--; i
++, first
=0) {
2303 if (len
> sizeof(buf
) - 1)
2304 len
= sizeof(buf
) - 1;
2305 if (copy_from_user(buf
, s
, len
))
2309 if (*p
== '-' && left
> 1) {
2313 if (*p
< '0' || *p
> '9')
2316 lval
= simple_strtoul(p
, &p
, 0);
2319 if ((len
< left
) && *p
&& !isspace(*p
))
2326 if (conv(&neg
, &lval
, i
, 1, data
))
2333 if (conv(&neg
, &lval
, i
, 0, data
))
2336 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2340 if(copy_to_user(s
, buf
, len
))
2347 if (!write
&& !first
&& left
) {
2348 if(put_user('\n', s
))
2355 if (get_user(c
, s
++))
2370 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2371 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2372 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2373 int write
, void *data
),
2376 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2377 buffer
, lenp
, ppos
, conv
, data
);
2381 * proc_dointvec - read a vector of integers
2382 * @table: the sysctl table
2383 * @write: %TRUE if this is a write to the sysctl file
2384 * @filp: the file structure
2385 * @buffer: the user buffer
2386 * @lenp: the size of the user buffer
2387 * @ppos: file position
2389 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2390 * values from/to the user buffer, treated as an ASCII string.
2392 * Returns 0 on success.
2394 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2395 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2397 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2402 * Taint values can only be increased
2403 * This means we can safely use a temporary.
2405 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2406 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2409 unsigned long tmptaint
= get_taint();
2412 if (write
&& !capable(CAP_SYS_ADMIN
))
2417 err
= proc_doulongvec_minmax(&t
, write
, filp
, buffer
, lenp
, ppos
);
2423 * Poor man's atomic or. Not worth adding a primitive
2424 * to everyone's atomic.h for this
2427 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2428 if ((tmptaint
>> i
) & 1)
2436 struct do_proc_dointvec_minmax_conv_param
{
2441 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2443 int write
, void *data
)
2445 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2447 int val
= *negp
? -*lvalp
: *lvalp
;
2448 if ((param
->min
&& *param
->min
> val
) ||
2449 (param
->max
&& *param
->max
< val
))
2456 *lvalp
= (unsigned long)-val
;
2459 *lvalp
= (unsigned long)val
;
2466 * proc_dointvec_minmax - read a vector of integers with min/max values
2467 * @table: the sysctl table
2468 * @write: %TRUE if this is a write to the sysctl file
2469 * @filp: the file structure
2470 * @buffer: the user buffer
2471 * @lenp: the size of the user buffer
2472 * @ppos: file position
2474 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2475 * values from/to the user buffer, treated as an ASCII string.
2477 * This routine will ensure the values are within the range specified by
2478 * table->extra1 (min) and table->extra2 (max).
2480 * Returns 0 on success.
2482 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2483 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2485 struct do_proc_dointvec_minmax_conv_param param
= {
2486 .min
= (int *) table
->extra1
,
2487 .max
= (int *) table
->extra2
,
2489 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2490 do_proc_dointvec_minmax_conv
, ¶m
);
2493 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2495 void __user
*buffer
,
2496 size_t *lenp
, loff_t
*ppos
,
2497 unsigned long convmul
,
2498 unsigned long convdiv
)
2500 #define TMPBUFLEN 21
2501 unsigned long *i
, *min
, *max
, val
;
2502 int vleft
, first
=1, neg
;
2504 char buf
[TMPBUFLEN
], *p
;
2505 char __user
*s
= buffer
;
2507 if (!data
|| !table
->maxlen
|| !*lenp
||
2508 (*ppos
&& !write
)) {
2513 i
= (unsigned long *) data
;
2514 min
= (unsigned long *) table
->extra1
;
2515 max
= (unsigned long *) table
->extra2
;
2516 vleft
= table
->maxlen
/ sizeof(unsigned long);
2519 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2534 if (len
> TMPBUFLEN
-1)
2536 if (copy_from_user(buf
, s
, len
))
2540 if (*p
== '-' && left
> 1) {
2544 if (*p
< '0' || *p
> '9')
2546 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2548 if ((len
< left
) && *p
&& !isspace(*p
))
2557 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2564 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2568 if(copy_to_user(s
, buf
, len
))
2575 if (!write
&& !first
&& left
) {
2576 if(put_user('\n', s
))
2583 if (get_user(c
, s
++))
2598 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2600 void __user
*buffer
,
2601 size_t *lenp
, loff_t
*ppos
,
2602 unsigned long convmul
,
2603 unsigned long convdiv
)
2605 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2606 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2610 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2611 * @table: the sysctl table
2612 * @write: %TRUE if this is a write to the sysctl file
2613 * @filp: the file structure
2614 * @buffer: the user buffer
2615 * @lenp: the size of the user buffer
2616 * @ppos: file position
2618 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2619 * values from/to the user buffer, treated as an ASCII string.
2621 * This routine will ensure the values are within the range specified by
2622 * table->extra1 (min) and table->extra2 (max).
2624 * Returns 0 on success.
2626 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2627 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2629 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2633 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2634 * @table: the sysctl table
2635 * @write: %TRUE if this is a write to the sysctl file
2636 * @filp: the file structure
2637 * @buffer: the user buffer
2638 * @lenp: the size of the user buffer
2639 * @ppos: file position
2641 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2642 * values from/to the user buffer, treated as an ASCII string. The values
2643 * are treated as milliseconds, and converted to jiffies when they are stored.
2645 * This routine will ensure the values are within the range specified by
2646 * table->extra1 (min) and table->extra2 (max).
2648 * Returns 0 on success.
2650 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2652 void __user
*buffer
,
2653 size_t *lenp
, loff_t
*ppos
)
2655 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2656 lenp
, ppos
, HZ
, 1000l);
2660 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2662 int write
, void *data
)
2665 if (*lvalp
> LONG_MAX
/ HZ
)
2667 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2673 lval
= (unsigned long)-val
;
2676 lval
= (unsigned long)val
;
2683 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2685 int write
, void *data
)
2688 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2690 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2696 lval
= (unsigned long)-val
;
2699 lval
= (unsigned long)val
;
2701 *lvalp
= jiffies_to_clock_t(lval
);
2706 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2708 int write
, void *data
)
2711 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2717 lval
= (unsigned long)-val
;
2720 lval
= (unsigned long)val
;
2722 *lvalp
= jiffies_to_msecs(lval
);
2728 * proc_dointvec_jiffies - read a vector of integers as seconds
2729 * @table: the sysctl table
2730 * @write: %TRUE if this is a write to the sysctl file
2731 * @filp: the file structure
2732 * @buffer: the user buffer
2733 * @lenp: the size of the user buffer
2734 * @ppos: file position
2736 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2737 * values from/to the user buffer, treated as an ASCII string.
2738 * The values read are assumed to be in seconds, and are converted into
2741 * Returns 0 on success.
2743 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2744 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2746 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2747 do_proc_dointvec_jiffies_conv
,NULL
);
2751 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2752 * @table: the sysctl table
2753 * @write: %TRUE if this is a write to the sysctl file
2754 * @filp: the file structure
2755 * @buffer: the user buffer
2756 * @lenp: the size of the user buffer
2757 * @ppos: pointer to the file position
2759 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2760 * values from/to the user buffer, treated as an ASCII string.
2761 * The values read are assumed to be in 1/USER_HZ seconds, and
2762 * are converted into jiffies.
2764 * Returns 0 on success.
2766 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2767 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2769 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2770 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2774 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2775 * @table: the sysctl table
2776 * @write: %TRUE if this is a write to the sysctl file
2777 * @filp: the file structure
2778 * @buffer: the user buffer
2779 * @lenp: the size of the user buffer
2780 * @ppos: file position
2781 * @ppos: the current position in the file
2783 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2784 * values from/to the user buffer, treated as an ASCII string.
2785 * The values read are assumed to be in 1/1000 seconds, and
2786 * are converted into jiffies.
2788 * Returns 0 on success.
2790 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2791 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2793 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2794 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2797 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2798 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2800 struct pid
*new_pid
;
2804 tmp
= pid_vnr(cad_pid
);
2806 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2807 lenp
, ppos
, NULL
, NULL
);
2811 new_pid
= find_get_pid(tmp
);
2815 put_pid(xchg(&cad_pid
, new_pid
));
2819 #else /* CONFIG_PROC_FS */
2821 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2822 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2827 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2828 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2833 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2834 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2839 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2840 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2845 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2846 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2851 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2852 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2857 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2858 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2863 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2865 void __user
*buffer
,
2866 size_t *lenp
, loff_t
*ppos
)
2872 #endif /* CONFIG_PROC_FS */
2875 #ifdef CONFIG_SYSCTL_SYSCALL
2877 * General sysctl support routines
2880 /* The generic sysctl data routine (used if no strategy routine supplied) */
2881 int sysctl_data(struct ctl_table
*table
,
2882 void __user
*oldval
, size_t __user
*oldlenp
,
2883 void __user
*newval
, size_t newlen
)
2887 /* Get out of I don't have a variable */
2888 if (!table
->data
|| !table
->maxlen
)
2891 if (oldval
&& oldlenp
) {
2892 if (get_user(len
, oldlenp
))
2895 if (len
> table
->maxlen
)
2896 len
= table
->maxlen
;
2897 if (copy_to_user(oldval
, table
->data
, len
))
2899 if (put_user(len
, oldlenp
))
2904 if (newval
&& newlen
) {
2905 if (newlen
> table
->maxlen
)
2906 newlen
= table
->maxlen
;
2908 if (copy_from_user(table
->data
, newval
, newlen
))
2914 /* The generic string strategy routine: */
2915 int sysctl_string(struct ctl_table
*table
,
2916 void __user
*oldval
, size_t __user
*oldlenp
,
2917 void __user
*newval
, size_t newlen
)
2919 if (!table
->data
|| !table
->maxlen
)
2922 if (oldval
&& oldlenp
) {
2924 if (get_user(bufsize
, oldlenp
))
2927 size_t len
= strlen(table
->data
), copied
;
2929 /* This shouldn't trigger for a well-formed sysctl */
2930 if (len
> table
->maxlen
)
2931 len
= table
->maxlen
;
2933 /* Copy up to a max of bufsize-1 bytes of the string */
2934 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2936 if (copy_to_user(oldval
, table
->data
, copied
) ||
2937 put_user(0, (char __user
*)(oldval
+ copied
)))
2939 if (put_user(len
, oldlenp
))
2943 if (newval
&& newlen
) {
2944 size_t len
= newlen
;
2945 if (len
> table
->maxlen
)
2946 len
= table
->maxlen
;
2947 if(copy_from_user(table
->data
, newval
, len
))
2949 if (len
== table
->maxlen
)
2951 ((char *) table
->data
)[len
] = 0;
2957 * This function makes sure that all of the integers in the vector
2958 * are between the minimum and maximum values given in the arrays
2959 * table->extra1 and table->extra2, respectively.
2961 int sysctl_intvec(struct ctl_table
*table
,
2962 void __user
*oldval
, size_t __user
*oldlenp
,
2963 void __user
*newval
, size_t newlen
)
2966 if (newval
&& newlen
) {
2967 int __user
*vec
= (int __user
*) newval
;
2968 int *min
= (int *) table
->extra1
;
2969 int *max
= (int *) table
->extra2
;
2973 if (newlen
% sizeof(int) != 0)
2976 if (!table
->extra1
&& !table
->extra2
)
2979 if (newlen
> table
->maxlen
)
2980 newlen
= table
->maxlen
;
2981 length
= newlen
/ sizeof(int);
2983 for (i
= 0; i
< length
; i
++) {
2985 if (get_user(value
, vec
+ i
))
2987 if (min
&& value
< min
[i
])
2989 if (max
&& value
> max
[i
])
2996 /* Strategy function to convert jiffies to seconds */
2997 int sysctl_jiffies(struct ctl_table
*table
,
2998 void __user
*oldval
, size_t __user
*oldlenp
,
2999 void __user
*newval
, size_t newlen
)
3001 if (oldval
&& oldlenp
) {
3004 if (get_user(olen
, oldlenp
))
3009 if (olen
< sizeof(int))
3012 val
= *(int *)(table
->data
) / HZ
;
3013 if (put_user(val
, (int __user
*)oldval
))
3015 if (put_user(sizeof(int), oldlenp
))
3019 if (newval
&& newlen
) {
3021 if (newlen
!= sizeof(int))
3023 if (get_user(new, (int __user
*)newval
))
3025 *(int *)(table
->data
) = new*HZ
;
3030 /* Strategy function to convert jiffies to seconds */
3031 int sysctl_ms_jiffies(struct ctl_table
*table
,
3032 void __user
*oldval
, size_t __user
*oldlenp
,
3033 void __user
*newval
, size_t newlen
)
3035 if (oldval
&& oldlenp
) {
3038 if (get_user(olen
, oldlenp
))
3043 if (olen
< sizeof(int))
3046 val
= jiffies_to_msecs(*(int *)(table
->data
));
3047 if (put_user(val
, (int __user
*)oldval
))
3049 if (put_user(sizeof(int), oldlenp
))
3053 if (newval
&& newlen
) {
3055 if (newlen
!= sizeof(int))
3057 if (get_user(new, (int __user
*)newval
))
3059 *(int *)(table
->data
) = msecs_to_jiffies(new);
3066 #else /* CONFIG_SYSCTL_SYSCALL */
3069 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
3071 struct __sysctl_args tmp
;
3074 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
3077 error
= deprecated_sysctl_warning(&tmp
);
3079 /* If no error reading the parameters then just -ENOSYS ... */
3086 int sysctl_data(struct ctl_table
*table
,
3087 void __user
*oldval
, size_t __user
*oldlenp
,
3088 void __user
*newval
, size_t newlen
)
3093 int sysctl_string(struct ctl_table
*table
,
3094 void __user
*oldval
, size_t __user
*oldlenp
,
3095 void __user
*newval
, size_t newlen
)
3100 int sysctl_intvec(struct ctl_table
*table
,
3101 void __user
*oldval
, size_t __user
*oldlenp
,
3102 void __user
*newval
, size_t newlen
)
3107 int sysctl_jiffies(struct ctl_table
*table
,
3108 void __user
*oldval
, size_t __user
*oldlenp
,
3109 void __user
*newval
, size_t newlen
)
3114 int sysctl_ms_jiffies(struct ctl_table
*table
,
3115 void __user
*oldval
, size_t __user
*oldlenp
,
3116 void __user
*newval
, size_t newlen
)
3121 #endif /* CONFIG_SYSCTL_SYSCALL */
3123 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
3125 static int msg_count
;
3126 int name
[CTL_MAXNAME
];
3129 /* Check args->nlen. */
3130 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
3133 /* Read in the sysctl name for better debug message logging */
3134 for (i
= 0; i
< args
->nlen
; i
++)
3135 if (get_user(name
[i
], args
->name
+ i
))
3138 /* Ignore accesses to kernel.version */
3139 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
3142 if (msg_count
< 5) {
3145 "warning: process `%s' used the deprecated sysctl "
3146 "system call with ", current
->comm
);
3147 for (i
= 0; i
< args
->nlen
; i
++)
3148 printk("%d.", name
[i
]);
3155 * No sense putting this after each symbol definition, twice,
3156 * exception granted :-)
3158 EXPORT_SYMBOL(proc_dointvec
);
3159 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3160 EXPORT_SYMBOL(proc_dointvec_minmax
);
3161 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3162 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3163 EXPORT_SYMBOL(proc_dostring
);
3164 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3165 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
3166 EXPORT_SYMBOL(register_sysctl_table
);
3167 EXPORT_SYMBOL(register_sysctl_paths
);
3168 EXPORT_SYMBOL(sysctl_intvec
);
3169 EXPORT_SYMBOL(sysctl_jiffies
);
3170 EXPORT_SYMBOL(sysctl_ms_jiffies
);
3171 EXPORT_SYMBOL(sysctl_string
);
3172 EXPORT_SYMBOL(sysctl_data
);
3173 EXPORT_SYMBOL(unregister_sysctl_table
);