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 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
181 int sysctl_legacy_va_layout
;
184 extern int prove_locking
;
185 extern int lock_stat
;
187 /* The default sysctl tables: */
189 static struct ctl_table root_table
[] = {
191 .ctl_name
= CTL_KERN
,
192 .procname
= "kernel",
209 .ctl_name
= CTL_DEBUG
,
212 .child
= debug_table
,
221 * NOTE: do not add new entries to this table unless you have read
222 * Documentation/sysctl/ctl_unnumbered.txt
227 #ifdef CONFIG_SCHED_DEBUG
228 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
229 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
230 static int min_wakeup_granularity_ns
; /* 0 usecs */
231 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
234 static struct ctl_table kern_table
[] = {
235 #ifdef CONFIG_SCHED_DEBUG
237 .ctl_name
= CTL_UNNUMBERED
,
238 .procname
= "sched_min_granularity_ns",
239 .data
= &sysctl_sched_min_granularity
,
240 .maxlen
= sizeof(unsigned int),
242 .proc_handler
= &sched_nr_latency_handler
,
243 .strategy
= &sysctl_intvec
,
244 .extra1
= &min_sched_granularity_ns
,
245 .extra2
= &max_sched_granularity_ns
,
248 .ctl_name
= CTL_UNNUMBERED
,
249 .procname
= "sched_latency_ns",
250 .data
= &sysctl_sched_latency
,
251 .maxlen
= sizeof(unsigned int),
253 .proc_handler
= &sched_nr_latency_handler
,
254 .strategy
= &sysctl_intvec
,
255 .extra1
= &min_sched_granularity_ns
,
256 .extra2
= &max_sched_granularity_ns
,
259 .ctl_name
= CTL_UNNUMBERED
,
260 .procname
= "sched_wakeup_granularity_ns",
261 .data
= &sysctl_sched_wakeup_granularity
,
262 .maxlen
= sizeof(unsigned int),
264 .proc_handler
= &proc_dointvec_minmax
,
265 .strategy
= &sysctl_intvec
,
266 .extra1
= &min_wakeup_granularity_ns
,
267 .extra2
= &max_wakeup_granularity_ns
,
270 .ctl_name
= CTL_UNNUMBERED
,
271 .procname
= "sched_shares_ratelimit",
272 .data
= &sysctl_sched_shares_ratelimit
,
273 .maxlen
= sizeof(unsigned int),
275 .proc_handler
= &proc_dointvec
,
278 .ctl_name
= CTL_UNNUMBERED
,
279 .procname
= "sched_shares_thresh",
280 .data
= &sysctl_sched_shares_thresh
,
281 .maxlen
= sizeof(unsigned int),
283 .proc_handler
= &proc_dointvec_minmax
,
284 .strategy
= &sysctl_intvec
,
288 .ctl_name
= CTL_UNNUMBERED
,
289 .procname
= "sched_child_runs_first",
290 .data
= &sysctl_sched_child_runs_first
,
291 .maxlen
= sizeof(unsigned int),
293 .proc_handler
= &proc_dointvec
,
296 .ctl_name
= CTL_UNNUMBERED
,
297 .procname
= "sched_features",
298 .data
= &sysctl_sched_features
,
299 .maxlen
= sizeof(unsigned int),
301 .proc_handler
= &proc_dointvec
,
304 .ctl_name
= CTL_UNNUMBERED
,
305 .procname
= "sched_migration_cost",
306 .data
= &sysctl_sched_migration_cost
,
307 .maxlen
= sizeof(unsigned int),
309 .proc_handler
= &proc_dointvec
,
312 .ctl_name
= CTL_UNNUMBERED
,
313 .procname
= "sched_nr_migrate",
314 .data
= &sysctl_sched_nr_migrate
,
315 .maxlen
= sizeof(unsigned int),
317 .proc_handler
= &proc_dointvec
,
321 .ctl_name
= CTL_UNNUMBERED
,
322 .procname
= "sched_rt_period_us",
323 .data
= &sysctl_sched_rt_period
,
324 .maxlen
= sizeof(unsigned int),
326 .proc_handler
= &sched_rt_handler
,
329 .ctl_name
= CTL_UNNUMBERED
,
330 .procname
= "sched_rt_runtime_us",
331 .data
= &sysctl_sched_rt_runtime
,
332 .maxlen
= sizeof(int),
334 .proc_handler
= &sched_rt_handler
,
337 .ctl_name
= CTL_UNNUMBERED
,
338 .procname
= "sched_compat_yield",
339 .data
= &sysctl_sched_compat_yield
,
340 .maxlen
= sizeof(unsigned int),
342 .proc_handler
= &proc_dointvec
,
344 #ifdef CONFIG_PROVE_LOCKING
346 .ctl_name
= CTL_UNNUMBERED
,
347 .procname
= "prove_locking",
348 .data
= &prove_locking
,
349 .maxlen
= sizeof(int),
351 .proc_handler
= &proc_dointvec
,
354 #ifdef CONFIG_LOCK_STAT
356 .ctl_name
= CTL_UNNUMBERED
,
357 .procname
= "lock_stat",
359 .maxlen
= sizeof(int),
361 .proc_handler
= &proc_dointvec
,
365 .ctl_name
= KERN_PANIC
,
367 .data
= &panic_timeout
,
368 .maxlen
= sizeof(int),
370 .proc_handler
= &proc_dointvec
,
373 .ctl_name
= KERN_CORE_USES_PID
,
374 .procname
= "core_uses_pid",
375 .data
= &core_uses_pid
,
376 .maxlen
= sizeof(int),
378 .proc_handler
= &proc_dointvec
,
381 .ctl_name
= KERN_CORE_PATTERN
,
382 .procname
= "core_pattern",
383 .data
= core_pattern
,
384 .maxlen
= CORENAME_MAX_SIZE
,
386 .proc_handler
= &proc_dostring
,
387 .strategy
= &sysctl_string
,
389 #ifdef CONFIG_PROC_SYSCTL
391 .procname
= "tainted",
392 .maxlen
= sizeof(long),
394 .proc_handler
= &proc_taint
,
397 #ifdef CONFIG_LATENCYTOP
399 .procname
= "latencytop",
400 .data
= &latencytop_enabled
,
401 .maxlen
= sizeof(int),
403 .proc_handler
= &proc_dointvec
,
406 #ifdef CONFIG_BLK_DEV_INITRD
408 .ctl_name
= KERN_REALROOTDEV
,
409 .procname
= "real-root-dev",
410 .data
= &real_root_dev
,
411 .maxlen
= sizeof(int),
413 .proc_handler
= &proc_dointvec
,
417 .ctl_name
= CTL_UNNUMBERED
,
418 .procname
= "print-fatal-signals",
419 .data
= &print_fatal_signals
,
420 .maxlen
= sizeof(int),
422 .proc_handler
= &proc_dointvec
,
426 .ctl_name
= KERN_SPARC_REBOOT
,
427 .procname
= "reboot-cmd",
428 .data
= reboot_command
,
431 .proc_handler
= &proc_dostring
,
432 .strategy
= &sysctl_string
,
435 .ctl_name
= KERN_SPARC_STOP_A
,
436 .procname
= "stop-a",
437 .data
= &stop_a_enabled
,
438 .maxlen
= sizeof (int),
440 .proc_handler
= &proc_dointvec
,
443 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
444 .procname
= "scons-poweroff",
445 .data
= &scons_pwroff
,
446 .maxlen
= sizeof (int),
448 .proc_handler
= &proc_dointvec
,
453 .ctl_name
= KERN_HPPA_PWRSW
,
454 .procname
= "soft-power",
455 .data
= &pwrsw_enabled
,
456 .maxlen
= sizeof (int),
458 .proc_handler
= &proc_dointvec
,
461 .ctl_name
= KERN_HPPA_UNALIGNED
,
462 .procname
= "unaligned-trap",
463 .data
= &unaligned_enabled
,
464 .maxlen
= sizeof (int),
466 .proc_handler
= &proc_dointvec
,
470 .ctl_name
= KERN_CTLALTDEL
,
471 .procname
= "ctrl-alt-del",
473 .maxlen
= sizeof(int),
475 .proc_handler
= &proc_dointvec
,
477 #ifdef CONFIG_FUNCTION_TRACER
479 .ctl_name
= CTL_UNNUMBERED
,
480 .procname
= "ftrace_enabled",
481 .data
= &ftrace_enabled
,
482 .maxlen
= sizeof(int),
484 .proc_handler
= &ftrace_enable_sysctl
,
487 #ifdef CONFIG_MODULES
489 .ctl_name
= KERN_MODPROBE
,
490 .procname
= "modprobe",
491 .data
= &modprobe_path
,
492 .maxlen
= KMOD_PATH_LEN
,
494 .proc_handler
= &proc_dostring
,
495 .strategy
= &sysctl_string
,
498 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
500 .ctl_name
= KERN_HOTPLUG
,
501 .procname
= "hotplug",
502 .data
= &uevent_helper
,
503 .maxlen
= UEVENT_HELPER_PATH_LEN
,
505 .proc_handler
= &proc_dostring
,
506 .strategy
= &sysctl_string
,
509 #ifdef CONFIG_CHR_DEV_SG
511 .ctl_name
= KERN_SG_BIG_BUFF
,
512 .procname
= "sg-big-buff",
513 .data
= &sg_big_buff
,
514 .maxlen
= sizeof (int),
516 .proc_handler
= &proc_dointvec
,
519 #ifdef CONFIG_BSD_PROCESS_ACCT
521 .ctl_name
= KERN_ACCT
,
524 .maxlen
= 3*sizeof(int),
526 .proc_handler
= &proc_dointvec
,
529 #ifdef CONFIG_MAGIC_SYSRQ
531 .ctl_name
= KERN_SYSRQ
,
533 .data
= &__sysrq_enabled
,
534 .maxlen
= sizeof (int),
536 .proc_handler
= &proc_dointvec
,
539 #ifdef CONFIG_PROC_SYSCTL
541 .procname
= "cad_pid",
543 .maxlen
= sizeof (int),
545 .proc_handler
= &proc_do_cad_pid
,
549 .ctl_name
= KERN_MAX_THREADS
,
550 .procname
= "threads-max",
551 .data
= &max_threads
,
552 .maxlen
= sizeof(int),
554 .proc_handler
= &proc_dointvec
,
557 .ctl_name
= KERN_RANDOM
,
558 .procname
= "random",
560 .child
= random_table
,
563 .ctl_name
= KERN_OVERFLOWUID
,
564 .procname
= "overflowuid",
565 .data
= &overflowuid
,
566 .maxlen
= sizeof(int),
568 .proc_handler
= &proc_dointvec_minmax
,
569 .strategy
= &sysctl_intvec
,
570 .extra1
= &minolduid
,
571 .extra2
= &maxolduid
,
574 .ctl_name
= KERN_OVERFLOWGID
,
575 .procname
= "overflowgid",
576 .data
= &overflowgid
,
577 .maxlen
= sizeof(int),
579 .proc_handler
= &proc_dointvec_minmax
,
580 .strategy
= &sysctl_intvec
,
581 .extra1
= &minolduid
,
582 .extra2
= &maxolduid
,
585 #ifdef CONFIG_MATHEMU
587 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
588 .procname
= "ieee_emulation_warnings",
589 .data
= &sysctl_ieee_emulation_warnings
,
590 .maxlen
= sizeof(int),
592 .proc_handler
= &proc_dointvec
,
596 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
597 .procname
= "userprocess_debug",
598 .data
= &sysctl_userprocess_debug
,
599 .maxlen
= sizeof(int),
601 .proc_handler
= &proc_dointvec
,
605 .ctl_name
= KERN_PIDMAX
,
606 .procname
= "pid_max",
608 .maxlen
= sizeof (int),
610 .proc_handler
= &proc_dointvec_minmax
,
611 .strategy
= sysctl_intvec
,
612 .extra1
= &pid_max_min
,
613 .extra2
= &pid_max_max
,
616 .ctl_name
= KERN_PANIC_ON_OOPS
,
617 .procname
= "panic_on_oops",
618 .data
= &panic_on_oops
,
619 .maxlen
= sizeof(int),
621 .proc_handler
= &proc_dointvec
,
623 #if defined CONFIG_PRINTK
625 .ctl_name
= KERN_PRINTK
,
626 .procname
= "printk",
627 .data
= &console_loglevel
,
628 .maxlen
= 4*sizeof(int),
630 .proc_handler
= &proc_dointvec
,
633 .ctl_name
= KERN_PRINTK_RATELIMIT
,
634 .procname
= "printk_ratelimit",
635 .data
= &printk_ratelimit_state
.interval
,
636 .maxlen
= sizeof(int),
638 .proc_handler
= &proc_dointvec_jiffies
,
639 .strategy
= &sysctl_jiffies
,
642 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
643 .procname
= "printk_ratelimit_burst",
644 .data
= &printk_ratelimit_state
.burst
,
645 .maxlen
= sizeof(int),
647 .proc_handler
= &proc_dointvec
,
651 .ctl_name
= KERN_NGROUPS_MAX
,
652 .procname
= "ngroups_max",
653 .data
= &ngroups_max
,
654 .maxlen
= sizeof (int),
656 .proc_handler
= &proc_dointvec
,
658 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
660 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
661 .procname
= "unknown_nmi_panic",
662 .data
= &unknown_nmi_panic
,
663 .maxlen
= sizeof (int),
665 .proc_handler
= &proc_dointvec
,
668 .procname
= "nmi_watchdog",
669 .data
= &nmi_watchdog_enabled
,
670 .maxlen
= sizeof (int),
672 .proc_handler
= &proc_nmi_enabled
,
675 #if defined(CONFIG_X86)
677 .ctl_name
= KERN_PANIC_ON_NMI
,
678 .procname
= "panic_on_unrecovered_nmi",
679 .data
= &panic_on_unrecovered_nmi
,
680 .maxlen
= sizeof(int),
682 .proc_handler
= &proc_dointvec
,
685 .ctl_name
= KERN_BOOTLOADER_TYPE
,
686 .procname
= "bootloader_type",
687 .data
= &bootloader_type
,
688 .maxlen
= sizeof (int),
690 .proc_handler
= &proc_dointvec
,
693 .ctl_name
= CTL_UNNUMBERED
,
694 .procname
= "kstack_depth_to_print",
695 .data
= &kstack_depth_to_print
,
696 .maxlen
= sizeof(int),
698 .proc_handler
= &proc_dointvec
,
701 .ctl_name
= CTL_UNNUMBERED
,
702 .procname
= "io_delay_type",
703 .data
= &io_delay_type
,
704 .maxlen
= sizeof(int),
706 .proc_handler
= &proc_dointvec
,
709 #if defined(CONFIG_MMU)
711 .ctl_name
= KERN_RANDOMIZE
,
712 .procname
= "randomize_va_space",
713 .data
= &randomize_va_space
,
714 .maxlen
= sizeof(int),
716 .proc_handler
= &proc_dointvec
,
719 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
721 .ctl_name
= KERN_SPIN_RETRY
,
722 .procname
= "spin_retry",
724 .maxlen
= sizeof (int),
726 .proc_handler
= &proc_dointvec
,
729 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
731 .procname
= "acpi_video_flags",
732 .data
= &acpi_realmode_flags
,
733 .maxlen
= sizeof (unsigned long),
735 .proc_handler
= &proc_doulongvec_minmax
,
740 .ctl_name
= KERN_IA64_UNALIGNED
,
741 .procname
= "ignore-unaligned-usertrap",
742 .data
= &no_unaligned_warning
,
743 .maxlen
= sizeof (int),
745 .proc_handler
= &proc_dointvec
,
748 #ifdef CONFIG_DETECT_SOFTLOCKUP
750 .ctl_name
= CTL_UNNUMBERED
,
751 .procname
= "softlockup_panic",
752 .data
= &softlockup_panic
,
753 .maxlen
= sizeof(int),
755 .proc_handler
= &proc_dointvec_minmax
,
756 .strategy
= &sysctl_intvec
,
761 .ctl_name
= CTL_UNNUMBERED
,
762 .procname
= "softlockup_thresh",
763 .data
= &softlockup_thresh
,
764 .maxlen
= sizeof(int),
766 .proc_handler
= &proc_dointvec_minmax
,
767 .strategy
= &sysctl_intvec
,
772 .ctl_name
= CTL_UNNUMBERED
,
773 .procname
= "hung_task_check_count",
774 .data
= &sysctl_hung_task_check_count
,
775 .maxlen
= sizeof(unsigned long),
777 .proc_handler
= &proc_doulongvec_minmax
,
778 .strategy
= &sysctl_intvec
,
781 .ctl_name
= CTL_UNNUMBERED
,
782 .procname
= "hung_task_timeout_secs",
783 .data
= &sysctl_hung_task_timeout_secs
,
784 .maxlen
= sizeof(unsigned long),
786 .proc_handler
= &proc_doulongvec_minmax
,
787 .strategy
= &sysctl_intvec
,
790 .ctl_name
= CTL_UNNUMBERED
,
791 .procname
= "hung_task_warnings",
792 .data
= &sysctl_hung_task_warnings
,
793 .maxlen
= sizeof(unsigned long),
795 .proc_handler
= &proc_doulongvec_minmax
,
796 .strategy
= &sysctl_intvec
,
801 .ctl_name
= KERN_COMPAT_LOG
,
802 .procname
= "compat-log",
804 .maxlen
= sizeof (int),
806 .proc_handler
= &proc_dointvec
,
809 #ifdef CONFIG_RT_MUTEXES
811 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
812 .procname
= "max_lock_depth",
813 .data
= &max_lock_depth
,
814 .maxlen
= sizeof(int),
816 .proc_handler
= &proc_dointvec
,
820 .ctl_name
= CTL_UNNUMBERED
,
821 .procname
= "poweroff_cmd",
822 .data
= &poweroff_cmd
,
823 .maxlen
= POWEROFF_CMD_PATH_LEN
,
825 .proc_handler
= &proc_dostring
,
826 .strategy
= &sysctl_string
,
830 .ctl_name
= CTL_UNNUMBERED
,
833 .child
= key_sysctls
,
836 #ifdef CONFIG_RCU_TORTURE_TEST
838 .ctl_name
= CTL_UNNUMBERED
,
839 .procname
= "rcutorture_runnable",
840 .data
= &rcutorture_runnable
,
841 .maxlen
= sizeof(int),
843 .proc_handler
= &proc_dointvec
,
846 #ifdef CONFIG_UNEVICTABLE_LRU
848 .ctl_name
= CTL_UNNUMBERED
,
849 .procname
= "scan_unevictable_pages",
850 .data
= &scan_unevictable_pages
,
851 .maxlen
= sizeof(scan_unevictable_pages
),
853 .proc_handler
= &scan_unevictable_handler
,
857 * NOTE: do not add new entries to this table unless you have read
858 * Documentation/sysctl/ctl_unnumbered.txt
863 static struct ctl_table vm_table
[] = {
865 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
866 .procname
= "overcommit_memory",
867 .data
= &sysctl_overcommit_memory
,
868 .maxlen
= sizeof(sysctl_overcommit_memory
),
870 .proc_handler
= &proc_dointvec
,
873 .ctl_name
= VM_PANIC_ON_OOM
,
874 .procname
= "panic_on_oom",
875 .data
= &sysctl_panic_on_oom
,
876 .maxlen
= sizeof(sysctl_panic_on_oom
),
878 .proc_handler
= &proc_dointvec
,
881 .ctl_name
= CTL_UNNUMBERED
,
882 .procname
= "oom_kill_allocating_task",
883 .data
= &sysctl_oom_kill_allocating_task
,
884 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
886 .proc_handler
= &proc_dointvec
,
889 .ctl_name
= CTL_UNNUMBERED
,
890 .procname
= "oom_dump_tasks",
891 .data
= &sysctl_oom_dump_tasks
,
892 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
894 .proc_handler
= &proc_dointvec
,
897 .ctl_name
= VM_OVERCOMMIT_RATIO
,
898 .procname
= "overcommit_ratio",
899 .data
= &sysctl_overcommit_ratio
,
900 .maxlen
= sizeof(sysctl_overcommit_ratio
),
902 .proc_handler
= &proc_dointvec
,
905 .ctl_name
= VM_PAGE_CLUSTER
,
906 .procname
= "page-cluster",
907 .data
= &page_cluster
,
908 .maxlen
= sizeof(int),
910 .proc_handler
= &proc_dointvec
,
913 .ctl_name
= VM_DIRTY_BACKGROUND
,
914 .procname
= "dirty_background_ratio",
915 .data
= &dirty_background_ratio
,
916 .maxlen
= sizeof(dirty_background_ratio
),
918 .proc_handler
= &proc_dointvec_minmax
,
919 .strategy
= &sysctl_intvec
,
921 .extra2
= &one_hundred
,
924 .ctl_name
= VM_DIRTY_RATIO
,
925 .procname
= "dirty_ratio",
926 .data
= &vm_dirty_ratio
,
927 .maxlen
= sizeof(vm_dirty_ratio
),
929 .proc_handler
= &dirty_ratio_handler
,
930 .strategy
= &sysctl_intvec
,
932 .extra2
= &one_hundred
,
935 .procname
= "dirty_writeback_centisecs",
936 .data
= &dirty_writeback_interval
,
937 .maxlen
= sizeof(dirty_writeback_interval
),
939 .proc_handler
= &dirty_writeback_centisecs_handler
,
942 .procname
= "dirty_expire_centisecs",
943 .data
= &dirty_expire_interval
,
944 .maxlen
= sizeof(dirty_expire_interval
),
946 .proc_handler
= &proc_dointvec_userhz_jiffies
,
949 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
950 .procname
= "nr_pdflush_threads",
951 .data
= &nr_pdflush_threads
,
952 .maxlen
= sizeof nr_pdflush_threads
,
953 .mode
= 0444 /* read-only*/,
954 .proc_handler
= &proc_dointvec
,
957 .ctl_name
= VM_SWAPPINESS
,
958 .procname
= "swappiness",
959 .data
= &vm_swappiness
,
960 .maxlen
= sizeof(vm_swappiness
),
962 .proc_handler
= &proc_dointvec_minmax
,
963 .strategy
= &sysctl_intvec
,
965 .extra2
= &one_hundred
,
967 #ifdef CONFIG_HUGETLB_PAGE
969 .procname
= "nr_hugepages",
971 .maxlen
= sizeof(unsigned long),
973 .proc_handler
= &hugetlb_sysctl_handler
,
974 .extra1
= (void *)&hugetlb_zero
,
975 .extra2
= (void *)&hugetlb_infinity
,
978 .ctl_name
= VM_HUGETLB_GROUP
,
979 .procname
= "hugetlb_shm_group",
980 .data
= &sysctl_hugetlb_shm_group
,
981 .maxlen
= sizeof(gid_t
),
983 .proc_handler
= &proc_dointvec
,
986 .ctl_name
= CTL_UNNUMBERED
,
987 .procname
= "hugepages_treat_as_movable",
988 .data
= &hugepages_treat_as_movable
,
989 .maxlen
= sizeof(int),
991 .proc_handler
= &hugetlb_treat_movable_handler
,
994 .ctl_name
= CTL_UNNUMBERED
,
995 .procname
= "nr_overcommit_hugepages",
997 .maxlen
= sizeof(unsigned long),
999 .proc_handler
= &hugetlb_overcommit_handler
,
1000 .extra1
= (void *)&hugetlb_zero
,
1001 .extra2
= (void *)&hugetlb_infinity
,
1005 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
1006 .procname
= "lowmem_reserve_ratio",
1007 .data
= &sysctl_lowmem_reserve_ratio
,
1008 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1010 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
1011 .strategy
= &sysctl_intvec
,
1014 .ctl_name
= VM_DROP_PAGECACHE
,
1015 .procname
= "drop_caches",
1016 .data
= &sysctl_drop_caches
,
1017 .maxlen
= sizeof(int),
1019 .proc_handler
= drop_caches_sysctl_handler
,
1020 .strategy
= &sysctl_intvec
,
1023 .ctl_name
= VM_MIN_FREE_KBYTES
,
1024 .procname
= "min_free_kbytes",
1025 .data
= &min_free_kbytes
,
1026 .maxlen
= sizeof(min_free_kbytes
),
1028 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1029 .strategy
= &sysctl_intvec
,
1033 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1034 .procname
= "percpu_pagelist_fraction",
1035 .data
= &percpu_pagelist_fraction
,
1036 .maxlen
= sizeof(percpu_pagelist_fraction
),
1038 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1039 .strategy
= &sysctl_intvec
,
1040 .extra1
= &min_percpu_pagelist_fract
,
1044 .ctl_name
= VM_MAX_MAP_COUNT
,
1045 .procname
= "max_map_count",
1046 .data
= &sysctl_max_map_count
,
1047 .maxlen
= sizeof(sysctl_max_map_count
),
1049 .proc_handler
= &proc_dointvec
1053 .ctl_name
= VM_LAPTOP_MODE
,
1054 .procname
= "laptop_mode",
1055 .data
= &laptop_mode
,
1056 .maxlen
= sizeof(laptop_mode
),
1058 .proc_handler
= &proc_dointvec_jiffies
,
1059 .strategy
= &sysctl_jiffies
,
1062 .ctl_name
= VM_BLOCK_DUMP
,
1063 .procname
= "block_dump",
1064 .data
= &block_dump
,
1065 .maxlen
= sizeof(block_dump
),
1067 .proc_handler
= &proc_dointvec
,
1068 .strategy
= &sysctl_intvec
,
1072 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1073 .procname
= "vfs_cache_pressure",
1074 .data
= &sysctl_vfs_cache_pressure
,
1075 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1077 .proc_handler
= &proc_dointvec
,
1078 .strategy
= &sysctl_intvec
,
1081 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1083 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1084 .procname
= "legacy_va_layout",
1085 .data
= &sysctl_legacy_va_layout
,
1086 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1088 .proc_handler
= &proc_dointvec
,
1089 .strategy
= &sysctl_intvec
,
1095 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1096 .procname
= "zone_reclaim_mode",
1097 .data
= &zone_reclaim_mode
,
1098 .maxlen
= sizeof(zone_reclaim_mode
),
1100 .proc_handler
= &proc_dointvec
,
1101 .strategy
= &sysctl_intvec
,
1105 .ctl_name
= VM_MIN_UNMAPPED
,
1106 .procname
= "min_unmapped_ratio",
1107 .data
= &sysctl_min_unmapped_ratio
,
1108 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1110 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1111 .strategy
= &sysctl_intvec
,
1113 .extra2
= &one_hundred
,
1116 .ctl_name
= VM_MIN_SLAB
,
1117 .procname
= "min_slab_ratio",
1118 .data
= &sysctl_min_slab_ratio
,
1119 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1121 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1122 .strategy
= &sysctl_intvec
,
1124 .extra2
= &one_hundred
,
1129 .ctl_name
= CTL_UNNUMBERED
,
1130 .procname
= "stat_interval",
1131 .data
= &sysctl_stat_interval
,
1132 .maxlen
= sizeof(sysctl_stat_interval
),
1134 .proc_handler
= &proc_dointvec_jiffies
,
1135 .strategy
= &sysctl_jiffies
,
1138 #ifdef CONFIG_SECURITY
1140 .ctl_name
= CTL_UNNUMBERED
,
1141 .procname
= "mmap_min_addr",
1142 .data
= &mmap_min_addr
,
1143 .maxlen
= sizeof(unsigned long),
1145 .proc_handler
= &proc_doulongvec_minmax
,
1150 .ctl_name
= CTL_UNNUMBERED
,
1151 .procname
= "numa_zonelist_order",
1152 .data
= &numa_zonelist_order
,
1153 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1155 .proc_handler
= &numa_zonelist_order_handler
,
1156 .strategy
= &sysctl_string
,
1159 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1160 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1162 .ctl_name
= VM_VDSO_ENABLED
,
1163 .procname
= "vdso_enabled",
1164 .data
= &vdso_enabled
,
1165 .maxlen
= sizeof(vdso_enabled
),
1167 .proc_handler
= &proc_dointvec
,
1168 .strategy
= &sysctl_intvec
,
1172 #ifdef CONFIG_HIGHMEM
1174 .ctl_name
= CTL_UNNUMBERED
,
1175 .procname
= "highmem_is_dirtyable",
1176 .data
= &vm_highmem_is_dirtyable
,
1177 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1179 .proc_handler
= &proc_dointvec_minmax
,
1180 .strategy
= &sysctl_intvec
,
1186 * NOTE: do not add new entries to this table unless you have read
1187 * Documentation/sysctl/ctl_unnumbered.txt
1192 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1193 static struct ctl_table binfmt_misc_table
[] = {
1198 static struct ctl_table fs_table
[] = {
1200 .ctl_name
= FS_NRINODE
,
1201 .procname
= "inode-nr",
1202 .data
= &inodes_stat
,
1203 .maxlen
= 2*sizeof(int),
1205 .proc_handler
= &proc_dointvec
,
1208 .ctl_name
= FS_STATINODE
,
1209 .procname
= "inode-state",
1210 .data
= &inodes_stat
,
1211 .maxlen
= 7*sizeof(int),
1213 .proc_handler
= &proc_dointvec
,
1216 .procname
= "file-nr",
1217 .data
= &files_stat
,
1218 .maxlen
= 3*sizeof(int),
1220 .proc_handler
= &proc_nr_files
,
1223 .ctl_name
= FS_MAXFILE
,
1224 .procname
= "file-max",
1225 .data
= &files_stat
.max_files
,
1226 .maxlen
= sizeof(int),
1228 .proc_handler
= &proc_dointvec
,
1231 .ctl_name
= CTL_UNNUMBERED
,
1232 .procname
= "nr_open",
1233 .data
= &sysctl_nr_open
,
1234 .maxlen
= sizeof(int),
1236 .proc_handler
= &proc_dointvec_minmax
,
1237 .extra1
= &sysctl_nr_open_min
,
1238 .extra2
= &sysctl_nr_open_max
,
1241 .ctl_name
= FS_DENTRY
,
1242 .procname
= "dentry-state",
1243 .data
= &dentry_stat
,
1244 .maxlen
= 6*sizeof(int),
1246 .proc_handler
= &proc_dointvec
,
1249 .ctl_name
= FS_OVERFLOWUID
,
1250 .procname
= "overflowuid",
1251 .data
= &fs_overflowuid
,
1252 .maxlen
= sizeof(int),
1254 .proc_handler
= &proc_dointvec_minmax
,
1255 .strategy
= &sysctl_intvec
,
1256 .extra1
= &minolduid
,
1257 .extra2
= &maxolduid
,
1260 .ctl_name
= FS_OVERFLOWGID
,
1261 .procname
= "overflowgid",
1262 .data
= &fs_overflowgid
,
1263 .maxlen
= sizeof(int),
1265 .proc_handler
= &proc_dointvec_minmax
,
1266 .strategy
= &sysctl_intvec
,
1267 .extra1
= &minolduid
,
1268 .extra2
= &maxolduid
,
1270 #ifdef CONFIG_FILE_LOCKING
1272 .ctl_name
= FS_LEASES
,
1273 .procname
= "leases-enable",
1274 .data
= &leases_enable
,
1275 .maxlen
= sizeof(int),
1277 .proc_handler
= &proc_dointvec
,
1280 #ifdef CONFIG_DNOTIFY
1282 .ctl_name
= FS_DIR_NOTIFY
,
1283 .procname
= "dir-notify-enable",
1284 .data
= &dir_notify_enable
,
1285 .maxlen
= sizeof(int),
1287 .proc_handler
= &proc_dointvec
,
1291 #ifdef CONFIG_FILE_LOCKING
1293 .ctl_name
= FS_LEASE_TIME
,
1294 .procname
= "lease-break-time",
1295 .data
= &lease_break_time
,
1296 .maxlen
= sizeof(int),
1298 .proc_handler
= &proc_dointvec_minmax
,
1299 .strategy
= &sysctl_intvec
,
1306 .procname
= "aio-nr",
1308 .maxlen
= sizeof(aio_nr
),
1310 .proc_handler
= &proc_doulongvec_minmax
,
1313 .procname
= "aio-max-nr",
1314 .data
= &aio_max_nr
,
1315 .maxlen
= sizeof(aio_max_nr
),
1317 .proc_handler
= &proc_doulongvec_minmax
,
1319 #endif /* CONFIG_AIO */
1320 #ifdef CONFIG_INOTIFY_USER
1322 .ctl_name
= FS_INOTIFY
,
1323 .procname
= "inotify",
1325 .child
= inotify_table
,
1330 .ctl_name
= KERN_SETUID_DUMPABLE
,
1331 .procname
= "suid_dumpable",
1332 .data
= &suid_dumpable
,
1333 .maxlen
= sizeof(int),
1335 .proc_handler
= &proc_dointvec
,
1337 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1339 .ctl_name
= CTL_UNNUMBERED
,
1340 .procname
= "binfmt_misc",
1342 .child
= binfmt_misc_table
,
1346 * NOTE: do not add new entries to this table unless you have read
1347 * Documentation/sysctl/ctl_unnumbered.txt
1352 static struct ctl_table debug_table
[] = {
1353 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1355 .ctl_name
= CTL_UNNUMBERED
,
1356 .procname
= "exception-trace",
1357 .data
= &show_unhandled_signals
,
1358 .maxlen
= sizeof(int),
1360 .proc_handler
= proc_dointvec
1366 static struct ctl_table dev_table
[] = {
1370 static DEFINE_SPINLOCK(sysctl_lock
);
1372 /* called under sysctl_lock */
1373 static int use_table(struct ctl_table_header
*p
)
1375 if (unlikely(p
->unregistering
))
1381 /* called under sysctl_lock */
1382 static void unuse_table(struct ctl_table_header
*p
)
1385 if (unlikely(p
->unregistering
))
1386 complete(p
->unregistering
);
1389 /* called under sysctl_lock, will reacquire if has to wait */
1390 static void start_unregistering(struct ctl_table_header
*p
)
1393 * if p->used is 0, nobody will ever touch that entry again;
1394 * we'll eliminate all paths to it before dropping sysctl_lock
1396 if (unlikely(p
->used
)) {
1397 struct completion wait
;
1398 init_completion(&wait
);
1399 p
->unregistering
= &wait
;
1400 spin_unlock(&sysctl_lock
);
1401 wait_for_completion(&wait
);
1402 spin_lock(&sysctl_lock
);
1404 /* anything non-NULL; we'll never dereference it */
1405 p
->unregistering
= ERR_PTR(-EINVAL
);
1408 * do not remove from the list until nobody holds it; walking the
1409 * list in do_sysctl() relies on that.
1411 list_del_init(&p
->ctl_entry
);
1414 void sysctl_head_get(struct ctl_table_header
*head
)
1416 spin_lock(&sysctl_lock
);
1418 spin_unlock(&sysctl_lock
);
1421 void sysctl_head_put(struct ctl_table_header
*head
)
1423 spin_lock(&sysctl_lock
);
1426 spin_unlock(&sysctl_lock
);
1429 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1433 spin_lock(&sysctl_lock
);
1434 if (!use_table(head
))
1435 head
= ERR_PTR(-ENOENT
);
1436 spin_unlock(&sysctl_lock
);
1440 void sysctl_head_finish(struct ctl_table_header
*head
)
1444 spin_lock(&sysctl_lock
);
1446 spin_unlock(&sysctl_lock
);
1449 static struct ctl_table_set
*
1450 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1452 struct ctl_table_set
*set
= &root
->default_set
;
1454 set
= root
->lookup(root
, namespaces
);
1458 static struct list_head
*
1459 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1461 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1465 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1466 struct ctl_table_header
*prev
)
1468 struct ctl_table_root
*root
;
1469 struct list_head
*header_list
;
1470 struct ctl_table_header
*head
;
1471 struct list_head
*tmp
;
1473 spin_lock(&sysctl_lock
);
1476 tmp
= &prev
->ctl_entry
;
1480 tmp
= &root_table_header
.ctl_entry
;
1482 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1484 if (!use_table(head
))
1486 spin_unlock(&sysctl_lock
);
1491 header_list
= lookup_header_list(root
, namespaces
);
1492 if (tmp
!= header_list
)
1496 root
= list_entry(root
->root_list
.next
,
1497 struct ctl_table_root
, root_list
);
1498 if (root
== &sysctl_table_root
)
1500 header_list
= lookup_header_list(root
, namespaces
);
1501 } while (list_empty(header_list
));
1502 tmp
= header_list
->next
;
1505 spin_unlock(&sysctl_lock
);
1509 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1511 return __sysctl_head_next(current
->nsproxy
, prev
);
1514 void register_sysctl_root(struct ctl_table_root
*root
)
1516 spin_lock(&sysctl_lock
);
1517 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1518 spin_unlock(&sysctl_lock
);
1521 #ifdef CONFIG_SYSCTL_SYSCALL
1522 /* Perform the actual read/write of a sysctl table entry. */
1523 static int do_sysctl_strategy(struct ctl_table_root
*root
,
1524 struct ctl_table
*table
,
1525 void __user
*oldval
, size_t __user
*oldlenp
,
1526 void __user
*newval
, size_t newlen
)
1534 if (sysctl_perm(root
, table
, op
))
1537 if (table
->strategy
) {
1538 rc
= table
->strategy(table
, oldval
, oldlenp
, newval
, newlen
);
1545 /* If there is no strategy routine, or if the strategy returns
1546 * zero, proceed with automatic r/w */
1547 if (table
->data
&& table
->maxlen
) {
1548 rc
= sysctl_data(table
, oldval
, oldlenp
, newval
, newlen
);
1555 static int parse_table(int __user
*name
, int nlen
,
1556 void __user
*oldval
, size_t __user
*oldlenp
,
1557 void __user
*newval
, size_t newlen
,
1558 struct ctl_table_root
*root
,
1559 struct ctl_table
*table
)
1565 if (get_user(n
, name
))
1567 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1568 if (!table
->ctl_name
)
1570 if (n
== table
->ctl_name
) {
1573 if (sysctl_perm(root
, table
, MAY_EXEC
))
1577 table
= table
->child
;
1580 error
= do_sysctl_strategy(root
, table
,
1589 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1590 void __user
*newval
, size_t newlen
)
1592 struct ctl_table_header
*head
;
1593 int error
= -ENOTDIR
;
1595 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1599 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1603 for (head
= sysctl_head_next(NULL
); head
;
1604 head
= sysctl_head_next(head
)) {
1605 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1607 head
->root
, head
->ctl_table
);
1608 if (error
!= -ENOTDIR
) {
1609 sysctl_head_finish(head
);
1616 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1618 struct __sysctl_args tmp
;
1621 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1624 error
= deprecated_sysctl_warning(&tmp
);
1629 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1630 tmp
.newval
, tmp
.newlen
);
1635 #endif /* CONFIG_SYSCTL_SYSCALL */
1638 * sysctl_perm does NOT grant the superuser all rights automatically, because
1639 * some sysctl variables are readonly even to root.
1642 static int test_perm(int mode
, int op
)
1646 else if (in_egroup_p(0))
1648 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1653 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1658 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1662 if (root
->permissions
)
1663 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1667 return test_perm(mode
, op
);
1670 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1672 for (; table
->ctl_name
|| table
->procname
; table
++) {
1673 table
->parent
= parent
;
1675 sysctl_set_parent(table
, table
->child
);
1679 static __init
int sysctl_init(void)
1681 sysctl_set_parent(NULL
, root_table
);
1682 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1685 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1691 core_initcall(sysctl_init
);
1693 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1694 struct ctl_table
*table
)
1696 struct ctl_table
*p
;
1697 const char *s
= branch
->procname
;
1699 /* branch should have named subdirectory as its first element */
1700 if (!s
|| !branch
->child
)
1703 /* ... and nothing else */
1704 if (branch
[1].procname
|| branch
[1].ctl_name
)
1707 /* table should contain subdirectory with the same name */
1708 for (p
= table
; p
->procname
|| p
->ctl_name
; p
++) {
1711 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1717 /* see if attaching q to p would be an improvement */
1718 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1720 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1721 struct ctl_table
*next
;
1723 int not_in_parent
= !p
->attached_by
;
1725 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1726 if (by
== q
->attached_by
)
1728 if (to
== p
->attached_by
)
1734 if (is_better
&& not_in_parent
) {
1735 q
->attached_by
= by
;
1736 q
->attached_to
= to
;
1742 * __register_sysctl_paths - register a sysctl hierarchy
1743 * @root: List of sysctl headers to register on
1744 * @namespaces: Data to compute which lists of sysctl entries are visible
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 * The members of the &struct ctl_table structure are used as follows:
1753 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1754 * must be unique within that level of sysctl
1756 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1757 * enter a sysctl file
1759 * data - a pointer to data for use by proc_handler
1761 * maxlen - the maximum size in bytes of the data
1763 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1765 * child - a pointer to the child sysctl table if this entry is a directory, or
1768 * proc_handler - the text handler routine (described below)
1770 * strategy - the strategy routine (described below)
1772 * de - for internal use by the sysctl routines
1774 * extra1, extra2 - extra pointers usable by the proc handler routines
1776 * Leaf nodes in the sysctl tree will be represented by a single file
1777 * under /proc; non-leaf nodes will be represented by directories.
1779 * sysctl(2) can automatically manage read and write requests through
1780 * the sysctl table. The data and maxlen fields of the ctl_table
1781 * struct enable minimal validation of the values being written to be
1782 * performed, and the mode field allows minimal authentication.
1784 * More sophisticated management can be enabled by the provision of a
1785 * strategy routine with the table entry. This will be called before
1786 * any automatic read or write of the data is performed.
1788 * The strategy routine may return
1790 * < 0 - Error occurred (error is passed to user process)
1792 * 0 - OK - proceed with automatic read or write.
1794 * > 0 - OK - read or write has been done by the strategy routine, so
1795 * return immediately.
1797 * There must be a proc_handler routine for any terminal nodes
1798 * mirrored under /proc/sys (non-terminals are handled by a built-in
1799 * directory handler). Several default handlers are available to
1800 * cover common cases -
1802 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1803 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1804 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1806 * It is the handler's job to read the input buffer from user memory
1807 * and process it. The handler should return 0 on success.
1809 * This routine returns %NULL on a failure to register, and a pointer
1810 * to the table header on success.
1812 struct ctl_table_header
*__register_sysctl_paths(
1813 struct ctl_table_root
*root
,
1814 struct nsproxy
*namespaces
,
1815 const struct ctl_path
*path
, struct ctl_table
*table
)
1817 struct ctl_table_header
*header
;
1818 struct ctl_table
*new, **prevp
;
1819 unsigned int n
, npath
;
1820 struct ctl_table_set
*set
;
1822 /* Count the path components */
1823 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
1827 * For each path component, allocate a 2-element ctl_table array.
1828 * The first array element will be filled with the sysctl entry
1829 * for this, the second will be the sentinel (ctl_name == 0).
1831 * We allocate everything in one go so that we don't have to
1832 * worry about freeing additional memory in unregister_sysctl_table.
1834 header
= kzalloc(sizeof(struct ctl_table_header
) +
1835 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1839 new = (struct ctl_table
*) (header
+ 1);
1841 /* Now connect the dots */
1842 prevp
= &header
->ctl_table
;
1843 for (n
= 0; n
< npath
; ++n
, ++path
) {
1844 /* Copy the procname */
1845 new->procname
= path
->procname
;
1846 new->ctl_name
= path
->ctl_name
;
1850 prevp
= &new->child
;
1855 header
->ctl_table_arg
= table
;
1857 INIT_LIST_HEAD(&header
->ctl_entry
);
1859 header
->unregistering
= NULL
;
1860 header
->root
= root
;
1861 sysctl_set_parent(NULL
, header
->ctl_table
);
1863 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1864 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1869 spin_lock(&sysctl_lock
);
1870 header
->set
= lookup_header_set(root
, namespaces
);
1871 header
->attached_by
= header
->ctl_table
;
1872 header
->attached_to
= root_table
;
1873 header
->parent
= &root_table_header
;
1874 for (set
= header
->set
; set
; set
= set
->parent
) {
1875 struct ctl_table_header
*p
;
1876 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
1877 if (p
->unregistering
)
1879 try_attach(p
, header
);
1882 header
->parent
->count
++;
1883 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
1884 spin_unlock(&sysctl_lock
);
1890 * register_sysctl_table_path - register a sysctl table hierarchy
1891 * @path: The path to the directory the sysctl table is in.
1892 * @table: the top-level table structure
1894 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1895 * array. A completely 0 filled entry terminates the table.
1897 * See __register_sysctl_paths for more details.
1899 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1900 struct ctl_table
*table
)
1902 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1907 * register_sysctl_table - register a sysctl table hierarchy
1908 * @table: the top-level table structure
1910 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1911 * array. A completely 0 filled entry terminates the table.
1913 * See register_sysctl_paths for more details.
1915 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1917 static const struct ctl_path null_path
[] = { {} };
1919 return register_sysctl_paths(null_path
, table
);
1923 * unregister_sysctl_table - unregister a sysctl table hierarchy
1924 * @header: the header returned from register_sysctl_table
1926 * Unregisters the sysctl table and all children. proc entries may not
1927 * actually be removed until they are no longer used by anyone.
1929 void unregister_sysctl_table(struct ctl_table_header
* header
)
1936 spin_lock(&sysctl_lock
);
1937 start_unregistering(header
);
1938 if (!--header
->parent
->count
) {
1940 kfree(header
->parent
);
1942 if (!--header
->count
)
1944 spin_unlock(&sysctl_lock
);
1947 int sysctl_is_seen(struct ctl_table_header
*p
)
1949 struct ctl_table_set
*set
= p
->set
;
1951 spin_lock(&sysctl_lock
);
1952 if (p
->unregistering
)
1954 else if (!set
->is_seen
)
1957 res
= set
->is_seen(set
);
1958 spin_unlock(&sysctl_lock
);
1962 void setup_sysctl_set(struct ctl_table_set
*p
,
1963 struct ctl_table_set
*parent
,
1964 int (*is_seen
)(struct ctl_table_set
*))
1966 INIT_LIST_HEAD(&p
->list
);
1967 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
1968 p
->is_seen
= is_seen
;
1971 #else /* !CONFIG_SYSCTL */
1972 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1977 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1978 struct ctl_table
*table
)
1983 void unregister_sysctl_table(struct ctl_table_header
* table
)
1987 void setup_sysctl_set(struct ctl_table_set
*p
,
1988 struct ctl_table_set
*parent
,
1989 int (*is_seen
)(struct ctl_table_set
*))
1993 void sysctl_head_put(struct ctl_table_header
*head
)
1997 #endif /* CONFIG_SYSCTL */
2003 #ifdef CONFIG_PROC_SYSCTL
2005 static int _proc_do_string(void* data
, int maxlen
, int write
,
2006 struct file
*filp
, void __user
*buffer
,
2007 size_t *lenp
, loff_t
*ppos
)
2013 if (!data
|| !maxlen
|| !*lenp
) {
2021 while (len
< *lenp
) {
2022 if (get_user(c
, p
++))
2024 if (c
== 0 || c
== '\n')
2030 if(copy_from_user(data
, buffer
, len
))
2032 ((char *) data
)[len
] = 0;
2050 if(copy_to_user(buffer
, data
, len
))
2053 if(put_user('\n', ((char __user
*) buffer
) + len
))
2064 * proc_dostring - read a string sysctl
2065 * @table: the sysctl table
2066 * @write: %TRUE if this is a write to the sysctl file
2067 * @filp: the file structure
2068 * @buffer: the user buffer
2069 * @lenp: the size of the user buffer
2070 * @ppos: file position
2072 * Reads/writes a string from/to the user buffer. If the kernel
2073 * buffer provided is not large enough to hold the string, the
2074 * string is truncated. The copied string is %NULL-terminated.
2075 * If the string is being read by the user process, it is copied
2076 * and a newline '\n' is added. It is truncated if the buffer is
2079 * Returns 0 on success.
2081 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2082 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2084 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
2085 buffer
, lenp
, ppos
);
2089 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
2091 int write
, void *data
)
2094 *valp
= *negp
? -*lvalp
: *lvalp
;
2099 *lvalp
= (unsigned long)-val
;
2102 *lvalp
= (unsigned long)val
;
2108 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2109 int write
, struct file
*filp
, void __user
*buffer
,
2110 size_t *lenp
, loff_t
*ppos
,
2111 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2112 int write
, void *data
),
2115 #define TMPBUFLEN 21
2116 int *i
, vleft
, first
=1, neg
, val
;
2120 char buf
[TMPBUFLEN
], *p
;
2121 char __user
*s
= buffer
;
2123 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
2124 (*ppos
&& !write
)) {
2129 i
= (int *) tbl_data
;
2130 vleft
= table
->maxlen
/ sizeof(*i
);
2134 conv
= do_proc_dointvec_conv
;
2136 for (; left
&& vleft
--; i
++, first
=0) {
2151 if (len
> sizeof(buf
) - 1)
2152 len
= sizeof(buf
) - 1;
2153 if (copy_from_user(buf
, s
, len
))
2157 if (*p
== '-' && left
> 1) {
2161 if (*p
< '0' || *p
> '9')
2164 lval
= simple_strtoul(p
, &p
, 0);
2167 if ((len
< left
) && *p
&& !isspace(*p
))
2174 if (conv(&neg
, &lval
, i
, 1, data
))
2181 if (conv(&neg
, &lval
, i
, 0, data
))
2184 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2188 if(copy_to_user(s
, buf
, len
))
2195 if (!write
&& !first
&& left
) {
2196 if(put_user('\n', s
))
2203 if (get_user(c
, s
++))
2218 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2219 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2220 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2221 int write
, void *data
),
2224 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2225 buffer
, lenp
, ppos
, conv
, data
);
2229 * proc_dointvec - read a vector of integers
2230 * @table: the sysctl table
2231 * @write: %TRUE if this is a write to the sysctl file
2232 * @filp: the file structure
2233 * @buffer: the user buffer
2234 * @lenp: the size of the user buffer
2235 * @ppos: file position
2237 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2238 * values from/to the user buffer, treated as an ASCII string.
2240 * Returns 0 on success.
2242 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2243 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2245 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2250 * Taint values can only be increased
2251 * This means we can safely use a temporary.
2253 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2254 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2257 unsigned long tmptaint
= get_taint();
2260 if (write
&& !capable(CAP_SYS_ADMIN
))
2265 err
= proc_doulongvec_minmax(&t
, write
, filp
, buffer
, lenp
, ppos
);
2271 * Poor man's atomic or. Not worth adding a primitive
2272 * to everyone's atomic.h for this
2275 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2276 if ((tmptaint
>> i
) & 1)
2284 struct do_proc_dointvec_minmax_conv_param
{
2289 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2291 int write
, void *data
)
2293 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2295 int val
= *negp
? -*lvalp
: *lvalp
;
2296 if ((param
->min
&& *param
->min
> val
) ||
2297 (param
->max
&& *param
->max
< val
))
2304 *lvalp
= (unsigned long)-val
;
2307 *lvalp
= (unsigned long)val
;
2314 * proc_dointvec_minmax - read a vector of integers with min/max values
2315 * @table: the sysctl table
2316 * @write: %TRUE if this is a write to the sysctl file
2317 * @filp: the file structure
2318 * @buffer: the user buffer
2319 * @lenp: the size of the user buffer
2320 * @ppos: file position
2322 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2323 * values from/to the user buffer, treated as an ASCII string.
2325 * This routine will ensure the values are within the range specified by
2326 * table->extra1 (min) and table->extra2 (max).
2328 * Returns 0 on success.
2330 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2331 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2333 struct do_proc_dointvec_minmax_conv_param param
= {
2334 .min
= (int *) table
->extra1
,
2335 .max
= (int *) table
->extra2
,
2337 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2338 do_proc_dointvec_minmax_conv
, ¶m
);
2341 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2343 void __user
*buffer
,
2344 size_t *lenp
, loff_t
*ppos
,
2345 unsigned long convmul
,
2346 unsigned long convdiv
)
2348 #define TMPBUFLEN 21
2349 unsigned long *i
, *min
, *max
, val
;
2350 int vleft
, first
=1, neg
;
2352 char buf
[TMPBUFLEN
], *p
;
2353 char __user
*s
= buffer
;
2355 if (!data
|| !table
->maxlen
|| !*lenp
||
2356 (*ppos
&& !write
)) {
2361 i
= (unsigned long *) data
;
2362 min
= (unsigned long *) table
->extra1
;
2363 max
= (unsigned long *) table
->extra2
;
2364 vleft
= table
->maxlen
/ sizeof(unsigned long);
2367 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2382 if (len
> TMPBUFLEN
-1)
2384 if (copy_from_user(buf
, s
, len
))
2388 if (*p
== '-' && left
> 1) {
2392 if (*p
< '0' || *p
> '9')
2394 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2396 if ((len
< left
) && *p
&& !isspace(*p
))
2405 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2412 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2416 if(copy_to_user(s
, buf
, len
))
2423 if (!write
&& !first
&& left
) {
2424 if(put_user('\n', s
))
2431 if (get_user(c
, s
++))
2446 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2448 void __user
*buffer
,
2449 size_t *lenp
, loff_t
*ppos
,
2450 unsigned long convmul
,
2451 unsigned long convdiv
)
2453 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2454 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2458 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2459 * @table: the sysctl table
2460 * @write: %TRUE if this is a write to the sysctl file
2461 * @filp: the file structure
2462 * @buffer: the user buffer
2463 * @lenp: the size of the user buffer
2464 * @ppos: file position
2466 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2467 * values from/to the user buffer, treated as an ASCII string.
2469 * This routine will ensure the values are within the range specified by
2470 * table->extra1 (min) and table->extra2 (max).
2472 * Returns 0 on success.
2474 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2475 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2477 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2481 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2482 * @table: the sysctl table
2483 * @write: %TRUE if this is a write to the sysctl file
2484 * @filp: the file structure
2485 * @buffer: the user buffer
2486 * @lenp: the size of the user buffer
2487 * @ppos: file position
2489 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2490 * values from/to the user buffer, treated as an ASCII string. The values
2491 * are treated as milliseconds, and converted to jiffies when they are stored.
2493 * This routine will ensure the values are within the range specified by
2494 * table->extra1 (min) and table->extra2 (max).
2496 * Returns 0 on success.
2498 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2500 void __user
*buffer
,
2501 size_t *lenp
, loff_t
*ppos
)
2503 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2504 lenp
, ppos
, HZ
, 1000l);
2508 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2510 int write
, void *data
)
2513 if (*lvalp
> LONG_MAX
/ HZ
)
2515 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2521 lval
= (unsigned long)-val
;
2524 lval
= (unsigned long)val
;
2531 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2533 int write
, void *data
)
2536 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2538 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2544 lval
= (unsigned long)-val
;
2547 lval
= (unsigned long)val
;
2549 *lvalp
= jiffies_to_clock_t(lval
);
2554 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2556 int write
, void *data
)
2559 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2565 lval
= (unsigned long)-val
;
2568 lval
= (unsigned long)val
;
2570 *lvalp
= jiffies_to_msecs(lval
);
2576 * proc_dointvec_jiffies - read a vector of integers as seconds
2577 * @table: the sysctl table
2578 * @write: %TRUE if this is a write to the sysctl file
2579 * @filp: the file structure
2580 * @buffer: the user buffer
2581 * @lenp: the size of the user buffer
2582 * @ppos: file position
2584 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2585 * values from/to the user buffer, treated as an ASCII string.
2586 * The values read are assumed to be in seconds, and are converted into
2589 * Returns 0 on success.
2591 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2592 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2594 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2595 do_proc_dointvec_jiffies_conv
,NULL
);
2599 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2600 * @table: the sysctl table
2601 * @write: %TRUE if this is a write to the sysctl file
2602 * @filp: the file structure
2603 * @buffer: the user buffer
2604 * @lenp: the size of the user buffer
2605 * @ppos: pointer to the file position
2607 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2608 * values from/to the user buffer, treated as an ASCII string.
2609 * The values read are assumed to be in 1/USER_HZ seconds, and
2610 * are converted into jiffies.
2612 * Returns 0 on success.
2614 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2615 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2617 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2618 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2622 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2623 * @table: the sysctl table
2624 * @write: %TRUE if this is a write to the sysctl file
2625 * @filp: the file structure
2626 * @buffer: the user buffer
2627 * @lenp: the size of the user buffer
2628 * @ppos: file position
2629 * @ppos: the current position in the file
2631 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2632 * values from/to the user buffer, treated as an ASCII string.
2633 * The values read are assumed to be in 1/1000 seconds, and
2634 * are converted into jiffies.
2636 * Returns 0 on success.
2638 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2639 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2641 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2642 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2645 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2646 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2648 struct pid
*new_pid
;
2652 tmp
= pid_vnr(cad_pid
);
2654 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2655 lenp
, ppos
, NULL
, NULL
);
2659 new_pid
= find_get_pid(tmp
);
2663 put_pid(xchg(&cad_pid
, new_pid
));
2667 #else /* CONFIG_PROC_FS */
2669 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2670 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2675 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2676 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2681 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2682 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2687 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2688 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2693 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2694 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2699 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2700 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2705 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2706 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2711 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2713 void __user
*buffer
,
2714 size_t *lenp
, loff_t
*ppos
)
2720 #endif /* CONFIG_PROC_FS */
2723 #ifdef CONFIG_SYSCTL_SYSCALL
2725 * General sysctl support routines
2728 /* The generic sysctl data routine (used if no strategy routine supplied) */
2729 int sysctl_data(struct ctl_table
*table
,
2730 void __user
*oldval
, size_t __user
*oldlenp
,
2731 void __user
*newval
, size_t newlen
)
2735 /* Get out of I don't have a variable */
2736 if (!table
->data
|| !table
->maxlen
)
2739 if (oldval
&& oldlenp
) {
2740 if (get_user(len
, oldlenp
))
2743 if (len
> table
->maxlen
)
2744 len
= table
->maxlen
;
2745 if (copy_to_user(oldval
, table
->data
, len
))
2747 if (put_user(len
, oldlenp
))
2752 if (newval
&& newlen
) {
2753 if (newlen
> table
->maxlen
)
2754 newlen
= table
->maxlen
;
2756 if (copy_from_user(table
->data
, newval
, newlen
))
2762 /* The generic string strategy routine: */
2763 int sysctl_string(struct ctl_table
*table
,
2764 void __user
*oldval
, size_t __user
*oldlenp
,
2765 void __user
*newval
, size_t newlen
)
2767 if (!table
->data
|| !table
->maxlen
)
2770 if (oldval
&& oldlenp
) {
2772 if (get_user(bufsize
, oldlenp
))
2775 size_t len
= strlen(table
->data
), copied
;
2777 /* This shouldn't trigger for a well-formed sysctl */
2778 if (len
> table
->maxlen
)
2779 len
= table
->maxlen
;
2781 /* Copy up to a max of bufsize-1 bytes of the string */
2782 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2784 if (copy_to_user(oldval
, table
->data
, copied
) ||
2785 put_user(0, (char __user
*)(oldval
+ copied
)))
2787 if (put_user(len
, oldlenp
))
2791 if (newval
&& newlen
) {
2792 size_t len
= newlen
;
2793 if (len
> table
->maxlen
)
2794 len
= table
->maxlen
;
2795 if(copy_from_user(table
->data
, newval
, len
))
2797 if (len
== table
->maxlen
)
2799 ((char *) table
->data
)[len
] = 0;
2805 * This function makes sure that all of the integers in the vector
2806 * are between the minimum and maximum values given in the arrays
2807 * table->extra1 and table->extra2, respectively.
2809 int sysctl_intvec(struct ctl_table
*table
,
2810 void __user
*oldval
, size_t __user
*oldlenp
,
2811 void __user
*newval
, size_t newlen
)
2814 if (newval
&& newlen
) {
2815 int __user
*vec
= (int __user
*) newval
;
2816 int *min
= (int *) table
->extra1
;
2817 int *max
= (int *) table
->extra2
;
2821 if (newlen
% sizeof(int) != 0)
2824 if (!table
->extra1
&& !table
->extra2
)
2827 if (newlen
> table
->maxlen
)
2828 newlen
= table
->maxlen
;
2829 length
= newlen
/ sizeof(int);
2831 for (i
= 0; i
< length
; i
++) {
2833 if (get_user(value
, vec
+ i
))
2835 if (min
&& value
< min
[i
])
2837 if (max
&& value
> max
[i
])
2844 /* Strategy function to convert jiffies to seconds */
2845 int sysctl_jiffies(struct ctl_table
*table
,
2846 void __user
*oldval
, size_t __user
*oldlenp
,
2847 void __user
*newval
, size_t newlen
)
2849 if (oldval
&& oldlenp
) {
2852 if (get_user(olen
, oldlenp
))
2857 if (olen
< sizeof(int))
2860 val
= *(int *)(table
->data
) / HZ
;
2861 if (put_user(val
, (int __user
*)oldval
))
2863 if (put_user(sizeof(int), oldlenp
))
2867 if (newval
&& newlen
) {
2869 if (newlen
!= sizeof(int))
2871 if (get_user(new, (int __user
*)newval
))
2873 *(int *)(table
->data
) = new*HZ
;
2878 /* Strategy function to convert jiffies to seconds */
2879 int sysctl_ms_jiffies(struct ctl_table
*table
,
2880 void __user
*oldval
, size_t __user
*oldlenp
,
2881 void __user
*newval
, size_t newlen
)
2883 if (oldval
&& oldlenp
) {
2886 if (get_user(olen
, oldlenp
))
2891 if (olen
< sizeof(int))
2894 val
= jiffies_to_msecs(*(int *)(table
->data
));
2895 if (put_user(val
, (int __user
*)oldval
))
2897 if (put_user(sizeof(int), oldlenp
))
2901 if (newval
&& newlen
) {
2903 if (newlen
!= sizeof(int))
2905 if (get_user(new, (int __user
*)newval
))
2907 *(int *)(table
->data
) = msecs_to_jiffies(new);
2914 #else /* CONFIG_SYSCTL_SYSCALL */
2917 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2919 struct __sysctl_args tmp
;
2922 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
2925 error
= deprecated_sysctl_warning(&tmp
);
2927 /* If no error reading the parameters then just -ENOSYS ... */
2934 int sysctl_data(struct ctl_table
*table
,
2935 void __user
*oldval
, size_t __user
*oldlenp
,
2936 void __user
*newval
, size_t newlen
)
2941 int sysctl_string(struct ctl_table
*table
,
2942 void __user
*oldval
, size_t __user
*oldlenp
,
2943 void __user
*newval
, size_t newlen
)
2948 int sysctl_intvec(struct ctl_table
*table
,
2949 void __user
*oldval
, size_t __user
*oldlenp
,
2950 void __user
*newval
, size_t newlen
)
2955 int sysctl_jiffies(struct ctl_table
*table
,
2956 void __user
*oldval
, size_t __user
*oldlenp
,
2957 void __user
*newval
, size_t newlen
)
2962 int sysctl_ms_jiffies(struct ctl_table
*table
,
2963 void __user
*oldval
, size_t __user
*oldlenp
,
2964 void __user
*newval
, size_t newlen
)
2969 #endif /* CONFIG_SYSCTL_SYSCALL */
2971 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
2973 static int msg_count
;
2974 int name
[CTL_MAXNAME
];
2977 /* Check args->nlen. */
2978 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
2981 /* Read in the sysctl name for better debug message logging */
2982 for (i
= 0; i
< args
->nlen
; i
++)
2983 if (get_user(name
[i
], args
->name
+ i
))
2986 /* Ignore accesses to kernel.version */
2987 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
2990 if (msg_count
< 5) {
2993 "warning: process `%s' used the deprecated sysctl "
2994 "system call with ", current
->comm
);
2995 for (i
= 0; i
< args
->nlen
; i
++)
2996 printk("%d.", name
[i
]);
3003 * No sense putting this after each symbol definition, twice,
3004 * exception granted :-)
3006 EXPORT_SYMBOL(proc_dointvec
);
3007 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3008 EXPORT_SYMBOL(proc_dointvec_minmax
);
3009 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3010 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3011 EXPORT_SYMBOL(proc_dostring
);
3012 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3013 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
3014 EXPORT_SYMBOL(register_sysctl_table
);
3015 EXPORT_SYMBOL(register_sysctl_paths
);
3016 EXPORT_SYMBOL(sysctl_intvec
);
3017 EXPORT_SYMBOL(sysctl_jiffies
);
3018 EXPORT_SYMBOL(sysctl_ms_jiffies
);
3019 EXPORT_SYMBOL(sysctl_string
);
3020 EXPORT_SYMBOL(sysctl_data
);
3021 EXPORT_SYMBOL(unregister_sysctl_table
);