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/security.h>
41 #include <linux/initrd.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/nfs_fs.h>
47 #include <linux/acpi.h>
48 #include <linux/reboot.h>
50 #include <asm/uaccess.h>
51 #include <asm/processor.h>
55 #include <asm/stacktrace.h>
59 static int deprecated_sysctl_warning(struct __sysctl_args
*args
);
61 #if defined(CONFIG_SYSCTL)
63 /* External variables not in a header file. */
65 extern int print_fatal_signals
;
66 extern int sysctl_overcommit_memory
;
67 extern int sysctl_overcommit_ratio
;
68 extern int sysctl_panic_on_oom
;
69 extern int sysctl_oom_kill_allocating_task
;
70 extern int sysctl_oom_dump_tasks
;
71 extern int max_threads
;
72 extern int core_uses_pid
;
73 extern int suid_dumpable
;
74 extern char core_pattern
[];
76 extern int min_free_kbytes
;
77 extern int printk_ratelimit_jiffies
;
78 extern int printk_ratelimit_burst
;
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 sysctl_stat_interval
;
85 extern int latencytop_enabled
;
87 /* Constants used for minimum and maximum */
88 #if defined(CONFIG_DETECT_SOFTLOCKUP) || defined(CONFIG_HIGHMEM)
92 #ifdef CONFIG_DETECT_SOFTLOCKUP
93 static int sixty
= 60;
101 static int one_hundred
= 100;
103 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
104 static int maxolduid
= 65535;
105 static int minolduid
;
106 static int min_percpu_pagelist_fract
= 8;
108 static int ngroups_max
= NGROUPS_MAX
;
111 extern char modprobe_path
[];
113 #ifdef CONFIG_CHR_DEV_SG
114 extern int sg_big_buff
;
118 extern char reboot_command
[];
119 extern int stop_a_enabled
;
120 extern int scons_pwroff
;
124 extern int pwrsw_enabled
;
125 extern int unaligned_enabled
;
129 #ifdef CONFIG_MATHEMU
130 extern int sysctl_ieee_emulation_warnings
;
132 extern int sysctl_userprocess_debug
;
133 extern int spin_retry
;
136 extern int sysctl_hz_timer
;
138 #ifdef CONFIG_BSD_PROCESS_ACCT
139 extern int acct_parm
[];
143 extern int no_unaligned_warning
;
146 #ifdef CONFIG_RT_MUTEXES
147 extern int max_lock_depth
;
150 #ifdef CONFIG_SYSCTL_SYSCALL
151 static int parse_table(int __user
*, int, void __user
*, size_t __user
*,
152 void __user
*, size_t, struct ctl_table
*);
156 #ifdef CONFIG_PROC_SYSCTL
157 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
158 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
159 static int proc_dointvec_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
160 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
163 static struct ctl_table root_table
[];
164 static struct ctl_table_root sysctl_table_root
;
165 static struct ctl_table_header root_table_header
= {
166 .ctl_table
= root_table
,
167 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.header_list
),
168 .root
= &sysctl_table_root
,
170 static struct ctl_table_root sysctl_table_root
= {
171 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
172 .header_list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
175 static struct ctl_table kern_table
[];
176 static struct ctl_table vm_table
[];
177 static struct ctl_table fs_table
[];
178 static struct ctl_table debug_table
[];
179 static struct ctl_table dev_table
[];
180 extern struct ctl_table random_table
[];
181 #ifdef CONFIG_INOTIFY_USER
182 extern struct ctl_table inotify_table
[];
185 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
186 int sysctl_legacy_va_layout
;
189 extern int prove_locking
;
190 extern int lock_stat
;
192 /* The default sysctl tables: */
194 static struct ctl_table root_table
[] = {
196 .ctl_name
= CTL_KERN
,
197 .procname
= "kernel",
214 .ctl_name
= CTL_DEBUG
,
217 .child
= debug_table
,
226 * NOTE: do not add new entries to this table unless you have read
227 * Documentation/sysctl/ctl_unnumbered.txt
232 #ifdef CONFIG_SCHED_DEBUG
233 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
234 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
235 static int min_wakeup_granularity_ns
; /* 0 usecs */
236 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
239 static struct ctl_table kern_table
[] = {
240 #ifdef CONFIG_SCHED_DEBUG
242 .ctl_name
= CTL_UNNUMBERED
,
243 .procname
= "sched_min_granularity_ns",
244 .data
= &sysctl_sched_min_granularity
,
245 .maxlen
= sizeof(unsigned int),
247 .proc_handler
= &sched_nr_latency_handler
,
248 .strategy
= &sysctl_intvec
,
249 .extra1
= &min_sched_granularity_ns
,
250 .extra2
= &max_sched_granularity_ns
,
253 .ctl_name
= CTL_UNNUMBERED
,
254 .procname
= "sched_latency_ns",
255 .data
= &sysctl_sched_latency
,
256 .maxlen
= sizeof(unsigned int),
258 .proc_handler
= &sched_nr_latency_handler
,
259 .strategy
= &sysctl_intvec
,
260 .extra1
= &min_sched_granularity_ns
,
261 .extra2
= &max_sched_granularity_ns
,
264 .ctl_name
= CTL_UNNUMBERED
,
265 .procname
= "sched_wakeup_granularity_ns",
266 .data
= &sysctl_sched_wakeup_granularity
,
267 .maxlen
= sizeof(unsigned int),
269 .proc_handler
= &proc_dointvec_minmax
,
270 .strategy
= &sysctl_intvec
,
271 .extra1
= &min_wakeup_granularity_ns
,
272 .extra2
= &max_wakeup_granularity_ns
,
275 .ctl_name
= CTL_UNNUMBERED
,
276 .procname
= "sched_batch_wakeup_granularity_ns",
277 .data
= &sysctl_sched_batch_wakeup_granularity
,
278 .maxlen
= sizeof(unsigned int),
280 .proc_handler
= &proc_dointvec_minmax
,
281 .strategy
= &sysctl_intvec
,
282 .extra1
= &min_wakeup_granularity_ns
,
283 .extra2
= &max_wakeup_granularity_ns
,
286 .ctl_name
= CTL_UNNUMBERED
,
287 .procname
= "sched_child_runs_first",
288 .data
= &sysctl_sched_child_runs_first
,
289 .maxlen
= sizeof(unsigned int),
291 .proc_handler
= &proc_dointvec
,
294 .ctl_name
= CTL_UNNUMBERED
,
295 .procname
= "sched_features",
296 .data
= &sysctl_sched_features
,
297 .maxlen
= sizeof(unsigned int),
299 .proc_handler
= &proc_dointvec
,
302 .ctl_name
= CTL_UNNUMBERED
,
303 .procname
= "sched_migration_cost",
304 .data
= &sysctl_sched_migration_cost
,
305 .maxlen
= sizeof(unsigned int),
307 .proc_handler
= &proc_dointvec
,
310 .ctl_name
= CTL_UNNUMBERED
,
311 .procname
= "sched_nr_migrate",
312 .data
= &sysctl_sched_nr_migrate
,
313 .maxlen
= sizeof(unsigned int),
315 .proc_handler
= &proc_dointvec
,
318 .ctl_name
= CTL_UNNUMBERED
,
319 .procname
= "sched_rt_period_ms",
320 .data
= &sysctl_sched_rt_period
,
321 .maxlen
= sizeof(unsigned int),
323 .proc_handler
= &proc_dointvec
,
326 .ctl_name
= CTL_UNNUMBERED
,
327 .procname
= "sched_rt_ratio",
328 .data
= &sysctl_sched_rt_ratio
,
329 .maxlen
= sizeof(unsigned int),
331 .proc_handler
= &proc_dointvec
,
333 #if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_SMP)
335 .ctl_name
= CTL_UNNUMBERED
,
336 .procname
= "sched_min_bal_int_shares",
337 .data
= &sysctl_sched_min_bal_int_shares
,
338 .maxlen
= sizeof(unsigned int),
340 .proc_handler
= &proc_dointvec
,
343 .ctl_name
= CTL_UNNUMBERED
,
344 .procname
= "sched_max_bal_int_shares",
345 .data
= &sysctl_sched_max_bal_int_shares
,
346 .maxlen
= sizeof(unsigned int),
348 .proc_handler
= &proc_dointvec
,
353 .ctl_name
= CTL_UNNUMBERED
,
354 .procname
= "sched_compat_yield",
355 .data
= &sysctl_sched_compat_yield
,
356 .maxlen
= sizeof(unsigned int),
358 .proc_handler
= &proc_dointvec
,
360 #ifdef CONFIG_PROVE_LOCKING
362 .ctl_name
= CTL_UNNUMBERED
,
363 .procname
= "prove_locking",
364 .data
= &prove_locking
,
365 .maxlen
= sizeof(int),
367 .proc_handler
= &proc_dointvec
,
370 #ifdef CONFIG_LOCK_STAT
372 .ctl_name
= CTL_UNNUMBERED
,
373 .procname
= "lock_stat",
375 .maxlen
= sizeof(int),
377 .proc_handler
= &proc_dointvec
,
381 .ctl_name
= KERN_PANIC
,
383 .data
= &panic_timeout
,
384 .maxlen
= sizeof(int),
386 .proc_handler
= &proc_dointvec
,
389 .ctl_name
= KERN_CORE_USES_PID
,
390 .procname
= "core_uses_pid",
391 .data
= &core_uses_pid
,
392 .maxlen
= sizeof(int),
394 .proc_handler
= &proc_dointvec
,
397 .ctl_name
= KERN_CORE_PATTERN
,
398 .procname
= "core_pattern",
399 .data
= core_pattern
,
400 .maxlen
= CORENAME_MAX_SIZE
,
402 .proc_handler
= &proc_dostring
,
403 .strategy
= &sysctl_string
,
405 #ifdef CONFIG_PROC_SYSCTL
407 .procname
= "tainted",
409 .maxlen
= sizeof(int),
411 .proc_handler
= &proc_dointvec_taint
,
414 #ifdef CONFIG_LATENCYTOP
416 .procname
= "latencytop",
417 .data
= &latencytop_enabled
,
418 .maxlen
= sizeof(int),
420 .proc_handler
= &proc_dointvec
,
423 #ifdef CONFIG_BLK_DEV_INITRD
425 .ctl_name
= KERN_REALROOTDEV
,
426 .procname
= "real-root-dev",
427 .data
= &real_root_dev
,
428 .maxlen
= sizeof(int),
430 .proc_handler
= &proc_dointvec
,
434 .ctl_name
= CTL_UNNUMBERED
,
435 .procname
= "print-fatal-signals",
436 .data
= &print_fatal_signals
,
437 .maxlen
= sizeof(int),
439 .proc_handler
= &proc_dointvec
,
443 .ctl_name
= KERN_SPARC_REBOOT
,
444 .procname
= "reboot-cmd",
445 .data
= reboot_command
,
448 .proc_handler
= &proc_dostring
,
449 .strategy
= &sysctl_string
,
452 .ctl_name
= KERN_SPARC_STOP_A
,
453 .procname
= "stop-a",
454 .data
= &stop_a_enabled
,
455 .maxlen
= sizeof (int),
457 .proc_handler
= &proc_dointvec
,
460 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
461 .procname
= "scons-poweroff",
462 .data
= &scons_pwroff
,
463 .maxlen
= sizeof (int),
465 .proc_handler
= &proc_dointvec
,
470 .ctl_name
= KERN_HPPA_PWRSW
,
471 .procname
= "soft-power",
472 .data
= &pwrsw_enabled
,
473 .maxlen
= sizeof (int),
475 .proc_handler
= &proc_dointvec
,
478 .ctl_name
= KERN_HPPA_UNALIGNED
,
479 .procname
= "unaligned-trap",
480 .data
= &unaligned_enabled
,
481 .maxlen
= sizeof (int),
483 .proc_handler
= &proc_dointvec
,
487 .ctl_name
= KERN_CTLALTDEL
,
488 .procname
= "ctrl-alt-del",
490 .maxlen
= sizeof(int),
492 .proc_handler
= &proc_dointvec
,
495 .ctl_name
= KERN_PRINTK
,
496 .procname
= "printk",
497 .data
= &console_loglevel
,
498 .maxlen
= 4*sizeof(int),
500 .proc_handler
= &proc_dointvec
,
504 .ctl_name
= KERN_MODPROBE
,
505 .procname
= "modprobe",
506 .data
= &modprobe_path
,
507 .maxlen
= KMOD_PATH_LEN
,
509 .proc_handler
= &proc_dostring
,
510 .strategy
= &sysctl_string
,
513 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
515 .ctl_name
= KERN_HOTPLUG
,
516 .procname
= "hotplug",
517 .data
= &uevent_helper
,
518 .maxlen
= UEVENT_HELPER_PATH_LEN
,
520 .proc_handler
= &proc_dostring
,
521 .strategy
= &sysctl_string
,
524 #ifdef CONFIG_CHR_DEV_SG
526 .ctl_name
= KERN_SG_BIG_BUFF
,
527 .procname
= "sg-big-buff",
528 .data
= &sg_big_buff
,
529 .maxlen
= sizeof (int),
531 .proc_handler
= &proc_dointvec
,
534 #ifdef CONFIG_BSD_PROCESS_ACCT
536 .ctl_name
= KERN_ACCT
,
539 .maxlen
= 3*sizeof(int),
541 .proc_handler
= &proc_dointvec
,
544 #ifdef CONFIG_MAGIC_SYSRQ
546 .ctl_name
= KERN_SYSRQ
,
548 .data
= &__sysrq_enabled
,
549 .maxlen
= sizeof (int),
551 .proc_handler
= &proc_dointvec
,
554 #ifdef CONFIG_PROC_SYSCTL
556 .procname
= "cad_pid",
558 .maxlen
= sizeof (int),
560 .proc_handler
= &proc_do_cad_pid
,
564 .ctl_name
= KERN_MAX_THREADS
,
565 .procname
= "threads-max",
566 .data
= &max_threads
,
567 .maxlen
= sizeof(int),
569 .proc_handler
= &proc_dointvec
,
572 .ctl_name
= KERN_RANDOM
,
573 .procname
= "random",
575 .child
= random_table
,
578 .ctl_name
= KERN_OVERFLOWUID
,
579 .procname
= "overflowuid",
580 .data
= &overflowuid
,
581 .maxlen
= sizeof(int),
583 .proc_handler
= &proc_dointvec_minmax
,
584 .strategy
= &sysctl_intvec
,
585 .extra1
= &minolduid
,
586 .extra2
= &maxolduid
,
589 .ctl_name
= KERN_OVERFLOWGID
,
590 .procname
= "overflowgid",
591 .data
= &overflowgid
,
592 .maxlen
= sizeof(int),
594 .proc_handler
= &proc_dointvec_minmax
,
595 .strategy
= &sysctl_intvec
,
596 .extra1
= &minolduid
,
597 .extra2
= &maxolduid
,
600 #ifdef CONFIG_MATHEMU
602 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
603 .procname
= "ieee_emulation_warnings",
604 .data
= &sysctl_ieee_emulation_warnings
,
605 .maxlen
= sizeof(int),
607 .proc_handler
= &proc_dointvec
,
610 #ifdef CONFIG_NO_IDLE_HZ
612 .ctl_name
= KERN_HZ_TIMER
,
613 .procname
= "hz_timer",
614 .data
= &sysctl_hz_timer
,
615 .maxlen
= sizeof(int),
617 .proc_handler
= &proc_dointvec
,
621 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
622 .procname
= "userprocess_debug",
623 .data
= &sysctl_userprocess_debug
,
624 .maxlen
= sizeof(int),
626 .proc_handler
= &proc_dointvec
,
630 .ctl_name
= KERN_PIDMAX
,
631 .procname
= "pid_max",
633 .maxlen
= sizeof (int),
635 .proc_handler
= &proc_dointvec_minmax
,
636 .strategy
= sysctl_intvec
,
637 .extra1
= &pid_max_min
,
638 .extra2
= &pid_max_max
,
641 .ctl_name
= KERN_PANIC_ON_OOPS
,
642 .procname
= "panic_on_oops",
643 .data
= &panic_on_oops
,
644 .maxlen
= sizeof(int),
646 .proc_handler
= &proc_dointvec
,
649 .ctl_name
= KERN_PRINTK_RATELIMIT
,
650 .procname
= "printk_ratelimit",
651 .data
= &printk_ratelimit_jiffies
,
652 .maxlen
= sizeof(int),
654 .proc_handler
= &proc_dointvec_jiffies
,
655 .strategy
= &sysctl_jiffies
,
658 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
659 .procname
= "printk_ratelimit_burst",
660 .data
= &printk_ratelimit_burst
,
661 .maxlen
= sizeof(int),
663 .proc_handler
= &proc_dointvec
,
666 .ctl_name
= KERN_NGROUPS_MAX
,
667 .procname
= "ngroups_max",
668 .data
= &ngroups_max
,
669 .maxlen
= sizeof (int),
671 .proc_handler
= &proc_dointvec
,
673 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
675 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
676 .procname
= "unknown_nmi_panic",
677 .data
= &unknown_nmi_panic
,
678 .maxlen
= sizeof (int),
680 .proc_handler
= &proc_dointvec
,
683 .procname
= "nmi_watchdog",
684 .data
= &nmi_watchdog_enabled
,
685 .maxlen
= sizeof (int),
687 .proc_handler
= &proc_nmi_enabled
,
690 #if defined(CONFIG_X86)
692 .ctl_name
= KERN_PANIC_ON_NMI
,
693 .procname
= "panic_on_unrecovered_nmi",
694 .data
= &panic_on_unrecovered_nmi
,
695 .maxlen
= sizeof(int),
697 .proc_handler
= &proc_dointvec
,
700 .ctl_name
= KERN_BOOTLOADER_TYPE
,
701 .procname
= "bootloader_type",
702 .data
= &bootloader_type
,
703 .maxlen
= sizeof (int),
705 .proc_handler
= &proc_dointvec
,
708 .ctl_name
= CTL_UNNUMBERED
,
709 .procname
= "kstack_depth_to_print",
710 .data
= &kstack_depth_to_print
,
711 .maxlen
= sizeof(int),
713 .proc_handler
= &proc_dointvec
,
716 .ctl_name
= CTL_UNNUMBERED
,
717 .procname
= "io_delay_type",
718 .data
= &io_delay_type
,
719 .maxlen
= sizeof(int),
721 .proc_handler
= &proc_dointvec
,
724 #if defined(CONFIG_MMU)
726 .ctl_name
= KERN_RANDOMIZE
,
727 .procname
= "randomize_va_space",
728 .data
= &randomize_va_space
,
729 .maxlen
= sizeof(int),
731 .proc_handler
= &proc_dointvec
,
734 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
736 .ctl_name
= KERN_SPIN_RETRY
,
737 .procname
= "spin_retry",
739 .maxlen
= sizeof (int),
741 .proc_handler
= &proc_dointvec
,
744 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
746 .procname
= "acpi_video_flags",
747 .data
= &acpi_realmode_flags
,
748 .maxlen
= sizeof (unsigned long),
750 .proc_handler
= &proc_doulongvec_minmax
,
755 .ctl_name
= KERN_IA64_UNALIGNED
,
756 .procname
= "ignore-unaligned-usertrap",
757 .data
= &no_unaligned_warning
,
758 .maxlen
= sizeof (int),
760 .proc_handler
= &proc_dointvec
,
763 #ifdef CONFIG_DETECT_SOFTLOCKUP
765 .ctl_name
= CTL_UNNUMBERED
,
766 .procname
= "softlockup_thresh",
767 .data
= &softlockup_thresh
,
768 .maxlen
= sizeof(unsigned long),
770 .proc_handler
= &proc_doulongvec_minmax
,
771 .strategy
= &sysctl_intvec
,
776 .ctl_name
= CTL_UNNUMBERED
,
777 .procname
= "hung_task_check_count",
778 .data
= &sysctl_hung_task_check_count
,
779 .maxlen
= sizeof(unsigned long),
781 .proc_handler
= &proc_doulongvec_minmax
,
782 .strategy
= &sysctl_intvec
,
785 .ctl_name
= CTL_UNNUMBERED
,
786 .procname
= "hung_task_timeout_secs",
787 .data
= &sysctl_hung_task_timeout_secs
,
788 .maxlen
= sizeof(unsigned long),
790 .proc_handler
= &proc_doulongvec_minmax
,
791 .strategy
= &sysctl_intvec
,
794 .ctl_name
= CTL_UNNUMBERED
,
795 .procname
= "hung_task_warnings",
796 .data
= &sysctl_hung_task_warnings
,
797 .maxlen
= sizeof(unsigned long),
799 .proc_handler
= &proc_doulongvec_minmax
,
800 .strategy
= &sysctl_intvec
,
805 .ctl_name
= KERN_COMPAT_LOG
,
806 .procname
= "compat-log",
808 .maxlen
= sizeof (int),
810 .proc_handler
= &proc_dointvec
,
813 #ifdef CONFIG_RT_MUTEXES
815 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
816 .procname
= "max_lock_depth",
817 .data
= &max_lock_depth
,
818 .maxlen
= sizeof(int),
820 .proc_handler
= &proc_dointvec
,
823 #ifdef CONFIG_PROC_FS
825 .ctl_name
= CTL_UNNUMBERED
,
826 .procname
= "maps_protect",
827 .data
= &maps_protect
,
828 .maxlen
= sizeof(int),
830 .proc_handler
= &proc_dointvec
,
834 .ctl_name
= CTL_UNNUMBERED
,
835 .procname
= "poweroff_cmd",
836 .data
= &poweroff_cmd
,
837 .maxlen
= POWEROFF_CMD_PATH_LEN
,
839 .proc_handler
= &proc_dostring
,
840 .strategy
= &sysctl_string
,
843 * NOTE: do not add new entries to this table unless you have read
844 * Documentation/sysctl/ctl_unnumbered.txt
849 static struct ctl_table vm_table
[] = {
851 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
852 .procname
= "overcommit_memory",
853 .data
= &sysctl_overcommit_memory
,
854 .maxlen
= sizeof(sysctl_overcommit_memory
),
856 .proc_handler
= &proc_dointvec
,
859 .ctl_name
= VM_PANIC_ON_OOM
,
860 .procname
= "panic_on_oom",
861 .data
= &sysctl_panic_on_oom
,
862 .maxlen
= sizeof(sysctl_panic_on_oom
),
864 .proc_handler
= &proc_dointvec
,
867 .ctl_name
= CTL_UNNUMBERED
,
868 .procname
= "oom_kill_allocating_task",
869 .data
= &sysctl_oom_kill_allocating_task
,
870 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
872 .proc_handler
= &proc_dointvec
,
875 .ctl_name
= CTL_UNNUMBERED
,
876 .procname
= "oom_dump_tasks",
877 .data
= &sysctl_oom_dump_tasks
,
878 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
880 .proc_handler
= &proc_dointvec
,
883 .ctl_name
= VM_OVERCOMMIT_RATIO
,
884 .procname
= "overcommit_ratio",
885 .data
= &sysctl_overcommit_ratio
,
886 .maxlen
= sizeof(sysctl_overcommit_ratio
),
888 .proc_handler
= &proc_dointvec
,
891 .ctl_name
= VM_PAGE_CLUSTER
,
892 .procname
= "page-cluster",
893 .data
= &page_cluster
,
894 .maxlen
= sizeof(int),
896 .proc_handler
= &proc_dointvec
,
899 .ctl_name
= VM_DIRTY_BACKGROUND
,
900 .procname
= "dirty_background_ratio",
901 .data
= &dirty_background_ratio
,
902 .maxlen
= sizeof(dirty_background_ratio
),
904 .proc_handler
= &proc_dointvec_minmax
,
905 .strategy
= &sysctl_intvec
,
907 .extra2
= &one_hundred
,
910 .ctl_name
= VM_DIRTY_RATIO
,
911 .procname
= "dirty_ratio",
912 .data
= &vm_dirty_ratio
,
913 .maxlen
= sizeof(vm_dirty_ratio
),
915 .proc_handler
= &dirty_ratio_handler
,
916 .strategy
= &sysctl_intvec
,
918 .extra2
= &one_hundred
,
921 .procname
= "dirty_writeback_centisecs",
922 .data
= &dirty_writeback_interval
,
923 .maxlen
= sizeof(dirty_writeback_interval
),
925 .proc_handler
= &dirty_writeback_centisecs_handler
,
928 .procname
= "dirty_expire_centisecs",
929 .data
= &dirty_expire_interval
,
930 .maxlen
= sizeof(dirty_expire_interval
),
932 .proc_handler
= &proc_dointvec_userhz_jiffies
,
935 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
936 .procname
= "nr_pdflush_threads",
937 .data
= &nr_pdflush_threads
,
938 .maxlen
= sizeof nr_pdflush_threads
,
939 .mode
= 0444 /* read-only*/,
940 .proc_handler
= &proc_dointvec
,
943 .ctl_name
= VM_SWAPPINESS
,
944 .procname
= "swappiness",
945 .data
= &vm_swappiness
,
946 .maxlen
= sizeof(vm_swappiness
),
948 .proc_handler
= &proc_dointvec_minmax
,
949 .strategy
= &sysctl_intvec
,
951 .extra2
= &one_hundred
,
953 #ifdef CONFIG_HUGETLB_PAGE
955 .procname
= "nr_hugepages",
956 .data
= &max_huge_pages
,
957 .maxlen
= sizeof(unsigned long),
959 .proc_handler
= &hugetlb_sysctl_handler
,
960 .extra1
= (void *)&hugetlb_zero
,
961 .extra2
= (void *)&hugetlb_infinity
,
964 .ctl_name
= VM_HUGETLB_GROUP
,
965 .procname
= "hugetlb_shm_group",
966 .data
= &sysctl_hugetlb_shm_group
,
967 .maxlen
= sizeof(gid_t
),
969 .proc_handler
= &proc_dointvec
,
972 .ctl_name
= CTL_UNNUMBERED
,
973 .procname
= "hugepages_treat_as_movable",
974 .data
= &hugepages_treat_as_movable
,
975 .maxlen
= sizeof(int),
977 .proc_handler
= &hugetlb_treat_movable_handler
,
980 .ctl_name
= CTL_UNNUMBERED
,
981 .procname
= "nr_overcommit_hugepages",
982 .data
= &nr_overcommit_huge_pages
,
983 .maxlen
= sizeof(nr_overcommit_huge_pages
),
985 .proc_handler
= &proc_doulongvec_minmax
,
989 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
990 .procname
= "lowmem_reserve_ratio",
991 .data
= &sysctl_lowmem_reserve_ratio
,
992 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
994 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
995 .strategy
= &sysctl_intvec
,
998 .ctl_name
= VM_DROP_PAGECACHE
,
999 .procname
= "drop_caches",
1000 .data
= &sysctl_drop_caches
,
1001 .maxlen
= sizeof(int),
1003 .proc_handler
= drop_caches_sysctl_handler
,
1004 .strategy
= &sysctl_intvec
,
1007 .ctl_name
= VM_MIN_FREE_KBYTES
,
1008 .procname
= "min_free_kbytes",
1009 .data
= &min_free_kbytes
,
1010 .maxlen
= sizeof(min_free_kbytes
),
1012 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1013 .strategy
= &sysctl_intvec
,
1017 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1018 .procname
= "percpu_pagelist_fraction",
1019 .data
= &percpu_pagelist_fraction
,
1020 .maxlen
= sizeof(percpu_pagelist_fraction
),
1022 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1023 .strategy
= &sysctl_intvec
,
1024 .extra1
= &min_percpu_pagelist_fract
,
1028 .ctl_name
= VM_MAX_MAP_COUNT
,
1029 .procname
= "max_map_count",
1030 .data
= &sysctl_max_map_count
,
1031 .maxlen
= sizeof(sysctl_max_map_count
),
1033 .proc_handler
= &proc_dointvec
1037 .ctl_name
= VM_LAPTOP_MODE
,
1038 .procname
= "laptop_mode",
1039 .data
= &laptop_mode
,
1040 .maxlen
= sizeof(laptop_mode
),
1042 .proc_handler
= &proc_dointvec_jiffies
,
1043 .strategy
= &sysctl_jiffies
,
1046 .ctl_name
= VM_BLOCK_DUMP
,
1047 .procname
= "block_dump",
1048 .data
= &block_dump
,
1049 .maxlen
= sizeof(block_dump
),
1051 .proc_handler
= &proc_dointvec
,
1052 .strategy
= &sysctl_intvec
,
1056 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1057 .procname
= "vfs_cache_pressure",
1058 .data
= &sysctl_vfs_cache_pressure
,
1059 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1061 .proc_handler
= &proc_dointvec
,
1062 .strategy
= &sysctl_intvec
,
1065 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1067 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1068 .procname
= "legacy_va_layout",
1069 .data
= &sysctl_legacy_va_layout
,
1070 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1072 .proc_handler
= &proc_dointvec
,
1073 .strategy
= &sysctl_intvec
,
1079 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1080 .procname
= "zone_reclaim_mode",
1081 .data
= &zone_reclaim_mode
,
1082 .maxlen
= sizeof(zone_reclaim_mode
),
1084 .proc_handler
= &proc_dointvec
,
1085 .strategy
= &sysctl_intvec
,
1089 .ctl_name
= VM_MIN_UNMAPPED
,
1090 .procname
= "min_unmapped_ratio",
1091 .data
= &sysctl_min_unmapped_ratio
,
1092 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1094 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1095 .strategy
= &sysctl_intvec
,
1097 .extra2
= &one_hundred
,
1100 .ctl_name
= VM_MIN_SLAB
,
1101 .procname
= "min_slab_ratio",
1102 .data
= &sysctl_min_slab_ratio
,
1103 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1105 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1106 .strategy
= &sysctl_intvec
,
1108 .extra2
= &one_hundred
,
1113 .ctl_name
= CTL_UNNUMBERED
,
1114 .procname
= "stat_interval",
1115 .data
= &sysctl_stat_interval
,
1116 .maxlen
= sizeof(sysctl_stat_interval
),
1118 .proc_handler
= &proc_dointvec_jiffies
,
1119 .strategy
= &sysctl_jiffies
,
1122 #ifdef CONFIG_SECURITY
1124 .ctl_name
= CTL_UNNUMBERED
,
1125 .procname
= "mmap_min_addr",
1126 .data
= &mmap_min_addr
,
1127 .maxlen
= sizeof(unsigned long),
1129 .proc_handler
= &proc_doulongvec_minmax
,
1134 .ctl_name
= CTL_UNNUMBERED
,
1135 .procname
= "numa_zonelist_order",
1136 .data
= &numa_zonelist_order
,
1137 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1139 .proc_handler
= &numa_zonelist_order_handler
,
1140 .strategy
= &sysctl_string
,
1143 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1144 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1146 .ctl_name
= VM_VDSO_ENABLED
,
1147 .procname
= "vdso_enabled",
1148 .data
= &vdso_enabled
,
1149 .maxlen
= sizeof(vdso_enabled
),
1151 .proc_handler
= &proc_dointvec
,
1152 .strategy
= &sysctl_intvec
,
1156 #ifdef CONFIG_HIGHMEM
1158 .ctl_name
= CTL_UNNUMBERED
,
1159 .procname
= "highmem_is_dirtyable",
1160 .data
= &vm_highmem_is_dirtyable
,
1161 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1163 .proc_handler
= &proc_dointvec_minmax
,
1164 .strategy
= &sysctl_intvec
,
1170 * NOTE: do not add new entries to this table unless you have read
1171 * Documentation/sysctl/ctl_unnumbered.txt
1176 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1177 static struct ctl_table binfmt_misc_table
[] = {
1182 static struct ctl_table fs_table
[] = {
1184 .ctl_name
= FS_NRINODE
,
1185 .procname
= "inode-nr",
1186 .data
= &inodes_stat
,
1187 .maxlen
= 2*sizeof(int),
1189 .proc_handler
= &proc_dointvec
,
1192 .ctl_name
= FS_STATINODE
,
1193 .procname
= "inode-state",
1194 .data
= &inodes_stat
,
1195 .maxlen
= 7*sizeof(int),
1197 .proc_handler
= &proc_dointvec
,
1200 .procname
= "file-nr",
1201 .data
= &files_stat
,
1202 .maxlen
= 3*sizeof(int),
1204 .proc_handler
= &proc_nr_files
,
1207 .ctl_name
= FS_MAXFILE
,
1208 .procname
= "file-max",
1209 .data
= &files_stat
.max_files
,
1210 .maxlen
= sizeof(int),
1212 .proc_handler
= &proc_dointvec
,
1215 .ctl_name
= CTL_UNNUMBERED
,
1216 .procname
= "nr_open",
1217 .data
= &sysctl_nr_open
,
1218 .maxlen
= sizeof(int),
1220 .proc_handler
= &proc_dointvec
,
1223 .ctl_name
= FS_DENTRY
,
1224 .procname
= "dentry-state",
1225 .data
= &dentry_stat
,
1226 .maxlen
= 6*sizeof(int),
1228 .proc_handler
= &proc_dointvec
,
1231 .ctl_name
= FS_OVERFLOWUID
,
1232 .procname
= "overflowuid",
1233 .data
= &fs_overflowuid
,
1234 .maxlen
= sizeof(int),
1236 .proc_handler
= &proc_dointvec_minmax
,
1237 .strategy
= &sysctl_intvec
,
1238 .extra1
= &minolduid
,
1239 .extra2
= &maxolduid
,
1242 .ctl_name
= FS_OVERFLOWGID
,
1243 .procname
= "overflowgid",
1244 .data
= &fs_overflowgid
,
1245 .maxlen
= sizeof(int),
1247 .proc_handler
= &proc_dointvec_minmax
,
1248 .strategy
= &sysctl_intvec
,
1249 .extra1
= &minolduid
,
1250 .extra2
= &maxolduid
,
1253 .ctl_name
= FS_LEASES
,
1254 .procname
= "leases-enable",
1255 .data
= &leases_enable
,
1256 .maxlen
= sizeof(int),
1258 .proc_handler
= &proc_dointvec
,
1260 #ifdef CONFIG_DNOTIFY
1262 .ctl_name
= FS_DIR_NOTIFY
,
1263 .procname
= "dir-notify-enable",
1264 .data
= &dir_notify_enable
,
1265 .maxlen
= sizeof(int),
1267 .proc_handler
= &proc_dointvec
,
1272 .ctl_name
= FS_LEASE_TIME
,
1273 .procname
= "lease-break-time",
1274 .data
= &lease_break_time
,
1275 .maxlen
= sizeof(int),
1277 .proc_handler
= &proc_dointvec_minmax
,
1278 .strategy
= &sysctl_intvec
,
1283 .procname
= "aio-nr",
1285 .maxlen
= sizeof(aio_nr
),
1287 .proc_handler
= &proc_doulongvec_minmax
,
1290 .procname
= "aio-max-nr",
1291 .data
= &aio_max_nr
,
1292 .maxlen
= sizeof(aio_max_nr
),
1294 .proc_handler
= &proc_doulongvec_minmax
,
1296 #ifdef CONFIG_INOTIFY_USER
1298 .ctl_name
= FS_INOTIFY
,
1299 .procname
= "inotify",
1301 .child
= inotify_table
,
1306 .ctl_name
= KERN_SETUID_DUMPABLE
,
1307 .procname
= "suid_dumpable",
1308 .data
= &suid_dumpable
,
1309 .maxlen
= sizeof(int),
1311 .proc_handler
= &proc_dointvec
,
1313 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1315 .ctl_name
= CTL_UNNUMBERED
,
1316 .procname
= "binfmt_misc",
1318 .child
= binfmt_misc_table
,
1322 * NOTE: do not add new entries to this table unless you have read
1323 * Documentation/sysctl/ctl_unnumbered.txt
1328 static struct ctl_table debug_table
[] = {
1329 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1331 .ctl_name
= CTL_UNNUMBERED
,
1332 .procname
= "exception-trace",
1333 .data
= &show_unhandled_signals
,
1334 .maxlen
= sizeof(int),
1336 .proc_handler
= proc_dointvec
1342 static struct ctl_table dev_table
[] = {
1346 static DEFINE_SPINLOCK(sysctl_lock
);
1348 /* called under sysctl_lock */
1349 static int use_table(struct ctl_table_header
*p
)
1351 if (unlikely(p
->unregistering
))
1357 /* called under sysctl_lock */
1358 static void unuse_table(struct ctl_table_header
*p
)
1361 if (unlikely(p
->unregistering
))
1362 complete(p
->unregistering
);
1365 /* called under sysctl_lock, will reacquire if has to wait */
1366 static void start_unregistering(struct ctl_table_header
*p
)
1369 * if p->used is 0, nobody will ever touch that entry again;
1370 * we'll eliminate all paths to it before dropping sysctl_lock
1372 if (unlikely(p
->used
)) {
1373 struct completion wait
;
1374 init_completion(&wait
);
1375 p
->unregistering
= &wait
;
1376 spin_unlock(&sysctl_lock
);
1377 wait_for_completion(&wait
);
1378 spin_lock(&sysctl_lock
);
1381 * do not remove from the list until nobody holds it; walking the
1382 * list in do_sysctl() relies on that.
1384 list_del_init(&p
->ctl_entry
);
1387 void sysctl_head_finish(struct ctl_table_header
*head
)
1391 spin_lock(&sysctl_lock
);
1393 spin_unlock(&sysctl_lock
);
1396 static struct list_head
*
1397 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1399 struct list_head
*header_list
;
1400 header_list
= &root
->header_list
;
1402 header_list
= root
->lookup(root
, namespaces
);
1406 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1407 struct ctl_table_header
*prev
)
1409 struct ctl_table_root
*root
;
1410 struct list_head
*header_list
;
1411 struct ctl_table_header
*head
;
1412 struct list_head
*tmp
;
1414 spin_lock(&sysctl_lock
);
1417 tmp
= &prev
->ctl_entry
;
1421 tmp
= &root_table_header
.ctl_entry
;
1423 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1425 if (!use_table(head
))
1427 spin_unlock(&sysctl_lock
);
1432 header_list
= lookup_header_list(root
, namespaces
);
1433 if (tmp
!= header_list
)
1437 root
= list_entry(root
->root_list
.next
,
1438 struct ctl_table_root
, root_list
);
1439 if (root
== &sysctl_table_root
)
1441 header_list
= lookup_header_list(root
, namespaces
);
1442 } while (list_empty(header_list
));
1443 tmp
= header_list
->next
;
1446 spin_unlock(&sysctl_lock
);
1450 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1452 return __sysctl_head_next(current
->nsproxy
, prev
);
1455 void register_sysctl_root(struct ctl_table_root
*root
)
1457 spin_lock(&sysctl_lock
);
1458 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1459 spin_unlock(&sysctl_lock
);
1462 #ifdef CONFIG_SYSCTL_SYSCALL
1463 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1464 void __user
*newval
, size_t newlen
)
1466 struct ctl_table_header
*head
;
1467 int error
= -ENOTDIR
;
1469 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1473 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1477 for (head
= sysctl_head_next(NULL
); head
;
1478 head
= sysctl_head_next(head
)) {
1479 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1480 newval
, newlen
, head
->ctl_table
);
1481 if (error
!= -ENOTDIR
) {
1482 sysctl_head_finish(head
);
1489 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1491 struct __sysctl_args tmp
;
1494 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1497 error
= deprecated_sysctl_warning(&tmp
);
1502 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1503 tmp
.newval
, tmp
.newlen
);
1508 #endif /* CONFIG_SYSCTL_SYSCALL */
1511 * sysctl_perm does NOT grant the superuser all rights automatically, because
1512 * some sysctl variables are readonly even to root.
1515 static int test_perm(int mode
, int op
)
1519 else if (in_egroup_p(0))
1521 if ((mode
& op
& 0007) == op
)
1526 int sysctl_perm(struct ctl_table
*table
, int op
)
1529 error
= security_sysctl(table
, op
);
1532 return test_perm(table
->mode
, op
);
1535 #ifdef CONFIG_SYSCTL_SYSCALL
1536 static int parse_table(int __user
*name
, int nlen
,
1537 void __user
*oldval
, size_t __user
*oldlenp
,
1538 void __user
*newval
, size_t newlen
,
1539 struct ctl_table
*table
)
1545 if (get_user(n
, name
))
1547 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1548 if (!table
->ctl_name
)
1550 if (n
== table
->ctl_name
) {
1553 if (sysctl_perm(table
, 001))
1557 table
= table
->child
;
1560 error
= do_sysctl_strategy(table
, name
, nlen
,
1569 /* Perform the actual read/write of a sysctl table entry. */
1570 int do_sysctl_strategy (struct ctl_table
*table
,
1571 int __user
*name
, int nlen
,
1572 void __user
*oldval
, size_t __user
*oldlenp
,
1573 void __user
*newval
, size_t newlen
)
1581 if (sysctl_perm(table
, op
))
1584 if (table
->strategy
) {
1585 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1593 /* If there is no strategy routine, or if the strategy returns
1594 * zero, proceed with automatic r/w */
1595 if (table
->data
&& table
->maxlen
) {
1596 rc
= sysctl_data(table
, name
, nlen
, oldval
, oldlenp
,
1603 #endif /* CONFIG_SYSCTL_SYSCALL */
1605 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1607 for (; table
->ctl_name
|| table
->procname
; table
++) {
1608 table
->parent
= parent
;
1610 sysctl_set_parent(table
, table
->child
);
1614 static __init
int sysctl_init(void)
1617 sysctl_set_parent(NULL
, root_table
);
1618 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1622 core_initcall(sysctl_init
);
1625 * __register_sysctl_paths - register a sysctl hierarchy
1626 * @root: List of sysctl headers to register on
1627 * @namespaces: Data to compute which lists of sysctl entries are visible
1628 * @path: The path to the directory the sysctl table is in.
1629 * @table: the top-level table structure
1631 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1632 * array. A completely 0 filled entry terminates the table.
1634 * The members of the &struct ctl_table structure are used as follows:
1636 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1637 * must be unique within that level of sysctl
1639 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1640 * enter a sysctl file
1642 * data - a pointer to data for use by proc_handler
1644 * maxlen - the maximum size in bytes of the data
1646 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1648 * child - a pointer to the child sysctl table if this entry is a directory, or
1651 * proc_handler - the text handler routine (described below)
1653 * strategy - the strategy routine (described below)
1655 * de - for internal use by the sysctl routines
1657 * extra1, extra2 - extra pointers usable by the proc handler routines
1659 * Leaf nodes in the sysctl tree will be represented by a single file
1660 * under /proc; non-leaf nodes will be represented by directories.
1662 * sysctl(2) can automatically manage read and write requests through
1663 * the sysctl table. The data and maxlen fields of the ctl_table
1664 * struct enable minimal validation of the values being written to be
1665 * performed, and the mode field allows minimal authentication.
1667 * More sophisticated management can be enabled by the provision of a
1668 * strategy routine with the table entry. This will be called before
1669 * any automatic read or write of the data is performed.
1671 * The strategy routine may return
1673 * < 0 - Error occurred (error is passed to user process)
1675 * 0 - OK - proceed with automatic read or write.
1677 * > 0 - OK - read or write has been done by the strategy routine, so
1678 * return immediately.
1680 * There must be a proc_handler routine for any terminal nodes
1681 * mirrored under /proc/sys (non-terminals are handled by a built-in
1682 * directory handler). Several default handlers are available to
1683 * cover common cases -
1685 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1686 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1687 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1689 * It is the handler's job to read the input buffer from user memory
1690 * and process it. The handler should return 0 on success.
1692 * This routine returns %NULL on a failure to register, and a pointer
1693 * to the table header on success.
1695 struct ctl_table_header
*__register_sysctl_paths(
1696 struct ctl_table_root
*root
,
1697 struct nsproxy
*namespaces
,
1698 const struct ctl_path
*path
, struct ctl_table
*table
)
1700 struct list_head
*header_list
;
1701 struct ctl_table_header
*header
;
1702 struct ctl_table
*new, **prevp
;
1703 unsigned int n
, npath
;
1705 /* Count the path components */
1706 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
1710 * For each path component, allocate a 2-element ctl_table array.
1711 * The first array element will be filled with the sysctl entry
1712 * for this, the second will be the sentinel (ctl_name == 0).
1714 * We allocate everything in one go so that we don't have to
1715 * worry about freeing additional memory in unregister_sysctl_table.
1717 header
= kzalloc(sizeof(struct ctl_table_header
) +
1718 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1722 new = (struct ctl_table
*) (header
+ 1);
1724 /* Now connect the dots */
1725 prevp
= &header
->ctl_table
;
1726 for (n
= 0; n
< npath
; ++n
, ++path
) {
1727 /* Copy the procname */
1728 new->procname
= path
->procname
;
1729 new->ctl_name
= path
->ctl_name
;
1733 prevp
= &new->child
;
1738 header
->ctl_table_arg
= table
;
1740 INIT_LIST_HEAD(&header
->ctl_entry
);
1742 header
->unregistering
= NULL
;
1743 header
->root
= root
;
1744 sysctl_set_parent(NULL
, header
->ctl_table
);
1745 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1749 spin_lock(&sysctl_lock
);
1750 header_list
= lookup_header_list(root
, namespaces
);
1751 list_add_tail(&header
->ctl_entry
, header_list
);
1752 spin_unlock(&sysctl_lock
);
1758 * register_sysctl_table_path - register a sysctl table hierarchy
1759 * @path: The path to the directory the sysctl table is in.
1760 * @table: the top-level table structure
1762 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1763 * array. A completely 0 filled entry terminates the table.
1765 * See __register_sysctl_paths for more details.
1767 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1768 struct ctl_table
*table
)
1770 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1775 * register_sysctl_table - register a sysctl table hierarchy
1776 * @table: the top-level table structure
1778 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1779 * array. A completely 0 filled entry terminates the table.
1781 * See register_sysctl_paths for more details.
1783 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1785 static const struct ctl_path null_path
[] = { {} };
1787 return register_sysctl_paths(null_path
, table
);
1791 * unregister_sysctl_table - unregister a sysctl table hierarchy
1792 * @header: the header returned from register_sysctl_table
1794 * Unregisters the sysctl table and all children. proc entries may not
1795 * actually be removed until they are no longer used by anyone.
1797 void unregister_sysctl_table(struct ctl_table_header
* header
)
1804 spin_lock(&sysctl_lock
);
1805 start_unregistering(header
);
1806 spin_unlock(&sysctl_lock
);
1810 #else /* !CONFIG_SYSCTL */
1811 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1816 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1817 struct ctl_table
*table
)
1822 void unregister_sysctl_table(struct ctl_table_header
* table
)
1826 #endif /* CONFIG_SYSCTL */
1832 #ifdef CONFIG_PROC_SYSCTL
1834 static int _proc_do_string(void* data
, int maxlen
, int write
,
1835 struct file
*filp
, void __user
*buffer
,
1836 size_t *lenp
, loff_t
*ppos
)
1842 if (!data
|| !maxlen
|| !*lenp
) {
1850 while (len
< *lenp
) {
1851 if (get_user(c
, p
++))
1853 if (c
== 0 || c
== '\n')
1859 if(copy_from_user(data
, buffer
, len
))
1861 ((char *) data
)[len
] = 0;
1879 if(copy_to_user(buffer
, data
, len
))
1882 if(put_user('\n', ((char __user
*) buffer
) + len
))
1893 * proc_dostring - read a string sysctl
1894 * @table: the sysctl table
1895 * @write: %TRUE if this is a write to the sysctl file
1896 * @filp: the file structure
1897 * @buffer: the user buffer
1898 * @lenp: the size of the user buffer
1899 * @ppos: file position
1901 * Reads/writes a string from/to the user buffer. If the kernel
1902 * buffer provided is not large enough to hold the string, the
1903 * string is truncated. The copied string is %NULL-terminated.
1904 * If the string is being read by the user process, it is copied
1905 * and a newline '\n' is added. It is truncated if the buffer is
1908 * Returns 0 on success.
1910 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
1911 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1913 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
1914 buffer
, lenp
, ppos
);
1918 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1920 int write
, void *data
)
1923 *valp
= *negp
? -*lvalp
: *lvalp
;
1928 *lvalp
= (unsigned long)-val
;
1931 *lvalp
= (unsigned long)val
;
1937 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1938 int write
, struct file
*filp
, void __user
*buffer
,
1939 size_t *lenp
, loff_t
*ppos
,
1940 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1941 int write
, void *data
),
1944 #define TMPBUFLEN 21
1945 int *i
, vleft
, first
=1, neg
, val
;
1949 char buf
[TMPBUFLEN
], *p
;
1950 char __user
*s
= buffer
;
1952 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
1953 (*ppos
&& !write
)) {
1958 i
= (int *) tbl_data
;
1959 vleft
= table
->maxlen
/ sizeof(*i
);
1963 conv
= do_proc_dointvec_conv
;
1965 for (; left
&& vleft
--; i
++, first
=0) {
1980 if (len
> sizeof(buf
) - 1)
1981 len
= sizeof(buf
) - 1;
1982 if (copy_from_user(buf
, s
, len
))
1986 if (*p
== '-' && left
> 1) {
1990 if (*p
< '0' || *p
> '9')
1993 lval
= simple_strtoul(p
, &p
, 0);
1996 if ((len
< left
) && *p
&& !isspace(*p
))
2003 if (conv(&neg
, &lval
, i
, 1, data
))
2010 if (conv(&neg
, &lval
, i
, 0, data
))
2013 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2017 if(copy_to_user(s
, buf
, len
))
2024 if (!write
&& !first
&& left
) {
2025 if(put_user('\n', s
))
2032 if (get_user(c
, s
++))
2047 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2048 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2049 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2050 int write
, void *data
),
2053 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2054 buffer
, lenp
, ppos
, conv
, data
);
2058 * proc_dointvec - read a vector of integers
2059 * @table: the sysctl table
2060 * @write: %TRUE if this is a write to the sysctl file
2061 * @filp: the file structure
2062 * @buffer: the user buffer
2063 * @lenp: the size of the user buffer
2064 * @ppos: file position
2066 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2067 * values from/to the user buffer, treated as an ASCII string.
2069 * Returns 0 on success.
2071 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2072 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2074 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2082 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
2084 int write
, void *data
)
2086 int op
= *(int *)data
;
2088 int val
= *negp
? -*lvalp
: *lvalp
;
2090 case OP_SET
: *valp
= val
; break;
2091 case OP_AND
: *valp
&= val
; break;
2092 case OP_OR
: *valp
|= val
; break;
2098 *lvalp
= (unsigned long)-val
;
2101 *lvalp
= (unsigned long)val
;
2108 * Taint values can only be increased
2110 static int proc_dointvec_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2111 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2115 if (write
&& !capable(CAP_SYS_ADMIN
))
2119 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2120 do_proc_dointvec_bset_conv
,&op
);
2123 struct do_proc_dointvec_minmax_conv_param
{
2128 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2130 int write
, void *data
)
2132 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2134 int val
= *negp
? -*lvalp
: *lvalp
;
2135 if ((param
->min
&& *param
->min
> val
) ||
2136 (param
->max
&& *param
->max
< val
))
2143 *lvalp
= (unsigned long)-val
;
2146 *lvalp
= (unsigned long)val
;
2153 * proc_dointvec_minmax - read a vector of integers with min/max values
2154 * @table: the sysctl table
2155 * @write: %TRUE if this is a write to the sysctl file
2156 * @filp: the file structure
2157 * @buffer: the user buffer
2158 * @lenp: the size of the user buffer
2159 * @ppos: file position
2161 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2162 * values from/to the user buffer, treated as an ASCII string.
2164 * This routine will ensure the values are within the range specified by
2165 * table->extra1 (min) and table->extra2 (max).
2167 * Returns 0 on success.
2169 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2170 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2172 struct do_proc_dointvec_minmax_conv_param param
= {
2173 .min
= (int *) table
->extra1
,
2174 .max
= (int *) table
->extra2
,
2176 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2177 do_proc_dointvec_minmax_conv
, ¶m
);
2180 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2182 void __user
*buffer
,
2183 size_t *lenp
, loff_t
*ppos
,
2184 unsigned long convmul
,
2185 unsigned long convdiv
)
2187 #define TMPBUFLEN 21
2188 unsigned long *i
, *min
, *max
, val
;
2189 int vleft
, first
=1, neg
;
2191 char buf
[TMPBUFLEN
], *p
;
2192 char __user
*s
= buffer
;
2194 if (!data
|| !table
->maxlen
|| !*lenp
||
2195 (*ppos
&& !write
)) {
2200 i
= (unsigned long *) data
;
2201 min
= (unsigned long *) table
->extra1
;
2202 max
= (unsigned long *) table
->extra2
;
2203 vleft
= table
->maxlen
/ sizeof(unsigned long);
2206 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2221 if (len
> TMPBUFLEN
-1)
2223 if (copy_from_user(buf
, s
, len
))
2227 if (*p
== '-' && left
> 1) {
2231 if (*p
< '0' || *p
> '9')
2233 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2235 if ((len
< left
) && *p
&& !isspace(*p
))
2244 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2251 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2255 if(copy_to_user(s
, buf
, len
))
2262 if (!write
&& !first
&& left
) {
2263 if(put_user('\n', s
))
2270 if (get_user(c
, s
++))
2285 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2287 void __user
*buffer
,
2288 size_t *lenp
, loff_t
*ppos
,
2289 unsigned long convmul
,
2290 unsigned long convdiv
)
2292 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2293 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2297 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2298 * @table: the sysctl table
2299 * @write: %TRUE if this is a write to the sysctl file
2300 * @filp: the file structure
2301 * @buffer: the user buffer
2302 * @lenp: the size of the user buffer
2303 * @ppos: file position
2305 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2306 * values from/to the user buffer, treated as an ASCII string.
2308 * This routine will ensure the values are within the range specified by
2309 * table->extra1 (min) and table->extra2 (max).
2311 * Returns 0 on success.
2313 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2314 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2316 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2320 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2321 * @table: the sysctl table
2322 * @write: %TRUE if this is a write to the sysctl file
2323 * @filp: the file structure
2324 * @buffer: the user buffer
2325 * @lenp: the size of the user buffer
2326 * @ppos: file position
2328 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2329 * values from/to the user buffer, treated as an ASCII string. The values
2330 * are treated as milliseconds, and converted to jiffies when they are stored.
2332 * This routine will ensure the values are within the range specified by
2333 * table->extra1 (min) and table->extra2 (max).
2335 * Returns 0 on success.
2337 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2339 void __user
*buffer
,
2340 size_t *lenp
, loff_t
*ppos
)
2342 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2343 lenp
, ppos
, HZ
, 1000l);
2347 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2349 int write
, void *data
)
2352 if (*lvalp
> LONG_MAX
/ HZ
)
2354 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2360 lval
= (unsigned long)-val
;
2363 lval
= (unsigned long)val
;
2370 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2372 int write
, void *data
)
2375 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2377 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2383 lval
= (unsigned long)-val
;
2386 lval
= (unsigned long)val
;
2388 *lvalp
= jiffies_to_clock_t(lval
);
2393 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2395 int write
, void *data
)
2398 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2404 lval
= (unsigned long)-val
;
2407 lval
= (unsigned long)val
;
2409 *lvalp
= jiffies_to_msecs(lval
);
2415 * proc_dointvec_jiffies - read a vector of integers as seconds
2416 * @table: the sysctl table
2417 * @write: %TRUE if this is a write to the sysctl file
2418 * @filp: the file structure
2419 * @buffer: the user buffer
2420 * @lenp: the size of the user buffer
2421 * @ppos: file position
2423 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2424 * values from/to the user buffer, treated as an ASCII string.
2425 * The values read are assumed to be in seconds, and are converted into
2428 * Returns 0 on success.
2430 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2431 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2433 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2434 do_proc_dointvec_jiffies_conv
,NULL
);
2438 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2439 * @table: the sysctl table
2440 * @write: %TRUE if this is a write to the sysctl file
2441 * @filp: the file structure
2442 * @buffer: the user buffer
2443 * @lenp: the size of the user buffer
2444 * @ppos: pointer to the file position
2446 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2447 * values from/to the user buffer, treated as an ASCII string.
2448 * The values read are assumed to be in 1/USER_HZ seconds, and
2449 * are converted into jiffies.
2451 * Returns 0 on success.
2453 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2454 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2456 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2457 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2461 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2462 * @table: the sysctl table
2463 * @write: %TRUE if this is a write to the sysctl file
2464 * @filp: the file structure
2465 * @buffer: the user buffer
2466 * @lenp: the size of the user buffer
2467 * @ppos: file position
2468 * @ppos: the current position in the file
2470 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2471 * values from/to the user buffer, treated as an ASCII string.
2472 * The values read are assumed to be in 1/1000 seconds, and
2473 * are converted into jiffies.
2475 * Returns 0 on success.
2477 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2478 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2480 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2481 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2484 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2485 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2487 struct pid
*new_pid
;
2491 tmp
= pid_nr_ns(cad_pid
, current
->nsproxy
->pid_ns
);
2493 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2494 lenp
, ppos
, NULL
, NULL
);
2498 new_pid
= find_get_pid(tmp
);
2502 put_pid(xchg(&cad_pid
, new_pid
));
2506 #else /* CONFIG_PROC_FS */
2508 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2509 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2514 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2515 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2520 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2521 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2526 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2527 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2532 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2533 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2538 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2539 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2544 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2545 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2550 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2552 void __user
*buffer
,
2553 size_t *lenp
, loff_t
*ppos
)
2559 #endif /* CONFIG_PROC_FS */
2562 #ifdef CONFIG_SYSCTL_SYSCALL
2564 * General sysctl support routines
2567 /* The generic sysctl data routine (used if no strategy routine supplied) */
2568 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2569 void __user
*oldval
, size_t __user
*oldlenp
,
2570 void __user
*newval
, size_t newlen
)
2574 /* Get out of I don't have a variable */
2575 if (!table
->data
|| !table
->maxlen
)
2578 if (oldval
&& oldlenp
) {
2579 if (get_user(len
, oldlenp
))
2582 if (len
> table
->maxlen
)
2583 len
= table
->maxlen
;
2584 if (copy_to_user(oldval
, table
->data
, len
))
2586 if (put_user(len
, oldlenp
))
2591 if (newval
&& newlen
) {
2592 if (newlen
> table
->maxlen
)
2593 newlen
= table
->maxlen
;
2595 if (copy_from_user(table
->data
, newval
, newlen
))
2601 /* The generic string strategy routine: */
2602 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2603 void __user
*oldval
, size_t __user
*oldlenp
,
2604 void __user
*newval
, size_t newlen
)
2606 if (!table
->data
|| !table
->maxlen
)
2609 if (oldval
&& oldlenp
) {
2611 if (get_user(bufsize
, oldlenp
))
2614 size_t len
= strlen(table
->data
), copied
;
2616 /* This shouldn't trigger for a well-formed sysctl */
2617 if (len
> table
->maxlen
)
2618 len
= table
->maxlen
;
2620 /* Copy up to a max of bufsize-1 bytes of the string */
2621 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2623 if (copy_to_user(oldval
, table
->data
, copied
) ||
2624 put_user(0, (char __user
*)(oldval
+ copied
)))
2626 if (put_user(len
, oldlenp
))
2630 if (newval
&& newlen
) {
2631 size_t len
= newlen
;
2632 if (len
> table
->maxlen
)
2633 len
= table
->maxlen
;
2634 if(copy_from_user(table
->data
, newval
, len
))
2636 if (len
== table
->maxlen
)
2638 ((char *) table
->data
)[len
] = 0;
2644 * This function makes sure that all of the integers in the vector
2645 * are between the minimum and maximum values given in the arrays
2646 * table->extra1 and table->extra2, respectively.
2648 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2649 void __user
*oldval
, size_t __user
*oldlenp
,
2650 void __user
*newval
, size_t newlen
)
2653 if (newval
&& newlen
) {
2654 int __user
*vec
= (int __user
*) newval
;
2655 int *min
= (int *) table
->extra1
;
2656 int *max
= (int *) table
->extra2
;
2660 if (newlen
% sizeof(int) != 0)
2663 if (!table
->extra1
&& !table
->extra2
)
2666 if (newlen
> table
->maxlen
)
2667 newlen
= table
->maxlen
;
2668 length
= newlen
/ sizeof(int);
2670 for (i
= 0; i
< length
; i
++) {
2672 if (get_user(value
, vec
+ i
))
2674 if (min
&& value
< min
[i
])
2676 if (max
&& value
> max
[i
])
2683 /* Strategy function to convert jiffies to seconds */
2684 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2685 void __user
*oldval
, size_t __user
*oldlenp
,
2686 void __user
*newval
, size_t newlen
)
2688 if (oldval
&& oldlenp
) {
2691 if (get_user(olen
, oldlenp
))
2696 if (olen
< sizeof(int))
2699 val
= *(int *)(table
->data
) / HZ
;
2700 if (put_user(val
, (int __user
*)oldval
))
2702 if (put_user(sizeof(int), oldlenp
))
2706 if (newval
&& newlen
) {
2708 if (newlen
!= sizeof(int))
2710 if (get_user(new, (int __user
*)newval
))
2712 *(int *)(table
->data
) = new*HZ
;
2717 /* Strategy function to convert jiffies to seconds */
2718 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2719 void __user
*oldval
, size_t __user
*oldlenp
,
2720 void __user
*newval
, size_t newlen
)
2722 if (oldval
&& oldlenp
) {
2725 if (get_user(olen
, oldlenp
))
2730 if (olen
< sizeof(int))
2733 val
= jiffies_to_msecs(*(int *)(table
->data
));
2734 if (put_user(val
, (int __user
*)oldval
))
2736 if (put_user(sizeof(int), oldlenp
))
2740 if (newval
&& newlen
) {
2742 if (newlen
!= sizeof(int))
2744 if (get_user(new, (int __user
*)newval
))
2746 *(int *)(table
->data
) = msecs_to_jiffies(new);
2753 #else /* CONFIG_SYSCTL_SYSCALL */
2756 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2758 struct __sysctl_args tmp
;
2761 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
2764 error
= deprecated_sysctl_warning(&tmp
);
2766 /* If no error reading the parameters then just -ENOSYS ... */
2773 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2774 void __user
*oldval
, size_t __user
*oldlenp
,
2775 void __user
*newval
, size_t newlen
)
2780 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2781 void __user
*oldval
, size_t __user
*oldlenp
,
2782 void __user
*newval
, size_t newlen
)
2787 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2788 void __user
*oldval
, size_t __user
*oldlenp
,
2789 void __user
*newval
, size_t newlen
)
2794 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2795 void __user
*oldval
, size_t __user
*oldlenp
,
2796 void __user
*newval
, size_t newlen
)
2801 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2802 void __user
*oldval
, size_t __user
*oldlenp
,
2803 void __user
*newval
, size_t newlen
)
2808 #endif /* CONFIG_SYSCTL_SYSCALL */
2810 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
2812 static int msg_count
;
2813 int name
[CTL_MAXNAME
];
2816 /* Check args->nlen. */
2817 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
2820 /* Read in the sysctl name for better debug message logging */
2821 for (i
= 0; i
< args
->nlen
; i
++)
2822 if (get_user(name
[i
], args
->name
+ i
))
2825 /* Ignore accesses to kernel.version */
2826 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
2829 if (msg_count
< 5) {
2832 "warning: process `%s' used the deprecated sysctl "
2833 "system call with ", current
->comm
);
2834 for (i
= 0; i
< args
->nlen
; i
++)
2835 printk("%d.", name
[i
]);
2842 * No sense putting this after each symbol definition, twice,
2843 * exception granted :-)
2845 EXPORT_SYMBOL(proc_dointvec
);
2846 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2847 EXPORT_SYMBOL(proc_dointvec_minmax
);
2848 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2849 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2850 EXPORT_SYMBOL(proc_dostring
);
2851 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2852 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2853 EXPORT_SYMBOL(register_sysctl_table
);
2854 EXPORT_SYMBOL(register_sysctl_paths
);
2855 EXPORT_SYMBOL(sysctl_intvec
);
2856 EXPORT_SYMBOL(sysctl_jiffies
);
2857 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2858 EXPORT_SYMBOL(sysctl_string
);
2859 EXPORT_SYMBOL(sysctl_data
);
2860 EXPORT_SYMBOL(unregister_sysctl_table
);