2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/proc_fs.h>
27 #include <linux/security.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/hugetlb.h>
40 #include <linux/security.h>
41 #include <linux/initrd.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/nfs_fs.h>
47 #include <linux/acpi.h>
48 #include <linux/reboot.h>
50 #include <asm/uaccess.h>
51 #include <asm/processor.h>
55 #include <asm/stacktrace.h>
59 static int deprecated_sysctl_warning(struct __sysctl_args
*args
);
61 #if defined(CONFIG_SYSCTL)
63 /* External variables not in a header file. */
65 extern int print_fatal_signals
;
66 extern int sysctl_overcommit_memory
;
67 extern int sysctl_overcommit_ratio
;
68 extern int sysctl_panic_on_oom
;
69 extern int sysctl_oom_kill_allocating_task
;
70 extern int max_threads
;
71 extern int core_uses_pid
;
72 extern int suid_dumpable
;
73 extern char core_pattern
[];
75 extern int min_free_kbytes
;
76 extern int printk_ratelimit_jiffies
;
77 extern int printk_ratelimit_burst
;
78 extern int pid_max_min
, pid_max_max
;
79 extern int sysctl_drop_caches
;
80 extern int percpu_pagelist_fraction
;
81 extern int compat_log
;
82 extern int maps_protect
;
83 extern int sysctl_stat_interval
;
84 extern int latencytop_enabled
;
86 /* Constants used for minimum and maximum */
87 #if defined(CONFIG_DETECT_SOFTLOCKUP) || defined(CONFIG_HIGHMEM)
91 #ifdef CONFIG_DETECT_SOFTLOCKUP
92 static int sixty
= 60;
100 static int one_hundred
= 100;
102 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
103 static int maxolduid
= 65535;
104 static int minolduid
;
105 static int min_percpu_pagelist_fract
= 8;
107 static int ngroups_max
= NGROUPS_MAX
;
110 extern char modprobe_path
[];
112 #ifdef CONFIG_CHR_DEV_SG
113 extern int sg_big_buff
;
117 extern char reboot_command
[];
118 extern int stop_a_enabled
;
119 extern int scons_pwroff
;
123 extern int pwrsw_enabled
;
124 extern int unaligned_enabled
;
128 #ifdef CONFIG_MATHEMU
129 extern int sysctl_ieee_emulation_warnings
;
131 extern int sysctl_userprocess_debug
;
132 extern int spin_retry
;
135 extern int sysctl_hz_timer
;
137 #ifdef CONFIG_BSD_PROCESS_ACCT
138 extern int acct_parm
[];
142 extern int no_unaligned_warning
;
145 #ifdef CONFIG_RT_MUTEXES
146 extern int max_lock_depth
;
149 #ifdef CONFIG_SYSCTL_SYSCALL
150 static int parse_table(int __user
*, int, void __user
*, size_t __user
*,
151 void __user
*, size_t, struct ctl_table
*);
155 #ifdef CONFIG_PROC_SYSCTL
156 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
157 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
158 static int proc_dointvec_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
159 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
162 static struct ctl_table root_table
[];
163 static struct ctl_table_root sysctl_table_root
;
164 static struct ctl_table_header root_table_header
= {
165 .ctl_table
= root_table
,
166 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.header_list
),
167 .root
= &sysctl_table_root
,
169 static struct ctl_table_root sysctl_table_root
= {
170 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
171 .header_list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
174 static struct ctl_table kern_table
[];
175 static struct ctl_table vm_table
[];
176 static struct ctl_table fs_table
[];
177 static struct ctl_table debug_table
[];
178 static struct ctl_table dev_table
[];
179 extern struct ctl_table random_table
[];
180 #ifdef CONFIG_INOTIFY_USER
181 extern struct ctl_table inotify_table
[];
184 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
185 int sysctl_legacy_va_layout
;
188 extern int prove_locking
;
189 extern int lock_stat
;
191 /* The default sysctl tables: */
193 static struct ctl_table root_table
[] = {
195 .ctl_name
= CTL_KERN
,
196 .procname
= "kernel",
213 .ctl_name
= CTL_DEBUG
,
216 .child
= debug_table
,
225 * NOTE: do not add new entries to this table unless you have read
226 * Documentation/sysctl/ctl_unnumbered.txt
231 #ifdef CONFIG_SCHED_DEBUG
232 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
233 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
234 static int min_wakeup_granularity_ns
; /* 0 usecs */
235 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
238 static struct ctl_table kern_table
[] = {
239 #ifdef CONFIG_SCHED_DEBUG
241 .ctl_name
= CTL_UNNUMBERED
,
242 .procname
= "sched_min_granularity_ns",
243 .data
= &sysctl_sched_min_granularity
,
244 .maxlen
= sizeof(unsigned int),
246 .proc_handler
= &sched_nr_latency_handler
,
247 .strategy
= &sysctl_intvec
,
248 .extra1
= &min_sched_granularity_ns
,
249 .extra2
= &max_sched_granularity_ns
,
252 .ctl_name
= CTL_UNNUMBERED
,
253 .procname
= "sched_latency_ns",
254 .data
= &sysctl_sched_latency
,
255 .maxlen
= sizeof(unsigned int),
257 .proc_handler
= &sched_nr_latency_handler
,
258 .strategy
= &sysctl_intvec
,
259 .extra1
= &min_sched_granularity_ns
,
260 .extra2
= &max_sched_granularity_ns
,
263 .ctl_name
= CTL_UNNUMBERED
,
264 .procname
= "sched_wakeup_granularity_ns",
265 .data
= &sysctl_sched_wakeup_granularity
,
266 .maxlen
= sizeof(unsigned int),
268 .proc_handler
= &proc_dointvec_minmax
,
269 .strategy
= &sysctl_intvec
,
270 .extra1
= &min_wakeup_granularity_ns
,
271 .extra2
= &max_wakeup_granularity_ns
,
274 .ctl_name
= CTL_UNNUMBERED
,
275 .procname
= "sched_batch_wakeup_granularity_ns",
276 .data
= &sysctl_sched_batch_wakeup_granularity
,
277 .maxlen
= sizeof(unsigned int),
279 .proc_handler
= &proc_dointvec_minmax
,
280 .strategy
= &sysctl_intvec
,
281 .extra1
= &min_wakeup_granularity_ns
,
282 .extra2
= &max_wakeup_granularity_ns
,
285 .ctl_name
= CTL_UNNUMBERED
,
286 .procname
= "sched_child_runs_first",
287 .data
= &sysctl_sched_child_runs_first
,
288 .maxlen
= sizeof(unsigned int),
290 .proc_handler
= &proc_dointvec
,
293 .ctl_name
= CTL_UNNUMBERED
,
294 .procname
= "sched_features",
295 .data
= &sysctl_sched_features
,
296 .maxlen
= sizeof(unsigned int),
298 .proc_handler
= &proc_dointvec
,
301 .ctl_name
= CTL_UNNUMBERED
,
302 .procname
= "sched_migration_cost",
303 .data
= &sysctl_sched_migration_cost
,
304 .maxlen
= sizeof(unsigned int),
306 .proc_handler
= &proc_dointvec
,
309 .ctl_name
= CTL_UNNUMBERED
,
310 .procname
= "sched_nr_migrate",
311 .data
= &sysctl_sched_nr_migrate
,
312 .maxlen
= sizeof(unsigned int),
314 .proc_handler
= &proc_dointvec
,
317 .ctl_name
= CTL_UNNUMBERED
,
318 .procname
= "sched_rt_period_ms",
319 .data
= &sysctl_sched_rt_period
,
320 .maxlen
= sizeof(unsigned int),
322 .proc_handler
= &proc_dointvec
,
325 .ctl_name
= CTL_UNNUMBERED
,
326 .procname
= "sched_rt_ratio",
327 .data
= &sysctl_sched_rt_ratio
,
328 .maxlen
= sizeof(unsigned int),
330 .proc_handler
= &proc_dointvec
,
332 #if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_SMP)
334 .ctl_name
= CTL_UNNUMBERED
,
335 .procname
= "sched_min_bal_int_shares",
336 .data
= &sysctl_sched_min_bal_int_shares
,
337 .maxlen
= sizeof(unsigned int),
339 .proc_handler
= &proc_dointvec
,
342 .ctl_name
= CTL_UNNUMBERED
,
343 .procname
= "sched_max_bal_int_shares",
344 .data
= &sysctl_sched_max_bal_int_shares
,
345 .maxlen
= sizeof(unsigned int),
347 .proc_handler
= &proc_dointvec
,
352 .ctl_name
= CTL_UNNUMBERED
,
353 .procname
= "sched_compat_yield",
354 .data
= &sysctl_sched_compat_yield
,
355 .maxlen
= sizeof(unsigned int),
357 .proc_handler
= &proc_dointvec
,
359 #ifdef CONFIG_PROVE_LOCKING
361 .ctl_name
= CTL_UNNUMBERED
,
362 .procname
= "prove_locking",
363 .data
= &prove_locking
,
364 .maxlen
= sizeof(int),
366 .proc_handler
= &proc_dointvec
,
369 #ifdef CONFIG_LOCK_STAT
371 .ctl_name
= CTL_UNNUMBERED
,
372 .procname
= "lock_stat",
374 .maxlen
= sizeof(int),
376 .proc_handler
= &proc_dointvec
,
380 .ctl_name
= KERN_PANIC
,
382 .data
= &panic_timeout
,
383 .maxlen
= sizeof(int),
385 .proc_handler
= &proc_dointvec
,
388 .ctl_name
= KERN_CORE_USES_PID
,
389 .procname
= "core_uses_pid",
390 .data
= &core_uses_pid
,
391 .maxlen
= sizeof(int),
393 .proc_handler
= &proc_dointvec
,
396 .ctl_name
= KERN_CORE_PATTERN
,
397 .procname
= "core_pattern",
398 .data
= core_pattern
,
399 .maxlen
= CORENAME_MAX_SIZE
,
401 .proc_handler
= &proc_dostring
,
402 .strategy
= &sysctl_string
,
404 #ifdef CONFIG_PROC_SYSCTL
406 .procname
= "tainted",
408 .maxlen
= sizeof(int),
410 .proc_handler
= &proc_dointvec_taint
,
413 #ifdef CONFIG_LATENCYTOP
415 .procname
= "latencytop",
416 .data
= &latencytop_enabled
,
417 .maxlen
= sizeof(int),
419 .proc_handler
= &proc_dointvec
,
422 #ifdef CONFIG_SECURITY_CAPABILITIES
424 .procname
= "cap-bound",
426 .maxlen
= sizeof(kernel_cap_t
),
428 .proc_handler
= &proc_dointvec_bset
,
430 #endif /* def CONFIG_SECURITY_CAPABILITIES */
431 #ifdef CONFIG_BLK_DEV_INITRD
433 .ctl_name
= KERN_REALROOTDEV
,
434 .procname
= "real-root-dev",
435 .data
= &real_root_dev
,
436 .maxlen
= sizeof(int),
438 .proc_handler
= &proc_dointvec
,
442 .ctl_name
= CTL_UNNUMBERED
,
443 .procname
= "print-fatal-signals",
444 .data
= &print_fatal_signals
,
445 .maxlen
= sizeof(int),
447 .proc_handler
= &proc_dointvec
,
451 .ctl_name
= KERN_SPARC_REBOOT
,
452 .procname
= "reboot-cmd",
453 .data
= reboot_command
,
456 .proc_handler
= &proc_dostring
,
457 .strategy
= &sysctl_string
,
460 .ctl_name
= KERN_SPARC_STOP_A
,
461 .procname
= "stop-a",
462 .data
= &stop_a_enabled
,
463 .maxlen
= sizeof (int),
465 .proc_handler
= &proc_dointvec
,
468 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
469 .procname
= "scons-poweroff",
470 .data
= &scons_pwroff
,
471 .maxlen
= sizeof (int),
473 .proc_handler
= &proc_dointvec
,
478 .ctl_name
= KERN_HPPA_PWRSW
,
479 .procname
= "soft-power",
480 .data
= &pwrsw_enabled
,
481 .maxlen
= sizeof (int),
483 .proc_handler
= &proc_dointvec
,
486 .ctl_name
= KERN_HPPA_UNALIGNED
,
487 .procname
= "unaligned-trap",
488 .data
= &unaligned_enabled
,
489 .maxlen
= sizeof (int),
491 .proc_handler
= &proc_dointvec
,
495 .ctl_name
= KERN_CTLALTDEL
,
496 .procname
= "ctrl-alt-del",
498 .maxlen
= sizeof(int),
500 .proc_handler
= &proc_dointvec
,
503 .ctl_name
= KERN_PRINTK
,
504 .procname
= "printk",
505 .data
= &console_loglevel
,
506 .maxlen
= 4*sizeof(int),
508 .proc_handler
= &proc_dointvec
,
512 .ctl_name
= KERN_MODPROBE
,
513 .procname
= "modprobe",
514 .data
= &modprobe_path
,
515 .maxlen
= KMOD_PATH_LEN
,
517 .proc_handler
= &proc_dostring
,
518 .strategy
= &sysctl_string
,
521 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
523 .ctl_name
= KERN_HOTPLUG
,
524 .procname
= "hotplug",
525 .data
= &uevent_helper
,
526 .maxlen
= UEVENT_HELPER_PATH_LEN
,
528 .proc_handler
= &proc_dostring
,
529 .strategy
= &sysctl_string
,
532 #ifdef CONFIG_CHR_DEV_SG
534 .ctl_name
= KERN_SG_BIG_BUFF
,
535 .procname
= "sg-big-buff",
536 .data
= &sg_big_buff
,
537 .maxlen
= sizeof (int),
539 .proc_handler
= &proc_dointvec
,
542 #ifdef CONFIG_BSD_PROCESS_ACCT
544 .ctl_name
= KERN_ACCT
,
547 .maxlen
= 3*sizeof(int),
549 .proc_handler
= &proc_dointvec
,
552 #ifdef CONFIG_MAGIC_SYSRQ
554 .ctl_name
= KERN_SYSRQ
,
556 .data
= &__sysrq_enabled
,
557 .maxlen
= sizeof (int),
559 .proc_handler
= &proc_dointvec
,
562 #ifdef CONFIG_PROC_SYSCTL
564 .procname
= "cad_pid",
566 .maxlen
= sizeof (int),
568 .proc_handler
= &proc_do_cad_pid
,
572 .ctl_name
= KERN_MAX_THREADS
,
573 .procname
= "threads-max",
574 .data
= &max_threads
,
575 .maxlen
= sizeof(int),
577 .proc_handler
= &proc_dointvec
,
580 .ctl_name
= KERN_RANDOM
,
581 .procname
= "random",
583 .child
= random_table
,
586 .ctl_name
= KERN_OVERFLOWUID
,
587 .procname
= "overflowuid",
588 .data
= &overflowuid
,
589 .maxlen
= sizeof(int),
591 .proc_handler
= &proc_dointvec_minmax
,
592 .strategy
= &sysctl_intvec
,
593 .extra1
= &minolduid
,
594 .extra2
= &maxolduid
,
597 .ctl_name
= KERN_OVERFLOWGID
,
598 .procname
= "overflowgid",
599 .data
= &overflowgid
,
600 .maxlen
= sizeof(int),
602 .proc_handler
= &proc_dointvec_minmax
,
603 .strategy
= &sysctl_intvec
,
604 .extra1
= &minolduid
,
605 .extra2
= &maxolduid
,
608 #ifdef CONFIG_MATHEMU
610 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
611 .procname
= "ieee_emulation_warnings",
612 .data
= &sysctl_ieee_emulation_warnings
,
613 .maxlen
= sizeof(int),
615 .proc_handler
= &proc_dointvec
,
618 #ifdef CONFIG_NO_IDLE_HZ
620 .ctl_name
= KERN_HZ_TIMER
,
621 .procname
= "hz_timer",
622 .data
= &sysctl_hz_timer
,
623 .maxlen
= sizeof(int),
625 .proc_handler
= &proc_dointvec
,
629 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
630 .procname
= "userprocess_debug",
631 .data
= &sysctl_userprocess_debug
,
632 .maxlen
= sizeof(int),
634 .proc_handler
= &proc_dointvec
,
638 .ctl_name
= KERN_PIDMAX
,
639 .procname
= "pid_max",
641 .maxlen
= sizeof (int),
643 .proc_handler
= &proc_dointvec_minmax
,
644 .strategy
= sysctl_intvec
,
645 .extra1
= &pid_max_min
,
646 .extra2
= &pid_max_max
,
649 .ctl_name
= KERN_PANIC_ON_OOPS
,
650 .procname
= "panic_on_oops",
651 .data
= &panic_on_oops
,
652 .maxlen
= sizeof(int),
654 .proc_handler
= &proc_dointvec
,
657 .ctl_name
= KERN_PRINTK_RATELIMIT
,
658 .procname
= "printk_ratelimit",
659 .data
= &printk_ratelimit_jiffies
,
660 .maxlen
= sizeof(int),
662 .proc_handler
= &proc_dointvec_jiffies
,
663 .strategy
= &sysctl_jiffies
,
666 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
667 .procname
= "printk_ratelimit_burst",
668 .data
= &printk_ratelimit_burst
,
669 .maxlen
= sizeof(int),
671 .proc_handler
= &proc_dointvec
,
674 .ctl_name
= KERN_NGROUPS_MAX
,
675 .procname
= "ngroups_max",
676 .data
= &ngroups_max
,
677 .maxlen
= sizeof (int),
679 .proc_handler
= &proc_dointvec
,
681 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
683 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
684 .procname
= "unknown_nmi_panic",
685 .data
= &unknown_nmi_panic
,
686 .maxlen
= sizeof (int),
688 .proc_handler
= &proc_dointvec
,
691 .procname
= "nmi_watchdog",
692 .data
= &nmi_watchdog_enabled
,
693 .maxlen
= sizeof (int),
695 .proc_handler
= &proc_nmi_enabled
,
698 #if defined(CONFIG_X86)
700 .ctl_name
= KERN_PANIC_ON_NMI
,
701 .procname
= "panic_on_unrecovered_nmi",
702 .data
= &panic_on_unrecovered_nmi
,
703 .maxlen
= sizeof(int),
705 .proc_handler
= &proc_dointvec
,
708 .ctl_name
= KERN_BOOTLOADER_TYPE
,
709 .procname
= "bootloader_type",
710 .data
= &bootloader_type
,
711 .maxlen
= sizeof (int),
713 .proc_handler
= &proc_dointvec
,
716 .ctl_name
= CTL_UNNUMBERED
,
717 .procname
= "kstack_depth_to_print",
718 .data
= &kstack_depth_to_print
,
719 .maxlen
= sizeof(int),
721 .proc_handler
= &proc_dointvec
,
724 .ctl_name
= CTL_UNNUMBERED
,
725 .procname
= "io_delay_type",
726 .data
= &io_delay_type
,
727 .maxlen
= sizeof(int),
729 .proc_handler
= &proc_dointvec
,
732 #if defined(CONFIG_MMU)
734 .ctl_name
= KERN_RANDOMIZE
,
735 .procname
= "randomize_va_space",
736 .data
= &randomize_va_space
,
737 .maxlen
= sizeof(int),
739 .proc_handler
= &proc_dointvec
,
742 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
744 .ctl_name
= KERN_SPIN_RETRY
,
745 .procname
= "spin_retry",
747 .maxlen
= sizeof (int),
749 .proc_handler
= &proc_dointvec
,
752 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
754 .procname
= "acpi_video_flags",
755 .data
= &acpi_realmode_flags
,
756 .maxlen
= sizeof (unsigned long),
758 .proc_handler
= &proc_doulongvec_minmax
,
763 .ctl_name
= KERN_IA64_UNALIGNED
,
764 .procname
= "ignore-unaligned-usertrap",
765 .data
= &no_unaligned_warning
,
766 .maxlen
= sizeof (int),
768 .proc_handler
= &proc_dointvec
,
771 #ifdef CONFIG_DETECT_SOFTLOCKUP
773 .ctl_name
= CTL_UNNUMBERED
,
774 .procname
= "softlockup_thresh",
775 .data
= &softlockup_thresh
,
776 .maxlen
= sizeof(unsigned long),
778 .proc_handler
= &proc_doulongvec_minmax
,
779 .strategy
= &sysctl_intvec
,
784 .ctl_name
= CTL_UNNUMBERED
,
785 .procname
= "hung_task_check_count",
786 .data
= &sysctl_hung_task_check_count
,
787 .maxlen
= sizeof(unsigned long),
789 .proc_handler
= &proc_doulongvec_minmax
,
790 .strategy
= &sysctl_intvec
,
793 .ctl_name
= CTL_UNNUMBERED
,
794 .procname
= "hung_task_timeout_secs",
795 .data
= &sysctl_hung_task_timeout_secs
,
796 .maxlen
= sizeof(unsigned long),
798 .proc_handler
= &proc_doulongvec_minmax
,
799 .strategy
= &sysctl_intvec
,
802 .ctl_name
= CTL_UNNUMBERED
,
803 .procname
= "hung_task_warnings",
804 .data
= &sysctl_hung_task_warnings
,
805 .maxlen
= sizeof(unsigned long),
807 .proc_handler
= &proc_doulongvec_minmax
,
808 .strategy
= &sysctl_intvec
,
813 .ctl_name
= KERN_COMPAT_LOG
,
814 .procname
= "compat-log",
816 .maxlen
= sizeof (int),
818 .proc_handler
= &proc_dointvec
,
821 #ifdef CONFIG_RT_MUTEXES
823 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
824 .procname
= "max_lock_depth",
825 .data
= &max_lock_depth
,
826 .maxlen
= sizeof(int),
828 .proc_handler
= &proc_dointvec
,
831 #ifdef CONFIG_PROC_FS
833 .ctl_name
= CTL_UNNUMBERED
,
834 .procname
= "maps_protect",
835 .data
= &maps_protect
,
836 .maxlen
= sizeof(int),
838 .proc_handler
= &proc_dointvec
,
842 .ctl_name
= CTL_UNNUMBERED
,
843 .procname
= "poweroff_cmd",
844 .data
= &poweroff_cmd
,
845 .maxlen
= POWEROFF_CMD_PATH_LEN
,
847 .proc_handler
= &proc_dostring
,
848 .strategy
= &sysctl_string
,
851 * NOTE: do not add new entries to this table unless you have read
852 * Documentation/sysctl/ctl_unnumbered.txt
857 static struct ctl_table vm_table
[] = {
859 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
860 .procname
= "overcommit_memory",
861 .data
= &sysctl_overcommit_memory
,
862 .maxlen
= sizeof(sysctl_overcommit_memory
),
864 .proc_handler
= &proc_dointvec
,
867 .ctl_name
= VM_PANIC_ON_OOM
,
868 .procname
= "panic_on_oom",
869 .data
= &sysctl_panic_on_oom
,
870 .maxlen
= sizeof(sysctl_panic_on_oom
),
872 .proc_handler
= &proc_dointvec
,
875 .ctl_name
= CTL_UNNUMBERED
,
876 .procname
= "oom_kill_allocating_task",
877 .data
= &sysctl_oom_kill_allocating_task
,
878 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
880 .proc_handler
= &proc_dointvec
,
883 .ctl_name
= VM_OVERCOMMIT_RATIO
,
884 .procname
= "overcommit_ratio",
885 .data
= &sysctl_overcommit_ratio
,
886 .maxlen
= sizeof(sysctl_overcommit_ratio
),
888 .proc_handler
= &proc_dointvec
,
891 .ctl_name
= VM_PAGE_CLUSTER
,
892 .procname
= "page-cluster",
893 .data
= &page_cluster
,
894 .maxlen
= sizeof(int),
896 .proc_handler
= &proc_dointvec
,
899 .ctl_name
= VM_DIRTY_BACKGROUND
,
900 .procname
= "dirty_background_ratio",
901 .data
= &dirty_background_ratio
,
902 .maxlen
= sizeof(dirty_background_ratio
),
904 .proc_handler
= &proc_dointvec_minmax
,
905 .strategy
= &sysctl_intvec
,
907 .extra2
= &one_hundred
,
910 .ctl_name
= VM_DIRTY_RATIO
,
911 .procname
= "dirty_ratio",
912 .data
= &vm_dirty_ratio
,
913 .maxlen
= sizeof(vm_dirty_ratio
),
915 .proc_handler
= &dirty_ratio_handler
,
916 .strategy
= &sysctl_intvec
,
918 .extra2
= &one_hundred
,
921 .procname
= "dirty_writeback_centisecs",
922 .data
= &dirty_writeback_interval
,
923 .maxlen
= sizeof(dirty_writeback_interval
),
925 .proc_handler
= &dirty_writeback_centisecs_handler
,
928 .procname
= "dirty_expire_centisecs",
929 .data
= &dirty_expire_interval
,
930 .maxlen
= sizeof(dirty_expire_interval
),
932 .proc_handler
= &proc_dointvec_userhz_jiffies
,
935 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
936 .procname
= "nr_pdflush_threads",
937 .data
= &nr_pdflush_threads
,
938 .maxlen
= sizeof nr_pdflush_threads
,
939 .mode
= 0444 /* read-only*/,
940 .proc_handler
= &proc_dointvec
,
943 .ctl_name
= VM_SWAPPINESS
,
944 .procname
= "swappiness",
945 .data
= &vm_swappiness
,
946 .maxlen
= sizeof(vm_swappiness
),
948 .proc_handler
= &proc_dointvec_minmax
,
949 .strategy
= &sysctl_intvec
,
951 .extra2
= &one_hundred
,
953 #ifdef CONFIG_HUGETLB_PAGE
955 .procname
= "nr_hugepages",
956 .data
= &max_huge_pages
,
957 .maxlen
= sizeof(unsigned long),
959 .proc_handler
= &hugetlb_sysctl_handler
,
960 .extra1
= (void *)&hugetlb_zero
,
961 .extra2
= (void *)&hugetlb_infinity
,
964 .ctl_name
= VM_HUGETLB_GROUP
,
965 .procname
= "hugetlb_shm_group",
966 .data
= &sysctl_hugetlb_shm_group
,
967 .maxlen
= sizeof(gid_t
),
969 .proc_handler
= &proc_dointvec
,
972 .ctl_name
= CTL_UNNUMBERED
,
973 .procname
= "hugepages_treat_as_movable",
974 .data
= &hugepages_treat_as_movable
,
975 .maxlen
= sizeof(int),
977 .proc_handler
= &hugetlb_treat_movable_handler
,
980 .ctl_name
= CTL_UNNUMBERED
,
981 .procname
= "nr_overcommit_hugepages",
982 .data
= &nr_overcommit_huge_pages
,
983 .maxlen
= sizeof(nr_overcommit_huge_pages
),
985 .proc_handler
= &proc_doulongvec_minmax
,
989 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
990 .procname
= "lowmem_reserve_ratio",
991 .data
= &sysctl_lowmem_reserve_ratio
,
992 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
994 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
995 .strategy
= &sysctl_intvec
,
998 .ctl_name
= VM_DROP_PAGECACHE
,
999 .procname
= "drop_caches",
1000 .data
= &sysctl_drop_caches
,
1001 .maxlen
= sizeof(int),
1003 .proc_handler
= drop_caches_sysctl_handler
,
1004 .strategy
= &sysctl_intvec
,
1007 .ctl_name
= VM_MIN_FREE_KBYTES
,
1008 .procname
= "min_free_kbytes",
1009 .data
= &min_free_kbytes
,
1010 .maxlen
= sizeof(min_free_kbytes
),
1012 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1013 .strategy
= &sysctl_intvec
,
1017 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1018 .procname
= "percpu_pagelist_fraction",
1019 .data
= &percpu_pagelist_fraction
,
1020 .maxlen
= sizeof(percpu_pagelist_fraction
),
1022 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1023 .strategy
= &sysctl_intvec
,
1024 .extra1
= &min_percpu_pagelist_fract
,
1028 .ctl_name
= VM_MAX_MAP_COUNT
,
1029 .procname
= "max_map_count",
1030 .data
= &sysctl_max_map_count
,
1031 .maxlen
= sizeof(sysctl_max_map_count
),
1033 .proc_handler
= &proc_dointvec
1037 .ctl_name
= VM_LAPTOP_MODE
,
1038 .procname
= "laptop_mode",
1039 .data
= &laptop_mode
,
1040 .maxlen
= sizeof(laptop_mode
),
1042 .proc_handler
= &proc_dointvec_jiffies
,
1043 .strategy
= &sysctl_jiffies
,
1046 .ctl_name
= VM_BLOCK_DUMP
,
1047 .procname
= "block_dump",
1048 .data
= &block_dump
,
1049 .maxlen
= sizeof(block_dump
),
1051 .proc_handler
= &proc_dointvec
,
1052 .strategy
= &sysctl_intvec
,
1056 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1057 .procname
= "vfs_cache_pressure",
1058 .data
= &sysctl_vfs_cache_pressure
,
1059 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1061 .proc_handler
= &proc_dointvec
,
1062 .strategy
= &sysctl_intvec
,
1065 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1067 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1068 .procname
= "legacy_va_layout",
1069 .data
= &sysctl_legacy_va_layout
,
1070 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1072 .proc_handler
= &proc_dointvec
,
1073 .strategy
= &sysctl_intvec
,
1079 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1080 .procname
= "zone_reclaim_mode",
1081 .data
= &zone_reclaim_mode
,
1082 .maxlen
= sizeof(zone_reclaim_mode
),
1084 .proc_handler
= &proc_dointvec
,
1085 .strategy
= &sysctl_intvec
,
1089 .ctl_name
= VM_MIN_UNMAPPED
,
1090 .procname
= "min_unmapped_ratio",
1091 .data
= &sysctl_min_unmapped_ratio
,
1092 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1094 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1095 .strategy
= &sysctl_intvec
,
1097 .extra2
= &one_hundred
,
1100 .ctl_name
= VM_MIN_SLAB
,
1101 .procname
= "min_slab_ratio",
1102 .data
= &sysctl_min_slab_ratio
,
1103 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1105 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1106 .strategy
= &sysctl_intvec
,
1108 .extra2
= &one_hundred
,
1113 .ctl_name
= CTL_UNNUMBERED
,
1114 .procname
= "stat_interval",
1115 .data
= &sysctl_stat_interval
,
1116 .maxlen
= sizeof(sysctl_stat_interval
),
1118 .proc_handler
= &proc_dointvec_jiffies
,
1119 .strategy
= &sysctl_jiffies
,
1122 #ifdef CONFIG_SECURITY
1124 .ctl_name
= CTL_UNNUMBERED
,
1125 .procname
= "mmap_min_addr",
1126 .data
= &mmap_min_addr
,
1127 .maxlen
= sizeof(unsigned long),
1129 .proc_handler
= &proc_doulongvec_minmax
,
1134 .ctl_name
= CTL_UNNUMBERED
,
1135 .procname
= "numa_zonelist_order",
1136 .data
= &numa_zonelist_order
,
1137 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1139 .proc_handler
= &numa_zonelist_order_handler
,
1140 .strategy
= &sysctl_string
,
1143 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1144 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1146 .ctl_name
= VM_VDSO_ENABLED
,
1147 .procname
= "vdso_enabled",
1148 .data
= &vdso_enabled
,
1149 .maxlen
= sizeof(vdso_enabled
),
1151 .proc_handler
= &proc_dointvec
,
1152 .strategy
= &sysctl_intvec
,
1156 #ifdef CONFIG_HIGHMEM
1158 .ctl_name
= CTL_UNNUMBERED
,
1159 .procname
= "highmem_is_dirtyable",
1160 .data
= &vm_highmem_is_dirtyable
,
1161 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1163 .proc_handler
= &proc_dointvec_minmax
,
1164 .strategy
= &sysctl_intvec
,
1170 * NOTE: do not add new entries to this table unless you have read
1171 * Documentation/sysctl/ctl_unnumbered.txt
1176 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1177 static struct ctl_table binfmt_misc_table
[] = {
1182 static struct ctl_table fs_table
[] = {
1184 .ctl_name
= FS_NRINODE
,
1185 .procname
= "inode-nr",
1186 .data
= &inodes_stat
,
1187 .maxlen
= 2*sizeof(int),
1189 .proc_handler
= &proc_dointvec
,
1192 .ctl_name
= FS_STATINODE
,
1193 .procname
= "inode-state",
1194 .data
= &inodes_stat
,
1195 .maxlen
= 7*sizeof(int),
1197 .proc_handler
= &proc_dointvec
,
1200 .procname
= "file-nr",
1201 .data
= &files_stat
,
1202 .maxlen
= 3*sizeof(int),
1204 .proc_handler
= &proc_nr_files
,
1207 .ctl_name
= FS_MAXFILE
,
1208 .procname
= "file-max",
1209 .data
= &files_stat
.max_files
,
1210 .maxlen
= sizeof(int),
1212 .proc_handler
= &proc_dointvec
,
1215 .ctl_name
= FS_DENTRY
,
1216 .procname
= "dentry-state",
1217 .data
= &dentry_stat
,
1218 .maxlen
= 6*sizeof(int),
1220 .proc_handler
= &proc_dointvec
,
1223 .ctl_name
= FS_OVERFLOWUID
,
1224 .procname
= "overflowuid",
1225 .data
= &fs_overflowuid
,
1226 .maxlen
= sizeof(int),
1228 .proc_handler
= &proc_dointvec_minmax
,
1229 .strategy
= &sysctl_intvec
,
1230 .extra1
= &minolduid
,
1231 .extra2
= &maxolduid
,
1234 .ctl_name
= FS_OVERFLOWGID
,
1235 .procname
= "overflowgid",
1236 .data
= &fs_overflowgid
,
1237 .maxlen
= sizeof(int),
1239 .proc_handler
= &proc_dointvec_minmax
,
1240 .strategy
= &sysctl_intvec
,
1241 .extra1
= &minolduid
,
1242 .extra2
= &maxolduid
,
1245 .ctl_name
= FS_LEASES
,
1246 .procname
= "leases-enable",
1247 .data
= &leases_enable
,
1248 .maxlen
= sizeof(int),
1250 .proc_handler
= &proc_dointvec
,
1252 #ifdef CONFIG_DNOTIFY
1254 .ctl_name
= FS_DIR_NOTIFY
,
1255 .procname
= "dir-notify-enable",
1256 .data
= &dir_notify_enable
,
1257 .maxlen
= sizeof(int),
1259 .proc_handler
= &proc_dointvec
,
1264 .ctl_name
= FS_LEASE_TIME
,
1265 .procname
= "lease-break-time",
1266 .data
= &lease_break_time
,
1267 .maxlen
= sizeof(int),
1269 .proc_handler
= &proc_dointvec_minmax
,
1270 .strategy
= &sysctl_intvec
,
1275 .procname
= "aio-nr",
1277 .maxlen
= sizeof(aio_nr
),
1279 .proc_handler
= &proc_doulongvec_minmax
,
1282 .procname
= "aio-max-nr",
1283 .data
= &aio_max_nr
,
1284 .maxlen
= sizeof(aio_max_nr
),
1286 .proc_handler
= &proc_doulongvec_minmax
,
1288 #ifdef CONFIG_INOTIFY_USER
1290 .ctl_name
= FS_INOTIFY
,
1291 .procname
= "inotify",
1293 .child
= inotify_table
,
1298 .ctl_name
= KERN_SETUID_DUMPABLE
,
1299 .procname
= "suid_dumpable",
1300 .data
= &suid_dumpable
,
1301 .maxlen
= sizeof(int),
1303 .proc_handler
= &proc_dointvec
,
1305 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1307 .ctl_name
= CTL_UNNUMBERED
,
1308 .procname
= "binfmt_misc",
1310 .child
= binfmt_misc_table
,
1314 * NOTE: do not add new entries to this table unless you have read
1315 * Documentation/sysctl/ctl_unnumbered.txt
1320 static struct ctl_table debug_table
[] = {
1321 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1323 .ctl_name
= CTL_UNNUMBERED
,
1324 .procname
= "exception-trace",
1325 .data
= &show_unhandled_signals
,
1326 .maxlen
= sizeof(int),
1328 .proc_handler
= proc_dointvec
1334 static struct ctl_table dev_table
[] = {
1338 static DEFINE_SPINLOCK(sysctl_lock
);
1340 /* called under sysctl_lock */
1341 static int use_table(struct ctl_table_header
*p
)
1343 if (unlikely(p
->unregistering
))
1349 /* called under sysctl_lock */
1350 static void unuse_table(struct ctl_table_header
*p
)
1353 if (unlikely(p
->unregistering
))
1354 complete(p
->unregistering
);
1357 /* called under sysctl_lock, will reacquire if has to wait */
1358 static void start_unregistering(struct ctl_table_header
*p
)
1361 * if p->used is 0, nobody will ever touch that entry again;
1362 * we'll eliminate all paths to it before dropping sysctl_lock
1364 if (unlikely(p
->used
)) {
1365 struct completion wait
;
1366 init_completion(&wait
);
1367 p
->unregistering
= &wait
;
1368 spin_unlock(&sysctl_lock
);
1369 wait_for_completion(&wait
);
1370 spin_lock(&sysctl_lock
);
1373 * do not remove from the list until nobody holds it; walking the
1374 * list in do_sysctl() relies on that.
1376 list_del_init(&p
->ctl_entry
);
1379 void sysctl_head_finish(struct ctl_table_header
*head
)
1383 spin_lock(&sysctl_lock
);
1385 spin_unlock(&sysctl_lock
);
1388 static struct list_head
*
1389 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1391 struct list_head
*header_list
;
1392 header_list
= &root
->header_list
;
1394 header_list
= root
->lookup(root
, namespaces
);
1398 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1399 struct ctl_table_header
*prev
)
1401 struct ctl_table_root
*root
;
1402 struct list_head
*header_list
;
1403 struct ctl_table_header
*head
;
1404 struct list_head
*tmp
;
1406 spin_lock(&sysctl_lock
);
1409 tmp
= &prev
->ctl_entry
;
1413 tmp
= &root_table_header
.ctl_entry
;
1415 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1417 if (!use_table(head
))
1419 spin_unlock(&sysctl_lock
);
1424 header_list
= lookup_header_list(root
, namespaces
);
1425 if (tmp
!= header_list
)
1429 root
= list_entry(root
->root_list
.next
,
1430 struct ctl_table_root
, root_list
);
1431 if (root
== &sysctl_table_root
)
1433 header_list
= lookup_header_list(root
, namespaces
);
1434 } while (list_empty(header_list
));
1435 tmp
= header_list
->next
;
1438 spin_unlock(&sysctl_lock
);
1442 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1444 return __sysctl_head_next(current
->nsproxy
, prev
);
1447 void register_sysctl_root(struct ctl_table_root
*root
)
1449 spin_lock(&sysctl_lock
);
1450 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1451 spin_unlock(&sysctl_lock
);
1454 #ifdef CONFIG_SYSCTL_SYSCALL
1455 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1456 void __user
*newval
, size_t newlen
)
1458 struct ctl_table_header
*head
;
1459 int error
= -ENOTDIR
;
1461 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1465 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1469 for (head
= sysctl_head_next(NULL
); head
;
1470 head
= sysctl_head_next(head
)) {
1471 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1472 newval
, newlen
, head
->ctl_table
);
1473 if (error
!= -ENOTDIR
) {
1474 sysctl_head_finish(head
);
1481 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1483 struct __sysctl_args tmp
;
1486 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1489 error
= deprecated_sysctl_warning(&tmp
);
1494 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1495 tmp
.newval
, tmp
.newlen
);
1500 #endif /* CONFIG_SYSCTL_SYSCALL */
1503 * sysctl_perm does NOT grant the superuser all rights automatically, because
1504 * some sysctl variables are readonly even to root.
1507 static int test_perm(int mode
, int op
)
1511 else if (in_egroup_p(0))
1513 if ((mode
& op
& 0007) == op
)
1518 int sysctl_perm(struct ctl_table
*table
, int op
)
1521 error
= security_sysctl(table
, op
);
1524 return test_perm(table
->mode
, op
);
1527 #ifdef CONFIG_SYSCTL_SYSCALL
1528 static int parse_table(int __user
*name
, int nlen
,
1529 void __user
*oldval
, size_t __user
*oldlenp
,
1530 void __user
*newval
, size_t newlen
,
1531 struct ctl_table
*table
)
1537 if (get_user(n
, name
))
1539 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1540 if (!table
->ctl_name
)
1542 if (n
== table
->ctl_name
) {
1545 if (sysctl_perm(table
, 001))
1549 table
= table
->child
;
1552 error
= do_sysctl_strategy(table
, name
, nlen
,
1561 /* Perform the actual read/write of a sysctl table entry. */
1562 int do_sysctl_strategy (struct ctl_table
*table
,
1563 int __user
*name
, int nlen
,
1564 void __user
*oldval
, size_t __user
*oldlenp
,
1565 void __user
*newval
, size_t newlen
)
1573 if (sysctl_perm(table
, op
))
1576 if (table
->strategy
) {
1577 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1585 /* If there is no strategy routine, or if the strategy returns
1586 * zero, proceed with automatic r/w */
1587 if (table
->data
&& table
->maxlen
) {
1588 rc
= sysctl_data(table
, name
, nlen
, oldval
, oldlenp
,
1595 #endif /* CONFIG_SYSCTL_SYSCALL */
1597 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1599 for (; table
->ctl_name
|| table
->procname
; table
++) {
1600 table
->parent
= parent
;
1602 sysctl_set_parent(table
, table
->child
);
1606 static __init
int sysctl_init(void)
1609 sysctl_set_parent(NULL
, root_table
);
1610 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1614 core_initcall(sysctl_init
);
1617 * __register_sysctl_paths - register a sysctl hierarchy
1618 * @root: List of sysctl headers to register on
1619 * @namespaces: Data to compute which lists of sysctl entries are visible
1620 * @path: The path to the directory the sysctl table is in.
1621 * @table: the top-level table structure
1623 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1624 * array. A completely 0 filled entry terminates the table.
1626 * The members of the &struct ctl_table structure are used as follows:
1628 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1629 * must be unique within that level of sysctl
1631 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1632 * enter a sysctl file
1634 * data - a pointer to data for use by proc_handler
1636 * maxlen - the maximum size in bytes of the data
1638 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1640 * child - a pointer to the child sysctl table if this entry is a directory, or
1643 * proc_handler - the text handler routine (described below)
1645 * strategy - the strategy routine (described below)
1647 * de - for internal use by the sysctl routines
1649 * extra1, extra2 - extra pointers usable by the proc handler routines
1651 * Leaf nodes in the sysctl tree will be represented by a single file
1652 * under /proc; non-leaf nodes will be represented by directories.
1654 * sysctl(2) can automatically manage read and write requests through
1655 * the sysctl table. The data and maxlen fields of the ctl_table
1656 * struct enable minimal validation of the values being written to be
1657 * performed, and the mode field allows minimal authentication.
1659 * More sophisticated management can be enabled by the provision of a
1660 * strategy routine with the table entry. This will be called before
1661 * any automatic read or write of the data is performed.
1663 * The strategy routine may return
1665 * < 0 - Error occurred (error is passed to user process)
1667 * 0 - OK - proceed with automatic read or write.
1669 * > 0 - OK - read or write has been done by the strategy routine, so
1670 * return immediately.
1672 * There must be a proc_handler routine for any terminal nodes
1673 * mirrored under /proc/sys (non-terminals are handled by a built-in
1674 * directory handler). Several default handlers are available to
1675 * cover common cases -
1677 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1678 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1679 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1681 * It is the handler's job to read the input buffer from user memory
1682 * and process it. The handler should return 0 on success.
1684 * This routine returns %NULL on a failure to register, and a pointer
1685 * to the table header on success.
1687 struct ctl_table_header
*__register_sysctl_paths(
1688 struct ctl_table_root
*root
,
1689 struct nsproxy
*namespaces
,
1690 const struct ctl_path
*path
, struct ctl_table
*table
)
1692 struct list_head
*header_list
;
1693 struct ctl_table_header
*header
;
1694 struct ctl_table
*new, **prevp
;
1695 unsigned int n
, npath
;
1697 /* Count the path components */
1698 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
1702 * For each path component, allocate a 2-element ctl_table array.
1703 * The first array element will be filled with the sysctl entry
1704 * for this, the second will be the sentinel (ctl_name == 0).
1706 * We allocate everything in one go so that we don't have to
1707 * worry about freeing additional memory in unregister_sysctl_table.
1709 header
= kzalloc(sizeof(struct ctl_table_header
) +
1710 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1714 new = (struct ctl_table
*) (header
+ 1);
1716 /* Now connect the dots */
1717 prevp
= &header
->ctl_table
;
1718 for (n
= 0; n
< npath
; ++n
, ++path
) {
1719 /* Copy the procname */
1720 new->procname
= path
->procname
;
1721 new->ctl_name
= path
->ctl_name
;
1725 prevp
= &new->child
;
1730 header
->ctl_table_arg
= table
;
1732 INIT_LIST_HEAD(&header
->ctl_entry
);
1734 header
->unregistering
= NULL
;
1735 header
->root
= root
;
1736 sysctl_set_parent(NULL
, header
->ctl_table
);
1737 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1741 spin_lock(&sysctl_lock
);
1742 header_list
= lookup_header_list(root
, namespaces
);
1743 list_add_tail(&header
->ctl_entry
, header_list
);
1744 spin_unlock(&sysctl_lock
);
1750 * register_sysctl_table_path - register a sysctl table hierarchy
1751 * @path: The path to the directory the sysctl table is in.
1752 * @table: the top-level table structure
1754 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1755 * array. A completely 0 filled entry terminates the table.
1757 * See __register_sysctl_paths for more details.
1759 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1760 struct ctl_table
*table
)
1762 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1767 * register_sysctl_table - register a sysctl table hierarchy
1768 * @table: the top-level table structure
1770 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1771 * array. A completely 0 filled entry terminates the table.
1773 * See register_sysctl_paths for more details.
1775 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1777 static const struct ctl_path null_path
[] = { {} };
1779 return register_sysctl_paths(null_path
, table
);
1783 * unregister_sysctl_table - unregister a sysctl table hierarchy
1784 * @header: the header returned from register_sysctl_table
1786 * Unregisters the sysctl table and all children. proc entries may not
1787 * actually be removed until they are no longer used by anyone.
1789 void unregister_sysctl_table(struct ctl_table_header
* header
)
1796 spin_lock(&sysctl_lock
);
1797 start_unregistering(header
);
1798 spin_unlock(&sysctl_lock
);
1802 #else /* !CONFIG_SYSCTL */
1803 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1808 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1809 struct ctl_table
*table
)
1814 void unregister_sysctl_table(struct ctl_table_header
* table
)
1818 #endif /* CONFIG_SYSCTL */
1824 #ifdef CONFIG_PROC_SYSCTL
1826 static int _proc_do_string(void* data
, int maxlen
, int write
,
1827 struct file
*filp
, void __user
*buffer
,
1828 size_t *lenp
, loff_t
*ppos
)
1834 if (!data
|| !maxlen
|| !*lenp
) {
1842 while (len
< *lenp
) {
1843 if (get_user(c
, p
++))
1845 if (c
== 0 || c
== '\n')
1851 if(copy_from_user(data
, buffer
, len
))
1853 ((char *) data
)[len
] = 0;
1871 if(copy_to_user(buffer
, data
, len
))
1874 if(put_user('\n', ((char __user
*) buffer
) + len
))
1885 * proc_dostring - read a string sysctl
1886 * @table: the sysctl table
1887 * @write: %TRUE if this is a write to the sysctl file
1888 * @filp: the file structure
1889 * @buffer: the user buffer
1890 * @lenp: the size of the user buffer
1891 * @ppos: file position
1893 * Reads/writes a string from/to the user buffer. If the kernel
1894 * buffer provided is not large enough to hold the string, the
1895 * string is truncated. The copied string is %NULL-terminated.
1896 * If the string is being read by the user process, it is copied
1897 * and a newline '\n' is added. It is truncated if the buffer is
1900 * Returns 0 on success.
1902 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
1903 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1905 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
1906 buffer
, lenp
, ppos
);
1910 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1912 int write
, void *data
)
1915 *valp
= *negp
? -*lvalp
: *lvalp
;
1920 *lvalp
= (unsigned long)-val
;
1923 *lvalp
= (unsigned long)val
;
1929 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1930 int write
, struct file
*filp
, void __user
*buffer
,
1931 size_t *lenp
, loff_t
*ppos
,
1932 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1933 int write
, void *data
),
1936 #define TMPBUFLEN 21
1937 int *i
, vleft
, first
=1, neg
, val
;
1941 char buf
[TMPBUFLEN
], *p
;
1942 char __user
*s
= buffer
;
1944 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
1945 (*ppos
&& !write
)) {
1950 i
= (int *) tbl_data
;
1951 vleft
= table
->maxlen
/ sizeof(*i
);
1955 conv
= do_proc_dointvec_conv
;
1957 for (; left
&& vleft
--; i
++, first
=0) {
1972 if (len
> sizeof(buf
) - 1)
1973 len
= sizeof(buf
) - 1;
1974 if (copy_from_user(buf
, s
, len
))
1978 if (*p
== '-' && left
> 1) {
1982 if (*p
< '0' || *p
> '9')
1985 lval
= simple_strtoul(p
, &p
, 0);
1988 if ((len
< left
) && *p
&& !isspace(*p
))
1995 if (conv(&neg
, &lval
, i
, 1, data
))
2002 if (conv(&neg
, &lval
, i
, 0, data
))
2005 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2009 if(copy_to_user(s
, buf
, len
))
2016 if (!write
&& !first
&& left
) {
2017 if(put_user('\n', s
))
2024 if (get_user(c
, s
++))
2039 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2040 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2041 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2042 int write
, void *data
),
2045 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2046 buffer
, lenp
, ppos
, conv
, data
);
2050 * proc_dointvec - read a vector of integers
2051 * @table: the sysctl table
2052 * @write: %TRUE if this is a write to the sysctl file
2053 * @filp: the file structure
2054 * @buffer: the user buffer
2055 * @lenp: the size of the user buffer
2056 * @ppos: file position
2058 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2059 * values from/to the user buffer, treated as an ASCII string.
2061 * Returns 0 on success.
2063 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2064 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2066 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2074 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
2076 int write
, void *data
)
2078 int op
= *(int *)data
;
2080 int val
= *negp
? -*lvalp
: *lvalp
;
2082 case OP_SET
: *valp
= val
; break;
2083 case OP_AND
: *valp
&= val
; break;
2084 case OP_OR
: *valp
|= val
; break;
2090 *lvalp
= (unsigned long)-val
;
2093 *lvalp
= (unsigned long)val
;
2099 #ifdef CONFIG_SECURITY_CAPABILITIES
2101 * init may raise the set.
2104 int proc_dointvec_bset(struct ctl_table
*table
, int write
, struct file
*filp
,
2105 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2109 if (write
&& !capable(CAP_SYS_MODULE
)) {
2113 op
= is_global_init(current
) ? OP_SET
: OP_AND
;
2114 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2115 do_proc_dointvec_bset_conv
,&op
);
2117 #endif /* def CONFIG_SECURITY_CAPABILITIES */
2120 * Taint values can only be increased
2122 static int proc_dointvec_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2123 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2127 if (write
&& !capable(CAP_SYS_ADMIN
))
2131 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2132 do_proc_dointvec_bset_conv
,&op
);
2135 struct do_proc_dointvec_minmax_conv_param
{
2140 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2142 int write
, void *data
)
2144 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2146 int val
= *negp
? -*lvalp
: *lvalp
;
2147 if ((param
->min
&& *param
->min
> val
) ||
2148 (param
->max
&& *param
->max
< val
))
2155 *lvalp
= (unsigned long)-val
;
2158 *lvalp
= (unsigned long)val
;
2165 * proc_dointvec_minmax - read a vector of integers with min/max values
2166 * @table: the sysctl table
2167 * @write: %TRUE if this is a write to the sysctl file
2168 * @filp: the file structure
2169 * @buffer: the user buffer
2170 * @lenp: the size of the user buffer
2171 * @ppos: file position
2173 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2174 * values from/to the user buffer, treated as an ASCII string.
2176 * This routine will ensure the values are within the range specified by
2177 * table->extra1 (min) and table->extra2 (max).
2179 * Returns 0 on success.
2181 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2182 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2184 struct do_proc_dointvec_minmax_conv_param param
= {
2185 .min
= (int *) table
->extra1
,
2186 .max
= (int *) table
->extra2
,
2188 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2189 do_proc_dointvec_minmax_conv
, ¶m
);
2192 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2194 void __user
*buffer
,
2195 size_t *lenp
, loff_t
*ppos
,
2196 unsigned long convmul
,
2197 unsigned long convdiv
)
2199 #define TMPBUFLEN 21
2200 unsigned long *i
, *min
, *max
, val
;
2201 int vleft
, first
=1, neg
;
2203 char buf
[TMPBUFLEN
], *p
;
2204 char __user
*s
= buffer
;
2206 if (!data
|| !table
->maxlen
|| !*lenp
||
2207 (*ppos
&& !write
)) {
2212 i
= (unsigned long *) data
;
2213 min
= (unsigned long *) table
->extra1
;
2214 max
= (unsigned long *) table
->extra2
;
2215 vleft
= table
->maxlen
/ sizeof(unsigned long);
2218 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2233 if (len
> TMPBUFLEN
-1)
2235 if (copy_from_user(buf
, s
, len
))
2239 if (*p
== '-' && left
> 1) {
2243 if (*p
< '0' || *p
> '9')
2245 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2247 if ((len
< left
) && *p
&& !isspace(*p
))
2256 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2263 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2267 if(copy_to_user(s
, buf
, len
))
2274 if (!write
&& !first
&& left
) {
2275 if(put_user('\n', s
))
2282 if (get_user(c
, s
++))
2297 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2299 void __user
*buffer
,
2300 size_t *lenp
, loff_t
*ppos
,
2301 unsigned long convmul
,
2302 unsigned long convdiv
)
2304 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2305 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2309 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2310 * @table: the sysctl table
2311 * @write: %TRUE if this is a write to the sysctl file
2312 * @filp: the file structure
2313 * @buffer: the user buffer
2314 * @lenp: the size of the user buffer
2315 * @ppos: file position
2317 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2318 * values from/to the user buffer, treated as an ASCII string.
2320 * This routine will ensure the values are within the range specified by
2321 * table->extra1 (min) and table->extra2 (max).
2323 * Returns 0 on success.
2325 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2326 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2328 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2332 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2333 * @table: the sysctl table
2334 * @write: %TRUE if this is a write to the sysctl file
2335 * @filp: the file structure
2336 * @buffer: the user buffer
2337 * @lenp: the size of the user buffer
2338 * @ppos: file position
2340 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2341 * values from/to the user buffer, treated as an ASCII string. The values
2342 * are treated as milliseconds, and converted to jiffies when they are stored.
2344 * This routine will ensure the values are within the range specified by
2345 * table->extra1 (min) and table->extra2 (max).
2347 * Returns 0 on success.
2349 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2351 void __user
*buffer
,
2352 size_t *lenp
, loff_t
*ppos
)
2354 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2355 lenp
, ppos
, HZ
, 1000l);
2359 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2361 int write
, void *data
)
2364 if (*lvalp
> LONG_MAX
/ HZ
)
2366 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2372 lval
= (unsigned long)-val
;
2375 lval
= (unsigned long)val
;
2382 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2384 int write
, void *data
)
2387 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2389 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2395 lval
= (unsigned long)-val
;
2398 lval
= (unsigned long)val
;
2400 *lvalp
= jiffies_to_clock_t(lval
);
2405 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2407 int write
, void *data
)
2410 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2416 lval
= (unsigned long)-val
;
2419 lval
= (unsigned long)val
;
2421 *lvalp
= jiffies_to_msecs(lval
);
2427 * proc_dointvec_jiffies - read a vector of integers as seconds
2428 * @table: the sysctl table
2429 * @write: %TRUE if this is a write to the sysctl file
2430 * @filp: the file structure
2431 * @buffer: the user buffer
2432 * @lenp: the size of the user buffer
2433 * @ppos: file position
2435 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2436 * values from/to the user buffer, treated as an ASCII string.
2437 * The values read are assumed to be in seconds, and are converted into
2440 * Returns 0 on success.
2442 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2443 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2445 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2446 do_proc_dointvec_jiffies_conv
,NULL
);
2450 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2451 * @table: the sysctl table
2452 * @write: %TRUE if this is a write to the sysctl file
2453 * @filp: the file structure
2454 * @buffer: the user buffer
2455 * @lenp: the size of the user buffer
2456 * @ppos: pointer to the file position
2458 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2459 * values from/to the user buffer, treated as an ASCII string.
2460 * The values read are assumed to be in 1/USER_HZ seconds, and
2461 * are converted into jiffies.
2463 * Returns 0 on success.
2465 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2466 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2468 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2469 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2473 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2474 * @table: the sysctl table
2475 * @write: %TRUE if this is a write to the sysctl file
2476 * @filp: the file structure
2477 * @buffer: the user buffer
2478 * @lenp: the size of the user buffer
2479 * @ppos: file position
2480 * @ppos: the current position in the file
2482 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2483 * values from/to the user buffer, treated as an ASCII string.
2484 * The values read are assumed to be in 1/1000 seconds, and
2485 * are converted into jiffies.
2487 * Returns 0 on success.
2489 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2490 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2492 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2493 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2496 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2497 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2499 struct pid
*new_pid
;
2503 tmp
= pid_nr_ns(cad_pid
, current
->nsproxy
->pid_ns
);
2505 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2506 lenp
, ppos
, NULL
, NULL
);
2510 new_pid
= find_get_pid(tmp
);
2514 put_pid(xchg(&cad_pid
, new_pid
));
2518 #else /* CONFIG_PROC_FS */
2520 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2521 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2526 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2527 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2532 int proc_dointvec_bset(struct ctl_table
*table
, int write
, struct file
*filp
,
2533 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2538 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2539 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2544 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2545 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2550 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2551 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2556 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2557 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2562 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2563 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2568 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2570 void __user
*buffer
,
2571 size_t *lenp
, loff_t
*ppos
)
2577 #endif /* CONFIG_PROC_FS */
2580 #ifdef CONFIG_SYSCTL_SYSCALL
2582 * General sysctl support routines
2585 /* The generic sysctl data routine (used if no strategy routine supplied) */
2586 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2587 void __user
*oldval
, size_t __user
*oldlenp
,
2588 void __user
*newval
, size_t newlen
)
2592 /* Get out of I don't have a variable */
2593 if (!table
->data
|| !table
->maxlen
)
2596 if (oldval
&& oldlenp
) {
2597 if (get_user(len
, oldlenp
))
2600 if (len
> table
->maxlen
)
2601 len
= table
->maxlen
;
2602 if (copy_to_user(oldval
, table
->data
, len
))
2604 if (put_user(len
, oldlenp
))
2609 if (newval
&& newlen
) {
2610 if (newlen
> table
->maxlen
)
2611 newlen
= table
->maxlen
;
2613 if (copy_from_user(table
->data
, newval
, newlen
))
2619 /* The generic string strategy routine: */
2620 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2621 void __user
*oldval
, size_t __user
*oldlenp
,
2622 void __user
*newval
, size_t newlen
)
2624 if (!table
->data
|| !table
->maxlen
)
2627 if (oldval
&& oldlenp
) {
2629 if (get_user(bufsize
, oldlenp
))
2632 size_t len
= strlen(table
->data
), copied
;
2634 /* This shouldn't trigger for a well-formed sysctl */
2635 if (len
> table
->maxlen
)
2636 len
= table
->maxlen
;
2638 /* Copy up to a max of bufsize-1 bytes of the string */
2639 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2641 if (copy_to_user(oldval
, table
->data
, copied
) ||
2642 put_user(0, (char __user
*)(oldval
+ copied
)))
2644 if (put_user(len
, oldlenp
))
2648 if (newval
&& newlen
) {
2649 size_t len
= newlen
;
2650 if (len
> table
->maxlen
)
2651 len
= table
->maxlen
;
2652 if(copy_from_user(table
->data
, newval
, len
))
2654 if (len
== table
->maxlen
)
2656 ((char *) table
->data
)[len
] = 0;
2662 * This function makes sure that all of the integers in the vector
2663 * are between the minimum and maximum values given in the arrays
2664 * table->extra1 and table->extra2, respectively.
2666 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2667 void __user
*oldval
, size_t __user
*oldlenp
,
2668 void __user
*newval
, size_t newlen
)
2671 if (newval
&& newlen
) {
2672 int __user
*vec
= (int __user
*) newval
;
2673 int *min
= (int *) table
->extra1
;
2674 int *max
= (int *) table
->extra2
;
2678 if (newlen
% sizeof(int) != 0)
2681 if (!table
->extra1
&& !table
->extra2
)
2684 if (newlen
> table
->maxlen
)
2685 newlen
= table
->maxlen
;
2686 length
= newlen
/ sizeof(int);
2688 for (i
= 0; i
< length
; i
++) {
2690 if (get_user(value
, vec
+ i
))
2692 if (min
&& value
< min
[i
])
2694 if (max
&& value
> max
[i
])
2701 /* Strategy function to convert jiffies to seconds */
2702 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2703 void __user
*oldval
, size_t __user
*oldlenp
,
2704 void __user
*newval
, size_t newlen
)
2706 if (oldval
&& oldlenp
) {
2709 if (get_user(olen
, oldlenp
))
2714 if (olen
< sizeof(int))
2717 val
= *(int *)(table
->data
) / HZ
;
2718 if (put_user(val
, (int __user
*)oldval
))
2720 if (put_user(sizeof(int), oldlenp
))
2724 if (newval
&& newlen
) {
2726 if (newlen
!= sizeof(int))
2728 if (get_user(new, (int __user
*)newval
))
2730 *(int *)(table
->data
) = new*HZ
;
2735 /* Strategy function to convert jiffies to seconds */
2736 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2737 void __user
*oldval
, size_t __user
*oldlenp
,
2738 void __user
*newval
, size_t newlen
)
2740 if (oldval
&& oldlenp
) {
2743 if (get_user(olen
, oldlenp
))
2748 if (olen
< sizeof(int))
2751 val
= jiffies_to_msecs(*(int *)(table
->data
));
2752 if (put_user(val
, (int __user
*)oldval
))
2754 if (put_user(sizeof(int), oldlenp
))
2758 if (newval
&& newlen
) {
2760 if (newlen
!= sizeof(int))
2762 if (get_user(new, (int __user
*)newval
))
2764 *(int *)(table
->data
) = msecs_to_jiffies(new);
2771 #else /* CONFIG_SYSCTL_SYSCALL */
2774 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2776 struct __sysctl_args tmp
;
2779 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
2782 error
= deprecated_sysctl_warning(&tmp
);
2784 /* If no error reading the parameters then just -ENOSYS ... */
2791 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2792 void __user
*oldval
, size_t __user
*oldlenp
,
2793 void __user
*newval
, size_t newlen
)
2798 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2799 void __user
*oldval
, size_t __user
*oldlenp
,
2800 void __user
*newval
, size_t newlen
)
2805 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2806 void __user
*oldval
, size_t __user
*oldlenp
,
2807 void __user
*newval
, size_t newlen
)
2812 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2813 void __user
*oldval
, size_t __user
*oldlenp
,
2814 void __user
*newval
, size_t newlen
)
2819 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2820 void __user
*oldval
, size_t __user
*oldlenp
,
2821 void __user
*newval
, size_t newlen
)
2826 #endif /* CONFIG_SYSCTL_SYSCALL */
2828 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
2830 static int msg_count
;
2831 int name
[CTL_MAXNAME
];
2834 /* Check args->nlen. */
2835 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
2838 /* Read in the sysctl name for better debug message logging */
2839 for (i
= 0; i
< args
->nlen
; i
++)
2840 if (get_user(name
[i
], args
->name
+ i
))
2843 /* Ignore accesses to kernel.version */
2844 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
2847 if (msg_count
< 5) {
2850 "warning: process `%s' used the deprecated sysctl "
2851 "system call with ", current
->comm
);
2852 for (i
= 0; i
< args
->nlen
; i
++)
2853 printk("%d.", name
[i
]);
2860 * No sense putting this after each symbol definition, twice,
2861 * exception granted :-)
2863 EXPORT_SYMBOL(proc_dointvec
);
2864 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2865 EXPORT_SYMBOL(proc_dointvec_minmax
);
2866 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2867 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2868 EXPORT_SYMBOL(proc_dostring
);
2869 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2870 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2871 EXPORT_SYMBOL(register_sysctl_table
);
2872 EXPORT_SYMBOL(register_sysctl_paths
);
2873 EXPORT_SYMBOL(sysctl_intvec
);
2874 EXPORT_SYMBOL(sysctl_jiffies
);
2875 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2876 EXPORT_SYMBOL(sysctl_string
);
2877 EXPORT_SYMBOL(sysctl_data
);
2878 EXPORT_SYMBOL(unregister_sysctl_table
);