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>
50 #include <asm/uaccess.h>
51 #include <asm/processor.h>
55 #include <asm/stacktrace.h>
59 static int deprecated_sysctl_warning(struct __sysctl_args
*args
);
61 #if defined(CONFIG_SYSCTL)
63 /* External variables not in a header file. */
65 extern int print_fatal_signals
;
66 extern int sysctl_overcommit_memory
;
67 extern int sysctl_overcommit_ratio
;
68 extern int sysctl_panic_on_oom
;
69 extern int sysctl_oom_kill_allocating_task
;
70 extern int sysctl_oom_dump_tasks
;
71 extern int max_threads
;
72 extern int core_uses_pid
;
73 extern int suid_dumpable
;
74 extern char core_pattern
[];
76 extern int min_free_kbytes
;
77 extern int pid_max_min
, pid_max_max
;
78 extern int sysctl_drop_caches
;
79 extern int percpu_pagelist_fraction
;
80 extern int compat_log
;
81 extern int maps_protect
;
82 extern int sysctl_stat_interval
;
83 extern int latencytop_enabled
;
84 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
86 /* Constants used for minimum and maximum */
91 #ifdef CONFIG_DETECT_SOFTLOCKUP
92 static int sixty
= 60;
93 static int neg_one
= -1;
101 static int one_hundred
= 100;
103 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
104 static int maxolduid
= 65535;
105 static int minolduid
;
106 static int min_percpu_pagelist_fract
= 8;
108 static int ngroups_max
= NGROUPS_MAX
;
111 extern char modprobe_path
[];
113 #ifdef CONFIG_CHR_DEV_SG
114 extern int sg_big_buff
;
118 extern char reboot_command
[];
119 extern int stop_a_enabled
;
120 extern int scons_pwroff
;
124 extern int pwrsw_enabled
;
125 extern int unaligned_enabled
;
129 #ifdef CONFIG_MATHEMU
130 extern int sysctl_ieee_emulation_warnings
;
132 extern int sysctl_userprocess_debug
;
133 extern int spin_retry
;
136 extern int sysctl_hz_timer
;
138 #ifdef CONFIG_BSD_PROCESS_ACCT
139 extern int acct_parm
[];
143 extern int no_unaligned_warning
;
146 #ifdef CONFIG_RT_MUTEXES
147 extern int max_lock_depth
;
150 #ifdef CONFIG_PROC_SYSCTL
151 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
152 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
153 static int proc_dointvec_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
154 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
157 static struct ctl_table root_table
[];
158 static struct ctl_table_root sysctl_table_root
;
159 static struct ctl_table_header root_table_header
= {
160 .ctl_table
= root_table
,
161 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.header_list
),
162 .root
= &sysctl_table_root
,
164 static struct ctl_table_root sysctl_table_root
= {
165 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
166 .header_list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
169 static struct ctl_table kern_table
[];
170 static struct ctl_table vm_table
[];
171 static struct ctl_table fs_table
[];
172 static struct ctl_table debug_table
[];
173 static struct ctl_table dev_table
[];
174 extern struct ctl_table random_table
[];
175 #ifdef CONFIG_INOTIFY_USER
176 extern struct ctl_table inotify_table
[];
179 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
180 int sysctl_legacy_va_layout
;
183 extern int prove_locking
;
184 extern int lock_stat
;
186 /* The default sysctl tables: */
188 static struct ctl_table root_table
[] = {
190 .ctl_name
= CTL_KERN
,
191 .procname
= "kernel",
208 .ctl_name
= CTL_DEBUG
,
211 .child
= debug_table
,
220 * NOTE: do not add new entries to this table unless you have read
221 * Documentation/sysctl/ctl_unnumbered.txt
226 #ifdef CONFIG_SCHED_DEBUG
227 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
228 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
229 static int min_wakeup_granularity_ns
; /* 0 usecs */
230 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
233 static struct ctl_table kern_table
[] = {
234 #ifdef CONFIG_SCHED_DEBUG
236 .ctl_name
= CTL_UNNUMBERED
,
237 .procname
= "sched_min_granularity_ns",
238 .data
= &sysctl_sched_min_granularity
,
239 .maxlen
= sizeof(unsigned int),
241 .proc_handler
= &sched_nr_latency_handler
,
242 .strategy
= &sysctl_intvec
,
243 .extra1
= &min_sched_granularity_ns
,
244 .extra2
= &max_sched_granularity_ns
,
247 .ctl_name
= CTL_UNNUMBERED
,
248 .procname
= "sched_latency_ns",
249 .data
= &sysctl_sched_latency
,
250 .maxlen
= sizeof(unsigned int),
252 .proc_handler
= &sched_nr_latency_handler
,
253 .strategy
= &sysctl_intvec
,
254 .extra1
= &min_sched_granularity_ns
,
255 .extra2
= &max_sched_granularity_ns
,
258 .ctl_name
= CTL_UNNUMBERED
,
259 .procname
= "sched_wakeup_granularity_ns",
260 .data
= &sysctl_sched_wakeup_granularity
,
261 .maxlen
= sizeof(unsigned int),
263 .proc_handler
= &proc_dointvec_minmax
,
264 .strategy
= &sysctl_intvec
,
265 .extra1
= &min_wakeup_granularity_ns
,
266 .extra2
= &max_wakeup_granularity_ns
,
269 .ctl_name
= CTL_UNNUMBERED
,
270 .procname
= "sched_child_runs_first",
271 .data
= &sysctl_sched_child_runs_first
,
272 .maxlen
= sizeof(unsigned int),
274 .proc_handler
= &proc_dointvec
,
277 .ctl_name
= CTL_UNNUMBERED
,
278 .procname
= "sched_features",
279 .data
= &sysctl_sched_features
,
280 .maxlen
= sizeof(unsigned int),
282 .proc_handler
= &proc_dointvec
,
285 .ctl_name
= CTL_UNNUMBERED
,
286 .procname
= "sched_migration_cost",
287 .data
= &sysctl_sched_migration_cost
,
288 .maxlen
= sizeof(unsigned int),
290 .proc_handler
= &proc_dointvec
,
293 .ctl_name
= CTL_UNNUMBERED
,
294 .procname
= "sched_nr_migrate",
295 .data
= &sysctl_sched_nr_migrate
,
296 .maxlen
= sizeof(unsigned int),
298 .proc_handler
= &proc_dointvec
,
302 .ctl_name
= CTL_UNNUMBERED
,
303 .procname
= "sched_rt_period_us",
304 .data
= &sysctl_sched_rt_period
,
305 .maxlen
= sizeof(unsigned int),
307 .proc_handler
= &sched_rt_handler
,
310 .ctl_name
= CTL_UNNUMBERED
,
311 .procname
= "sched_rt_runtime_us",
312 .data
= &sysctl_sched_rt_runtime
,
313 .maxlen
= sizeof(int),
315 .proc_handler
= &sched_rt_handler
,
318 .ctl_name
= CTL_UNNUMBERED
,
319 .procname
= "sched_compat_yield",
320 .data
= &sysctl_sched_compat_yield
,
321 .maxlen
= sizeof(unsigned int),
323 .proc_handler
= &proc_dointvec
,
325 #ifdef CONFIG_PROVE_LOCKING
327 .ctl_name
= CTL_UNNUMBERED
,
328 .procname
= "prove_locking",
329 .data
= &prove_locking
,
330 .maxlen
= sizeof(int),
332 .proc_handler
= &proc_dointvec
,
335 #ifdef CONFIG_LOCK_STAT
337 .ctl_name
= CTL_UNNUMBERED
,
338 .procname
= "lock_stat",
340 .maxlen
= sizeof(int),
342 .proc_handler
= &proc_dointvec
,
346 .ctl_name
= KERN_PANIC
,
348 .data
= &panic_timeout
,
349 .maxlen
= sizeof(int),
351 .proc_handler
= &proc_dointvec
,
354 .ctl_name
= KERN_CORE_USES_PID
,
355 .procname
= "core_uses_pid",
356 .data
= &core_uses_pid
,
357 .maxlen
= sizeof(int),
359 .proc_handler
= &proc_dointvec
,
362 .ctl_name
= KERN_CORE_PATTERN
,
363 .procname
= "core_pattern",
364 .data
= core_pattern
,
365 .maxlen
= CORENAME_MAX_SIZE
,
367 .proc_handler
= &proc_dostring
,
368 .strategy
= &sysctl_string
,
370 #ifdef CONFIG_PROC_SYSCTL
372 .procname
= "tainted",
374 .maxlen
= sizeof(int),
376 .proc_handler
= &proc_dointvec_taint
,
379 #ifdef CONFIG_LATENCYTOP
381 .procname
= "latencytop",
382 .data
= &latencytop_enabled
,
383 .maxlen
= sizeof(int),
385 .proc_handler
= &proc_dointvec
,
388 #ifdef CONFIG_BLK_DEV_INITRD
390 .ctl_name
= KERN_REALROOTDEV
,
391 .procname
= "real-root-dev",
392 .data
= &real_root_dev
,
393 .maxlen
= sizeof(int),
395 .proc_handler
= &proc_dointvec
,
399 .ctl_name
= CTL_UNNUMBERED
,
400 .procname
= "print-fatal-signals",
401 .data
= &print_fatal_signals
,
402 .maxlen
= sizeof(int),
404 .proc_handler
= &proc_dointvec
,
408 .ctl_name
= KERN_SPARC_REBOOT
,
409 .procname
= "reboot-cmd",
410 .data
= reboot_command
,
413 .proc_handler
= &proc_dostring
,
414 .strategy
= &sysctl_string
,
417 .ctl_name
= KERN_SPARC_STOP_A
,
418 .procname
= "stop-a",
419 .data
= &stop_a_enabled
,
420 .maxlen
= sizeof (int),
422 .proc_handler
= &proc_dointvec
,
425 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
426 .procname
= "scons-poweroff",
427 .data
= &scons_pwroff
,
428 .maxlen
= sizeof (int),
430 .proc_handler
= &proc_dointvec
,
435 .ctl_name
= KERN_HPPA_PWRSW
,
436 .procname
= "soft-power",
437 .data
= &pwrsw_enabled
,
438 .maxlen
= sizeof (int),
440 .proc_handler
= &proc_dointvec
,
443 .ctl_name
= KERN_HPPA_UNALIGNED
,
444 .procname
= "unaligned-trap",
445 .data
= &unaligned_enabled
,
446 .maxlen
= sizeof (int),
448 .proc_handler
= &proc_dointvec
,
452 .ctl_name
= KERN_CTLALTDEL
,
453 .procname
= "ctrl-alt-del",
455 .maxlen
= sizeof(int),
457 .proc_handler
= &proc_dointvec
,
461 .ctl_name
= KERN_MODPROBE
,
462 .procname
= "modprobe",
463 .data
= &modprobe_path
,
464 .maxlen
= KMOD_PATH_LEN
,
466 .proc_handler
= &proc_dostring
,
467 .strategy
= &sysctl_string
,
470 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
472 .ctl_name
= KERN_HOTPLUG
,
473 .procname
= "hotplug",
474 .data
= &uevent_helper
,
475 .maxlen
= UEVENT_HELPER_PATH_LEN
,
477 .proc_handler
= &proc_dostring
,
478 .strategy
= &sysctl_string
,
481 #ifdef CONFIG_CHR_DEV_SG
483 .ctl_name
= KERN_SG_BIG_BUFF
,
484 .procname
= "sg-big-buff",
485 .data
= &sg_big_buff
,
486 .maxlen
= sizeof (int),
488 .proc_handler
= &proc_dointvec
,
491 #ifdef CONFIG_BSD_PROCESS_ACCT
493 .ctl_name
= KERN_ACCT
,
496 .maxlen
= 3*sizeof(int),
498 .proc_handler
= &proc_dointvec
,
501 #ifdef CONFIG_MAGIC_SYSRQ
503 .ctl_name
= KERN_SYSRQ
,
505 .data
= &__sysrq_enabled
,
506 .maxlen
= sizeof (int),
508 .proc_handler
= &proc_dointvec
,
511 #ifdef CONFIG_PROC_SYSCTL
513 .procname
= "cad_pid",
515 .maxlen
= sizeof (int),
517 .proc_handler
= &proc_do_cad_pid
,
521 .ctl_name
= KERN_MAX_THREADS
,
522 .procname
= "threads-max",
523 .data
= &max_threads
,
524 .maxlen
= sizeof(int),
526 .proc_handler
= &proc_dointvec
,
529 .ctl_name
= KERN_RANDOM
,
530 .procname
= "random",
532 .child
= random_table
,
535 .ctl_name
= KERN_OVERFLOWUID
,
536 .procname
= "overflowuid",
537 .data
= &overflowuid
,
538 .maxlen
= sizeof(int),
540 .proc_handler
= &proc_dointvec_minmax
,
541 .strategy
= &sysctl_intvec
,
542 .extra1
= &minolduid
,
543 .extra2
= &maxolduid
,
546 .ctl_name
= KERN_OVERFLOWGID
,
547 .procname
= "overflowgid",
548 .data
= &overflowgid
,
549 .maxlen
= sizeof(int),
551 .proc_handler
= &proc_dointvec_minmax
,
552 .strategy
= &sysctl_intvec
,
553 .extra1
= &minolduid
,
554 .extra2
= &maxolduid
,
557 #ifdef CONFIG_MATHEMU
559 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
560 .procname
= "ieee_emulation_warnings",
561 .data
= &sysctl_ieee_emulation_warnings
,
562 .maxlen
= sizeof(int),
564 .proc_handler
= &proc_dointvec
,
567 #ifdef CONFIG_NO_IDLE_HZ
569 .ctl_name
= KERN_HZ_TIMER
,
570 .procname
= "hz_timer",
571 .data
= &sysctl_hz_timer
,
572 .maxlen
= sizeof(int),
574 .proc_handler
= &proc_dointvec
,
578 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
579 .procname
= "userprocess_debug",
580 .data
= &sysctl_userprocess_debug
,
581 .maxlen
= sizeof(int),
583 .proc_handler
= &proc_dointvec
,
587 .ctl_name
= KERN_PIDMAX
,
588 .procname
= "pid_max",
590 .maxlen
= sizeof (int),
592 .proc_handler
= &proc_dointvec_minmax
,
593 .strategy
= sysctl_intvec
,
594 .extra1
= &pid_max_min
,
595 .extra2
= &pid_max_max
,
598 .ctl_name
= KERN_PANIC_ON_OOPS
,
599 .procname
= "panic_on_oops",
600 .data
= &panic_on_oops
,
601 .maxlen
= sizeof(int),
603 .proc_handler
= &proc_dointvec
,
605 #if defined CONFIG_PRINTK
607 .ctl_name
= KERN_PRINTK
,
608 .procname
= "printk",
609 .data
= &console_loglevel
,
610 .maxlen
= 4*sizeof(int),
612 .proc_handler
= &proc_dointvec
,
615 .ctl_name
= KERN_PRINTK_RATELIMIT
,
616 .procname
= "printk_ratelimit",
617 .data
= &printk_ratelimit_jiffies
,
618 .maxlen
= sizeof(int),
620 .proc_handler
= &proc_dointvec_jiffies
,
621 .strategy
= &sysctl_jiffies
,
624 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
625 .procname
= "printk_ratelimit_burst",
626 .data
= &printk_ratelimit_burst
,
627 .maxlen
= sizeof(int),
629 .proc_handler
= &proc_dointvec
,
633 .ctl_name
= KERN_NGROUPS_MAX
,
634 .procname
= "ngroups_max",
635 .data
= &ngroups_max
,
636 .maxlen
= sizeof (int),
638 .proc_handler
= &proc_dointvec
,
640 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
642 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
643 .procname
= "unknown_nmi_panic",
644 .data
= &unknown_nmi_panic
,
645 .maxlen
= sizeof (int),
647 .proc_handler
= &proc_dointvec
,
650 .procname
= "nmi_watchdog",
651 .data
= &nmi_watchdog_enabled
,
652 .maxlen
= sizeof (int),
654 .proc_handler
= &proc_nmi_enabled
,
657 #if defined(CONFIG_X86)
659 .ctl_name
= KERN_PANIC_ON_NMI
,
660 .procname
= "panic_on_unrecovered_nmi",
661 .data
= &panic_on_unrecovered_nmi
,
662 .maxlen
= sizeof(int),
664 .proc_handler
= &proc_dointvec
,
667 .ctl_name
= KERN_BOOTLOADER_TYPE
,
668 .procname
= "bootloader_type",
669 .data
= &bootloader_type
,
670 .maxlen
= sizeof (int),
672 .proc_handler
= &proc_dointvec
,
675 .ctl_name
= CTL_UNNUMBERED
,
676 .procname
= "kstack_depth_to_print",
677 .data
= &kstack_depth_to_print
,
678 .maxlen
= sizeof(int),
680 .proc_handler
= &proc_dointvec
,
683 .ctl_name
= CTL_UNNUMBERED
,
684 .procname
= "io_delay_type",
685 .data
= &io_delay_type
,
686 .maxlen
= sizeof(int),
688 .proc_handler
= &proc_dointvec
,
691 #if defined(CONFIG_MMU)
693 .ctl_name
= KERN_RANDOMIZE
,
694 .procname
= "randomize_va_space",
695 .data
= &randomize_va_space
,
696 .maxlen
= sizeof(int),
698 .proc_handler
= &proc_dointvec
,
701 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
703 .ctl_name
= KERN_SPIN_RETRY
,
704 .procname
= "spin_retry",
706 .maxlen
= sizeof (int),
708 .proc_handler
= &proc_dointvec
,
711 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
713 .procname
= "acpi_video_flags",
714 .data
= &acpi_realmode_flags
,
715 .maxlen
= sizeof (unsigned long),
717 .proc_handler
= &proc_doulongvec_minmax
,
722 .ctl_name
= KERN_IA64_UNALIGNED
,
723 .procname
= "ignore-unaligned-usertrap",
724 .data
= &no_unaligned_warning
,
725 .maxlen
= sizeof (int),
727 .proc_handler
= &proc_dointvec
,
730 #ifdef CONFIG_DETECT_SOFTLOCKUP
732 .ctl_name
= CTL_UNNUMBERED
,
733 .procname
= "softlockup_panic",
734 .data
= &softlockup_panic
,
735 .maxlen
= sizeof(int),
737 .proc_handler
= &proc_doulongvec_minmax
,
738 .strategy
= &sysctl_intvec
,
743 .ctl_name
= CTL_UNNUMBERED
,
744 .procname
= "softlockup_thresh",
745 .data
= &softlockup_thresh
,
746 .maxlen
= sizeof(int),
748 .proc_handler
= &proc_dointvec_minmax
,
749 .strategy
= &sysctl_intvec
,
754 .ctl_name
= CTL_UNNUMBERED
,
755 .procname
= "hung_task_check_count",
756 .data
= &sysctl_hung_task_check_count
,
757 .maxlen
= sizeof(unsigned long),
759 .proc_handler
= &proc_doulongvec_minmax
,
760 .strategy
= &sysctl_intvec
,
763 .ctl_name
= CTL_UNNUMBERED
,
764 .procname
= "hung_task_timeout_secs",
765 .data
= &sysctl_hung_task_timeout_secs
,
766 .maxlen
= sizeof(unsigned long),
768 .proc_handler
= &proc_doulongvec_minmax
,
769 .strategy
= &sysctl_intvec
,
772 .ctl_name
= CTL_UNNUMBERED
,
773 .procname
= "hung_task_warnings",
774 .data
= &sysctl_hung_task_warnings
,
775 .maxlen
= sizeof(unsigned long),
777 .proc_handler
= &proc_doulongvec_minmax
,
778 .strategy
= &sysctl_intvec
,
783 .ctl_name
= KERN_COMPAT_LOG
,
784 .procname
= "compat-log",
786 .maxlen
= sizeof (int),
788 .proc_handler
= &proc_dointvec
,
791 #ifdef CONFIG_RT_MUTEXES
793 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
794 .procname
= "max_lock_depth",
795 .data
= &max_lock_depth
,
796 .maxlen
= sizeof(int),
798 .proc_handler
= &proc_dointvec
,
801 #ifdef CONFIG_PROC_FS
803 .ctl_name
= CTL_UNNUMBERED
,
804 .procname
= "maps_protect",
805 .data
= &maps_protect
,
806 .maxlen
= sizeof(int),
808 .proc_handler
= &proc_dointvec
,
812 .ctl_name
= CTL_UNNUMBERED
,
813 .procname
= "poweroff_cmd",
814 .data
= &poweroff_cmd
,
815 .maxlen
= POWEROFF_CMD_PATH_LEN
,
817 .proc_handler
= &proc_dostring
,
818 .strategy
= &sysctl_string
,
822 .ctl_name
= CTL_UNNUMBERED
,
825 .child
= key_sysctls
,
829 * NOTE: do not add new entries to this table unless you have read
830 * Documentation/sysctl/ctl_unnumbered.txt
835 static struct ctl_table vm_table
[] = {
837 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
838 .procname
= "overcommit_memory",
839 .data
= &sysctl_overcommit_memory
,
840 .maxlen
= sizeof(sysctl_overcommit_memory
),
842 .proc_handler
= &proc_dointvec
,
845 .ctl_name
= VM_PANIC_ON_OOM
,
846 .procname
= "panic_on_oom",
847 .data
= &sysctl_panic_on_oom
,
848 .maxlen
= sizeof(sysctl_panic_on_oom
),
850 .proc_handler
= &proc_dointvec
,
853 .ctl_name
= CTL_UNNUMBERED
,
854 .procname
= "oom_kill_allocating_task",
855 .data
= &sysctl_oom_kill_allocating_task
,
856 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
858 .proc_handler
= &proc_dointvec
,
861 .ctl_name
= CTL_UNNUMBERED
,
862 .procname
= "oom_dump_tasks",
863 .data
= &sysctl_oom_dump_tasks
,
864 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
866 .proc_handler
= &proc_dointvec
,
869 .ctl_name
= VM_OVERCOMMIT_RATIO
,
870 .procname
= "overcommit_ratio",
871 .data
= &sysctl_overcommit_ratio
,
872 .maxlen
= sizeof(sysctl_overcommit_ratio
),
874 .proc_handler
= &proc_dointvec
,
877 .ctl_name
= VM_PAGE_CLUSTER
,
878 .procname
= "page-cluster",
879 .data
= &page_cluster
,
880 .maxlen
= sizeof(int),
882 .proc_handler
= &proc_dointvec
,
885 .ctl_name
= VM_DIRTY_BACKGROUND
,
886 .procname
= "dirty_background_ratio",
887 .data
= &dirty_background_ratio
,
888 .maxlen
= sizeof(dirty_background_ratio
),
890 .proc_handler
= &proc_dointvec_minmax
,
891 .strategy
= &sysctl_intvec
,
893 .extra2
= &one_hundred
,
896 .ctl_name
= VM_DIRTY_RATIO
,
897 .procname
= "dirty_ratio",
898 .data
= &vm_dirty_ratio
,
899 .maxlen
= sizeof(vm_dirty_ratio
),
901 .proc_handler
= &dirty_ratio_handler
,
902 .strategy
= &sysctl_intvec
,
904 .extra2
= &one_hundred
,
907 .procname
= "dirty_writeback_centisecs",
908 .data
= &dirty_writeback_interval
,
909 .maxlen
= sizeof(dirty_writeback_interval
),
911 .proc_handler
= &dirty_writeback_centisecs_handler
,
914 .procname
= "dirty_expire_centisecs",
915 .data
= &dirty_expire_interval
,
916 .maxlen
= sizeof(dirty_expire_interval
),
918 .proc_handler
= &proc_dointvec_userhz_jiffies
,
921 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
922 .procname
= "nr_pdflush_threads",
923 .data
= &nr_pdflush_threads
,
924 .maxlen
= sizeof nr_pdflush_threads
,
925 .mode
= 0444 /* read-only*/,
926 .proc_handler
= &proc_dointvec
,
929 .ctl_name
= VM_SWAPPINESS
,
930 .procname
= "swappiness",
931 .data
= &vm_swappiness
,
932 .maxlen
= sizeof(vm_swappiness
),
934 .proc_handler
= &proc_dointvec_minmax
,
935 .strategy
= &sysctl_intvec
,
937 .extra2
= &one_hundred
,
939 #ifdef CONFIG_HUGETLB_PAGE
941 .procname
= "nr_hugepages",
942 .data
= &max_huge_pages
,
943 .maxlen
= sizeof(unsigned long),
945 .proc_handler
= &hugetlb_sysctl_handler
,
946 .extra1
= (void *)&hugetlb_zero
,
947 .extra2
= (void *)&hugetlb_infinity
,
950 .ctl_name
= VM_HUGETLB_GROUP
,
951 .procname
= "hugetlb_shm_group",
952 .data
= &sysctl_hugetlb_shm_group
,
953 .maxlen
= sizeof(gid_t
),
955 .proc_handler
= &proc_dointvec
,
958 .ctl_name
= CTL_UNNUMBERED
,
959 .procname
= "hugepages_treat_as_movable",
960 .data
= &hugepages_treat_as_movable
,
961 .maxlen
= sizeof(int),
963 .proc_handler
= &hugetlb_treat_movable_handler
,
966 .ctl_name
= CTL_UNNUMBERED
,
967 .procname
= "nr_overcommit_hugepages",
968 .data
= &sysctl_overcommit_huge_pages
,
969 .maxlen
= sizeof(sysctl_overcommit_huge_pages
),
971 .proc_handler
= &hugetlb_overcommit_handler
,
975 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
976 .procname
= "lowmem_reserve_ratio",
977 .data
= &sysctl_lowmem_reserve_ratio
,
978 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
980 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
981 .strategy
= &sysctl_intvec
,
984 .ctl_name
= VM_DROP_PAGECACHE
,
985 .procname
= "drop_caches",
986 .data
= &sysctl_drop_caches
,
987 .maxlen
= sizeof(int),
989 .proc_handler
= drop_caches_sysctl_handler
,
990 .strategy
= &sysctl_intvec
,
993 .ctl_name
= VM_MIN_FREE_KBYTES
,
994 .procname
= "min_free_kbytes",
995 .data
= &min_free_kbytes
,
996 .maxlen
= sizeof(min_free_kbytes
),
998 .proc_handler
= &min_free_kbytes_sysctl_handler
,
999 .strategy
= &sysctl_intvec
,
1003 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1004 .procname
= "percpu_pagelist_fraction",
1005 .data
= &percpu_pagelist_fraction
,
1006 .maxlen
= sizeof(percpu_pagelist_fraction
),
1008 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1009 .strategy
= &sysctl_intvec
,
1010 .extra1
= &min_percpu_pagelist_fract
,
1014 .ctl_name
= VM_MAX_MAP_COUNT
,
1015 .procname
= "max_map_count",
1016 .data
= &sysctl_max_map_count
,
1017 .maxlen
= sizeof(sysctl_max_map_count
),
1019 .proc_handler
= &proc_dointvec
1023 .ctl_name
= VM_LAPTOP_MODE
,
1024 .procname
= "laptop_mode",
1025 .data
= &laptop_mode
,
1026 .maxlen
= sizeof(laptop_mode
),
1028 .proc_handler
= &proc_dointvec_jiffies
,
1029 .strategy
= &sysctl_jiffies
,
1032 .ctl_name
= VM_BLOCK_DUMP
,
1033 .procname
= "block_dump",
1034 .data
= &block_dump
,
1035 .maxlen
= sizeof(block_dump
),
1037 .proc_handler
= &proc_dointvec
,
1038 .strategy
= &sysctl_intvec
,
1042 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1043 .procname
= "vfs_cache_pressure",
1044 .data
= &sysctl_vfs_cache_pressure
,
1045 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1047 .proc_handler
= &proc_dointvec
,
1048 .strategy
= &sysctl_intvec
,
1051 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1053 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1054 .procname
= "legacy_va_layout",
1055 .data
= &sysctl_legacy_va_layout
,
1056 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1058 .proc_handler
= &proc_dointvec
,
1059 .strategy
= &sysctl_intvec
,
1065 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1066 .procname
= "zone_reclaim_mode",
1067 .data
= &zone_reclaim_mode
,
1068 .maxlen
= sizeof(zone_reclaim_mode
),
1070 .proc_handler
= &proc_dointvec
,
1071 .strategy
= &sysctl_intvec
,
1075 .ctl_name
= VM_MIN_UNMAPPED
,
1076 .procname
= "min_unmapped_ratio",
1077 .data
= &sysctl_min_unmapped_ratio
,
1078 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1080 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1081 .strategy
= &sysctl_intvec
,
1083 .extra2
= &one_hundred
,
1086 .ctl_name
= VM_MIN_SLAB
,
1087 .procname
= "min_slab_ratio",
1088 .data
= &sysctl_min_slab_ratio
,
1089 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1091 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1092 .strategy
= &sysctl_intvec
,
1094 .extra2
= &one_hundred
,
1099 .ctl_name
= CTL_UNNUMBERED
,
1100 .procname
= "stat_interval",
1101 .data
= &sysctl_stat_interval
,
1102 .maxlen
= sizeof(sysctl_stat_interval
),
1104 .proc_handler
= &proc_dointvec_jiffies
,
1105 .strategy
= &sysctl_jiffies
,
1108 #ifdef CONFIG_SECURITY
1110 .ctl_name
= CTL_UNNUMBERED
,
1111 .procname
= "mmap_min_addr",
1112 .data
= &mmap_min_addr
,
1113 .maxlen
= sizeof(unsigned long),
1115 .proc_handler
= &proc_doulongvec_minmax
,
1120 .ctl_name
= CTL_UNNUMBERED
,
1121 .procname
= "numa_zonelist_order",
1122 .data
= &numa_zonelist_order
,
1123 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1125 .proc_handler
= &numa_zonelist_order_handler
,
1126 .strategy
= &sysctl_string
,
1129 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1130 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1132 .ctl_name
= VM_VDSO_ENABLED
,
1133 .procname
= "vdso_enabled",
1134 .data
= &vdso_enabled
,
1135 .maxlen
= sizeof(vdso_enabled
),
1137 .proc_handler
= &proc_dointvec
,
1138 .strategy
= &sysctl_intvec
,
1142 #ifdef CONFIG_HIGHMEM
1144 .ctl_name
= CTL_UNNUMBERED
,
1145 .procname
= "highmem_is_dirtyable",
1146 .data
= &vm_highmem_is_dirtyable
,
1147 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1149 .proc_handler
= &proc_dointvec_minmax
,
1150 .strategy
= &sysctl_intvec
,
1156 * NOTE: do not add new entries to this table unless you have read
1157 * Documentation/sysctl/ctl_unnumbered.txt
1162 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1163 static struct ctl_table binfmt_misc_table
[] = {
1168 static struct ctl_table fs_table
[] = {
1170 .ctl_name
= FS_NRINODE
,
1171 .procname
= "inode-nr",
1172 .data
= &inodes_stat
,
1173 .maxlen
= 2*sizeof(int),
1175 .proc_handler
= &proc_dointvec
,
1178 .ctl_name
= FS_STATINODE
,
1179 .procname
= "inode-state",
1180 .data
= &inodes_stat
,
1181 .maxlen
= 7*sizeof(int),
1183 .proc_handler
= &proc_dointvec
,
1186 .procname
= "file-nr",
1187 .data
= &files_stat
,
1188 .maxlen
= 3*sizeof(int),
1190 .proc_handler
= &proc_nr_files
,
1193 .ctl_name
= FS_MAXFILE
,
1194 .procname
= "file-max",
1195 .data
= &files_stat
.max_files
,
1196 .maxlen
= sizeof(int),
1198 .proc_handler
= &proc_dointvec
,
1201 .ctl_name
= CTL_UNNUMBERED
,
1202 .procname
= "nr_open",
1203 .data
= &sysctl_nr_open
,
1204 .maxlen
= sizeof(int),
1206 .proc_handler
= &proc_dointvec_minmax
,
1207 .extra1
= &sysctl_nr_open_min
,
1208 .extra2
= &sysctl_nr_open_max
,
1211 .ctl_name
= FS_DENTRY
,
1212 .procname
= "dentry-state",
1213 .data
= &dentry_stat
,
1214 .maxlen
= 6*sizeof(int),
1216 .proc_handler
= &proc_dointvec
,
1219 .ctl_name
= FS_OVERFLOWUID
,
1220 .procname
= "overflowuid",
1221 .data
= &fs_overflowuid
,
1222 .maxlen
= sizeof(int),
1224 .proc_handler
= &proc_dointvec_minmax
,
1225 .strategy
= &sysctl_intvec
,
1226 .extra1
= &minolduid
,
1227 .extra2
= &maxolduid
,
1230 .ctl_name
= FS_OVERFLOWGID
,
1231 .procname
= "overflowgid",
1232 .data
= &fs_overflowgid
,
1233 .maxlen
= sizeof(int),
1235 .proc_handler
= &proc_dointvec_minmax
,
1236 .strategy
= &sysctl_intvec
,
1237 .extra1
= &minolduid
,
1238 .extra2
= &maxolduid
,
1241 .ctl_name
= FS_LEASES
,
1242 .procname
= "leases-enable",
1243 .data
= &leases_enable
,
1244 .maxlen
= sizeof(int),
1246 .proc_handler
= &proc_dointvec
,
1248 #ifdef CONFIG_DNOTIFY
1250 .ctl_name
= FS_DIR_NOTIFY
,
1251 .procname
= "dir-notify-enable",
1252 .data
= &dir_notify_enable
,
1253 .maxlen
= sizeof(int),
1255 .proc_handler
= &proc_dointvec
,
1260 .ctl_name
= FS_LEASE_TIME
,
1261 .procname
= "lease-break-time",
1262 .data
= &lease_break_time
,
1263 .maxlen
= sizeof(int),
1265 .proc_handler
= &proc_dointvec_minmax
,
1266 .strategy
= &sysctl_intvec
,
1271 .procname
= "aio-nr",
1273 .maxlen
= sizeof(aio_nr
),
1275 .proc_handler
= &proc_doulongvec_minmax
,
1278 .procname
= "aio-max-nr",
1279 .data
= &aio_max_nr
,
1280 .maxlen
= sizeof(aio_max_nr
),
1282 .proc_handler
= &proc_doulongvec_minmax
,
1284 #ifdef CONFIG_INOTIFY_USER
1286 .ctl_name
= FS_INOTIFY
,
1287 .procname
= "inotify",
1289 .child
= inotify_table
,
1294 .ctl_name
= KERN_SETUID_DUMPABLE
,
1295 .procname
= "suid_dumpable",
1296 .data
= &suid_dumpable
,
1297 .maxlen
= sizeof(int),
1299 .proc_handler
= &proc_dointvec
,
1301 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1303 .ctl_name
= CTL_UNNUMBERED
,
1304 .procname
= "binfmt_misc",
1306 .child
= binfmt_misc_table
,
1310 * NOTE: do not add new entries to this table unless you have read
1311 * Documentation/sysctl/ctl_unnumbered.txt
1316 static struct ctl_table debug_table
[] = {
1317 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1319 .ctl_name
= CTL_UNNUMBERED
,
1320 .procname
= "exception-trace",
1321 .data
= &show_unhandled_signals
,
1322 .maxlen
= sizeof(int),
1324 .proc_handler
= proc_dointvec
1330 static struct ctl_table dev_table
[] = {
1334 static DEFINE_SPINLOCK(sysctl_lock
);
1336 /* called under sysctl_lock */
1337 static int use_table(struct ctl_table_header
*p
)
1339 if (unlikely(p
->unregistering
))
1345 /* called under sysctl_lock */
1346 static void unuse_table(struct ctl_table_header
*p
)
1349 if (unlikely(p
->unregistering
))
1350 complete(p
->unregistering
);
1353 /* called under sysctl_lock, will reacquire if has to wait */
1354 static void start_unregistering(struct ctl_table_header
*p
)
1357 * if p->used is 0, nobody will ever touch that entry again;
1358 * we'll eliminate all paths to it before dropping sysctl_lock
1360 if (unlikely(p
->used
)) {
1361 struct completion wait
;
1362 init_completion(&wait
);
1363 p
->unregistering
= &wait
;
1364 spin_unlock(&sysctl_lock
);
1365 wait_for_completion(&wait
);
1366 spin_lock(&sysctl_lock
);
1369 * do not remove from the list until nobody holds it; walking the
1370 * list in do_sysctl() relies on that.
1372 list_del_init(&p
->ctl_entry
);
1375 void sysctl_head_finish(struct ctl_table_header
*head
)
1379 spin_lock(&sysctl_lock
);
1381 spin_unlock(&sysctl_lock
);
1384 static struct list_head
*
1385 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1387 struct list_head
*header_list
;
1388 header_list
= &root
->header_list
;
1390 header_list
= root
->lookup(root
, namespaces
);
1394 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1395 struct ctl_table_header
*prev
)
1397 struct ctl_table_root
*root
;
1398 struct list_head
*header_list
;
1399 struct ctl_table_header
*head
;
1400 struct list_head
*tmp
;
1402 spin_lock(&sysctl_lock
);
1405 tmp
= &prev
->ctl_entry
;
1409 tmp
= &root_table_header
.ctl_entry
;
1411 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1413 if (!use_table(head
))
1415 spin_unlock(&sysctl_lock
);
1420 header_list
= lookup_header_list(root
, namespaces
);
1421 if (tmp
!= header_list
)
1425 root
= list_entry(root
->root_list
.next
,
1426 struct ctl_table_root
, root_list
);
1427 if (root
== &sysctl_table_root
)
1429 header_list
= lookup_header_list(root
, namespaces
);
1430 } while (list_empty(header_list
));
1431 tmp
= header_list
->next
;
1434 spin_unlock(&sysctl_lock
);
1438 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1440 return __sysctl_head_next(current
->nsproxy
, prev
);
1443 void register_sysctl_root(struct ctl_table_root
*root
)
1445 spin_lock(&sysctl_lock
);
1446 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1447 spin_unlock(&sysctl_lock
);
1450 #ifdef CONFIG_SYSCTL_SYSCALL
1451 /* Perform the actual read/write of a sysctl table entry. */
1452 static int do_sysctl_strategy(struct ctl_table_root
*root
,
1453 struct ctl_table
*table
,
1454 int __user
*name
, int nlen
,
1455 void __user
*oldval
, size_t __user
*oldlenp
,
1456 void __user
*newval
, size_t newlen
)
1464 if (sysctl_perm(root
, table
, op
))
1467 if (table
->strategy
) {
1468 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1476 /* If there is no strategy routine, or if the strategy returns
1477 * zero, proceed with automatic r/w */
1478 if (table
->data
&& table
->maxlen
) {
1479 rc
= sysctl_data(table
, name
, nlen
, oldval
, oldlenp
,
1487 static int parse_table(int __user
*name
, int nlen
,
1488 void __user
*oldval
, size_t __user
*oldlenp
,
1489 void __user
*newval
, size_t newlen
,
1490 struct ctl_table_root
*root
,
1491 struct ctl_table
*table
)
1497 if (get_user(n
, name
))
1499 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1500 if (!table
->ctl_name
)
1502 if (n
== table
->ctl_name
) {
1505 if (sysctl_perm(root
, table
, 001))
1509 table
= table
->child
;
1512 error
= do_sysctl_strategy(root
, table
, name
, nlen
,
1521 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1522 void __user
*newval
, size_t newlen
)
1524 struct ctl_table_header
*head
;
1525 int error
= -ENOTDIR
;
1527 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1531 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1535 for (head
= sysctl_head_next(NULL
); head
;
1536 head
= sysctl_head_next(head
)) {
1537 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1539 head
->root
, head
->ctl_table
);
1540 if (error
!= -ENOTDIR
) {
1541 sysctl_head_finish(head
);
1548 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1550 struct __sysctl_args tmp
;
1553 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1556 error
= deprecated_sysctl_warning(&tmp
);
1561 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1562 tmp
.newval
, tmp
.newlen
);
1567 #endif /* CONFIG_SYSCTL_SYSCALL */
1570 * sysctl_perm does NOT grant the superuser all rights automatically, because
1571 * some sysctl variables are readonly even to root.
1574 static int test_perm(int mode
, int op
)
1578 else if (in_egroup_p(0))
1580 if ((mode
& op
& 0007) == op
)
1585 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1590 error
= security_sysctl(table
, op
);
1594 if (root
->permissions
)
1595 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1599 return test_perm(mode
, op
);
1602 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1604 for (; table
->ctl_name
|| table
->procname
; table
++) {
1605 table
->parent
= parent
;
1607 sysctl_set_parent(table
, table
->child
);
1611 static __init
int sysctl_init(void)
1613 sysctl_set_parent(NULL
, root_table
);
1614 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1617 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1623 core_initcall(sysctl_init
);
1626 * __register_sysctl_paths - register a sysctl hierarchy
1627 * @root: List of sysctl headers to register on
1628 * @namespaces: Data to compute which lists of sysctl entries are visible
1629 * @path: The path to the directory the sysctl table is in.
1630 * @table: the top-level table structure
1632 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1633 * array. A completely 0 filled entry terminates the table.
1635 * The members of the &struct ctl_table structure are used as follows:
1637 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1638 * must be unique within that level of sysctl
1640 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1641 * enter a sysctl file
1643 * data - a pointer to data for use by proc_handler
1645 * maxlen - the maximum size in bytes of the data
1647 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1649 * child - a pointer to the child sysctl table if this entry is a directory, or
1652 * proc_handler - the text handler routine (described below)
1654 * strategy - the strategy routine (described below)
1656 * de - for internal use by the sysctl routines
1658 * extra1, extra2 - extra pointers usable by the proc handler routines
1660 * Leaf nodes in the sysctl tree will be represented by a single file
1661 * under /proc; non-leaf nodes will be represented by directories.
1663 * sysctl(2) can automatically manage read and write requests through
1664 * the sysctl table. The data and maxlen fields of the ctl_table
1665 * struct enable minimal validation of the values being written to be
1666 * performed, and the mode field allows minimal authentication.
1668 * More sophisticated management can be enabled by the provision of a
1669 * strategy routine with the table entry. This will be called before
1670 * any automatic read or write of the data is performed.
1672 * The strategy routine may return
1674 * < 0 - Error occurred (error is passed to user process)
1676 * 0 - OK - proceed with automatic read or write.
1678 * > 0 - OK - read or write has been done by the strategy routine, so
1679 * return immediately.
1681 * There must be a proc_handler routine for any terminal nodes
1682 * mirrored under /proc/sys (non-terminals are handled by a built-in
1683 * directory handler). Several default handlers are available to
1684 * cover common cases -
1686 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1687 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1688 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1690 * It is the handler's job to read the input buffer from user memory
1691 * and process it. The handler should return 0 on success.
1693 * This routine returns %NULL on a failure to register, and a pointer
1694 * to the table header on success.
1696 struct ctl_table_header
*__register_sysctl_paths(
1697 struct ctl_table_root
*root
,
1698 struct nsproxy
*namespaces
,
1699 const struct ctl_path
*path
, struct ctl_table
*table
)
1701 struct list_head
*header_list
;
1702 struct ctl_table_header
*header
;
1703 struct ctl_table
*new, **prevp
;
1704 unsigned int n
, npath
;
1706 /* Count the path components */
1707 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
1711 * For each path component, allocate a 2-element ctl_table array.
1712 * The first array element will be filled with the sysctl entry
1713 * for this, the second will be the sentinel (ctl_name == 0).
1715 * We allocate everything in one go so that we don't have to
1716 * worry about freeing additional memory in unregister_sysctl_table.
1718 header
= kzalloc(sizeof(struct ctl_table_header
) +
1719 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1723 new = (struct ctl_table
*) (header
+ 1);
1725 /* Now connect the dots */
1726 prevp
= &header
->ctl_table
;
1727 for (n
= 0; n
< npath
; ++n
, ++path
) {
1728 /* Copy the procname */
1729 new->procname
= path
->procname
;
1730 new->ctl_name
= path
->ctl_name
;
1734 prevp
= &new->child
;
1739 header
->ctl_table_arg
= table
;
1741 INIT_LIST_HEAD(&header
->ctl_entry
);
1743 header
->unregistering
= NULL
;
1744 header
->root
= root
;
1745 sysctl_set_parent(NULL
, header
->ctl_table
);
1746 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1747 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1752 spin_lock(&sysctl_lock
);
1753 header_list
= lookup_header_list(root
, namespaces
);
1754 list_add_tail(&header
->ctl_entry
, header_list
);
1755 spin_unlock(&sysctl_lock
);
1761 * register_sysctl_table_path - register a sysctl table hierarchy
1762 * @path: The path to the directory the sysctl table is in.
1763 * @table: the top-level table structure
1765 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1766 * array. A completely 0 filled entry terminates the table.
1768 * See __register_sysctl_paths for more details.
1770 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1771 struct ctl_table
*table
)
1773 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1778 * register_sysctl_table - register a sysctl table hierarchy
1779 * @table: the top-level table structure
1781 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1782 * array. A completely 0 filled entry terminates the table.
1784 * See register_sysctl_paths for more details.
1786 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1788 static const struct ctl_path null_path
[] = { {} };
1790 return register_sysctl_paths(null_path
, table
);
1794 * unregister_sysctl_table - unregister a sysctl table hierarchy
1795 * @header: the header returned from register_sysctl_table
1797 * Unregisters the sysctl table and all children. proc entries may not
1798 * actually be removed until they are no longer used by anyone.
1800 void unregister_sysctl_table(struct ctl_table_header
* header
)
1807 spin_lock(&sysctl_lock
);
1808 start_unregistering(header
);
1809 spin_unlock(&sysctl_lock
);
1813 #else /* !CONFIG_SYSCTL */
1814 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1819 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1820 struct ctl_table
*table
)
1825 void unregister_sysctl_table(struct ctl_table_header
* table
)
1829 #endif /* CONFIG_SYSCTL */
1835 #ifdef CONFIG_PROC_SYSCTL
1837 static int _proc_do_string(void* data
, int maxlen
, int write
,
1838 struct file
*filp
, void __user
*buffer
,
1839 size_t *lenp
, loff_t
*ppos
)
1845 if (!data
|| !maxlen
|| !*lenp
) {
1853 while (len
< *lenp
) {
1854 if (get_user(c
, p
++))
1856 if (c
== 0 || c
== '\n')
1862 if(copy_from_user(data
, buffer
, len
))
1864 ((char *) data
)[len
] = 0;
1882 if(copy_to_user(buffer
, data
, len
))
1885 if(put_user('\n', ((char __user
*) buffer
) + len
))
1896 * proc_dostring - read a string sysctl
1897 * @table: the sysctl table
1898 * @write: %TRUE if this is a write to the sysctl file
1899 * @filp: the file structure
1900 * @buffer: the user buffer
1901 * @lenp: the size of the user buffer
1902 * @ppos: file position
1904 * Reads/writes a string from/to the user buffer. If the kernel
1905 * buffer provided is not large enough to hold the string, the
1906 * string is truncated. The copied string is %NULL-terminated.
1907 * If the string is being read by the user process, it is copied
1908 * and a newline '\n' is added. It is truncated if the buffer is
1911 * Returns 0 on success.
1913 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
1914 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1916 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
1917 buffer
, lenp
, ppos
);
1921 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1923 int write
, void *data
)
1926 *valp
= *negp
? -*lvalp
: *lvalp
;
1931 *lvalp
= (unsigned long)-val
;
1934 *lvalp
= (unsigned long)val
;
1940 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1941 int write
, struct file
*filp
, void __user
*buffer
,
1942 size_t *lenp
, loff_t
*ppos
,
1943 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1944 int write
, void *data
),
1947 #define TMPBUFLEN 21
1948 int *i
, vleft
, first
=1, neg
, val
;
1952 char buf
[TMPBUFLEN
], *p
;
1953 char __user
*s
= buffer
;
1955 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
1956 (*ppos
&& !write
)) {
1961 i
= (int *) tbl_data
;
1962 vleft
= table
->maxlen
/ sizeof(*i
);
1966 conv
= do_proc_dointvec_conv
;
1968 for (; left
&& vleft
--; i
++, first
=0) {
1983 if (len
> sizeof(buf
) - 1)
1984 len
= sizeof(buf
) - 1;
1985 if (copy_from_user(buf
, s
, len
))
1989 if (*p
== '-' && left
> 1) {
1993 if (*p
< '0' || *p
> '9')
1996 lval
= simple_strtoul(p
, &p
, 0);
1999 if ((len
< left
) && *p
&& !isspace(*p
))
2006 if (conv(&neg
, &lval
, i
, 1, data
))
2013 if (conv(&neg
, &lval
, i
, 0, data
))
2016 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2020 if(copy_to_user(s
, buf
, len
))
2027 if (!write
&& !first
&& left
) {
2028 if(put_user('\n', s
))
2035 if (get_user(c
, s
++))
2050 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2051 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2052 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2053 int write
, void *data
),
2056 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2057 buffer
, lenp
, ppos
, conv
, data
);
2061 * proc_dointvec - read a vector of integers
2062 * @table: the sysctl table
2063 * @write: %TRUE if this is a write to the sysctl file
2064 * @filp: the file structure
2065 * @buffer: the user buffer
2066 * @lenp: the size of the user buffer
2067 * @ppos: file position
2069 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2070 * values from/to the user buffer, treated as an ASCII string.
2072 * Returns 0 on success.
2074 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2075 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2077 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2085 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
2087 int write
, void *data
)
2089 int op
= *(int *)data
;
2091 int val
= *negp
? -*lvalp
: *lvalp
;
2093 case OP_SET
: *valp
= val
; break;
2094 case OP_AND
: *valp
&= val
; break;
2095 case OP_OR
: *valp
|= val
; break;
2101 *lvalp
= (unsigned long)-val
;
2104 *lvalp
= (unsigned long)val
;
2111 * Taint values can only be increased
2113 static int proc_dointvec_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2114 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2118 if (write
&& !capable(CAP_SYS_ADMIN
))
2122 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2123 do_proc_dointvec_bset_conv
,&op
);
2126 struct do_proc_dointvec_minmax_conv_param
{
2131 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2133 int write
, void *data
)
2135 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2137 int val
= *negp
? -*lvalp
: *lvalp
;
2138 if ((param
->min
&& *param
->min
> val
) ||
2139 (param
->max
&& *param
->max
< val
))
2146 *lvalp
= (unsigned long)-val
;
2149 *lvalp
= (unsigned long)val
;
2156 * proc_dointvec_minmax - read a vector of integers with min/max values
2157 * @table: the sysctl table
2158 * @write: %TRUE if this is a write to the sysctl file
2159 * @filp: the file structure
2160 * @buffer: the user buffer
2161 * @lenp: the size of the user buffer
2162 * @ppos: file position
2164 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2165 * values from/to the user buffer, treated as an ASCII string.
2167 * This routine will ensure the values are within the range specified by
2168 * table->extra1 (min) and table->extra2 (max).
2170 * Returns 0 on success.
2172 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2173 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2175 struct do_proc_dointvec_minmax_conv_param param
= {
2176 .min
= (int *) table
->extra1
,
2177 .max
= (int *) table
->extra2
,
2179 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2180 do_proc_dointvec_minmax_conv
, ¶m
);
2183 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2185 void __user
*buffer
,
2186 size_t *lenp
, loff_t
*ppos
,
2187 unsigned long convmul
,
2188 unsigned long convdiv
)
2190 #define TMPBUFLEN 21
2191 unsigned long *i
, *min
, *max
, val
;
2192 int vleft
, first
=1, neg
;
2194 char buf
[TMPBUFLEN
], *p
;
2195 char __user
*s
= buffer
;
2197 if (!data
|| !table
->maxlen
|| !*lenp
||
2198 (*ppos
&& !write
)) {
2203 i
= (unsigned long *) data
;
2204 min
= (unsigned long *) table
->extra1
;
2205 max
= (unsigned long *) table
->extra2
;
2206 vleft
= table
->maxlen
/ sizeof(unsigned long);
2209 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2224 if (len
> TMPBUFLEN
-1)
2226 if (copy_from_user(buf
, s
, len
))
2230 if (*p
== '-' && left
> 1) {
2234 if (*p
< '0' || *p
> '9')
2236 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2238 if ((len
< left
) && *p
&& !isspace(*p
))
2247 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2254 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2258 if(copy_to_user(s
, buf
, len
))
2265 if (!write
&& !first
&& left
) {
2266 if(put_user('\n', s
))
2273 if (get_user(c
, s
++))
2288 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2290 void __user
*buffer
,
2291 size_t *lenp
, loff_t
*ppos
,
2292 unsigned long convmul
,
2293 unsigned long convdiv
)
2295 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2296 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2300 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2301 * @table: the sysctl table
2302 * @write: %TRUE if this is a write to the sysctl file
2303 * @filp: the file structure
2304 * @buffer: the user buffer
2305 * @lenp: the size of the user buffer
2306 * @ppos: file position
2308 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2309 * values from/to the user buffer, treated as an ASCII string.
2311 * This routine will ensure the values are within the range specified by
2312 * table->extra1 (min) and table->extra2 (max).
2314 * Returns 0 on success.
2316 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2317 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2319 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2323 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2324 * @table: the sysctl table
2325 * @write: %TRUE if this is a write to the sysctl file
2326 * @filp: the file structure
2327 * @buffer: the user buffer
2328 * @lenp: the size of the user buffer
2329 * @ppos: file position
2331 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2332 * values from/to the user buffer, treated as an ASCII string. The values
2333 * are treated as milliseconds, and converted to jiffies when they are stored.
2335 * This routine will ensure the values are within the range specified by
2336 * table->extra1 (min) and table->extra2 (max).
2338 * Returns 0 on success.
2340 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2342 void __user
*buffer
,
2343 size_t *lenp
, loff_t
*ppos
)
2345 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2346 lenp
, ppos
, HZ
, 1000l);
2350 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2352 int write
, void *data
)
2355 if (*lvalp
> LONG_MAX
/ HZ
)
2357 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2363 lval
= (unsigned long)-val
;
2366 lval
= (unsigned long)val
;
2373 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2375 int write
, void *data
)
2378 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2380 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2386 lval
= (unsigned long)-val
;
2389 lval
= (unsigned long)val
;
2391 *lvalp
= jiffies_to_clock_t(lval
);
2396 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2398 int write
, void *data
)
2401 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2407 lval
= (unsigned long)-val
;
2410 lval
= (unsigned long)val
;
2412 *lvalp
= jiffies_to_msecs(lval
);
2418 * proc_dointvec_jiffies - read a vector of integers as seconds
2419 * @table: the sysctl table
2420 * @write: %TRUE if this is a write to the sysctl file
2421 * @filp: the file structure
2422 * @buffer: the user buffer
2423 * @lenp: the size of the user buffer
2424 * @ppos: file position
2426 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2427 * values from/to the user buffer, treated as an ASCII string.
2428 * The values read are assumed to be in seconds, and are converted into
2431 * Returns 0 on success.
2433 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2434 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2436 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2437 do_proc_dointvec_jiffies_conv
,NULL
);
2441 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2442 * @table: the sysctl table
2443 * @write: %TRUE if this is a write to the sysctl file
2444 * @filp: the file structure
2445 * @buffer: the user buffer
2446 * @lenp: the size of the user buffer
2447 * @ppos: pointer to the file position
2449 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2450 * values from/to the user buffer, treated as an ASCII string.
2451 * The values read are assumed to be in 1/USER_HZ seconds, and
2452 * are converted into jiffies.
2454 * Returns 0 on success.
2456 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2457 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2459 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2460 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2464 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2465 * @table: the sysctl table
2466 * @write: %TRUE if this is a write to the sysctl file
2467 * @filp: the file structure
2468 * @buffer: the user buffer
2469 * @lenp: the size of the user buffer
2470 * @ppos: file position
2471 * @ppos: the current position in the file
2473 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2474 * values from/to the user buffer, treated as an ASCII string.
2475 * The values read are assumed to be in 1/1000 seconds, and
2476 * are converted into jiffies.
2478 * Returns 0 on success.
2480 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2481 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2483 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2484 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2487 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2488 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2490 struct pid
*new_pid
;
2494 tmp
= pid_vnr(cad_pid
);
2496 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2497 lenp
, ppos
, NULL
, NULL
);
2501 new_pid
= find_get_pid(tmp
);
2505 put_pid(xchg(&cad_pid
, new_pid
));
2509 #else /* CONFIG_PROC_FS */
2511 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2512 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2517 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2518 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2523 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2524 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2529 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2530 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2535 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2536 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2541 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2542 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2547 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2548 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2553 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2555 void __user
*buffer
,
2556 size_t *lenp
, loff_t
*ppos
)
2562 #endif /* CONFIG_PROC_FS */
2565 #ifdef CONFIG_SYSCTL_SYSCALL
2567 * General sysctl support routines
2570 /* The generic sysctl data routine (used if no strategy routine supplied) */
2571 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2572 void __user
*oldval
, size_t __user
*oldlenp
,
2573 void __user
*newval
, size_t newlen
)
2577 /* Get out of I don't have a variable */
2578 if (!table
->data
|| !table
->maxlen
)
2581 if (oldval
&& oldlenp
) {
2582 if (get_user(len
, oldlenp
))
2585 if (len
> table
->maxlen
)
2586 len
= table
->maxlen
;
2587 if (copy_to_user(oldval
, table
->data
, len
))
2589 if (put_user(len
, oldlenp
))
2594 if (newval
&& newlen
) {
2595 if (newlen
> table
->maxlen
)
2596 newlen
= table
->maxlen
;
2598 if (copy_from_user(table
->data
, newval
, newlen
))
2604 /* The generic string strategy routine: */
2605 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2606 void __user
*oldval
, size_t __user
*oldlenp
,
2607 void __user
*newval
, size_t newlen
)
2609 if (!table
->data
|| !table
->maxlen
)
2612 if (oldval
&& oldlenp
) {
2614 if (get_user(bufsize
, oldlenp
))
2617 size_t len
= strlen(table
->data
), copied
;
2619 /* This shouldn't trigger for a well-formed sysctl */
2620 if (len
> table
->maxlen
)
2621 len
= table
->maxlen
;
2623 /* Copy up to a max of bufsize-1 bytes of the string */
2624 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2626 if (copy_to_user(oldval
, table
->data
, copied
) ||
2627 put_user(0, (char __user
*)(oldval
+ copied
)))
2629 if (put_user(len
, oldlenp
))
2633 if (newval
&& newlen
) {
2634 size_t len
= newlen
;
2635 if (len
> table
->maxlen
)
2636 len
= table
->maxlen
;
2637 if(copy_from_user(table
->data
, newval
, len
))
2639 if (len
== table
->maxlen
)
2641 ((char *) table
->data
)[len
] = 0;
2647 * This function makes sure that all of the integers in the vector
2648 * are between the minimum and maximum values given in the arrays
2649 * table->extra1 and table->extra2, respectively.
2651 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2652 void __user
*oldval
, size_t __user
*oldlenp
,
2653 void __user
*newval
, size_t newlen
)
2656 if (newval
&& newlen
) {
2657 int __user
*vec
= (int __user
*) newval
;
2658 int *min
= (int *) table
->extra1
;
2659 int *max
= (int *) table
->extra2
;
2663 if (newlen
% sizeof(int) != 0)
2666 if (!table
->extra1
&& !table
->extra2
)
2669 if (newlen
> table
->maxlen
)
2670 newlen
= table
->maxlen
;
2671 length
= newlen
/ sizeof(int);
2673 for (i
= 0; i
< length
; i
++) {
2675 if (get_user(value
, vec
+ i
))
2677 if (min
&& value
< min
[i
])
2679 if (max
&& value
> max
[i
])
2686 /* Strategy function to convert jiffies to seconds */
2687 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2688 void __user
*oldval
, size_t __user
*oldlenp
,
2689 void __user
*newval
, size_t newlen
)
2691 if (oldval
&& oldlenp
) {
2694 if (get_user(olen
, oldlenp
))
2699 if (olen
< sizeof(int))
2702 val
= *(int *)(table
->data
) / HZ
;
2703 if (put_user(val
, (int __user
*)oldval
))
2705 if (put_user(sizeof(int), oldlenp
))
2709 if (newval
&& newlen
) {
2711 if (newlen
!= sizeof(int))
2713 if (get_user(new, (int __user
*)newval
))
2715 *(int *)(table
->data
) = new*HZ
;
2720 /* Strategy function to convert jiffies to seconds */
2721 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2722 void __user
*oldval
, size_t __user
*oldlenp
,
2723 void __user
*newval
, size_t newlen
)
2725 if (oldval
&& oldlenp
) {
2728 if (get_user(olen
, oldlenp
))
2733 if (olen
< sizeof(int))
2736 val
= jiffies_to_msecs(*(int *)(table
->data
));
2737 if (put_user(val
, (int __user
*)oldval
))
2739 if (put_user(sizeof(int), oldlenp
))
2743 if (newval
&& newlen
) {
2745 if (newlen
!= sizeof(int))
2747 if (get_user(new, (int __user
*)newval
))
2749 *(int *)(table
->data
) = msecs_to_jiffies(new);
2756 #else /* CONFIG_SYSCTL_SYSCALL */
2759 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2761 struct __sysctl_args tmp
;
2764 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
2767 error
= deprecated_sysctl_warning(&tmp
);
2769 /* If no error reading the parameters then just -ENOSYS ... */
2776 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2777 void __user
*oldval
, size_t __user
*oldlenp
,
2778 void __user
*newval
, size_t newlen
)
2783 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2784 void __user
*oldval
, size_t __user
*oldlenp
,
2785 void __user
*newval
, size_t newlen
)
2790 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2791 void __user
*oldval
, size_t __user
*oldlenp
,
2792 void __user
*newval
, size_t newlen
)
2797 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2798 void __user
*oldval
, size_t __user
*oldlenp
,
2799 void __user
*newval
, size_t newlen
)
2804 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2805 void __user
*oldval
, size_t __user
*oldlenp
,
2806 void __user
*newval
, size_t newlen
)
2811 #endif /* CONFIG_SYSCTL_SYSCALL */
2813 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
2815 static int msg_count
;
2816 int name
[CTL_MAXNAME
];
2819 /* Check args->nlen. */
2820 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
2823 /* Read in the sysctl name for better debug message logging */
2824 for (i
= 0; i
< args
->nlen
; i
++)
2825 if (get_user(name
[i
], args
->name
+ i
))
2828 /* Ignore accesses to kernel.version */
2829 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
2832 if (msg_count
< 5) {
2835 "warning: process `%s' used the deprecated sysctl "
2836 "system call with ", current
->comm
);
2837 for (i
= 0; i
< args
->nlen
; i
++)
2838 printk("%d.", name
[i
]);
2845 * No sense putting this after each symbol definition, twice,
2846 * exception granted :-)
2848 EXPORT_SYMBOL(proc_dointvec
);
2849 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2850 EXPORT_SYMBOL(proc_dointvec_minmax
);
2851 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2852 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2853 EXPORT_SYMBOL(proc_dostring
);
2854 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2855 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2856 EXPORT_SYMBOL(register_sysctl_table
);
2857 EXPORT_SYMBOL(register_sysctl_paths
);
2858 EXPORT_SYMBOL(sysctl_intvec
);
2859 EXPORT_SYMBOL(sysctl_jiffies
);
2860 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2861 EXPORT_SYMBOL(sysctl_string
);
2862 EXPORT_SYMBOL(sysctl_data
);
2863 EXPORT_SYMBOL(unregister_sysctl_table
);