2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/proc_fs.h>
27 #include <linux/security.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/hugetlb.h>
40 #include <linux/initrd.h>
41 #include <linux/key.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/nfs_fs.h>
47 #include <linux/acpi.h>
48 #include <linux/reboot.h>
49 #include <linux/ftrace.h>
51 #include <asm/uaccess.h>
52 #include <asm/processor.h>
56 #include <asm/stacktrace.h>
60 static int deprecated_sysctl_warning(struct __sysctl_args
*args
);
62 #if defined(CONFIG_SYSCTL)
64 /* External variables not in a header file. */
66 extern int print_fatal_signals
;
67 extern int sysctl_overcommit_memory
;
68 extern int sysctl_overcommit_ratio
;
69 extern int sysctl_panic_on_oom
;
70 extern int sysctl_oom_kill_allocating_task
;
71 extern int sysctl_oom_dump_tasks
;
72 extern int max_threads
;
73 extern int core_uses_pid
;
74 extern int suid_dumpable
;
75 extern char core_pattern
[];
77 extern int min_free_kbytes
;
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
;
85 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
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 #ifdef CONFIG_BSD_PROCESS_ACCT
137 extern int acct_parm
[];
141 extern int no_unaligned_warning
;
144 #ifdef CONFIG_RT_MUTEXES
145 extern int max_lock_depth
;
148 #ifdef CONFIG_PROC_SYSCTL
149 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
150 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
151 static int proc_dointvec_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
152 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
155 static struct ctl_table root_table
[];
156 static struct ctl_table_root sysctl_table_root
;
157 static struct ctl_table_header root_table_header
= {
158 .ctl_table
= root_table
,
159 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.header_list
),
160 .root
= &sysctl_table_root
,
162 static struct ctl_table_root sysctl_table_root
= {
163 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
164 .header_list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
167 static struct ctl_table kern_table
[];
168 static struct ctl_table vm_table
[];
169 static struct ctl_table fs_table
[];
170 static struct ctl_table debug_table
[];
171 static struct ctl_table dev_table
[];
172 extern struct ctl_table random_table
[];
173 #ifdef CONFIG_INOTIFY_USER
174 extern struct ctl_table inotify_table
[];
177 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
178 int sysctl_legacy_va_layout
;
181 extern int prove_locking
;
182 extern int lock_stat
;
184 /* The default sysctl tables: */
186 static struct ctl_table root_table
[] = {
188 .ctl_name
= CTL_KERN
,
189 .procname
= "kernel",
206 .ctl_name
= CTL_DEBUG
,
209 .child
= debug_table
,
218 * NOTE: do not add new entries to this table unless you have read
219 * Documentation/sysctl/ctl_unnumbered.txt
224 #ifdef CONFIG_SCHED_DEBUG
225 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
226 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
227 static int min_wakeup_granularity_ns
; /* 0 usecs */
228 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
231 static struct ctl_table kern_table
[] = {
232 #ifdef CONFIG_SCHED_DEBUG
234 .ctl_name
= CTL_UNNUMBERED
,
235 .procname
= "sched_min_granularity_ns",
236 .data
= &sysctl_sched_min_granularity
,
237 .maxlen
= sizeof(unsigned int),
239 .proc_handler
= &sched_nr_latency_handler
,
240 .strategy
= &sysctl_intvec
,
241 .extra1
= &min_sched_granularity_ns
,
242 .extra2
= &max_sched_granularity_ns
,
245 .ctl_name
= CTL_UNNUMBERED
,
246 .procname
= "sched_latency_ns",
247 .data
= &sysctl_sched_latency
,
248 .maxlen
= sizeof(unsigned int),
250 .proc_handler
= &sched_nr_latency_handler
,
251 .strategy
= &sysctl_intvec
,
252 .extra1
= &min_sched_granularity_ns
,
253 .extra2
= &max_sched_granularity_ns
,
256 .ctl_name
= CTL_UNNUMBERED
,
257 .procname
= "sched_wakeup_granularity_ns",
258 .data
= &sysctl_sched_wakeup_granularity
,
259 .maxlen
= sizeof(unsigned int),
261 .proc_handler
= &proc_dointvec_minmax
,
262 .strategy
= &sysctl_intvec
,
263 .extra1
= &min_wakeup_granularity_ns
,
264 .extra2
= &max_wakeup_granularity_ns
,
267 .ctl_name
= CTL_UNNUMBERED
,
268 .procname
= "sched_shares_ratelimit",
269 .data
= &sysctl_sched_shares_ratelimit
,
270 .maxlen
= sizeof(unsigned int),
272 .proc_handler
= &proc_dointvec
,
275 .ctl_name
= CTL_UNNUMBERED
,
276 .procname
= "sched_child_runs_first",
277 .data
= &sysctl_sched_child_runs_first
,
278 .maxlen
= sizeof(unsigned int),
280 .proc_handler
= &proc_dointvec
,
283 .ctl_name
= CTL_UNNUMBERED
,
284 .procname
= "sched_features",
285 .data
= &sysctl_sched_features
,
286 .maxlen
= sizeof(unsigned int),
288 .proc_handler
= &proc_dointvec
,
291 .ctl_name
= CTL_UNNUMBERED
,
292 .procname
= "sched_migration_cost",
293 .data
= &sysctl_sched_migration_cost
,
294 .maxlen
= sizeof(unsigned int),
296 .proc_handler
= &proc_dointvec
,
299 .ctl_name
= CTL_UNNUMBERED
,
300 .procname
= "sched_nr_migrate",
301 .data
= &sysctl_sched_nr_migrate
,
302 .maxlen
= sizeof(unsigned int),
304 .proc_handler
= &proc_dointvec
,
308 .ctl_name
= CTL_UNNUMBERED
,
309 .procname
= "sched_rt_period_us",
310 .data
= &sysctl_sched_rt_period
,
311 .maxlen
= sizeof(unsigned int),
313 .proc_handler
= &sched_rt_handler
,
316 .ctl_name
= CTL_UNNUMBERED
,
317 .procname
= "sched_rt_runtime_us",
318 .data
= &sysctl_sched_rt_runtime
,
319 .maxlen
= sizeof(int),
321 .proc_handler
= &sched_rt_handler
,
324 .ctl_name
= CTL_UNNUMBERED
,
325 .procname
= "sched_compat_yield",
326 .data
= &sysctl_sched_compat_yield
,
327 .maxlen
= sizeof(unsigned int),
329 .proc_handler
= &proc_dointvec
,
331 #ifdef CONFIG_PROVE_LOCKING
333 .ctl_name
= CTL_UNNUMBERED
,
334 .procname
= "prove_locking",
335 .data
= &prove_locking
,
336 .maxlen
= sizeof(int),
338 .proc_handler
= &proc_dointvec
,
341 #ifdef CONFIG_LOCK_STAT
343 .ctl_name
= CTL_UNNUMBERED
,
344 .procname
= "lock_stat",
346 .maxlen
= sizeof(int),
348 .proc_handler
= &proc_dointvec
,
352 .ctl_name
= KERN_PANIC
,
354 .data
= &panic_timeout
,
355 .maxlen
= sizeof(int),
357 .proc_handler
= &proc_dointvec
,
360 .ctl_name
= KERN_CORE_USES_PID
,
361 .procname
= "core_uses_pid",
362 .data
= &core_uses_pid
,
363 .maxlen
= sizeof(int),
365 .proc_handler
= &proc_dointvec
,
368 .ctl_name
= KERN_CORE_PATTERN
,
369 .procname
= "core_pattern",
370 .data
= core_pattern
,
371 .maxlen
= CORENAME_MAX_SIZE
,
373 .proc_handler
= &proc_dostring
,
374 .strategy
= &sysctl_string
,
376 #ifdef CONFIG_PROC_SYSCTL
378 .procname
= "tainted",
380 .maxlen
= sizeof(int),
382 .proc_handler
= &proc_dointvec_taint
,
385 #ifdef CONFIG_LATENCYTOP
387 .procname
= "latencytop",
388 .data
= &latencytop_enabled
,
389 .maxlen
= sizeof(int),
391 .proc_handler
= &proc_dointvec
,
394 #ifdef CONFIG_BLK_DEV_INITRD
396 .ctl_name
= KERN_REALROOTDEV
,
397 .procname
= "real-root-dev",
398 .data
= &real_root_dev
,
399 .maxlen
= sizeof(int),
401 .proc_handler
= &proc_dointvec
,
405 .ctl_name
= CTL_UNNUMBERED
,
406 .procname
= "print-fatal-signals",
407 .data
= &print_fatal_signals
,
408 .maxlen
= sizeof(int),
410 .proc_handler
= &proc_dointvec
,
414 .ctl_name
= KERN_SPARC_REBOOT
,
415 .procname
= "reboot-cmd",
416 .data
= reboot_command
,
419 .proc_handler
= &proc_dostring
,
420 .strategy
= &sysctl_string
,
423 .ctl_name
= KERN_SPARC_STOP_A
,
424 .procname
= "stop-a",
425 .data
= &stop_a_enabled
,
426 .maxlen
= sizeof (int),
428 .proc_handler
= &proc_dointvec
,
431 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
432 .procname
= "scons-poweroff",
433 .data
= &scons_pwroff
,
434 .maxlen
= sizeof (int),
436 .proc_handler
= &proc_dointvec
,
441 .ctl_name
= KERN_HPPA_PWRSW
,
442 .procname
= "soft-power",
443 .data
= &pwrsw_enabled
,
444 .maxlen
= sizeof (int),
446 .proc_handler
= &proc_dointvec
,
449 .ctl_name
= KERN_HPPA_UNALIGNED
,
450 .procname
= "unaligned-trap",
451 .data
= &unaligned_enabled
,
452 .maxlen
= sizeof (int),
454 .proc_handler
= &proc_dointvec
,
458 .ctl_name
= KERN_CTLALTDEL
,
459 .procname
= "ctrl-alt-del",
461 .maxlen
= sizeof(int),
463 .proc_handler
= &proc_dointvec
,
467 .ctl_name
= CTL_UNNUMBERED
,
468 .procname
= "ftrace_enabled",
469 .data
= &ftrace_enabled
,
470 .maxlen
= sizeof(int),
472 .proc_handler
= &ftrace_enable_sysctl
,
477 .ctl_name
= KERN_MODPROBE
,
478 .procname
= "modprobe",
479 .data
= &modprobe_path
,
480 .maxlen
= KMOD_PATH_LEN
,
482 .proc_handler
= &proc_dostring
,
483 .strategy
= &sysctl_string
,
486 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
488 .ctl_name
= KERN_HOTPLUG
,
489 .procname
= "hotplug",
490 .data
= &uevent_helper
,
491 .maxlen
= UEVENT_HELPER_PATH_LEN
,
493 .proc_handler
= &proc_dostring
,
494 .strategy
= &sysctl_string
,
497 #ifdef CONFIG_CHR_DEV_SG
499 .ctl_name
= KERN_SG_BIG_BUFF
,
500 .procname
= "sg-big-buff",
501 .data
= &sg_big_buff
,
502 .maxlen
= sizeof (int),
504 .proc_handler
= &proc_dointvec
,
507 #ifdef CONFIG_BSD_PROCESS_ACCT
509 .ctl_name
= KERN_ACCT
,
512 .maxlen
= 3*sizeof(int),
514 .proc_handler
= &proc_dointvec
,
517 #ifdef CONFIG_MAGIC_SYSRQ
519 .ctl_name
= KERN_SYSRQ
,
521 .data
= &__sysrq_enabled
,
522 .maxlen
= sizeof (int),
524 .proc_handler
= &proc_dointvec
,
527 #ifdef CONFIG_PROC_SYSCTL
529 .procname
= "cad_pid",
531 .maxlen
= sizeof (int),
533 .proc_handler
= &proc_do_cad_pid
,
537 .ctl_name
= KERN_MAX_THREADS
,
538 .procname
= "threads-max",
539 .data
= &max_threads
,
540 .maxlen
= sizeof(int),
542 .proc_handler
= &proc_dointvec
,
545 .ctl_name
= KERN_RANDOM
,
546 .procname
= "random",
548 .child
= random_table
,
551 .ctl_name
= KERN_OVERFLOWUID
,
552 .procname
= "overflowuid",
553 .data
= &overflowuid
,
554 .maxlen
= sizeof(int),
556 .proc_handler
= &proc_dointvec_minmax
,
557 .strategy
= &sysctl_intvec
,
558 .extra1
= &minolduid
,
559 .extra2
= &maxolduid
,
562 .ctl_name
= KERN_OVERFLOWGID
,
563 .procname
= "overflowgid",
564 .data
= &overflowgid
,
565 .maxlen
= sizeof(int),
567 .proc_handler
= &proc_dointvec_minmax
,
568 .strategy
= &sysctl_intvec
,
569 .extra1
= &minolduid
,
570 .extra2
= &maxolduid
,
573 #ifdef CONFIG_MATHEMU
575 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
576 .procname
= "ieee_emulation_warnings",
577 .data
= &sysctl_ieee_emulation_warnings
,
578 .maxlen
= sizeof(int),
580 .proc_handler
= &proc_dointvec
,
584 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
585 .procname
= "userprocess_debug",
586 .data
= &sysctl_userprocess_debug
,
587 .maxlen
= sizeof(int),
589 .proc_handler
= &proc_dointvec
,
593 .ctl_name
= KERN_PIDMAX
,
594 .procname
= "pid_max",
596 .maxlen
= sizeof (int),
598 .proc_handler
= &proc_dointvec_minmax
,
599 .strategy
= sysctl_intvec
,
600 .extra1
= &pid_max_min
,
601 .extra2
= &pid_max_max
,
604 .ctl_name
= KERN_PANIC_ON_OOPS
,
605 .procname
= "panic_on_oops",
606 .data
= &panic_on_oops
,
607 .maxlen
= sizeof(int),
609 .proc_handler
= &proc_dointvec
,
611 #if defined CONFIG_PRINTK
613 .ctl_name
= KERN_PRINTK
,
614 .procname
= "printk",
615 .data
= &console_loglevel
,
616 .maxlen
= 4*sizeof(int),
618 .proc_handler
= &proc_dointvec
,
621 .ctl_name
= KERN_PRINTK_RATELIMIT
,
622 .procname
= "printk_ratelimit",
623 .data
= &printk_ratelimit_jiffies
,
624 .maxlen
= sizeof(int),
626 .proc_handler
= &proc_dointvec_jiffies
,
627 .strategy
= &sysctl_jiffies
,
630 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
631 .procname
= "printk_ratelimit_burst",
632 .data
= &printk_ratelimit_burst
,
633 .maxlen
= sizeof(int),
635 .proc_handler
= &proc_dointvec
,
639 .ctl_name
= KERN_NGROUPS_MAX
,
640 .procname
= "ngroups_max",
641 .data
= &ngroups_max
,
642 .maxlen
= sizeof (int),
644 .proc_handler
= &proc_dointvec
,
646 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
648 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
649 .procname
= "unknown_nmi_panic",
650 .data
= &unknown_nmi_panic
,
651 .maxlen
= sizeof (int),
653 .proc_handler
= &proc_dointvec
,
656 .procname
= "nmi_watchdog",
657 .data
= &nmi_watchdog_enabled
,
658 .maxlen
= sizeof (int),
660 .proc_handler
= &proc_nmi_enabled
,
663 #if defined(CONFIG_X86)
665 .ctl_name
= KERN_PANIC_ON_NMI
,
666 .procname
= "panic_on_unrecovered_nmi",
667 .data
= &panic_on_unrecovered_nmi
,
668 .maxlen
= sizeof(int),
670 .proc_handler
= &proc_dointvec
,
673 .ctl_name
= KERN_BOOTLOADER_TYPE
,
674 .procname
= "bootloader_type",
675 .data
= &bootloader_type
,
676 .maxlen
= sizeof (int),
678 .proc_handler
= &proc_dointvec
,
681 .ctl_name
= CTL_UNNUMBERED
,
682 .procname
= "kstack_depth_to_print",
683 .data
= &kstack_depth_to_print
,
684 .maxlen
= sizeof(int),
686 .proc_handler
= &proc_dointvec
,
689 .ctl_name
= CTL_UNNUMBERED
,
690 .procname
= "io_delay_type",
691 .data
= &io_delay_type
,
692 .maxlen
= sizeof(int),
694 .proc_handler
= &proc_dointvec
,
697 #if defined(CONFIG_MMU)
699 .ctl_name
= KERN_RANDOMIZE
,
700 .procname
= "randomize_va_space",
701 .data
= &randomize_va_space
,
702 .maxlen
= sizeof(int),
704 .proc_handler
= &proc_dointvec
,
707 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
709 .ctl_name
= KERN_SPIN_RETRY
,
710 .procname
= "spin_retry",
712 .maxlen
= sizeof (int),
714 .proc_handler
= &proc_dointvec
,
717 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
719 .procname
= "acpi_video_flags",
720 .data
= &acpi_realmode_flags
,
721 .maxlen
= sizeof (unsigned long),
723 .proc_handler
= &proc_doulongvec_minmax
,
728 .ctl_name
= KERN_IA64_UNALIGNED
,
729 .procname
= "ignore-unaligned-usertrap",
730 .data
= &no_unaligned_warning
,
731 .maxlen
= sizeof (int),
733 .proc_handler
= &proc_dointvec
,
736 #ifdef CONFIG_DETECT_SOFTLOCKUP
738 .ctl_name
= CTL_UNNUMBERED
,
739 .procname
= "softlockup_thresh",
740 .data
= &softlockup_thresh
,
741 .maxlen
= sizeof(unsigned long),
743 .proc_handler
= &proc_doulongvec_minmax
,
744 .strategy
= &sysctl_intvec
,
749 .ctl_name
= CTL_UNNUMBERED
,
750 .procname
= "hung_task_check_count",
751 .data
= &sysctl_hung_task_check_count
,
752 .maxlen
= sizeof(unsigned long),
754 .proc_handler
= &proc_doulongvec_minmax
,
755 .strategy
= &sysctl_intvec
,
758 .ctl_name
= CTL_UNNUMBERED
,
759 .procname
= "hung_task_timeout_secs",
760 .data
= &sysctl_hung_task_timeout_secs
,
761 .maxlen
= sizeof(unsigned long),
763 .proc_handler
= &proc_doulongvec_minmax
,
764 .strategy
= &sysctl_intvec
,
767 .ctl_name
= CTL_UNNUMBERED
,
768 .procname
= "hung_task_warnings",
769 .data
= &sysctl_hung_task_warnings
,
770 .maxlen
= sizeof(unsigned long),
772 .proc_handler
= &proc_doulongvec_minmax
,
773 .strategy
= &sysctl_intvec
,
778 .ctl_name
= KERN_COMPAT_LOG
,
779 .procname
= "compat-log",
781 .maxlen
= sizeof (int),
783 .proc_handler
= &proc_dointvec
,
786 #ifdef CONFIG_RT_MUTEXES
788 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
789 .procname
= "max_lock_depth",
790 .data
= &max_lock_depth
,
791 .maxlen
= sizeof(int),
793 .proc_handler
= &proc_dointvec
,
796 #ifdef CONFIG_PROC_FS
798 .ctl_name
= CTL_UNNUMBERED
,
799 .procname
= "maps_protect",
800 .data
= &maps_protect
,
801 .maxlen
= sizeof(int),
803 .proc_handler
= &proc_dointvec
,
807 .ctl_name
= CTL_UNNUMBERED
,
808 .procname
= "poweroff_cmd",
809 .data
= &poweroff_cmd
,
810 .maxlen
= POWEROFF_CMD_PATH_LEN
,
812 .proc_handler
= &proc_dostring
,
813 .strategy
= &sysctl_string
,
817 .ctl_name
= CTL_UNNUMBERED
,
820 .child
= key_sysctls
,
824 * NOTE: do not add new entries to this table unless you have read
825 * Documentation/sysctl/ctl_unnumbered.txt
830 static struct ctl_table vm_table
[] = {
832 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
833 .procname
= "overcommit_memory",
834 .data
= &sysctl_overcommit_memory
,
835 .maxlen
= sizeof(sysctl_overcommit_memory
),
837 .proc_handler
= &proc_dointvec
,
840 .ctl_name
= VM_PANIC_ON_OOM
,
841 .procname
= "panic_on_oom",
842 .data
= &sysctl_panic_on_oom
,
843 .maxlen
= sizeof(sysctl_panic_on_oom
),
845 .proc_handler
= &proc_dointvec
,
848 .ctl_name
= CTL_UNNUMBERED
,
849 .procname
= "oom_kill_allocating_task",
850 .data
= &sysctl_oom_kill_allocating_task
,
851 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
853 .proc_handler
= &proc_dointvec
,
856 .ctl_name
= CTL_UNNUMBERED
,
857 .procname
= "oom_dump_tasks",
858 .data
= &sysctl_oom_dump_tasks
,
859 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
861 .proc_handler
= &proc_dointvec
,
864 .ctl_name
= VM_OVERCOMMIT_RATIO
,
865 .procname
= "overcommit_ratio",
866 .data
= &sysctl_overcommit_ratio
,
867 .maxlen
= sizeof(sysctl_overcommit_ratio
),
869 .proc_handler
= &proc_dointvec
,
872 .ctl_name
= VM_PAGE_CLUSTER
,
873 .procname
= "page-cluster",
874 .data
= &page_cluster
,
875 .maxlen
= sizeof(int),
877 .proc_handler
= &proc_dointvec
,
880 .ctl_name
= VM_DIRTY_BACKGROUND
,
881 .procname
= "dirty_background_ratio",
882 .data
= &dirty_background_ratio
,
883 .maxlen
= sizeof(dirty_background_ratio
),
885 .proc_handler
= &proc_dointvec_minmax
,
886 .strategy
= &sysctl_intvec
,
888 .extra2
= &one_hundred
,
891 .ctl_name
= VM_DIRTY_RATIO
,
892 .procname
= "dirty_ratio",
893 .data
= &vm_dirty_ratio
,
894 .maxlen
= sizeof(vm_dirty_ratio
),
896 .proc_handler
= &dirty_ratio_handler
,
897 .strategy
= &sysctl_intvec
,
899 .extra2
= &one_hundred
,
902 .procname
= "dirty_writeback_centisecs",
903 .data
= &dirty_writeback_interval
,
904 .maxlen
= sizeof(dirty_writeback_interval
),
906 .proc_handler
= &dirty_writeback_centisecs_handler
,
909 .procname
= "dirty_expire_centisecs",
910 .data
= &dirty_expire_interval
,
911 .maxlen
= sizeof(dirty_expire_interval
),
913 .proc_handler
= &proc_dointvec_userhz_jiffies
,
916 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
917 .procname
= "nr_pdflush_threads",
918 .data
= &nr_pdflush_threads
,
919 .maxlen
= sizeof nr_pdflush_threads
,
920 .mode
= 0444 /* read-only*/,
921 .proc_handler
= &proc_dointvec
,
924 .ctl_name
= VM_SWAPPINESS
,
925 .procname
= "swappiness",
926 .data
= &vm_swappiness
,
927 .maxlen
= sizeof(vm_swappiness
),
929 .proc_handler
= &proc_dointvec_minmax
,
930 .strategy
= &sysctl_intvec
,
932 .extra2
= &one_hundred
,
934 #ifdef CONFIG_HUGETLB_PAGE
936 .procname
= "nr_hugepages",
937 .data
= &max_huge_pages
,
938 .maxlen
= sizeof(unsigned long),
940 .proc_handler
= &hugetlb_sysctl_handler
,
941 .extra1
= (void *)&hugetlb_zero
,
942 .extra2
= (void *)&hugetlb_infinity
,
945 .ctl_name
= VM_HUGETLB_GROUP
,
946 .procname
= "hugetlb_shm_group",
947 .data
= &sysctl_hugetlb_shm_group
,
948 .maxlen
= sizeof(gid_t
),
950 .proc_handler
= &proc_dointvec
,
953 .ctl_name
= CTL_UNNUMBERED
,
954 .procname
= "hugepages_treat_as_movable",
955 .data
= &hugepages_treat_as_movable
,
956 .maxlen
= sizeof(int),
958 .proc_handler
= &hugetlb_treat_movable_handler
,
961 .ctl_name
= CTL_UNNUMBERED
,
962 .procname
= "nr_overcommit_hugepages",
963 .data
= &sysctl_overcommit_huge_pages
,
964 .maxlen
= sizeof(sysctl_overcommit_huge_pages
),
966 .proc_handler
= &hugetlb_overcommit_handler
,
970 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
971 .procname
= "lowmem_reserve_ratio",
972 .data
= &sysctl_lowmem_reserve_ratio
,
973 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
975 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
976 .strategy
= &sysctl_intvec
,
979 .ctl_name
= VM_DROP_PAGECACHE
,
980 .procname
= "drop_caches",
981 .data
= &sysctl_drop_caches
,
982 .maxlen
= sizeof(int),
984 .proc_handler
= drop_caches_sysctl_handler
,
985 .strategy
= &sysctl_intvec
,
988 .ctl_name
= VM_MIN_FREE_KBYTES
,
989 .procname
= "min_free_kbytes",
990 .data
= &min_free_kbytes
,
991 .maxlen
= sizeof(min_free_kbytes
),
993 .proc_handler
= &min_free_kbytes_sysctl_handler
,
994 .strategy
= &sysctl_intvec
,
998 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
999 .procname
= "percpu_pagelist_fraction",
1000 .data
= &percpu_pagelist_fraction
,
1001 .maxlen
= sizeof(percpu_pagelist_fraction
),
1003 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1004 .strategy
= &sysctl_intvec
,
1005 .extra1
= &min_percpu_pagelist_fract
,
1009 .ctl_name
= VM_MAX_MAP_COUNT
,
1010 .procname
= "max_map_count",
1011 .data
= &sysctl_max_map_count
,
1012 .maxlen
= sizeof(sysctl_max_map_count
),
1014 .proc_handler
= &proc_dointvec
1018 .ctl_name
= VM_LAPTOP_MODE
,
1019 .procname
= "laptop_mode",
1020 .data
= &laptop_mode
,
1021 .maxlen
= sizeof(laptop_mode
),
1023 .proc_handler
= &proc_dointvec_jiffies
,
1024 .strategy
= &sysctl_jiffies
,
1027 .ctl_name
= VM_BLOCK_DUMP
,
1028 .procname
= "block_dump",
1029 .data
= &block_dump
,
1030 .maxlen
= sizeof(block_dump
),
1032 .proc_handler
= &proc_dointvec
,
1033 .strategy
= &sysctl_intvec
,
1037 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1038 .procname
= "vfs_cache_pressure",
1039 .data
= &sysctl_vfs_cache_pressure
,
1040 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1042 .proc_handler
= &proc_dointvec
,
1043 .strategy
= &sysctl_intvec
,
1046 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1048 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1049 .procname
= "legacy_va_layout",
1050 .data
= &sysctl_legacy_va_layout
,
1051 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1053 .proc_handler
= &proc_dointvec
,
1054 .strategy
= &sysctl_intvec
,
1060 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1061 .procname
= "zone_reclaim_mode",
1062 .data
= &zone_reclaim_mode
,
1063 .maxlen
= sizeof(zone_reclaim_mode
),
1065 .proc_handler
= &proc_dointvec
,
1066 .strategy
= &sysctl_intvec
,
1070 .ctl_name
= VM_MIN_UNMAPPED
,
1071 .procname
= "min_unmapped_ratio",
1072 .data
= &sysctl_min_unmapped_ratio
,
1073 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1075 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1076 .strategy
= &sysctl_intvec
,
1078 .extra2
= &one_hundred
,
1081 .ctl_name
= VM_MIN_SLAB
,
1082 .procname
= "min_slab_ratio",
1083 .data
= &sysctl_min_slab_ratio
,
1084 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1086 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1087 .strategy
= &sysctl_intvec
,
1089 .extra2
= &one_hundred
,
1094 .ctl_name
= CTL_UNNUMBERED
,
1095 .procname
= "stat_interval",
1096 .data
= &sysctl_stat_interval
,
1097 .maxlen
= sizeof(sysctl_stat_interval
),
1099 .proc_handler
= &proc_dointvec_jiffies
,
1100 .strategy
= &sysctl_jiffies
,
1103 #ifdef CONFIG_SECURITY
1105 .ctl_name
= CTL_UNNUMBERED
,
1106 .procname
= "mmap_min_addr",
1107 .data
= &mmap_min_addr
,
1108 .maxlen
= sizeof(unsigned long),
1110 .proc_handler
= &proc_doulongvec_minmax
,
1115 .ctl_name
= CTL_UNNUMBERED
,
1116 .procname
= "numa_zonelist_order",
1117 .data
= &numa_zonelist_order
,
1118 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1120 .proc_handler
= &numa_zonelist_order_handler
,
1121 .strategy
= &sysctl_string
,
1124 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1125 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1127 .ctl_name
= VM_VDSO_ENABLED
,
1128 .procname
= "vdso_enabled",
1129 .data
= &vdso_enabled
,
1130 .maxlen
= sizeof(vdso_enabled
),
1132 .proc_handler
= &proc_dointvec
,
1133 .strategy
= &sysctl_intvec
,
1137 #ifdef CONFIG_HIGHMEM
1139 .ctl_name
= CTL_UNNUMBERED
,
1140 .procname
= "highmem_is_dirtyable",
1141 .data
= &vm_highmem_is_dirtyable
,
1142 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1144 .proc_handler
= &proc_dointvec_minmax
,
1145 .strategy
= &sysctl_intvec
,
1151 * NOTE: do not add new entries to this table unless you have read
1152 * Documentation/sysctl/ctl_unnumbered.txt
1157 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1158 static struct ctl_table binfmt_misc_table
[] = {
1163 static struct ctl_table fs_table
[] = {
1165 .ctl_name
= FS_NRINODE
,
1166 .procname
= "inode-nr",
1167 .data
= &inodes_stat
,
1168 .maxlen
= 2*sizeof(int),
1170 .proc_handler
= &proc_dointvec
,
1173 .ctl_name
= FS_STATINODE
,
1174 .procname
= "inode-state",
1175 .data
= &inodes_stat
,
1176 .maxlen
= 7*sizeof(int),
1178 .proc_handler
= &proc_dointvec
,
1181 .procname
= "file-nr",
1182 .data
= &files_stat
,
1183 .maxlen
= 3*sizeof(int),
1185 .proc_handler
= &proc_nr_files
,
1188 .ctl_name
= FS_MAXFILE
,
1189 .procname
= "file-max",
1190 .data
= &files_stat
.max_files
,
1191 .maxlen
= sizeof(int),
1193 .proc_handler
= &proc_dointvec
,
1196 .ctl_name
= CTL_UNNUMBERED
,
1197 .procname
= "nr_open",
1198 .data
= &sysctl_nr_open
,
1199 .maxlen
= sizeof(int),
1201 .proc_handler
= &proc_dointvec_minmax
,
1202 .extra1
= &sysctl_nr_open_min
,
1203 .extra2
= &sysctl_nr_open_max
,
1206 .ctl_name
= FS_DENTRY
,
1207 .procname
= "dentry-state",
1208 .data
= &dentry_stat
,
1209 .maxlen
= 6*sizeof(int),
1211 .proc_handler
= &proc_dointvec
,
1214 .ctl_name
= FS_OVERFLOWUID
,
1215 .procname
= "overflowuid",
1216 .data
= &fs_overflowuid
,
1217 .maxlen
= sizeof(int),
1219 .proc_handler
= &proc_dointvec_minmax
,
1220 .strategy
= &sysctl_intvec
,
1221 .extra1
= &minolduid
,
1222 .extra2
= &maxolduid
,
1225 .ctl_name
= FS_OVERFLOWGID
,
1226 .procname
= "overflowgid",
1227 .data
= &fs_overflowgid
,
1228 .maxlen
= sizeof(int),
1230 .proc_handler
= &proc_dointvec_minmax
,
1231 .strategy
= &sysctl_intvec
,
1232 .extra1
= &minolduid
,
1233 .extra2
= &maxolduid
,
1236 .ctl_name
= FS_LEASES
,
1237 .procname
= "leases-enable",
1238 .data
= &leases_enable
,
1239 .maxlen
= sizeof(int),
1241 .proc_handler
= &proc_dointvec
,
1243 #ifdef CONFIG_DNOTIFY
1245 .ctl_name
= FS_DIR_NOTIFY
,
1246 .procname
= "dir-notify-enable",
1247 .data
= &dir_notify_enable
,
1248 .maxlen
= sizeof(int),
1250 .proc_handler
= &proc_dointvec
,
1255 .ctl_name
= FS_LEASE_TIME
,
1256 .procname
= "lease-break-time",
1257 .data
= &lease_break_time
,
1258 .maxlen
= sizeof(int),
1260 .proc_handler
= &proc_dointvec_minmax
,
1261 .strategy
= &sysctl_intvec
,
1266 .procname
= "aio-nr",
1268 .maxlen
= sizeof(aio_nr
),
1270 .proc_handler
= &proc_doulongvec_minmax
,
1273 .procname
= "aio-max-nr",
1274 .data
= &aio_max_nr
,
1275 .maxlen
= sizeof(aio_max_nr
),
1277 .proc_handler
= &proc_doulongvec_minmax
,
1279 #ifdef CONFIG_INOTIFY_USER
1281 .ctl_name
= FS_INOTIFY
,
1282 .procname
= "inotify",
1284 .child
= inotify_table
,
1289 .ctl_name
= KERN_SETUID_DUMPABLE
,
1290 .procname
= "suid_dumpable",
1291 .data
= &suid_dumpable
,
1292 .maxlen
= sizeof(int),
1294 .proc_handler
= &proc_dointvec
,
1296 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1298 .ctl_name
= CTL_UNNUMBERED
,
1299 .procname
= "binfmt_misc",
1301 .child
= binfmt_misc_table
,
1305 * NOTE: do not add new entries to this table unless you have read
1306 * Documentation/sysctl/ctl_unnumbered.txt
1311 static struct ctl_table debug_table
[] = {
1312 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1314 .ctl_name
= CTL_UNNUMBERED
,
1315 .procname
= "exception-trace",
1316 .data
= &show_unhandled_signals
,
1317 .maxlen
= sizeof(int),
1319 .proc_handler
= proc_dointvec
1325 static struct ctl_table dev_table
[] = {
1329 static DEFINE_SPINLOCK(sysctl_lock
);
1331 /* called under sysctl_lock */
1332 static int use_table(struct ctl_table_header
*p
)
1334 if (unlikely(p
->unregistering
))
1340 /* called under sysctl_lock */
1341 static void unuse_table(struct ctl_table_header
*p
)
1344 if (unlikely(p
->unregistering
))
1345 complete(p
->unregistering
);
1348 /* called under sysctl_lock, will reacquire if has to wait */
1349 static void start_unregistering(struct ctl_table_header
*p
)
1352 * if p->used is 0, nobody will ever touch that entry again;
1353 * we'll eliminate all paths to it before dropping sysctl_lock
1355 if (unlikely(p
->used
)) {
1356 struct completion wait
;
1357 init_completion(&wait
);
1358 p
->unregistering
= &wait
;
1359 spin_unlock(&sysctl_lock
);
1360 wait_for_completion(&wait
);
1361 spin_lock(&sysctl_lock
);
1364 * do not remove from the list until nobody holds it; walking the
1365 * list in do_sysctl() relies on that.
1367 list_del_init(&p
->ctl_entry
);
1370 void sysctl_head_finish(struct ctl_table_header
*head
)
1374 spin_lock(&sysctl_lock
);
1376 spin_unlock(&sysctl_lock
);
1379 static struct list_head
*
1380 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1382 struct list_head
*header_list
;
1383 header_list
= &root
->header_list
;
1385 header_list
= root
->lookup(root
, namespaces
);
1389 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1390 struct ctl_table_header
*prev
)
1392 struct ctl_table_root
*root
;
1393 struct list_head
*header_list
;
1394 struct ctl_table_header
*head
;
1395 struct list_head
*tmp
;
1397 spin_lock(&sysctl_lock
);
1400 tmp
= &prev
->ctl_entry
;
1404 tmp
= &root_table_header
.ctl_entry
;
1406 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1408 if (!use_table(head
))
1410 spin_unlock(&sysctl_lock
);
1415 header_list
= lookup_header_list(root
, namespaces
);
1416 if (tmp
!= header_list
)
1420 root
= list_entry(root
->root_list
.next
,
1421 struct ctl_table_root
, root_list
);
1422 if (root
== &sysctl_table_root
)
1424 header_list
= lookup_header_list(root
, namespaces
);
1425 } while (list_empty(header_list
));
1426 tmp
= header_list
->next
;
1429 spin_unlock(&sysctl_lock
);
1433 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1435 return __sysctl_head_next(current
->nsproxy
, prev
);
1438 void register_sysctl_root(struct ctl_table_root
*root
)
1440 spin_lock(&sysctl_lock
);
1441 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1442 spin_unlock(&sysctl_lock
);
1445 #ifdef CONFIG_SYSCTL_SYSCALL
1446 /* Perform the actual read/write of a sysctl table entry. */
1447 static int do_sysctl_strategy(struct ctl_table_root
*root
,
1448 struct ctl_table
*table
,
1449 int __user
*name
, int nlen
,
1450 void __user
*oldval
, size_t __user
*oldlenp
,
1451 void __user
*newval
, size_t newlen
)
1459 if (sysctl_perm(root
, table
, op
))
1462 if (table
->strategy
) {
1463 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1471 /* If there is no strategy routine, or if the strategy returns
1472 * zero, proceed with automatic r/w */
1473 if (table
->data
&& table
->maxlen
) {
1474 rc
= sysctl_data(table
, name
, nlen
, oldval
, oldlenp
,
1482 static int parse_table(int __user
*name
, int nlen
,
1483 void __user
*oldval
, size_t __user
*oldlenp
,
1484 void __user
*newval
, size_t newlen
,
1485 struct ctl_table_root
*root
,
1486 struct ctl_table
*table
)
1492 if (get_user(n
, name
))
1494 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1495 if (!table
->ctl_name
)
1497 if (n
== table
->ctl_name
) {
1500 if (sysctl_perm(root
, table
, 001))
1504 table
= table
->child
;
1507 error
= do_sysctl_strategy(root
, table
, name
, nlen
,
1516 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1517 void __user
*newval
, size_t newlen
)
1519 struct ctl_table_header
*head
;
1520 int error
= -ENOTDIR
;
1522 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1526 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1530 for (head
= sysctl_head_next(NULL
); head
;
1531 head
= sysctl_head_next(head
)) {
1532 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1534 head
->root
, head
->ctl_table
);
1535 if (error
!= -ENOTDIR
) {
1536 sysctl_head_finish(head
);
1543 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1545 struct __sysctl_args tmp
;
1548 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1551 error
= deprecated_sysctl_warning(&tmp
);
1556 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1557 tmp
.newval
, tmp
.newlen
);
1562 #endif /* CONFIG_SYSCTL_SYSCALL */
1565 * sysctl_perm does NOT grant the superuser all rights automatically, because
1566 * some sysctl variables are readonly even to root.
1569 static int test_perm(int mode
, int op
)
1573 else if (in_egroup_p(0))
1575 if ((mode
& op
& 0007) == op
)
1580 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1585 error
= security_sysctl(table
, op
);
1589 if (root
->permissions
)
1590 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1594 return test_perm(mode
, op
);
1597 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1599 for (; table
->ctl_name
|| table
->procname
; table
++) {
1600 table
->parent
= parent
;
1602 sysctl_set_parent(table
, table
->child
);
1606 static __init
int sysctl_init(void)
1608 sysctl_set_parent(NULL
, root_table
);
1609 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1612 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1618 core_initcall(sysctl_init
);
1621 * __register_sysctl_paths - register a sysctl hierarchy
1622 * @root: List of sysctl headers to register on
1623 * @namespaces: Data to compute which lists of sysctl entries are visible
1624 * @path: The path to the directory the sysctl table is in.
1625 * @table: the top-level table structure
1627 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1628 * array. A completely 0 filled entry terminates the table.
1630 * The members of the &struct ctl_table structure are used as follows:
1632 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1633 * must be unique within that level of sysctl
1635 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1636 * enter a sysctl file
1638 * data - a pointer to data for use by proc_handler
1640 * maxlen - the maximum size in bytes of the data
1642 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1644 * child - a pointer to the child sysctl table if this entry is a directory, or
1647 * proc_handler - the text handler routine (described below)
1649 * strategy - the strategy routine (described below)
1651 * de - for internal use by the sysctl routines
1653 * extra1, extra2 - extra pointers usable by the proc handler routines
1655 * Leaf nodes in the sysctl tree will be represented by a single file
1656 * under /proc; non-leaf nodes will be represented by directories.
1658 * sysctl(2) can automatically manage read and write requests through
1659 * the sysctl table. The data and maxlen fields of the ctl_table
1660 * struct enable minimal validation of the values being written to be
1661 * performed, and the mode field allows minimal authentication.
1663 * More sophisticated management can be enabled by the provision of a
1664 * strategy routine with the table entry. This will be called before
1665 * any automatic read or write of the data is performed.
1667 * The strategy routine may return
1669 * < 0 - Error occurred (error is passed to user process)
1671 * 0 - OK - proceed with automatic read or write.
1673 * > 0 - OK - read or write has been done by the strategy routine, so
1674 * return immediately.
1676 * There must be a proc_handler routine for any terminal nodes
1677 * mirrored under /proc/sys (non-terminals are handled by a built-in
1678 * directory handler). Several default handlers are available to
1679 * cover common cases -
1681 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1682 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1683 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1685 * It is the handler's job to read the input buffer from user memory
1686 * and process it. The handler should return 0 on success.
1688 * This routine returns %NULL on a failure to register, and a pointer
1689 * to the table header on success.
1691 struct ctl_table_header
*__register_sysctl_paths(
1692 struct ctl_table_root
*root
,
1693 struct nsproxy
*namespaces
,
1694 const struct ctl_path
*path
, struct ctl_table
*table
)
1696 struct list_head
*header_list
;
1697 struct ctl_table_header
*header
;
1698 struct ctl_table
*new, **prevp
;
1699 unsigned int n
, npath
;
1701 /* Count the path components */
1702 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
1706 * For each path component, allocate a 2-element ctl_table array.
1707 * The first array element will be filled with the sysctl entry
1708 * for this, the second will be the sentinel (ctl_name == 0).
1710 * We allocate everything in one go so that we don't have to
1711 * worry about freeing additional memory in unregister_sysctl_table.
1713 header
= kzalloc(sizeof(struct ctl_table_header
) +
1714 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1718 new = (struct ctl_table
*) (header
+ 1);
1720 /* Now connect the dots */
1721 prevp
= &header
->ctl_table
;
1722 for (n
= 0; n
< npath
; ++n
, ++path
) {
1723 /* Copy the procname */
1724 new->procname
= path
->procname
;
1725 new->ctl_name
= path
->ctl_name
;
1729 prevp
= &new->child
;
1734 header
->ctl_table_arg
= table
;
1736 INIT_LIST_HEAD(&header
->ctl_entry
);
1738 header
->unregistering
= NULL
;
1739 header
->root
= root
;
1740 sysctl_set_parent(NULL
, header
->ctl_table
);
1741 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1742 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1747 spin_lock(&sysctl_lock
);
1748 header_list
= lookup_header_list(root
, namespaces
);
1749 list_add_tail(&header
->ctl_entry
, header_list
);
1750 spin_unlock(&sysctl_lock
);
1756 * register_sysctl_table_path - register a sysctl table hierarchy
1757 * @path: The path to the directory the sysctl table is in.
1758 * @table: the top-level table structure
1760 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1761 * array. A completely 0 filled entry terminates the table.
1763 * See __register_sysctl_paths for more details.
1765 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1766 struct ctl_table
*table
)
1768 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1773 * register_sysctl_table - register a sysctl table hierarchy
1774 * @table: the top-level table structure
1776 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1777 * array. A completely 0 filled entry terminates the table.
1779 * See register_sysctl_paths for more details.
1781 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1783 static const struct ctl_path null_path
[] = { {} };
1785 return register_sysctl_paths(null_path
, table
);
1789 * unregister_sysctl_table - unregister a sysctl table hierarchy
1790 * @header: the header returned from register_sysctl_table
1792 * Unregisters the sysctl table and all children. proc entries may not
1793 * actually be removed until they are no longer used by anyone.
1795 void unregister_sysctl_table(struct ctl_table_header
* header
)
1802 spin_lock(&sysctl_lock
);
1803 start_unregistering(header
);
1804 spin_unlock(&sysctl_lock
);
1808 #else /* !CONFIG_SYSCTL */
1809 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1814 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1815 struct ctl_table
*table
)
1820 void unregister_sysctl_table(struct ctl_table_header
* table
)
1824 #endif /* CONFIG_SYSCTL */
1830 #ifdef CONFIG_PROC_SYSCTL
1832 static int _proc_do_string(void* data
, int maxlen
, int write
,
1833 struct file
*filp
, void __user
*buffer
,
1834 size_t *lenp
, loff_t
*ppos
)
1840 if (!data
|| !maxlen
|| !*lenp
) {
1848 while (len
< *lenp
) {
1849 if (get_user(c
, p
++))
1851 if (c
== 0 || c
== '\n')
1857 if(copy_from_user(data
, buffer
, len
))
1859 ((char *) data
)[len
] = 0;
1877 if(copy_to_user(buffer
, data
, len
))
1880 if(put_user('\n', ((char __user
*) buffer
) + len
))
1891 * proc_dostring - read a string sysctl
1892 * @table: the sysctl table
1893 * @write: %TRUE if this is a write to the sysctl file
1894 * @filp: the file structure
1895 * @buffer: the user buffer
1896 * @lenp: the size of the user buffer
1897 * @ppos: file position
1899 * Reads/writes a string from/to the user buffer. If the kernel
1900 * buffer provided is not large enough to hold the string, the
1901 * string is truncated. The copied string is %NULL-terminated.
1902 * If the string is being read by the user process, it is copied
1903 * and a newline '\n' is added. It is truncated if the buffer is
1906 * Returns 0 on success.
1908 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
1909 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1911 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
1912 buffer
, lenp
, ppos
);
1916 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1918 int write
, void *data
)
1921 *valp
= *negp
? -*lvalp
: *lvalp
;
1926 *lvalp
= (unsigned long)-val
;
1929 *lvalp
= (unsigned long)val
;
1935 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1936 int write
, struct file
*filp
, void __user
*buffer
,
1937 size_t *lenp
, loff_t
*ppos
,
1938 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1939 int write
, void *data
),
1942 #define TMPBUFLEN 21
1943 int *i
, vleft
, first
=1, neg
, val
;
1947 char buf
[TMPBUFLEN
], *p
;
1948 char __user
*s
= buffer
;
1950 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
1951 (*ppos
&& !write
)) {
1956 i
= (int *) tbl_data
;
1957 vleft
= table
->maxlen
/ sizeof(*i
);
1961 conv
= do_proc_dointvec_conv
;
1963 for (; left
&& vleft
--; i
++, first
=0) {
1978 if (len
> sizeof(buf
) - 1)
1979 len
= sizeof(buf
) - 1;
1980 if (copy_from_user(buf
, s
, len
))
1984 if (*p
== '-' && left
> 1) {
1988 if (*p
< '0' || *p
> '9')
1991 lval
= simple_strtoul(p
, &p
, 0);
1994 if ((len
< left
) && *p
&& !isspace(*p
))
2001 if (conv(&neg
, &lval
, i
, 1, data
))
2008 if (conv(&neg
, &lval
, i
, 0, data
))
2011 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2015 if(copy_to_user(s
, buf
, len
))
2022 if (!write
&& !first
&& left
) {
2023 if(put_user('\n', s
))
2030 if (get_user(c
, s
++))
2045 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2046 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2047 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2048 int write
, void *data
),
2051 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2052 buffer
, lenp
, ppos
, conv
, data
);
2056 * proc_dointvec - read a vector of integers
2057 * @table: the sysctl table
2058 * @write: %TRUE if this is a write to the sysctl file
2059 * @filp: the file structure
2060 * @buffer: the user buffer
2061 * @lenp: the size of the user buffer
2062 * @ppos: file position
2064 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2065 * values from/to the user buffer, treated as an ASCII string.
2067 * Returns 0 on success.
2069 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2070 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2072 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2080 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
2082 int write
, void *data
)
2084 int op
= *(int *)data
;
2086 int val
= *negp
? -*lvalp
: *lvalp
;
2088 case OP_SET
: *valp
= val
; break;
2089 case OP_AND
: *valp
&= val
; break;
2090 case OP_OR
: *valp
|= val
; break;
2096 *lvalp
= (unsigned long)-val
;
2099 *lvalp
= (unsigned long)val
;
2106 * Taint values can only be increased
2108 static int proc_dointvec_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2109 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2113 if (write
&& !capable(CAP_SYS_ADMIN
))
2117 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2118 do_proc_dointvec_bset_conv
,&op
);
2121 struct do_proc_dointvec_minmax_conv_param
{
2126 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2128 int write
, void *data
)
2130 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2132 int val
= *negp
? -*lvalp
: *lvalp
;
2133 if ((param
->min
&& *param
->min
> val
) ||
2134 (param
->max
&& *param
->max
< val
))
2141 *lvalp
= (unsigned long)-val
;
2144 *lvalp
= (unsigned long)val
;
2151 * proc_dointvec_minmax - read a vector of integers with min/max values
2152 * @table: the sysctl table
2153 * @write: %TRUE if this is a write to the sysctl file
2154 * @filp: the file structure
2155 * @buffer: the user buffer
2156 * @lenp: the size of the user buffer
2157 * @ppos: file position
2159 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2160 * values from/to the user buffer, treated as an ASCII string.
2162 * This routine will ensure the values are within the range specified by
2163 * table->extra1 (min) and table->extra2 (max).
2165 * Returns 0 on success.
2167 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2168 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2170 struct do_proc_dointvec_minmax_conv_param param
= {
2171 .min
= (int *) table
->extra1
,
2172 .max
= (int *) table
->extra2
,
2174 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2175 do_proc_dointvec_minmax_conv
, ¶m
);
2178 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2180 void __user
*buffer
,
2181 size_t *lenp
, loff_t
*ppos
,
2182 unsigned long convmul
,
2183 unsigned long convdiv
)
2185 #define TMPBUFLEN 21
2186 unsigned long *i
, *min
, *max
, val
;
2187 int vleft
, first
=1, neg
;
2189 char buf
[TMPBUFLEN
], *p
;
2190 char __user
*s
= buffer
;
2192 if (!data
|| !table
->maxlen
|| !*lenp
||
2193 (*ppos
&& !write
)) {
2198 i
= (unsigned long *) data
;
2199 min
= (unsigned long *) table
->extra1
;
2200 max
= (unsigned long *) table
->extra2
;
2201 vleft
= table
->maxlen
/ sizeof(unsigned long);
2204 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2219 if (len
> TMPBUFLEN
-1)
2221 if (copy_from_user(buf
, s
, len
))
2225 if (*p
== '-' && left
> 1) {
2229 if (*p
< '0' || *p
> '9')
2231 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2233 if ((len
< left
) && *p
&& !isspace(*p
))
2242 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2249 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2253 if(copy_to_user(s
, buf
, len
))
2260 if (!write
&& !first
&& left
) {
2261 if(put_user('\n', s
))
2268 if (get_user(c
, s
++))
2283 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2285 void __user
*buffer
,
2286 size_t *lenp
, loff_t
*ppos
,
2287 unsigned long convmul
,
2288 unsigned long convdiv
)
2290 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2291 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2295 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2296 * @table: the sysctl table
2297 * @write: %TRUE if this is a write to the sysctl file
2298 * @filp: the file structure
2299 * @buffer: the user buffer
2300 * @lenp: the size of the user buffer
2301 * @ppos: file position
2303 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2304 * values from/to the user buffer, treated as an ASCII string.
2306 * This routine will ensure the values are within the range specified by
2307 * table->extra1 (min) and table->extra2 (max).
2309 * Returns 0 on success.
2311 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2312 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2314 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2318 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2319 * @table: the sysctl table
2320 * @write: %TRUE if this is a write to the sysctl file
2321 * @filp: the file structure
2322 * @buffer: the user buffer
2323 * @lenp: the size of the user buffer
2324 * @ppos: file position
2326 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2327 * values from/to the user buffer, treated as an ASCII string. The values
2328 * are treated as milliseconds, and converted to jiffies when they are stored.
2330 * This routine will ensure the values are within the range specified by
2331 * table->extra1 (min) and table->extra2 (max).
2333 * Returns 0 on success.
2335 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2337 void __user
*buffer
,
2338 size_t *lenp
, loff_t
*ppos
)
2340 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2341 lenp
, ppos
, HZ
, 1000l);
2345 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2347 int write
, void *data
)
2350 if (*lvalp
> LONG_MAX
/ HZ
)
2352 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2358 lval
= (unsigned long)-val
;
2361 lval
= (unsigned long)val
;
2368 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2370 int write
, void *data
)
2373 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2375 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2381 lval
= (unsigned long)-val
;
2384 lval
= (unsigned long)val
;
2386 *lvalp
= jiffies_to_clock_t(lval
);
2391 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2393 int write
, void *data
)
2396 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2402 lval
= (unsigned long)-val
;
2405 lval
= (unsigned long)val
;
2407 *lvalp
= jiffies_to_msecs(lval
);
2413 * proc_dointvec_jiffies - read a vector of integers as seconds
2414 * @table: the sysctl table
2415 * @write: %TRUE if this is a write to the sysctl file
2416 * @filp: the file structure
2417 * @buffer: the user buffer
2418 * @lenp: the size of the user buffer
2419 * @ppos: file position
2421 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2422 * values from/to the user buffer, treated as an ASCII string.
2423 * The values read are assumed to be in seconds, and are converted into
2426 * Returns 0 on success.
2428 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2429 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2431 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2432 do_proc_dointvec_jiffies_conv
,NULL
);
2436 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2437 * @table: the sysctl table
2438 * @write: %TRUE if this is a write to the sysctl file
2439 * @filp: the file structure
2440 * @buffer: the user buffer
2441 * @lenp: the size of the user buffer
2442 * @ppos: pointer to the file position
2444 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2445 * values from/to the user buffer, treated as an ASCII string.
2446 * The values read are assumed to be in 1/USER_HZ seconds, and
2447 * are converted into jiffies.
2449 * Returns 0 on success.
2451 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2452 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2454 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2455 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2459 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2460 * @table: the sysctl table
2461 * @write: %TRUE if this is a write to the sysctl file
2462 * @filp: the file structure
2463 * @buffer: the user buffer
2464 * @lenp: the size of the user buffer
2465 * @ppos: file position
2466 * @ppos: the current position in the file
2468 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2469 * values from/to the user buffer, treated as an ASCII string.
2470 * The values read are assumed to be in 1/1000 seconds, and
2471 * are converted into jiffies.
2473 * Returns 0 on success.
2475 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2476 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2478 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2479 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2482 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2483 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2485 struct pid
*new_pid
;
2489 tmp
= pid_vnr(cad_pid
);
2491 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2492 lenp
, ppos
, NULL
, NULL
);
2496 new_pid
= find_get_pid(tmp
);
2500 put_pid(xchg(&cad_pid
, new_pid
));
2504 #else /* CONFIG_PROC_FS */
2506 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2507 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2512 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2513 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2518 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2519 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2524 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2525 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2530 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2531 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2536 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2537 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2542 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2543 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2548 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2550 void __user
*buffer
,
2551 size_t *lenp
, loff_t
*ppos
)
2557 #endif /* CONFIG_PROC_FS */
2560 #ifdef CONFIG_SYSCTL_SYSCALL
2562 * General sysctl support routines
2565 /* The generic sysctl data routine (used if no strategy routine supplied) */
2566 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2567 void __user
*oldval
, size_t __user
*oldlenp
,
2568 void __user
*newval
, size_t newlen
)
2572 /* Get out of I don't have a variable */
2573 if (!table
->data
|| !table
->maxlen
)
2576 if (oldval
&& oldlenp
) {
2577 if (get_user(len
, oldlenp
))
2580 if (len
> table
->maxlen
)
2581 len
= table
->maxlen
;
2582 if (copy_to_user(oldval
, table
->data
, len
))
2584 if (put_user(len
, oldlenp
))
2589 if (newval
&& newlen
) {
2590 if (newlen
> table
->maxlen
)
2591 newlen
= table
->maxlen
;
2593 if (copy_from_user(table
->data
, newval
, newlen
))
2599 /* The generic string strategy routine: */
2600 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2601 void __user
*oldval
, size_t __user
*oldlenp
,
2602 void __user
*newval
, size_t newlen
)
2604 if (!table
->data
|| !table
->maxlen
)
2607 if (oldval
&& oldlenp
) {
2609 if (get_user(bufsize
, oldlenp
))
2612 size_t len
= strlen(table
->data
), copied
;
2614 /* This shouldn't trigger for a well-formed sysctl */
2615 if (len
> table
->maxlen
)
2616 len
= table
->maxlen
;
2618 /* Copy up to a max of bufsize-1 bytes of the string */
2619 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2621 if (copy_to_user(oldval
, table
->data
, copied
) ||
2622 put_user(0, (char __user
*)(oldval
+ copied
)))
2624 if (put_user(len
, oldlenp
))
2628 if (newval
&& newlen
) {
2629 size_t len
= newlen
;
2630 if (len
> table
->maxlen
)
2631 len
= table
->maxlen
;
2632 if(copy_from_user(table
->data
, newval
, len
))
2634 if (len
== table
->maxlen
)
2636 ((char *) table
->data
)[len
] = 0;
2642 * This function makes sure that all of the integers in the vector
2643 * are between the minimum and maximum values given in the arrays
2644 * table->extra1 and table->extra2, respectively.
2646 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2647 void __user
*oldval
, size_t __user
*oldlenp
,
2648 void __user
*newval
, size_t newlen
)
2651 if (newval
&& newlen
) {
2652 int __user
*vec
= (int __user
*) newval
;
2653 int *min
= (int *) table
->extra1
;
2654 int *max
= (int *) table
->extra2
;
2658 if (newlen
% sizeof(int) != 0)
2661 if (!table
->extra1
&& !table
->extra2
)
2664 if (newlen
> table
->maxlen
)
2665 newlen
= table
->maxlen
;
2666 length
= newlen
/ sizeof(int);
2668 for (i
= 0; i
< length
; i
++) {
2670 if (get_user(value
, vec
+ i
))
2672 if (min
&& value
< min
[i
])
2674 if (max
&& value
> max
[i
])
2681 /* Strategy function to convert jiffies to seconds */
2682 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2683 void __user
*oldval
, size_t __user
*oldlenp
,
2684 void __user
*newval
, size_t newlen
)
2686 if (oldval
&& oldlenp
) {
2689 if (get_user(olen
, oldlenp
))
2694 if (olen
< sizeof(int))
2697 val
= *(int *)(table
->data
) / HZ
;
2698 if (put_user(val
, (int __user
*)oldval
))
2700 if (put_user(sizeof(int), oldlenp
))
2704 if (newval
&& newlen
) {
2706 if (newlen
!= sizeof(int))
2708 if (get_user(new, (int __user
*)newval
))
2710 *(int *)(table
->data
) = new*HZ
;
2715 /* Strategy function to convert jiffies to seconds */
2716 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2717 void __user
*oldval
, size_t __user
*oldlenp
,
2718 void __user
*newval
, size_t newlen
)
2720 if (oldval
&& oldlenp
) {
2723 if (get_user(olen
, oldlenp
))
2728 if (olen
< sizeof(int))
2731 val
= jiffies_to_msecs(*(int *)(table
->data
));
2732 if (put_user(val
, (int __user
*)oldval
))
2734 if (put_user(sizeof(int), oldlenp
))
2738 if (newval
&& newlen
) {
2740 if (newlen
!= sizeof(int))
2742 if (get_user(new, (int __user
*)newval
))
2744 *(int *)(table
->data
) = msecs_to_jiffies(new);
2751 #else /* CONFIG_SYSCTL_SYSCALL */
2754 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2756 struct __sysctl_args tmp
;
2759 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
2762 error
= deprecated_sysctl_warning(&tmp
);
2764 /* If no error reading the parameters then just -ENOSYS ... */
2771 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2772 void __user
*oldval
, size_t __user
*oldlenp
,
2773 void __user
*newval
, size_t newlen
)
2778 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2779 void __user
*oldval
, size_t __user
*oldlenp
,
2780 void __user
*newval
, size_t newlen
)
2785 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2786 void __user
*oldval
, size_t __user
*oldlenp
,
2787 void __user
*newval
, size_t newlen
)
2792 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2793 void __user
*oldval
, size_t __user
*oldlenp
,
2794 void __user
*newval
, size_t newlen
)
2799 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2800 void __user
*oldval
, size_t __user
*oldlenp
,
2801 void __user
*newval
, size_t newlen
)
2806 #endif /* CONFIG_SYSCTL_SYSCALL */
2808 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
2810 static int msg_count
;
2811 int name
[CTL_MAXNAME
];
2814 /* Check args->nlen. */
2815 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
2818 /* Read in the sysctl name for better debug message logging */
2819 for (i
= 0; i
< args
->nlen
; i
++)
2820 if (get_user(name
[i
], args
->name
+ i
))
2823 /* Ignore accesses to kernel.version */
2824 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
2827 if (msg_count
< 5) {
2830 "warning: process `%s' used the deprecated sysctl "
2831 "system call with ", current
->comm
);
2832 for (i
= 0; i
< args
->nlen
; i
++)
2833 printk("%d.", name
[i
]);
2840 * No sense putting this after each symbol definition, twice,
2841 * exception granted :-)
2843 EXPORT_SYMBOL(proc_dointvec
);
2844 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2845 EXPORT_SYMBOL(proc_dointvec_minmax
);
2846 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2847 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2848 EXPORT_SYMBOL(proc_dostring
);
2849 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2850 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2851 EXPORT_SYMBOL(register_sysctl_table
);
2852 EXPORT_SYMBOL(register_sysctl_paths
);
2853 EXPORT_SYMBOL(sysctl_intvec
);
2854 EXPORT_SYMBOL(sysctl_jiffies
);
2855 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2856 EXPORT_SYMBOL(sysctl_string
);
2857 EXPORT_SYMBOL(sysctl_data
);
2858 EXPORT_SYMBOL(unregister_sysctl_table
);