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/times.h>
42 #include <linux/limits.h>
43 #include <linux/dcache.h>
44 #include <linux/syscalls.h>
45 #include <linux/nfs_fs.h>
46 #include <linux/acpi.h>
47 #include <linux/reboot.h>
49 #include <asm/uaccess.h>
50 #include <asm/processor.h>
54 #include <asm/stacktrace.h>
58 static int deprecated_sysctl_warning(struct __sysctl_args
*args
);
60 #if defined(CONFIG_SYSCTL)
62 /* External variables not in a header file. */
64 extern int print_fatal_signals
;
65 extern int sysctl_overcommit_memory
;
66 extern int sysctl_overcommit_ratio
;
67 extern int sysctl_panic_on_oom
;
68 extern int sysctl_oom_kill_allocating_task
;
69 extern int sysctl_oom_dump_tasks
;
70 extern int max_threads
;
71 extern int core_uses_pid
;
72 extern int suid_dumpable
;
73 extern char core_pattern
[];
75 extern int min_free_kbytes
;
76 extern int pid_max_min
, pid_max_max
;
77 extern int sysctl_drop_caches
;
78 extern int percpu_pagelist_fraction
;
79 extern int compat_log
;
80 extern int maps_protect
;
81 extern int sysctl_stat_interval
;
82 extern int latencytop_enabled
;
84 /* Constants used for minimum and maximum */
85 #if defined(CONFIG_DETECT_SOFTLOCKUP) || defined(CONFIG_HIGHMEM)
89 #ifdef CONFIG_DETECT_SOFTLOCKUP
90 static int sixty
= 60;
98 static int one_hundred
= 100;
100 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
101 static int maxolduid
= 65535;
102 static int minolduid
;
103 static int min_percpu_pagelist_fract
= 8;
105 static int ngroups_max
= NGROUPS_MAX
;
108 extern char modprobe_path
[];
110 #ifdef CONFIG_CHR_DEV_SG
111 extern int sg_big_buff
;
115 extern char reboot_command
[];
116 extern int stop_a_enabled
;
117 extern int scons_pwroff
;
121 extern int pwrsw_enabled
;
122 extern int unaligned_enabled
;
126 #ifdef CONFIG_MATHEMU
127 extern int sysctl_ieee_emulation_warnings
;
129 extern int sysctl_userprocess_debug
;
130 extern int spin_retry
;
133 extern int sysctl_hz_timer
;
135 #ifdef CONFIG_BSD_PROCESS_ACCT
136 extern int acct_parm
[];
140 extern int no_unaligned_warning
;
143 #ifdef CONFIG_RT_MUTEXES
144 extern int max_lock_depth
;
147 #ifdef CONFIG_SYSCTL_SYSCALL
148 static int parse_table(int __user
*, int, void __user
*, size_t __user
*,
149 void __user
*, size_t, struct ctl_table
*);
153 #ifdef CONFIG_PROC_SYSCTL
154 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
155 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
156 static int proc_dointvec_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
157 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
160 static struct ctl_table root_table
[];
161 static struct ctl_table_root sysctl_table_root
;
162 static struct ctl_table_header root_table_header
= {
163 .ctl_table
= root_table
,
164 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.header_list
),
165 .root
= &sysctl_table_root
,
167 static struct ctl_table_root sysctl_table_root
= {
168 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
169 .header_list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
172 static struct ctl_table kern_table
[];
173 static struct ctl_table vm_table
[];
174 static struct ctl_table fs_table
[];
175 static struct ctl_table debug_table
[];
176 static struct ctl_table dev_table
[];
177 extern struct ctl_table random_table
[];
178 #ifdef CONFIG_INOTIFY_USER
179 extern struct ctl_table inotify_table
[];
182 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
183 int sysctl_legacy_va_layout
;
186 extern int prove_locking
;
187 extern int lock_stat
;
189 /* The default sysctl tables: */
191 static struct ctl_table root_table
[] = {
193 .ctl_name
= CTL_KERN
,
194 .procname
= "kernel",
211 .ctl_name
= CTL_DEBUG
,
214 .child
= debug_table
,
223 * NOTE: do not add new entries to this table unless you have read
224 * Documentation/sysctl/ctl_unnumbered.txt
229 #ifdef CONFIG_SCHED_DEBUG
230 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
231 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
232 static int min_wakeup_granularity_ns
; /* 0 usecs */
233 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
236 static struct ctl_table kern_table
[] = {
237 #ifdef CONFIG_SCHED_DEBUG
239 .ctl_name
= CTL_UNNUMBERED
,
240 .procname
= "sched_min_granularity_ns",
241 .data
= &sysctl_sched_min_granularity
,
242 .maxlen
= sizeof(unsigned int),
244 .proc_handler
= &sched_nr_latency_handler
,
245 .strategy
= &sysctl_intvec
,
246 .extra1
= &min_sched_granularity_ns
,
247 .extra2
= &max_sched_granularity_ns
,
250 .ctl_name
= CTL_UNNUMBERED
,
251 .procname
= "sched_latency_ns",
252 .data
= &sysctl_sched_latency
,
253 .maxlen
= sizeof(unsigned int),
255 .proc_handler
= &sched_nr_latency_handler
,
256 .strategy
= &sysctl_intvec
,
257 .extra1
= &min_sched_granularity_ns
,
258 .extra2
= &max_sched_granularity_ns
,
261 .ctl_name
= CTL_UNNUMBERED
,
262 .procname
= "sched_wakeup_granularity_ns",
263 .data
= &sysctl_sched_wakeup_granularity
,
264 .maxlen
= sizeof(unsigned int),
266 .proc_handler
= &proc_dointvec_minmax
,
267 .strategy
= &sysctl_intvec
,
268 .extra1
= &min_wakeup_granularity_ns
,
269 .extra2
= &max_wakeup_granularity_ns
,
272 .ctl_name
= CTL_UNNUMBERED
,
273 .procname
= "sched_batch_wakeup_granularity_ns",
274 .data
= &sysctl_sched_batch_wakeup_granularity
,
275 .maxlen
= sizeof(unsigned int),
277 .proc_handler
= &proc_dointvec_minmax
,
278 .strategy
= &sysctl_intvec
,
279 .extra1
= &min_wakeup_granularity_ns
,
280 .extra2
= &max_wakeup_granularity_ns
,
283 .ctl_name
= CTL_UNNUMBERED
,
284 .procname
= "sched_child_runs_first",
285 .data
= &sysctl_sched_child_runs_first
,
286 .maxlen
= sizeof(unsigned int),
288 .proc_handler
= &proc_dointvec
,
291 .ctl_name
= CTL_UNNUMBERED
,
292 .procname
= "sched_features",
293 .data
= &sysctl_sched_features
,
294 .maxlen
= sizeof(unsigned int),
296 .proc_handler
= &proc_dointvec
,
299 .ctl_name
= CTL_UNNUMBERED
,
300 .procname
= "sched_migration_cost",
301 .data
= &sysctl_sched_migration_cost
,
302 .maxlen
= sizeof(unsigned int),
304 .proc_handler
= &proc_dointvec
,
307 .ctl_name
= CTL_UNNUMBERED
,
308 .procname
= "sched_nr_migrate",
309 .data
= &sysctl_sched_nr_migrate
,
310 .maxlen
= sizeof(unsigned int),
312 .proc_handler
= &proc_dointvec
,
314 <<<<<<< HEAD
:kernel
/sysctl
.c
315 #if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_SMP)
317 .ctl_name
= CTL_UNNUMBERED
,
318 .procname
= "sched_min_bal_int_shares",
319 .data
= &sysctl_sched_min_bal_int_shares
,
320 .maxlen
= sizeof(unsigned int),
322 .proc_handler
= &proc_dointvec
,
325 .ctl_name
= CTL_UNNUMBERED
,
326 .procname
= "sched_max_bal_int_shares",
327 .data
= &sysctl_sched_max_bal_int_shares
,
328 .maxlen
= sizeof(unsigned int),
330 .proc_handler
= &proc_dointvec
,
334 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:kernel
/sysctl
.c
337 .ctl_name
= CTL_UNNUMBERED
,
338 .procname
= "sched_rt_period_us",
339 .data
= &sysctl_sched_rt_period
,
340 .maxlen
= sizeof(unsigned int),
342 .proc_handler
= &proc_dointvec
,
345 .ctl_name
= CTL_UNNUMBERED
,
346 .procname
= "sched_rt_runtime_us",
347 .data
= &sysctl_sched_rt_runtime
,
348 .maxlen
= sizeof(int),
350 .proc_handler
= &proc_dointvec
,
353 .ctl_name
= CTL_UNNUMBERED
,
354 .procname
= "sched_compat_yield",
355 .data
= &sysctl_sched_compat_yield
,
356 .maxlen
= sizeof(unsigned int),
358 .proc_handler
= &proc_dointvec
,
360 #ifdef CONFIG_PROVE_LOCKING
362 .ctl_name
= CTL_UNNUMBERED
,
363 .procname
= "prove_locking",
364 .data
= &prove_locking
,
365 .maxlen
= sizeof(int),
367 .proc_handler
= &proc_dointvec
,
370 #ifdef CONFIG_LOCK_STAT
372 .ctl_name
= CTL_UNNUMBERED
,
373 .procname
= "lock_stat",
375 .maxlen
= sizeof(int),
377 .proc_handler
= &proc_dointvec
,
381 .ctl_name
= KERN_PANIC
,
383 .data
= &panic_timeout
,
384 .maxlen
= sizeof(int),
386 .proc_handler
= &proc_dointvec
,
389 .ctl_name
= KERN_CORE_USES_PID
,
390 .procname
= "core_uses_pid",
391 .data
= &core_uses_pid
,
392 .maxlen
= sizeof(int),
394 .proc_handler
= &proc_dointvec
,
397 .ctl_name
= KERN_CORE_PATTERN
,
398 .procname
= "core_pattern",
399 .data
= core_pattern
,
400 .maxlen
= CORENAME_MAX_SIZE
,
402 .proc_handler
= &proc_dostring
,
403 .strategy
= &sysctl_string
,
405 #ifdef CONFIG_PROC_SYSCTL
407 .procname
= "tainted",
409 .maxlen
= sizeof(int),
411 .proc_handler
= &proc_dointvec_taint
,
414 #ifdef CONFIG_LATENCYTOP
416 .procname
= "latencytop",
417 .data
= &latencytop_enabled
,
418 .maxlen
= sizeof(int),
420 .proc_handler
= &proc_dointvec
,
423 #ifdef CONFIG_BLK_DEV_INITRD
425 .ctl_name
= KERN_REALROOTDEV
,
426 .procname
= "real-root-dev",
427 .data
= &real_root_dev
,
428 .maxlen
= sizeof(int),
430 .proc_handler
= &proc_dointvec
,
434 .ctl_name
= CTL_UNNUMBERED
,
435 .procname
= "print-fatal-signals",
436 .data
= &print_fatal_signals
,
437 .maxlen
= sizeof(int),
439 .proc_handler
= &proc_dointvec
,
443 .ctl_name
= KERN_SPARC_REBOOT
,
444 .procname
= "reboot-cmd",
445 .data
= reboot_command
,
448 .proc_handler
= &proc_dostring
,
449 .strategy
= &sysctl_string
,
452 .ctl_name
= KERN_SPARC_STOP_A
,
453 .procname
= "stop-a",
454 .data
= &stop_a_enabled
,
455 .maxlen
= sizeof (int),
457 .proc_handler
= &proc_dointvec
,
460 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
461 .procname
= "scons-poweroff",
462 .data
= &scons_pwroff
,
463 .maxlen
= sizeof (int),
465 .proc_handler
= &proc_dointvec
,
470 .ctl_name
= KERN_HPPA_PWRSW
,
471 .procname
= "soft-power",
472 .data
= &pwrsw_enabled
,
473 .maxlen
= sizeof (int),
475 .proc_handler
= &proc_dointvec
,
478 .ctl_name
= KERN_HPPA_UNALIGNED
,
479 .procname
= "unaligned-trap",
480 .data
= &unaligned_enabled
,
481 .maxlen
= sizeof (int),
483 .proc_handler
= &proc_dointvec
,
487 .ctl_name
= KERN_CTLALTDEL
,
488 .procname
= "ctrl-alt-del",
490 .maxlen
= sizeof(int),
492 .proc_handler
= &proc_dointvec
,
496 .ctl_name
= KERN_MODPROBE
,
497 .procname
= "modprobe",
498 .data
= &modprobe_path
,
499 .maxlen
= KMOD_PATH_LEN
,
501 .proc_handler
= &proc_dostring
,
502 .strategy
= &sysctl_string
,
505 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
507 .ctl_name
= KERN_HOTPLUG
,
508 .procname
= "hotplug",
509 .data
= &uevent_helper
,
510 .maxlen
= UEVENT_HELPER_PATH_LEN
,
512 .proc_handler
= &proc_dostring
,
513 .strategy
= &sysctl_string
,
516 #ifdef CONFIG_CHR_DEV_SG
518 .ctl_name
= KERN_SG_BIG_BUFF
,
519 .procname
= "sg-big-buff",
520 .data
= &sg_big_buff
,
521 .maxlen
= sizeof (int),
523 .proc_handler
= &proc_dointvec
,
526 #ifdef CONFIG_BSD_PROCESS_ACCT
528 .ctl_name
= KERN_ACCT
,
531 .maxlen
= 3*sizeof(int),
533 .proc_handler
= &proc_dointvec
,
536 #ifdef CONFIG_MAGIC_SYSRQ
538 .ctl_name
= KERN_SYSRQ
,
540 .data
= &__sysrq_enabled
,
541 .maxlen
= sizeof (int),
543 .proc_handler
= &proc_dointvec
,
546 #ifdef CONFIG_PROC_SYSCTL
548 .procname
= "cad_pid",
550 .maxlen
= sizeof (int),
552 .proc_handler
= &proc_do_cad_pid
,
556 .ctl_name
= KERN_MAX_THREADS
,
557 .procname
= "threads-max",
558 .data
= &max_threads
,
559 .maxlen
= sizeof(int),
561 .proc_handler
= &proc_dointvec
,
564 .ctl_name
= KERN_RANDOM
,
565 .procname
= "random",
567 .child
= random_table
,
570 .ctl_name
= KERN_OVERFLOWUID
,
571 .procname
= "overflowuid",
572 .data
= &overflowuid
,
573 .maxlen
= sizeof(int),
575 .proc_handler
= &proc_dointvec_minmax
,
576 .strategy
= &sysctl_intvec
,
577 .extra1
= &minolduid
,
578 .extra2
= &maxolduid
,
581 .ctl_name
= KERN_OVERFLOWGID
,
582 .procname
= "overflowgid",
583 .data
= &overflowgid
,
584 .maxlen
= sizeof(int),
586 .proc_handler
= &proc_dointvec_minmax
,
587 .strategy
= &sysctl_intvec
,
588 .extra1
= &minolduid
,
589 .extra2
= &maxolduid
,
592 #ifdef CONFIG_MATHEMU
594 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
595 .procname
= "ieee_emulation_warnings",
596 .data
= &sysctl_ieee_emulation_warnings
,
597 .maxlen
= sizeof(int),
599 .proc_handler
= &proc_dointvec
,
602 #ifdef CONFIG_NO_IDLE_HZ
604 .ctl_name
= KERN_HZ_TIMER
,
605 .procname
= "hz_timer",
606 .data
= &sysctl_hz_timer
,
607 .maxlen
= sizeof(int),
609 .proc_handler
= &proc_dointvec
,
613 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
614 .procname
= "userprocess_debug",
615 .data
= &sysctl_userprocess_debug
,
616 .maxlen
= sizeof(int),
618 .proc_handler
= &proc_dointvec
,
622 .ctl_name
= KERN_PIDMAX
,
623 .procname
= "pid_max",
625 .maxlen
= sizeof (int),
627 .proc_handler
= &proc_dointvec_minmax
,
628 .strategy
= sysctl_intvec
,
629 .extra1
= &pid_max_min
,
630 .extra2
= &pid_max_max
,
633 .ctl_name
= KERN_PANIC_ON_OOPS
,
634 .procname
= "panic_on_oops",
635 .data
= &panic_on_oops
,
636 .maxlen
= sizeof(int),
638 .proc_handler
= &proc_dointvec
,
640 #if defined CONFIG_PRINTK
642 .ctl_name
= KERN_PRINTK
,
643 .procname
= "printk",
644 .data
= &console_loglevel
,
645 .maxlen
= 4*sizeof(int),
647 .proc_handler
= &proc_dointvec
,
650 .ctl_name
= KERN_PRINTK_RATELIMIT
,
651 .procname
= "printk_ratelimit",
652 .data
= &printk_ratelimit_jiffies
,
653 .maxlen
= sizeof(int),
655 .proc_handler
= &proc_dointvec_jiffies
,
656 .strategy
= &sysctl_jiffies
,
659 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
660 .procname
= "printk_ratelimit_burst",
661 .data
= &printk_ratelimit_burst
,
662 .maxlen
= sizeof(int),
664 .proc_handler
= &proc_dointvec
,
668 .ctl_name
= KERN_NGROUPS_MAX
,
669 .procname
= "ngroups_max",
670 .data
= &ngroups_max
,
671 .maxlen
= sizeof (int),
673 .proc_handler
= &proc_dointvec
,
675 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
677 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
678 .procname
= "unknown_nmi_panic",
679 .data
= &unknown_nmi_panic
,
680 .maxlen
= sizeof (int),
682 .proc_handler
= &proc_dointvec
,
685 .procname
= "nmi_watchdog",
686 .data
= &nmi_watchdog_enabled
,
687 .maxlen
= sizeof (int),
689 .proc_handler
= &proc_nmi_enabled
,
692 #if defined(CONFIG_X86)
694 .ctl_name
= KERN_PANIC_ON_NMI
,
695 .procname
= "panic_on_unrecovered_nmi",
696 .data
= &panic_on_unrecovered_nmi
,
697 .maxlen
= sizeof(int),
699 .proc_handler
= &proc_dointvec
,
702 .ctl_name
= KERN_BOOTLOADER_TYPE
,
703 .procname
= "bootloader_type",
704 .data
= &bootloader_type
,
705 .maxlen
= sizeof (int),
707 .proc_handler
= &proc_dointvec
,
710 .ctl_name
= CTL_UNNUMBERED
,
711 .procname
= "kstack_depth_to_print",
712 .data
= &kstack_depth_to_print
,
713 .maxlen
= sizeof(int),
715 .proc_handler
= &proc_dointvec
,
718 .ctl_name
= CTL_UNNUMBERED
,
719 .procname
= "io_delay_type",
720 .data
= &io_delay_type
,
721 .maxlen
= sizeof(int),
723 .proc_handler
= &proc_dointvec
,
726 #if defined(CONFIG_MMU)
728 .ctl_name
= KERN_RANDOMIZE
,
729 .procname
= "randomize_va_space",
730 .data
= &randomize_va_space
,
731 .maxlen
= sizeof(int),
733 .proc_handler
= &proc_dointvec
,
736 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
738 .ctl_name
= KERN_SPIN_RETRY
,
739 .procname
= "spin_retry",
741 .maxlen
= sizeof (int),
743 .proc_handler
= &proc_dointvec
,
746 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
748 .procname
= "acpi_video_flags",
749 .data
= &acpi_realmode_flags
,
750 .maxlen
= sizeof (unsigned long),
752 .proc_handler
= &proc_doulongvec_minmax
,
757 .ctl_name
= KERN_IA64_UNALIGNED
,
758 .procname
= "ignore-unaligned-usertrap",
759 .data
= &no_unaligned_warning
,
760 .maxlen
= sizeof (int),
762 .proc_handler
= &proc_dointvec
,
765 #ifdef CONFIG_DETECT_SOFTLOCKUP
767 .ctl_name
= CTL_UNNUMBERED
,
768 .procname
= "softlockup_thresh",
769 .data
= &softlockup_thresh
,
770 .maxlen
= sizeof(unsigned long),
772 .proc_handler
= &proc_doulongvec_minmax
,
773 .strategy
= &sysctl_intvec
,
778 .ctl_name
= CTL_UNNUMBERED
,
779 .procname
= "hung_task_check_count",
780 .data
= &sysctl_hung_task_check_count
,
781 .maxlen
= sizeof(unsigned long),
783 .proc_handler
= &proc_doulongvec_minmax
,
784 .strategy
= &sysctl_intvec
,
787 .ctl_name
= CTL_UNNUMBERED
,
788 .procname
= "hung_task_timeout_secs",
789 .data
= &sysctl_hung_task_timeout_secs
,
790 .maxlen
= sizeof(unsigned long),
792 .proc_handler
= &proc_doulongvec_minmax
,
793 .strategy
= &sysctl_intvec
,
796 .ctl_name
= CTL_UNNUMBERED
,
797 .procname
= "hung_task_warnings",
798 .data
= &sysctl_hung_task_warnings
,
799 .maxlen
= sizeof(unsigned long),
801 .proc_handler
= &proc_doulongvec_minmax
,
802 .strategy
= &sysctl_intvec
,
807 .ctl_name
= KERN_COMPAT_LOG
,
808 .procname
= "compat-log",
810 .maxlen
= sizeof (int),
812 .proc_handler
= &proc_dointvec
,
815 #ifdef CONFIG_RT_MUTEXES
817 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
818 .procname
= "max_lock_depth",
819 .data
= &max_lock_depth
,
820 .maxlen
= sizeof(int),
822 .proc_handler
= &proc_dointvec
,
825 #ifdef CONFIG_PROC_FS
827 .ctl_name
= CTL_UNNUMBERED
,
828 .procname
= "maps_protect",
829 .data
= &maps_protect
,
830 .maxlen
= sizeof(int),
832 .proc_handler
= &proc_dointvec
,
836 .ctl_name
= CTL_UNNUMBERED
,
837 .procname
= "poweroff_cmd",
838 .data
= &poweroff_cmd
,
839 .maxlen
= POWEROFF_CMD_PATH_LEN
,
841 .proc_handler
= &proc_dostring
,
842 .strategy
= &sysctl_string
,
845 * NOTE: do not add new entries to this table unless you have read
846 * Documentation/sysctl/ctl_unnumbered.txt
851 static struct ctl_table vm_table
[] = {
853 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
854 .procname
= "overcommit_memory",
855 .data
= &sysctl_overcommit_memory
,
856 .maxlen
= sizeof(sysctl_overcommit_memory
),
858 .proc_handler
= &proc_dointvec
,
861 .ctl_name
= VM_PANIC_ON_OOM
,
862 .procname
= "panic_on_oom",
863 .data
= &sysctl_panic_on_oom
,
864 .maxlen
= sizeof(sysctl_panic_on_oom
),
866 .proc_handler
= &proc_dointvec
,
869 .ctl_name
= CTL_UNNUMBERED
,
870 .procname
= "oom_kill_allocating_task",
871 .data
= &sysctl_oom_kill_allocating_task
,
872 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
874 .proc_handler
= &proc_dointvec
,
877 .ctl_name
= CTL_UNNUMBERED
,
878 .procname
= "oom_dump_tasks",
879 .data
= &sysctl_oom_dump_tasks
,
880 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
882 .proc_handler
= &proc_dointvec
,
885 .ctl_name
= VM_OVERCOMMIT_RATIO
,
886 .procname
= "overcommit_ratio",
887 .data
= &sysctl_overcommit_ratio
,
888 .maxlen
= sizeof(sysctl_overcommit_ratio
),
890 .proc_handler
= &proc_dointvec
,
893 .ctl_name
= VM_PAGE_CLUSTER
,
894 .procname
= "page-cluster",
895 .data
= &page_cluster
,
896 .maxlen
= sizeof(int),
898 .proc_handler
= &proc_dointvec
,
901 .ctl_name
= VM_DIRTY_BACKGROUND
,
902 .procname
= "dirty_background_ratio",
903 .data
= &dirty_background_ratio
,
904 .maxlen
= sizeof(dirty_background_ratio
),
906 .proc_handler
= &proc_dointvec_minmax
,
907 .strategy
= &sysctl_intvec
,
909 .extra2
= &one_hundred
,
912 .ctl_name
= VM_DIRTY_RATIO
,
913 .procname
= "dirty_ratio",
914 .data
= &vm_dirty_ratio
,
915 .maxlen
= sizeof(vm_dirty_ratio
),
917 .proc_handler
= &dirty_ratio_handler
,
918 .strategy
= &sysctl_intvec
,
920 .extra2
= &one_hundred
,
923 .procname
= "dirty_writeback_centisecs",
924 .data
= &dirty_writeback_interval
,
925 .maxlen
= sizeof(dirty_writeback_interval
),
927 .proc_handler
= &dirty_writeback_centisecs_handler
,
930 .procname
= "dirty_expire_centisecs",
931 .data
= &dirty_expire_interval
,
932 .maxlen
= sizeof(dirty_expire_interval
),
934 .proc_handler
= &proc_dointvec_userhz_jiffies
,
937 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
938 .procname
= "nr_pdflush_threads",
939 .data
= &nr_pdflush_threads
,
940 .maxlen
= sizeof nr_pdflush_threads
,
941 .mode
= 0444 /* read-only*/,
942 .proc_handler
= &proc_dointvec
,
945 .ctl_name
= VM_SWAPPINESS
,
946 .procname
= "swappiness",
947 .data
= &vm_swappiness
,
948 .maxlen
= sizeof(vm_swappiness
),
950 .proc_handler
= &proc_dointvec_minmax
,
951 .strategy
= &sysctl_intvec
,
953 .extra2
= &one_hundred
,
955 #ifdef CONFIG_HUGETLB_PAGE
957 .procname
= "nr_hugepages",
958 .data
= &max_huge_pages
,
959 .maxlen
= sizeof(unsigned long),
961 .proc_handler
= &hugetlb_sysctl_handler
,
962 .extra1
= (void *)&hugetlb_zero
,
963 .extra2
= (void *)&hugetlb_infinity
,
966 .ctl_name
= VM_HUGETLB_GROUP
,
967 .procname
= "hugetlb_shm_group",
968 .data
= &sysctl_hugetlb_shm_group
,
969 .maxlen
= sizeof(gid_t
),
971 .proc_handler
= &proc_dointvec
,
974 .ctl_name
= CTL_UNNUMBERED
,
975 .procname
= "hugepages_treat_as_movable",
976 .data
= &hugepages_treat_as_movable
,
977 .maxlen
= sizeof(int),
979 .proc_handler
= &hugetlb_treat_movable_handler
,
982 .ctl_name
= CTL_UNNUMBERED
,
983 .procname
= "nr_overcommit_hugepages",
984 .data
= &sysctl_overcommit_huge_pages
,
985 .maxlen
= sizeof(sysctl_overcommit_huge_pages
),
987 .proc_handler
= &hugetlb_overcommit_handler
,
991 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
992 .procname
= "lowmem_reserve_ratio",
993 .data
= &sysctl_lowmem_reserve_ratio
,
994 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
996 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
997 .strategy
= &sysctl_intvec
,
1000 .ctl_name
= VM_DROP_PAGECACHE
,
1001 .procname
= "drop_caches",
1002 .data
= &sysctl_drop_caches
,
1003 .maxlen
= sizeof(int),
1005 .proc_handler
= drop_caches_sysctl_handler
,
1006 .strategy
= &sysctl_intvec
,
1009 .ctl_name
= VM_MIN_FREE_KBYTES
,
1010 .procname
= "min_free_kbytes",
1011 .data
= &min_free_kbytes
,
1012 .maxlen
= sizeof(min_free_kbytes
),
1014 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1015 .strategy
= &sysctl_intvec
,
1019 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1020 .procname
= "percpu_pagelist_fraction",
1021 .data
= &percpu_pagelist_fraction
,
1022 .maxlen
= sizeof(percpu_pagelist_fraction
),
1024 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1025 .strategy
= &sysctl_intvec
,
1026 .extra1
= &min_percpu_pagelist_fract
,
1030 .ctl_name
= VM_MAX_MAP_COUNT
,
1031 .procname
= "max_map_count",
1032 .data
= &sysctl_max_map_count
,
1033 .maxlen
= sizeof(sysctl_max_map_count
),
1035 .proc_handler
= &proc_dointvec
1039 .ctl_name
= VM_LAPTOP_MODE
,
1040 .procname
= "laptop_mode",
1041 .data
= &laptop_mode
,
1042 .maxlen
= sizeof(laptop_mode
),
1044 .proc_handler
= &proc_dointvec_jiffies
,
1045 .strategy
= &sysctl_jiffies
,
1048 .ctl_name
= VM_BLOCK_DUMP
,
1049 .procname
= "block_dump",
1050 .data
= &block_dump
,
1051 .maxlen
= sizeof(block_dump
),
1053 .proc_handler
= &proc_dointvec
,
1054 .strategy
= &sysctl_intvec
,
1058 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1059 .procname
= "vfs_cache_pressure",
1060 .data
= &sysctl_vfs_cache_pressure
,
1061 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1063 .proc_handler
= &proc_dointvec
,
1064 .strategy
= &sysctl_intvec
,
1067 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1069 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1070 .procname
= "legacy_va_layout",
1071 .data
= &sysctl_legacy_va_layout
,
1072 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1074 .proc_handler
= &proc_dointvec
,
1075 .strategy
= &sysctl_intvec
,
1081 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1082 .procname
= "zone_reclaim_mode",
1083 .data
= &zone_reclaim_mode
,
1084 .maxlen
= sizeof(zone_reclaim_mode
),
1086 .proc_handler
= &proc_dointvec
,
1087 .strategy
= &sysctl_intvec
,
1091 .ctl_name
= VM_MIN_UNMAPPED
,
1092 .procname
= "min_unmapped_ratio",
1093 .data
= &sysctl_min_unmapped_ratio
,
1094 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1096 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1097 .strategy
= &sysctl_intvec
,
1099 .extra2
= &one_hundred
,
1102 .ctl_name
= VM_MIN_SLAB
,
1103 .procname
= "min_slab_ratio",
1104 .data
= &sysctl_min_slab_ratio
,
1105 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1107 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1108 .strategy
= &sysctl_intvec
,
1110 .extra2
= &one_hundred
,
1115 .ctl_name
= CTL_UNNUMBERED
,
1116 .procname
= "stat_interval",
1117 .data
= &sysctl_stat_interval
,
1118 .maxlen
= sizeof(sysctl_stat_interval
),
1120 .proc_handler
= &proc_dointvec_jiffies
,
1121 .strategy
= &sysctl_jiffies
,
1124 #ifdef CONFIG_SECURITY
1126 .ctl_name
= CTL_UNNUMBERED
,
1127 .procname
= "mmap_min_addr",
1128 .data
= &mmap_min_addr
,
1129 .maxlen
= sizeof(unsigned long),
1131 .proc_handler
= &proc_doulongvec_minmax
,
1136 .ctl_name
= CTL_UNNUMBERED
,
1137 .procname
= "numa_zonelist_order",
1138 .data
= &numa_zonelist_order
,
1139 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1141 .proc_handler
= &numa_zonelist_order_handler
,
1142 .strategy
= &sysctl_string
,
1145 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1146 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1148 .ctl_name
= VM_VDSO_ENABLED
,
1149 .procname
= "vdso_enabled",
1150 .data
= &vdso_enabled
,
1151 .maxlen
= sizeof(vdso_enabled
),
1153 .proc_handler
= &proc_dointvec
,
1154 .strategy
= &sysctl_intvec
,
1158 #ifdef CONFIG_HIGHMEM
1160 .ctl_name
= CTL_UNNUMBERED
,
1161 .procname
= "highmem_is_dirtyable",
1162 .data
= &vm_highmem_is_dirtyable
,
1163 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1165 .proc_handler
= &proc_dointvec_minmax
,
1166 .strategy
= &sysctl_intvec
,
1172 * NOTE: do not add new entries to this table unless you have read
1173 * Documentation/sysctl/ctl_unnumbered.txt
1178 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1179 static struct ctl_table binfmt_misc_table
[] = {
1184 static struct ctl_table fs_table
[] = {
1186 .ctl_name
= FS_NRINODE
,
1187 .procname
= "inode-nr",
1188 .data
= &inodes_stat
,
1189 .maxlen
= 2*sizeof(int),
1191 .proc_handler
= &proc_dointvec
,
1194 .ctl_name
= FS_STATINODE
,
1195 .procname
= "inode-state",
1196 .data
= &inodes_stat
,
1197 .maxlen
= 7*sizeof(int),
1199 .proc_handler
= &proc_dointvec
,
1202 .procname
= "file-nr",
1203 .data
= &files_stat
,
1204 .maxlen
= 3*sizeof(int),
1206 .proc_handler
= &proc_nr_files
,
1209 .ctl_name
= FS_MAXFILE
,
1210 .procname
= "file-max",
1211 .data
= &files_stat
.max_files
,
1212 .maxlen
= sizeof(int),
1214 .proc_handler
= &proc_dointvec
,
1217 .ctl_name
= CTL_UNNUMBERED
,
1218 .procname
= "nr_open",
1219 .data
= &sysctl_nr_open
,
1220 .maxlen
= sizeof(int),
1222 .proc_handler
= &proc_dointvec
,
1225 .ctl_name
= FS_DENTRY
,
1226 .procname
= "dentry-state",
1227 .data
= &dentry_stat
,
1228 .maxlen
= 6*sizeof(int),
1230 .proc_handler
= &proc_dointvec
,
1233 .ctl_name
= FS_OVERFLOWUID
,
1234 .procname
= "overflowuid",
1235 .data
= &fs_overflowuid
,
1236 .maxlen
= sizeof(int),
1238 .proc_handler
= &proc_dointvec_minmax
,
1239 .strategy
= &sysctl_intvec
,
1240 .extra1
= &minolduid
,
1241 .extra2
= &maxolduid
,
1244 .ctl_name
= FS_OVERFLOWGID
,
1245 .procname
= "overflowgid",
1246 .data
= &fs_overflowgid
,
1247 .maxlen
= sizeof(int),
1249 .proc_handler
= &proc_dointvec_minmax
,
1250 .strategy
= &sysctl_intvec
,
1251 .extra1
= &minolduid
,
1252 .extra2
= &maxolduid
,
1255 .ctl_name
= FS_LEASES
,
1256 .procname
= "leases-enable",
1257 .data
= &leases_enable
,
1258 .maxlen
= sizeof(int),
1260 .proc_handler
= &proc_dointvec
,
1262 #ifdef CONFIG_DNOTIFY
1264 .ctl_name
= FS_DIR_NOTIFY
,
1265 .procname
= "dir-notify-enable",
1266 .data
= &dir_notify_enable
,
1267 .maxlen
= sizeof(int),
1269 .proc_handler
= &proc_dointvec
,
1274 .ctl_name
= FS_LEASE_TIME
,
1275 .procname
= "lease-break-time",
1276 .data
= &lease_break_time
,
1277 .maxlen
= sizeof(int),
1279 .proc_handler
= &proc_dointvec_minmax
,
1280 .strategy
= &sysctl_intvec
,
1285 .procname
= "aio-nr",
1287 .maxlen
= sizeof(aio_nr
),
1289 .proc_handler
= &proc_doulongvec_minmax
,
1292 .procname
= "aio-max-nr",
1293 .data
= &aio_max_nr
,
1294 .maxlen
= sizeof(aio_max_nr
),
1296 .proc_handler
= &proc_doulongvec_minmax
,
1298 #ifdef CONFIG_INOTIFY_USER
1300 .ctl_name
= FS_INOTIFY
,
1301 .procname
= "inotify",
1303 .child
= inotify_table
,
1308 .ctl_name
= KERN_SETUID_DUMPABLE
,
1309 .procname
= "suid_dumpable",
1310 .data
= &suid_dumpable
,
1311 .maxlen
= sizeof(int),
1313 .proc_handler
= &proc_dointvec
,
1315 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1317 .ctl_name
= CTL_UNNUMBERED
,
1318 .procname
= "binfmt_misc",
1320 .child
= binfmt_misc_table
,
1324 * NOTE: do not add new entries to this table unless you have read
1325 * Documentation/sysctl/ctl_unnumbered.txt
1330 static struct ctl_table debug_table
[] = {
1331 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1333 .ctl_name
= CTL_UNNUMBERED
,
1334 .procname
= "exception-trace",
1335 .data
= &show_unhandled_signals
,
1336 .maxlen
= sizeof(int),
1338 .proc_handler
= proc_dointvec
1344 static struct ctl_table dev_table
[] = {
1348 static DEFINE_SPINLOCK(sysctl_lock
);
1350 /* called under sysctl_lock */
1351 static int use_table(struct ctl_table_header
*p
)
1353 if (unlikely(p
->unregistering
))
1359 /* called under sysctl_lock */
1360 static void unuse_table(struct ctl_table_header
*p
)
1363 if (unlikely(p
->unregistering
))
1364 complete(p
->unregistering
);
1367 /* called under sysctl_lock, will reacquire if has to wait */
1368 static void start_unregistering(struct ctl_table_header
*p
)
1371 * if p->used is 0, nobody will ever touch that entry again;
1372 * we'll eliminate all paths to it before dropping sysctl_lock
1374 if (unlikely(p
->used
)) {
1375 struct completion wait
;
1376 init_completion(&wait
);
1377 p
->unregistering
= &wait
;
1378 spin_unlock(&sysctl_lock
);
1379 wait_for_completion(&wait
);
1380 spin_lock(&sysctl_lock
);
1383 * do not remove from the list until nobody holds it; walking the
1384 * list in do_sysctl() relies on that.
1386 list_del_init(&p
->ctl_entry
);
1389 void sysctl_head_finish(struct ctl_table_header
*head
)
1393 spin_lock(&sysctl_lock
);
1395 spin_unlock(&sysctl_lock
);
1398 static struct list_head
*
1399 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1401 struct list_head
*header_list
;
1402 header_list
= &root
->header_list
;
1404 header_list
= root
->lookup(root
, namespaces
);
1408 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1409 struct ctl_table_header
*prev
)
1411 struct ctl_table_root
*root
;
1412 struct list_head
*header_list
;
1413 struct ctl_table_header
*head
;
1414 struct list_head
*tmp
;
1416 spin_lock(&sysctl_lock
);
1419 tmp
= &prev
->ctl_entry
;
1423 tmp
= &root_table_header
.ctl_entry
;
1425 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1427 if (!use_table(head
))
1429 spin_unlock(&sysctl_lock
);
1434 header_list
= lookup_header_list(root
, namespaces
);
1435 if (tmp
!= header_list
)
1439 root
= list_entry(root
->root_list
.next
,
1440 struct ctl_table_root
, root_list
);
1441 if (root
== &sysctl_table_root
)
1443 header_list
= lookup_header_list(root
, namespaces
);
1444 } while (list_empty(header_list
));
1445 tmp
= header_list
->next
;
1448 spin_unlock(&sysctl_lock
);
1452 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1454 return __sysctl_head_next(current
->nsproxy
, prev
);
1457 void register_sysctl_root(struct ctl_table_root
*root
)
1459 spin_lock(&sysctl_lock
);
1460 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1461 spin_unlock(&sysctl_lock
);
1464 #ifdef CONFIG_SYSCTL_SYSCALL
1465 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1466 void __user
*newval
, size_t newlen
)
1468 struct ctl_table_header
*head
;
1469 int error
= -ENOTDIR
;
1471 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1475 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1479 for (head
= sysctl_head_next(NULL
); head
;
1480 head
= sysctl_head_next(head
)) {
1481 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1482 newval
, newlen
, head
->ctl_table
);
1483 if (error
!= -ENOTDIR
) {
1484 sysctl_head_finish(head
);
1491 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1493 struct __sysctl_args tmp
;
1496 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1499 error
= deprecated_sysctl_warning(&tmp
);
1504 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1505 tmp
.newval
, tmp
.newlen
);
1510 #endif /* CONFIG_SYSCTL_SYSCALL */
1513 * sysctl_perm does NOT grant the superuser all rights automatically, because
1514 * some sysctl variables are readonly even to root.
1517 static int test_perm(int mode
, int op
)
1521 else if (in_egroup_p(0))
1523 if ((mode
& op
& 0007) == op
)
1528 int sysctl_perm(struct ctl_table
*table
, int op
)
1531 error
= security_sysctl(table
, op
);
1534 return test_perm(table
->mode
, op
);
1537 #ifdef CONFIG_SYSCTL_SYSCALL
1538 static int parse_table(int __user
*name
, int nlen
,
1539 void __user
*oldval
, size_t __user
*oldlenp
,
1540 void __user
*newval
, size_t newlen
,
1541 struct ctl_table
*table
)
1547 if (get_user(n
, name
))
1549 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1550 if (!table
->ctl_name
)
1552 if (n
== table
->ctl_name
) {
1555 if (sysctl_perm(table
, 001))
1559 table
= table
->child
;
1562 error
= do_sysctl_strategy(table
, name
, nlen
,
1571 /* Perform the actual read/write of a sysctl table entry. */
1572 int do_sysctl_strategy (struct ctl_table
*table
,
1573 int __user
*name
, int nlen
,
1574 void __user
*oldval
, size_t __user
*oldlenp
,
1575 void __user
*newval
, size_t newlen
)
1583 if (sysctl_perm(table
, op
))
1586 if (table
->strategy
) {
1587 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1595 /* If there is no strategy routine, or if the strategy returns
1596 * zero, proceed with automatic r/w */
1597 if (table
->data
&& table
->maxlen
) {
1598 rc
= sysctl_data(table
, name
, nlen
, oldval
, oldlenp
,
1605 #endif /* CONFIG_SYSCTL_SYSCALL */
1607 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1609 for (; table
->ctl_name
|| table
->procname
; table
++) {
1610 table
->parent
= parent
;
1612 sysctl_set_parent(table
, table
->child
);
1616 static __init
int sysctl_init(void)
1619 sysctl_set_parent(NULL
, root_table
);
1620 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1624 core_initcall(sysctl_init
);
1627 * __register_sysctl_paths - register a sysctl hierarchy
1628 * @root: List of sysctl headers to register on
1629 * @namespaces: Data to compute which lists of sysctl entries are visible
1630 * @path: The path to the directory the sysctl table is in.
1631 * @table: the top-level table structure
1633 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1634 * array. A completely 0 filled entry terminates the table.
1636 * The members of the &struct ctl_table structure are used as follows:
1638 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1639 * must be unique within that level of sysctl
1641 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1642 * enter a sysctl file
1644 * data - a pointer to data for use by proc_handler
1646 * maxlen - the maximum size in bytes of the data
1648 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1650 * child - a pointer to the child sysctl table if this entry is a directory, or
1653 * proc_handler - the text handler routine (described below)
1655 * strategy - the strategy routine (described below)
1657 * de - for internal use by the sysctl routines
1659 * extra1, extra2 - extra pointers usable by the proc handler routines
1661 * Leaf nodes in the sysctl tree will be represented by a single file
1662 * under /proc; non-leaf nodes will be represented by directories.
1664 * sysctl(2) can automatically manage read and write requests through
1665 * the sysctl table. The data and maxlen fields of the ctl_table
1666 * struct enable minimal validation of the values being written to be
1667 * performed, and the mode field allows minimal authentication.
1669 * More sophisticated management can be enabled by the provision of a
1670 * strategy routine with the table entry. This will be called before
1671 * any automatic read or write of the data is performed.
1673 * The strategy routine may return
1675 * < 0 - Error occurred (error is passed to user process)
1677 * 0 - OK - proceed with automatic read or write.
1679 * > 0 - OK - read or write has been done by the strategy routine, so
1680 * return immediately.
1682 * There must be a proc_handler routine for any terminal nodes
1683 * mirrored under /proc/sys (non-terminals are handled by a built-in
1684 * directory handler). Several default handlers are available to
1685 * cover common cases -
1687 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1688 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1689 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1691 * It is the handler's job to read the input buffer from user memory
1692 * and process it. The handler should return 0 on success.
1694 * This routine returns %NULL on a failure to register, and a pointer
1695 * to the table header on success.
1697 struct ctl_table_header
*__register_sysctl_paths(
1698 struct ctl_table_root
*root
,
1699 struct nsproxy
*namespaces
,
1700 const struct ctl_path
*path
, struct ctl_table
*table
)
1702 struct list_head
*header_list
;
1703 struct ctl_table_header
*header
;
1704 struct ctl_table
*new, **prevp
;
1705 unsigned int n
, npath
;
1707 /* Count the path components */
1708 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
1712 * For each path component, allocate a 2-element ctl_table array.
1713 * The first array element will be filled with the sysctl entry
1714 * for this, the second will be the sentinel (ctl_name == 0).
1716 * We allocate everything in one go so that we don't have to
1717 * worry about freeing additional memory in unregister_sysctl_table.
1719 header
= kzalloc(sizeof(struct ctl_table_header
) +
1720 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1724 new = (struct ctl_table
*) (header
+ 1);
1726 /* Now connect the dots */
1727 prevp
= &header
->ctl_table
;
1728 for (n
= 0; n
< npath
; ++n
, ++path
) {
1729 /* Copy the procname */
1730 new->procname
= path
->procname
;
1731 new->ctl_name
= path
->ctl_name
;
1735 prevp
= &new->child
;
1740 header
->ctl_table_arg
= table
;
1742 INIT_LIST_HEAD(&header
->ctl_entry
);
1744 header
->unregistering
= NULL
;
1745 header
->root
= root
;
1746 sysctl_set_parent(NULL
, header
->ctl_table
);
1747 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1751 spin_lock(&sysctl_lock
);
1752 header_list
= lookup_header_list(root
, namespaces
);
1753 list_add_tail(&header
->ctl_entry
, header_list
);
1754 spin_unlock(&sysctl_lock
);
1760 * register_sysctl_table_path - register a sysctl table hierarchy
1761 * @path: The path to the directory the sysctl table is in.
1762 * @table: the top-level table structure
1764 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1765 * array. A completely 0 filled entry terminates the table.
1767 * See __register_sysctl_paths for more details.
1769 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1770 struct ctl_table
*table
)
1772 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1777 * register_sysctl_table - register a sysctl table hierarchy
1778 * @table: the top-level table structure
1780 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1781 * array. A completely 0 filled entry terminates the table.
1783 * See register_sysctl_paths for more details.
1785 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1787 static const struct ctl_path null_path
[] = { {} };
1789 return register_sysctl_paths(null_path
, table
);
1793 * unregister_sysctl_table - unregister a sysctl table hierarchy
1794 * @header: the header returned from register_sysctl_table
1796 * Unregisters the sysctl table and all children. proc entries may not
1797 * actually be removed until they are no longer used by anyone.
1799 void unregister_sysctl_table(struct ctl_table_header
* header
)
1806 spin_lock(&sysctl_lock
);
1807 start_unregistering(header
);
1808 spin_unlock(&sysctl_lock
);
1812 #else /* !CONFIG_SYSCTL */
1813 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1818 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1819 struct ctl_table
*table
)
1824 void unregister_sysctl_table(struct ctl_table_header
* table
)
1828 #endif /* CONFIG_SYSCTL */
1834 #ifdef CONFIG_PROC_SYSCTL
1836 static int _proc_do_string(void* data
, int maxlen
, int write
,
1837 struct file
*filp
, void __user
*buffer
,
1838 size_t *lenp
, loff_t
*ppos
)
1844 if (!data
|| !maxlen
|| !*lenp
) {
1852 while (len
< *lenp
) {
1853 if (get_user(c
, p
++))
1855 if (c
== 0 || c
== '\n')
1861 if(copy_from_user(data
, buffer
, len
))
1863 ((char *) data
)[len
] = 0;
1881 if(copy_to_user(buffer
, data
, len
))
1884 if(put_user('\n', ((char __user
*) buffer
) + len
))
1895 * proc_dostring - read a string sysctl
1896 * @table: the sysctl table
1897 * @write: %TRUE if this is a write to the sysctl file
1898 * @filp: the file structure
1899 * @buffer: the user buffer
1900 * @lenp: the size of the user buffer
1901 * @ppos: file position
1903 * Reads/writes a string from/to the user buffer. If the kernel
1904 * buffer provided is not large enough to hold the string, the
1905 * string is truncated. The copied string is %NULL-terminated.
1906 * If the string is being read by the user process, it is copied
1907 * and a newline '\n' is added. It is truncated if the buffer is
1910 * Returns 0 on success.
1912 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
1913 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1915 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
1916 buffer
, lenp
, ppos
);
1920 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1922 int write
, void *data
)
1925 *valp
= *negp
? -*lvalp
: *lvalp
;
1930 *lvalp
= (unsigned long)-val
;
1933 *lvalp
= (unsigned long)val
;
1939 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1940 int write
, struct file
*filp
, void __user
*buffer
,
1941 size_t *lenp
, loff_t
*ppos
,
1942 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1943 int write
, void *data
),
1946 #define TMPBUFLEN 21
1947 int *i
, vleft
, first
=1, neg
, val
;
1951 char buf
[TMPBUFLEN
], *p
;
1952 char __user
*s
= buffer
;
1954 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
1955 (*ppos
&& !write
)) {
1960 i
= (int *) tbl_data
;
1961 vleft
= table
->maxlen
/ sizeof(*i
);
1965 conv
= do_proc_dointvec_conv
;
1967 for (; left
&& vleft
--; i
++, first
=0) {
1982 if (len
> sizeof(buf
) - 1)
1983 len
= sizeof(buf
) - 1;
1984 if (copy_from_user(buf
, s
, len
))
1988 if (*p
== '-' && left
> 1) {
1992 if (*p
< '0' || *p
> '9')
1995 lval
= simple_strtoul(p
, &p
, 0);
1998 if ((len
< left
) && *p
&& !isspace(*p
))
2005 if (conv(&neg
, &lval
, i
, 1, data
))
2012 if (conv(&neg
, &lval
, i
, 0, data
))
2015 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2019 if(copy_to_user(s
, buf
, len
))
2026 if (!write
&& !first
&& left
) {
2027 if(put_user('\n', s
))
2034 if (get_user(c
, s
++))
2049 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2050 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2051 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2052 int write
, void *data
),
2055 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2056 buffer
, lenp
, ppos
, conv
, data
);
2060 * proc_dointvec - read a vector of integers
2061 * @table: the sysctl table
2062 * @write: %TRUE if this is a write to the sysctl file
2063 * @filp: the file structure
2064 * @buffer: the user buffer
2065 * @lenp: the size of the user buffer
2066 * @ppos: file position
2068 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2069 * values from/to the user buffer, treated as an ASCII string.
2071 * Returns 0 on success.
2073 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2074 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2076 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2084 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
2086 int write
, void *data
)
2088 int op
= *(int *)data
;
2090 int val
= *negp
? -*lvalp
: *lvalp
;
2092 case OP_SET
: *valp
= val
; break;
2093 case OP_AND
: *valp
&= val
; break;
2094 case OP_OR
: *valp
|= val
; break;
2100 *lvalp
= (unsigned long)-val
;
2103 *lvalp
= (unsigned long)val
;
2110 * Taint values can only be increased
2112 static int proc_dointvec_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2113 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2117 if (write
&& !capable(CAP_SYS_ADMIN
))
2121 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2122 do_proc_dointvec_bset_conv
,&op
);
2125 struct do_proc_dointvec_minmax_conv_param
{
2130 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2132 int write
, void *data
)
2134 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2136 int val
= *negp
? -*lvalp
: *lvalp
;
2137 if ((param
->min
&& *param
->min
> val
) ||
2138 (param
->max
&& *param
->max
< val
))
2145 *lvalp
= (unsigned long)-val
;
2148 *lvalp
= (unsigned long)val
;
2155 * proc_dointvec_minmax - read a vector of integers with min/max values
2156 * @table: the sysctl table
2157 * @write: %TRUE if this is a write to the sysctl file
2158 * @filp: the file structure
2159 * @buffer: the user buffer
2160 * @lenp: the size of the user buffer
2161 * @ppos: file position
2163 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2164 * values from/to the user buffer, treated as an ASCII string.
2166 * This routine will ensure the values are within the range specified by
2167 * table->extra1 (min) and table->extra2 (max).
2169 * Returns 0 on success.
2171 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2172 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2174 struct do_proc_dointvec_minmax_conv_param param
= {
2175 .min
= (int *) table
->extra1
,
2176 .max
= (int *) table
->extra2
,
2178 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2179 do_proc_dointvec_minmax_conv
, ¶m
);
2182 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2184 void __user
*buffer
,
2185 size_t *lenp
, loff_t
*ppos
,
2186 unsigned long convmul
,
2187 unsigned long convdiv
)
2189 #define TMPBUFLEN 21
2190 unsigned long *i
, *min
, *max
, val
;
2191 int vleft
, first
=1, neg
;
2193 char buf
[TMPBUFLEN
], *p
;
2194 char __user
*s
= buffer
;
2196 if (!data
|| !table
->maxlen
|| !*lenp
||
2197 (*ppos
&& !write
)) {
2202 i
= (unsigned long *) data
;
2203 min
= (unsigned long *) table
->extra1
;
2204 max
= (unsigned long *) table
->extra2
;
2205 vleft
= table
->maxlen
/ sizeof(unsigned long);
2208 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2223 if (len
> TMPBUFLEN
-1)
2225 if (copy_from_user(buf
, s
, len
))
2229 if (*p
== '-' && left
> 1) {
2233 if (*p
< '0' || *p
> '9')
2235 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2237 if ((len
< left
) && *p
&& !isspace(*p
))
2246 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2253 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2257 if(copy_to_user(s
, buf
, len
))
2264 if (!write
&& !first
&& left
) {
2265 if(put_user('\n', s
))
2272 if (get_user(c
, s
++))
2287 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2289 void __user
*buffer
,
2290 size_t *lenp
, loff_t
*ppos
,
2291 unsigned long convmul
,
2292 unsigned long convdiv
)
2294 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2295 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2299 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2300 * @table: the sysctl table
2301 * @write: %TRUE if this is a write to the sysctl file
2302 * @filp: the file structure
2303 * @buffer: the user buffer
2304 * @lenp: the size of the user buffer
2305 * @ppos: file position
2307 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2308 * values from/to the user buffer, treated as an ASCII string.
2310 * This routine will ensure the values are within the range specified by
2311 * table->extra1 (min) and table->extra2 (max).
2313 * Returns 0 on success.
2315 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2316 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2318 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2322 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2323 * @table: the sysctl table
2324 * @write: %TRUE if this is a write to the sysctl file
2325 * @filp: the file structure
2326 * @buffer: the user buffer
2327 * @lenp: the size of the user buffer
2328 * @ppos: file position
2330 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2331 * values from/to the user buffer, treated as an ASCII string. The values
2332 * are treated as milliseconds, and converted to jiffies when they are stored.
2334 * This routine will ensure the values are within the range specified by
2335 * table->extra1 (min) and table->extra2 (max).
2337 * Returns 0 on success.
2339 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2341 void __user
*buffer
,
2342 size_t *lenp
, loff_t
*ppos
)
2344 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2345 lenp
, ppos
, HZ
, 1000l);
2349 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2351 int write
, void *data
)
2354 if (*lvalp
> LONG_MAX
/ HZ
)
2356 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2362 lval
= (unsigned long)-val
;
2365 lval
= (unsigned long)val
;
2372 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2374 int write
, void *data
)
2377 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2379 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2385 lval
= (unsigned long)-val
;
2388 lval
= (unsigned long)val
;
2390 *lvalp
= jiffies_to_clock_t(lval
);
2395 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2397 int write
, void *data
)
2400 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2406 lval
= (unsigned long)-val
;
2409 lval
= (unsigned long)val
;
2411 *lvalp
= jiffies_to_msecs(lval
);
2417 * proc_dointvec_jiffies - read a vector of integers as seconds
2418 * @table: the sysctl table
2419 * @write: %TRUE if this is a write to the sysctl file
2420 * @filp: the file structure
2421 * @buffer: the user buffer
2422 * @lenp: the size of the user buffer
2423 * @ppos: file position
2425 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2426 * values from/to the user buffer, treated as an ASCII string.
2427 * The values read are assumed to be in seconds, and are converted into
2430 * Returns 0 on success.
2432 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2433 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2435 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2436 do_proc_dointvec_jiffies_conv
,NULL
);
2440 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2441 * @table: the sysctl table
2442 * @write: %TRUE if this is a write to the sysctl file
2443 * @filp: the file structure
2444 * @buffer: the user buffer
2445 * @lenp: the size of the user buffer
2446 * @ppos: pointer to the file position
2448 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2449 * values from/to the user buffer, treated as an ASCII string.
2450 * The values read are assumed to be in 1/USER_HZ seconds, and
2451 * are converted into jiffies.
2453 * Returns 0 on success.
2455 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2456 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2458 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2459 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2463 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2464 * @table: the sysctl table
2465 * @write: %TRUE if this is a write to the sysctl file
2466 * @filp: the file structure
2467 * @buffer: the user buffer
2468 * @lenp: the size of the user buffer
2469 * @ppos: file position
2470 * @ppos: the current position in the file
2472 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2473 * values from/to the user buffer, treated as an ASCII string.
2474 * The values read are assumed to be in 1/1000 seconds, and
2475 * are converted into jiffies.
2477 * Returns 0 on success.
2479 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2480 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2482 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2483 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2486 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2487 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2489 struct pid
*new_pid
;
2493 tmp
= pid_vnr(cad_pid
);
2495 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2496 lenp
, ppos
, NULL
, NULL
);
2500 new_pid
= find_get_pid(tmp
);
2504 put_pid(xchg(&cad_pid
, new_pid
));
2508 #else /* CONFIG_PROC_FS */
2510 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2511 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2516 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2517 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2522 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2523 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2528 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2529 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2534 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2535 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2540 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2541 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2546 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2547 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2552 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2554 void __user
*buffer
,
2555 size_t *lenp
, loff_t
*ppos
)
2561 #endif /* CONFIG_PROC_FS */
2564 #ifdef CONFIG_SYSCTL_SYSCALL
2566 * General sysctl support routines
2569 /* The generic sysctl data routine (used if no strategy routine supplied) */
2570 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2571 void __user
*oldval
, size_t __user
*oldlenp
,
2572 void __user
*newval
, size_t newlen
)
2576 /* Get out of I don't have a variable */
2577 if (!table
->data
|| !table
->maxlen
)
2580 if (oldval
&& oldlenp
) {
2581 if (get_user(len
, oldlenp
))
2584 if (len
> table
->maxlen
)
2585 len
= table
->maxlen
;
2586 if (copy_to_user(oldval
, table
->data
, len
))
2588 if (put_user(len
, oldlenp
))
2593 if (newval
&& newlen
) {
2594 if (newlen
> table
->maxlen
)
2595 newlen
= table
->maxlen
;
2597 if (copy_from_user(table
->data
, newval
, newlen
))
2603 /* The generic string strategy routine: */
2604 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2605 void __user
*oldval
, size_t __user
*oldlenp
,
2606 void __user
*newval
, size_t newlen
)
2608 if (!table
->data
|| !table
->maxlen
)
2611 if (oldval
&& oldlenp
) {
2613 if (get_user(bufsize
, oldlenp
))
2616 size_t len
= strlen(table
->data
), copied
;
2618 /* This shouldn't trigger for a well-formed sysctl */
2619 if (len
> table
->maxlen
)
2620 len
= table
->maxlen
;
2622 /* Copy up to a max of bufsize-1 bytes of the string */
2623 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2625 if (copy_to_user(oldval
, table
->data
, copied
) ||
2626 put_user(0, (char __user
*)(oldval
+ copied
)))
2628 if (put_user(len
, oldlenp
))
2632 if (newval
&& newlen
) {
2633 size_t len
= newlen
;
2634 if (len
> table
->maxlen
)
2635 len
= table
->maxlen
;
2636 if(copy_from_user(table
->data
, newval
, len
))
2638 if (len
== table
->maxlen
)
2640 ((char *) table
->data
)[len
] = 0;
2646 * This function makes sure that all of the integers in the vector
2647 * are between the minimum and maximum values given in the arrays
2648 * table->extra1 and table->extra2, respectively.
2650 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2651 void __user
*oldval
, size_t __user
*oldlenp
,
2652 void __user
*newval
, size_t newlen
)
2655 if (newval
&& newlen
) {
2656 int __user
*vec
= (int __user
*) newval
;
2657 int *min
= (int *) table
->extra1
;
2658 int *max
= (int *) table
->extra2
;
2662 if (newlen
% sizeof(int) != 0)
2665 if (!table
->extra1
&& !table
->extra2
)
2668 if (newlen
> table
->maxlen
)
2669 newlen
= table
->maxlen
;
2670 length
= newlen
/ sizeof(int);
2672 for (i
= 0; i
< length
; i
++) {
2674 if (get_user(value
, vec
+ i
))
2676 if (min
&& value
< min
[i
])
2678 if (max
&& value
> max
[i
])
2685 /* Strategy function to convert jiffies to seconds */
2686 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2687 void __user
*oldval
, size_t __user
*oldlenp
,
2688 void __user
*newval
, size_t newlen
)
2690 if (oldval
&& oldlenp
) {
2693 if (get_user(olen
, oldlenp
))
2698 if (olen
< sizeof(int))
2701 val
= *(int *)(table
->data
) / HZ
;
2702 if (put_user(val
, (int __user
*)oldval
))
2704 if (put_user(sizeof(int), oldlenp
))
2708 if (newval
&& newlen
) {
2710 if (newlen
!= sizeof(int))
2712 if (get_user(new, (int __user
*)newval
))
2714 *(int *)(table
->data
) = new*HZ
;
2719 /* Strategy function to convert jiffies to seconds */
2720 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2721 void __user
*oldval
, size_t __user
*oldlenp
,
2722 void __user
*newval
, size_t newlen
)
2724 if (oldval
&& oldlenp
) {
2727 if (get_user(olen
, oldlenp
))
2732 if (olen
< sizeof(int))
2735 val
= jiffies_to_msecs(*(int *)(table
->data
));
2736 if (put_user(val
, (int __user
*)oldval
))
2738 if (put_user(sizeof(int), oldlenp
))
2742 if (newval
&& newlen
) {
2744 if (newlen
!= sizeof(int))
2746 if (get_user(new, (int __user
*)newval
))
2748 *(int *)(table
->data
) = msecs_to_jiffies(new);
2755 #else /* CONFIG_SYSCTL_SYSCALL */
2758 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2760 struct __sysctl_args tmp
;
2763 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
2766 error
= deprecated_sysctl_warning(&tmp
);
2768 /* If no error reading the parameters then just -ENOSYS ... */
2775 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2776 void __user
*oldval
, size_t __user
*oldlenp
,
2777 void __user
*newval
, size_t newlen
)
2782 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2783 void __user
*oldval
, size_t __user
*oldlenp
,
2784 void __user
*newval
, size_t newlen
)
2789 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2790 void __user
*oldval
, size_t __user
*oldlenp
,
2791 void __user
*newval
, size_t newlen
)
2796 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2797 void __user
*oldval
, size_t __user
*oldlenp
,
2798 void __user
*newval
, size_t newlen
)
2803 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2804 void __user
*oldval
, size_t __user
*oldlenp
,
2805 void __user
*newval
, size_t newlen
)
2810 #endif /* CONFIG_SYSCTL_SYSCALL */
2812 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
2814 static int msg_count
;
2815 int name
[CTL_MAXNAME
];
2818 /* Check args->nlen. */
2819 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
2822 /* Read in the sysctl name for better debug message logging */
2823 for (i
= 0; i
< args
->nlen
; i
++)
2824 if (get_user(name
[i
], args
->name
+ i
))
2827 /* Ignore accesses to kernel.version */
2828 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
2831 if (msg_count
< 5) {
2834 "warning: process `%s' used the deprecated sysctl "
2835 "system call with ", current
->comm
);
2836 for (i
= 0; i
< args
->nlen
; i
++)
2837 printk("%d.", name
[i
]);
2844 * No sense putting this after each symbol definition, twice,
2845 * exception granted :-)
2847 EXPORT_SYMBOL(proc_dointvec
);
2848 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2849 EXPORT_SYMBOL(proc_dointvec_minmax
);
2850 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2851 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2852 EXPORT_SYMBOL(proc_dostring
);
2853 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2854 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2855 EXPORT_SYMBOL(register_sysctl_table
);
2856 EXPORT_SYMBOL(register_sysctl_paths
);
2857 EXPORT_SYMBOL(sysctl_intvec
);
2858 EXPORT_SYMBOL(sysctl_jiffies
);
2859 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2860 EXPORT_SYMBOL(sysctl_string
);
2861 EXPORT_SYMBOL(sysctl_data
);
2862 EXPORT_SYMBOL(unregister_sysctl_table
);