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>
52 #include <asm/uaccess.h>
53 #include <asm/processor.h>
57 #include <asm/stacktrace.h>
61 static int deprecated_sysctl_warning(struct __sysctl_args
*args
);
63 #if defined(CONFIG_SYSCTL)
65 /* External variables not in a header file. */
67 extern int print_fatal_signals
;
68 extern int sysctl_overcommit_memory
;
69 extern int sysctl_overcommit_ratio
;
70 extern int sysctl_panic_on_oom
;
71 extern int sysctl_oom_kill_allocating_task
;
72 extern int sysctl_oom_dump_tasks
;
73 extern int max_threads
;
74 extern int core_uses_pid
;
75 extern int suid_dumpable
;
76 extern char core_pattern
[];
78 extern int min_free_kbytes
;
79 extern int pid_max_min
, pid_max_max
;
80 extern int sysctl_drop_caches
;
81 extern int percpu_pagelist_fraction
;
82 extern int compat_log
;
83 extern int maps_protect
;
84 extern int latencytop_enabled
;
85 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
86 #ifdef CONFIG_RCU_TORTURE_TEST
87 extern int rcutorture_runnable
;
88 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
90 /* Constants used for minimum and maximum */
91 #if defined(CONFIG_HIGHMEM) || defined(CONFIG_DETECT_SOFTLOCKUP)
95 #ifdef CONFIG_DETECT_SOFTLOCKUP
96 static int sixty
= 60;
97 static int neg_one
= -1;
105 static int one_hundred
= 100;
107 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
108 static int maxolduid
= 65535;
109 static int minolduid
;
110 static int min_percpu_pagelist_fract
= 8;
112 static int ngroups_max
= NGROUPS_MAX
;
114 #ifdef CONFIG_MODULES
115 extern char modprobe_path
[];
117 #ifdef CONFIG_CHR_DEV_SG
118 extern int sg_big_buff
;
122 extern char reboot_command
[];
123 extern int stop_a_enabled
;
124 extern int scons_pwroff
;
128 extern int pwrsw_enabled
;
129 extern int unaligned_enabled
;
133 #ifdef CONFIG_MATHEMU
134 extern int sysctl_ieee_emulation_warnings
;
136 extern int sysctl_userprocess_debug
;
137 extern int spin_retry
;
140 #ifdef CONFIG_BSD_PROCESS_ACCT
141 extern int acct_parm
[];
145 extern int no_unaligned_warning
;
148 #ifdef CONFIG_RT_MUTEXES
149 extern int max_lock_depth
;
152 #ifdef CONFIG_PROC_SYSCTL
153 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
154 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
155 static int proc_dointvec_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
156 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
159 static struct ctl_table root_table
[];
160 static struct ctl_table_root sysctl_table_root
;
161 static struct ctl_table_header root_table_header
= {
163 .ctl_table
= root_table
,
164 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),
165 .root
= &sysctl_table_root
,
166 .set
= &sysctl_table_root
.default_set
,
168 static struct ctl_table_root sysctl_table_root
= {
169 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
170 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
173 static struct ctl_table kern_table
[];
174 static struct ctl_table vm_table
[];
175 static struct ctl_table fs_table
[];
176 static struct ctl_table debug_table
[];
177 static struct ctl_table dev_table
[];
178 extern struct ctl_table random_table
[];
179 #ifdef CONFIG_INOTIFY_USER
180 extern struct ctl_table inotify_table
[];
183 extern struct ctl_table epoll_table
[];
186 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
187 int sysctl_legacy_va_layout
;
190 extern int prove_locking
;
191 extern int lock_stat
;
193 /* The default sysctl tables: */
195 static struct ctl_table root_table
[] = {
197 .ctl_name
= CTL_KERN
,
198 .procname
= "kernel",
215 .ctl_name
= CTL_DEBUG
,
218 .child
= debug_table
,
227 * NOTE: do not add new entries to this table unless you have read
228 * Documentation/sysctl/ctl_unnumbered.txt
233 #ifdef CONFIG_SCHED_DEBUG
234 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
235 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
236 static int min_wakeup_granularity_ns
; /* 0 usecs */
237 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
240 static struct ctl_table kern_table
[] = {
241 #ifdef CONFIG_SCHED_DEBUG
243 .ctl_name
= CTL_UNNUMBERED
,
244 .procname
= "sched_min_granularity_ns",
245 .data
= &sysctl_sched_min_granularity
,
246 .maxlen
= sizeof(unsigned int),
248 .proc_handler
= &sched_nr_latency_handler
,
249 .strategy
= &sysctl_intvec
,
250 .extra1
= &min_sched_granularity_ns
,
251 .extra2
= &max_sched_granularity_ns
,
254 .ctl_name
= CTL_UNNUMBERED
,
255 .procname
= "sched_latency_ns",
256 .data
= &sysctl_sched_latency
,
257 .maxlen
= sizeof(unsigned int),
259 .proc_handler
= &sched_nr_latency_handler
,
260 .strategy
= &sysctl_intvec
,
261 .extra1
= &min_sched_granularity_ns
,
262 .extra2
= &max_sched_granularity_ns
,
265 .ctl_name
= CTL_UNNUMBERED
,
266 .procname
= "sched_wakeup_granularity_ns",
267 .data
= &sysctl_sched_wakeup_granularity
,
268 .maxlen
= sizeof(unsigned int),
270 .proc_handler
= &proc_dointvec_minmax
,
271 .strategy
= &sysctl_intvec
,
272 .extra1
= &min_wakeup_granularity_ns
,
273 .extra2
= &max_wakeup_granularity_ns
,
276 .ctl_name
= CTL_UNNUMBERED
,
277 .procname
= "sched_shares_ratelimit",
278 .data
= &sysctl_sched_shares_ratelimit
,
279 .maxlen
= sizeof(unsigned int),
281 .proc_handler
= &proc_dointvec
,
284 .ctl_name
= CTL_UNNUMBERED
,
285 .procname
= "sched_child_runs_first",
286 .data
= &sysctl_sched_child_runs_first
,
287 .maxlen
= sizeof(unsigned int),
289 .proc_handler
= &proc_dointvec
,
292 .ctl_name
= CTL_UNNUMBERED
,
293 .procname
= "sched_features",
294 .data
= &sysctl_sched_features
,
295 .maxlen
= sizeof(unsigned int),
297 .proc_handler
= &proc_dointvec
,
300 .ctl_name
= CTL_UNNUMBERED
,
301 .procname
= "sched_migration_cost",
302 .data
= &sysctl_sched_migration_cost
,
303 .maxlen
= sizeof(unsigned int),
305 .proc_handler
= &proc_dointvec
,
308 .ctl_name
= CTL_UNNUMBERED
,
309 .procname
= "sched_nr_migrate",
310 .data
= &sysctl_sched_nr_migrate
,
311 .maxlen
= sizeof(unsigned int),
313 .proc_handler
= &proc_dointvec
,
317 .ctl_name
= CTL_UNNUMBERED
,
318 .procname
= "sched_rt_period_us",
319 .data
= &sysctl_sched_rt_period
,
320 .maxlen
= sizeof(unsigned int),
322 .proc_handler
= &sched_rt_handler
,
325 .ctl_name
= CTL_UNNUMBERED
,
326 .procname
= "sched_rt_runtime_us",
327 .data
= &sysctl_sched_rt_runtime
,
328 .maxlen
= sizeof(int),
330 .proc_handler
= &sched_rt_handler
,
333 .ctl_name
= CTL_UNNUMBERED
,
334 .procname
= "sched_compat_yield",
335 .data
= &sysctl_sched_compat_yield
,
336 .maxlen
= sizeof(unsigned int),
338 .proc_handler
= &proc_dointvec
,
340 #ifdef CONFIG_PROVE_LOCKING
342 .ctl_name
= CTL_UNNUMBERED
,
343 .procname
= "prove_locking",
344 .data
= &prove_locking
,
345 .maxlen
= sizeof(int),
347 .proc_handler
= &proc_dointvec
,
350 #ifdef CONFIG_LOCK_STAT
352 .ctl_name
= CTL_UNNUMBERED
,
353 .procname
= "lock_stat",
355 .maxlen
= sizeof(int),
357 .proc_handler
= &proc_dointvec
,
361 .ctl_name
= KERN_PANIC
,
363 .data
= &panic_timeout
,
364 .maxlen
= sizeof(int),
366 .proc_handler
= &proc_dointvec
,
369 .ctl_name
= KERN_CORE_USES_PID
,
370 .procname
= "core_uses_pid",
371 .data
= &core_uses_pid
,
372 .maxlen
= sizeof(int),
374 .proc_handler
= &proc_dointvec
,
377 .ctl_name
= KERN_CORE_PATTERN
,
378 .procname
= "core_pattern",
379 .data
= core_pattern
,
380 .maxlen
= CORENAME_MAX_SIZE
,
382 .proc_handler
= &proc_dostring
,
383 .strategy
= &sysctl_string
,
385 #ifdef CONFIG_PROC_SYSCTL
387 .procname
= "tainted",
389 .maxlen
= sizeof(int),
391 .proc_handler
= &proc_dointvec_taint
,
394 #ifdef CONFIG_LATENCYTOP
396 .procname
= "latencytop",
397 .data
= &latencytop_enabled
,
398 .maxlen
= sizeof(int),
400 .proc_handler
= &proc_dointvec
,
403 #ifdef CONFIG_BLK_DEV_INITRD
405 .ctl_name
= KERN_REALROOTDEV
,
406 .procname
= "real-root-dev",
407 .data
= &real_root_dev
,
408 .maxlen
= sizeof(int),
410 .proc_handler
= &proc_dointvec
,
414 .ctl_name
= CTL_UNNUMBERED
,
415 .procname
= "print-fatal-signals",
416 .data
= &print_fatal_signals
,
417 .maxlen
= sizeof(int),
419 .proc_handler
= &proc_dointvec
,
423 .ctl_name
= KERN_SPARC_REBOOT
,
424 .procname
= "reboot-cmd",
425 .data
= reboot_command
,
428 .proc_handler
= &proc_dostring
,
429 .strategy
= &sysctl_string
,
432 .ctl_name
= KERN_SPARC_STOP_A
,
433 .procname
= "stop-a",
434 .data
= &stop_a_enabled
,
435 .maxlen
= sizeof (int),
437 .proc_handler
= &proc_dointvec
,
440 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
441 .procname
= "scons-poweroff",
442 .data
= &scons_pwroff
,
443 .maxlen
= sizeof (int),
445 .proc_handler
= &proc_dointvec
,
450 .ctl_name
= KERN_HPPA_PWRSW
,
451 .procname
= "soft-power",
452 .data
= &pwrsw_enabled
,
453 .maxlen
= sizeof (int),
455 .proc_handler
= &proc_dointvec
,
458 .ctl_name
= KERN_HPPA_UNALIGNED
,
459 .procname
= "unaligned-trap",
460 .data
= &unaligned_enabled
,
461 .maxlen
= sizeof (int),
463 .proc_handler
= &proc_dointvec
,
467 .ctl_name
= KERN_CTLALTDEL
,
468 .procname
= "ctrl-alt-del",
470 .maxlen
= sizeof(int),
472 .proc_handler
= &proc_dointvec
,
476 .ctl_name
= CTL_UNNUMBERED
,
477 .procname
= "ftrace_enabled",
478 .data
= &ftrace_enabled
,
479 .maxlen
= sizeof(int),
481 .proc_handler
= &ftrace_enable_sysctl
,
484 #ifdef CONFIG_MODULES
486 .ctl_name
= KERN_MODPROBE
,
487 .procname
= "modprobe",
488 .data
= &modprobe_path
,
489 .maxlen
= KMOD_PATH_LEN
,
491 .proc_handler
= &proc_dostring
,
492 .strategy
= &sysctl_string
,
495 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
497 .ctl_name
= KERN_HOTPLUG
,
498 .procname
= "hotplug",
499 .data
= &uevent_helper
,
500 .maxlen
= UEVENT_HELPER_PATH_LEN
,
502 .proc_handler
= &proc_dostring
,
503 .strategy
= &sysctl_string
,
506 #ifdef CONFIG_CHR_DEV_SG
508 .ctl_name
= KERN_SG_BIG_BUFF
,
509 .procname
= "sg-big-buff",
510 .data
= &sg_big_buff
,
511 .maxlen
= sizeof (int),
513 .proc_handler
= &proc_dointvec
,
516 #ifdef CONFIG_BSD_PROCESS_ACCT
518 .ctl_name
= KERN_ACCT
,
521 .maxlen
= 3*sizeof(int),
523 .proc_handler
= &proc_dointvec
,
526 #ifdef CONFIG_MAGIC_SYSRQ
528 .ctl_name
= KERN_SYSRQ
,
530 .data
= &__sysrq_enabled
,
531 .maxlen
= sizeof (int),
533 .proc_handler
= &proc_dointvec
,
536 #ifdef CONFIG_PROC_SYSCTL
538 .procname
= "cad_pid",
540 .maxlen
= sizeof (int),
542 .proc_handler
= &proc_do_cad_pid
,
546 .ctl_name
= KERN_MAX_THREADS
,
547 .procname
= "threads-max",
548 .data
= &max_threads
,
549 .maxlen
= sizeof(int),
551 .proc_handler
= &proc_dointvec
,
554 .ctl_name
= KERN_RANDOM
,
555 .procname
= "random",
557 .child
= random_table
,
560 .ctl_name
= KERN_OVERFLOWUID
,
561 .procname
= "overflowuid",
562 .data
= &overflowuid
,
563 .maxlen
= sizeof(int),
565 .proc_handler
= &proc_dointvec_minmax
,
566 .strategy
= &sysctl_intvec
,
567 .extra1
= &minolduid
,
568 .extra2
= &maxolduid
,
571 .ctl_name
= KERN_OVERFLOWGID
,
572 .procname
= "overflowgid",
573 .data
= &overflowgid
,
574 .maxlen
= sizeof(int),
576 .proc_handler
= &proc_dointvec_minmax
,
577 .strategy
= &sysctl_intvec
,
578 .extra1
= &minolduid
,
579 .extra2
= &maxolduid
,
582 #ifdef CONFIG_MATHEMU
584 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
585 .procname
= "ieee_emulation_warnings",
586 .data
= &sysctl_ieee_emulation_warnings
,
587 .maxlen
= sizeof(int),
589 .proc_handler
= &proc_dointvec
,
593 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
594 .procname
= "userprocess_debug",
595 .data
= &sysctl_userprocess_debug
,
596 .maxlen
= sizeof(int),
598 .proc_handler
= &proc_dointvec
,
602 .ctl_name
= KERN_PIDMAX
,
603 .procname
= "pid_max",
605 .maxlen
= sizeof (int),
607 .proc_handler
= &proc_dointvec_minmax
,
608 .strategy
= sysctl_intvec
,
609 .extra1
= &pid_max_min
,
610 .extra2
= &pid_max_max
,
613 .ctl_name
= KERN_PANIC_ON_OOPS
,
614 .procname
= "panic_on_oops",
615 .data
= &panic_on_oops
,
616 .maxlen
= sizeof(int),
618 .proc_handler
= &proc_dointvec
,
620 #if defined CONFIG_PRINTK
622 .ctl_name
= KERN_PRINTK
,
623 .procname
= "printk",
624 .data
= &console_loglevel
,
625 .maxlen
= 4*sizeof(int),
627 .proc_handler
= &proc_dointvec
,
630 .ctl_name
= KERN_PRINTK_RATELIMIT
,
631 .procname
= "printk_ratelimit",
632 .data
= &printk_ratelimit_state
.interval
,
633 .maxlen
= sizeof(int),
635 .proc_handler
= &proc_dointvec_jiffies
,
636 .strategy
= &sysctl_jiffies
,
639 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
640 .procname
= "printk_ratelimit_burst",
641 .data
= &printk_ratelimit_state
.burst
,
642 .maxlen
= sizeof(int),
644 .proc_handler
= &proc_dointvec
,
648 .ctl_name
= KERN_NGROUPS_MAX
,
649 .procname
= "ngroups_max",
650 .data
= &ngroups_max
,
651 .maxlen
= sizeof (int),
653 .proc_handler
= &proc_dointvec
,
655 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
657 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
658 .procname
= "unknown_nmi_panic",
659 .data
= &unknown_nmi_panic
,
660 .maxlen
= sizeof (int),
662 .proc_handler
= &proc_dointvec
,
665 .procname
= "nmi_watchdog",
666 .data
= &nmi_watchdog_enabled
,
667 .maxlen
= sizeof (int),
669 .proc_handler
= &proc_nmi_enabled
,
672 #if defined(CONFIG_X86)
674 .ctl_name
= KERN_PANIC_ON_NMI
,
675 .procname
= "panic_on_unrecovered_nmi",
676 .data
= &panic_on_unrecovered_nmi
,
677 .maxlen
= sizeof(int),
679 .proc_handler
= &proc_dointvec
,
682 .ctl_name
= KERN_BOOTLOADER_TYPE
,
683 .procname
= "bootloader_type",
684 .data
= &bootloader_type
,
685 .maxlen
= sizeof (int),
687 .proc_handler
= &proc_dointvec
,
690 .ctl_name
= CTL_UNNUMBERED
,
691 .procname
= "kstack_depth_to_print",
692 .data
= &kstack_depth_to_print
,
693 .maxlen
= sizeof(int),
695 .proc_handler
= &proc_dointvec
,
698 .ctl_name
= CTL_UNNUMBERED
,
699 .procname
= "io_delay_type",
700 .data
= &io_delay_type
,
701 .maxlen
= sizeof(int),
703 .proc_handler
= &proc_dointvec
,
706 #if defined(CONFIG_MMU)
708 .ctl_name
= KERN_RANDOMIZE
,
709 .procname
= "randomize_va_space",
710 .data
= &randomize_va_space
,
711 .maxlen
= sizeof(int),
713 .proc_handler
= &proc_dointvec
,
716 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
718 .ctl_name
= KERN_SPIN_RETRY
,
719 .procname
= "spin_retry",
721 .maxlen
= sizeof (int),
723 .proc_handler
= &proc_dointvec
,
726 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
728 .procname
= "acpi_video_flags",
729 .data
= &acpi_realmode_flags
,
730 .maxlen
= sizeof (unsigned long),
732 .proc_handler
= &proc_doulongvec_minmax
,
737 .ctl_name
= KERN_IA64_UNALIGNED
,
738 .procname
= "ignore-unaligned-usertrap",
739 .data
= &no_unaligned_warning
,
740 .maxlen
= sizeof (int),
742 .proc_handler
= &proc_dointvec
,
745 #ifdef CONFIG_DETECT_SOFTLOCKUP
747 .ctl_name
= CTL_UNNUMBERED
,
748 .procname
= "softlockup_panic",
749 .data
= &softlockup_panic
,
750 .maxlen
= sizeof(int),
752 .proc_handler
= &proc_dointvec_minmax
,
753 .strategy
= &sysctl_intvec
,
758 .ctl_name
= CTL_UNNUMBERED
,
759 .procname
= "softlockup_thresh",
760 .data
= &softlockup_thresh
,
761 .maxlen
= sizeof(int),
763 .proc_handler
= &proc_dointvec_minmax
,
764 .strategy
= &sysctl_intvec
,
769 .ctl_name
= CTL_UNNUMBERED
,
770 .procname
= "hung_task_check_count",
771 .data
= &sysctl_hung_task_check_count
,
772 .maxlen
= sizeof(unsigned long),
774 .proc_handler
= &proc_doulongvec_minmax
,
775 .strategy
= &sysctl_intvec
,
778 .ctl_name
= CTL_UNNUMBERED
,
779 .procname
= "hung_task_timeout_secs",
780 .data
= &sysctl_hung_task_timeout_secs
,
781 .maxlen
= sizeof(unsigned long),
783 .proc_handler
= &proc_doulongvec_minmax
,
784 .strategy
= &sysctl_intvec
,
787 .ctl_name
= CTL_UNNUMBERED
,
788 .procname
= "hung_task_warnings",
789 .data
= &sysctl_hung_task_warnings
,
790 .maxlen
= sizeof(unsigned long),
792 .proc_handler
= &proc_doulongvec_minmax
,
793 .strategy
= &sysctl_intvec
,
798 .ctl_name
= KERN_COMPAT_LOG
,
799 .procname
= "compat-log",
801 .maxlen
= sizeof (int),
803 .proc_handler
= &proc_dointvec
,
806 #ifdef CONFIG_RT_MUTEXES
808 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
809 .procname
= "max_lock_depth",
810 .data
= &max_lock_depth
,
811 .maxlen
= sizeof(int),
813 .proc_handler
= &proc_dointvec
,
816 #ifdef CONFIG_PROC_FS
818 .ctl_name
= CTL_UNNUMBERED
,
819 .procname
= "maps_protect",
820 .data
= &maps_protect
,
821 .maxlen
= sizeof(int),
823 .proc_handler
= &proc_dointvec
,
827 .ctl_name
= CTL_UNNUMBERED
,
828 .procname
= "poweroff_cmd",
829 .data
= &poweroff_cmd
,
830 .maxlen
= POWEROFF_CMD_PATH_LEN
,
832 .proc_handler
= &proc_dostring
,
833 .strategy
= &sysctl_string
,
837 .ctl_name
= CTL_UNNUMBERED
,
840 .child
= key_sysctls
,
843 #ifdef CONFIG_RCU_TORTURE_TEST
845 .ctl_name
= CTL_UNNUMBERED
,
846 .procname
= "rcutorture_runnable",
847 .data
= &rcutorture_runnable
,
848 .maxlen
= sizeof(int),
850 .proc_handler
= &proc_dointvec
,
854 * NOTE: do not add new entries to this table unless you have read
855 * Documentation/sysctl/ctl_unnumbered.txt
860 static struct ctl_table vm_table
[] = {
862 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
863 .procname
= "overcommit_memory",
864 .data
= &sysctl_overcommit_memory
,
865 .maxlen
= sizeof(sysctl_overcommit_memory
),
867 .proc_handler
= &proc_dointvec
,
870 .ctl_name
= VM_PANIC_ON_OOM
,
871 .procname
= "panic_on_oom",
872 .data
= &sysctl_panic_on_oom
,
873 .maxlen
= sizeof(sysctl_panic_on_oom
),
875 .proc_handler
= &proc_dointvec
,
878 .ctl_name
= CTL_UNNUMBERED
,
879 .procname
= "oom_kill_allocating_task",
880 .data
= &sysctl_oom_kill_allocating_task
,
881 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
883 .proc_handler
= &proc_dointvec
,
886 .ctl_name
= CTL_UNNUMBERED
,
887 .procname
= "oom_dump_tasks",
888 .data
= &sysctl_oom_dump_tasks
,
889 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
891 .proc_handler
= &proc_dointvec
,
894 .ctl_name
= VM_OVERCOMMIT_RATIO
,
895 .procname
= "overcommit_ratio",
896 .data
= &sysctl_overcommit_ratio
,
897 .maxlen
= sizeof(sysctl_overcommit_ratio
),
899 .proc_handler
= &proc_dointvec
,
902 .ctl_name
= VM_PAGE_CLUSTER
,
903 .procname
= "page-cluster",
904 .data
= &page_cluster
,
905 .maxlen
= sizeof(int),
907 .proc_handler
= &proc_dointvec
,
910 .ctl_name
= VM_DIRTY_BACKGROUND
,
911 .procname
= "dirty_background_ratio",
912 .data
= &dirty_background_ratio
,
913 .maxlen
= sizeof(dirty_background_ratio
),
915 .proc_handler
= &proc_dointvec_minmax
,
916 .strategy
= &sysctl_intvec
,
918 .extra2
= &one_hundred
,
921 .ctl_name
= VM_DIRTY_RATIO
,
922 .procname
= "dirty_ratio",
923 .data
= &vm_dirty_ratio
,
924 .maxlen
= sizeof(vm_dirty_ratio
),
926 .proc_handler
= &dirty_ratio_handler
,
927 .strategy
= &sysctl_intvec
,
929 .extra2
= &one_hundred
,
932 .procname
= "dirty_writeback_centisecs",
933 .data
= &dirty_writeback_interval
,
934 .maxlen
= sizeof(dirty_writeback_interval
),
936 .proc_handler
= &dirty_writeback_centisecs_handler
,
939 .procname
= "dirty_expire_centisecs",
940 .data
= &dirty_expire_interval
,
941 .maxlen
= sizeof(dirty_expire_interval
),
943 .proc_handler
= &proc_dointvec_userhz_jiffies
,
946 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
947 .procname
= "nr_pdflush_threads",
948 .data
= &nr_pdflush_threads
,
949 .maxlen
= sizeof nr_pdflush_threads
,
950 .mode
= 0444 /* read-only*/,
951 .proc_handler
= &proc_dointvec
,
954 .ctl_name
= VM_SWAPPINESS
,
955 .procname
= "swappiness",
956 .data
= &vm_swappiness
,
957 .maxlen
= sizeof(vm_swappiness
),
959 .proc_handler
= &proc_dointvec_minmax
,
960 .strategy
= &sysctl_intvec
,
962 .extra2
= &one_hundred
,
964 #ifdef CONFIG_HUGETLB_PAGE
966 .procname
= "nr_hugepages",
968 .maxlen
= sizeof(unsigned long),
970 .proc_handler
= &hugetlb_sysctl_handler
,
971 .extra1
= (void *)&hugetlb_zero
,
972 .extra2
= (void *)&hugetlb_infinity
,
975 .ctl_name
= VM_HUGETLB_GROUP
,
976 .procname
= "hugetlb_shm_group",
977 .data
= &sysctl_hugetlb_shm_group
,
978 .maxlen
= sizeof(gid_t
),
980 .proc_handler
= &proc_dointvec
,
983 .ctl_name
= CTL_UNNUMBERED
,
984 .procname
= "hugepages_treat_as_movable",
985 .data
= &hugepages_treat_as_movable
,
986 .maxlen
= sizeof(int),
988 .proc_handler
= &hugetlb_treat_movable_handler
,
991 .ctl_name
= CTL_UNNUMBERED
,
992 .procname
= "nr_overcommit_hugepages",
994 .maxlen
= sizeof(unsigned long),
996 .proc_handler
= &hugetlb_overcommit_handler
,
997 .extra1
= (void *)&hugetlb_zero
,
998 .extra2
= (void *)&hugetlb_infinity
,
1002 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
1003 .procname
= "lowmem_reserve_ratio",
1004 .data
= &sysctl_lowmem_reserve_ratio
,
1005 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1007 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
1008 .strategy
= &sysctl_intvec
,
1011 .ctl_name
= VM_DROP_PAGECACHE
,
1012 .procname
= "drop_caches",
1013 .data
= &sysctl_drop_caches
,
1014 .maxlen
= sizeof(int),
1016 .proc_handler
= drop_caches_sysctl_handler
,
1017 .strategy
= &sysctl_intvec
,
1020 .ctl_name
= VM_MIN_FREE_KBYTES
,
1021 .procname
= "min_free_kbytes",
1022 .data
= &min_free_kbytes
,
1023 .maxlen
= sizeof(min_free_kbytes
),
1025 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1026 .strategy
= &sysctl_intvec
,
1030 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1031 .procname
= "percpu_pagelist_fraction",
1032 .data
= &percpu_pagelist_fraction
,
1033 .maxlen
= sizeof(percpu_pagelist_fraction
),
1035 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1036 .strategy
= &sysctl_intvec
,
1037 .extra1
= &min_percpu_pagelist_fract
,
1041 .ctl_name
= VM_MAX_MAP_COUNT
,
1042 .procname
= "max_map_count",
1043 .data
= &sysctl_max_map_count
,
1044 .maxlen
= sizeof(sysctl_max_map_count
),
1046 .proc_handler
= &proc_dointvec
1050 .ctl_name
= VM_LAPTOP_MODE
,
1051 .procname
= "laptop_mode",
1052 .data
= &laptop_mode
,
1053 .maxlen
= sizeof(laptop_mode
),
1055 .proc_handler
= &proc_dointvec_jiffies
,
1056 .strategy
= &sysctl_jiffies
,
1059 .ctl_name
= VM_BLOCK_DUMP
,
1060 .procname
= "block_dump",
1061 .data
= &block_dump
,
1062 .maxlen
= sizeof(block_dump
),
1064 .proc_handler
= &proc_dointvec
,
1065 .strategy
= &sysctl_intvec
,
1069 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1070 .procname
= "vfs_cache_pressure",
1071 .data
= &sysctl_vfs_cache_pressure
,
1072 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1074 .proc_handler
= &proc_dointvec
,
1075 .strategy
= &sysctl_intvec
,
1078 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1080 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1081 .procname
= "legacy_va_layout",
1082 .data
= &sysctl_legacy_va_layout
,
1083 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1085 .proc_handler
= &proc_dointvec
,
1086 .strategy
= &sysctl_intvec
,
1092 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1093 .procname
= "zone_reclaim_mode",
1094 .data
= &zone_reclaim_mode
,
1095 .maxlen
= sizeof(zone_reclaim_mode
),
1097 .proc_handler
= &proc_dointvec
,
1098 .strategy
= &sysctl_intvec
,
1102 .ctl_name
= VM_MIN_UNMAPPED
,
1103 .procname
= "min_unmapped_ratio",
1104 .data
= &sysctl_min_unmapped_ratio
,
1105 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1107 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1108 .strategy
= &sysctl_intvec
,
1110 .extra2
= &one_hundred
,
1113 .ctl_name
= VM_MIN_SLAB
,
1114 .procname
= "min_slab_ratio",
1115 .data
= &sysctl_min_slab_ratio
,
1116 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1118 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1119 .strategy
= &sysctl_intvec
,
1121 .extra2
= &one_hundred
,
1126 .ctl_name
= CTL_UNNUMBERED
,
1127 .procname
= "stat_interval",
1128 .data
= &sysctl_stat_interval
,
1129 .maxlen
= sizeof(sysctl_stat_interval
),
1131 .proc_handler
= &proc_dointvec_jiffies
,
1132 .strategy
= &sysctl_jiffies
,
1135 #ifdef CONFIG_SECURITY
1137 .ctl_name
= CTL_UNNUMBERED
,
1138 .procname
= "mmap_min_addr",
1139 .data
= &mmap_min_addr
,
1140 .maxlen
= sizeof(unsigned long),
1142 .proc_handler
= &proc_doulongvec_minmax
,
1147 .ctl_name
= CTL_UNNUMBERED
,
1148 .procname
= "numa_zonelist_order",
1149 .data
= &numa_zonelist_order
,
1150 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1152 .proc_handler
= &numa_zonelist_order_handler
,
1153 .strategy
= &sysctl_string
,
1156 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1157 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1159 .ctl_name
= VM_VDSO_ENABLED
,
1160 .procname
= "vdso_enabled",
1161 .data
= &vdso_enabled
,
1162 .maxlen
= sizeof(vdso_enabled
),
1164 .proc_handler
= &proc_dointvec
,
1165 .strategy
= &sysctl_intvec
,
1169 #ifdef CONFIG_HIGHMEM
1171 .ctl_name
= CTL_UNNUMBERED
,
1172 .procname
= "highmem_is_dirtyable",
1173 .data
= &vm_highmem_is_dirtyable
,
1174 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1176 .proc_handler
= &proc_dointvec_minmax
,
1177 .strategy
= &sysctl_intvec
,
1183 * NOTE: do not add new entries to this table unless you have read
1184 * Documentation/sysctl/ctl_unnumbered.txt
1189 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1190 static struct ctl_table binfmt_misc_table
[] = {
1195 static struct ctl_table fs_table
[] = {
1197 .ctl_name
= FS_NRINODE
,
1198 .procname
= "inode-nr",
1199 .data
= &inodes_stat
,
1200 .maxlen
= 2*sizeof(int),
1202 .proc_handler
= &proc_dointvec
,
1205 .ctl_name
= FS_STATINODE
,
1206 .procname
= "inode-state",
1207 .data
= &inodes_stat
,
1208 .maxlen
= 7*sizeof(int),
1210 .proc_handler
= &proc_dointvec
,
1213 .procname
= "file-nr",
1214 .data
= &files_stat
,
1215 .maxlen
= 3*sizeof(int),
1217 .proc_handler
= &proc_nr_files
,
1220 .ctl_name
= FS_MAXFILE
,
1221 .procname
= "file-max",
1222 .data
= &files_stat
.max_files
,
1223 .maxlen
= sizeof(int),
1225 .proc_handler
= &proc_dointvec
,
1228 .ctl_name
= CTL_UNNUMBERED
,
1229 .procname
= "nr_open",
1230 .data
= &sysctl_nr_open
,
1231 .maxlen
= sizeof(int),
1233 .proc_handler
= &proc_dointvec_minmax
,
1234 .extra1
= &sysctl_nr_open_min
,
1235 .extra2
= &sysctl_nr_open_max
,
1238 .ctl_name
= FS_DENTRY
,
1239 .procname
= "dentry-state",
1240 .data
= &dentry_stat
,
1241 .maxlen
= 6*sizeof(int),
1243 .proc_handler
= &proc_dointvec
,
1246 .ctl_name
= FS_OVERFLOWUID
,
1247 .procname
= "overflowuid",
1248 .data
= &fs_overflowuid
,
1249 .maxlen
= sizeof(int),
1251 .proc_handler
= &proc_dointvec_minmax
,
1252 .strategy
= &sysctl_intvec
,
1253 .extra1
= &minolduid
,
1254 .extra2
= &maxolduid
,
1257 .ctl_name
= FS_OVERFLOWGID
,
1258 .procname
= "overflowgid",
1259 .data
= &fs_overflowgid
,
1260 .maxlen
= sizeof(int),
1262 .proc_handler
= &proc_dointvec_minmax
,
1263 .strategy
= &sysctl_intvec
,
1264 .extra1
= &minolduid
,
1265 .extra2
= &maxolduid
,
1268 .ctl_name
= FS_LEASES
,
1269 .procname
= "leases-enable",
1270 .data
= &leases_enable
,
1271 .maxlen
= sizeof(int),
1273 .proc_handler
= &proc_dointvec
,
1275 #ifdef CONFIG_DNOTIFY
1277 .ctl_name
= FS_DIR_NOTIFY
,
1278 .procname
= "dir-notify-enable",
1279 .data
= &dir_notify_enable
,
1280 .maxlen
= sizeof(int),
1282 .proc_handler
= &proc_dointvec
,
1287 .ctl_name
= FS_LEASE_TIME
,
1288 .procname
= "lease-break-time",
1289 .data
= &lease_break_time
,
1290 .maxlen
= sizeof(int),
1292 .proc_handler
= &proc_dointvec_minmax
,
1293 .strategy
= &sysctl_intvec
,
1298 .procname
= "aio-nr",
1300 .maxlen
= sizeof(aio_nr
),
1302 .proc_handler
= &proc_doulongvec_minmax
,
1305 .procname
= "aio-max-nr",
1306 .data
= &aio_max_nr
,
1307 .maxlen
= sizeof(aio_max_nr
),
1309 .proc_handler
= &proc_doulongvec_minmax
,
1311 #ifdef CONFIG_INOTIFY_USER
1313 .ctl_name
= FS_INOTIFY
,
1314 .procname
= "inotify",
1316 .child
= inotify_table
,
1321 .procname
= "epoll",
1323 .child
= epoll_table
,
1328 .ctl_name
= KERN_SETUID_DUMPABLE
,
1329 .procname
= "suid_dumpable",
1330 .data
= &suid_dumpable
,
1331 .maxlen
= sizeof(int),
1333 .proc_handler
= &proc_dointvec
,
1335 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1337 .ctl_name
= CTL_UNNUMBERED
,
1338 .procname
= "binfmt_misc",
1340 .child
= binfmt_misc_table
,
1344 * NOTE: do not add new entries to this table unless you have read
1345 * Documentation/sysctl/ctl_unnumbered.txt
1350 static struct ctl_table debug_table
[] = {
1351 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1353 .ctl_name
= CTL_UNNUMBERED
,
1354 .procname
= "exception-trace",
1355 .data
= &show_unhandled_signals
,
1356 .maxlen
= sizeof(int),
1358 .proc_handler
= proc_dointvec
1364 static struct ctl_table dev_table
[] = {
1368 static DEFINE_SPINLOCK(sysctl_lock
);
1370 /* called under sysctl_lock */
1371 static int use_table(struct ctl_table_header
*p
)
1373 if (unlikely(p
->unregistering
))
1379 /* called under sysctl_lock */
1380 static void unuse_table(struct ctl_table_header
*p
)
1383 if (unlikely(p
->unregistering
))
1384 complete(p
->unregistering
);
1387 /* called under sysctl_lock, will reacquire if has to wait */
1388 static void start_unregistering(struct ctl_table_header
*p
)
1391 * if p->used is 0, nobody will ever touch that entry again;
1392 * we'll eliminate all paths to it before dropping sysctl_lock
1394 if (unlikely(p
->used
)) {
1395 struct completion wait
;
1396 init_completion(&wait
);
1397 p
->unregistering
= &wait
;
1398 spin_unlock(&sysctl_lock
);
1399 wait_for_completion(&wait
);
1400 spin_lock(&sysctl_lock
);
1402 /* anything non-NULL; we'll never dereference it */
1403 p
->unregistering
= ERR_PTR(-EINVAL
);
1406 * do not remove from the list until nobody holds it; walking the
1407 * list in do_sysctl() relies on that.
1409 list_del_init(&p
->ctl_entry
);
1412 void sysctl_head_get(struct ctl_table_header
*head
)
1414 spin_lock(&sysctl_lock
);
1416 spin_unlock(&sysctl_lock
);
1419 void sysctl_head_put(struct ctl_table_header
*head
)
1421 spin_lock(&sysctl_lock
);
1424 spin_unlock(&sysctl_lock
);
1427 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1431 spin_lock(&sysctl_lock
);
1432 if (!use_table(head
))
1433 head
= ERR_PTR(-ENOENT
);
1434 spin_unlock(&sysctl_lock
);
1438 void sysctl_head_finish(struct ctl_table_header
*head
)
1442 spin_lock(&sysctl_lock
);
1444 spin_unlock(&sysctl_lock
);
1447 static struct ctl_table_set
*
1448 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1450 struct ctl_table_set
*set
= &root
->default_set
;
1452 set
= root
->lookup(root
, namespaces
);
1456 static struct list_head
*
1457 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1459 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1463 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1464 struct ctl_table_header
*prev
)
1466 struct ctl_table_root
*root
;
1467 struct list_head
*header_list
;
1468 struct ctl_table_header
*head
;
1469 struct list_head
*tmp
;
1471 spin_lock(&sysctl_lock
);
1474 tmp
= &prev
->ctl_entry
;
1478 tmp
= &root_table_header
.ctl_entry
;
1480 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1482 if (!use_table(head
))
1484 spin_unlock(&sysctl_lock
);
1489 header_list
= lookup_header_list(root
, namespaces
);
1490 if (tmp
!= header_list
)
1494 root
= list_entry(root
->root_list
.next
,
1495 struct ctl_table_root
, root_list
);
1496 if (root
== &sysctl_table_root
)
1498 header_list
= lookup_header_list(root
, namespaces
);
1499 } while (list_empty(header_list
));
1500 tmp
= header_list
->next
;
1503 spin_unlock(&sysctl_lock
);
1507 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1509 return __sysctl_head_next(current
->nsproxy
, prev
);
1512 void register_sysctl_root(struct ctl_table_root
*root
)
1514 spin_lock(&sysctl_lock
);
1515 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1516 spin_unlock(&sysctl_lock
);
1519 #ifdef CONFIG_SYSCTL_SYSCALL
1520 /* Perform the actual read/write of a sysctl table entry. */
1521 static int do_sysctl_strategy(struct ctl_table_root
*root
,
1522 struct ctl_table
*table
,
1523 int __user
*name
, int nlen
,
1524 void __user
*oldval
, size_t __user
*oldlenp
,
1525 void __user
*newval
, size_t newlen
)
1533 if (sysctl_perm(root
, table
, op
))
1536 if (table
->strategy
) {
1537 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1545 /* If there is no strategy routine, or if the strategy returns
1546 * zero, proceed with automatic r/w */
1547 if (table
->data
&& table
->maxlen
) {
1548 rc
= sysctl_data(table
, name
, nlen
, oldval
, oldlenp
,
1556 static int parse_table(int __user
*name
, int nlen
,
1557 void __user
*oldval
, size_t __user
*oldlenp
,
1558 void __user
*newval
, size_t newlen
,
1559 struct ctl_table_root
*root
,
1560 struct ctl_table
*table
)
1566 if (get_user(n
, name
))
1568 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1569 if (!table
->ctl_name
)
1571 if (n
== table
->ctl_name
) {
1574 if (sysctl_perm(root
, table
, MAY_EXEC
))
1578 table
= table
->child
;
1581 error
= do_sysctl_strategy(root
, table
, name
, nlen
,
1590 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1591 void __user
*newval
, size_t newlen
)
1593 struct ctl_table_header
*head
;
1594 int error
= -ENOTDIR
;
1596 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1600 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1604 for (head
= sysctl_head_next(NULL
); head
;
1605 head
= sysctl_head_next(head
)) {
1606 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1608 head
->root
, head
->ctl_table
);
1609 if (error
!= -ENOTDIR
) {
1610 sysctl_head_finish(head
);
1617 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
1619 struct __sysctl_args tmp
;
1622 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1625 error
= deprecated_sysctl_warning(&tmp
);
1630 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1631 tmp
.newval
, tmp
.newlen
);
1636 #endif /* CONFIG_SYSCTL_SYSCALL */
1639 * sysctl_perm does NOT grant the superuser all rights automatically, because
1640 * some sysctl variables are readonly even to root.
1643 static int test_perm(int mode
, int op
)
1647 else if (in_egroup_p(0))
1649 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1654 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1659 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1663 if (root
->permissions
)
1664 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1668 return test_perm(mode
, op
);
1671 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1673 for (; table
->ctl_name
|| table
->procname
; table
++) {
1674 table
->parent
= parent
;
1676 sysctl_set_parent(table
, table
->child
);
1680 static __init
int sysctl_init(void)
1682 sysctl_set_parent(NULL
, root_table
);
1683 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1686 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1692 core_initcall(sysctl_init
);
1694 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1695 struct ctl_table
*table
)
1697 struct ctl_table
*p
;
1698 const char *s
= branch
->procname
;
1700 /* branch should have named subdirectory as its first element */
1701 if (!s
|| !branch
->child
)
1704 /* ... and nothing else */
1705 if (branch
[1].procname
|| branch
[1].ctl_name
)
1708 /* table should contain subdirectory with the same name */
1709 for (p
= table
; p
->procname
|| p
->ctl_name
; p
++) {
1712 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1718 /* see if attaching q to p would be an improvement */
1719 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1721 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1722 struct ctl_table
*next
;
1724 int not_in_parent
= !p
->attached_by
;
1726 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1727 if (by
== q
->attached_by
)
1729 if (to
== p
->attached_by
)
1735 if (is_better
&& not_in_parent
) {
1736 q
->attached_by
= by
;
1737 q
->attached_to
= to
;
1743 * __register_sysctl_paths - register a sysctl hierarchy
1744 * @root: List of sysctl headers to register on
1745 * @namespaces: Data to compute which lists of sysctl entries are visible
1746 * @path: The path to the directory the sysctl table is in.
1747 * @table: the top-level table structure
1749 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1750 * array. A completely 0 filled entry terminates the table.
1752 * The members of the &struct ctl_table structure are used as follows:
1754 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1755 * must be unique within that level of sysctl
1757 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1758 * enter a sysctl file
1760 * data - a pointer to data for use by proc_handler
1762 * maxlen - the maximum size in bytes of the data
1764 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1766 * child - a pointer to the child sysctl table if this entry is a directory, or
1769 * proc_handler - the text handler routine (described below)
1771 * strategy - the strategy routine (described below)
1773 * de - for internal use by the sysctl routines
1775 * extra1, extra2 - extra pointers usable by the proc handler routines
1777 * Leaf nodes in the sysctl tree will be represented by a single file
1778 * under /proc; non-leaf nodes will be represented by directories.
1780 * sysctl(2) can automatically manage read and write requests through
1781 * the sysctl table. The data and maxlen fields of the ctl_table
1782 * struct enable minimal validation of the values being written to be
1783 * performed, and the mode field allows minimal authentication.
1785 * More sophisticated management can be enabled by the provision of a
1786 * strategy routine with the table entry. This will be called before
1787 * any automatic read or write of the data is performed.
1789 * The strategy routine may return
1791 * < 0 - Error occurred (error is passed to user process)
1793 * 0 - OK - proceed with automatic read or write.
1795 * > 0 - OK - read or write has been done by the strategy routine, so
1796 * return immediately.
1798 * There must be a proc_handler routine for any terminal nodes
1799 * mirrored under /proc/sys (non-terminals are handled by a built-in
1800 * directory handler). Several default handlers are available to
1801 * cover common cases -
1803 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1804 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1805 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1807 * It is the handler's job to read the input buffer from user memory
1808 * and process it. The handler should return 0 on success.
1810 * This routine returns %NULL on a failure to register, and a pointer
1811 * to the table header on success.
1813 struct ctl_table_header
*__register_sysctl_paths(
1814 struct ctl_table_root
*root
,
1815 struct nsproxy
*namespaces
,
1816 const struct ctl_path
*path
, struct ctl_table
*table
)
1818 struct ctl_table_header
*header
;
1819 struct ctl_table
*new, **prevp
;
1820 unsigned int n
, npath
;
1821 struct ctl_table_set
*set
;
1823 /* Count the path components */
1824 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
1828 * For each path component, allocate a 2-element ctl_table array.
1829 * The first array element will be filled with the sysctl entry
1830 * for this, the second will be the sentinel (ctl_name == 0).
1832 * We allocate everything in one go so that we don't have to
1833 * worry about freeing additional memory in unregister_sysctl_table.
1835 header
= kzalloc(sizeof(struct ctl_table_header
) +
1836 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1840 new = (struct ctl_table
*) (header
+ 1);
1842 /* Now connect the dots */
1843 prevp
= &header
->ctl_table
;
1844 for (n
= 0; n
< npath
; ++n
, ++path
) {
1845 /* Copy the procname */
1846 new->procname
= path
->procname
;
1847 new->ctl_name
= path
->ctl_name
;
1851 prevp
= &new->child
;
1856 header
->ctl_table_arg
= table
;
1858 INIT_LIST_HEAD(&header
->ctl_entry
);
1860 header
->unregistering
= NULL
;
1861 header
->root
= root
;
1862 sysctl_set_parent(NULL
, header
->ctl_table
);
1864 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1865 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1870 spin_lock(&sysctl_lock
);
1871 header
->set
= lookup_header_set(root
, namespaces
);
1872 header
->attached_by
= header
->ctl_table
;
1873 header
->attached_to
= root_table
;
1874 header
->parent
= &root_table_header
;
1875 for (set
= header
->set
; set
; set
= set
->parent
) {
1876 struct ctl_table_header
*p
;
1877 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
1878 if (p
->unregistering
)
1880 try_attach(p
, header
);
1883 header
->parent
->count
++;
1884 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
1885 spin_unlock(&sysctl_lock
);
1891 * register_sysctl_table_path - register a sysctl table hierarchy
1892 * @path: The path to the directory the sysctl table is in.
1893 * @table: the top-level table structure
1895 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1896 * array. A completely 0 filled entry terminates the table.
1898 * See __register_sysctl_paths for more details.
1900 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1901 struct ctl_table
*table
)
1903 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1908 * register_sysctl_table - register a sysctl table hierarchy
1909 * @table: the top-level table structure
1911 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1912 * array. A completely 0 filled entry terminates the table.
1914 * See register_sysctl_paths for more details.
1916 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1918 static const struct ctl_path null_path
[] = { {} };
1920 return register_sysctl_paths(null_path
, table
);
1924 * unregister_sysctl_table - unregister a sysctl table hierarchy
1925 * @header: the header returned from register_sysctl_table
1927 * Unregisters the sysctl table and all children. proc entries may not
1928 * actually be removed until they are no longer used by anyone.
1930 void unregister_sysctl_table(struct ctl_table_header
* header
)
1937 spin_lock(&sysctl_lock
);
1938 start_unregistering(header
);
1939 if (!--header
->parent
->count
) {
1941 kfree(header
->parent
);
1943 if (!--header
->count
)
1945 spin_unlock(&sysctl_lock
);
1948 int sysctl_is_seen(struct ctl_table_header
*p
)
1950 struct ctl_table_set
*set
= p
->set
;
1952 spin_lock(&sysctl_lock
);
1953 if (p
->unregistering
)
1955 else if (!set
->is_seen
)
1958 res
= set
->is_seen(set
);
1959 spin_unlock(&sysctl_lock
);
1963 void setup_sysctl_set(struct ctl_table_set
*p
,
1964 struct ctl_table_set
*parent
,
1965 int (*is_seen
)(struct ctl_table_set
*))
1967 INIT_LIST_HEAD(&p
->list
);
1968 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
1969 p
->is_seen
= is_seen
;
1972 #else /* !CONFIG_SYSCTL */
1973 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1978 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1979 struct ctl_table
*table
)
1984 void unregister_sysctl_table(struct ctl_table_header
* table
)
1988 void setup_sysctl_set(struct ctl_table_set
*p
,
1989 struct ctl_table_set
*parent
,
1990 int (*is_seen
)(struct ctl_table_set
*))
1994 void sysctl_head_put(struct ctl_table_header
*head
)
1998 #endif /* CONFIG_SYSCTL */
2004 #ifdef CONFIG_PROC_SYSCTL
2006 static int _proc_do_string(void* data
, int maxlen
, int write
,
2007 struct file
*filp
, void __user
*buffer
,
2008 size_t *lenp
, loff_t
*ppos
)
2014 if (!data
|| !maxlen
|| !*lenp
) {
2022 while (len
< *lenp
) {
2023 if (get_user(c
, p
++))
2025 if (c
== 0 || c
== '\n')
2031 if(copy_from_user(data
, buffer
, len
))
2033 ((char *) data
)[len
] = 0;
2051 if(copy_to_user(buffer
, data
, len
))
2054 if(put_user('\n', ((char __user
*) buffer
) + len
))
2065 * proc_dostring - read a string sysctl
2066 * @table: the sysctl table
2067 * @write: %TRUE if this is a write to the sysctl file
2068 * @filp: the file structure
2069 * @buffer: the user buffer
2070 * @lenp: the size of the user buffer
2071 * @ppos: file position
2073 * Reads/writes a string from/to the user buffer. If the kernel
2074 * buffer provided is not large enough to hold the string, the
2075 * string is truncated. The copied string is %NULL-terminated.
2076 * If the string is being read by the user process, it is copied
2077 * and a newline '\n' is added. It is truncated if the buffer is
2080 * Returns 0 on success.
2082 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2083 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2085 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
2086 buffer
, lenp
, ppos
);
2090 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
2092 int write
, void *data
)
2095 *valp
= *negp
? -*lvalp
: *lvalp
;
2100 *lvalp
= (unsigned long)-val
;
2103 *lvalp
= (unsigned long)val
;
2109 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2110 int write
, struct file
*filp
, void __user
*buffer
,
2111 size_t *lenp
, loff_t
*ppos
,
2112 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2113 int write
, void *data
),
2116 #define TMPBUFLEN 21
2117 int *i
, vleft
, first
=1, neg
, val
;
2121 char buf
[TMPBUFLEN
], *p
;
2122 char __user
*s
= buffer
;
2124 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
2125 (*ppos
&& !write
)) {
2130 i
= (int *) tbl_data
;
2131 vleft
= table
->maxlen
/ sizeof(*i
);
2135 conv
= do_proc_dointvec_conv
;
2137 for (; left
&& vleft
--; i
++, first
=0) {
2152 if (len
> sizeof(buf
) - 1)
2153 len
= sizeof(buf
) - 1;
2154 if (copy_from_user(buf
, s
, len
))
2158 if (*p
== '-' && left
> 1) {
2162 if (*p
< '0' || *p
> '9')
2165 lval
= simple_strtoul(p
, &p
, 0);
2168 if ((len
< left
) && *p
&& !isspace(*p
))
2175 if (conv(&neg
, &lval
, i
, 1, data
))
2182 if (conv(&neg
, &lval
, i
, 0, data
))
2185 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2189 if(copy_to_user(s
, buf
, len
))
2196 if (!write
&& !first
&& left
) {
2197 if(put_user('\n', s
))
2204 if (get_user(c
, s
++))
2219 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2220 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2221 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2222 int write
, void *data
),
2225 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2226 buffer
, lenp
, ppos
, conv
, data
);
2230 * proc_dointvec - read a vector of integers
2231 * @table: the sysctl table
2232 * @write: %TRUE if this is a write to the sysctl file
2233 * @filp: the file structure
2234 * @buffer: the user buffer
2235 * @lenp: the size of the user buffer
2236 * @ppos: file position
2238 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2239 * values from/to the user buffer, treated as an ASCII string.
2241 * Returns 0 on success.
2243 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2244 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2246 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2254 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
2256 int write
, void *data
)
2258 int op
= *(int *)data
;
2260 int val
= *negp
? -*lvalp
: *lvalp
;
2262 case OP_SET
: *valp
= val
; break;
2263 case OP_AND
: *valp
&= val
; break;
2264 case OP_OR
: *valp
|= val
; break;
2270 *lvalp
= (unsigned long)-val
;
2273 *lvalp
= (unsigned long)val
;
2280 * Taint values can only be increased
2282 static int proc_dointvec_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2283 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2287 if (write
&& !capable(CAP_SYS_ADMIN
))
2291 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2292 do_proc_dointvec_bset_conv
,&op
);
2295 struct do_proc_dointvec_minmax_conv_param
{
2300 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2302 int write
, void *data
)
2304 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2306 int val
= *negp
? -*lvalp
: *lvalp
;
2307 if ((param
->min
&& *param
->min
> val
) ||
2308 (param
->max
&& *param
->max
< val
))
2315 *lvalp
= (unsigned long)-val
;
2318 *lvalp
= (unsigned long)val
;
2325 * proc_dointvec_minmax - read a vector of integers with min/max values
2326 * @table: the sysctl table
2327 * @write: %TRUE if this is a write to the sysctl file
2328 * @filp: the file structure
2329 * @buffer: the user buffer
2330 * @lenp: the size of the user buffer
2331 * @ppos: file position
2333 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2334 * values from/to the user buffer, treated as an ASCII string.
2336 * This routine will ensure the values are within the range specified by
2337 * table->extra1 (min) and table->extra2 (max).
2339 * Returns 0 on success.
2341 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2342 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2344 struct do_proc_dointvec_minmax_conv_param param
= {
2345 .min
= (int *) table
->extra1
,
2346 .max
= (int *) table
->extra2
,
2348 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2349 do_proc_dointvec_minmax_conv
, ¶m
);
2352 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2354 void __user
*buffer
,
2355 size_t *lenp
, loff_t
*ppos
,
2356 unsigned long convmul
,
2357 unsigned long convdiv
)
2359 #define TMPBUFLEN 21
2360 unsigned long *i
, *min
, *max
, val
;
2361 int vleft
, first
=1, neg
;
2363 char buf
[TMPBUFLEN
], *p
;
2364 char __user
*s
= buffer
;
2366 if (!data
|| !table
->maxlen
|| !*lenp
||
2367 (*ppos
&& !write
)) {
2372 i
= (unsigned long *) data
;
2373 min
= (unsigned long *) table
->extra1
;
2374 max
= (unsigned long *) table
->extra2
;
2375 vleft
= table
->maxlen
/ sizeof(unsigned long);
2378 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2393 if (len
> TMPBUFLEN
-1)
2395 if (copy_from_user(buf
, s
, len
))
2399 if (*p
== '-' && left
> 1) {
2403 if (*p
< '0' || *p
> '9')
2405 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2407 if ((len
< left
) && *p
&& !isspace(*p
))
2416 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2423 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2427 if(copy_to_user(s
, buf
, len
))
2434 if (!write
&& !first
&& left
) {
2435 if(put_user('\n', s
))
2442 if (get_user(c
, s
++))
2457 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2459 void __user
*buffer
,
2460 size_t *lenp
, loff_t
*ppos
,
2461 unsigned long convmul
,
2462 unsigned long convdiv
)
2464 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2465 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2469 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2470 * @table: the sysctl table
2471 * @write: %TRUE if this is a write to the sysctl file
2472 * @filp: the file structure
2473 * @buffer: the user buffer
2474 * @lenp: the size of the user buffer
2475 * @ppos: file position
2477 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2478 * values from/to the user buffer, treated as an ASCII string.
2480 * This routine will ensure the values are within the range specified by
2481 * table->extra1 (min) and table->extra2 (max).
2483 * Returns 0 on success.
2485 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2486 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2488 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2492 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2493 * @table: the sysctl table
2494 * @write: %TRUE if this is a write to the sysctl file
2495 * @filp: the file structure
2496 * @buffer: the user buffer
2497 * @lenp: the size of the user buffer
2498 * @ppos: file position
2500 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2501 * values from/to the user buffer, treated as an ASCII string. The values
2502 * are treated as milliseconds, and converted to jiffies when they are stored.
2504 * This routine will ensure the values are within the range specified by
2505 * table->extra1 (min) and table->extra2 (max).
2507 * Returns 0 on success.
2509 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2511 void __user
*buffer
,
2512 size_t *lenp
, loff_t
*ppos
)
2514 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2515 lenp
, ppos
, HZ
, 1000l);
2519 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2521 int write
, void *data
)
2524 if (*lvalp
> LONG_MAX
/ HZ
)
2526 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2532 lval
= (unsigned long)-val
;
2535 lval
= (unsigned long)val
;
2542 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2544 int write
, void *data
)
2547 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2549 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2555 lval
= (unsigned long)-val
;
2558 lval
= (unsigned long)val
;
2560 *lvalp
= jiffies_to_clock_t(lval
);
2565 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2567 int write
, void *data
)
2570 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2576 lval
= (unsigned long)-val
;
2579 lval
= (unsigned long)val
;
2581 *lvalp
= jiffies_to_msecs(lval
);
2587 * proc_dointvec_jiffies - read a vector of integers as seconds
2588 * @table: the sysctl table
2589 * @write: %TRUE if this is a write to the sysctl file
2590 * @filp: the file structure
2591 * @buffer: the user buffer
2592 * @lenp: the size of the user buffer
2593 * @ppos: file position
2595 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2596 * values from/to the user buffer, treated as an ASCII string.
2597 * The values read are assumed to be in seconds, and are converted into
2600 * Returns 0 on success.
2602 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2603 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2605 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2606 do_proc_dointvec_jiffies_conv
,NULL
);
2610 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
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: pointer to the file position
2618 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2619 * values from/to the user buffer, treated as an ASCII string.
2620 * The values read are assumed to be in 1/USER_HZ seconds, and
2621 * are converted into jiffies.
2623 * Returns 0 on success.
2625 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2626 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2628 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2629 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2633 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
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
2640 * @ppos: the current position in the file
2642 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2643 * values from/to the user buffer, treated as an ASCII string.
2644 * The values read are assumed to be in 1/1000 seconds, and
2645 * are converted into jiffies.
2647 * Returns 0 on success.
2649 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2650 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2652 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2653 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2656 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2657 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2659 struct pid
*new_pid
;
2663 tmp
= pid_vnr(cad_pid
);
2665 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2666 lenp
, ppos
, NULL
, NULL
);
2670 new_pid
= find_get_pid(tmp
);
2674 put_pid(xchg(&cad_pid
, new_pid
));
2678 #else /* CONFIG_PROC_FS */
2680 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2681 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2686 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2687 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2692 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2693 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2698 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2699 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2704 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2705 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2710 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2711 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2716 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2717 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2722 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2724 void __user
*buffer
,
2725 size_t *lenp
, loff_t
*ppos
)
2731 #endif /* CONFIG_PROC_FS */
2734 #ifdef CONFIG_SYSCTL_SYSCALL
2736 * General sysctl support routines
2739 /* The generic sysctl data routine (used if no strategy routine supplied) */
2740 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2741 void __user
*oldval
, size_t __user
*oldlenp
,
2742 void __user
*newval
, size_t newlen
)
2746 /* Get out of I don't have a variable */
2747 if (!table
->data
|| !table
->maxlen
)
2750 if (oldval
&& oldlenp
) {
2751 if (get_user(len
, oldlenp
))
2754 if (len
> table
->maxlen
)
2755 len
= table
->maxlen
;
2756 if (copy_to_user(oldval
, table
->data
, len
))
2758 if (put_user(len
, oldlenp
))
2763 if (newval
&& newlen
) {
2764 if (newlen
> table
->maxlen
)
2765 newlen
= table
->maxlen
;
2767 if (copy_from_user(table
->data
, newval
, newlen
))
2773 /* The generic string strategy routine: */
2774 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2775 void __user
*oldval
, size_t __user
*oldlenp
,
2776 void __user
*newval
, size_t newlen
)
2778 if (!table
->data
|| !table
->maxlen
)
2781 if (oldval
&& oldlenp
) {
2783 if (get_user(bufsize
, oldlenp
))
2786 size_t len
= strlen(table
->data
), copied
;
2788 /* This shouldn't trigger for a well-formed sysctl */
2789 if (len
> table
->maxlen
)
2790 len
= table
->maxlen
;
2792 /* Copy up to a max of bufsize-1 bytes of the string */
2793 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2795 if (copy_to_user(oldval
, table
->data
, copied
) ||
2796 put_user(0, (char __user
*)(oldval
+ copied
)))
2798 if (put_user(len
, oldlenp
))
2802 if (newval
&& newlen
) {
2803 size_t len
= newlen
;
2804 if (len
> table
->maxlen
)
2805 len
= table
->maxlen
;
2806 if(copy_from_user(table
->data
, newval
, len
))
2808 if (len
== table
->maxlen
)
2810 ((char *) table
->data
)[len
] = 0;
2816 * This function makes sure that all of the integers in the vector
2817 * are between the minimum and maximum values given in the arrays
2818 * table->extra1 and table->extra2, respectively.
2820 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2821 void __user
*oldval
, size_t __user
*oldlenp
,
2822 void __user
*newval
, size_t newlen
)
2825 if (newval
&& newlen
) {
2826 int __user
*vec
= (int __user
*) newval
;
2827 int *min
= (int *) table
->extra1
;
2828 int *max
= (int *) table
->extra2
;
2832 if (newlen
% sizeof(int) != 0)
2835 if (!table
->extra1
&& !table
->extra2
)
2838 if (newlen
> table
->maxlen
)
2839 newlen
= table
->maxlen
;
2840 length
= newlen
/ sizeof(int);
2842 for (i
= 0; i
< length
; i
++) {
2844 if (get_user(value
, vec
+ i
))
2846 if (min
&& value
< min
[i
])
2848 if (max
&& value
> max
[i
])
2855 /* Strategy function to convert jiffies to seconds */
2856 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2857 void __user
*oldval
, size_t __user
*oldlenp
,
2858 void __user
*newval
, size_t newlen
)
2860 if (oldval
&& oldlenp
) {
2863 if (get_user(olen
, oldlenp
))
2868 if (olen
< sizeof(int))
2871 val
= *(int *)(table
->data
) / HZ
;
2872 if (put_user(val
, (int __user
*)oldval
))
2874 if (put_user(sizeof(int), oldlenp
))
2878 if (newval
&& newlen
) {
2880 if (newlen
!= sizeof(int))
2882 if (get_user(new, (int __user
*)newval
))
2884 *(int *)(table
->data
) = new*HZ
;
2889 /* Strategy function to convert jiffies to seconds */
2890 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2891 void __user
*oldval
, size_t __user
*oldlenp
,
2892 void __user
*newval
, size_t newlen
)
2894 if (oldval
&& oldlenp
) {
2897 if (get_user(olen
, oldlenp
))
2902 if (olen
< sizeof(int))
2905 val
= jiffies_to_msecs(*(int *)(table
->data
));
2906 if (put_user(val
, (int __user
*)oldval
))
2908 if (put_user(sizeof(int), oldlenp
))
2912 if (newval
&& newlen
) {
2914 if (newlen
!= sizeof(int))
2916 if (get_user(new, (int __user
*)newval
))
2918 *(int *)(table
->data
) = msecs_to_jiffies(new);
2925 #else /* CONFIG_SYSCTL_SYSCALL */
2928 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
2930 struct __sysctl_args tmp
;
2933 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
2936 error
= deprecated_sysctl_warning(&tmp
);
2938 /* If no error reading the parameters then just -ENOSYS ... */
2945 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2946 void __user
*oldval
, size_t __user
*oldlenp
,
2947 void __user
*newval
, size_t newlen
)
2952 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2953 void __user
*oldval
, size_t __user
*oldlenp
,
2954 void __user
*newval
, size_t newlen
)
2959 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2960 void __user
*oldval
, size_t __user
*oldlenp
,
2961 void __user
*newval
, size_t newlen
)
2966 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2967 void __user
*oldval
, size_t __user
*oldlenp
,
2968 void __user
*newval
, size_t newlen
)
2973 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2974 void __user
*oldval
, size_t __user
*oldlenp
,
2975 void __user
*newval
, size_t newlen
)
2980 #endif /* CONFIG_SYSCTL_SYSCALL */
2982 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
2984 static int msg_count
;
2985 int name
[CTL_MAXNAME
];
2988 /* Check args->nlen. */
2989 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
2992 /* Read in the sysctl name for better debug message logging */
2993 for (i
= 0; i
< args
->nlen
; i
++)
2994 if (get_user(name
[i
], args
->name
+ i
))
2997 /* Ignore accesses to kernel.version */
2998 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
3001 if (msg_count
< 5) {
3004 "warning: process `%s' used the deprecated sysctl "
3005 "system call with ", current
->comm
);
3006 for (i
= 0; i
< args
->nlen
; i
++)
3007 printk("%d.", name
[i
]);
3014 * No sense putting this after each symbol definition, twice,
3015 * exception granted :-)
3017 EXPORT_SYMBOL(proc_dointvec
);
3018 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3019 EXPORT_SYMBOL(proc_dointvec_minmax
);
3020 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3021 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3022 EXPORT_SYMBOL(proc_dostring
);
3023 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3024 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
3025 EXPORT_SYMBOL(register_sysctl_table
);
3026 EXPORT_SYMBOL(register_sysctl_paths
);
3027 EXPORT_SYMBOL(sysctl_intvec
);
3028 EXPORT_SYMBOL(sysctl_jiffies
);
3029 EXPORT_SYMBOL(sysctl_ms_jiffies
);
3030 EXPORT_SYMBOL(sysctl_string
);
3031 EXPORT_SYMBOL(sysctl_data
);
3032 EXPORT_SYMBOL(unregister_sysctl_table
);