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>
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 max_threads
;
70 extern int core_uses_pid
;
71 extern int suid_dumpable
;
72 extern char core_pattern
[];
74 extern int min_free_kbytes
;
75 extern int printk_ratelimit_jiffies
;
76 extern int printk_ratelimit_burst
;
77 extern int pid_max_min
, pid_max_max
;
78 extern int sysctl_drop_caches
;
79 extern int percpu_pagelist_fraction
;
80 extern int compat_log
;
81 extern int maps_protect
;
82 extern int sysctl_stat_interval
;
83 extern int audit_argv_kb
;
84 extern int latencytop_enabled
;
86 /* Constants used for minimum and maximum */
87 #ifdef CONFIG_DETECT_SOFTLOCKUP
89 static int sixty
= 60;
97 static int one_hundred
= 100;
99 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
100 static int maxolduid
= 65535;
101 static int minolduid
;
102 static int min_percpu_pagelist_fract
= 8;
104 static int ngroups_max
= NGROUPS_MAX
;
107 extern char modprobe_path
[];
109 #ifdef CONFIG_CHR_DEV_SG
110 extern int sg_big_buff
;
114 extern char reboot_command
[];
115 extern int stop_a_enabled
;
116 extern int scons_pwroff
;
120 extern int pwrsw_enabled
;
121 extern int unaligned_enabled
;
125 #ifdef CONFIG_MATHEMU
126 extern int sysctl_ieee_emulation_warnings
;
128 extern int sysctl_userprocess_debug
;
129 extern int spin_retry
;
132 extern int sysctl_hz_timer
;
134 #ifdef CONFIG_BSD_PROCESS_ACCT
135 extern int acct_parm
[];
139 extern int no_unaligned_warning
;
142 #ifdef CONFIG_RT_MUTEXES
143 extern int max_lock_depth
;
146 #ifdef CONFIG_SYSCTL_SYSCALL
147 static int parse_table(int __user
*, int, void __user
*, size_t __user
*,
148 void __user
*, size_t, struct ctl_table
*);
152 #ifdef CONFIG_PROC_SYSCTL
153 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
154 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
155 static int proc_dointvec_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
156 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
159 static struct ctl_table root_table
[];
160 static struct ctl_table_root sysctl_table_root
;
161 static struct ctl_table_header root_table_header
= {
162 .ctl_table
= root_table
,
163 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.header_list
),
164 .root
= &sysctl_table_root
,
166 static struct ctl_table_root sysctl_table_root
= {
167 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
168 .header_list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
171 static struct ctl_table kern_table
[];
172 static struct ctl_table vm_table
[];
173 static struct ctl_table fs_table
[];
174 static struct ctl_table debug_table
[];
175 static struct ctl_table dev_table
[];
176 extern struct ctl_table random_table
[];
177 #ifdef CONFIG_INOTIFY_USER
178 extern struct ctl_table inotify_table
[];
181 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
182 int sysctl_legacy_va_layout
;
185 extern int prove_locking
;
186 extern int lock_stat
;
188 /* The default sysctl tables: */
190 static struct ctl_table root_table
[] = {
192 .ctl_name
= CTL_KERN
,
193 .procname
= "kernel",
218 .ctl_name
= CTL_DEBUG
,
221 .child
= debug_table
,
230 * NOTE: do not add new entries to this table unless you have read
231 * Documentation/sysctl/ctl_unnumbered.txt
236 #ifdef CONFIG_SCHED_DEBUG
237 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
238 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
239 static int min_wakeup_granularity_ns
; /* 0 usecs */
240 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
243 static struct ctl_table kern_table
[] = {
244 #ifdef CONFIG_SCHED_DEBUG
246 .ctl_name
= CTL_UNNUMBERED
,
247 .procname
= "sched_min_granularity_ns",
248 .data
= &sysctl_sched_min_granularity
,
249 .maxlen
= sizeof(unsigned int),
251 .proc_handler
= &sched_nr_latency_handler
,
252 .strategy
= &sysctl_intvec
,
253 .extra1
= &min_sched_granularity_ns
,
254 .extra2
= &max_sched_granularity_ns
,
257 .ctl_name
= CTL_UNNUMBERED
,
258 .procname
= "sched_latency_ns",
259 .data
= &sysctl_sched_latency
,
260 .maxlen
= sizeof(unsigned int),
262 .proc_handler
= &sched_nr_latency_handler
,
263 .strategy
= &sysctl_intvec
,
264 .extra1
= &min_sched_granularity_ns
,
265 .extra2
= &max_sched_granularity_ns
,
268 .ctl_name
= CTL_UNNUMBERED
,
269 .procname
= "sched_wakeup_granularity_ns",
270 .data
= &sysctl_sched_wakeup_granularity
,
271 .maxlen
= sizeof(unsigned int),
273 .proc_handler
= &proc_dointvec_minmax
,
274 .strategy
= &sysctl_intvec
,
275 .extra1
= &min_wakeup_granularity_ns
,
276 .extra2
= &max_wakeup_granularity_ns
,
279 .ctl_name
= CTL_UNNUMBERED
,
280 .procname
= "sched_batch_wakeup_granularity_ns",
281 .data
= &sysctl_sched_batch_wakeup_granularity
,
282 .maxlen
= sizeof(unsigned int),
284 .proc_handler
= &proc_dointvec_minmax
,
285 .strategy
= &sysctl_intvec
,
286 .extra1
= &min_wakeup_granularity_ns
,
287 .extra2
= &max_wakeup_granularity_ns
,
290 .ctl_name
= CTL_UNNUMBERED
,
291 .procname
= "sched_child_runs_first",
292 .data
= &sysctl_sched_child_runs_first
,
293 .maxlen
= sizeof(unsigned int),
295 .proc_handler
= &proc_dointvec
,
298 .ctl_name
= CTL_UNNUMBERED
,
299 .procname
= "sched_features",
300 .data
= &sysctl_sched_features
,
301 .maxlen
= sizeof(unsigned int),
303 .proc_handler
= &proc_dointvec
,
306 .ctl_name
= CTL_UNNUMBERED
,
307 .procname
= "sched_migration_cost",
308 .data
= &sysctl_sched_migration_cost
,
309 .maxlen
= sizeof(unsigned int),
311 .proc_handler
= &proc_dointvec
,
314 .ctl_name
= CTL_UNNUMBERED
,
315 .procname
= "sched_nr_migrate",
316 .data
= &sysctl_sched_nr_migrate
,
317 .maxlen
= sizeof(unsigned int),
319 .proc_handler
= &proc_dointvec
,
322 .ctl_name
= CTL_UNNUMBERED
,
323 .procname
= "sched_rt_period_ms",
324 .data
= &sysctl_sched_rt_period
,
325 .maxlen
= sizeof(unsigned int),
327 .proc_handler
= &proc_dointvec
,
330 .ctl_name
= CTL_UNNUMBERED
,
331 .procname
= "sched_rt_ratio",
332 .data
= &sysctl_sched_rt_ratio
,
333 .maxlen
= sizeof(unsigned int),
335 .proc_handler
= &proc_dointvec
,
337 #if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_SMP)
339 .ctl_name
= CTL_UNNUMBERED
,
340 .procname
= "sched_min_bal_int_shares",
341 .data
= &sysctl_sched_min_bal_int_shares
,
342 .maxlen
= sizeof(unsigned int),
344 .proc_handler
= &proc_dointvec
,
347 .ctl_name
= CTL_UNNUMBERED
,
348 .procname
= "sched_max_bal_int_shares",
349 .data
= &sysctl_sched_max_bal_int_shares
,
350 .maxlen
= sizeof(unsigned int),
352 .proc_handler
= &proc_dointvec
,
357 .ctl_name
= CTL_UNNUMBERED
,
358 .procname
= "sched_compat_yield",
359 .data
= &sysctl_sched_compat_yield
,
360 .maxlen
= sizeof(unsigned int),
362 .proc_handler
= &proc_dointvec
,
364 #ifdef CONFIG_PROVE_LOCKING
366 .ctl_name
= CTL_UNNUMBERED
,
367 .procname
= "prove_locking",
368 .data
= &prove_locking
,
369 .maxlen
= sizeof(int),
371 .proc_handler
= &proc_dointvec
,
374 #ifdef CONFIG_LOCK_STAT
376 .ctl_name
= CTL_UNNUMBERED
,
377 .procname
= "lock_stat",
379 .maxlen
= sizeof(int),
381 .proc_handler
= &proc_dointvec
,
385 .ctl_name
= KERN_PANIC
,
387 .data
= &panic_timeout
,
388 .maxlen
= sizeof(int),
390 .proc_handler
= &proc_dointvec
,
393 .ctl_name
= KERN_CORE_USES_PID
,
394 .procname
= "core_uses_pid",
395 .data
= &core_uses_pid
,
396 .maxlen
= sizeof(int),
398 .proc_handler
= &proc_dointvec
,
400 #ifdef CONFIG_AUDITSYSCALL
402 .ctl_name
= CTL_UNNUMBERED
,
403 .procname
= "audit_argv_kb",
404 .data
= &audit_argv_kb
,
405 .maxlen
= sizeof(int),
407 .proc_handler
= &proc_dointvec
,
411 .ctl_name
= KERN_CORE_PATTERN
,
412 .procname
= "core_pattern",
413 .data
= core_pattern
,
414 .maxlen
= CORENAME_MAX_SIZE
,
416 .proc_handler
= &proc_dostring
,
417 .strategy
= &sysctl_string
,
419 #ifdef CONFIG_PROC_SYSCTL
421 .procname
= "tainted",
423 .maxlen
= sizeof(int),
425 .proc_handler
= &proc_dointvec_taint
,
428 #ifdef CONFIG_LATENCYTOP
430 .procname
= "latencytop",
431 .data
= &latencytop_enabled
,
432 .maxlen
= sizeof(int),
434 .proc_handler
= &proc_dointvec
,
437 #ifdef CONFIG_SECURITY_CAPABILITIES
439 .procname
= "cap-bound",
441 .maxlen
= sizeof(kernel_cap_t
),
443 .proc_handler
= &proc_dointvec_bset
,
445 #endif /* def CONFIG_SECURITY_CAPABILITIES */
446 #ifdef CONFIG_BLK_DEV_INITRD
448 .ctl_name
= KERN_REALROOTDEV
,
449 .procname
= "real-root-dev",
450 .data
= &real_root_dev
,
451 .maxlen
= sizeof(int),
453 .proc_handler
= &proc_dointvec
,
457 .ctl_name
= CTL_UNNUMBERED
,
458 .procname
= "print-fatal-signals",
459 .data
= &print_fatal_signals
,
460 .maxlen
= sizeof(int),
462 .proc_handler
= &proc_dointvec
,
466 .ctl_name
= KERN_SPARC_REBOOT
,
467 .procname
= "reboot-cmd",
468 .data
= reboot_command
,
471 .proc_handler
= &proc_dostring
,
472 .strategy
= &sysctl_string
,
475 .ctl_name
= KERN_SPARC_STOP_A
,
476 .procname
= "stop-a",
477 .data
= &stop_a_enabled
,
478 .maxlen
= sizeof (int),
480 .proc_handler
= &proc_dointvec
,
483 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
484 .procname
= "scons-poweroff",
485 .data
= &scons_pwroff
,
486 .maxlen
= sizeof (int),
488 .proc_handler
= &proc_dointvec
,
493 .ctl_name
= KERN_HPPA_PWRSW
,
494 .procname
= "soft-power",
495 .data
= &pwrsw_enabled
,
496 .maxlen
= sizeof (int),
498 .proc_handler
= &proc_dointvec
,
501 .ctl_name
= KERN_HPPA_UNALIGNED
,
502 .procname
= "unaligned-trap",
503 .data
= &unaligned_enabled
,
504 .maxlen
= sizeof (int),
506 .proc_handler
= &proc_dointvec
,
510 .ctl_name
= KERN_CTLALTDEL
,
511 .procname
= "ctrl-alt-del",
513 .maxlen
= sizeof(int),
515 .proc_handler
= &proc_dointvec
,
518 .ctl_name
= KERN_PRINTK
,
519 .procname
= "printk",
520 .data
= &console_loglevel
,
521 .maxlen
= 4*sizeof(int),
523 .proc_handler
= &proc_dointvec
,
527 .ctl_name
= KERN_MODPROBE
,
528 .procname
= "modprobe",
529 .data
= &modprobe_path
,
530 .maxlen
= KMOD_PATH_LEN
,
532 .proc_handler
= &proc_dostring
,
533 .strategy
= &sysctl_string
,
536 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
538 .ctl_name
= KERN_HOTPLUG
,
539 .procname
= "hotplug",
540 .data
= &uevent_helper
,
541 .maxlen
= UEVENT_HELPER_PATH_LEN
,
543 .proc_handler
= &proc_dostring
,
544 .strategy
= &sysctl_string
,
547 #ifdef CONFIG_CHR_DEV_SG
549 .ctl_name
= KERN_SG_BIG_BUFF
,
550 .procname
= "sg-big-buff",
551 .data
= &sg_big_buff
,
552 .maxlen
= sizeof (int),
554 .proc_handler
= &proc_dointvec
,
557 #ifdef CONFIG_BSD_PROCESS_ACCT
559 .ctl_name
= KERN_ACCT
,
562 .maxlen
= 3*sizeof(int),
564 .proc_handler
= &proc_dointvec
,
567 #ifdef CONFIG_MAGIC_SYSRQ
569 .ctl_name
= KERN_SYSRQ
,
571 .data
= &__sysrq_enabled
,
572 .maxlen
= sizeof (int),
574 .proc_handler
= &proc_dointvec
,
577 #ifdef CONFIG_PROC_SYSCTL
579 .procname
= "cad_pid",
581 .maxlen
= sizeof (int),
583 .proc_handler
= &proc_do_cad_pid
,
587 .ctl_name
= KERN_MAX_THREADS
,
588 .procname
= "threads-max",
589 .data
= &max_threads
,
590 .maxlen
= sizeof(int),
592 .proc_handler
= &proc_dointvec
,
595 .ctl_name
= KERN_RANDOM
,
596 .procname
= "random",
598 .child
= random_table
,
601 .ctl_name
= KERN_OVERFLOWUID
,
602 .procname
= "overflowuid",
603 .data
= &overflowuid
,
604 .maxlen
= sizeof(int),
606 .proc_handler
= &proc_dointvec_minmax
,
607 .strategy
= &sysctl_intvec
,
608 .extra1
= &minolduid
,
609 .extra2
= &maxolduid
,
612 .ctl_name
= KERN_OVERFLOWGID
,
613 .procname
= "overflowgid",
614 .data
= &overflowgid
,
615 .maxlen
= sizeof(int),
617 .proc_handler
= &proc_dointvec_minmax
,
618 .strategy
= &sysctl_intvec
,
619 .extra1
= &minolduid
,
620 .extra2
= &maxolduid
,
623 #ifdef CONFIG_MATHEMU
625 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
626 .procname
= "ieee_emulation_warnings",
627 .data
= &sysctl_ieee_emulation_warnings
,
628 .maxlen
= sizeof(int),
630 .proc_handler
= &proc_dointvec
,
633 #ifdef CONFIG_NO_IDLE_HZ
635 .ctl_name
= KERN_HZ_TIMER
,
636 .procname
= "hz_timer",
637 .data
= &sysctl_hz_timer
,
638 .maxlen
= sizeof(int),
640 .proc_handler
= &proc_dointvec
,
644 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
645 .procname
= "userprocess_debug",
646 .data
= &sysctl_userprocess_debug
,
647 .maxlen
= sizeof(int),
649 .proc_handler
= &proc_dointvec
,
653 .ctl_name
= KERN_PIDMAX
,
654 .procname
= "pid_max",
656 .maxlen
= sizeof (int),
658 .proc_handler
= &proc_dointvec_minmax
,
659 .strategy
= sysctl_intvec
,
660 .extra1
= &pid_max_min
,
661 .extra2
= &pid_max_max
,
664 .ctl_name
= KERN_PANIC_ON_OOPS
,
665 .procname
= "panic_on_oops",
666 .data
= &panic_on_oops
,
667 .maxlen
= sizeof(int),
669 .proc_handler
= &proc_dointvec
,
672 .ctl_name
= KERN_PRINTK_RATELIMIT
,
673 .procname
= "printk_ratelimit",
674 .data
= &printk_ratelimit_jiffies
,
675 .maxlen
= sizeof(int),
677 .proc_handler
= &proc_dointvec_jiffies
,
678 .strategy
= &sysctl_jiffies
,
681 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
682 .procname
= "printk_ratelimit_burst",
683 .data
= &printk_ratelimit_burst
,
684 .maxlen
= sizeof(int),
686 .proc_handler
= &proc_dointvec
,
689 .ctl_name
= KERN_NGROUPS_MAX
,
690 .procname
= "ngroups_max",
691 .data
= &ngroups_max
,
692 .maxlen
= sizeof (int),
694 .proc_handler
= &proc_dointvec
,
696 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
698 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
699 .procname
= "unknown_nmi_panic",
700 .data
= &unknown_nmi_panic
,
701 .maxlen
= sizeof (int),
703 .proc_handler
= &proc_dointvec
,
706 .procname
= "nmi_watchdog",
707 .data
= &nmi_watchdog_enabled
,
708 .maxlen
= sizeof (int),
710 .proc_handler
= &proc_nmi_enabled
,
713 #if defined(CONFIG_X86)
715 .ctl_name
= KERN_PANIC_ON_NMI
,
716 .procname
= "panic_on_unrecovered_nmi",
717 .data
= &panic_on_unrecovered_nmi
,
718 .maxlen
= sizeof(int),
720 .proc_handler
= &proc_dointvec
,
723 .ctl_name
= KERN_BOOTLOADER_TYPE
,
724 .procname
= "bootloader_type",
725 .data
= &bootloader_type
,
726 .maxlen
= sizeof (int),
728 .proc_handler
= &proc_dointvec
,
731 .ctl_name
= CTL_UNNUMBERED
,
732 .procname
= "kstack_depth_to_print",
733 .data
= &kstack_depth_to_print
,
734 .maxlen
= sizeof(int),
736 .proc_handler
= &proc_dointvec
,
739 #if defined(CONFIG_MMU)
741 .ctl_name
= KERN_RANDOMIZE
,
742 .procname
= "randomize_va_space",
743 .data
= &randomize_va_space
,
744 .maxlen
= sizeof(int),
746 .proc_handler
= &proc_dointvec
,
749 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
751 .ctl_name
= KERN_SPIN_RETRY
,
752 .procname
= "spin_retry",
754 .maxlen
= sizeof (int),
756 .proc_handler
= &proc_dointvec
,
759 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
761 .procname
= "acpi_video_flags",
762 .data
= &acpi_realmode_flags
,
763 .maxlen
= sizeof (unsigned long),
765 .proc_handler
= &proc_doulongvec_minmax
,
770 .ctl_name
= KERN_IA64_UNALIGNED
,
771 .procname
= "ignore-unaligned-usertrap",
772 .data
= &no_unaligned_warning
,
773 .maxlen
= sizeof (int),
775 .proc_handler
= &proc_dointvec
,
778 #ifdef CONFIG_DETECT_SOFTLOCKUP
780 .ctl_name
= CTL_UNNUMBERED
,
781 .procname
= "softlockup_thresh",
782 .data
= &softlockup_thresh
,
783 .maxlen
= sizeof(unsigned long),
785 .proc_handler
= &proc_doulongvec_minmax
,
786 .strategy
= &sysctl_intvec
,
791 .ctl_name
= CTL_UNNUMBERED
,
792 .procname
= "hung_task_check_count",
793 .data
= &sysctl_hung_task_check_count
,
794 .maxlen
= sizeof(unsigned long),
796 .proc_handler
= &proc_doulongvec_minmax
,
797 .strategy
= &sysctl_intvec
,
800 .ctl_name
= CTL_UNNUMBERED
,
801 .procname
= "hung_task_timeout_secs",
802 .data
= &sysctl_hung_task_timeout_secs
,
803 .maxlen
= sizeof(unsigned long),
805 .proc_handler
= &proc_doulongvec_minmax
,
806 .strategy
= &sysctl_intvec
,
809 .ctl_name
= CTL_UNNUMBERED
,
810 .procname
= "hung_task_warnings",
811 .data
= &sysctl_hung_task_warnings
,
812 .maxlen
= sizeof(unsigned long),
814 .proc_handler
= &proc_doulongvec_minmax
,
815 .strategy
= &sysctl_intvec
,
820 .ctl_name
= KERN_COMPAT_LOG
,
821 .procname
= "compat-log",
823 .maxlen
= sizeof (int),
825 .proc_handler
= &proc_dointvec
,
828 #ifdef CONFIG_RT_MUTEXES
830 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
831 .procname
= "max_lock_depth",
832 .data
= &max_lock_depth
,
833 .maxlen
= sizeof(int),
835 .proc_handler
= &proc_dointvec
,
838 #ifdef CONFIG_PROC_FS
840 .ctl_name
= CTL_UNNUMBERED
,
841 .procname
= "maps_protect",
842 .data
= &maps_protect
,
843 .maxlen
= sizeof(int),
845 .proc_handler
= &proc_dointvec
,
849 .ctl_name
= CTL_UNNUMBERED
,
850 .procname
= "poweroff_cmd",
851 .data
= &poweroff_cmd
,
852 .maxlen
= POWEROFF_CMD_PATH_LEN
,
854 .proc_handler
= &proc_dostring
,
855 .strategy
= &sysctl_string
,
858 * NOTE: do not add new entries to this table unless you have read
859 * Documentation/sysctl/ctl_unnumbered.txt
864 static struct ctl_table vm_table
[] = {
866 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
867 .procname
= "overcommit_memory",
868 .data
= &sysctl_overcommit_memory
,
869 .maxlen
= sizeof(sysctl_overcommit_memory
),
871 .proc_handler
= &proc_dointvec
,
874 .ctl_name
= VM_PANIC_ON_OOM
,
875 .procname
= "panic_on_oom",
876 .data
= &sysctl_panic_on_oom
,
877 .maxlen
= sizeof(sysctl_panic_on_oom
),
879 .proc_handler
= &proc_dointvec
,
882 .ctl_name
= CTL_UNNUMBERED
,
883 .procname
= "oom_kill_allocating_task",
884 .data
= &sysctl_oom_kill_allocating_task
,
885 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
887 .proc_handler
= &proc_dointvec
,
890 .ctl_name
= VM_OVERCOMMIT_RATIO
,
891 .procname
= "overcommit_ratio",
892 .data
= &sysctl_overcommit_ratio
,
893 .maxlen
= sizeof(sysctl_overcommit_ratio
),
895 .proc_handler
= &proc_dointvec
,
898 .ctl_name
= VM_PAGE_CLUSTER
,
899 .procname
= "page-cluster",
900 .data
= &page_cluster
,
901 .maxlen
= sizeof(int),
903 .proc_handler
= &proc_dointvec
,
906 .ctl_name
= VM_DIRTY_BACKGROUND
,
907 .procname
= "dirty_background_ratio",
908 .data
= &dirty_background_ratio
,
909 .maxlen
= sizeof(dirty_background_ratio
),
911 .proc_handler
= &proc_dointvec_minmax
,
912 .strategy
= &sysctl_intvec
,
914 .extra2
= &one_hundred
,
917 .ctl_name
= VM_DIRTY_RATIO
,
918 .procname
= "dirty_ratio",
919 .data
= &vm_dirty_ratio
,
920 .maxlen
= sizeof(vm_dirty_ratio
),
922 .proc_handler
= &dirty_ratio_handler
,
923 .strategy
= &sysctl_intvec
,
925 .extra2
= &one_hundred
,
928 .procname
= "dirty_writeback_centisecs",
929 .data
= &dirty_writeback_interval
,
930 .maxlen
= sizeof(dirty_writeback_interval
),
932 .proc_handler
= &dirty_writeback_centisecs_handler
,
935 .procname
= "dirty_expire_centisecs",
936 .data
= &dirty_expire_interval
,
937 .maxlen
= sizeof(dirty_expire_interval
),
939 .proc_handler
= &proc_dointvec_userhz_jiffies
,
942 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
943 .procname
= "nr_pdflush_threads",
944 .data
= &nr_pdflush_threads
,
945 .maxlen
= sizeof nr_pdflush_threads
,
946 .mode
= 0444 /* read-only*/,
947 .proc_handler
= &proc_dointvec
,
950 .ctl_name
= VM_SWAPPINESS
,
951 .procname
= "swappiness",
952 .data
= &vm_swappiness
,
953 .maxlen
= sizeof(vm_swappiness
),
955 .proc_handler
= &proc_dointvec_minmax
,
956 .strategy
= &sysctl_intvec
,
958 .extra2
= &one_hundred
,
960 #ifdef CONFIG_HUGETLB_PAGE
962 .procname
= "nr_hugepages",
963 .data
= &max_huge_pages
,
964 .maxlen
= sizeof(unsigned long),
966 .proc_handler
= &hugetlb_sysctl_handler
,
967 .extra1
= (void *)&hugetlb_zero
,
968 .extra2
= (void *)&hugetlb_infinity
,
971 .ctl_name
= VM_HUGETLB_GROUP
,
972 .procname
= "hugetlb_shm_group",
973 .data
= &sysctl_hugetlb_shm_group
,
974 .maxlen
= sizeof(gid_t
),
976 .proc_handler
= &proc_dointvec
,
979 .ctl_name
= CTL_UNNUMBERED
,
980 .procname
= "hugepages_treat_as_movable",
981 .data
= &hugepages_treat_as_movable
,
982 .maxlen
= sizeof(int),
984 .proc_handler
= &hugetlb_treat_movable_handler
,
987 .ctl_name
= CTL_UNNUMBERED
,
988 .procname
= "nr_overcommit_hugepages",
989 .data
= &nr_overcommit_huge_pages
,
990 .maxlen
= sizeof(nr_overcommit_huge_pages
),
992 .proc_handler
= &proc_doulongvec_minmax
,
996 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
997 .procname
= "lowmem_reserve_ratio",
998 .data
= &sysctl_lowmem_reserve_ratio
,
999 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1001 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
1002 .strategy
= &sysctl_intvec
,
1005 .ctl_name
= VM_DROP_PAGECACHE
,
1006 .procname
= "drop_caches",
1007 .data
= &sysctl_drop_caches
,
1008 .maxlen
= sizeof(int),
1010 .proc_handler
= drop_caches_sysctl_handler
,
1011 .strategy
= &sysctl_intvec
,
1014 .ctl_name
= VM_MIN_FREE_KBYTES
,
1015 .procname
= "min_free_kbytes",
1016 .data
= &min_free_kbytes
,
1017 .maxlen
= sizeof(min_free_kbytes
),
1019 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1020 .strategy
= &sysctl_intvec
,
1024 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1025 .procname
= "percpu_pagelist_fraction",
1026 .data
= &percpu_pagelist_fraction
,
1027 .maxlen
= sizeof(percpu_pagelist_fraction
),
1029 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1030 .strategy
= &sysctl_intvec
,
1031 .extra1
= &min_percpu_pagelist_fract
,
1035 .ctl_name
= VM_MAX_MAP_COUNT
,
1036 .procname
= "max_map_count",
1037 .data
= &sysctl_max_map_count
,
1038 .maxlen
= sizeof(sysctl_max_map_count
),
1040 .proc_handler
= &proc_dointvec
1044 .ctl_name
= VM_LAPTOP_MODE
,
1045 .procname
= "laptop_mode",
1046 .data
= &laptop_mode
,
1047 .maxlen
= sizeof(laptop_mode
),
1049 .proc_handler
= &proc_dointvec_jiffies
,
1050 .strategy
= &sysctl_jiffies
,
1053 .ctl_name
= VM_BLOCK_DUMP
,
1054 .procname
= "block_dump",
1055 .data
= &block_dump
,
1056 .maxlen
= sizeof(block_dump
),
1058 .proc_handler
= &proc_dointvec
,
1059 .strategy
= &sysctl_intvec
,
1063 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1064 .procname
= "vfs_cache_pressure",
1065 .data
= &sysctl_vfs_cache_pressure
,
1066 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1068 .proc_handler
= &proc_dointvec
,
1069 .strategy
= &sysctl_intvec
,
1072 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1074 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1075 .procname
= "legacy_va_layout",
1076 .data
= &sysctl_legacy_va_layout
,
1077 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1079 .proc_handler
= &proc_dointvec
,
1080 .strategy
= &sysctl_intvec
,
1086 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1087 .procname
= "zone_reclaim_mode",
1088 .data
= &zone_reclaim_mode
,
1089 .maxlen
= sizeof(zone_reclaim_mode
),
1091 .proc_handler
= &proc_dointvec
,
1092 .strategy
= &sysctl_intvec
,
1096 .ctl_name
= VM_MIN_UNMAPPED
,
1097 .procname
= "min_unmapped_ratio",
1098 .data
= &sysctl_min_unmapped_ratio
,
1099 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1101 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1102 .strategy
= &sysctl_intvec
,
1104 .extra2
= &one_hundred
,
1107 .ctl_name
= VM_MIN_SLAB
,
1108 .procname
= "min_slab_ratio",
1109 .data
= &sysctl_min_slab_ratio
,
1110 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1112 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1113 .strategy
= &sysctl_intvec
,
1115 .extra2
= &one_hundred
,
1120 .ctl_name
= CTL_UNNUMBERED
,
1121 .procname
= "stat_interval",
1122 .data
= &sysctl_stat_interval
,
1123 .maxlen
= sizeof(sysctl_stat_interval
),
1125 .proc_handler
= &proc_dointvec_jiffies
,
1126 .strategy
= &sysctl_jiffies
,
1129 #ifdef CONFIG_SECURITY
1131 .ctl_name
= CTL_UNNUMBERED
,
1132 .procname
= "mmap_min_addr",
1133 .data
= &mmap_min_addr
,
1134 .maxlen
= sizeof(unsigned long),
1136 .proc_handler
= &proc_doulongvec_minmax
,
1141 .ctl_name
= CTL_UNNUMBERED
,
1142 .procname
= "numa_zonelist_order",
1143 .data
= &numa_zonelist_order
,
1144 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1146 .proc_handler
= &numa_zonelist_order_handler
,
1147 .strategy
= &sysctl_string
,
1150 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1151 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1153 .ctl_name
= VM_VDSO_ENABLED
,
1154 .procname
= "vdso_enabled",
1155 .data
= &vdso_enabled
,
1156 .maxlen
= sizeof(vdso_enabled
),
1158 .proc_handler
= &proc_dointvec
,
1159 .strategy
= &sysctl_intvec
,
1164 * NOTE: do not add new entries to this table unless you have read
1165 * Documentation/sysctl/ctl_unnumbered.txt
1170 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1171 static struct ctl_table binfmt_misc_table
[] = {
1176 static struct ctl_table fs_table
[] = {
1178 .ctl_name
= FS_NRINODE
,
1179 .procname
= "inode-nr",
1180 .data
= &inodes_stat
,
1181 .maxlen
= 2*sizeof(int),
1183 .proc_handler
= &proc_dointvec
,
1186 .ctl_name
= FS_STATINODE
,
1187 .procname
= "inode-state",
1188 .data
= &inodes_stat
,
1189 .maxlen
= 7*sizeof(int),
1191 .proc_handler
= &proc_dointvec
,
1194 .procname
= "file-nr",
1195 .data
= &files_stat
,
1196 .maxlen
= 3*sizeof(int),
1198 .proc_handler
= &proc_nr_files
,
1201 .ctl_name
= FS_MAXFILE
,
1202 .procname
= "file-max",
1203 .data
= &files_stat
.max_files
,
1204 .maxlen
= sizeof(int),
1206 .proc_handler
= &proc_dointvec
,
1209 .ctl_name
= FS_DENTRY
,
1210 .procname
= "dentry-state",
1211 .data
= &dentry_stat
,
1212 .maxlen
= 6*sizeof(int),
1214 .proc_handler
= &proc_dointvec
,
1217 .ctl_name
= FS_OVERFLOWUID
,
1218 .procname
= "overflowuid",
1219 .data
= &fs_overflowuid
,
1220 .maxlen
= sizeof(int),
1222 .proc_handler
= &proc_dointvec_minmax
,
1223 .strategy
= &sysctl_intvec
,
1224 .extra1
= &minolduid
,
1225 .extra2
= &maxolduid
,
1228 .ctl_name
= FS_OVERFLOWGID
,
1229 .procname
= "overflowgid",
1230 .data
= &fs_overflowgid
,
1231 .maxlen
= sizeof(int),
1233 .proc_handler
= &proc_dointvec_minmax
,
1234 .strategy
= &sysctl_intvec
,
1235 .extra1
= &minolduid
,
1236 .extra2
= &maxolduid
,
1239 .ctl_name
= FS_LEASES
,
1240 .procname
= "leases-enable",
1241 .data
= &leases_enable
,
1242 .maxlen
= sizeof(int),
1244 .proc_handler
= &proc_dointvec
,
1246 #ifdef CONFIG_DNOTIFY
1248 .ctl_name
= FS_DIR_NOTIFY
,
1249 .procname
= "dir-notify-enable",
1250 .data
= &dir_notify_enable
,
1251 .maxlen
= sizeof(int),
1253 .proc_handler
= &proc_dointvec
,
1258 .ctl_name
= FS_LEASE_TIME
,
1259 .procname
= "lease-break-time",
1260 .data
= &lease_break_time
,
1261 .maxlen
= sizeof(int),
1263 .proc_handler
= &proc_dointvec_minmax
,
1264 .strategy
= &sysctl_intvec
,
1269 .procname
= "aio-nr",
1271 .maxlen
= sizeof(aio_nr
),
1273 .proc_handler
= &proc_doulongvec_minmax
,
1276 .procname
= "aio-max-nr",
1277 .data
= &aio_max_nr
,
1278 .maxlen
= sizeof(aio_max_nr
),
1280 .proc_handler
= &proc_doulongvec_minmax
,
1282 #ifdef CONFIG_INOTIFY_USER
1284 .ctl_name
= FS_INOTIFY
,
1285 .procname
= "inotify",
1287 .child
= inotify_table
,
1292 .ctl_name
= KERN_SETUID_DUMPABLE
,
1293 .procname
= "suid_dumpable",
1294 .data
= &suid_dumpable
,
1295 .maxlen
= sizeof(int),
1297 .proc_handler
= &proc_dointvec
,
1299 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1301 .ctl_name
= CTL_UNNUMBERED
,
1302 .procname
= "binfmt_misc",
1304 .child
= binfmt_misc_table
,
1308 * NOTE: do not add new entries to this table unless you have read
1309 * Documentation/sysctl/ctl_unnumbered.txt
1314 static struct ctl_table debug_table
[] = {
1315 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1317 .ctl_name
= CTL_UNNUMBERED
,
1318 .procname
= "exception-trace",
1319 .data
= &show_unhandled_signals
,
1320 .maxlen
= sizeof(int),
1322 .proc_handler
= proc_dointvec
1328 static struct ctl_table dev_table
[] = {
1332 static DEFINE_SPINLOCK(sysctl_lock
);
1334 /* called under sysctl_lock */
1335 static int use_table(struct ctl_table_header
*p
)
1337 if (unlikely(p
->unregistering
))
1343 /* called under sysctl_lock */
1344 static void unuse_table(struct ctl_table_header
*p
)
1347 if (unlikely(p
->unregistering
))
1348 complete(p
->unregistering
);
1351 /* called under sysctl_lock, will reacquire if has to wait */
1352 static void start_unregistering(struct ctl_table_header
*p
)
1355 * if p->used is 0, nobody will ever touch that entry again;
1356 * we'll eliminate all paths to it before dropping sysctl_lock
1358 if (unlikely(p
->used
)) {
1359 struct completion wait
;
1360 init_completion(&wait
);
1361 p
->unregistering
= &wait
;
1362 spin_unlock(&sysctl_lock
);
1363 wait_for_completion(&wait
);
1364 spin_lock(&sysctl_lock
);
1367 * do not remove from the list until nobody holds it; walking the
1368 * list in do_sysctl() relies on that.
1370 list_del_init(&p
->ctl_entry
);
1373 void sysctl_head_finish(struct ctl_table_header
*head
)
1377 spin_lock(&sysctl_lock
);
1379 spin_unlock(&sysctl_lock
);
1382 static struct list_head
*
1383 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1385 struct list_head
*header_list
;
1386 header_list
= &root
->header_list
;
1388 header_list
= root
->lookup(root
, namespaces
);
1392 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1393 struct ctl_table_header
*prev
)
1395 struct ctl_table_root
*root
;
1396 struct list_head
*header_list
;
1397 struct ctl_table_header
*head
;
1398 struct list_head
*tmp
;
1400 spin_lock(&sysctl_lock
);
1403 tmp
= &prev
->ctl_entry
;
1407 tmp
= &root_table_header
.ctl_entry
;
1409 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1411 if (!use_table(head
))
1413 spin_unlock(&sysctl_lock
);
1418 header_list
= lookup_header_list(root
, namespaces
);
1419 if (tmp
!= header_list
)
1423 root
= list_entry(root
->root_list
.next
,
1424 struct ctl_table_root
, root_list
);
1425 if (root
== &sysctl_table_root
)
1427 header_list
= lookup_header_list(root
, namespaces
);
1428 } while (list_empty(header_list
));
1429 tmp
= header_list
->next
;
1432 spin_unlock(&sysctl_lock
);
1436 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1438 return __sysctl_head_next(current
->nsproxy
, prev
);
1441 void register_sysctl_root(struct ctl_table_root
*root
)
1443 spin_lock(&sysctl_lock
);
1444 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1445 spin_unlock(&sysctl_lock
);
1448 #ifdef CONFIG_SYSCTL_SYSCALL
1449 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1450 void __user
*newval
, size_t newlen
)
1452 struct ctl_table_header
*head
;
1453 int error
= -ENOTDIR
;
1455 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1459 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1463 for (head
= sysctl_head_next(NULL
); head
;
1464 head
= sysctl_head_next(head
)) {
1465 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1466 newval
, newlen
, head
->ctl_table
);
1467 if (error
!= -ENOTDIR
) {
1468 sysctl_head_finish(head
);
1475 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1477 struct __sysctl_args tmp
;
1480 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1483 error
= deprecated_sysctl_warning(&tmp
);
1488 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1489 tmp
.newval
, tmp
.newlen
);
1494 #endif /* CONFIG_SYSCTL_SYSCALL */
1497 * sysctl_perm does NOT grant the superuser all rights automatically, because
1498 * some sysctl variables are readonly even to root.
1501 static int test_perm(int mode
, int op
)
1505 else if (in_egroup_p(0))
1507 if ((mode
& op
& 0007) == op
)
1512 int sysctl_perm(struct ctl_table
*table
, int op
)
1515 error
= security_sysctl(table
, op
);
1518 return test_perm(table
->mode
, op
);
1521 #ifdef CONFIG_SYSCTL_SYSCALL
1522 static int parse_table(int __user
*name
, int nlen
,
1523 void __user
*oldval
, size_t __user
*oldlenp
,
1524 void __user
*newval
, size_t newlen
,
1525 struct ctl_table
*table
)
1531 if (get_user(n
, name
))
1533 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1534 if (!table
->ctl_name
)
1536 if (n
== table
->ctl_name
) {
1539 if (sysctl_perm(table
, 001))
1543 table
= table
->child
;
1546 error
= do_sysctl_strategy(table
, name
, nlen
,
1555 /* Perform the actual read/write of a sysctl table entry. */
1556 int do_sysctl_strategy (struct ctl_table
*table
,
1557 int __user
*name
, int nlen
,
1558 void __user
*oldval
, size_t __user
*oldlenp
,
1559 void __user
*newval
, size_t newlen
)
1567 if (sysctl_perm(table
, op
))
1570 if (table
->strategy
) {
1571 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1579 /* If there is no strategy routine, or if the strategy returns
1580 * zero, proceed with automatic r/w */
1581 if (table
->data
&& table
->maxlen
) {
1582 rc
= sysctl_data(table
, name
, nlen
, oldval
, oldlenp
,
1589 #endif /* CONFIG_SYSCTL_SYSCALL */
1591 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1593 for (; table
->ctl_name
|| table
->procname
; table
++) {
1594 table
->parent
= parent
;
1596 sysctl_set_parent(table
, table
->child
);
1600 static __init
int sysctl_init(void)
1603 sysctl_set_parent(NULL
, root_table
);
1604 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1608 core_initcall(sysctl_init
);
1611 * __register_sysctl_paths - register a sysctl hierarchy
1612 * @root: List of sysctl headers to register on
1613 * @namespaces: Data to compute which lists of sysctl entries are visible
1614 * @path: The path to the directory the sysctl table is in.
1615 * @table: the top-level table structure
1617 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1618 * array. A completely 0 filled entry terminates the table.
1620 * The members of the &struct ctl_table structure are used as follows:
1622 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1623 * must be unique within that level of sysctl
1625 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1626 * enter a sysctl file
1628 * data - a pointer to data for use by proc_handler
1630 * maxlen - the maximum size in bytes of the data
1632 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1634 * child - a pointer to the child sysctl table if this entry is a directory, or
1637 * proc_handler - the text handler routine (described below)
1639 * strategy - the strategy routine (described below)
1641 * de - for internal use by the sysctl routines
1643 * extra1, extra2 - extra pointers usable by the proc handler routines
1645 * Leaf nodes in the sysctl tree will be represented by a single file
1646 * under /proc; non-leaf nodes will be represented by directories.
1648 * sysctl(2) can automatically manage read and write requests through
1649 * the sysctl table. The data and maxlen fields of the ctl_table
1650 * struct enable minimal validation of the values being written to be
1651 * performed, and the mode field allows minimal authentication.
1653 * More sophisticated management can be enabled by the provision of a
1654 * strategy routine with the table entry. This will be called before
1655 * any automatic read or write of the data is performed.
1657 * The strategy routine may return
1659 * < 0 - Error occurred (error is passed to user process)
1661 * 0 - OK - proceed with automatic read or write.
1663 * > 0 - OK - read or write has been done by the strategy routine, so
1664 * return immediately.
1666 * There must be a proc_handler routine for any terminal nodes
1667 * mirrored under /proc/sys (non-terminals are handled by a built-in
1668 * directory handler). Several default handlers are available to
1669 * cover common cases -
1671 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1672 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1673 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1675 * It is the handler's job to read the input buffer from user memory
1676 * and process it. The handler should return 0 on success.
1678 * This routine returns %NULL on a failure to register, and a pointer
1679 * to the table header on success.
1681 struct ctl_table_header
*__register_sysctl_paths(
1682 struct ctl_table_root
*root
,
1683 struct nsproxy
*namespaces
,
1684 const struct ctl_path
*path
, struct ctl_table
*table
)
1686 struct list_head
*header_list
;
1687 struct ctl_table_header
*header
;
1688 struct ctl_table
*new, **prevp
;
1689 unsigned int n
, npath
;
1691 /* Count the path components */
1692 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
1696 * For each path component, allocate a 2-element ctl_table array.
1697 * The first array element will be filled with the sysctl entry
1698 * for this, the second will be the sentinel (ctl_name == 0).
1700 * We allocate everything in one go so that we don't have to
1701 * worry about freeing additional memory in unregister_sysctl_table.
1703 header
= kzalloc(sizeof(struct ctl_table_header
) +
1704 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1708 new = (struct ctl_table
*) (header
+ 1);
1710 /* Now connect the dots */
1711 prevp
= &header
->ctl_table
;
1712 for (n
= 0; n
< npath
; ++n
, ++path
) {
1713 /* Copy the procname */
1714 new->procname
= path
->procname
;
1715 new->ctl_name
= path
->ctl_name
;
1719 prevp
= &new->child
;
1724 header
->ctl_table_arg
= table
;
1726 INIT_LIST_HEAD(&header
->ctl_entry
);
1728 header
->unregistering
= NULL
;
1729 header
->root
= root
;
1730 sysctl_set_parent(NULL
, header
->ctl_table
);
1731 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1735 spin_lock(&sysctl_lock
);
1736 header_list
= lookup_header_list(root
, namespaces
);
1737 list_add_tail(&header
->ctl_entry
, header_list
);
1738 spin_unlock(&sysctl_lock
);
1744 * register_sysctl_table_path - register a sysctl table hierarchy
1745 * @path: The path to the directory the sysctl table is in.
1746 * @table: the top-level table structure
1748 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1749 * array. A completely 0 filled entry terminates the table.
1751 * See __register_sysctl_paths for more details.
1753 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1754 struct ctl_table
*table
)
1756 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1761 * register_sysctl_table - register a sysctl table hierarchy
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_table(struct ctl_table
*table
)
1771 static const struct ctl_path null_path
[] = { {} };
1773 return register_sysctl_paths(null_path
, table
);
1777 * unregister_sysctl_table - unregister a sysctl table hierarchy
1778 * @header: the header returned from register_sysctl_table
1780 * Unregisters the sysctl table and all children. proc entries may not
1781 * actually be removed until they are no longer used by anyone.
1783 void unregister_sysctl_table(struct ctl_table_header
* header
)
1790 spin_lock(&sysctl_lock
);
1791 start_unregistering(header
);
1792 spin_unlock(&sysctl_lock
);
1796 #else /* !CONFIG_SYSCTL */
1797 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1802 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1803 struct ctl_table
*table
)
1808 void unregister_sysctl_table(struct ctl_table_header
* table
)
1812 #endif /* CONFIG_SYSCTL */
1818 #ifdef CONFIG_PROC_SYSCTL
1820 static int _proc_do_string(void* data
, int maxlen
, int write
,
1821 struct file
*filp
, void __user
*buffer
,
1822 size_t *lenp
, loff_t
*ppos
)
1828 if (!data
|| !maxlen
|| !*lenp
) {
1836 while (len
< *lenp
) {
1837 if (get_user(c
, p
++))
1839 if (c
== 0 || c
== '\n')
1845 if(copy_from_user(data
, buffer
, len
))
1847 ((char *) data
)[len
] = 0;
1865 if(copy_to_user(buffer
, data
, len
))
1868 if(put_user('\n', ((char __user
*) buffer
) + len
))
1879 * proc_dostring - read a string sysctl
1880 * @table: the sysctl table
1881 * @write: %TRUE if this is a write to the sysctl file
1882 * @filp: the file structure
1883 * @buffer: the user buffer
1884 * @lenp: the size of the user buffer
1885 * @ppos: file position
1887 * Reads/writes a string from/to the user buffer. If the kernel
1888 * buffer provided is not large enough to hold the string, the
1889 * string is truncated. The copied string is %NULL-terminated.
1890 * If the string is being read by the user process, it is copied
1891 * and a newline '\n' is added. It is truncated if the buffer is
1894 * Returns 0 on success.
1896 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
1897 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1899 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
1900 buffer
, lenp
, ppos
);
1904 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1906 int write
, void *data
)
1909 *valp
= *negp
? -*lvalp
: *lvalp
;
1914 *lvalp
= (unsigned long)-val
;
1917 *lvalp
= (unsigned long)val
;
1923 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1924 int write
, struct file
*filp
, void __user
*buffer
,
1925 size_t *lenp
, loff_t
*ppos
,
1926 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1927 int write
, void *data
),
1930 #define TMPBUFLEN 21
1931 int *i
, vleft
, first
=1, neg
, val
;
1935 char buf
[TMPBUFLEN
], *p
;
1936 char __user
*s
= buffer
;
1938 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
1939 (*ppos
&& !write
)) {
1944 i
= (int *) tbl_data
;
1945 vleft
= table
->maxlen
/ sizeof(*i
);
1949 conv
= do_proc_dointvec_conv
;
1951 for (; left
&& vleft
--; i
++, first
=0) {
1966 if (len
> sizeof(buf
) - 1)
1967 len
= sizeof(buf
) - 1;
1968 if (copy_from_user(buf
, s
, len
))
1972 if (*p
== '-' && left
> 1) {
1976 if (*p
< '0' || *p
> '9')
1979 lval
= simple_strtoul(p
, &p
, 0);
1982 if ((len
< left
) && *p
&& !isspace(*p
))
1989 if (conv(&neg
, &lval
, i
, 1, data
))
1996 if (conv(&neg
, &lval
, i
, 0, data
))
1999 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2003 if(copy_to_user(s
, buf
, len
))
2010 if (!write
&& !first
&& left
) {
2011 if(put_user('\n', s
))
2018 if (get_user(c
, s
++))
2033 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2034 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2035 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2036 int write
, void *data
),
2039 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2040 buffer
, lenp
, ppos
, conv
, data
);
2044 * proc_dointvec - read a vector of integers
2045 * @table: the sysctl table
2046 * @write: %TRUE if this is a write to the sysctl file
2047 * @filp: the file structure
2048 * @buffer: the user buffer
2049 * @lenp: the size of the user buffer
2050 * @ppos: file position
2052 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2053 * values from/to the user buffer, treated as an ASCII string.
2055 * Returns 0 on success.
2057 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2058 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2060 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2068 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
2070 int write
, void *data
)
2072 int op
= *(int *)data
;
2074 int val
= *negp
? -*lvalp
: *lvalp
;
2076 case OP_SET
: *valp
= val
; break;
2077 case OP_AND
: *valp
&= val
; break;
2078 case OP_OR
: *valp
|= val
; break;
2084 *lvalp
= (unsigned long)-val
;
2087 *lvalp
= (unsigned long)val
;
2093 #ifdef CONFIG_SECURITY_CAPABILITIES
2095 * init may raise the set.
2098 int proc_dointvec_bset(struct ctl_table
*table
, int write
, struct file
*filp
,
2099 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2103 if (write
&& !capable(CAP_SYS_MODULE
)) {
2107 op
= is_global_init(current
) ? OP_SET
: OP_AND
;
2108 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2109 do_proc_dointvec_bset_conv
,&op
);
2111 #endif /* def CONFIG_SECURITY_CAPABILITIES */
2114 * Taint values can only be increased
2116 static int proc_dointvec_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2117 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2121 if (write
&& !capable(CAP_SYS_ADMIN
))
2125 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2126 do_proc_dointvec_bset_conv
,&op
);
2129 struct do_proc_dointvec_minmax_conv_param
{
2134 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2136 int write
, void *data
)
2138 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2140 int val
= *negp
? -*lvalp
: *lvalp
;
2141 if ((param
->min
&& *param
->min
> val
) ||
2142 (param
->max
&& *param
->max
< val
))
2149 *lvalp
= (unsigned long)-val
;
2152 *lvalp
= (unsigned long)val
;
2159 * proc_dointvec_minmax - read a vector of integers with min/max values
2160 * @table: the sysctl table
2161 * @write: %TRUE if this is a write to the sysctl file
2162 * @filp: the file structure
2163 * @buffer: the user buffer
2164 * @lenp: the size of the user buffer
2165 * @ppos: file position
2167 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2168 * values from/to the user buffer, treated as an ASCII string.
2170 * This routine will ensure the values are within the range specified by
2171 * table->extra1 (min) and table->extra2 (max).
2173 * Returns 0 on success.
2175 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2176 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2178 struct do_proc_dointvec_minmax_conv_param param
= {
2179 .min
= (int *) table
->extra1
,
2180 .max
= (int *) table
->extra2
,
2182 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2183 do_proc_dointvec_minmax_conv
, ¶m
);
2186 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2188 void __user
*buffer
,
2189 size_t *lenp
, loff_t
*ppos
,
2190 unsigned long convmul
,
2191 unsigned long convdiv
)
2193 #define TMPBUFLEN 21
2194 unsigned long *i
, *min
, *max
, val
;
2195 int vleft
, first
=1, neg
;
2197 char buf
[TMPBUFLEN
], *p
;
2198 char __user
*s
= buffer
;
2200 if (!data
|| !table
->maxlen
|| !*lenp
||
2201 (*ppos
&& !write
)) {
2206 i
= (unsigned long *) data
;
2207 min
= (unsigned long *) table
->extra1
;
2208 max
= (unsigned long *) table
->extra2
;
2209 vleft
= table
->maxlen
/ sizeof(unsigned long);
2212 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2227 if (len
> TMPBUFLEN
-1)
2229 if (copy_from_user(buf
, s
, len
))
2233 if (*p
== '-' && left
> 1) {
2237 if (*p
< '0' || *p
> '9')
2239 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2241 if ((len
< left
) && *p
&& !isspace(*p
))
2250 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2257 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2261 if(copy_to_user(s
, buf
, len
))
2268 if (!write
&& !first
&& left
) {
2269 if(put_user('\n', s
))
2276 if (get_user(c
, s
++))
2291 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2293 void __user
*buffer
,
2294 size_t *lenp
, loff_t
*ppos
,
2295 unsigned long convmul
,
2296 unsigned long convdiv
)
2298 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2299 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2303 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2304 * @table: the sysctl table
2305 * @write: %TRUE if this is a write to the sysctl file
2306 * @filp: the file structure
2307 * @buffer: the user buffer
2308 * @lenp: the size of the user buffer
2309 * @ppos: file position
2311 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2312 * values from/to the user buffer, treated as an ASCII string.
2314 * This routine will ensure the values are within the range specified by
2315 * table->extra1 (min) and table->extra2 (max).
2317 * Returns 0 on success.
2319 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2320 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2322 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2326 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2327 * @table: the sysctl table
2328 * @write: %TRUE if this is a write to the sysctl file
2329 * @filp: the file structure
2330 * @buffer: the user buffer
2331 * @lenp: the size of the user buffer
2332 * @ppos: file position
2334 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2335 * values from/to the user buffer, treated as an ASCII string. The values
2336 * are treated as milliseconds, and converted to jiffies when they are stored.
2338 * This routine will ensure the values are within the range specified by
2339 * table->extra1 (min) and table->extra2 (max).
2341 * Returns 0 on success.
2343 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2345 void __user
*buffer
,
2346 size_t *lenp
, loff_t
*ppos
)
2348 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2349 lenp
, ppos
, HZ
, 1000l);
2353 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2355 int write
, void *data
)
2358 if (*lvalp
> LONG_MAX
/ HZ
)
2360 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2366 lval
= (unsigned long)-val
;
2369 lval
= (unsigned long)val
;
2376 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2378 int write
, void *data
)
2381 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2383 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2389 lval
= (unsigned long)-val
;
2392 lval
= (unsigned long)val
;
2394 *lvalp
= jiffies_to_clock_t(lval
);
2399 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2401 int write
, void *data
)
2404 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2410 lval
= (unsigned long)-val
;
2413 lval
= (unsigned long)val
;
2415 *lvalp
= jiffies_to_msecs(lval
);
2421 * proc_dointvec_jiffies - read a vector of integers as seconds
2422 * @table: the sysctl table
2423 * @write: %TRUE if this is a write to the sysctl file
2424 * @filp: the file structure
2425 * @buffer: the user buffer
2426 * @lenp: the size of the user buffer
2427 * @ppos: file position
2429 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2430 * values from/to the user buffer, treated as an ASCII string.
2431 * The values read are assumed to be in seconds, and are converted into
2434 * Returns 0 on success.
2436 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2437 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2439 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2440 do_proc_dointvec_jiffies_conv
,NULL
);
2444 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2445 * @table: the sysctl table
2446 * @write: %TRUE if this is a write to the sysctl file
2447 * @filp: the file structure
2448 * @buffer: the user buffer
2449 * @lenp: the size of the user buffer
2450 * @ppos: pointer to the file position
2452 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2453 * values from/to the user buffer, treated as an ASCII string.
2454 * The values read are assumed to be in 1/USER_HZ seconds, and
2455 * are converted into jiffies.
2457 * Returns 0 on success.
2459 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2460 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2462 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2463 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2467 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2468 * @table: the sysctl table
2469 * @write: %TRUE if this is a write to the sysctl file
2470 * @filp: the file structure
2471 * @buffer: the user buffer
2472 * @lenp: the size of the user buffer
2473 * @ppos: file position
2474 * @ppos: the current position in the file
2476 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2477 * values from/to the user buffer, treated as an ASCII string.
2478 * The values read are assumed to be in 1/1000 seconds, and
2479 * are converted into jiffies.
2481 * Returns 0 on success.
2483 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2484 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2486 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2487 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2490 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2491 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2493 struct pid
*new_pid
;
2497 tmp
= pid_nr_ns(cad_pid
, current
->nsproxy
->pid_ns
);
2499 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2500 lenp
, ppos
, NULL
, NULL
);
2504 new_pid
= find_get_pid(tmp
);
2508 put_pid(xchg(&cad_pid
, new_pid
));
2512 #else /* CONFIG_PROC_FS */
2514 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2515 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2520 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2521 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2526 int proc_dointvec_bset(struct ctl_table
*table
, int write
, struct file
*filp
,
2527 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2532 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2533 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2538 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2539 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2544 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2545 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2550 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2551 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2556 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2557 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2562 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2564 void __user
*buffer
,
2565 size_t *lenp
, loff_t
*ppos
)
2571 #endif /* CONFIG_PROC_FS */
2574 #ifdef CONFIG_SYSCTL_SYSCALL
2576 * General sysctl support routines
2579 /* The generic sysctl data routine (used if no strategy routine supplied) */
2580 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2581 void __user
*oldval
, size_t __user
*oldlenp
,
2582 void __user
*newval
, size_t newlen
)
2586 /* Get out of I don't have a variable */
2587 if (!table
->data
|| !table
->maxlen
)
2590 if (oldval
&& oldlenp
) {
2591 if (get_user(len
, oldlenp
))
2594 if (len
> table
->maxlen
)
2595 len
= table
->maxlen
;
2596 if (copy_to_user(oldval
, table
->data
, len
))
2598 if (put_user(len
, oldlenp
))
2603 if (newval
&& newlen
) {
2604 if (newlen
> table
->maxlen
)
2605 newlen
= table
->maxlen
;
2607 if (copy_from_user(table
->data
, newval
, newlen
))
2613 /* The generic string strategy routine: */
2614 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2615 void __user
*oldval
, size_t __user
*oldlenp
,
2616 void __user
*newval
, size_t newlen
)
2618 if (!table
->data
|| !table
->maxlen
)
2621 if (oldval
&& oldlenp
) {
2623 if (get_user(bufsize
, oldlenp
))
2626 size_t len
= strlen(table
->data
), copied
;
2628 /* This shouldn't trigger for a well-formed sysctl */
2629 if (len
> table
->maxlen
)
2630 len
= table
->maxlen
;
2632 /* Copy up to a max of bufsize-1 bytes of the string */
2633 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2635 if (copy_to_user(oldval
, table
->data
, copied
) ||
2636 put_user(0, (char __user
*)(oldval
+ copied
)))
2638 if (put_user(len
, oldlenp
))
2642 if (newval
&& newlen
) {
2643 size_t len
= newlen
;
2644 if (len
> table
->maxlen
)
2645 len
= table
->maxlen
;
2646 if(copy_from_user(table
->data
, newval
, len
))
2648 if (len
== table
->maxlen
)
2650 ((char *) table
->data
)[len
] = 0;
2656 * This function makes sure that all of the integers in the vector
2657 * are between the minimum and maximum values given in the arrays
2658 * table->extra1 and table->extra2, respectively.
2660 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2661 void __user
*oldval
, size_t __user
*oldlenp
,
2662 void __user
*newval
, size_t newlen
)
2665 if (newval
&& newlen
) {
2666 int __user
*vec
= (int __user
*) newval
;
2667 int *min
= (int *) table
->extra1
;
2668 int *max
= (int *) table
->extra2
;
2672 if (newlen
% sizeof(int) != 0)
2675 if (!table
->extra1
&& !table
->extra2
)
2678 if (newlen
> table
->maxlen
)
2679 newlen
= table
->maxlen
;
2680 length
= newlen
/ sizeof(int);
2682 for (i
= 0; i
< length
; i
++) {
2684 if (get_user(value
, vec
+ i
))
2686 if (min
&& value
< min
[i
])
2688 if (max
&& value
> max
[i
])
2695 /* Strategy function to convert jiffies to seconds */
2696 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2697 void __user
*oldval
, size_t __user
*oldlenp
,
2698 void __user
*newval
, size_t newlen
)
2700 if (oldval
&& oldlenp
) {
2703 if (get_user(olen
, oldlenp
))
2708 if (olen
< sizeof(int))
2711 val
= *(int *)(table
->data
) / HZ
;
2712 if (put_user(val
, (int __user
*)oldval
))
2714 if (put_user(sizeof(int), oldlenp
))
2718 if (newval
&& newlen
) {
2720 if (newlen
!= sizeof(int))
2722 if (get_user(new, (int __user
*)newval
))
2724 *(int *)(table
->data
) = new*HZ
;
2729 /* Strategy function to convert jiffies to seconds */
2730 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2731 void __user
*oldval
, size_t __user
*oldlenp
,
2732 void __user
*newval
, size_t newlen
)
2734 if (oldval
&& oldlenp
) {
2737 if (get_user(olen
, oldlenp
))
2742 if (olen
< sizeof(int))
2745 val
= jiffies_to_msecs(*(int *)(table
->data
));
2746 if (put_user(val
, (int __user
*)oldval
))
2748 if (put_user(sizeof(int), oldlenp
))
2752 if (newval
&& newlen
) {
2754 if (newlen
!= sizeof(int))
2756 if (get_user(new, (int __user
*)newval
))
2758 *(int *)(table
->data
) = msecs_to_jiffies(new);
2765 #else /* CONFIG_SYSCTL_SYSCALL */
2768 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2770 struct __sysctl_args tmp
;
2773 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
2776 error
= deprecated_sysctl_warning(&tmp
);
2778 /* If no error reading the parameters then just -ENOSYS ... */
2785 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2786 void __user
*oldval
, size_t __user
*oldlenp
,
2787 void __user
*newval
, size_t newlen
)
2792 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2793 void __user
*oldval
, size_t __user
*oldlenp
,
2794 void __user
*newval
, size_t newlen
)
2799 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2800 void __user
*oldval
, size_t __user
*oldlenp
,
2801 void __user
*newval
, size_t newlen
)
2806 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2807 void __user
*oldval
, size_t __user
*oldlenp
,
2808 void __user
*newval
, size_t newlen
)
2813 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2814 void __user
*oldval
, size_t __user
*oldlenp
,
2815 void __user
*newval
, size_t newlen
)
2820 #endif /* CONFIG_SYSCTL_SYSCALL */
2822 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
2824 static int msg_count
;
2825 int name
[CTL_MAXNAME
];
2828 /* Check args->nlen. */
2829 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
2832 /* Read in the sysctl name for better debug message logging */
2833 for (i
= 0; i
< args
->nlen
; i
++)
2834 if (get_user(name
[i
], args
->name
+ i
))
2837 /* Ignore accesses to kernel.version */
2838 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
2841 if (msg_count
< 5) {
2844 "warning: process `%s' used the deprecated sysctl "
2845 "system call with ", current
->comm
);
2846 for (i
= 0; i
< args
->nlen
; i
++)
2847 printk("%d.", name
[i
]);
2854 * No sense putting this after each symbol definition, twice,
2855 * exception granted :-)
2857 EXPORT_SYMBOL(proc_dointvec
);
2858 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2859 EXPORT_SYMBOL(proc_dointvec_minmax
);
2860 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2861 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2862 EXPORT_SYMBOL(proc_dostring
);
2863 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2864 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2865 EXPORT_SYMBOL(register_sysctl_table
);
2866 EXPORT_SYMBOL(register_sysctl_paths
);
2867 EXPORT_SYMBOL(sysctl_intvec
);
2868 EXPORT_SYMBOL(sysctl_jiffies
);
2869 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2870 EXPORT_SYMBOL(sysctl_string
);
2871 EXPORT_SYMBOL(sysctl_data
);
2872 EXPORT_SYMBOL(unregister_sysctl_table
);