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
= {
162 .ctl_table
= root_table
,
163 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.header_list
),
164 .root
= &sysctl_table_root
,
166 static struct ctl_table_root sysctl_table_root
= {
167 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
168 .header_list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
171 static struct ctl_table kern_table
[];
172 static struct ctl_table vm_table
[];
173 static struct ctl_table fs_table
[];
174 static struct ctl_table debug_table
[];
175 static struct ctl_table dev_table
[];
176 extern struct ctl_table random_table
[];
177 #ifdef CONFIG_INOTIFY_USER
178 extern struct ctl_table inotify_table
[];
181 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
182 int sysctl_legacy_va_layout
;
185 extern int prove_locking
;
186 extern int lock_stat
;
188 /* The default sysctl tables: */
190 static struct ctl_table root_table
[] = {
192 .ctl_name
= CTL_KERN
,
193 .procname
= "kernel",
210 .ctl_name
= CTL_DEBUG
,
213 .child
= debug_table
,
222 * NOTE: do not add new entries to this table unless you have read
223 * Documentation/sysctl/ctl_unnumbered.txt
228 #ifdef CONFIG_SCHED_DEBUG
229 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
230 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
231 static int min_wakeup_granularity_ns
; /* 0 usecs */
232 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
235 static struct ctl_table kern_table
[] = {
236 #ifdef CONFIG_SCHED_DEBUG
238 .ctl_name
= CTL_UNNUMBERED
,
239 .procname
= "sched_min_granularity_ns",
240 .data
= &sysctl_sched_min_granularity
,
241 .maxlen
= sizeof(unsigned int),
243 .proc_handler
= &sched_nr_latency_handler
,
244 .strategy
= &sysctl_intvec
,
245 .extra1
= &min_sched_granularity_ns
,
246 .extra2
= &max_sched_granularity_ns
,
249 .ctl_name
= CTL_UNNUMBERED
,
250 .procname
= "sched_latency_ns",
251 .data
= &sysctl_sched_latency
,
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_wakeup_granularity_ns",
262 .data
= &sysctl_sched_wakeup_granularity
,
263 .maxlen
= sizeof(unsigned int),
265 .proc_handler
= &proc_dointvec_minmax
,
266 .strategy
= &sysctl_intvec
,
267 .extra1
= &min_wakeup_granularity_ns
,
268 .extra2
= &max_wakeup_granularity_ns
,
271 .ctl_name
= CTL_UNNUMBERED
,
272 .procname
= "sched_shares_ratelimit",
273 .data
= &sysctl_sched_shares_ratelimit
,
274 .maxlen
= sizeof(unsigned int),
276 .proc_handler
= &proc_dointvec
,
279 .ctl_name
= CTL_UNNUMBERED
,
280 .procname
= "sched_child_runs_first",
281 .data
= &sysctl_sched_child_runs_first
,
282 .maxlen
= sizeof(unsigned int),
284 .proc_handler
= &proc_dointvec
,
287 .ctl_name
= CTL_UNNUMBERED
,
288 .procname
= "sched_features",
289 .data
= &sysctl_sched_features
,
290 .maxlen
= sizeof(unsigned int),
292 .proc_handler
= &proc_dointvec
,
295 .ctl_name
= CTL_UNNUMBERED
,
296 .procname
= "sched_migration_cost",
297 .data
= &sysctl_sched_migration_cost
,
298 .maxlen
= sizeof(unsigned int),
300 .proc_handler
= &proc_dointvec
,
303 .ctl_name
= CTL_UNNUMBERED
,
304 .procname
= "sched_nr_migrate",
305 .data
= &sysctl_sched_nr_migrate
,
306 .maxlen
= sizeof(unsigned int),
308 .proc_handler
= &proc_dointvec
,
312 .ctl_name
= CTL_UNNUMBERED
,
313 .procname
= "sched_rt_period_us",
314 .data
= &sysctl_sched_rt_period
,
315 .maxlen
= sizeof(unsigned int),
317 .proc_handler
= &sched_rt_handler
,
320 .ctl_name
= CTL_UNNUMBERED
,
321 .procname
= "sched_rt_runtime_us",
322 .data
= &sysctl_sched_rt_runtime
,
323 .maxlen
= sizeof(int),
325 .proc_handler
= &sched_rt_handler
,
328 .ctl_name
= CTL_UNNUMBERED
,
329 .procname
= "sched_compat_yield",
330 .data
= &sysctl_sched_compat_yield
,
331 .maxlen
= sizeof(unsigned int),
333 .proc_handler
= &proc_dointvec
,
335 #ifdef CONFIG_PROVE_LOCKING
337 .ctl_name
= CTL_UNNUMBERED
,
338 .procname
= "prove_locking",
339 .data
= &prove_locking
,
340 .maxlen
= sizeof(int),
342 .proc_handler
= &proc_dointvec
,
345 #ifdef CONFIG_LOCK_STAT
347 .ctl_name
= CTL_UNNUMBERED
,
348 .procname
= "lock_stat",
350 .maxlen
= sizeof(int),
352 .proc_handler
= &proc_dointvec
,
356 .ctl_name
= KERN_PANIC
,
358 .data
= &panic_timeout
,
359 .maxlen
= sizeof(int),
361 .proc_handler
= &proc_dointvec
,
364 .ctl_name
= KERN_CORE_USES_PID
,
365 .procname
= "core_uses_pid",
366 .data
= &core_uses_pid
,
367 .maxlen
= sizeof(int),
369 .proc_handler
= &proc_dointvec
,
372 .ctl_name
= KERN_CORE_PATTERN
,
373 .procname
= "core_pattern",
374 .data
= core_pattern
,
375 .maxlen
= CORENAME_MAX_SIZE
,
377 .proc_handler
= &proc_dostring
,
378 .strategy
= &sysctl_string
,
380 #ifdef CONFIG_PROC_SYSCTL
382 .procname
= "tainted",
384 .maxlen
= sizeof(int),
386 .proc_handler
= &proc_dointvec_taint
,
389 #ifdef CONFIG_LATENCYTOP
391 .procname
= "latencytop",
392 .data
= &latencytop_enabled
,
393 .maxlen
= sizeof(int),
395 .proc_handler
= &proc_dointvec
,
398 #ifdef CONFIG_BLK_DEV_INITRD
400 .ctl_name
= KERN_REALROOTDEV
,
401 .procname
= "real-root-dev",
402 .data
= &real_root_dev
,
403 .maxlen
= sizeof(int),
405 .proc_handler
= &proc_dointvec
,
409 .ctl_name
= CTL_UNNUMBERED
,
410 .procname
= "print-fatal-signals",
411 .data
= &print_fatal_signals
,
412 .maxlen
= sizeof(int),
414 .proc_handler
= &proc_dointvec
,
418 .ctl_name
= KERN_SPARC_REBOOT
,
419 .procname
= "reboot-cmd",
420 .data
= reboot_command
,
423 .proc_handler
= &proc_dostring
,
424 .strategy
= &sysctl_string
,
427 .ctl_name
= KERN_SPARC_STOP_A
,
428 .procname
= "stop-a",
429 .data
= &stop_a_enabled
,
430 .maxlen
= sizeof (int),
432 .proc_handler
= &proc_dointvec
,
435 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
436 .procname
= "scons-poweroff",
437 .data
= &scons_pwroff
,
438 .maxlen
= sizeof (int),
440 .proc_handler
= &proc_dointvec
,
445 .ctl_name
= KERN_HPPA_PWRSW
,
446 .procname
= "soft-power",
447 .data
= &pwrsw_enabled
,
448 .maxlen
= sizeof (int),
450 .proc_handler
= &proc_dointvec
,
453 .ctl_name
= KERN_HPPA_UNALIGNED
,
454 .procname
= "unaligned-trap",
455 .data
= &unaligned_enabled
,
456 .maxlen
= sizeof (int),
458 .proc_handler
= &proc_dointvec
,
462 .ctl_name
= KERN_CTLALTDEL
,
463 .procname
= "ctrl-alt-del",
465 .maxlen
= sizeof(int),
467 .proc_handler
= &proc_dointvec
,
471 .ctl_name
= CTL_UNNUMBERED
,
472 .procname
= "ftrace_enabled",
473 .data
= &ftrace_enabled
,
474 .maxlen
= sizeof(int),
476 .proc_handler
= &ftrace_enable_sysctl
,
479 #ifdef CONFIG_MODULES
481 .ctl_name
= KERN_MODPROBE
,
482 .procname
= "modprobe",
483 .data
= &modprobe_path
,
484 .maxlen
= KMOD_PATH_LEN
,
486 .proc_handler
= &proc_dostring
,
487 .strategy
= &sysctl_string
,
490 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
492 .ctl_name
= KERN_HOTPLUG
,
493 .procname
= "hotplug",
494 .data
= &uevent_helper
,
495 .maxlen
= UEVENT_HELPER_PATH_LEN
,
497 .proc_handler
= &proc_dostring
,
498 .strategy
= &sysctl_string
,
501 #ifdef CONFIG_CHR_DEV_SG
503 .ctl_name
= KERN_SG_BIG_BUFF
,
504 .procname
= "sg-big-buff",
505 .data
= &sg_big_buff
,
506 .maxlen
= sizeof (int),
508 .proc_handler
= &proc_dointvec
,
511 #ifdef CONFIG_BSD_PROCESS_ACCT
513 .ctl_name
= KERN_ACCT
,
516 .maxlen
= 3*sizeof(int),
518 .proc_handler
= &proc_dointvec
,
521 #ifdef CONFIG_MAGIC_SYSRQ
523 .ctl_name
= KERN_SYSRQ
,
525 .data
= &__sysrq_enabled
,
526 .maxlen
= sizeof (int),
528 .proc_handler
= &proc_dointvec
,
531 #ifdef CONFIG_PROC_SYSCTL
533 .procname
= "cad_pid",
535 .maxlen
= sizeof (int),
537 .proc_handler
= &proc_do_cad_pid
,
541 .ctl_name
= KERN_MAX_THREADS
,
542 .procname
= "threads-max",
543 .data
= &max_threads
,
544 .maxlen
= sizeof(int),
546 .proc_handler
= &proc_dointvec
,
549 .ctl_name
= KERN_RANDOM
,
550 .procname
= "random",
552 .child
= random_table
,
555 .ctl_name
= KERN_OVERFLOWUID
,
556 .procname
= "overflowuid",
557 .data
= &overflowuid
,
558 .maxlen
= sizeof(int),
560 .proc_handler
= &proc_dointvec_minmax
,
561 .strategy
= &sysctl_intvec
,
562 .extra1
= &minolduid
,
563 .extra2
= &maxolduid
,
566 .ctl_name
= KERN_OVERFLOWGID
,
567 .procname
= "overflowgid",
568 .data
= &overflowgid
,
569 .maxlen
= sizeof(int),
571 .proc_handler
= &proc_dointvec_minmax
,
572 .strategy
= &sysctl_intvec
,
573 .extra1
= &minolduid
,
574 .extra2
= &maxolduid
,
577 #ifdef CONFIG_MATHEMU
579 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
580 .procname
= "ieee_emulation_warnings",
581 .data
= &sysctl_ieee_emulation_warnings
,
582 .maxlen
= sizeof(int),
584 .proc_handler
= &proc_dointvec
,
588 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
589 .procname
= "userprocess_debug",
590 .data
= &sysctl_userprocess_debug
,
591 .maxlen
= sizeof(int),
593 .proc_handler
= &proc_dointvec
,
597 .ctl_name
= KERN_PIDMAX
,
598 .procname
= "pid_max",
600 .maxlen
= sizeof (int),
602 .proc_handler
= &proc_dointvec_minmax
,
603 .strategy
= sysctl_intvec
,
604 .extra1
= &pid_max_min
,
605 .extra2
= &pid_max_max
,
608 .ctl_name
= KERN_PANIC_ON_OOPS
,
609 .procname
= "panic_on_oops",
610 .data
= &panic_on_oops
,
611 .maxlen
= sizeof(int),
613 .proc_handler
= &proc_dointvec
,
615 #if defined CONFIG_PRINTK
617 .ctl_name
= KERN_PRINTK
,
618 .procname
= "printk",
619 .data
= &console_loglevel
,
620 .maxlen
= 4*sizeof(int),
622 .proc_handler
= &proc_dointvec
,
625 .ctl_name
= KERN_PRINTK_RATELIMIT
,
626 .procname
= "printk_ratelimit",
627 .data
= &printk_ratelimit_jiffies
,
628 .maxlen
= sizeof(int),
630 .proc_handler
= &proc_dointvec_jiffies
,
631 .strategy
= &sysctl_jiffies
,
634 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
635 .procname
= "printk_ratelimit_burst",
636 .data
= &printk_ratelimit_burst
,
637 .maxlen
= sizeof(int),
639 .proc_handler
= &proc_dointvec
,
643 .ctl_name
= KERN_NGROUPS_MAX
,
644 .procname
= "ngroups_max",
645 .data
= &ngroups_max
,
646 .maxlen
= sizeof (int),
648 .proc_handler
= &proc_dointvec
,
650 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
652 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
653 .procname
= "unknown_nmi_panic",
654 .data
= &unknown_nmi_panic
,
655 .maxlen
= sizeof (int),
657 .proc_handler
= &proc_dointvec
,
660 .procname
= "nmi_watchdog",
661 .data
= &nmi_watchdog_enabled
,
662 .maxlen
= sizeof (int),
664 .proc_handler
= &proc_nmi_enabled
,
667 #if defined(CONFIG_X86)
669 .ctl_name
= KERN_PANIC_ON_NMI
,
670 .procname
= "panic_on_unrecovered_nmi",
671 .data
= &panic_on_unrecovered_nmi
,
672 .maxlen
= sizeof(int),
674 .proc_handler
= &proc_dointvec
,
677 .ctl_name
= KERN_BOOTLOADER_TYPE
,
678 .procname
= "bootloader_type",
679 .data
= &bootloader_type
,
680 .maxlen
= sizeof (int),
682 .proc_handler
= &proc_dointvec
,
685 .ctl_name
= CTL_UNNUMBERED
,
686 .procname
= "kstack_depth_to_print",
687 .data
= &kstack_depth_to_print
,
688 .maxlen
= sizeof(int),
690 .proc_handler
= &proc_dointvec
,
693 .ctl_name
= CTL_UNNUMBERED
,
694 .procname
= "io_delay_type",
695 .data
= &io_delay_type
,
696 .maxlen
= sizeof(int),
698 .proc_handler
= &proc_dointvec
,
701 #if defined(CONFIG_MMU)
703 .ctl_name
= KERN_RANDOMIZE
,
704 .procname
= "randomize_va_space",
705 .data
= &randomize_va_space
,
706 .maxlen
= sizeof(int),
708 .proc_handler
= &proc_dointvec
,
711 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
713 .ctl_name
= KERN_SPIN_RETRY
,
714 .procname
= "spin_retry",
716 .maxlen
= sizeof (int),
718 .proc_handler
= &proc_dointvec
,
721 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
723 .procname
= "acpi_video_flags",
724 .data
= &acpi_realmode_flags
,
725 .maxlen
= sizeof (unsigned long),
727 .proc_handler
= &proc_doulongvec_minmax
,
732 .ctl_name
= KERN_IA64_UNALIGNED
,
733 .procname
= "ignore-unaligned-usertrap",
734 .data
= &no_unaligned_warning
,
735 .maxlen
= sizeof (int),
737 .proc_handler
= &proc_dointvec
,
740 #ifdef CONFIG_DETECT_SOFTLOCKUP
742 .ctl_name
= CTL_UNNUMBERED
,
743 .procname
= "softlockup_panic",
744 .data
= &softlockup_panic
,
745 .maxlen
= sizeof(int),
747 .proc_handler
= &proc_dointvec_minmax
,
748 .strategy
= &sysctl_intvec
,
753 .ctl_name
= CTL_UNNUMBERED
,
754 .procname
= "softlockup_thresh",
755 .data
= &softlockup_thresh
,
756 .maxlen
= sizeof(int),
758 .proc_handler
= &proc_dointvec_minmax
,
759 .strategy
= &sysctl_intvec
,
764 .ctl_name
= CTL_UNNUMBERED
,
765 .procname
= "hung_task_check_count",
766 .data
= &sysctl_hung_task_check_count
,
767 .maxlen
= sizeof(unsigned long),
769 .proc_handler
= &proc_doulongvec_minmax
,
770 .strategy
= &sysctl_intvec
,
773 .ctl_name
= CTL_UNNUMBERED
,
774 .procname
= "hung_task_timeout_secs",
775 .data
= &sysctl_hung_task_timeout_secs
,
776 .maxlen
= sizeof(unsigned long),
778 .proc_handler
= &proc_doulongvec_minmax
,
779 .strategy
= &sysctl_intvec
,
782 .ctl_name
= CTL_UNNUMBERED
,
783 .procname
= "hung_task_warnings",
784 .data
= &sysctl_hung_task_warnings
,
785 .maxlen
= sizeof(unsigned long),
787 .proc_handler
= &proc_doulongvec_minmax
,
788 .strategy
= &sysctl_intvec
,
793 .ctl_name
= KERN_COMPAT_LOG
,
794 .procname
= "compat-log",
796 .maxlen
= sizeof (int),
798 .proc_handler
= &proc_dointvec
,
801 #ifdef CONFIG_RT_MUTEXES
803 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
804 .procname
= "max_lock_depth",
805 .data
= &max_lock_depth
,
806 .maxlen
= sizeof(int),
808 .proc_handler
= &proc_dointvec
,
811 #ifdef CONFIG_PROC_FS
813 .ctl_name
= CTL_UNNUMBERED
,
814 .procname
= "maps_protect",
815 .data
= &maps_protect
,
816 .maxlen
= sizeof(int),
818 .proc_handler
= &proc_dointvec
,
822 .ctl_name
= CTL_UNNUMBERED
,
823 .procname
= "poweroff_cmd",
824 .data
= &poweroff_cmd
,
825 .maxlen
= POWEROFF_CMD_PATH_LEN
,
827 .proc_handler
= &proc_dostring
,
828 .strategy
= &sysctl_string
,
832 .ctl_name
= CTL_UNNUMBERED
,
835 .child
= key_sysctls
,
838 #ifdef CONFIG_RCU_TORTURE_TEST
840 .ctl_name
= CTL_UNNUMBERED
,
841 .procname
= "rcutorture_runnable",
842 .data
= &rcutorture_runnable
,
843 .maxlen
= sizeof(int),
845 .proc_handler
= &proc_dointvec
,
849 * NOTE: do not add new entries to this table unless you have read
850 * Documentation/sysctl/ctl_unnumbered.txt
855 static struct ctl_table vm_table
[] = {
857 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
858 .procname
= "overcommit_memory",
859 .data
= &sysctl_overcommit_memory
,
860 .maxlen
= sizeof(sysctl_overcommit_memory
),
862 .proc_handler
= &proc_dointvec
,
865 .ctl_name
= VM_PANIC_ON_OOM
,
866 .procname
= "panic_on_oom",
867 .data
= &sysctl_panic_on_oom
,
868 .maxlen
= sizeof(sysctl_panic_on_oom
),
870 .proc_handler
= &proc_dointvec
,
873 .ctl_name
= CTL_UNNUMBERED
,
874 .procname
= "oom_kill_allocating_task",
875 .data
= &sysctl_oom_kill_allocating_task
,
876 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
878 .proc_handler
= &proc_dointvec
,
881 .ctl_name
= CTL_UNNUMBERED
,
882 .procname
= "oom_dump_tasks",
883 .data
= &sysctl_oom_dump_tasks
,
884 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
886 .proc_handler
= &proc_dointvec
,
889 .ctl_name
= VM_OVERCOMMIT_RATIO
,
890 .procname
= "overcommit_ratio",
891 .data
= &sysctl_overcommit_ratio
,
892 .maxlen
= sizeof(sysctl_overcommit_ratio
),
894 .proc_handler
= &proc_dointvec
,
897 .ctl_name
= VM_PAGE_CLUSTER
,
898 .procname
= "page-cluster",
899 .data
= &page_cluster
,
900 .maxlen
= sizeof(int),
902 .proc_handler
= &proc_dointvec
,
905 .ctl_name
= VM_DIRTY_BACKGROUND
,
906 .procname
= "dirty_background_ratio",
907 .data
= &dirty_background_ratio
,
908 .maxlen
= sizeof(dirty_background_ratio
),
910 .proc_handler
= &proc_dointvec_minmax
,
911 .strategy
= &sysctl_intvec
,
913 .extra2
= &one_hundred
,
916 .ctl_name
= VM_DIRTY_RATIO
,
917 .procname
= "dirty_ratio",
918 .data
= &vm_dirty_ratio
,
919 .maxlen
= sizeof(vm_dirty_ratio
),
921 .proc_handler
= &dirty_ratio_handler
,
922 .strategy
= &sysctl_intvec
,
924 .extra2
= &one_hundred
,
927 .procname
= "dirty_writeback_centisecs",
928 .data
= &dirty_writeback_interval
,
929 .maxlen
= sizeof(dirty_writeback_interval
),
931 .proc_handler
= &dirty_writeback_centisecs_handler
,
934 .procname
= "dirty_expire_centisecs",
935 .data
= &dirty_expire_interval
,
936 .maxlen
= sizeof(dirty_expire_interval
),
938 .proc_handler
= &proc_dointvec_userhz_jiffies
,
941 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
942 .procname
= "nr_pdflush_threads",
943 .data
= &nr_pdflush_threads
,
944 .maxlen
= sizeof nr_pdflush_threads
,
945 .mode
= 0444 /* read-only*/,
946 .proc_handler
= &proc_dointvec
,
949 .ctl_name
= VM_SWAPPINESS
,
950 .procname
= "swappiness",
951 .data
= &vm_swappiness
,
952 .maxlen
= sizeof(vm_swappiness
),
954 .proc_handler
= &proc_dointvec_minmax
,
955 .strategy
= &sysctl_intvec
,
957 .extra2
= &one_hundred
,
959 #ifdef CONFIG_HUGETLB_PAGE
961 .procname
= "nr_hugepages",
963 .maxlen
= sizeof(unsigned long),
965 .proc_handler
= &hugetlb_sysctl_handler
,
966 .extra1
= (void *)&hugetlb_zero
,
967 .extra2
= (void *)&hugetlb_infinity
,
970 .ctl_name
= VM_HUGETLB_GROUP
,
971 .procname
= "hugetlb_shm_group",
972 .data
= &sysctl_hugetlb_shm_group
,
973 .maxlen
= sizeof(gid_t
),
975 .proc_handler
= &proc_dointvec
,
978 .ctl_name
= CTL_UNNUMBERED
,
979 .procname
= "hugepages_treat_as_movable",
980 .data
= &hugepages_treat_as_movable
,
981 .maxlen
= sizeof(int),
983 .proc_handler
= &hugetlb_treat_movable_handler
,
986 .ctl_name
= CTL_UNNUMBERED
,
987 .procname
= "nr_overcommit_hugepages",
989 .maxlen
= sizeof(unsigned long),
991 .proc_handler
= &hugetlb_overcommit_handler
,
992 .extra1
= (void *)&hugetlb_zero
,
993 .extra2
= (void *)&hugetlb_infinity
,
997 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
998 .procname
= "lowmem_reserve_ratio",
999 .data
= &sysctl_lowmem_reserve_ratio
,
1000 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1002 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
1003 .strategy
= &sysctl_intvec
,
1006 .ctl_name
= VM_DROP_PAGECACHE
,
1007 .procname
= "drop_caches",
1008 .data
= &sysctl_drop_caches
,
1009 .maxlen
= sizeof(int),
1011 .proc_handler
= drop_caches_sysctl_handler
,
1012 .strategy
= &sysctl_intvec
,
1015 .ctl_name
= VM_MIN_FREE_KBYTES
,
1016 .procname
= "min_free_kbytes",
1017 .data
= &min_free_kbytes
,
1018 .maxlen
= sizeof(min_free_kbytes
),
1020 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1021 .strategy
= &sysctl_intvec
,
1025 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1026 .procname
= "percpu_pagelist_fraction",
1027 .data
= &percpu_pagelist_fraction
,
1028 .maxlen
= sizeof(percpu_pagelist_fraction
),
1030 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1031 .strategy
= &sysctl_intvec
,
1032 .extra1
= &min_percpu_pagelist_fract
,
1036 .ctl_name
= VM_MAX_MAP_COUNT
,
1037 .procname
= "max_map_count",
1038 .data
= &sysctl_max_map_count
,
1039 .maxlen
= sizeof(sysctl_max_map_count
),
1041 .proc_handler
= &proc_dointvec
1045 .ctl_name
= VM_LAPTOP_MODE
,
1046 .procname
= "laptop_mode",
1047 .data
= &laptop_mode
,
1048 .maxlen
= sizeof(laptop_mode
),
1050 .proc_handler
= &proc_dointvec_jiffies
,
1051 .strategy
= &sysctl_jiffies
,
1054 .ctl_name
= VM_BLOCK_DUMP
,
1055 .procname
= "block_dump",
1056 .data
= &block_dump
,
1057 .maxlen
= sizeof(block_dump
),
1059 .proc_handler
= &proc_dointvec
,
1060 .strategy
= &sysctl_intvec
,
1064 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1065 .procname
= "vfs_cache_pressure",
1066 .data
= &sysctl_vfs_cache_pressure
,
1067 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1069 .proc_handler
= &proc_dointvec
,
1070 .strategy
= &sysctl_intvec
,
1073 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1075 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1076 .procname
= "legacy_va_layout",
1077 .data
= &sysctl_legacy_va_layout
,
1078 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1080 .proc_handler
= &proc_dointvec
,
1081 .strategy
= &sysctl_intvec
,
1087 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1088 .procname
= "zone_reclaim_mode",
1089 .data
= &zone_reclaim_mode
,
1090 .maxlen
= sizeof(zone_reclaim_mode
),
1092 .proc_handler
= &proc_dointvec
,
1093 .strategy
= &sysctl_intvec
,
1097 .ctl_name
= VM_MIN_UNMAPPED
,
1098 .procname
= "min_unmapped_ratio",
1099 .data
= &sysctl_min_unmapped_ratio
,
1100 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1102 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1103 .strategy
= &sysctl_intvec
,
1105 .extra2
= &one_hundred
,
1108 .ctl_name
= VM_MIN_SLAB
,
1109 .procname
= "min_slab_ratio",
1110 .data
= &sysctl_min_slab_ratio
,
1111 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1113 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1114 .strategy
= &sysctl_intvec
,
1116 .extra2
= &one_hundred
,
1121 .ctl_name
= CTL_UNNUMBERED
,
1122 .procname
= "stat_interval",
1123 .data
= &sysctl_stat_interval
,
1124 .maxlen
= sizeof(sysctl_stat_interval
),
1126 .proc_handler
= &proc_dointvec_jiffies
,
1127 .strategy
= &sysctl_jiffies
,
1130 #ifdef CONFIG_SECURITY
1132 .ctl_name
= CTL_UNNUMBERED
,
1133 .procname
= "mmap_min_addr",
1134 .data
= &mmap_min_addr
,
1135 .maxlen
= sizeof(unsigned long),
1137 .proc_handler
= &proc_doulongvec_minmax
,
1142 .ctl_name
= CTL_UNNUMBERED
,
1143 .procname
= "numa_zonelist_order",
1144 .data
= &numa_zonelist_order
,
1145 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1147 .proc_handler
= &numa_zonelist_order_handler
,
1148 .strategy
= &sysctl_string
,
1151 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1152 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1154 .ctl_name
= VM_VDSO_ENABLED
,
1155 .procname
= "vdso_enabled",
1156 .data
= &vdso_enabled
,
1157 .maxlen
= sizeof(vdso_enabled
),
1159 .proc_handler
= &proc_dointvec
,
1160 .strategy
= &sysctl_intvec
,
1164 #ifdef CONFIG_HIGHMEM
1166 .ctl_name
= CTL_UNNUMBERED
,
1167 .procname
= "highmem_is_dirtyable",
1168 .data
= &vm_highmem_is_dirtyable
,
1169 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1171 .proc_handler
= &proc_dointvec_minmax
,
1172 .strategy
= &sysctl_intvec
,
1178 * NOTE: do not add new entries to this table unless you have read
1179 * Documentation/sysctl/ctl_unnumbered.txt
1184 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1185 static struct ctl_table binfmt_misc_table
[] = {
1190 static struct ctl_table fs_table
[] = {
1192 .ctl_name
= FS_NRINODE
,
1193 .procname
= "inode-nr",
1194 .data
= &inodes_stat
,
1195 .maxlen
= 2*sizeof(int),
1197 .proc_handler
= &proc_dointvec
,
1200 .ctl_name
= FS_STATINODE
,
1201 .procname
= "inode-state",
1202 .data
= &inodes_stat
,
1203 .maxlen
= 7*sizeof(int),
1205 .proc_handler
= &proc_dointvec
,
1208 .procname
= "file-nr",
1209 .data
= &files_stat
,
1210 .maxlen
= 3*sizeof(int),
1212 .proc_handler
= &proc_nr_files
,
1215 .ctl_name
= FS_MAXFILE
,
1216 .procname
= "file-max",
1217 .data
= &files_stat
.max_files
,
1218 .maxlen
= sizeof(int),
1220 .proc_handler
= &proc_dointvec
,
1223 .ctl_name
= CTL_UNNUMBERED
,
1224 .procname
= "nr_open",
1225 .data
= &sysctl_nr_open
,
1226 .maxlen
= sizeof(int),
1228 .proc_handler
= &proc_dointvec_minmax
,
1229 .extra1
= &sysctl_nr_open_min
,
1230 .extra2
= &sysctl_nr_open_max
,
1233 .ctl_name
= FS_DENTRY
,
1234 .procname
= "dentry-state",
1235 .data
= &dentry_stat
,
1236 .maxlen
= 6*sizeof(int),
1238 .proc_handler
= &proc_dointvec
,
1241 .ctl_name
= FS_OVERFLOWUID
,
1242 .procname
= "overflowuid",
1243 .data
= &fs_overflowuid
,
1244 .maxlen
= sizeof(int),
1246 .proc_handler
= &proc_dointvec_minmax
,
1247 .strategy
= &sysctl_intvec
,
1248 .extra1
= &minolduid
,
1249 .extra2
= &maxolduid
,
1252 .ctl_name
= FS_OVERFLOWGID
,
1253 .procname
= "overflowgid",
1254 .data
= &fs_overflowgid
,
1255 .maxlen
= sizeof(int),
1257 .proc_handler
= &proc_dointvec_minmax
,
1258 .strategy
= &sysctl_intvec
,
1259 .extra1
= &minolduid
,
1260 .extra2
= &maxolduid
,
1263 .ctl_name
= FS_LEASES
,
1264 .procname
= "leases-enable",
1265 .data
= &leases_enable
,
1266 .maxlen
= sizeof(int),
1268 .proc_handler
= &proc_dointvec
,
1270 #ifdef CONFIG_DNOTIFY
1272 .ctl_name
= FS_DIR_NOTIFY
,
1273 .procname
= "dir-notify-enable",
1274 .data
= &dir_notify_enable
,
1275 .maxlen
= sizeof(int),
1277 .proc_handler
= &proc_dointvec
,
1282 .ctl_name
= FS_LEASE_TIME
,
1283 .procname
= "lease-break-time",
1284 .data
= &lease_break_time
,
1285 .maxlen
= sizeof(int),
1287 .proc_handler
= &proc_dointvec_minmax
,
1288 .strategy
= &sysctl_intvec
,
1293 .procname
= "aio-nr",
1295 .maxlen
= sizeof(aio_nr
),
1297 .proc_handler
= &proc_doulongvec_minmax
,
1300 .procname
= "aio-max-nr",
1301 .data
= &aio_max_nr
,
1302 .maxlen
= sizeof(aio_max_nr
),
1304 .proc_handler
= &proc_doulongvec_minmax
,
1306 #ifdef CONFIG_INOTIFY_USER
1308 .ctl_name
= FS_INOTIFY
,
1309 .procname
= "inotify",
1311 .child
= inotify_table
,
1316 .ctl_name
= KERN_SETUID_DUMPABLE
,
1317 .procname
= "suid_dumpable",
1318 .data
= &suid_dumpable
,
1319 .maxlen
= sizeof(int),
1321 .proc_handler
= &proc_dointvec
,
1323 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1325 .ctl_name
= CTL_UNNUMBERED
,
1326 .procname
= "binfmt_misc",
1328 .child
= binfmt_misc_table
,
1332 * NOTE: do not add new entries to this table unless you have read
1333 * Documentation/sysctl/ctl_unnumbered.txt
1338 static struct ctl_table debug_table
[] = {
1339 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1341 .ctl_name
= CTL_UNNUMBERED
,
1342 .procname
= "exception-trace",
1343 .data
= &show_unhandled_signals
,
1344 .maxlen
= sizeof(int),
1346 .proc_handler
= proc_dointvec
1352 static struct ctl_table dev_table
[] = {
1356 static DEFINE_SPINLOCK(sysctl_lock
);
1358 /* called under sysctl_lock */
1359 static int use_table(struct ctl_table_header
*p
)
1361 if (unlikely(p
->unregistering
))
1367 /* called under sysctl_lock */
1368 static void unuse_table(struct ctl_table_header
*p
)
1371 if (unlikely(p
->unregistering
))
1372 complete(p
->unregistering
);
1375 /* called under sysctl_lock, will reacquire if has to wait */
1376 static void start_unregistering(struct ctl_table_header
*p
)
1379 * if p->used is 0, nobody will ever touch that entry again;
1380 * we'll eliminate all paths to it before dropping sysctl_lock
1382 if (unlikely(p
->used
)) {
1383 struct completion wait
;
1384 init_completion(&wait
);
1385 p
->unregistering
= &wait
;
1386 spin_unlock(&sysctl_lock
);
1387 wait_for_completion(&wait
);
1388 spin_lock(&sysctl_lock
);
1391 * do not remove from the list until nobody holds it; walking the
1392 * list in do_sysctl() relies on that.
1394 list_del_init(&p
->ctl_entry
);
1397 void sysctl_head_finish(struct ctl_table_header
*head
)
1401 spin_lock(&sysctl_lock
);
1403 spin_unlock(&sysctl_lock
);
1406 static struct list_head
*
1407 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1409 struct list_head
*header_list
;
1410 header_list
= &root
->header_list
;
1412 header_list
= root
->lookup(root
, namespaces
);
1416 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1417 struct ctl_table_header
*prev
)
1419 struct ctl_table_root
*root
;
1420 struct list_head
*header_list
;
1421 struct ctl_table_header
*head
;
1422 struct list_head
*tmp
;
1424 spin_lock(&sysctl_lock
);
1427 tmp
= &prev
->ctl_entry
;
1431 tmp
= &root_table_header
.ctl_entry
;
1433 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1435 if (!use_table(head
))
1437 spin_unlock(&sysctl_lock
);
1442 header_list
= lookup_header_list(root
, namespaces
);
1443 if (tmp
!= header_list
)
1447 root
= list_entry(root
->root_list
.next
,
1448 struct ctl_table_root
, root_list
);
1449 if (root
== &sysctl_table_root
)
1451 header_list
= lookup_header_list(root
, namespaces
);
1452 } while (list_empty(header_list
));
1453 tmp
= header_list
->next
;
1456 spin_unlock(&sysctl_lock
);
1460 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1462 return __sysctl_head_next(current
->nsproxy
, prev
);
1465 void register_sysctl_root(struct ctl_table_root
*root
)
1467 spin_lock(&sysctl_lock
);
1468 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1469 spin_unlock(&sysctl_lock
);
1472 #ifdef CONFIG_SYSCTL_SYSCALL
1473 /* Perform the actual read/write of a sysctl table entry. */
1474 static int do_sysctl_strategy(struct ctl_table_root
*root
,
1475 struct ctl_table
*table
,
1476 int __user
*name
, int nlen
,
1477 void __user
*oldval
, size_t __user
*oldlenp
,
1478 void __user
*newval
, size_t newlen
)
1486 if (sysctl_perm(root
, table
, op
))
1489 if (table
->strategy
) {
1490 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1498 /* If there is no strategy routine, or if the strategy returns
1499 * zero, proceed with automatic r/w */
1500 if (table
->data
&& table
->maxlen
) {
1501 rc
= sysctl_data(table
, name
, nlen
, oldval
, oldlenp
,
1509 static int parse_table(int __user
*name
, int nlen
,
1510 void __user
*oldval
, size_t __user
*oldlenp
,
1511 void __user
*newval
, size_t newlen
,
1512 struct ctl_table_root
*root
,
1513 struct ctl_table
*table
)
1519 if (get_user(n
, name
))
1521 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1522 if (!table
->ctl_name
)
1524 if (n
== table
->ctl_name
) {
1527 if (sysctl_perm(root
, table
, 001))
1531 table
= table
->child
;
1534 error
= do_sysctl_strategy(root
, table
, name
, nlen
,
1543 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1544 void __user
*newval
, size_t newlen
)
1546 struct ctl_table_header
*head
;
1547 int error
= -ENOTDIR
;
1549 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1553 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1557 for (head
= sysctl_head_next(NULL
); head
;
1558 head
= sysctl_head_next(head
)) {
1559 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1561 head
->root
, head
->ctl_table
);
1562 if (error
!= -ENOTDIR
) {
1563 sysctl_head_finish(head
);
1570 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1572 struct __sysctl_args tmp
;
1575 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1578 error
= deprecated_sysctl_warning(&tmp
);
1583 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1584 tmp
.newval
, tmp
.newlen
);
1589 #endif /* CONFIG_SYSCTL_SYSCALL */
1592 * sysctl_perm does NOT grant the superuser all rights automatically, because
1593 * some sysctl variables are readonly even to root.
1596 static int test_perm(int mode
, int op
)
1600 else if (in_egroup_p(0))
1602 if ((mode
& op
& 0007) == op
)
1607 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1612 error
= security_sysctl(table
, op
);
1616 if (root
->permissions
)
1617 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1621 return test_perm(mode
, op
);
1624 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1626 for (; table
->ctl_name
|| table
->procname
; table
++) {
1627 table
->parent
= parent
;
1629 sysctl_set_parent(table
, table
->child
);
1633 static __init
int sysctl_init(void)
1635 sysctl_set_parent(NULL
, root_table
);
1636 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1639 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1645 core_initcall(sysctl_init
);
1648 * __register_sysctl_paths - register a sysctl hierarchy
1649 * @root: List of sysctl headers to register on
1650 * @namespaces: Data to compute which lists of sysctl entries are visible
1651 * @path: The path to the directory the sysctl table is in.
1652 * @table: the top-level table structure
1654 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1655 * array. A completely 0 filled entry terminates the table.
1657 * The members of the &struct ctl_table structure are used as follows:
1659 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1660 * must be unique within that level of sysctl
1662 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1663 * enter a sysctl file
1665 * data - a pointer to data for use by proc_handler
1667 * maxlen - the maximum size in bytes of the data
1669 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1671 * child - a pointer to the child sysctl table if this entry is a directory, or
1674 * proc_handler - the text handler routine (described below)
1676 * strategy - the strategy routine (described below)
1678 * de - for internal use by the sysctl routines
1680 * extra1, extra2 - extra pointers usable by the proc handler routines
1682 * Leaf nodes in the sysctl tree will be represented by a single file
1683 * under /proc; non-leaf nodes will be represented by directories.
1685 * sysctl(2) can automatically manage read and write requests through
1686 * the sysctl table. The data and maxlen fields of the ctl_table
1687 * struct enable minimal validation of the values being written to be
1688 * performed, and the mode field allows minimal authentication.
1690 * More sophisticated management can be enabled by the provision of a
1691 * strategy routine with the table entry. This will be called before
1692 * any automatic read or write of the data is performed.
1694 * The strategy routine may return
1696 * < 0 - Error occurred (error is passed to user process)
1698 * 0 - OK - proceed with automatic read or write.
1700 * > 0 - OK - read or write has been done by the strategy routine, so
1701 * return immediately.
1703 * There must be a proc_handler routine for any terminal nodes
1704 * mirrored under /proc/sys (non-terminals are handled by a built-in
1705 * directory handler). Several default handlers are available to
1706 * cover common cases -
1708 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1709 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1710 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1712 * It is the handler's job to read the input buffer from user memory
1713 * and process it. The handler should return 0 on success.
1715 * This routine returns %NULL on a failure to register, and a pointer
1716 * to the table header on success.
1718 struct ctl_table_header
*__register_sysctl_paths(
1719 struct ctl_table_root
*root
,
1720 struct nsproxy
*namespaces
,
1721 const struct ctl_path
*path
, struct ctl_table
*table
)
1723 struct list_head
*header_list
;
1724 struct ctl_table_header
*header
;
1725 struct ctl_table
*new, **prevp
;
1726 unsigned int n
, npath
;
1728 /* Count the path components */
1729 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
1733 * For each path component, allocate a 2-element ctl_table array.
1734 * The first array element will be filled with the sysctl entry
1735 * for this, the second will be the sentinel (ctl_name == 0).
1737 * We allocate everything in one go so that we don't have to
1738 * worry about freeing additional memory in unregister_sysctl_table.
1740 header
= kzalloc(sizeof(struct ctl_table_header
) +
1741 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1745 new = (struct ctl_table
*) (header
+ 1);
1747 /* Now connect the dots */
1748 prevp
= &header
->ctl_table
;
1749 for (n
= 0; n
< npath
; ++n
, ++path
) {
1750 /* Copy the procname */
1751 new->procname
= path
->procname
;
1752 new->ctl_name
= path
->ctl_name
;
1756 prevp
= &new->child
;
1761 header
->ctl_table_arg
= table
;
1763 INIT_LIST_HEAD(&header
->ctl_entry
);
1765 header
->unregistering
= NULL
;
1766 header
->root
= root
;
1767 sysctl_set_parent(NULL
, header
->ctl_table
);
1768 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1769 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1774 spin_lock(&sysctl_lock
);
1775 header_list
= lookup_header_list(root
, namespaces
);
1776 list_add_tail(&header
->ctl_entry
, header_list
);
1777 spin_unlock(&sysctl_lock
);
1783 * register_sysctl_table_path - register a sysctl table hierarchy
1784 * @path: The path to the directory the sysctl table is in.
1785 * @table: the top-level table structure
1787 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1788 * array. A completely 0 filled entry terminates the table.
1790 * See __register_sysctl_paths for more details.
1792 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1793 struct ctl_table
*table
)
1795 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1800 * register_sysctl_table - register a sysctl table hierarchy
1801 * @table: the top-level table structure
1803 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1804 * array. A completely 0 filled entry terminates the table.
1806 * See register_sysctl_paths for more details.
1808 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1810 static const struct ctl_path null_path
[] = { {} };
1812 return register_sysctl_paths(null_path
, table
);
1816 * unregister_sysctl_table - unregister a sysctl table hierarchy
1817 * @header: the header returned from register_sysctl_table
1819 * Unregisters the sysctl table and all children. proc entries may not
1820 * actually be removed until they are no longer used by anyone.
1822 void unregister_sysctl_table(struct ctl_table_header
* header
)
1829 spin_lock(&sysctl_lock
);
1830 start_unregistering(header
);
1831 spin_unlock(&sysctl_lock
);
1835 #else /* !CONFIG_SYSCTL */
1836 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1841 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1842 struct ctl_table
*table
)
1847 void unregister_sysctl_table(struct ctl_table_header
* table
)
1851 #endif /* CONFIG_SYSCTL */
1857 #ifdef CONFIG_PROC_SYSCTL
1859 static int _proc_do_string(void* data
, int maxlen
, int write
,
1860 struct file
*filp
, void __user
*buffer
,
1861 size_t *lenp
, loff_t
*ppos
)
1867 if (!data
|| !maxlen
|| !*lenp
) {
1875 while (len
< *lenp
) {
1876 if (get_user(c
, p
++))
1878 if (c
== 0 || c
== '\n')
1884 if(copy_from_user(data
, buffer
, len
))
1886 ((char *) data
)[len
] = 0;
1904 if(copy_to_user(buffer
, data
, len
))
1907 if(put_user('\n', ((char __user
*) buffer
) + len
))
1918 * proc_dostring - read a string sysctl
1919 * @table: the sysctl table
1920 * @write: %TRUE if this is a write to the sysctl file
1921 * @filp: the file structure
1922 * @buffer: the user buffer
1923 * @lenp: the size of the user buffer
1924 * @ppos: file position
1926 * Reads/writes a string from/to the user buffer. If the kernel
1927 * buffer provided is not large enough to hold the string, the
1928 * string is truncated. The copied string is %NULL-terminated.
1929 * If the string is being read by the user process, it is copied
1930 * and a newline '\n' is added. It is truncated if the buffer is
1933 * Returns 0 on success.
1935 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
1936 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1938 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
1939 buffer
, lenp
, ppos
);
1943 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1945 int write
, void *data
)
1948 *valp
= *negp
? -*lvalp
: *lvalp
;
1953 *lvalp
= (unsigned long)-val
;
1956 *lvalp
= (unsigned long)val
;
1962 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1963 int write
, struct file
*filp
, void __user
*buffer
,
1964 size_t *lenp
, loff_t
*ppos
,
1965 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1966 int write
, void *data
),
1969 #define TMPBUFLEN 21
1970 int *i
, vleft
, first
=1, neg
, val
;
1974 char buf
[TMPBUFLEN
], *p
;
1975 char __user
*s
= buffer
;
1977 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
1978 (*ppos
&& !write
)) {
1983 i
= (int *) tbl_data
;
1984 vleft
= table
->maxlen
/ sizeof(*i
);
1988 conv
= do_proc_dointvec_conv
;
1990 for (; left
&& vleft
--; i
++, first
=0) {
2005 if (len
> sizeof(buf
) - 1)
2006 len
= sizeof(buf
) - 1;
2007 if (copy_from_user(buf
, s
, len
))
2011 if (*p
== '-' && left
> 1) {
2015 if (*p
< '0' || *p
> '9')
2018 lval
= simple_strtoul(p
, &p
, 0);
2021 if ((len
< left
) && *p
&& !isspace(*p
))
2028 if (conv(&neg
, &lval
, i
, 1, data
))
2035 if (conv(&neg
, &lval
, i
, 0, data
))
2038 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2042 if(copy_to_user(s
, buf
, len
))
2049 if (!write
&& !first
&& left
) {
2050 if(put_user('\n', s
))
2057 if (get_user(c
, s
++))
2072 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2073 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2074 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2075 int write
, void *data
),
2078 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2079 buffer
, lenp
, ppos
, conv
, data
);
2083 * proc_dointvec - read a vector of integers
2084 * @table: the sysctl table
2085 * @write: %TRUE if this is a write to the sysctl file
2086 * @filp: the file structure
2087 * @buffer: the user buffer
2088 * @lenp: the size of the user buffer
2089 * @ppos: file position
2091 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2092 * values from/to the user buffer, treated as an ASCII string.
2094 * Returns 0 on success.
2096 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2097 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2099 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2107 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
2109 int write
, void *data
)
2111 int op
= *(int *)data
;
2113 int val
= *negp
? -*lvalp
: *lvalp
;
2115 case OP_SET
: *valp
= val
; break;
2116 case OP_AND
: *valp
&= val
; break;
2117 case OP_OR
: *valp
|= val
; break;
2123 *lvalp
= (unsigned long)-val
;
2126 *lvalp
= (unsigned long)val
;
2133 * Taint values can only be increased
2135 static int proc_dointvec_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2136 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2140 if (write
&& !capable(CAP_SYS_ADMIN
))
2144 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2145 do_proc_dointvec_bset_conv
,&op
);
2148 struct do_proc_dointvec_minmax_conv_param
{
2153 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2155 int write
, void *data
)
2157 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2159 int val
= *negp
? -*lvalp
: *lvalp
;
2160 if ((param
->min
&& *param
->min
> val
) ||
2161 (param
->max
&& *param
->max
< val
))
2168 *lvalp
= (unsigned long)-val
;
2171 *lvalp
= (unsigned long)val
;
2178 * proc_dointvec_minmax - read a vector of integers with min/max values
2179 * @table: the sysctl table
2180 * @write: %TRUE if this is a write to the sysctl file
2181 * @filp: the file structure
2182 * @buffer: the user buffer
2183 * @lenp: the size of the user buffer
2184 * @ppos: file position
2186 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2187 * values from/to the user buffer, treated as an ASCII string.
2189 * This routine will ensure the values are within the range specified by
2190 * table->extra1 (min) and table->extra2 (max).
2192 * Returns 0 on success.
2194 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2195 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2197 struct do_proc_dointvec_minmax_conv_param param
= {
2198 .min
= (int *) table
->extra1
,
2199 .max
= (int *) table
->extra2
,
2201 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2202 do_proc_dointvec_minmax_conv
, ¶m
);
2205 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2207 void __user
*buffer
,
2208 size_t *lenp
, loff_t
*ppos
,
2209 unsigned long convmul
,
2210 unsigned long convdiv
)
2212 #define TMPBUFLEN 21
2213 unsigned long *i
, *min
, *max
, val
;
2214 int vleft
, first
=1, neg
;
2216 char buf
[TMPBUFLEN
], *p
;
2217 char __user
*s
= buffer
;
2219 if (!data
|| !table
->maxlen
|| !*lenp
||
2220 (*ppos
&& !write
)) {
2225 i
= (unsigned long *) data
;
2226 min
= (unsigned long *) table
->extra1
;
2227 max
= (unsigned long *) table
->extra2
;
2228 vleft
= table
->maxlen
/ sizeof(unsigned long);
2231 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2246 if (len
> TMPBUFLEN
-1)
2248 if (copy_from_user(buf
, s
, len
))
2252 if (*p
== '-' && left
> 1) {
2256 if (*p
< '0' || *p
> '9')
2258 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2260 if ((len
< left
) && *p
&& !isspace(*p
))
2269 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2276 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2280 if(copy_to_user(s
, buf
, len
))
2287 if (!write
&& !first
&& left
) {
2288 if(put_user('\n', s
))
2295 if (get_user(c
, s
++))
2310 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2312 void __user
*buffer
,
2313 size_t *lenp
, loff_t
*ppos
,
2314 unsigned long convmul
,
2315 unsigned long convdiv
)
2317 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2318 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2322 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2323 * @table: the sysctl table
2324 * @write: %TRUE if this is a write to the sysctl file
2325 * @filp: the file structure
2326 * @buffer: the user buffer
2327 * @lenp: the size of the user buffer
2328 * @ppos: file position
2330 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2331 * values from/to the user buffer, treated as an ASCII string.
2333 * This routine will ensure the values are within the range specified by
2334 * table->extra1 (min) and table->extra2 (max).
2336 * Returns 0 on success.
2338 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2339 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2341 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2345 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2346 * @table: the sysctl table
2347 * @write: %TRUE if this is a write to the sysctl file
2348 * @filp: the file structure
2349 * @buffer: the user buffer
2350 * @lenp: the size of the user buffer
2351 * @ppos: file position
2353 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2354 * values from/to the user buffer, treated as an ASCII string. The values
2355 * are treated as milliseconds, and converted to jiffies when they are stored.
2357 * This routine will ensure the values are within the range specified by
2358 * table->extra1 (min) and table->extra2 (max).
2360 * Returns 0 on success.
2362 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2364 void __user
*buffer
,
2365 size_t *lenp
, loff_t
*ppos
)
2367 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2368 lenp
, ppos
, HZ
, 1000l);
2372 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2374 int write
, void *data
)
2377 if (*lvalp
> LONG_MAX
/ HZ
)
2379 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2385 lval
= (unsigned long)-val
;
2388 lval
= (unsigned long)val
;
2395 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2397 int write
, void *data
)
2400 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2402 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2408 lval
= (unsigned long)-val
;
2411 lval
= (unsigned long)val
;
2413 *lvalp
= jiffies_to_clock_t(lval
);
2418 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2420 int write
, void *data
)
2423 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2429 lval
= (unsigned long)-val
;
2432 lval
= (unsigned long)val
;
2434 *lvalp
= jiffies_to_msecs(lval
);
2440 * proc_dointvec_jiffies - read a vector of integers as seconds
2441 * @table: the sysctl table
2442 * @write: %TRUE if this is a write to the sysctl file
2443 * @filp: the file structure
2444 * @buffer: the user buffer
2445 * @lenp: the size of the user buffer
2446 * @ppos: file position
2448 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2449 * values from/to the user buffer, treated as an ASCII string.
2450 * The values read are assumed to be in seconds, and are converted into
2453 * Returns 0 on success.
2455 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2456 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2458 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2459 do_proc_dointvec_jiffies_conv
,NULL
);
2463 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2464 * @table: the sysctl table
2465 * @write: %TRUE if this is a write to the sysctl file
2466 * @filp: the file structure
2467 * @buffer: the user buffer
2468 * @lenp: the size of the user buffer
2469 * @ppos: pointer to the file position
2471 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2472 * values from/to the user buffer, treated as an ASCII string.
2473 * The values read are assumed to be in 1/USER_HZ seconds, and
2474 * are converted into jiffies.
2476 * Returns 0 on success.
2478 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2479 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2481 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2482 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2486 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2487 * @table: the sysctl table
2488 * @write: %TRUE if this is a write to the sysctl file
2489 * @filp: the file structure
2490 * @buffer: the user buffer
2491 * @lenp: the size of the user buffer
2492 * @ppos: file position
2493 * @ppos: the current position in the file
2495 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2496 * values from/to the user buffer, treated as an ASCII string.
2497 * The values read are assumed to be in 1/1000 seconds, and
2498 * are converted into jiffies.
2500 * Returns 0 on success.
2502 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2503 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2505 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2506 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2509 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2510 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2512 struct pid
*new_pid
;
2516 tmp
= pid_vnr(cad_pid
);
2518 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2519 lenp
, ppos
, NULL
, NULL
);
2523 new_pid
= find_get_pid(tmp
);
2527 put_pid(xchg(&cad_pid
, new_pid
));
2531 #else /* CONFIG_PROC_FS */
2533 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2534 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2539 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2540 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2545 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2546 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2551 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2552 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2557 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2558 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2563 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2564 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2569 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2570 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2575 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2577 void __user
*buffer
,
2578 size_t *lenp
, loff_t
*ppos
)
2584 #endif /* CONFIG_PROC_FS */
2587 #ifdef CONFIG_SYSCTL_SYSCALL
2589 * General sysctl support routines
2592 /* The generic sysctl data routine (used if no strategy routine supplied) */
2593 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2594 void __user
*oldval
, size_t __user
*oldlenp
,
2595 void __user
*newval
, size_t newlen
)
2599 /* Get out of I don't have a variable */
2600 if (!table
->data
|| !table
->maxlen
)
2603 if (oldval
&& oldlenp
) {
2604 if (get_user(len
, oldlenp
))
2607 if (len
> table
->maxlen
)
2608 len
= table
->maxlen
;
2609 if (copy_to_user(oldval
, table
->data
, len
))
2611 if (put_user(len
, oldlenp
))
2616 if (newval
&& newlen
) {
2617 if (newlen
> table
->maxlen
)
2618 newlen
= table
->maxlen
;
2620 if (copy_from_user(table
->data
, newval
, newlen
))
2626 /* The generic string strategy routine: */
2627 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2628 void __user
*oldval
, size_t __user
*oldlenp
,
2629 void __user
*newval
, size_t newlen
)
2631 if (!table
->data
|| !table
->maxlen
)
2634 if (oldval
&& oldlenp
) {
2636 if (get_user(bufsize
, oldlenp
))
2639 size_t len
= strlen(table
->data
), copied
;
2641 /* This shouldn't trigger for a well-formed sysctl */
2642 if (len
> table
->maxlen
)
2643 len
= table
->maxlen
;
2645 /* Copy up to a max of bufsize-1 bytes of the string */
2646 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2648 if (copy_to_user(oldval
, table
->data
, copied
) ||
2649 put_user(0, (char __user
*)(oldval
+ copied
)))
2651 if (put_user(len
, oldlenp
))
2655 if (newval
&& newlen
) {
2656 size_t len
= newlen
;
2657 if (len
> table
->maxlen
)
2658 len
= table
->maxlen
;
2659 if(copy_from_user(table
->data
, newval
, len
))
2661 if (len
== table
->maxlen
)
2663 ((char *) table
->data
)[len
] = 0;
2669 * This function makes sure that all of the integers in the vector
2670 * are between the minimum and maximum values given in the arrays
2671 * table->extra1 and table->extra2, respectively.
2673 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2674 void __user
*oldval
, size_t __user
*oldlenp
,
2675 void __user
*newval
, size_t newlen
)
2678 if (newval
&& newlen
) {
2679 int __user
*vec
= (int __user
*) newval
;
2680 int *min
= (int *) table
->extra1
;
2681 int *max
= (int *) table
->extra2
;
2685 if (newlen
% sizeof(int) != 0)
2688 if (!table
->extra1
&& !table
->extra2
)
2691 if (newlen
> table
->maxlen
)
2692 newlen
= table
->maxlen
;
2693 length
= newlen
/ sizeof(int);
2695 for (i
= 0; i
< length
; i
++) {
2697 if (get_user(value
, vec
+ i
))
2699 if (min
&& value
< min
[i
])
2701 if (max
&& value
> max
[i
])
2708 /* Strategy function to convert jiffies to seconds */
2709 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2710 void __user
*oldval
, size_t __user
*oldlenp
,
2711 void __user
*newval
, size_t newlen
)
2713 if (oldval
&& oldlenp
) {
2716 if (get_user(olen
, oldlenp
))
2721 if (olen
< sizeof(int))
2724 val
= *(int *)(table
->data
) / HZ
;
2725 if (put_user(val
, (int __user
*)oldval
))
2727 if (put_user(sizeof(int), oldlenp
))
2731 if (newval
&& newlen
) {
2733 if (newlen
!= sizeof(int))
2735 if (get_user(new, (int __user
*)newval
))
2737 *(int *)(table
->data
) = new*HZ
;
2742 /* Strategy function to convert jiffies to seconds */
2743 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2744 void __user
*oldval
, size_t __user
*oldlenp
,
2745 void __user
*newval
, size_t newlen
)
2747 if (oldval
&& oldlenp
) {
2750 if (get_user(olen
, oldlenp
))
2755 if (olen
< sizeof(int))
2758 val
= jiffies_to_msecs(*(int *)(table
->data
));
2759 if (put_user(val
, (int __user
*)oldval
))
2761 if (put_user(sizeof(int), oldlenp
))
2765 if (newval
&& newlen
) {
2767 if (newlen
!= sizeof(int))
2769 if (get_user(new, (int __user
*)newval
))
2771 *(int *)(table
->data
) = msecs_to_jiffies(new);
2778 #else /* CONFIG_SYSCTL_SYSCALL */
2781 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2783 struct __sysctl_args tmp
;
2786 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
2789 error
= deprecated_sysctl_warning(&tmp
);
2791 /* If no error reading the parameters then just -ENOSYS ... */
2798 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2799 void __user
*oldval
, size_t __user
*oldlenp
,
2800 void __user
*newval
, size_t newlen
)
2805 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2806 void __user
*oldval
, size_t __user
*oldlenp
,
2807 void __user
*newval
, size_t newlen
)
2812 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2813 void __user
*oldval
, size_t __user
*oldlenp
,
2814 void __user
*newval
, size_t newlen
)
2819 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2820 void __user
*oldval
, size_t __user
*oldlenp
,
2821 void __user
*newval
, size_t newlen
)
2826 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2827 void __user
*oldval
, size_t __user
*oldlenp
,
2828 void __user
*newval
, size_t newlen
)
2833 #endif /* CONFIG_SYSCTL_SYSCALL */
2835 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
2837 static int msg_count
;
2838 int name
[CTL_MAXNAME
];
2841 /* Check args->nlen. */
2842 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
2845 /* Read in the sysctl name for better debug message logging */
2846 for (i
= 0; i
< args
->nlen
; i
++)
2847 if (get_user(name
[i
], args
->name
+ i
))
2850 /* Ignore accesses to kernel.version */
2851 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
2854 if (msg_count
< 5) {
2857 "warning: process `%s' used the deprecated sysctl "
2858 "system call with ", current
->comm
);
2859 for (i
= 0; i
< args
->nlen
; i
++)
2860 printk("%d.", name
[i
]);
2867 * No sense putting this after each symbol definition, twice,
2868 * exception granted :-)
2870 EXPORT_SYMBOL(proc_dointvec
);
2871 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2872 EXPORT_SYMBOL(proc_dointvec_minmax
);
2873 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2874 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2875 EXPORT_SYMBOL(proc_dostring
);
2876 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2877 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2878 EXPORT_SYMBOL(register_sysctl_table
);
2879 EXPORT_SYMBOL(register_sysctl_paths
);
2880 EXPORT_SYMBOL(sysctl_intvec
);
2881 EXPORT_SYMBOL(sysctl_jiffies
);
2882 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2883 EXPORT_SYMBOL(sysctl_string
);
2884 EXPORT_SYMBOL(sysctl_data
);
2885 EXPORT_SYMBOL(unregister_sysctl_table
);