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 max_threads
;
71 extern int core_uses_pid
;
72 extern int suid_dumpable
;
73 extern char core_pattern
[];
75 extern int min_free_kbytes
;
76 extern int printk_ratelimit_jiffies
;
77 extern int printk_ratelimit_burst
;
78 extern int pid_max_min
, pid_max_max
;
79 extern int sysctl_drop_caches
;
80 extern int percpu_pagelist_fraction
;
81 extern int compat_log
;
82 extern int maps_protect
;
83 extern int sysctl_stat_interval
;
84 extern int latencytop_enabled
;
86 /* Constants used for minimum and maximum */
87 #ifdef CONFIG_DETECT_SOFTLOCKUP
89 static int sixty
= 60;
97 static int one_hundred
= 100;
99 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
100 static int maxolduid
= 65535;
101 static int minolduid
;
102 static int min_percpu_pagelist_fract
= 8;
104 static int ngroups_max
= NGROUPS_MAX
;
107 extern char modprobe_path
[];
109 #ifdef CONFIG_CHR_DEV_SG
110 extern int sg_big_buff
;
114 extern char reboot_command
[];
115 extern int stop_a_enabled
;
116 extern int scons_pwroff
;
120 extern int pwrsw_enabled
;
121 extern int unaligned_enabled
;
125 #ifdef CONFIG_MATHEMU
126 extern int sysctl_ieee_emulation_warnings
;
128 extern int sysctl_userprocess_debug
;
129 extern int spin_retry
;
132 extern int sysctl_hz_timer
;
134 #ifdef CONFIG_BSD_PROCESS_ACCT
135 extern int acct_parm
[];
139 extern int no_unaligned_warning
;
142 #ifdef CONFIG_RT_MUTEXES
143 extern int max_lock_depth
;
146 #ifdef CONFIG_SYSCTL_SYSCALL
147 static int parse_table(int __user
*, int, void __user
*, size_t __user
*,
148 void __user
*, size_t, struct ctl_table
*);
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_batch_wakeup_granularity_ns",
273 .data
= &sysctl_sched_batch_wakeup_granularity
,
274 .maxlen
= sizeof(unsigned int),
276 .proc_handler
= &proc_dointvec_minmax
,
277 .strategy
= &sysctl_intvec
,
278 .extra1
= &min_wakeup_granularity_ns
,
279 .extra2
= &max_wakeup_granularity_ns
,
282 .ctl_name
= CTL_UNNUMBERED
,
283 .procname
= "sched_child_runs_first",
284 .data
= &sysctl_sched_child_runs_first
,
285 .maxlen
= sizeof(unsigned int),
287 .proc_handler
= &proc_dointvec
,
290 .ctl_name
= CTL_UNNUMBERED
,
291 .procname
= "sched_features",
292 .data
= &sysctl_sched_features
,
293 .maxlen
= sizeof(unsigned int),
295 .proc_handler
= &proc_dointvec
,
298 .ctl_name
= CTL_UNNUMBERED
,
299 .procname
= "sched_migration_cost",
300 .data
= &sysctl_sched_migration_cost
,
301 .maxlen
= sizeof(unsigned int),
303 .proc_handler
= &proc_dointvec
,
306 .ctl_name
= CTL_UNNUMBERED
,
307 .procname
= "sched_nr_migrate",
308 .data
= &sysctl_sched_nr_migrate
,
309 .maxlen
= sizeof(unsigned int),
311 .proc_handler
= &proc_dointvec
,
314 .ctl_name
= CTL_UNNUMBERED
,
315 .procname
= "sched_rt_period_ms",
316 .data
= &sysctl_sched_rt_period
,
317 .maxlen
= sizeof(unsigned int),
319 .proc_handler
= &proc_dointvec
,
322 .ctl_name
= CTL_UNNUMBERED
,
323 .procname
= "sched_rt_ratio",
324 .data
= &sysctl_sched_rt_ratio
,
325 .maxlen
= sizeof(unsigned int),
327 .proc_handler
= &proc_dointvec
,
329 #if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_SMP)
331 .ctl_name
= CTL_UNNUMBERED
,
332 .procname
= "sched_min_bal_int_shares",
333 .data
= &sysctl_sched_min_bal_int_shares
,
334 .maxlen
= sizeof(unsigned int),
336 .proc_handler
= &proc_dointvec
,
339 .ctl_name
= CTL_UNNUMBERED
,
340 .procname
= "sched_max_bal_int_shares",
341 .data
= &sysctl_sched_max_bal_int_shares
,
342 .maxlen
= sizeof(unsigned int),
344 .proc_handler
= &proc_dointvec
,
349 .ctl_name
= CTL_UNNUMBERED
,
350 .procname
= "sched_compat_yield",
351 .data
= &sysctl_sched_compat_yield
,
352 .maxlen
= sizeof(unsigned int),
354 .proc_handler
= &proc_dointvec
,
356 #ifdef CONFIG_PROVE_LOCKING
358 .ctl_name
= CTL_UNNUMBERED
,
359 .procname
= "prove_locking",
360 .data
= &prove_locking
,
361 .maxlen
= sizeof(int),
363 .proc_handler
= &proc_dointvec
,
366 #ifdef CONFIG_LOCK_STAT
368 .ctl_name
= CTL_UNNUMBERED
,
369 .procname
= "lock_stat",
371 .maxlen
= sizeof(int),
373 .proc_handler
= &proc_dointvec
,
377 .ctl_name
= KERN_PANIC
,
379 .data
= &panic_timeout
,
380 .maxlen
= sizeof(int),
382 .proc_handler
= &proc_dointvec
,
385 .ctl_name
= KERN_CORE_USES_PID
,
386 .procname
= "core_uses_pid",
387 .data
= &core_uses_pid
,
388 .maxlen
= sizeof(int),
390 .proc_handler
= &proc_dointvec
,
393 .ctl_name
= KERN_CORE_PATTERN
,
394 .procname
= "core_pattern",
395 .data
= core_pattern
,
396 .maxlen
= CORENAME_MAX_SIZE
,
398 .proc_handler
= &proc_dostring
,
399 .strategy
= &sysctl_string
,
401 #ifdef CONFIG_PROC_SYSCTL
403 .procname
= "tainted",
405 .maxlen
= sizeof(int),
407 .proc_handler
= &proc_dointvec_taint
,
410 #ifdef CONFIG_LATENCYTOP
412 .procname
= "latencytop",
413 .data
= &latencytop_enabled
,
414 .maxlen
= sizeof(int),
416 .proc_handler
= &proc_dointvec
,
419 #ifdef CONFIG_SECURITY_CAPABILITIES
421 .procname
= "cap-bound",
423 .maxlen
= sizeof(kernel_cap_t
),
425 .proc_handler
= &proc_dointvec_bset
,
427 #endif /* def CONFIG_SECURITY_CAPABILITIES */
428 #ifdef CONFIG_BLK_DEV_INITRD
430 .ctl_name
= KERN_REALROOTDEV
,
431 .procname
= "real-root-dev",
432 .data
= &real_root_dev
,
433 .maxlen
= sizeof(int),
435 .proc_handler
= &proc_dointvec
,
439 .ctl_name
= CTL_UNNUMBERED
,
440 .procname
= "print-fatal-signals",
441 .data
= &print_fatal_signals
,
442 .maxlen
= sizeof(int),
444 .proc_handler
= &proc_dointvec
,
448 .ctl_name
= KERN_SPARC_REBOOT
,
449 .procname
= "reboot-cmd",
450 .data
= reboot_command
,
453 .proc_handler
= &proc_dostring
,
454 .strategy
= &sysctl_string
,
457 .ctl_name
= KERN_SPARC_STOP_A
,
458 .procname
= "stop-a",
459 .data
= &stop_a_enabled
,
460 .maxlen
= sizeof (int),
462 .proc_handler
= &proc_dointvec
,
465 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
466 .procname
= "scons-poweroff",
467 .data
= &scons_pwroff
,
468 .maxlen
= sizeof (int),
470 .proc_handler
= &proc_dointvec
,
475 .ctl_name
= KERN_HPPA_PWRSW
,
476 .procname
= "soft-power",
477 .data
= &pwrsw_enabled
,
478 .maxlen
= sizeof (int),
480 .proc_handler
= &proc_dointvec
,
483 .ctl_name
= KERN_HPPA_UNALIGNED
,
484 .procname
= "unaligned-trap",
485 .data
= &unaligned_enabled
,
486 .maxlen
= sizeof (int),
488 .proc_handler
= &proc_dointvec
,
492 .ctl_name
= KERN_CTLALTDEL
,
493 .procname
= "ctrl-alt-del",
495 .maxlen
= sizeof(int),
497 .proc_handler
= &proc_dointvec
,
500 .ctl_name
= KERN_PRINTK
,
501 .procname
= "printk",
502 .data
= &console_loglevel
,
503 .maxlen
= 4*sizeof(int),
505 .proc_handler
= &proc_dointvec
,
509 .ctl_name
= KERN_MODPROBE
,
510 .procname
= "modprobe",
511 .data
= &modprobe_path
,
512 .maxlen
= KMOD_PATH_LEN
,
514 .proc_handler
= &proc_dostring
,
515 .strategy
= &sysctl_string
,
518 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
520 .ctl_name
= KERN_HOTPLUG
,
521 .procname
= "hotplug",
522 .data
= &uevent_helper
,
523 .maxlen
= UEVENT_HELPER_PATH_LEN
,
525 .proc_handler
= &proc_dostring
,
526 .strategy
= &sysctl_string
,
529 #ifdef CONFIG_CHR_DEV_SG
531 .ctl_name
= KERN_SG_BIG_BUFF
,
532 .procname
= "sg-big-buff",
533 .data
= &sg_big_buff
,
534 .maxlen
= sizeof (int),
536 .proc_handler
= &proc_dointvec
,
539 #ifdef CONFIG_BSD_PROCESS_ACCT
541 .ctl_name
= KERN_ACCT
,
544 .maxlen
= 3*sizeof(int),
546 .proc_handler
= &proc_dointvec
,
549 #ifdef CONFIG_MAGIC_SYSRQ
551 .ctl_name
= KERN_SYSRQ
,
553 .data
= &__sysrq_enabled
,
554 .maxlen
= sizeof (int),
556 .proc_handler
= &proc_dointvec
,
559 #ifdef CONFIG_PROC_SYSCTL
561 .procname
= "cad_pid",
563 .maxlen
= sizeof (int),
565 .proc_handler
= &proc_do_cad_pid
,
569 .ctl_name
= KERN_MAX_THREADS
,
570 .procname
= "threads-max",
571 .data
= &max_threads
,
572 .maxlen
= sizeof(int),
574 .proc_handler
= &proc_dointvec
,
577 .ctl_name
= KERN_RANDOM
,
578 .procname
= "random",
580 .child
= random_table
,
583 .ctl_name
= KERN_OVERFLOWUID
,
584 .procname
= "overflowuid",
585 .data
= &overflowuid
,
586 .maxlen
= sizeof(int),
588 .proc_handler
= &proc_dointvec_minmax
,
589 .strategy
= &sysctl_intvec
,
590 .extra1
= &minolduid
,
591 .extra2
= &maxolduid
,
594 .ctl_name
= KERN_OVERFLOWGID
,
595 .procname
= "overflowgid",
596 .data
= &overflowgid
,
597 .maxlen
= sizeof(int),
599 .proc_handler
= &proc_dointvec_minmax
,
600 .strategy
= &sysctl_intvec
,
601 .extra1
= &minolduid
,
602 .extra2
= &maxolduid
,
605 #ifdef CONFIG_MATHEMU
607 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
608 .procname
= "ieee_emulation_warnings",
609 .data
= &sysctl_ieee_emulation_warnings
,
610 .maxlen
= sizeof(int),
612 .proc_handler
= &proc_dointvec
,
615 #ifdef CONFIG_NO_IDLE_HZ
617 .ctl_name
= KERN_HZ_TIMER
,
618 .procname
= "hz_timer",
619 .data
= &sysctl_hz_timer
,
620 .maxlen
= sizeof(int),
622 .proc_handler
= &proc_dointvec
,
626 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
627 .procname
= "userprocess_debug",
628 .data
= &sysctl_userprocess_debug
,
629 .maxlen
= sizeof(int),
631 .proc_handler
= &proc_dointvec
,
635 .ctl_name
= KERN_PIDMAX
,
636 .procname
= "pid_max",
638 .maxlen
= sizeof (int),
640 .proc_handler
= &proc_dointvec_minmax
,
641 .strategy
= sysctl_intvec
,
642 .extra1
= &pid_max_min
,
643 .extra2
= &pid_max_max
,
646 .ctl_name
= KERN_PANIC_ON_OOPS
,
647 .procname
= "panic_on_oops",
648 .data
= &panic_on_oops
,
649 .maxlen
= sizeof(int),
651 .proc_handler
= &proc_dointvec
,
654 .ctl_name
= KERN_PRINTK_RATELIMIT
,
655 .procname
= "printk_ratelimit",
656 .data
= &printk_ratelimit_jiffies
,
657 .maxlen
= sizeof(int),
659 .proc_handler
= &proc_dointvec_jiffies
,
660 .strategy
= &sysctl_jiffies
,
663 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
664 .procname
= "printk_ratelimit_burst",
665 .data
= &printk_ratelimit_burst
,
666 .maxlen
= sizeof(int),
668 .proc_handler
= &proc_dointvec
,
671 .ctl_name
= KERN_NGROUPS_MAX
,
672 .procname
= "ngroups_max",
673 .data
= &ngroups_max
,
674 .maxlen
= sizeof (int),
676 .proc_handler
= &proc_dointvec
,
678 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
680 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
681 .procname
= "unknown_nmi_panic",
682 .data
= &unknown_nmi_panic
,
683 .maxlen
= sizeof (int),
685 .proc_handler
= &proc_dointvec
,
688 .procname
= "nmi_watchdog",
689 .data
= &nmi_watchdog_enabled
,
690 .maxlen
= sizeof (int),
692 .proc_handler
= &proc_nmi_enabled
,
695 #if defined(CONFIG_X86)
697 .ctl_name
= KERN_PANIC_ON_NMI
,
698 .procname
= "panic_on_unrecovered_nmi",
699 .data
= &panic_on_unrecovered_nmi
,
700 .maxlen
= sizeof(int),
702 .proc_handler
= &proc_dointvec
,
705 .ctl_name
= KERN_BOOTLOADER_TYPE
,
706 .procname
= "bootloader_type",
707 .data
= &bootloader_type
,
708 .maxlen
= sizeof (int),
710 .proc_handler
= &proc_dointvec
,
713 .ctl_name
= CTL_UNNUMBERED
,
714 .procname
= "kstack_depth_to_print",
715 .data
= &kstack_depth_to_print
,
716 .maxlen
= sizeof(int),
718 .proc_handler
= &proc_dointvec
,
721 .ctl_name
= CTL_UNNUMBERED
,
722 .procname
= "io_delay_type",
723 .data
= &io_delay_type
,
724 .maxlen
= sizeof(int),
726 .proc_handler
= &proc_dointvec
,
729 #if defined(CONFIG_MMU)
731 .ctl_name
= KERN_RANDOMIZE
,
732 .procname
= "randomize_va_space",
733 .data
= &randomize_va_space
,
734 .maxlen
= sizeof(int),
736 .proc_handler
= &proc_dointvec
,
739 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
741 .ctl_name
= KERN_SPIN_RETRY
,
742 .procname
= "spin_retry",
744 .maxlen
= sizeof (int),
746 .proc_handler
= &proc_dointvec
,
749 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
751 .procname
= "acpi_video_flags",
752 .data
= &acpi_realmode_flags
,
753 .maxlen
= sizeof (unsigned long),
755 .proc_handler
= &proc_doulongvec_minmax
,
760 .ctl_name
= KERN_IA64_UNALIGNED
,
761 .procname
= "ignore-unaligned-usertrap",
762 .data
= &no_unaligned_warning
,
763 .maxlen
= sizeof (int),
765 .proc_handler
= &proc_dointvec
,
768 #ifdef CONFIG_DETECT_SOFTLOCKUP
770 .ctl_name
= CTL_UNNUMBERED
,
771 .procname
= "softlockup_thresh",
772 .data
= &softlockup_thresh
,
773 .maxlen
= sizeof(unsigned long),
775 .proc_handler
= &proc_doulongvec_minmax
,
776 .strategy
= &sysctl_intvec
,
781 .ctl_name
= CTL_UNNUMBERED
,
782 .procname
= "hung_task_check_count",
783 .data
= &sysctl_hung_task_check_count
,
784 .maxlen
= sizeof(unsigned long),
786 .proc_handler
= &proc_doulongvec_minmax
,
787 .strategy
= &sysctl_intvec
,
790 .ctl_name
= CTL_UNNUMBERED
,
791 .procname
= "hung_task_timeout_secs",
792 .data
= &sysctl_hung_task_timeout_secs
,
793 .maxlen
= sizeof(unsigned long),
795 .proc_handler
= &proc_doulongvec_minmax
,
796 .strategy
= &sysctl_intvec
,
799 .ctl_name
= CTL_UNNUMBERED
,
800 .procname
= "hung_task_warnings",
801 .data
= &sysctl_hung_task_warnings
,
802 .maxlen
= sizeof(unsigned long),
804 .proc_handler
= &proc_doulongvec_minmax
,
805 .strategy
= &sysctl_intvec
,
810 .ctl_name
= KERN_COMPAT_LOG
,
811 .procname
= "compat-log",
813 .maxlen
= sizeof (int),
815 .proc_handler
= &proc_dointvec
,
818 #ifdef CONFIG_RT_MUTEXES
820 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
821 .procname
= "max_lock_depth",
822 .data
= &max_lock_depth
,
823 .maxlen
= sizeof(int),
825 .proc_handler
= &proc_dointvec
,
828 #ifdef CONFIG_PROC_FS
830 .ctl_name
= CTL_UNNUMBERED
,
831 .procname
= "maps_protect",
832 .data
= &maps_protect
,
833 .maxlen
= sizeof(int),
835 .proc_handler
= &proc_dointvec
,
839 .ctl_name
= CTL_UNNUMBERED
,
840 .procname
= "poweroff_cmd",
841 .data
= &poweroff_cmd
,
842 .maxlen
= POWEROFF_CMD_PATH_LEN
,
844 .proc_handler
= &proc_dostring
,
845 .strategy
= &sysctl_string
,
848 * NOTE: do not add new entries to this table unless you have read
849 * Documentation/sysctl/ctl_unnumbered.txt
854 static struct ctl_table vm_table
[] = {
856 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
857 .procname
= "overcommit_memory",
858 .data
= &sysctl_overcommit_memory
,
859 .maxlen
= sizeof(sysctl_overcommit_memory
),
861 .proc_handler
= &proc_dointvec
,
864 .ctl_name
= VM_PANIC_ON_OOM
,
865 .procname
= "panic_on_oom",
866 .data
= &sysctl_panic_on_oom
,
867 .maxlen
= sizeof(sysctl_panic_on_oom
),
869 .proc_handler
= &proc_dointvec
,
872 .ctl_name
= CTL_UNNUMBERED
,
873 .procname
= "oom_kill_allocating_task",
874 .data
= &sysctl_oom_kill_allocating_task
,
875 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
877 .proc_handler
= &proc_dointvec
,
880 .ctl_name
= VM_OVERCOMMIT_RATIO
,
881 .procname
= "overcommit_ratio",
882 .data
= &sysctl_overcommit_ratio
,
883 .maxlen
= sizeof(sysctl_overcommit_ratio
),
885 .proc_handler
= &proc_dointvec
,
888 .ctl_name
= VM_PAGE_CLUSTER
,
889 .procname
= "page-cluster",
890 .data
= &page_cluster
,
891 .maxlen
= sizeof(int),
893 .proc_handler
= &proc_dointvec
,
896 .ctl_name
= VM_DIRTY_BACKGROUND
,
897 .procname
= "dirty_background_ratio",
898 .data
= &dirty_background_ratio
,
899 .maxlen
= sizeof(dirty_background_ratio
),
901 .proc_handler
= &proc_dointvec_minmax
,
902 .strategy
= &sysctl_intvec
,
904 .extra2
= &one_hundred
,
907 .ctl_name
= VM_DIRTY_RATIO
,
908 .procname
= "dirty_ratio",
909 .data
= &vm_dirty_ratio
,
910 .maxlen
= sizeof(vm_dirty_ratio
),
912 .proc_handler
= &dirty_ratio_handler
,
913 .strategy
= &sysctl_intvec
,
915 .extra2
= &one_hundred
,
918 .procname
= "dirty_writeback_centisecs",
919 .data
= &dirty_writeback_interval
,
920 .maxlen
= sizeof(dirty_writeback_interval
),
922 .proc_handler
= &dirty_writeback_centisecs_handler
,
925 .procname
= "dirty_expire_centisecs",
926 .data
= &dirty_expire_interval
,
927 .maxlen
= sizeof(dirty_expire_interval
),
929 .proc_handler
= &proc_dointvec_userhz_jiffies
,
932 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
933 .procname
= "nr_pdflush_threads",
934 .data
= &nr_pdflush_threads
,
935 .maxlen
= sizeof nr_pdflush_threads
,
936 .mode
= 0444 /* read-only*/,
937 .proc_handler
= &proc_dointvec
,
940 .ctl_name
= VM_SWAPPINESS
,
941 .procname
= "swappiness",
942 .data
= &vm_swappiness
,
943 .maxlen
= sizeof(vm_swappiness
),
945 .proc_handler
= &proc_dointvec_minmax
,
946 .strategy
= &sysctl_intvec
,
948 .extra2
= &one_hundred
,
950 #ifdef CONFIG_HUGETLB_PAGE
952 .procname
= "nr_hugepages",
953 .data
= &max_huge_pages
,
954 .maxlen
= sizeof(unsigned long),
956 .proc_handler
= &hugetlb_sysctl_handler
,
957 .extra1
= (void *)&hugetlb_zero
,
958 .extra2
= (void *)&hugetlb_infinity
,
961 .ctl_name
= VM_HUGETLB_GROUP
,
962 .procname
= "hugetlb_shm_group",
963 .data
= &sysctl_hugetlb_shm_group
,
964 .maxlen
= sizeof(gid_t
),
966 .proc_handler
= &proc_dointvec
,
969 .ctl_name
= CTL_UNNUMBERED
,
970 .procname
= "hugepages_treat_as_movable",
971 .data
= &hugepages_treat_as_movable
,
972 .maxlen
= sizeof(int),
974 .proc_handler
= &hugetlb_treat_movable_handler
,
977 .ctl_name
= CTL_UNNUMBERED
,
978 .procname
= "nr_overcommit_hugepages",
979 .data
= &nr_overcommit_huge_pages
,
980 .maxlen
= sizeof(nr_overcommit_huge_pages
),
982 .proc_handler
= &proc_doulongvec_minmax
,
986 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
987 .procname
= "lowmem_reserve_ratio",
988 .data
= &sysctl_lowmem_reserve_ratio
,
989 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
991 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
992 .strategy
= &sysctl_intvec
,
995 .ctl_name
= VM_DROP_PAGECACHE
,
996 .procname
= "drop_caches",
997 .data
= &sysctl_drop_caches
,
998 .maxlen
= sizeof(int),
1000 .proc_handler
= drop_caches_sysctl_handler
,
1001 .strategy
= &sysctl_intvec
,
1004 .ctl_name
= VM_MIN_FREE_KBYTES
,
1005 .procname
= "min_free_kbytes",
1006 .data
= &min_free_kbytes
,
1007 .maxlen
= sizeof(min_free_kbytes
),
1009 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1010 .strategy
= &sysctl_intvec
,
1014 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1015 .procname
= "percpu_pagelist_fraction",
1016 .data
= &percpu_pagelist_fraction
,
1017 .maxlen
= sizeof(percpu_pagelist_fraction
),
1019 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1020 .strategy
= &sysctl_intvec
,
1021 .extra1
= &min_percpu_pagelist_fract
,
1025 .ctl_name
= VM_MAX_MAP_COUNT
,
1026 .procname
= "max_map_count",
1027 .data
= &sysctl_max_map_count
,
1028 .maxlen
= sizeof(sysctl_max_map_count
),
1030 .proc_handler
= &proc_dointvec
1034 .ctl_name
= VM_LAPTOP_MODE
,
1035 .procname
= "laptop_mode",
1036 .data
= &laptop_mode
,
1037 .maxlen
= sizeof(laptop_mode
),
1039 .proc_handler
= &proc_dointvec_jiffies
,
1040 .strategy
= &sysctl_jiffies
,
1043 .ctl_name
= VM_BLOCK_DUMP
,
1044 .procname
= "block_dump",
1045 .data
= &block_dump
,
1046 .maxlen
= sizeof(block_dump
),
1048 .proc_handler
= &proc_dointvec
,
1049 .strategy
= &sysctl_intvec
,
1053 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1054 .procname
= "vfs_cache_pressure",
1055 .data
= &sysctl_vfs_cache_pressure
,
1056 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1058 .proc_handler
= &proc_dointvec
,
1059 .strategy
= &sysctl_intvec
,
1062 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1064 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1065 .procname
= "legacy_va_layout",
1066 .data
= &sysctl_legacy_va_layout
,
1067 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1069 .proc_handler
= &proc_dointvec
,
1070 .strategy
= &sysctl_intvec
,
1076 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1077 .procname
= "zone_reclaim_mode",
1078 .data
= &zone_reclaim_mode
,
1079 .maxlen
= sizeof(zone_reclaim_mode
),
1081 .proc_handler
= &proc_dointvec
,
1082 .strategy
= &sysctl_intvec
,
1086 .ctl_name
= VM_MIN_UNMAPPED
,
1087 .procname
= "min_unmapped_ratio",
1088 .data
= &sysctl_min_unmapped_ratio
,
1089 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1091 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1092 .strategy
= &sysctl_intvec
,
1094 .extra2
= &one_hundred
,
1097 .ctl_name
= VM_MIN_SLAB
,
1098 .procname
= "min_slab_ratio",
1099 .data
= &sysctl_min_slab_ratio
,
1100 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1102 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1103 .strategy
= &sysctl_intvec
,
1105 .extra2
= &one_hundred
,
1110 .ctl_name
= CTL_UNNUMBERED
,
1111 .procname
= "stat_interval",
1112 .data
= &sysctl_stat_interval
,
1113 .maxlen
= sizeof(sysctl_stat_interval
),
1115 .proc_handler
= &proc_dointvec_jiffies
,
1116 .strategy
= &sysctl_jiffies
,
1119 #ifdef CONFIG_SECURITY
1121 .ctl_name
= CTL_UNNUMBERED
,
1122 .procname
= "mmap_min_addr",
1123 .data
= &mmap_min_addr
,
1124 .maxlen
= sizeof(unsigned long),
1126 .proc_handler
= &proc_doulongvec_minmax
,
1131 .ctl_name
= CTL_UNNUMBERED
,
1132 .procname
= "numa_zonelist_order",
1133 .data
= &numa_zonelist_order
,
1134 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1136 .proc_handler
= &numa_zonelist_order_handler
,
1137 .strategy
= &sysctl_string
,
1140 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1141 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1143 .ctl_name
= VM_VDSO_ENABLED
,
1144 .procname
= "vdso_enabled",
1145 .data
= &vdso_enabled
,
1146 .maxlen
= sizeof(vdso_enabled
),
1148 .proc_handler
= &proc_dointvec
,
1149 .strategy
= &sysctl_intvec
,
1154 * NOTE: do not add new entries to this table unless you have read
1155 * Documentation/sysctl/ctl_unnumbered.txt
1160 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1161 static struct ctl_table binfmt_misc_table
[] = {
1166 static struct ctl_table fs_table
[] = {
1168 .ctl_name
= FS_NRINODE
,
1169 .procname
= "inode-nr",
1170 .data
= &inodes_stat
,
1171 .maxlen
= 2*sizeof(int),
1173 .proc_handler
= &proc_dointvec
,
1176 .ctl_name
= FS_STATINODE
,
1177 .procname
= "inode-state",
1178 .data
= &inodes_stat
,
1179 .maxlen
= 7*sizeof(int),
1181 .proc_handler
= &proc_dointvec
,
1184 .procname
= "file-nr",
1185 .data
= &files_stat
,
1186 .maxlen
= 3*sizeof(int),
1188 .proc_handler
= &proc_nr_files
,
1191 .ctl_name
= FS_MAXFILE
,
1192 .procname
= "file-max",
1193 .data
= &files_stat
.max_files
,
1194 .maxlen
= sizeof(int),
1196 .proc_handler
= &proc_dointvec
,
1199 .ctl_name
= FS_DENTRY
,
1200 .procname
= "dentry-state",
1201 .data
= &dentry_stat
,
1202 .maxlen
= 6*sizeof(int),
1204 .proc_handler
= &proc_dointvec
,
1207 .ctl_name
= FS_OVERFLOWUID
,
1208 .procname
= "overflowuid",
1209 .data
= &fs_overflowuid
,
1210 .maxlen
= sizeof(int),
1212 .proc_handler
= &proc_dointvec_minmax
,
1213 .strategy
= &sysctl_intvec
,
1214 .extra1
= &minolduid
,
1215 .extra2
= &maxolduid
,
1218 .ctl_name
= FS_OVERFLOWGID
,
1219 .procname
= "overflowgid",
1220 .data
= &fs_overflowgid
,
1221 .maxlen
= sizeof(int),
1223 .proc_handler
= &proc_dointvec_minmax
,
1224 .strategy
= &sysctl_intvec
,
1225 .extra1
= &minolduid
,
1226 .extra2
= &maxolduid
,
1229 .ctl_name
= FS_LEASES
,
1230 .procname
= "leases-enable",
1231 .data
= &leases_enable
,
1232 .maxlen
= sizeof(int),
1234 .proc_handler
= &proc_dointvec
,
1236 #ifdef CONFIG_DNOTIFY
1238 .ctl_name
= FS_DIR_NOTIFY
,
1239 .procname
= "dir-notify-enable",
1240 .data
= &dir_notify_enable
,
1241 .maxlen
= sizeof(int),
1243 .proc_handler
= &proc_dointvec
,
1248 .ctl_name
= FS_LEASE_TIME
,
1249 .procname
= "lease-break-time",
1250 .data
= &lease_break_time
,
1251 .maxlen
= sizeof(int),
1253 .proc_handler
= &proc_dointvec_minmax
,
1254 .strategy
= &sysctl_intvec
,
1259 .procname
= "aio-nr",
1261 .maxlen
= sizeof(aio_nr
),
1263 .proc_handler
= &proc_doulongvec_minmax
,
1266 .procname
= "aio-max-nr",
1267 .data
= &aio_max_nr
,
1268 .maxlen
= sizeof(aio_max_nr
),
1270 .proc_handler
= &proc_doulongvec_minmax
,
1272 #ifdef CONFIG_INOTIFY_USER
1274 .ctl_name
= FS_INOTIFY
,
1275 .procname
= "inotify",
1277 .child
= inotify_table
,
1282 .ctl_name
= KERN_SETUID_DUMPABLE
,
1283 .procname
= "suid_dumpable",
1284 .data
= &suid_dumpable
,
1285 .maxlen
= sizeof(int),
1287 .proc_handler
= &proc_dointvec
,
1289 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1291 .ctl_name
= CTL_UNNUMBERED
,
1292 .procname
= "binfmt_misc",
1294 .child
= binfmt_misc_table
,
1298 * NOTE: do not add new entries to this table unless you have read
1299 * Documentation/sysctl/ctl_unnumbered.txt
1304 static struct ctl_table debug_table
[] = {
1305 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1307 .ctl_name
= CTL_UNNUMBERED
,
1308 .procname
= "exception-trace",
1309 .data
= &show_unhandled_signals
,
1310 .maxlen
= sizeof(int),
1312 .proc_handler
= proc_dointvec
1318 static struct ctl_table dev_table
[] = {
1322 static DEFINE_SPINLOCK(sysctl_lock
);
1324 /* called under sysctl_lock */
1325 static int use_table(struct ctl_table_header
*p
)
1327 if (unlikely(p
->unregistering
))
1333 /* called under sysctl_lock */
1334 static void unuse_table(struct ctl_table_header
*p
)
1337 if (unlikely(p
->unregistering
))
1338 complete(p
->unregistering
);
1341 /* called under sysctl_lock, will reacquire if has to wait */
1342 static void start_unregistering(struct ctl_table_header
*p
)
1345 * if p->used is 0, nobody will ever touch that entry again;
1346 * we'll eliminate all paths to it before dropping sysctl_lock
1348 if (unlikely(p
->used
)) {
1349 struct completion wait
;
1350 init_completion(&wait
);
1351 p
->unregistering
= &wait
;
1352 spin_unlock(&sysctl_lock
);
1353 wait_for_completion(&wait
);
1354 spin_lock(&sysctl_lock
);
1357 * do not remove from the list until nobody holds it; walking the
1358 * list in do_sysctl() relies on that.
1360 list_del_init(&p
->ctl_entry
);
1363 void sysctl_head_finish(struct ctl_table_header
*head
)
1367 spin_lock(&sysctl_lock
);
1369 spin_unlock(&sysctl_lock
);
1372 static struct list_head
*
1373 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1375 struct list_head
*header_list
;
1376 header_list
= &root
->header_list
;
1378 header_list
= root
->lookup(root
, namespaces
);
1382 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1383 struct ctl_table_header
*prev
)
1385 struct ctl_table_root
*root
;
1386 struct list_head
*header_list
;
1387 struct ctl_table_header
*head
;
1388 struct list_head
*tmp
;
1390 spin_lock(&sysctl_lock
);
1393 tmp
= &prev
->ctl_entry
;
1397 tmp
= &root_table_header
.ctl_entry
;
1399 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1401 if (!use_table(head
))
1403 spin_unlock(&sysctl_lock
);
1408 header_list
= lookup_header_list(root
, namespaces
);
1409 if (tmp
!= header_list
)
1413 root
= list_entry(root
->root_list
.next
,
1414 struct ctl_table_root
, root_list
);
1415 if (root
== &sysctl_table_root
)
1417 header_list
= lookup_header_list(root
, namespaces
);
1418 } while (list_empty(header_list
));
1419 tmp
= header_list
->next
;
1422 spin_unlock(&sysctl_lock
);
1426 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1428 return __sysctl_head_next(current
->nsproxy
, prev
);
1431 void register_sysctl_root(struct ctl_table_root
*root
)
1433 spin_lock(&sysctl_lock
);
1434 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1435 spin_unlock(&sysctl_lock
);
1438 #ifdef CONFIG_SYSCTL_SYSCALL
1439 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1440 void __user
*newval
, size_t newlen
)
1442 struct ctl_table_header
*head
;
1443 int error
= -ENOTDIR
;
1445 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1449 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1453 for (head
= sysctl_head_next(NULL
); head
;
1454 head
= sysctl_head_next(head
)) {
1455 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1456 newval
, newlen
, head
->ctl_table
);
1457 if (error
!= -ENOTDIR
) {
1458 sysctl_head_finish(head
);
1465 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1467 struct __sysctl_args tmp
;
1470 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1473 error
= deprecated_sysctl_warning(&tmp
);
1478 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1479 tmp
.newval
, tmp
.newlen
);
1484 #endif /* CONFIG_SYSCTL_SYSCALL */
1487 * sysctl_perm does NOT grant the superuser all rights automatically, because
1488 * some sysctl variables are readonly even to root.
1491 static int test_perm(int mode
, int op
)
1495 else if (in_egroup_p(0))
1497 if ((mode
& op
& 0007) == op
)
1502 int sysctl_perm(struct ctl_table
*table
, int op
)
1505 error
= security_sysctl(table
, op
);
1508 return test_perm(table
->mode
, op
);
1511 #ifdef CONFIG_SYSCTL_SYSCALL
1512 static int parse_table(int __user
*name
, int nlen
,
1513 void __user
*oldval
, size_t __user
*oldlenp
,
1514 void __user
*newval
, size_t newlen
,
1515 struct ctl_table
*table
)
1521 if (get_user(n
, name
))
1523 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1524 if (!table
->ctl_name
)
1526 if (n
== table
->ctl_name
) {
1529 if (sysctl_perm(table
, 001))
1533 table
= table
->child
;
1536 error
= do_sysctl_strategy(table
, name
, nlen
,
1545 /* Perform the actual read/write of a sysctl table entry. */
1546 int do_sysctl_strategy (struct ctl_table
*table
,
1547 int __user
*name
, int nlen
,
1548 void __user
*oldval
, size_t __user
*oldlenp
,
1549 void __user
*newval
, size_t newlen
)
1557 if (sysctl_perm(table
, op
))
1560 if (table
->strategy
) {
1561 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1569 /* If there is no strategy routine, or if the strategy returns
1570 * zero, proceed with automatic r/w */
1571 if (table
->data
&& table
->maxlen
) {
1572 rc
= sysctl_data(table
, name
, nlen
, oldval
, oldlenp
,
1579 #endif /* CONFIG_SYSCTL_SYSCALL */
1581 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1583 for (; table
->ctl_name
|| table
->procname
; table
++) {
1584 table
->parent
= parent
;
1586 sysctl_set_parent(table
, table
->child
);
1590 static __init
int sysctl_init(void)
1593 sysctl_set_parent(NULL
, root_table
);
1594 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1598 core_initcall(sysctl_init
);
1601 * __register_sysctl_paths - register a sysctl hierarchy
1602 * @root: List of sysctl headers to register on
1603 * @namespaces: Data to compute which lists of sysctl entries are visible
1604 * @path: The path to the directory the sysctl table is in.
1605 * @table: the top-level table structure
1607 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1608 * array. A completely 0 filled entry terminates the table.
1610 * The members of the &struct ctl_table structure are used as follows:
1612 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1613 * must be unique within that level of sysctl
1615 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1616 * enter a sysctl file
1618 * data - a pointer to data for use by proc_handler
1620 * maxlen - the maximum size in bytes of the data
1622 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1624 * child - a pointer to the child sysctl table if this entry is a directory, or
1627 * proc_handler - the text handler routine (described below)
1629 * strategy - the strategy routine (described below)
1631 * de - for internal use by the sysctl routines
1633 * extra1, extra2 - extra pointers usable by the proc handler routines
1635 * Leaf nodes in the sysctl tree will be represented by a single file
1636 * under /proc; non-leaf nodes will be represented by directories.
1638 * sysctl(2) can automatically manage read and write requests through
1639 * the sysctl table. The data and maxlen fields of the ctl_table
1640 * struct enable minimal validation of the values being written to be
1641 * performed, and the mode field allows minimal authentication.
1643 * More sophisticated management can be enabled by the provision of a
1644 * strategy routine with the table entry. This will be called before
1645 * any automatic read or write of the data is performed.
1647 * The strategy routine may return
1649 * < 0 - Error occurred (error is passed to user process)
1651 * 0 - OK - proceed with automatic read or write.
1653 * > 0 - OK - read or write has been done by the strategy routine, so
1654 * return immediately.
1656 * There must be a proc_handler routine for any terminal nodes
1657 * mirrored under /proc/sys (non-terminals are handled by a built-in
1658 * directory handler). Several default handlers are available to
1659 * cover common cases -
1661 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1662 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1663 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1665 * It is the handler's job to read the input buffer from user memory
1666 * and process it. The handler should return 0 on success.
1668 * This routine returns %NULL on a failure to register, and a pointer
1669 * to the table header on success.
1671 struct ctl_table_header
*__register_sysctl_paths(
1672 struct ctl_table_root
*root
,
1673 struct nsproxy
*namespaces
,
1674 const struct ctl_path
*path
, struct ctl_table
*table
)
1676 struct list_head
*header_list
;
1677 struct ctl_table_header
*header
;
1678 struct ctl_table
*new, **prevp
;
1679 unsigned int n
, npath
;
1681 /* Count the path components */
1682 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
1686 * For each path component, allocate a 2-element ctl_table array.
1687 * The first array element will be filled with the sysctl entry
1688 * for this, the second will be the sentinel (ctl_name == 0).
1690 * We allocate everything in one go so that we don't have to
1691 * worry about freeing additional memory in unregister_sysctl_table.
1693 header
= kzalloc(sizeof(struct ctl_table_header
) +
1694 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1698 new = (struct ctl_table
*) (header
+ 1);
1700 /* Now connect the dots */
1701 prevp
= &header
->ctl_table
;
1702 for (n
= 0; n
< npath
; ++n
, ++path
) {
1703 /* Copy the procname */
1704 new->procname
= path
->procname
;
1705 new->ctl_name
= path
->ctl_name
;
1709 prevp
= &new->child
;
1714 header
->ctl_table_arg
= table
;
1716 INIT_LIST_HEAD(&header
->ctl_entry
);
1718 header
->unregistering
= NULL
;
1719 header
->root
= root
;
1720 sysctl_set_parent(NULL
, header
->ctl_table
);
1721 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1725 spin_lock(&sysctl_lock
);
1726 header_list
= lookup_header_list(root
, namespaces
);
1727 list_add_tail(&header
->ctl_entry
, header_list
);
1728 spin_unlock(&sysctl_lock
);
1734 * register_sysctl_table_path - register a sysctl table hierarchy
1735 * @path: The path to the directory the sysctl table is in.
1736 * @table: the top-level table structure
1738 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1739 * array. A completely 0 filled entry terminates the table.
1741 * See __register_sysctl_paths for more details.
1743 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1744 struct ctl_table
*table
)
1746 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1751 * register_sysctl_table - register a sysctl table hierarchy
1752 * @table: the top-level table structure
1754 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1755 * array. A completely 0 filled entry terminates the table.
1757 * See register_sysctl_paths for more details.
1759 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1761 static const struct ctl_path null_path
[] = { {} };
1763 return register_sysctl_paths(null_path
, table
);
1767 * unregister_sysctl_table - unregister a sysctl table hierarchy
1768 * @header: the header returned from register_sysctl_table
1770 * Unregisters the sysctl table and all children. proc entries may not
1771 * actually be removed until they are no longer used by anyone.
1773 void unregister_sysctl_table(struct ctl_table_header
* header
)
1780 spin_lock(&sysctl_lock
);
1781 start_unregistering(header
);
1782 spin_unlock(&sysctl_lock
);
1786 #else /* !CONFIG_SYSCTL */
1787 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1792 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1793 struct ctl_table
*table
)
1798 void unregister_sysctl_table(struct ctl_table_header
* table
)
1802 #endif /* CONFIG_SYSCTL */
1808 #ifdef CONFIG_PROC_SYSCTL
1810 static int _proc_do_string(void* data
, int maxlen
, int write
,
1811 struct file
*filp
, void __user
*buffer
,
1812 size_t *lenp
, loff_t
*ppos
)
1818 if (!data
|| !maxlen
|| !*lenp
) {
1826 while (len
< *lenp
) {
1827 if (get_user(c
, p
++))
1829 if (c
== 0 || c
== '\n')
1835 if(copy_from_user(data
, buffer
, len
))
1837 ((char *) data
)[len
] = 0;
1855 if(copy_to_user(buffer
, data
, len
))
1858 if(put_user('\n', ((char __user
*) buffer
) + len
))
1869 * proc_dostring - read a string sysctl
1870 * @table: the sysctl table
1871 * @write: %TRUE if this is a write to the sysctl file
1872 * @filp: the file structure
1873 * @buffer: the user buffer
1874 * @lenp: the size of the user buffer
1875 * @ppos: file position
1877 * Reads/writes a string from/to the user buffer. If the kernel
1878 * buffer provided is not large enough to hold the string, the
1879 * string is truncated. The copied string is %NULL-terminated.
1880 * If the string is being read by the user process, it is copied
1881 * and a newline '\n' is added. It is truncated if the buffer is
1884 * Returns 0 on success.
1886 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
1887 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1889 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
1890 buffer
, lenp
, ppos
);
1894 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1896 int write
, void *data
)
1899 *valp
= *negp
? -*lvalp
: *lvalp
;
1904 *lvalp
= (unsigned long)-val
;
1907 *lvalp
= (unsigned long)val
;
1913 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1914 int write
, struct file
*filp
, void __user
*buffer
,
1915 size_t *lenp
, loff_t
*ppos
,
1916 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1917 int write
, void *data
),
1920 #define TMPBUFLEN 21
1921 int *i
, vleft
, first
=1, neg
, val
;
1925 char buf
[TMPBUFLEN
], *p
;
1926 char __user
*s
= buffer
;
1928 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
1929 (*ppos
&& !write
)) {
1934 i
= (int *) tbl_data
;
1935 vleft
= table
->maxlen
/ sizeof(*i
);
1939 conv
= do_proc_dointvec_conv
;
1941 for (; left
&& vleft
--; i
++, first
=0) {
1956 if (len
> sizeof(buf
) - 1)
1957 len
= sizeof(buf
) - 1;
1958 if (copy_from_user(buf
, s
, len
))
1962 if (*p
== '-' && left
> 1) {
1966 if (*p
< '0' || *p
> '9')
1969 lval
= simple_strtoul(p
, &p
, 0);
1972 if ((len
< left
) && *p
&& !isspace(*p
))
1979 if (conv(&neg
, &lval
, i
, 1, data
))
1986 if (conv(&neg
, &lval
, i
, 0, data
))
1989 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
1993 if(copy_to_user(s
, buf
, len
))
2000 if (!write
&& !first
&& left
) {
2001 if(put_user('\n', s
))
2008 if (get_user(c
, s
++))
2023 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2024 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2025 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2026 int write
, void *data
),
2029 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2030 buffer
, lenp
, ppos
, conv
, data
);
2034 * proc_dointvec - read a vector of integers
2035 * @table: the sysctl table
2036 * @write: %TRUE if this is a write to the sysctl file
2037 * @filp: the file structure
2038 * @buffer: the user buffer
2039 * @lenp: the size of the user buffer
2040 * @ppos: file position
2042 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2043 * values from/to the user buffer, treated as an ASCII string.
2045 * Returns 0 on success.
2047 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2048 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2050 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2058 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
2060 int write
, void *data
)
2062 int op
= *(int *)data
;
2064 int val
= *negp
? -*lvalp
: *lvalp
;
2066 case OP_SET
: *valp
= val
; break;
2067 case OP_AND
: *valp
&= val
; break;
2068 case OP_OR
: *valp
|= val
; break;
2074 *lvalp
= (unsigned long)-val
;
2077 *lvalp
= (unsigned long)val
;
2083 #ifdef CONFIG_SECURITY_CAPABILITIES
2085 * init may raise the set.
2088 int proc_dointvec_bset(struct ctl_table
*table
, int write
, struct file
*filp
,
2089 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2093 if (write
&& !capable(CAP_SYS_MODULE
)) {
2097 op
= is_global_init(current
) ? OP_SET
: OP_AND
;
2098 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2099 do_proc_dointvec_bset_conv
,&op
);
2101 #endif /* def CONFIG_SECURITY_CAPABILITIES */
2104 * Taint values can only be increased
2106 static int proc_dointvec_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2107 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2111 if (write
&& !capable(CAP_SYS_ADMIN
))
2115 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2116 do_proc_dointvec_bset_conv
,&op
);
2119 struct do_proc_dointvec_minmax_conv_param
{
2124 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2126 int write
, void *data
)
2128 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2130 int val
= *negp
? -*lvalp
: *lvalp
;
2131 if ((param
->min
&& *param
->min
> val
) ||
2132 (param
->max
&& *param
->max
< val
))
2139 *lvalp
= (unsigned long)-val
;
2142 *lvalp
= (unsigned long)val
;
2149 * proc_dointvec_minmax - read a vector of integers with min/max values
2150 * @table: the sysctl table
2151 * @write: %TRUE if this is a write to the sysctl file
2152 * @filp: the file structure
2153 * @buffer: the user buffer
2154 * @lenp: the size of the user buffer
2155 * @ppos: file position
2157 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2158 * values from/to the user buffer, treated as an ASCII string.
2160 * This routine will ensure the values are within the range specified by
2161 * table->extra1 (min) and table->extra2 (max).
2163 * Returns 0 on success.
2165 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2166 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2168 struct do_proc_dointvec_minmax_conv_param param
= {
2169 .min
= (int *) table
->extra1
,
2170 .max
= (int *) table
->extra2
,
2172 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2173 do_proc_dointvec_minmax_conv
, ¶m
);
2176 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2178 void __user
*buffer
,
2179 size_t *lenp
, loff_t
*ppos
,
2180 unsigned long convmul
,
2181 unsigned long convdiv
)
2183 #define TMPBUFLEN 21
2184 unsigned long *i
, *min
, *max
, val
;
2185 int vleft
, first
=1, neg
;
2187 char buf
[TMPBUFLEN
], *p
;
2188 char __user
*s
= buffer
;
2190 if (!data
|| !table
->maxlen
|| !*lenp
||
2191 (*ppos
&& !write
)) {
2196 i
= (unsigned long *) data
;
2197 min
= (unsigned long *) table
->extra1
;
2198 max
= (unsigned long *) table
->extra2
;
2199 vleft
= table
->maxlen
/ sizeof(unsigned long);
2202 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2217 if (len
> TMPBUFLEN
-1)
2219 if (copy_from_user(buf
, s
, len
))
2223 if (*p
== '-' && left
> 1) {
2227 if (*p
< '0' || *p
> '9')
2229 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2231 if ((len
< left
) && *p
&& !isspace(*p
))
2240 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2247 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2251 if(copy_to_user(s
, buf
, len
))
2258 if (!write
&& !first
&& left
) {
2259 if(put_user('\n', s
))
2266 if (get_user(c
, s
++))
2281 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2283 void __user
*buffer
,
2284 size_t *lenp
, loff_t
*ppos
,
2285 unsigned long convmul
,
2286 unsigned long convdiv
)
2288 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2289 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2293 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2294 * @table: the sysctl table
2295 * @write: %TRUE if this is a write to the sysctl file
2296 * @filp: the file structure
2297 * @buffer: the user buffer
2298 * @lenp: the size of the user buffer
2299 * @ppos: file position
2301 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2302 * values from/to the user buffer, treated as an ASCII string.
2304 * This routine will ensure the values are within the range specified by
2305 * table->extra1 (min) and table->extra2 (max).
2307 * Returns 0 on success.
2309 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2310 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2312 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2316 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2317 * @table: the sysctl table
2318 * @write: %TRUE if this is a write to the sysctl file
2319 * @filp: the file structure
2320 * @buffer: the user buffer
2321 * @lenp: the size of the user buffer
2322 * @ppos: file position
2324 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2325 * values from/to the user buffer, treated as an ASCII string. The values
2326 * are treated as milliseconds, and converted to jiffies when they are stored.
2328 * This routine will ensure the values are within the range specified by
2329 * table->extra1 (min) and table->extra2 (max).
2331 * Returns 0 on success.
2333 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2335 void __user
*buffer
,
2336 size_t *lenp
, loff_t
*ppos
)
2338 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2339 lenp
, ppos
, HZ
, 1000l);
2343 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2345 int write
, void *data
)
2348 if (*lvalp
> LONG_MAX
/ HZ
)
2350 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2356 lval
= (unsigned long)-val
;
2359 lval
= (unsigned long)val
;
2366 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2368 int write
, void *data
)
2371 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2373 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2379 lval
= (unsigned long)-val
;
2382 lval
= (unsigned long)val
;
2384 *lvalp
= jiffies_to_clock_t(lval
);
2389 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2391 int write
, void *data
)
2394 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2400 lval
= (unsigned long)-val
;
2403 lval
= (unsigned long)val
;
2405 *lvalp
= jiffies_to_msecs(lval
);
2411 * proc_dointvec_jiffies - read a vector of integers as seconds
2412 * @table: the sysctl table
2413 * @write: %TRUE if this is a write to the sysctl file
2414 * @filp: the file structure
2415 * @buffer: the user buffer
2416 * @lenp: the size of the user buffer
2417 * @ppos: file position
2419 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2420 * values from/to the user buffer, treated as an ASCII string.
2421 * The values read are assumed to be in seconds, and are converted into
2424 * Returns 0 on success.
2426 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2427 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2429 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2430 do_proc_dointvec_jiffies_conv
,NULL
);
2434 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2435 * @table: the sysctl table
2436 * @write: %TRUE if this is a write to the sysctl file
2437 * @filp: the file structure
2438 * @buffer: the user buffer
2439 * @lenp: the size of the user buffer
2440 * @ppos: pointer to the file position
2442 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2443 * values from/to the user buffer, treated as an ASCII string.
2444 * The values read are assumed to be in 1/USER_HZ seconds, and
2445 * are converted into jiffies.
2447 * Returns 0 on success.
2449 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2450 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2452 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2453 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2457 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2458 * @table: the sysctl table
2459 * @write: %TRUE if this is a write to the sysctl file
2460 * @filp: the file structure
2461 * @buffer: the user buffer
2462 * @lenp: the size of the user buffer
2463 * @ppos: file position
2464 * @ppos: the current position in the file
2466 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2467 * values from/to the user buffer, treated as an ASCII string.
2468 * The values read are assumed to be in 1/1000 seconds, and
2469 * are converted into jiffies.
2471 * Returns 0 on success.
2473 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2474 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2476 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2477 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2480 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2481 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2483 struct pid
*new_pid
;
2487 tmp
= pid_nr_ns(cad_pid
, current
->nsproxy
->pid_ns
);
2489 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2490 lenp
, ppos
, NULL
, NULL
);
2494 new_pid
= find_get_pid(tmp
);
2498 put_pid(xchg(&cad_pid
, new_pid
));
2502 #else /* CONFIG_PROC_FS */
2504 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2505 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2510 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2511 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2516 int proc_dointvec_bset(struct ctl_table
*table
, int write
, struct file
*filp
,
2517 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2522 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2523 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2528 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2529 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2534 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2535 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2540 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2541 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2546 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2547 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2552 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2554 void __user
*buffer
,
2555 size_t *lenp
, loff_t
*ppos
)
2561 #endif /* CONFIG_PROC_FS */
2564 #ifdef CONFIG_SYSCTL_SYSCALL
2566 * General sysctl support routines
2569 /* The generic sysctl data routine (used if no strategy routine supplied) */
2570 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2571 void __user
*oldval
, size_t __user
*oldlenp
,
2572 void __user
*newval
, size_t newlen
)
2576 /* Get out of I don't have a variable */
2577 if (!table
->data
|| !table
->maxlen
)
2580 if (oldval
&& oldlenp
) {
2581 if (get_user(len
, oldlenp
))
2584 if (len
> table
->maxlen
)
2585 len
= table
->maxlen
;
2586 if (copy_to_user(oldval
, table
->data
, len
))
2588 if (put_user(len
, oldlenp
))
2593 if (newval
&& newlen
) {
2594 if (newlen
> table
->maxlen
)
2595 newlen
= table
->maxlen
;
2597 if (copy_from_user(table
->data
, newval
, newlen
))
2603 /* The generic string strategy routine: */
2604 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2605 void __user
*oldval
, size_t __user
*oldlenp
,
2606 void __user
*newval
, size_t newlen
)
2608 if (!table
->data
|| !table
->maxlen
)
2611 if (oldval
&& oldlenp
) {
2613 if (get_user(bufsize
, oldlenp
))
2616 size_t len
= strlen(table
->data
), copied
;
2618 /* This shouldn't trigger for a well-formed sysctl */
2619 if (len
> table
->maxlen
)
2620 len
= table
->maxlen
;
2622 /* Copy up to a max of bufsize-1 bytes of the string */
2623 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2625 if (copy_to_user(oldval
, table
->data
, copied
) ||
2626 put_user(0, (char __user
*)(oldval
+ copied
)))
2628 if (put_user(len
, oldlenp
))
2632 if (newval
&& newlen
) {
2633 size_t len
= newlen
;
2634 if (len
> table
->maxlen
)
2635 len
= table
->maxlen
;
2636 if(copy_from_user(table
->data
, newval
, len
))
2638 if (len
== table
->maxlen
)
2640 ((char *) table
->data
)[len
] = 0;
2646 * This function makes sure that all of the integers in the vector
2647 * are between the minimum and maximum values given in the arrays
2648 * table->extra1 and table->extra2, respectively.
2650 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2651 void __user
*oldval
, size_t __user
*oldlenp
,
2652 void __user
*newval
, size_t newlen
)
2655 if (newval
&& newlen
) {
2656 int __user
*vec
= (int __user
*) newval
;
2657 int *min
= (int *) table
->extra1
;
2658 int *max
= (int *) table
->extra2
;
2662 if (newlen
% sizeof(int) != 0)
2665 if (!table
->extra1
&& !table
->extra2
)
2668 if (newlen
> table
->maxlen
)
2669 newlen
= table
->maxlen
;
2670 length
= newlen
/ sizeof(int);
2672 for (i
= 0; i
< length
; i
++) {
2674 if (get_user(value
, vec
+ i
))
2676 if (min
&& value
< min
[i
])
2678 if (max
&& value
> max
[i
])
2685 /* Strategy function to convert jiffies to seconds */
2686 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2687 void __user
*oldval
, size_t __user
*oldlenp
,
2688 void __user
*newval
, size_t newlen
)
2690 if (oldval
&& oldlenp
) {
2693 if (get_user(olen
, oldlenp
))
2698 if (olen
< sizeof(int))
2701 val
= *(int *)(table
->data
) / HZ
;
2702 if (put_user(val
, (int __user
*)oldval
))
2704 if (put_user(sizeof(int), oldlenp
))
2708 if (newval
&& newlen
) {
2710 if (newlen
!= sizeof(int))
2712 if (get_user(new, (int __user
*)newval
))
2714 *(int *)(table
->data
) = new*HZ
;
2719 /* Strategy function to convert jiffies to seconds */
2720 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2721 void __user
*oldval
, size_t __user
*oldlenp
,
2722 void __user
*newval
, size_t newlen
)
2724 if (oldval
&& oldlenp
) {
2727 if (get_user(olen
, oldlenp
))
2732 if (olen
< sizeof(int))
2735 val
= jiffies_to_msecs(*(int *)(table
->data
));
2736 if (put_user(val
, (int __user
*)oldval
))
2738 if (put_user(sizeof(int), oldlenp
))
2742 if (newval
&& newlen
) {
2744 if (newlen
!= sizeof(int))
2746 if (get_user(new, (int __user
*)newval
))
2748 *(int *)(table
->data
) = msecs_to_jiffies(new);
2755 #else /* CONFIG_SYSCTL_SYSCALL */
2758 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2760 struct __sysctl_args tmp
;
2763 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
2766 error
= deprecated_sysctl_warning(&tmp
);
2768 /* If no error reading the parameters then just -ENOSYS ... */
2775 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2776 void __user
*oldval
, size_t __user
*oldlenp
,
2777 void __user
*newval
, size_t newlen
)
2782 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2783 void __user
*oldval
, size_t __user
*oldlenp
,
2784 void __user
*newval
, size_t newlen
)
2789 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2790 void __user
*oldval
, size_t __user
*oldlenp
,
2791 void __user
*newval
, size_t newlen
)
2796 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2797 void __user
*oldval
, size_t __user
*oldlenp
,
2798 void __user
*newval
, size_t newlen
)
2803 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2804 void __user
*oldval
, size_t __user
*oldlenp
,
2805 void __user
*newval
, size_t newlen
)
2810 #endif /* CONFIG_SYSCTL_SYSCALL */
2812 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
2814 static int msg_count
;
2815 int name
[CTL_MAXNAME
];
2818 /* Check args->nlen. */
2819 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
2822 /* Read in the sysctl name for better debug message logging */
2823 for (i
= 0; i
< args
->nlen
; i
++)
2824 if (get_user(name
[i
], args
->name
+ i
))
2827 /* Ignore accesses to kernel.version */
2828 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
2831 if (msg_count
< 5) {
2834 "warning: process `%s' used the deprecated sysctl "
2835 "system call with ", current
->comm
);
2836 for (i
= 0; i
< args
->nlen
; i
++)
2837 printk("%d.", name
[i
]);
2844 * No sense putting this after each symbol definition, twice,
2845 * exception granted :-)
2847 EXPORT_SYMBOL(proc_dointvec
);
2848 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2849 EXPORT_SYMBOL(proc_dointvec_minmax
);
2850 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2851 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2852 EXPORT_SYMBOL(proc_dostring
);
2853 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2854 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2855 EXPORT_SYMBOL(register_sysctl_table
);
2856 EXPORT_SYMBOL(register_sysctl_paths
);
2857 EXPORT_SYMBOL(sysctl_intvec
);
2858 EXPORT_SYMBOL(sysctl_jiffies
);
2859 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2860 EXPORT_SYMBOL(sysctl_string
);
2861 EXPORT_SYMBOL(sysctl_data
);
2862 EXPORT_SYMBOL(unregister_sysctl_table
);