2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/proc_fs.h>
27 #include <linux/security.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/hugetlb.h>
40 #include <linux/initrd.h>
41 #include <linux/key.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/vmstat.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/acpi.h>
49 #include <linux/reboot.h>
50 #include <linux/ftrace.h>
52 #include <asm/uaccess.h>
53 #include <asm/processor.h>
57 #include <asm/stacktrace.h>
61 static int deprecated_sysctl_warning(struct __sysctl_args
*args
);
63 #if defined(CONFIG_SYSCTL)
65 /* External variables not in a header file. */
67 extern int print_fatal_signals
;
68 extern int sysctl_overcommit_memory
;
69 extern int sysctl_overcommit_ratio
;
70 extern int sysctl_panic_on_oom
;
71 extern int sysctl_oom_kill_allocating_task
;
72 extern int sysctl_oom_dump_tasks
;
73 extern int max_threads
;
74 extern int core_uses_pid
;
75 extern int suid_dumpable
;
76 extern char core_pattern
[];
78 extern int min_free_kbytes
;
79 extern int pid_max_min
, pid_max_max
;
80 extern int sysctl_drop_caches
;
81 extern int percpu_pagelist_fraction
;
82 extern int compat_log
;
83 extern int latencytop_enabled
;
84 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
85 #ifdef CONFIG_RCU_TORTURE_TEST
86 extern int rcutorture_runnable
;
87 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
89 /* Constants used for minimum and maximum */
90 #if defined(CONFIG_HIGHMEM) || defined(CONFIG_DETECT_SOFTLOCKUP)
94 #ifdef CONFIG_DETECT_SOFTLOCKUP
95 static int sixty
= 60;
96 static int neg_one
= -1;
99 #if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING)
104 static int one_hundred
= 100;
106 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
107 static int maxolduid
= 65535;
108 static int minolduid
;
109 static int min_percpu_pagelist_fract
= 8;
111 static int ngroups_max
= NGROUPS_MAX
;
113 #ifdef CONFIG_MODULES
114 extern char modprobe_path
[];
116 #ifdef CONFIG_CHR_DEV_SG
117 extern int sg_big_buff
;
121 #include <asm/system.h>
125 extern int pwrsw_enabled
;
126 extern int unaligned_enabled
;
130 #ifdef CONFIG_MATHEMU
131 extern int sysctl_ieee_emulation_warnings
;
133 extern int sysctl_userprocess_debug
;
134 extern int spin_retry
;
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_PROC_SYSCTL
150 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
151 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
152 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
153 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
156 static struct ctl_table root_table
[];
157 static struct ctl_table_root sysctl_table_root
;
158 static struct ctl_table_header root_table_header
= {
160 .ctl_table
= root_table
,
161 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),
162 .root
= &sysctl_table_root
,
163 .set
= &sysctl_table_root
.default_set
,
165 static struct ctl_table_root sysctl_table_root
= {
166 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
167 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
170 static struct ctl_table kern_table
[];
171 static struct ctl_table vm_table
[];
172 static struct ctl_table fs_table
[];
173 static struct ctl_table debug_table
[];
174 static struct ctl_table dev_table
[];
175 extern struct ctl_table random_table
[];
176 #ifdef CONFIG_INOTIFY_USER
177 extern struct ctl_table inotify_table
[];
180 extern struct ctl_table epoll_table
[];
183 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
184 int sysctl_legacy_va_layout
;
187 extern int prove_locking
;
188 extern int lock_stat
;
190 /* The default sysctl tables: */
192 static struct ctl_table root_table
[] = {
194 .ctl_name
= CTL_KERN
,
195 .procname
= "kernel",
212 .ctl_name
= CTL_DEBUG
,
215 .child
= debug_table
,
224 * NOTE: do not add new entries to this table unless you have read
225 * Documentation/sysctl/ctl_unnumbered.txt
230 #ifdef CONFIG_SCHED_DEBUG
231 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
232 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
233 static int min_wakeup_granularity_ns
; /* 0 usecs */
234 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
237 static struct ctl_table kern_table
[] = {
238 #ifdef CONFIG_SCHED_DEBUG
240 .ctl_name
= CTL_UNNUMBERED
,
241 .procname
= "sched_min_granularity_ns",
242 .data
= &sysctl_sched_min_granularity
,
243 .maxlen
= sizeof(unsigned int),
245 .proc_handler
= &sched_nr_latency_handler
,
246 .strategy
= &sysctl_intvec
,
247 .extra1
= &min_sched_granularity_ns
,
248 .extra2
= &max_sched_granularity_ns
,
251 .ctl_name
= CTL_UNNUMBERED
,
252 .procname
= "sched_latency_ns",
253 .data
= &sysctl_sched_latency
,
254 .maxlen
= sizeof(unsigned int),
256 .proc_handler
= &sched_nr_latency_handler
,
257 .strategy
= &sysctl_intvec
,
258 .extra1
= &min_sched_granularity_ns
,
259 .extra2
= &max_sched_granularity_ns
,
262 .ctl_name
= CTL_UNNUMBERED
,
263 .procname
= "sched_wakeup_granularity_ns",
264 .data
= &sysctl_sched_wakeup_granularity
,
265 .maxlen
= sizeof(unsigned int),
267 .proc_handler
= &proc_dointvec_minmax
,
268 .strategy
= &sysctl_intvec
,
269 .extra1
= &min_wakeup_granularity_ns
,
270 .extra2
= &max_wakeup_granularity_ns
,
273 .ctl_name
= CTL_UNNUMBERED
,
274 .procname
= "sched_shares_ratelimit",
275 .data
= &sysctl_sched_shares_ratelimit
,
276 .maxlen
= sizeof(unsigned int),
278 .proc_handler
= &proc_dointvec
,
281 .ctl_name
= CTL_UNNUMBERED
,
282 .procname
= "sched_shares_thresh",
283 .data
= &sysctl_sched_shares_thresh
,
284 .maxlen
= sizeof(unsigned int),
286 .proc_handler
= &proc_dointvec_minmax
,
287 .strategy
= &sysctl_intvec
,
291 .ctl_name
= CTL_UNNUMBERED
,
292 .procname
= "sched_child_runs_first",
293 .data
= &sysctl_sched_child_runs_first
,
294 .maxlen
= sizeof(unsigned int),
296 .proc_handler
= &proc_dointvec
,
299 .ctl_name
= CTL_UNNUMBERED
,
300 .procname
= "sched_features",
301 .data
= &sysctl_sched_features
,
302 .maxlen
= sizeof(unsigned int),
304 .proc_handler
= &proc_dointvec
,
307 .ctl_name
= CTL_UNNUMBERED
,
308 .procname
= "sched_migration_cost",
309 .data
= &sysctl_sched_migration_cost
,
310 .maxlen
= sizeof(unsigned int),
312 .proc_handler
= &proc_dointvec
,
315 .ctl_name
= CTL_UNNUMBERED
,
316 .procname
= "sched_nr_migrate",
317 .data
= &sysctl_sched_nr_migrate
,
318 .maxlen
= sizeof(unsigned int),
320 .proc_handler
= &proc_dointvec
,
324 .ctl_name
= CTL_UNNUMBERED
,
325 .procname
= "sched_rt_period_us",
326 .data
= &sysctl_sched_rt_period
,
327 .maxlen
= sizeof(unsigned int),
329 .proc_handler
= &sched_rt_handler
,
332 .ctl_name
= CTL_UNNUMBERED
,
333 .procname
= "sched_rt_runtime_us",
334 .data
= &sysctl_sched_rt_runtime
,
335 .maxlen
= sizeof(int),
337 .proc_handler
= &sched_rt_handler
,
340 .ctl_name
= CTL_UNNUMBERED
,
341 .procname
= "sched_compat_yield",
342 .data
= &sysctl_sched_compat_yield
,
343 .maxlen
= sizeof(unsigned int),
345 .proc_handler
= &proc_dointvec
,
347 #ifdef CONFIG_PROVE_LOCKING
349 .ctl_name
= CTL_UNNUMBERED
,
350 .procname
= "prove_locking",
351 .data
= &prove_locking
,
352 .maxlen
= sizeof(int),
354 .proc_handler
= &proc_dointvec
,
357 #ifdef CONFIG_LOCK_STAT
359 .ctl_name
= CTL_UNNUMBERED
,
360 .procname
= "lock_stat",
362 .maxlen
= sizeof(int),
364 .proc_handler
= &proc_dointvec
,
368 .ctl_name
= KERN_PANIC
,
370 .data
= &panic_timeout
,
371 .maxlen
= sizeof(int),
373 .proc_handler
= &proc_dointvec
,
376 .ctl_name
= KERN_CORE_USES_PID
,
377 .procname
= "core_uses_pid",
378 .data
= &core_uses_pid
,
379 .maxlen
= sizeof(int),
381 .proc_handler
= &proc_dointvec
,
384 .ctl_name
= KERN_CORE_PATTERN
,
385 .procname
= "core_pattern",
386 .data
= core_pattern
,
387 .maxlen
= CORENAME_MAX_SIZE
,
389 .proc_handler
= &proc_dostring
,
390 .strategy
= &sysctl_string
,
392 #ifdef CONFIG_PROC_SYSCTL
394 .procname
= "tainted",
395 .maxlen
= sizeof(long),
397 .proc_handler
= &proc_taint
,
400 #ifdef CONFIG_LATENCYTOP
402 .procname
= "latencytop",
403 .data
= &latencytop_enabled
,
404 .maxlen
= sizeof(int),
406 .proc_handler
= &proc_dointvec
,
409 #ifdef CONFIG_BLK_DEV_INITRD
411 .ctl_name
= KERN_REALROOTDEV
,
412 .procname
= "real-root-dev",
413 .data
= &real_root_dev
,
414 .maxlen
= sizeof(int),
416 .proc_handler
= &proc_dointvec
,
420 .ctl_name
= CTL_UNNUMBERED
,
421 .procname
= "print-fatal-signals",
422 .data
= &print_fatal_signals
,
423 .maxlen
= sizeof(int),
425 .proc_handler
= &proc_dointvec
,
429 .ctl_name
= KERN_SPARC_REBOOT
,
430 .procname
= "reboot-cmd",
431 .data
= reboot_command
,
434 .proc_handler
= &proc_dostring
,
435 .strategy
= &sysctl_string
,
438 .ctl_name
= KERN_SPARC_STOP_A
,
439 .procname
= "stop-a",
440 .data
= &stop_a_enabled
,
441 .maxlen
= sizeof (int),
443 .proc_handler
= &proc_dointvec
,
446 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
447 .procname
= "scons-poweroff",
448 .data
= &scons_pwroff
,
449 .maxlen
= sizeof (int),
451 .proc_handler
= &proc_dointvec
,
456 .ctl_name
= KERN_HPPA_PWRSW
,
457 .procname
= "soft-power",
458 .data
= &pwrsw_enabled
,
459 .maxlen
= sizeof (int),
461 .proc_handler
= &proc_dointvec
,
464 .ctl_name
= KERN_HPPA_UNALIGNED
,
465 .procname
= "unaligned-trap",
466 .data
= &unaligned_enabled
,
467 .maxlen
= sizeof (int),
469 .proc_handler
= &proc_dointvec
,
473 .ctl_name
= KERN_CTLALTDEL
,
474 .procname
= "ctrl-alt-del",
476 .maxlen
= sizeof(int),
478 .proc_handler
= &proc_dointvec
,
480 #ifdef CONFIG_FUNCTION_TRACER
482 .ctl_name
= CTL_UNNUMBERED
,
483 .procname
= "ftrace_enabled",
484 .data
= &ftrace_enabled
,
485 .maxlen
= sizeof(int),
487 .proc_handler
= &ftrace_enable_sysctl
,
490 #ifdef CONFIG_TRACING
492 .ctl_name
= CTL_UNNUMBERED
,
493 .procname
= "ftrace_dump_on_oops",
494 .data
= &ftrace_dump_on_oops
,
495 .maxlen
= sizeof(int),
497 .proc_handler
= &proc_dointvec
,
500 #ifdef CONFIG_MODULES
502 .ctl_name
= KERN_MODPROBE
,
503 .procname
= "modprobe",
504 .data
= &modprobe_path
,
505 .maxlen
= KMOD_PATH_LEN
,
507 .proc_handler
= &proc_dostring
,
508 .strategy
= &sysctl_string
,
511 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
513 .ctl_name
= KERN_HOTPLUG
,
514 .procname
= "hotplug",
515 .data
= &uevent_helper
,
516 .maxlen
= UEVENT_HELPER_PATH_LEN
,
518 .proc_handler
= &proc_dostring
,
519 .strategy
= &sysctl_string
,
522 #ifdef CONFIG_CHR_DEV_SG
524 .ctl_name
= KERN_SG_BIG_BUFF
,
525 .procname
= "sg-big-buff",
526 .data
= &sg_big_buff
,
527 .maxlen
= sizeof (int),
529 .proc_handler
= &proc_dointvec
,
532 #ifdef CONFIG_BSD_PROCESS_ACCT
534 .ctl_name
= KERN_ACCT
,
537 .maxlen
= 3*sizeof(int),
539 .proc_handler
= &proc_dointvec
,
542 #ifdef CONFIG_MAGIC_SYSRQ
544 .ctl_name
= KERN_SYSRQ
,
546 .data
= &__sysrq_enabled
,
547 .maxlen
= sizeof (int),
549 .proc_handler
= &proc_dointvec
,
552 #ifdef CONFIG_PROC_SYSCTL
554 .procname
= "cad_pid",
556 .maxlen
= sizeof (int),
558 .proc_handler
= &proc_do_cad_pid
,
562 .ctl_name
= KERN_MAX_THREADS
,
563 .procname
= "threads-max",
564 .data
= &max_threads
,
565 .maxlen
= sizeof(int),
567 .proc_handler
= &proc_dointvec
,
570 .ctl_name
= KERN_RANDOM
,
571 .procname
= "random",
573 .child
= random_table
,
576 .ctl_name
= KERN_OVERFLOWUID
,
577 .procname
= "overflowuid",
578 .data
= &overflowuid
,
579 .maxlen
= sizeof(int),
581 .proc_handler
= &proc_dointvec_minmax
,
582 .strategy
= &sysctl_intvec
,
583 .extra1
= &minolduid
,
584 .extra2
= &maxolduid
,
587 .ctl_name
= KERN_OVERFLOWGID
,
588 .procname
= "overflowgid",
589 .data
= &overflowgid
,
590 .maxlen
= sizeof(int),
592 .proc_handler
= &proc_dointvec_minmax
,
593 .strategy
= &sysctl_intvec
,
594 .extra1
= &minolduid
,
595 .extra2
= &maxolduid
,
598 #ifdef CONFIG_MATHEMU
600 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
601 .procname
= "ieee_emulation_warnings",
602 .data
= &sysctl_ieee_emulation_warnings
,
603 .maxlen
= sizeof(int),
605 .proc_handler
= &proc_dointvec
,
609 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
610 .procname
= "userprocess_debug",
611 .data
= &sysctl_userprocess_debug
,
612 .maxlen
= sizeof(int),
614 .proc_handler
= &proc_dointvec
,
618 .ctl_name
= KERN_PIDMAX
,
619 .procname
= "pid_max",
621 .maxlen
= sizeof (int),
623 .proc_handler
= &proc_dointvec_minmax
,
624 .strategy
= sysctl_intvec
,
625 .extra1
= &pid_max_min
,
626 .extra2
= &pid_max_max
,
629 .ctl_name
= KERN_PANIC_ON_OOPS
,
630 .procname
= "panic_on_oops",
631 .data
= &panic_on_oops
,
632 .maxlen
= sizeof(int),
634 .proc_handler
= &proc_dointvec
,
636 #if defined CONFIG_PRINTK
638 .ctl_name
= KERN_PRINTK
,
639 .procname
= "printk",
640 .data
= &console_loglevel
,
641 .maxlen
= 4*sizeof(int),
643 .proc_handler
= &proc_dointvec
,
646 .ctl_name
= KERN_PRINTK_RATELIMIT
,
647 .procname
= "printk_ratelimit",
648 .data
= &printk_ratelimit_state
.interval
,
649 .maxlen
= sizeof(int),
651 .proc_handler
= &proc_dointvec_jiffies
,
652 .strategy
= &sysctl_jiffies
,
655 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
656 .procname
= "printk_ratelimit_burst",
657 .data
= &printk_ratelimit_state
.burst
,
658 .maxlen
= sizeof(int),
660 .proc_handler
= &proc_dointvec
,
664 .ctl_name
= KERN_NGROUPS_MAX
,
665 .procname
= "ngroups_max",
666 .data
= &ngroups_max
,
667 .maxlen
= sizeof (int),
669 .proc_handler
= &proc_dointvec
,
671 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
673 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
674 .procname
= "unknown_nmi_panic",
675 .data
= &unknown_nmi_panic
,
676 .maxlen
= sizeof (int),
678 .proc_handler
= &proc_dointvec
,
681 .procname
= "nmi_watchdog",
682 .data
= &nmi_watchdog_enabled
,
683 .maxlen
= sizeof (int),
685 .proc_handler
= &proc_nmi_enabled
,
688 #if defined(CONFIG_X86)
690 .ctl_name
= KERN_PANIC_ON_NMI
,
691 .procname
= "panic_on_unrecovered_nmi",
692 .data
= &panic_on_unrecovered_nmi
,
693 .maxlen
= sizeof(int),
695 .proc_handler
= &proc_dointvec
,
698 .ctl_name
= KERN_BOOTLOADER_TYPE
,
699 .procname
= "bootloader_type",
700 .data
= &bootloader_type
,
701 .maxlen
= sizeof (int),
703 .proc_handler
= &proc_dointvec
,
706 .ctl_name
= CTL_UNNUMBERED
,
707 .procname
= "kstack_depth_to_print",
708 .data
= &kstack_depth_to_print
,
709 .maxlen
= sizeof(int),
711 .proc_handler
= &proc_dointvec
,
714 .ctl_name
= CTL_UNNUMBERED
,
715 .procname
= "io_delay_type",
716 .data
= &io_delay_type
,
717 .maxlen
= sizeof(int),
719 .proc_handler
= &proc_dointvec
,
722 #if defined(CONFIG_MMU)
724 .ctl_name
= KERN_RANDOMIZE
,
725 .procname
= "randomize_va_space",
726 .data
= &randomize_va_space
,
727 .maxlen
= sizeof(int),
729 .proc_handler
= &proc_dointvec
,
732 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
734 .ctl_name
= KERN_SPIN_RETRY
,
735 .procname
= "spin_retry",
737 .maxlen
= sizeof (int),
739 .proc_handler
= &proc_dointvec
,
742 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
744 .procname
= "acpi_video_flags",
745 .data
= &acpi_realmode_flags
,
746 .maxlen
= sizeof (unsigned long),
748 .proc_handler
= &proc_doulongvec_minmax
,
753 .ctl_name
= KERN_IA64_UNALIGNED
,
754 .procname
= "ignore-unaligned-usertrap",
755 .data
= &no_unaligned_warning
,
756 .maxlen
= sizeof (int),
758 .proc_handler
= &proc_dointvec
,
761 #ifdef CONFIG_DETECT_SOFTLOCKUP
763 .ctl_name
= CTL_UNNUMBERED
,
764 .procname
= "softlockup_panic",
765 .data
= &softlockup_panic
,
766 .maxlen
= sizeof(int),
768 .proc_handler
= &proc_dointvec_minmax
,
769 .strategy
= &sysctl_intvec
,
774 .ctl_name
= CTL_UNNUMBERED
,
775 .procname
= "softlockup_thresh",
776 .data
= &softlockup_thresh
,
777 .maxlen
= sizeof(int),
779 .proc_handler
= &proc_dointvec_minmax
,
780 .strategy
= &sysctl_intvec
,
785 .ctl_name
= CTL_UNNUMBERED
,
786 .procname
= "hung_task_check_count",
787 .data
= &sysctl_hung_task_check_count
,
788 .maxlen
= sizeof(unsigned long),
790 .proc_handler
= &proc_doulongvec_minmax
,
791 .strategy
= &sysctl_intvec
,
794 .ctl_name
= CTL_UNNUMBERED
,
795 .procname
= "hung_task_timeout_secs",
796 .data
= &sysctl_hung_task_timeout_secs
,
797 .maxlen
= sizeof(unsigned long),
799 .proc_handler
= &proc_doulongvec_minmax
,
800 .strategy
= &sysctl_intvec
,
803 .ctl_name
= CTL_UNNUMBERED
,
804 .procname
= "hung_task_warnings",
805 .data
= &sysctl_hung_task_warnings
,
806 .maxlen
= sizeof(unsigned long),
808 .proc_handler
= &proc_doulongvec_minmax
,
809 .strategy
= &sysctl_intvec
,
814 .ctl_name
= KERN_COMPAT_LOG
,
815 .procname
= "compat-log",
817 .maxlen
= sizeof (int),
819 .proc_handler
= &proc_dointvec
,
822 #ifdef CONFIG_RT_MUTEXES
824 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
825 .procname
= "max_lock_depth",
826 .data
= &max_lock_depth
,
827 .maxlen
= sizeof(int),
829 .proc_handler
= &proc_dointvec
,
833 .ctl_name
= CTL_UNNUMBERED
,
834 .procname
= "poweroff_cmd",
835 .data
= &poweroff_cmd
,
836 .maxlen
= POWEROFF_CMD_PATH_LEN
,
838 .proc_handler
= &proc_dostring
,
839 .strategy
= &sysctl_string
,
843 .ctl_name
= CTL_UNNUMBERED
,
846 .child
= key_sysctls
,
849 #ifdef CONFIG_RCU_TORTURE_TEST
851 .ctl_name
= CTL_UNNUMBERED
,
852 .procname
= "rcutorture_runnable",
853 .data
= &rcutorture_runnable
,
854 .maxlen
= sizeof(int),
856 .proc_handler
= &proc_dointvec
,
859 #ifdef CONFIG_UNEVICTABLE_LRU
861 .ctl_name
= CTL_UNNUMBERED
,
862 .procname
= "scan_unevictable_pages",
863 .data
= &scan_unevictable_pages
,
864 .maxlen
= sizeof(scan_unevictable_pages
),
866 .proc_handler
= &scan_unevictable_handler
,
870 * NOTE: do not add new entries to this table unless you have read
871 * Documentation/sysctl/ctl_unnumbered.txt
876 static struct ctl_table vm_table
[] = {
878 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
879 .procname
= "overcommit_memory",
880 .data
= &sysctl_overcommit_memory
,
881 .maxlen
= sizeof(sysctl_overcommit_memory
),
883 .proc_handler
= &proc_dointvec
,
886 .ctl_name
= VM_PANIC_ON_OOM
,
887 .procname
= "panic_on_oom",
888 .data
= &sysctl_panic_on_oom
,
889 .maxlen
= sizeof(sysctl_panic_on_oom
),
891 .proc_handler
= &proc_dointvec
,
894 .ctl_name
= CTL_UNNUMBERED
,
895 .procname
= "oom_kill_allocating_task",
896 .data
= &sysctl_oom_kill_allocating_task
,
897 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
899 .proc_handler
= &proc_dointvec
,
902 .ctl_name
= CTL_UNNUMBERED
,
903 .procname
= "oom_dump_tasks",
904 .data
= &sysctl_oom_dump_tasks
,
905 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
907 .proc_handler
= &proc_dointvec
,
910 .ctl_name
= VM_OVERCOMMIT_RATIO
,
911 .procname
= "overcommit_ratio",
912 .data
= &sysctl_overcommit_ratio
,
913 .maxlen
= sizeof(sysctl_overcommit_ratio
),
915 .proc_handler
= &proc_dointvec
,
918 .ctl_name
= VM_PAGE_CLUSTER
,
919 .procname
= "page-cluster",
920 .data
= &page_cluster
,
921 .maxlen
= sizeof(int),
923 .proc_handler
= &proc_dointvec
,
926 .ctl_name
= VM_DIRTY_BACKGROUND
,
927 .procname
= "dirty_background_ratio",
928 .data
= &dirty_background_ratio
,
929 .maxlen
= sizeof(dirty_background_ratio
),
931 .proc_handler
= &proc_dointvec_minmax
,
932 .strategy
= &sysctl_intvec
,
934 .extra2
= &one_hundred
,
937 .ctl_name
= VM_DIRTY_RATIO
,
938 .procname
= "dirty_ratio",
939 .data
= &vm_dirty_ratio
,
940 .maxlen
= sizeof(vm_dirty_ratio
),
942 .proc_handler
= &dirty_ratio_handler
,
943 .strategy
= &sysctl_intvec
,
945 .extra2
= &one_hundred
,
948 .procname
= "dirty_writeback_centisecs",
949 .data
= &dirty_writeback_interval
,
950 .maxlen
= sizeof(dirty_writeback_interval
),
952 .proc_handler
= &dirty_writeback_centisecs_handler
,
955 .procname
= "dirty_expire_centisecs",
956 .data
= &dirty_expire_interval
,
957 .maxlen
= sizeof(dirty_expire_interval
),
959 .proc_handler
= &proc_dointvec_userhz_jiffies
,
962 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
963 .procname
= "nr_pdflush_threads",
964 .data
= &nr_pdflush_threads
,
965 .maxlen
= sizeof nr_pdflush_threads
,
966 .mode
= 0444 /* read-only*/,
967 .proc_handler
= &proc_dointvec
,
970 .ctl_name
= VM_SWAPPINESS
,
971 .procname
= "swappiness",
972 .data
= &vm_swappiness
,
973 .maxlen
= sizeof(vm_swappiness
),
975 .proc_handler
= &proc_dointvec_minmax
,
976 .strategy
= &sysctl_intvec
,
978 .extra2
= &one_hundred
,
980 #ifdef CONFIG_HUGETLB_PAGE
982 .procname
= "nr_hugepages",
984 .maxlen
= sizeof(unsigned long),
986 .proc_handler
= &hugetlb_sysctl_handler
,
987 .extra1
= (void *)&hugetlb_zero
,
988 .extra2
= (void *)&hugetlb_infinity
,
991 .ctl_name
= VM_HUGETLB_GROUP
,
992 .procname
= "hugetlb_shm_group",
993 .data
= &sysctl_hugetlb_shm_group
,
994 .maxlen
= sizeof(gid_t
),
996 .proc_handler
= &proc_dointvec
,
999 .ctl_name
= CTL_UNNUMBERED
,
1000 .procname
= "hugepages_treat_as_movable",
1001 .data
= &hugepages_treat_as_movable
,
1002 .maxlen
= sizeof(int),
1004 .proc_handler
= &hugetlb_treat_movable_handler
,
1007 .ctl_name
= CTL_UNNUMBERED
,
1008 .procname
= "nr_overcommit_hugepages",
1010 .maxlen
= sizeof(unsigned long),
1012 .proc_handler
= &hugetlb_overcommit_handler
,
1013 .extra1
= (void *)&hugetlb_zero
,
1014 .extra2
= (void *)&hugetlb_infinity
,
1018 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
1019 .procname
= "lowmem_reserve_ratio",
1020 .data
= &sysctl_lowmem_reserve_ratio
,
1021 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1023 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
1024 .strategy
= &sysctl_intvec
,
1027 .ctl_name
= VM_DROP_PAGECACHE
,
1028 .procname
= "drop_caches",
1029 .data
= &sysctl_drop_caches
,
1030 .maxlen
= sizeof(int),
1032 .proc_handler
= drop_caches_sysctl_handler
,
1033 .strategy
= &sysctl_intvec
,
1036 .ctl_name
= VM_MIN_FREE_KBYTES
,
1037 .procname
= "min_free_kbytes",
1038 .data
= &min_free_kbytes
,
1039 .maxlen
= sizeof(min_free_kbytes
),
1041 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1042 .strategy
= &sysctl_intvec
,
1046 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1047 .procname
= "percpu_pagelist_fraction",
1048 .data
= &percpu_pagelist_fraction
,
1049 .maxlen
= sizeof(percpu_pagelist_fraction
),
1051 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1052 .strategy
= &sysctl_intvec
,
1053 .extra1
= &min_percpu_pagelist_fract
,
1057 .ctl_name
= VM_MAX_MAP_COUNT
,
1058 .procname
= "max_map_count",
1059 .data
= &sysctl_max_map_count
,
1060 .maxlen
= sizeof(sysctl_max_map_count
),
1062 .proc_handler
= &proc_dointvec
1066 .ctl_name
= VM_LAPTOP_MODE
,
1067 .procname
= "laptop_mode",
1068 .data
= &laptop_mode
,
1069 .maxlen
= sizeof(laptop_mode
),
1071 .proc_handler
= &proc_dointvec_jiffies
,
1072 .strategy
= &sysctl_jiffies
,
1075 .ctl_name
= VM_BLOCK_DUMP
,
1076 .procname
= "block_dump",
1077 .data
= &block_dump
,
1078 .maxlen
= sizeof(block_dump
),
1080 .proc_handler
= &proc_dointvec
,
1081 .strategy
= &sysctl_intvec
,
1085 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1086 .procname
= "vfs_cache_pressure",
1087 .data
= &sysctl_vfs_cache_pressure
,
1088 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1090 .proc_handler
= &proc_dointvec
,
1091 .strategy
= &sysctl_intvec
,
1094 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1096 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1097 .procname
= "legacy_va_layout",
1098 .data
= &sysctl_legacy_va_layout
,
1099 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1101 .proc_handler
= &proc_dointvec
,
1102 .strategy
= &sysctl_intvec
,
1108 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1109 .procname
= "zone_reclaim_mode",
1110 .data
= &zone_reclaim_mode
,
1111 .maxlen
= sizeof(zone_reclaim_mode
),
1113 .proc_handler
= &proc_dointvec
,
1114 .strategy
= &sysctl_intvec
,
1118 .ctl_name
= VM_MIN_UNMAPPED
,
1119 .procname
= "min_unmapped_ratio",
1120 .data
= &sysctl_min_unmapped_ratio
,
1121 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1123 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1124 .strategy
= &sysctl_intvec
,
1126 .extra2
= &one_hundred
,
1129 .ctl_name
= VM_MIN_SLAB
,
1130 .procname
= "min_slab_ratio",
1131 .data
= &sysctl_min_slab_ratio
,
1132 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1134 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1135 .strategy
= &sysctl_intvec
,
1137 .extra2
= &one_hundred
,
1142 .ctl_name
= CTL_UNNUMBERED
,
1143 .procname
= "stat_interval",
1144 .data
= &sysctl_stat_interval
,
1145 .maxlen
= sizeof(sysctl_stat_interval
),
1147 .proc_handler
= &proc_dointvec_jiffies
,
1148 .strategy
= &sysctl_jiffies
,
1151 #ifdef CONFIG_SECURITY
1153 .ctl_name
= CTL_UNNUMBERED
,
1154 .procname
= "mmap_min_addr",
1155 .data
= &mmap_min_addr
,
1156 .maxlen
= sizeof(unsigned long),
1158 .proc_handler
= &proc_doulongvec_minmax
,
1163 .ctl_name
= CTL_UNNUMBERED
,
1164 .procname
= "numa_zonelist_order",
1165 .data
= &numa_zonelist_order
,
1166 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1168 .proc_handler
= &numa_zonelist_order_handler
,
1169 .strategy
= &sysctl_string
,
1172 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1173 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1175 .ctl_name
= VM_VDSO_ENABLED
,
1176 .procname
= "vdso_enabled",
1177 .data
= &vdso_enabled
,
1178 .maxlen
= sizeof(vdso_enabled
),
1180 .proc_handler
= &proc_dointvec
,
1181 .strategy
= &sysctl_intvec
,
1185 #ifdef CONFIG_HIGHMEM
1187 .ctl_name
= CTL_UNNUMBERED
,
1188 .procname
= "highmem_is_dirtyable",
1189 .data
= &vm_highmem_is_dirtyable
,
1190 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1192 .proc_handler
= &proc_dointvec_minmax
,
1193 .strategy
= &sysctl_intvec
,
1199 * NOTE: do not add new entries to this table unless you have read
1200 * Documentation/sysctl/ctl_unnumbered.txt
1205 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1206 static struct ctl_table binfmt_misc_table
[] = {
1211 static struct ctl_table fs_table
[] = {
1213 .ctl_name
= FS_NRINODE
,
1214 .procname
= "inode-nr",
1215 .data
= &inodes_stat
,
1216 .maxlen
= 2*sizeof(int),
1218 .proc_handler
= &proc_dointvec
,
1221 .ctl_name
= FS_STATINODE
,
1222 .procname
= "inode-state",
1223 .data
= &inodes_stat
,
1224 .maxlen
= 7*sizeof(int),
1226 .proc_handler
= &proc_dointvec
,
1229 .procname
= "file-nr",
1230 .data
= &files_stat
,
1231 .maxlen
= 3*sizeof(int),
1233 .proc_handler
= &proc_nr_files
,
1236 .ctl_name
= FS_MAXFILE
,
1237 .procname
= "file-max",
1238 .data
= &files_stat
.max_files
,
1239 .maxlen
= sizeof(int),
1241 .proc_handler
= &proc_dointvec
,
1244 .ctl_name
= CTL_UNNUMBERED
,
1245 .procname
= "nr_open",
1246 .data
= &sysctl_nr_open
,
1247 .maxlen
= sizeof(int),
1249 .proc_handler
= &proc_dointvec_minmax
,
1250 .extra1
= &sysctl_nr_open_min
,
1251 .extra2
= &sysctl_nr_open_max
,
1254 .ctl_name
= FS_DENTRY
,
1255 .procname
= "dentry-state",
1256 .data
= &dentry_stat
,
1257 .maxlen
= 6*sizeof(int),
1259 .proc_handler
= &proc_dointvec
,
1262 .ctl_name
= FS_OVERFLOWUID
,
1263 .procname
= "overflowuid",
1264 .data
= &fs_overflowuid
,
1265 .maxlen
= sizeof(int),
1267 .proc_handler
= &proc_dointvec_minmax
,
1268 .strategy
= &sysctl_intvec
,
1269 .extra1
= &minolduid
,
1270 .extra2
= &maxolduid
,
1273 .ctl_name
= FS_OVERFLOWGID
,
1274 .procname
= "overflowgid",
1275 .data
= &fs_overflowgid
,
1276 .maxlen
= sizeof(int),
1278 .proc_handler
= &proc_dointvec_minmax
,
1279 .strategy
= &sysctl_intvec
,
1280 .extra1
= &minolduid
,
1281 .extra2
= &maxolduid
,
1283 #ifdef CONFIG_FILE_LOCKING
1285 .ctl_name
= FS_LEASES
,
1286 .procname
= "leases-enable",
1287 .data
= &leases_enable
,
1288 .maxlen
= sizeof(int),
1290 .proc_handler
= &proc_dointvec
,
1293 #ifdef CONFIG_DNOTIFY
1295 .ctl_name
= FS_DIR_NOTIFY
,
1296 .procname
= "dir-notify-enable",
1297 .data
= &dir_notify_enable
,
1298 .maxlen
= sizeof(int),
1300 .proc_handler
= &proc_dointvec
,
1304 #ifdef CONFIG_FILE_LOCKING
1306 .ctl_name
= FS_LEASE_TIME
,
1307 .procname
= "lease-break-time",
1308 .data
= &lease_break_time
,
1309 .maxlen
= sizeof(int),
1311 .proc_handler
= &proc_dointvec_minmax
,
1312 .strategy
= &sysctl_intvec
,
1319 .procname
= "aio-nr",
1321 .maxlen
= sizeof(aio_nr
),
1323 .proc_handler
= &proc_doulongvec_minmax
,
1326 .procname
= "aio-max-nr",
1327 .data
= &aio_max_nr
,
1328 .maxlen
= sizeof(aio_max_nr
),
1330 .proc_handler
= &proc_doulongvec_minmax
,
1332 #endif /* CONFIG_AIO */
1333 #ifdef CONFIG_INOTIFY_USER
1335 .ctl_name
= FS_INOTIFY
,
1336 .procname
= "inotify",
1338 .child
= inotify_table
,
1343 .procname
= "epoll",
1345 .child
= epoll_table
,
1350 .ctl_name
= KERN_SETUID_DUMPABLE
,
1351 .procname
= "suid_dumpable",
1352 .data
= &suid_dumpable
,
1353 .maxlen
= sizeof(int),
1355 .proc_handler
= &proc_dointvec
,
1357 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1359 .ctl_name
= CTL_UNNUMBERED
,
1360 .procname
= "binfmt_misc",
1362 .child
= binfmt_misc_table
,
1366 * NOTE: do not add new entries to this table unless you have read
1367 * Documentation/sysctl/ctl_unnumbered.txt
1372 static struct ctl_table debug_table
[] = {
1373 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1375 .ctl_name
= CTL_UNNUMBERED
,
1376 .procname
= "exception-trace",
1377 .data
= &show_unhandled_signals
,
1378 .maxlen
= sizeof(int),
1380 .proc_handler
= proc_dointvec
1386 static struct ctl_table dev_table
[] = {
1390 static DEFINE_SPINLOCK(sysctl_lock
);
1392 /* called under sysctl_lock */
1393 static int use_table(struct ctl_table_header
*p
)
1395 if (unlikely(p
->unregistering
))
1401 /* called under sysctl_lock */
1402 static void unuse_table(struct ctl_table_header
*p
)
1405 if (unlikely(p
->unregistering
))
1406 complete(p
->unregistering
);
1409 /* called under sysctl_lock, will reacquire if has to wait */
1410 static void start_unregistering(struct ctl_table_header
*p
)
1413 * if p->used is 0, nobody will ever touch that entry again;
1414 * we'll eliminate all paths to it before dropping sysctl_lock
1416 if (unlikely(p
->used
)) {
1417 struct completion wait
;
1418 init_completion(&wait
);
1419 p
->unregistering
= &wait
;
1420 spin_unlock(&sysctl_lock
);
1421 wait_for_completion(&wait
);
1422 spin_lock(&sysctl_lock
);
1424 /* anything non-NULL; we'll never dereference it */
1425 p
->unregistering
= ERR_PTR(-EINVAL
);
1428 * do not remove from the list until nobody holds it; walking the
1429 * list in do_sysctl() relies on that.
1431 list_del_init(&p
->ctl_entry
);
1434 void sysctl_head_get(struct ctl_table_header
*head
)
1436 spin_lock(&sysctl_lock
);
1438 spin_unlock(&sysctl_lock
);
1441 void sysctl_head_put(struct ctl_table_header
*head
)
1443 spin_lock(&sysctl_lock
);
1446 spin_unlock(&sysctl_lock
);
1449 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1453 spin_lock(&sysctl_lock
);
1454 if (!use_table(head
))
1455 head
= ERR_PTR(-ENOENT
);
1456 spin_unlock(&sysctl_lock
);
1460 void sysctl_head_finish(struct ctl_table_header
*head
)
1464 spin_lock(&sysctl_lock
);
1466 spin_unlock(&sysctl_lock
);
1469 static struct ctl_table_set
*
1470 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1472 struct ctl_table_set
*set
= &root
->default_set
;
1474 set
= root
->lookup(root
, namespaces
);
1478 static struct list_head
*
1479 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1481 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1485 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1486 struct ctl_table_header
*prev
)
1488 struct ctl_table_root
*root
;
1489 struct list_head
*header_list
;
1490 struct ctl_table_header
*head
;
1491 struct list_head
*tmp
;
1493 spin_lock(&sysctl_lock
);
1496 tmp
= &prev
->ctl_entry
;
1500 tmp
= &root_table_header
.ctl_entry
;
1502 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1504 if (!use_table(head
))
1506 spin_unlock(&sysctl_lock
);
1511 header_list
= lookup_header_list(root
, namespaces
);
1512 if (tmp
!= header_list
)
1516 root
= list_entry(root
->root_list
.next
,
1517 struct ctl_table_root
, root_list
);
1518 if (root
== &sysctl_table_root
)
1520 header_list
= lookup_header_list(root
, namespaces
);
1521 } while (list_empty(header_list
));
1522 tmp
= header_list
->next
;
1525 spin_unlock(&sysctl_lock
);
1529 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1531 return __sysctl_head_next(current
->nsproxy
, prev
);
1534 void register_sysctl_root(struct ctl_table_root
*root
)
1536 spin_lock(&sysctl_lock
);
1537 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1538 spin_unlock(&sysctl_lock
);
1541 #ifdef CONFIG_SYSCTL_SYSCALL
1542 /* Perform the actual read/write of a sysctl table entry. */
1543 static int do_sysctl_strategy(struct ctl_table_root
*root
,
1544 struct ctl_table
*table
,
1545 void __user
*oldval
, size_t __user
*oldlenp
,
1546 void __user
*newval
, size_t newlen
)
1554 if (sysctl_perm(root
, table
, op
))
1557 if (table
->strategy
) {
1558 rc
= table
->strategy(table
, oldval
, oldlenp
, newval
, newlen
);
1565 /* If there is no strategy routine, or if the strategy returns
1566 * zero, proceed with automatic r/w */
1567 if (table
->data
&& table
->maxlen
) {
1568 rc
= sysctl_data(table
, oldval
, oldlenp
, newval
, newlen
);
1575 static int parse_table(int __user
*name
, int nlen
,
1576 void __user
*oldval
, size_t __user
*oldlenp
,
1577 void __user
*newval
, size_t newlen
,
1578 struct ctl_table_root
*root
,
1579 struct ctl_table
*table
)
1585 if (get_user(n
, name
))
1587 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1588 if (!table
->ctl_name
)
1590 if (n
== table
->ctl_name
) {
1593 if (sysctl_perm(root
, table
, MAY_EXEC
))
1597 table
= table
->child
;
1600 error
= do_sysctl_strategy(root
, table
,
1609 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1610 void __user
*newval
, size_t newlen
)
1612 struct ctl_table_header
*head
;
1613 int error
= -ENOTDIR
;
1615 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1619 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1623 for (head
= sysctl_head_next(NULL
); head
;
1624 head
= sysctl_head_next(head
)) {
1625 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1627 head
->root
, head
->ctl_table
);
1628 if (error
!= -ENOTDIR
) {
1629 sysctl_head_finish(head
);
1636 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1638 struct __sysctl_args tmp
;
1641 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1644 error
= deprecated_sysctl_warning(&tmp
);
1649 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1650 tmp
.newval
, tmp
.newlen
);
1655 #endif /* CONFIG_SYSCTL_SYSCALL */
1658 * sysctl_perm does NOT grant the superuser all rights automatically, because
1659 * some sysctl variables are readonly even to root.
1662 static int test_perm(int mode
, int op
)
1666 else if (in_egroup_p(0))
1668 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1673 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1678 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1682 if (root
->permissions
)
1683 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1687 return test_perm(mode
, op
);
1690 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1692 for (; table
->ctl_name
|| table
->procname
; table
++) {
1693 table
->parent
= parent
;
1695 sysctl_set_parent(table
, table
->child
);
1699 static __init
int sysctl_init(void)
1701 sysctl_set_parent(NULL
, root_table
);
1702 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1705 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1711 core_initcall(sysctl_init
);
1713 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1714 struct ctl_table
*table
)
1716 struct ctl_table
*p
;
1717 const char *s
= branch
->procname
;
1719 /* branch should have named subdirectory as its first element */
1720 if (!s
|| !branch
->child
)
1723 /* ... and nothing else */
1724 if (branch
[1].procname
|| branch
[1].ctl_name
)
1727 /* table should contain subdirectory with the same name */
1728 for (p
= table
; p
->procname
|| p
->ctl_name
; p
++) {
1731 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1737 /* see if attaching q to p would be an improvement */
1738 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1740 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1741 struct ctl_table
*next
;
1743 int not_in_parent
= !p
->attached_by
;
1745 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1746 if (by
== q
->attached_by
)
1748 if (to
== p
->attached_by
)
1754 if (is_better
&& not_in_parent
) {
1755 q
->attached_by
= by
;
1756 q
->attached_to
= to
;
1762 * __register_sysctl_paths - register a sysctl hierarchy
1763 * @root: List of sysctl headers to register on
1764 * @namespaces: Data to compute which lists of sysctl entries are visible
1765 * @path: The path to the directory the sysctl table is in.
1766 * @table: the top-level table structure
1768 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1769 * array. A completely 0 filled entry terminates the table.
1771 * The members of the &struct ctl_table structure are used as follows:
1773 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1774 * must be unique within that level of sysctl
1776 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1777 * enter a sysctl file
1779 * data - a pointer to data for use by proc_handler
1781 * maxlen - the maximum size in bytes of the data
1783 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1785 * child - a pointer to the child sysctl table if this entry is a directory, or
1788 * proc_handler - the text handler routine (described below)
1790 * strategy - the strategy routine (described below)
1792 * de - for internal use by the sysctl routines
1794 * extra1, extra2 - extra pointers usable by the proc handler routines
1796 * Leaf nodes in the sysctl tree will be represented by a single file
1797 * under /proc; non-leaf nodes will be represented by directories.
1799 * sysctl(2) can automatically manage read and write requests through
1800 * the sysctl table. The data and maxlen fields of the ctl_table
1801 * struct enable minimal validation of the values being written to be
1802 * performed, and the mode field allows minimal authentication.
1804 * More sophisticated management can be enabled by the provision of a
1805 * strategy routine with the table entry. This will be called before
1806 * any automatic read or write of the data is performed.
1808 * The strategy routine may return
1810 * < 0 - Error occurred (error is passed to user process)
1812 * 0 - OK - proceed with automatic read or write.
1814 * > 0 - OK - read or write has been done by the strategy routine, so
1815 * return immediately.
1817 * There must be a proc_handler routine for any terminal nodes
1818 * mirrored under /proc/sys (non-terminals are handled by a built-in
1819 * directory handler). Several default handlers are available to
1820 * cover common cases -
1822 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1823 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1824 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1826 * It is the handler's job to read the input buffer from user memory
1827 * and process it. The handler should return 0 on success.
1829 * This routine returns %NULL on a failure to register, and a pointer
1830 * to the table header on success.
1832 struct ctl_table_header
*__register_sysctl_paths(
1833 struct ctl_table_root
*root
,
1834 struct nsproxy
*namespaces
,
1835 const struct ctl_path
*path
, struct ctl_table
*table
)
1837 struct ctl_table_header
*header
;
1838 struct ctl_table
*new, **prevp
;
1839 unsigned int n
, npath
;
1840 struct ctl_table_set
*set
;
1842 /* Count the path components */
1843 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
1847 * For each path component, allocate a 2-element ctl_table array.
1848 * The first array element will be filled with the sysctl entry
1849 * for this, the second will be the sentinel (ctl_name == 0).
1851 * We allocate everything in one go so that we don't have to
1852 * worry about freeing additional memory in unregister_sysctl_table.
1854 header
= kzalloc(sizeof(struct ctl_table_header
) +
1855 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1859 new = (struct ctl_table
*) (header
+ 1);
1861 /* Now connect the dots */
1862 prevp
= &header
->ctl_table
;
1863 for (n
= 0; n
< npath
; ++n
, ++path
) {
1864 /* Copy the procname */
1865 new->procname
= path
->procname
;
1866 new->ctl_name
= path
->ctl_name
;
1870 prevp
= &new->child
;
1875 header
->ctl_table_arg
= table
;
1877 INIT_LIST_HEAD(&header
->ctl_entry
);
1879 header
->unregistering
= NULL
;
1880 header
->root
= root
;
1881 sysctl_set_parent(NULL
, header
->ctl_table
);
1883 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1884 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1889 spin_lock(&sysctl_lock
);
1890 header
->set
= lookup_header_set(root
, namespaces
);
1891 header
->attached_by
= header
->ctl_table
;
1892 header
->attached_to
= root_table
;
1893 header
->parent
= &root_table_header
;
1894 for (set
= header
->set
; set
; set
= set
->parent
) {
1895 struct ctl_table_header
*p
;
1896 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
1897 if (p
->unregistering
)
1899 try_attach(p
, header
);
1902 header
->parent
->count
++;
1903 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
1904 spin_unlock(&sysctl_lock
);
1910 * register_sysctl_table_path - register a sysctl table hierarchy
1911 * @path: The path to the directory the sysctl table is in.
1912 * @table: the top-level table structure
1914 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1915 * array. A completely 0 filled entry terminates the table.
1917 * See __register_sysctl_paths for more details.
1919 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1920 struct ctl_table
*table
)
1922 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1927 * register_sysctl_table - register a sysctl table hierarchy
1928 * @table: the top-level table structure
1930 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1931 * array. A completely 0 filled entry terminates the table.
1933 * See register_sysctl_paths for more details.
1935 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1937 static const struct ctl_path null_path
[] = { {} };
1939 return register_sysctl_paths(null_path
, table
);
1943 * unregister_sysctl_table - unregister a sysctl table hierarchy
1944 * @header: the header returned from register_sysctl_table
1946 * Unregisters the sysctl table and all children. proc entries may not
1947 * actually be removed until they are no longer used by anyone.
1949 void unregister_sysctl_table(struct ctl_table_header
* header
)
1956 spin_lock(&sysctl_lock
);
1957 start_unregistering(header
);
1958 if (!--header
->parent
->count
) {
1960 kfree(header
->parent
);
1962 if (!--header
->count
)
1964 spin_unlock(&sysctl_lock
);
1967 int sysctl_is_seen(struct ctl_table_header
*p
)
1969 struct ctl_table_set
*set
= p
->set
;
1971 spin_lock(&sysctl_lock
);
1972 if (p
->unregistering
)
1974 else if (!set
->is_seen
)
1977 res
= set
->is_seen(set
);
1978 spin_unlock(&sysctl_lock
);
1982 void setup_sysctl_set(struct ctl_table_set
*p
,
1983 struct ctl_table_set
*parent
,
1984 int (*is_seen
)(struct ctl_table_set
*))
1986 INIT_LIST_HEAD(&p
->list
);
1987 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
1988 p
->is_seen
= is_seen
;
1991 #else /* !CONFIG_SYSCTL */
1992 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1997 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1998 struct ctl_table
*table
)
2003 void unregister_sysctl_table(struct ctl_table_header
* table
)
2007 void setup_sysctl_set(struct ctl_table_set
*p
,
2008 struct ctl_table_set
*parent
,
2009 int (*is_seen
)(struct ctl_table_set
*))
2013 void sysctl_head_put(struct ctl_table_header
*head
)
2017 #endif /* CONFIG_SYSCTL */
2023 #ifdef CONFIG_PROC_SYSCTL
2025 static int _proc_do_string(void* data
, int maxlen
, int write
,
2026 struct file
*filp
, void __user
*buffer
,
2027 size_t *lenp
, loff_t
*ppos
)
2033 if (!data
|| !maxlen
|| !*lenp
) {
2041 while (len
< *lenp
) {
2042 if (get_user(c
, p
++))
2044 if (c
== 0 || c
== '\n')
2050 if(copy_from_user(data
, buffer
, len
))
2052 ((char *) data
)[len
] = 0;
2070 if(copy_to_user(buffer
, data
, len
))
2073 if(put_user('\n', ((char __user
*) buffer
) + len
))
2084 * proc_dostring - read a string sysctl
2085 * @table: the sysctl table
2086 * @write: %TRUE if this is a write to the sysctl file
2087 * @filp: the file structure
2088 * @buffer: the user buffer
2089 * @lenp: the size of the user buffer
2090 * @ppos: file position
2092 * Reads/writes a string from/to the user buffer. If the kernel
2093 * buffer provided is not large enough to hold the string, the
2094 * string is truncated. The copied string is %NULL-terminated.
2095 * If the string is being read by the user process, it is copied
2096 * and a newline '\n' is added. It is truncated if the buffer is
2099 * Returns 0 on success.
2101 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2102 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2104 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
2105 buffer
, lenp
, ppos
);
2109 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
2111 int write
, void *data
)
2114 *valp
= *negp
? -*lvalp
: *lvalp
;
2119 *lvalp
= (unsigned long)-val
;
2122 *lvalp
= (unsigned long)val
;
2128 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2129 int write
, struct file
*filp
, void __user
*buffer
,
2130 size_t *lenp
, loff_t
*ppos
,
2131 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2132 int write
, void *data
),
2135 #define TMPBUFLEN 21
2136 int *i
, vleft
, first
=1, neg
, val
;
2140 char buf
[TMPBUFLEN
], *p
;
2141 char __user
*s
= buffer
;
2143 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
2144 (*ppos
&& !write
)) {
2149 i
= (int *) tbl_data
;
2150 vleft
= table
->maxlen
/ sizeof(*i
);
2154 conv
= do_proc_dointvec_conv
;
2156 for (; left
&& vleft
--; i
++, first
=0) {
2171 if (len
> sizeof(buf
) - 1)
2172 len
= sizeof(buf
) - 1;
2173 if (copy_from_user(buf
, s
, len
))
2177 if (*p
== '-' && left
> 1) {
2181 if (*p
< '0' || *p
> '9')
2184 lval
= simple_strtoul(p
, &p
, 0);
2187 if ((len
< left
) && *p
&& !isspace(*p
))
2194 if (conv(&neg
, &lval
, i
, 1, data
))
2201 if (conv(&neg
, &lval
, i
, 0, data
))
2204 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2208 if(copy_to_user(s
, buf
, len
))
2215 if (!write
&& !first
&& left
) {
2216 if(put_user('\n', s
))
2223 if (get_user(c
, s
++))
2238 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2239 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2240 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2241 int write
, void *data
),
2244 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2245 buffer
, lenp
, ppos
, conv
, data
);
2249 * proc_dointvec - read a vector of integers
2250 * @table: the sysctl table
2251 * @write: %TRUE if this is a write to the sysctl file
2252 * @filp: the file structure
2253 * @buffer: the user buffer
2254 * @lenp: the size of the user buffer
2255 * @ppos: file position
2257 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2258 * values from/to the user buffer, treated as an ASCII string.
2260 * Returns 0 on success.
2262 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2263 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2265 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2270 * Taint values can only be increased
2271 * This means we can safely use a temporary.
2273 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2274 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2277 unsigned long tmptaint
= get_taint();
2280 if (write
&& !capable(CAP_SYS_ADMIN
))
2285 err
= proc_doulongvec_minmax(&t
, write
, filp
, buffer
, lenp
, ppos
);
2291 * Poor man's atomic or. Not worth adding a primitive
2292 * to everyone's atomic.h for this
2295 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2296 if ((tmptaint
>> i
) & 1)
2304 struct do_proc_dointvec_minmax_conv_param
{
2309 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2311 int write
, void *data
)
2313 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2315 int val
= *negp
? -*lvalp
: *lvalp
;
2316 if ((param
->min
&& *param
->min
> val
) ||
2317 (param
->max
&& *param
->max
< val
))
2324 *lvalp
= (unsigned long)-val
;
2327 *lvalp
= (unsigned long)val
;
2334 * proc_dointvec_minmax - read a vector of integers with min/max values
2335 * @table: the sysctl table
2336 * @write: %TRUE if this is a write to the sysctl file
2337 * @filp: the file structure
2338 * @buffer: the user buffer
2339 * @lenp: the size of the user buffer
2340 * @ppos: file position
2342 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2343 * values from/to the user buffer, treated as an ASCII string.
2345 * This routine will ensure the values are within the range specified by
2346 * table->extra1 (min) and table->extra2 (max).
2348 * Returns 0 on success.
2350 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2351 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2353 struct do_proc_dointvec_minmax_conv_param param
= {
2354 .min
= (int *) table
->extra1
,
2355 .max
= (int *) table
->extra2
,
2357 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2358 do_proc_dointvec_minmax_conv
, ¶m
);
2361 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2363 void __user
*buffer
,
2364 size_t *lenp
, loff_t
*ppos
,
2365 unsigned long convmul
,
2366 unsigned long convdiv
)
2368 #define TMPBUFLEN 21
2369 unsigned long *i
, *min
, *max
, val
;
2370 int vleft
, first
=1, neg
;
2372 char buf
[TMPBUFLEN
], *p
;
2373 char __user
*s
= buffer
;
2375 if (!data
|| !table
->maxlen
|| !*lenp
||
2376 (*ppos
&& !write
)) {
2381 i
= (unsigned long *) data
;
2382 min
= (unsigned long *) table
->extra1
;
2383 max
= (unsigned long *) table
->extra2
;
2384 vleft
= table
->maxlen
/ sizeof(unsigned long);
2387 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2402 if (len
> TMPBUFLEN
-1)
2404 if (copy_from_user(buf
, s
, len
))
2408 if (*p
== '-' && left
> 1) {
2412 if (*p
< '0' || *p
> '9')
2414 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2416 if ((len
< left
) && *p
&& !isspace(*p
))
2425 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2432 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2436 if(copy_to_user(s
, buf
, len
))
2443 if (!write
&& !first
&& left
) {
2444 if(put_user('\n', s
))
2451 if (get_user(c
, s
++))
2466 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2468 void __user
*buffer
,
2469 size_t *lenp
, loff_t
*ppos
,
2470 unsigned long convmul
,
2471 unsigned long convdiv
)
2473 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2474 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2478 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2479 * @table: the sysctl table
2480 * @write: %TRUE if this is a write to the sysctl file
2481 * @filp: the file structure
2482 * @buffer: the user buffer
2483 * @lenp: the size of the user buffer
2484 * @ppos: file position
2486 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2487 * values from/to the user buffer, treated as an ASCII string.
2489 * This routine will ensure the values are within the range specified by
2490 * table->extra1 (min) and table->extra2 (max).
2492 * Returns 0 on success.
2494 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2495 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2497 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2501 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2502 * @table: the sysctl table
2503 * @write: %TRUE if this is a write to the sysctl file
2504 * @filp: the file structure
2505 * @buffer: the user buffer
2506 * @lenp: the size of the user buffer
2507 * @ppos: file position
2509 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2510 * values from/to the user buffer, treated as an ASCII string. The values
2511 * are treated as milliseconds, and converted to jiffies when they are stored.
2513 * This routine will ensure the values are within the range specified by
2514 * table->extra1 (min) and table->extra2 (max).
2516 * Returns 0 on success.
2518 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2520 void __user
*buffer
,
2521 size_t *lenp
, loff_t
*ppos
)
2523 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2524 lenp
, ppos
, HZ
, 1000l);
2528 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2530 int write
, void *data
)
2533 if (*lvalp
> LONG_MAX
/ HZ
)
2535 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2541 lval
= (unsigned long)-val
;
2544 lval
= (unsigned long)val
;
2551 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2553 int write
, void *data
)
2556 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2558 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2564 lval
= (unsigned long)-val
;
2567 lval
= (unsigned long)val
;
2569 *lvalp
= jiffies_to_clock_t(lval
);
2574 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2576 int write
, void *data
)
2579 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2585 lval
= (unsigned long)-val
;
2588 lval
= (unsigned long)val
;
2590 *lvalp
= jiffies_to_msecs(lval
);
2596 * proc_dointvec_jiffies - read a vector of integers as seconds
2597 * @table: the sysctl table
2598 * @write: %TRUE if this is a write to the sysctl file
2599 * @filp: the file structure
2600 * @buffer: the user buffer
2601 * @lenp: the size of the user buffer
2602 * @ppos: file position
2604 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2605 * values from/to the user buffer, treated as an ASCII string.
2606 * The values read are assumed to be in seconds, and are converted into
2609 * Returns 0 on success.
2611 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2612 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2614 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2615 do_proc_dointvec_jiffies_conv
,NULL
);
2619 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2620 * @table: the sysctl table
2621 * @write: %TRUE if this is a write to the sysctl file
2622 * @filp: the file structure
2623 * @buffer: the user buffer
2624 * @lenp: the size of the user buffer
2625 * @ppos: pointer to the file position
2627 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2628 * values from/to the user buffer, treated as an ASCII string.
2629 * The values read are assumed to be in 1/USER_HZ seconds, and
2630 * are converted into jiffies.
2632 * Returns 0 on success.
2634 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2635 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2637 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2638 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2642 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2643 * @table: the sysctl table
2644 * @write: %TRUE if this is a write to the sysctl file
2645 * @filp: the file structure
2646 * @buffer: the user buffer
2647 * @lenp: the size of the user buffer
2648 * @ppos: file position
2649 * @ppos: the current position in the file
2651 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2652 * values from/to the user buffer, treated as an ASCII string.
2653 * The values read are assumed to be in 1/1000 seconds, and
2654 * are converted into jiffies.
2656 * Returns 0 on success.
2658 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2659 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2661 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2662 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2665 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2666 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2668 struct pid
*new_pid
;
2672 tmp
= pid_vnr(cad_pid
);
2674 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2675 lenp
, ppos
, NULL
, NULL
);
2679 new_pid
= find_get_pid(tmp
);
2683 put_pid(xchg(&cad_pid
, new_pid
));
2687 #else /* CONFIG_PROC_FS */
2689 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2690 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2695 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2696 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2701 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2702 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2707 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2708 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2713 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2714 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2719 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2720 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2725 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2726 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2731 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2733 void __user
*buffer
,
2734 size_t *lenp
, loff_t
*ppos
)
2740 #endif /* CONFIG_PROC_FS */
2743 #ifdef CONFIG_SYSCTL_SYSCALL
2745 * General sysctl support routines
2748 /* The generic sysctl data routine (used if no strategy routine supplied) */
2749 int sysctl_data(struct ctl_table
*table
,
2750 void __user
*oldval
, size_t __user
*oldlenp
,
2751 void __user
*newval
, size_t newlen
)
2755 /* Get out of I don't have a variable */
2756 if (!table
->data
|| !table
->maxlen
)
2759 if (oldval
&& oldlenp
) {
2760 if (get_user(len
, oldlenp
))
2763 if (len
> table
->maxlen
)
2764 len
= table
->maxlen
;
2765 if (copy_to_user(oldval
, table
->data
, len
))
2767 if (put_user(len
, oldlenp
))
2772 if (newval
&& newlen
) {
2773 if (newlen
> table
->maxlen
)
2774 newlen
= table
->maxlen
;
2776 if (copy_from_user(table
->data
, newval
, newlen
))
2782 /* The generic string strategy routine: */
2783 int sysctl_string(struct ctl_table
*table
,
2784 void __user
*oldval
, size_t __user
*oldlenp
,
2785 void __user
*newval
, size_t newlen
)
2787 if (!table
->data
|| !table
->maxlen
)
2790 if (oldval
&& oldlenp
) {
2792 if (get_user(bufsize
, oldlenp
))
2795 size_t len
= strlen(table
->data
), copied
;
2797 /* This shouldn't trigger for a well-formed sysctl */
2798 if (len
> table
->maxlen
)
2799 len
= table
->maxlen
;
2801 /* Copy up to a max of bufsize-1 bytes of the string */
2802 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2804 if (copy_to_user(oldval
, table
->data
, copied
) ||
2805 put_user(0, (char __user
*)(oldval
+ copied
)))
2807 if (put_user(len
, oldlenp
))
2811 if (newval
&& newlen
) {
2812 size_t len
= newlen
;
2813 if (len
> table
->maxlen
)
2814 len
= table
->maxlen
;
2815 if(copy_from_user(table
->data
, newval
, len
))
2817 if (len
== table
->maxlen
)
2819 ((char *) table
->data
)[len
] = 0;
2825 * This function makes sure that all of the integers in the vector
2826 * are between the minimum and maximum values given in the arrays
2827 * table->extra1 and table->extra2, respectively.
2829 int sysctl_intvec(struct ctl_table
*table
,
2830 void __user
*oldval
, size_t __user
*oldlenp
,
2831 void __user
*newval
, size_t newlen
)
2834 if (newval
&& newlen
) {
2835 int __user
*vec
= (int __user
*) newval
;
2836 int *min
= (int *) table
->extra1
;
2837 int *max
= (int *) table
->extra2
;
2841 if (newlen
% sizeof(int) != 0)
2844 if (!table
->extra1
&& !table
->extra2
)
2847 if (newlen
> table
->maxlen
)
2848 newlen
= table
->maxlen
;
2849 length
= newlen
/ sizeof(int);
2851 for (i
= 0; i
< length
; i
++) {
2853 if (get_user(value
, vec
+ i
))
2855 if (min
&& value
< min
[i
])
2857 if (max
&& value
> max
[i
])
2864 /* Strategy function to convert jiffies to seconds */
2865 int sysctl_jiffies(struct ctl_table
*table
,
2866 void __user
*oldval
, size_t __user
*oldlenp
,
2867 void __user
*newval
, size_t newlen
)
2869 if (oldval
&& oldlenp
) {
2872 if (get_user(olen
, oldlenp
))
2877 if (olen
< sizeof(int))
2880 val
= *(int *)(table
->data
) / HZ
;
2881 if (put_user(val
, (int __user
*)oldval
))
2883 if (put_user(sizeof(int), oldlenp
))
2887 if (newval
&& newlen
) {
2889 if (newlen
!= sizeof(int))
2891 if (get_user(new, (int __user
*)newval
))
2893 *(int *)(table
->data
) = new*HZ
;
2898 /* Strategy function to convert jiffies to seconds */
2899 int sysctl_ms_jiffies(struct ctl_table
*table
,
2900 void __user
*oldval
, size_t __user
*oldlenp
,
2901 void __user
*newval
, size_t newlen
)
2903 if (oldval
&& oldlenp
) {
2906 if (get_user(olen
, oldlenp
))
2911 if (olen
< sizeof(int))
2914 val
= jiffies_to_msecs(*(int *)(table
->data
));
2915 if (put_user(val
, (int __user
*)oldval
))
2917 if (put_user(sizeof(int), oldlenp
))
2921 if (newval
&& newlen
) {
2923 if (newlen
!= sizeof(int))
2925 if (get_user(new, (int __user
*)newval
))
2927 *(int *)(table
->data
) = msecs_to_jiffies(new);
2934 #else /* CONFIG_SYSCTL_SYSCALL */
2937 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2939 struct __sysctl_args tmp
;
2942 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
2945 error
= deprecated_sysctl_warning(&tmp
);
2947 /* If no error reading the parameters then just -ENOSYS ... */
2954 int sysctl_data(struct ctl_table
*table
,
2955 void __user
*oldval
, size_t __user
*oldlenp
,
2956 void __user
*newval
, size_t newlen
)
2961 int sysctl_string(struct ctl_table
*table
,
2962 void __user
*oldval
, size_t __user
*oldlenp
,
2963 void __user
*newval
, size_t newlen
)
2968 int sysctl_intvec(struct ctl_table
*table
,
2969 void __user
*oldval
, size_t __user
*oldlenp
,
2970 void __user
*newval
, size_t newlen
)
2975 int sysctl_jiffies(struct ctl_table
*table
,
2976 void __user
*oldval
, size_t __user
*oldlenp
,
2977 void __user
*newval
, size_t newlen
)
2982 int sysctl_ms_jiffies(struct ctl_table
*table
,
2983 void __user
*oldval
, size_t __user
*oldlenp
,
2984 void __user
*newval
, size_t newlen
)
2989 #endif /* CONFIG_SYSCTL_SYSCALL */
2991 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
2993 static int msg_count
;
2994 int name
[CTL_MAXNAME
];
2997 /* Check args->nlen. */
2998 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
3001 /* Read in the sysctl name for better debug message logging */
3002 for (i
= 0; i
< args
->nlen
; i
++)
3003 if (get_user(name
[i
], args
->name
+ i
))
3006 /* Ignore accesses to kernel.version */
3007 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
3010 if (msg_count
< 5) {
3013 "warning: process `%s' used the deprecated sysctl "
3014 "system call with ", current
->comm
);
3015 for (i
= 0; i
< args
->nlen
; i
++)
3016 printk("%d.", name
[i
]);
3023 * No sense putting this after each symbol definition, twice,
3024 * exception granted :-)
3026 EXPORT_SYMBOL(proc_dointvec
);
3027 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3028 EXPORT_SYMBOL(proc_dointvec_minmax
);
3029 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3030 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3031 EXPORT_SYMBOL(proc_dostring
);
3032 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3033 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
3034 EXPORT_SYMBOL(register_sysctl_table
);
3035 EXPORT_SYMBOL(register_sysctl_paths
);
3036 EXPORT_SYMBOL(sysctl_intvec
);
3037 EXPORT_SYMBOL(sysctl_jiffies
);
3038 EXPORT_SYMBOL(sysctl_ms_jiffies
);
3039 EXPORT_SYMBOL(sysctl_string
);
3040 EXPORT_SYMBOL(sysctl_data
);
3041 EXPORT_SYMBOL(unregister_sysctl_table
);