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_child_runs_first",
280 .data
= &sysctl_sched_child_runs_first
,
281 .maxlen
= sizeof(unsigned int),
283 .proc_handler
= &proc_dointvec
,
286 .ctl_name
= CTL_UNNUMBERED
,
287 .procname
= "sched_features",
288 .data
= &sysctl_sched_features
,
289 .maxlen
= sizeof(unsigned int),
291 .proc_handler
= &proc_dointvec
,
294 .ctl_name
= CTL_UNNUMBERED
,
295 .procname
= "sched_migration_cost",
296 .data
= &sysctl_sched_migration_cost
,
297 .maxlen
= sizeof(unsigned int),
299 .proc_handler
= &proc_dointvec
,
302 .ctl_name
= CTL_UNNUMBERED
,
303 .procname
= "sched_nr_migrate",
304 .data
= &sysctl_sched_nr_migrate
,
305 .maxlen
= sizeof(unsigned int),
307 .proc_handler
= &proc_dointvec
,
311 .ctl_name
= CTL_UNNUMBERED
,
312 .procname
= "sched_rt_period_us",
313 .data
= &sysctl_sched_rt_period
,
314 .maxlen
= sizeof(unsigned int),
316 .proc_handler
= &sched_rt_handler
,
319 .ctl_name
= CTL_UNNUMBERED
,
320 .procname
= "sched_rt_runtime_us",
321 .data
= &sysctl_sched_rt_runtime
,
322 .maxlen
= sizeof(int),
324 .proc_handler
= &sched_rt_handler
,
327 .ctl_name
= CTL_UNNUMBERED
,
328 .procname
= "sched_compat_yield",
329 .data
= &sysctl_sched_compat_yield
,
330 .maxlen
= sizeof(unsigned int),
332 .proc_handler
= &proc_dointvec
,
334 #ifdef CONFIG_PROVE_LOCKING
336 .ctl_name
= CTL_UNNUMBERED
,
337 .procname
= "prove_locking",
338 .data
= &prove_locking
,
339 .maxlen
= sizeof(int),
341 .proc_handler
= &proc_dointvec
,
344 #ifdef CONFIG_LOCK_STAT
346 .ctl_name
= CTL_UNNUMBERED
,
347 .procname
= "lock_stat",
349 .maxlen
= sizeof(int),
351 .proc_handler
= &proc_dointvec
,
355 .ctl_name
= KERN_PANIC
,
357 .data
= &panic_timeout
,
358 .maxlen
= sizeof(int),
360 .proc_handler
= &proc_dointvec
,
363 .ctl_name
= KERN_CORE_USES_PID
,
364 .procname
= "core_uses_pid",
365 .data
= &core_uses_pid
,
366 .maxlen
= sizeof(int),
368 .proc_handler
= &proc_dointvec
,
371 .ctl_name
= KERN_CORE_PATTERN
,
372 .procname
= "core_pattern",
373 .data
= core_pattern
,
374 .maxlen
= CORENAME_MAX_SIZE
,
376 .proc_handler
= &proc_dostring
,
377 .strategy
= &sysctl_string
,
379 #ifdef CONFIG_PROC_SYSCTL
381 .procname
= "tainted",
382 .maxlen
= sizeof(long),
384 .proc_handler
= &proc_taint
,
387 #ifdef CONFIG_LATENCYTOP
389 .procname
= "latencytop",
390 .data
= &latencytop_enabled
,
391 .maxlen
= sizeof(int),
393 .proc_handler
= &proc_dointvec
,
396 #ifdef CONFIG_BLK_DEV_INITRD
398 .ctl_name
= KERN_REALROOTDEV
,
399 .procname
= "real-root-dev",
400 .data
= &real_root_dev
,
401 .maxlen
= sizeof(int),
403 .proc_handler
= &proc_dointvec
,
407 .ctl_name
= CTL_UNNUMBERED
,
408 .procname
= "print-fatal-signals",
409 .data
= &print_fatal_signals
,
410 .maxlen
= sizeof(int),
412 .proc_handler
= &proc_dointvec
,
416 .ctl_name
= KERN_SPARC_REBOOT
,
417 .procname
= "reboot-cmd",
418 .data
= reboot_command
,
421 .proc_handler
= &proc_dostring
,
422 .strategy
= &sysctl_string
,
425 .ctl_name
= KERN_SPARC_STOP_A
,
426 .procname
= "stop-a",
427 .data
= &stop_a_enabled
,
428 .maxlen
= sizeof (int),
430 .proc_handler
= &proc_dointvec
,
433 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
434 .procname
= "scons-poweroff",
435 .data
= &scons_pwroff
,
436 .maxlen
= sizeof (int),
438 .proc_handler
= &proc_dointvec
,
443 .ctl_name
= KERN_HPPA_PWRSW
,
444 .procname
= "soft-power",
445 .data
= &pwrsw_enabled
,
446 .maxlen
= sizeof (int),
448 .proc_handler
= &proc_dointvec
,
451 .ctl_name
= KERN_HPPA_UNALIGNED
,
452 .procname
= "unaligned-trap",
453 .data
= &unaligned_enabled
,
454 .maxlen
= sizeof (int),
456 .proc_handler
= &proc_dointvec
,
460 .ctl_name
= KERN_CTLALTDEL
,
461 .procname
= "ctrl-alt-del",
463 .maxlen
= sizeof(int),
465 .proc_handler
= &proc_dointvec
,
469 .ctl_name
= CTL_UNNUMBERED
,
470 .procname
= "ftrace_enabled",
471 .data
= &ftrace_enabled
,
472 .maxlen
= sizeof(int),
474 .proc_handler
= &ftrace_enable_sysctl
,
477 #ifdef CONFIG_MODULES
479 .ctl_name
= KERN_MODPROBE
,
480 .procname
= "modprobe",
481 .data
= &modprobe_path
,
482 .maxlen
= KMOD_PATH_LEN
,
484 .proc_handler
= &proc_dostring
,
485 .strategy
= &sysctl_string
,
488 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
490 .ctl_name
= KERN_HOTPLUG
,
491 .procname
= "hotplug",
492 .data
= &uevent_helper
,
493 .maxlen
= UEVENT_HELPER_PATH_LEN
,
495 .proc_handler
= &proc_dostring
,
496 .strategy
= &sysctl_string
,
499 #ifdef CONFIG_CHR_DEV_SG
501 .ctl_name
= KERN_SG_BIG_BUFF
,
502 .procname
= "sg-big-buff",
503 .data
= &sg_big_buff
,
504 .maxlen
= sizeof (int),
506 .proc_handler
= &proc_dointvec
,
509 #ifdef CONFIG_BSD_PROCESS_ACCT
511 .ctl_name
= KERN_ACCT
,
514 .maxlen
= 3*sizeof(int),
516 .proc_handler
= &proc_dointvec
,
519 #ifdef CONFIG_MAGIC_SYSRQ
521 .ctl_name
= KERN_SYSRQ
,
523 .data
= &__sysrq_enabled
,
524 .maxlen
= sizeof (int),
526 .proc_handler
= &proc_dointvec
,
529 #ifdef CONFIG_PROC_SYSCTL
531 .procname
= "cad_pid",
533 .maxlen
= sizeof (int),
535 .proc_handler
= &proc_do_cad_pid
,
539 .ctl_name
= KERN_MAX_THREADS
,
540 .procname
= "threads-max",
541 .data
= &max_threads
,
542 .maxlen
= sizeof(int),
544 .proc_handler
= &proc_dointvec
,
547 .ctl_name
= KERN_RANDOM
,
548 .procname
= "random",
550 .child
= random_table
,
553 .ctl_name
= KERN_OVERFLOWUID
,
554 .procname
= "overflowuid",
555 .data
= &overflowuid
,
556 .maxlen
= sizeof(int),
558 .proc_handler
= &proc_dointvec_minmax
,
559 .strategy
= &sysctl_intvec
,
560 .extra1
= &minolduid
,
561 .extra2
= &maxolduid
,
564 .ctl_name
= KERN_OVERFLOWGID
,
565 .procname
= "overflowgid",
566 .data
= &overflowgid
,
567 .maxlen
= sizeof(int),
569 .proc_handler
= &proc_dointvec_minmax
,
570 .strategy
= &sysctl_intvec
,
571 .extra1
= &minolduid
,
572 .extra2
= &maxolduid
,
575 #ifdef CONFIG_MATHEMU
577 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
578 .procname
= "ieee_emulation_warnings",
579 .data
= &sysctl_ieee_emulation_warnings
,
580 .maxlen
= sizeof(int),
582 .proc_handler
= &proc_dointvec
,
586 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
587 .procname
= "userprocess_debug",
588 .data
= &sysctl_userprocess_debug
,
589 .maxlen
= sizeof(int),
591 .proc_handler
= &proc_dointvec
,
595 .ctl_name
= KERN_PIDMAX
,
596 .procname
= "pid_max",
598 .maxlen
= sizeof (int),
600 .proc_handler
= &proc_dointvec_minmax
,
601 .strategy
= sysctl_intvec
,
602 .extra1
= &pid_max_min
,
603 .extra2
= &pid_max_max
,
606 .ctl_name
= KERN_PANIC_ON_OOPS
,
607 .procname
= "panic_on_oops",
608 .data
= &panic_on_oops
,
609 .maxlen
= sizeof(int),
611 .proc_handler
= &proc_dointvec
,
613 #if defined CONFIG_PRINTK
615 .ctl_name
= KERN_PRINTK
,
616 .procname
= "printk",
617 .data
= &console_loglevel
,
618 .maxlen
= 4*sizeof(int),
620 .proc_handler
= &proc_dointvec
,
623 .ctl_name
= KERN_PRINTK_RATELIMIT
,
624 .procname
= "printk_ratelimit",
625 .data
= &printk_ratelimit_state
.interval
,
626 .maxlen
= sizeof(int),
628 .proc_handler
= &proc_dointvec_jiffies
,
629 .strategy
= &sysctl_jiffies
,
632 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
633 .procname
= "printk_ratelimit_burst",
634 .data
= &printk_ratelimit_state
.burst
,
635 .maxlen
= sizeof(int),
637 .proc_handler
= &proc_dointvec
,
641 .ctl_name
= KERN_NGROUPS_MAX
,
642 .procname
= "ngroups_max",
643 .data
= &ngroups_max
,
644 .maxlen
= sizeof (int),
646 .proc_handler
= &proc_dointvec
,
648 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
650 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
651 .procname
= "unknown_nmi_panic",
652 .data
= &unknown_nmi_panic
,
653 .maxlen
= sizeof (int),
655 .proc_handler
= &proc_dointvec
,
658 .procname
= "nmi_watchdog",
659 .data
= &nmi_watchdog_enabled
,
660 .maxlen
= sizeof (int),
662 .proc_handler
= &proc_nmi_enabled
,
665 #if defined(CONFIG_X86)
667 .ctl_name
= KERN_PANIC_ON_NMI
,
668 .procname
= "panic_on_unrecovered_nmi",
669 .data
= &panic_on_unrecovered_nmi
,
670 .maxlen
= sizeof(int),
672 .proc_handler
= &proc_dointvec
,
675 .ctl_name
= KERN_BOOTLOADER_TYPE
,
676 .procname
= "bootloader_type",
677 .data
= &bootloader_type
,
678 .maxlen
= sizeof (int),
680 .proc_handler
= &proc_dointvec
,
683 .ctl_name
= CTL_UNNUMBERED
,
684 .procname
= "kstack_depth_to_print",
685 .data
= &kstack_depth_to_print
,
686 .maxlen
= sizeof(int),
688 .proc_handler
= &proc_dointvec
,
691 .ctl_name
= CTL_UNNUMBERED
,
692 .procname
= "io_delay_type",
693 .data
= &io_delay_type
,
694 .maxlen
= sizeof(int),
696 .proc_handler
= &proc_dointvec
,
699 #if defined(CONFIG_MMU)
701 .ctl_name
= KERN_RANDOMIZE
,
702 .procname
= "randomize_va_space",
703 .data
= &randomize_va_space
,
704 .maxlen
= sizeof(int),
706 .proc_handler
= &proc_dointvec
,
709 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
711 .ctl_name
= KERN_SPIN_RETRY
,
712 .procname
= "spin_retry",
714 .maxlen
= sizeof (int),
716 .proc_handler
= &proc_dointvec
,
719 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
721 .procname
= "acpi_video_flags",
722 .data
= &acpi_realmode_flags
,
723 .maxlen
= sizeof (unsigned long),
725 .proc_handler
= &proc_doulongvec_minmax
,
730 .ctl_name
= KERN_IA64_UNALIGNED
,
731 .procname
= "ignore-unaligned-usertrap",
732 .data
= &no_unaligned_warning
,
733 .maxlen
= sizeof (int),
735 .proc_handler
= &proc_dointvec
,
738 #ifdef CONFIG_DETECT_SOFTLOCKUP
740 .ctl_name
= CTL_UNNUMBERED
,
741 .procname
= "softlockup_panic",
742 .data
= &softlockup_panic
,
743 .maxlen
= sizeof(int),
745 .proc_handler
= &proc_dointvec_minmax
,
746 .strategy
= &sysctl_intvec
,
751 .ctl_name
= CTL_UNNUMBERED
,
752 .procname
= "softlockup_thresh",
753 .data
= &softlockup_thresh
,
754 .maxlen
= sizeof(int),
756 .proc_handler
= &proc_dointvec_minmax
,
757 .strategy
= &sysctl_intvec
,
762 .ctl_name
= CTL_UNNUMBERED
,
763 .procname
= "hung_task_check_count",
764 .data
= &sysctl_hung_task_check_count
,
765 .maxlen
= sizeof(unsigned long),
767 .proc_handler
= &proc_doulongvec_minmax
,
768 .strategy
= &sysctl_intvec
,
771 .ctl_name
= CTL_UNNUMBERED
,
772 .procname
= "hung_task_timeout_secs",
773 .data
= &sysctl_hung_task_timeout_secs
,
774 .maxlen
= sizeof(unsigned long),
776 .proc_handler
= &proc_doulongvec_minmax
,
777 .strategy
= &sysctl_intvec
,
780 .ctl_name
= CTL_UNNUMBERED
,
781 .procname
= "hung_task_warnings",
782 .data
= &sysctl_hung_task_warnings
,
783 .maxlen
= sizeof(unsigned long),
785 .proc_handler
= &proc_doulongvec_minmax
,
786 .strategy
= &sysctl_intvec
,
791 .ctl_name
= KERN_COMPAT_LOG
,
792 .procname
= "compat-log",
794 .maxlen
= sizeof (int),
796 .proc_handler
= &proc_dointvec
,
799 #ifdef CONFIG_RT_MUTEXES
801 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
802 .procname
= "max_lock_depth",
803 .data
= &max_lock_depth
,
804 .maxlen
= sizeof(int),
806 .proc_handler
= &proc_dointvec
,
810 .ctl_name
= CTL_UNNUMBERED
,
811 .procname
= "poweroff_cmd",
812 .data
= &poweroff_cmd
,
813 .maxlen
= POWEROFF_CMD_PATH_LEN
,
815 .proc_handler
= &proc_dostring
,
816 .strategy
= &sysctl_string
,
820 .ctl_name
= CTL_UNNUMBERED
,
823 .child
= key_sysctls
,
826 #ifdef CONFIG_RCU_TORTURE_TEST
828 .ctl_name
= CTL_UNNUMBERED
,
829 .procname
= "rcutorture_runnable",
830 .data
= &rcutorture_runnable
,
831 .maxlen
= sizeof(int),
833 .proc_handler
= &proc_dointvec
,
837 * NOTE: do not add new entries to this table unless you have read
838 * Documentation/sysctl/ctl_unnumbered.txt
843 static struct ctl_table vm_table
[] = {
845 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
846 .procname
= "overcommit_memory",
847 .data
= &sysctl_overcommit_memory
,
848 .maxlen
= sizeof(sysctl_overcommit_memory
),
850 .proc_handler
= &proc_dointvec
,
853 .ctl_name
= VM_PANIC_ON_OOM
,
854 .procname
= "panic_on_oom",
855 .data
= &sysctl_panic_on_oom
,
856 .maxlen
= sizeof(sysctl_panic_on_oom
),
858 .proc_handler
= &proc_dointvec
,
861 .ctl_name
= CTL_UNNUMBERED
,
862 .procname
= "oom_kill_allocating_task",
863 .data
= &sysctl_oom_kill_allocating_task
,
864 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
866 .proc_handler
= &proc_dointvec
,
869 .ctl_name
= CTL_UNNUMBERED
,
870 .procname
= "oom_dump_tasks",
871 .data
= &sysctl_oom_dump_tasks
,
872 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
874 .proc_handler
= &proc_dointvec
,
877 .ctl_name
= VM_OVERCOMMIT_RATIO
,
878 .procname
= "overcommit_ratio",
879 .data
= &sysctl_overcommit_ratio
,
880 .maxlen
= sizeof(sysctl_overcommit_ratio
),
882 .proc_handler
= &proc_dointvec
,
885 .ctl_name
= VM_PAGE_CLUSTER
,
886 .procname
= "page-cluster",
887 .data
= &page_cluster
,
888 .maxlen
= sizeof(int),
890 .proc_handler
= &proc_dointvec
,
893 .ctl_name
= VM_DIRTY_BACKGROUND
,
894 .procname
= "dirty_background_ratio",
895 .data
= &dirty_background_ratio
,
896 .maxlen
= sizeof(dirty_background_ratio
),
898 .proc_handler
= &proc_dointvec_minmax
,
899 .strategy
= &sysctl_intvec
,
901 .extra2
= &one_hundred
,
904 .ctl_name
= VM_DIRTY_RATIO
,
905 .procname
= "dirty_ratio",
906 .data
= &vm_dirty_ratio
,
907 .maxlen
= sizeof(vm_dirty_ratio
),
909 .proc_handler
= &dirty_ratio_handler
,
910 .strategy
= &sysctl_intvec
,
912 .extra2
= &one_hundred
,
915 .procname
= "dirty_writeback_centisecs",
916 .data
= &dirty_writeback_interval
,
917 .maxlen
= sizeof(dirty_writeback_interval
),
919 .proc_handler
= &dirty_writeback_centisecs_handler
,
922 .procname
= "dirty_expire_centisecs",
923 .data
= &dirty_expire_interval
,
924 .maxlen
= sizeof(dirty_expire_interval
),
926 .proc_handler
= &proc_dointvec_userhz_jiffies
,
929 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
930 .procname
= "nr_pdflush_threads",
931 .data
= &nr_pdflush_threads
,
932 .maxlen
= sizeof nr_pdflush_threads
,
933 .mode
= 0444 /* read-only*/,
934 .proc_handler
= &proc_dointvec
,
937 .ctl_name
= VM_SWAPPINESS
,
938 .procname
= "swappiness",
939 .data
= &vm_swappiness
,
940 .maxlen
= sizeof(vm_swappiness
),
942 .proc_handler
= &proc_dointvec_minmax
,
943 .strategy
= &sysctl_intvec
,
945 .extra2
= &one_hundred
,
947 #ifdef CONFIG_HUGETLB_PAGE
949 .procname
= "nr_hugepages",
951 .maxlen
= sizeof(unsigned long),
953 .proc_handler
= &hugetlb_sysctl_handler
,
954 .extra1
= (void *)&hugetlb_zero
,
955 .extra2
= (void *)&hugetlb_infinity
,
958 .ctl_name
= VM_HUGETLB_GROUP
,
959 .procname
= "hugetlb_shm_group",
960 .data
= &sysctl_hugetlb_shm_group
,
961 .maxlen
= sizeof(gid_t
),
963 .proc_handler
= &proc_dointvec
,
966 .ctl_name
= CTL_UNNUMBERED
,
967 .procname
= "hugepages_treat_as_movable",
968 .data
= &hugepages_treat_as_movable
,
969 .maxlen
= sizeof(int),
971 .proc_handler
= &hugetlb_treat_movable_handler
,
974 .ctl_name
= CTL_UNNUMBERED
,
975 .procname
= "nr_overcommit_hugepages",
977 .maxlen
= sizeof(unsigned long),
979 .proc_handler
= &hugetlb_overcommit_handler
,
980 .extra1
= (void *)&hugetlb_zero
,
981 .extra2
= (void *)&hugetlb_infinity
,
985 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
986 .procname
= "lowmem_reserve_ratio",
987 .data
= &sysctl_lowmem_reserve_ratio
,
988 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
990 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
991 .strategy
= &sysctl_intvec
,
994 .ctl_name
= VM_DROP_PAGECACHE
,
995 .procname
= "drop_caches",
996 .data
= &sysctl_drop_caches
,
997 .maxlen
= sizeof(int),
999 .proc_handler
= drop_caches_sysctl_handler
,
1000 .strategy
= &sysctl_intvec
,
1003 .ctl_name
= VM_MIN_FREE_KBYTES
,
1004 .procname
= "min_free_kbytes",
1005 .data
= &min_free_kbytes
,
1006 .maxlen
= sizeof(min_free_kbytes
),
1008 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1009 .strategy
= &sysctl_intvec
,
1013 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1014 .procname
= "percpu_pagelist_fraction",
1015 .data
= &percpu_pagelist_fraction
,
1016 .maxlen
= sizeof(percpu_pagelist_fraction
),
1018 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1019 .strategy
= &sysctl_intvec
,
1020 .extra1
= &min_percpu_pagelist_fract
,
1024 .ctl_name
= VM_MAX_MAP_COUNT
,
1025 .procname
= "max_map_count",
1026 .data
= &sysctl_max_map_count
,
1027 .maxlen
= sizeof(sysctl_max_map_count
),
1029 .proc_handler
= &proc_dointvec
1033 .ctl_name
= VM_LAPTOP_MODE
,
1034 .procname
= "laptop_mode",
1035 .data
= &laptop_mode
,
1036 .maxlen
= sizeof(laptop_mode
),
1038 .proc_handler
= &proc_dointvec_jiffies
,
1039 .strategy
= &sysctl_jiffies
,
1042 .ctl_name
= VM_BLOCK_DUMP
,
1043 .procname
= "block_dump",
1044 .data
= &block_dump
,
1045 .maxlen
= sizeof(block_dump
),
1047 .proc_handler
= &proc_dointvec
,
1048 .strategy
= &sysctl_intvec
,
1052 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1053 .procname
= "vfs_cache_pressure",
1054 .data
= &sysctl_vfs_cache_pressure
,
1055 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1057 .proc_handler
= &proc_dointvec
,
1058 .strategy
= &sysctl_intvec
,
1061 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1063 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1064 .procname
= "legacy_va_layout",
1065 .data
= &sysctl_legacy_va_layout
,
1066 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1068 .proc_handler
= &proc_dointvec
,
1069 .strategy
= &sysctl_intvec
,
1075 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1076 .procname
= "zone_reclaim_mode",
1077 .data
= &zone_reclaim_mode
,
1078 .maxlen
= sizeof(zone_reclaim_mode
),
1080 .proc_handler
= &proc_dointvec
,
1081 .strategy
= &sysctl_intvec
,
1085 .ctl_name
= VM_MIN_UNMAPPED
,
1086 .procname
= "min_unmapped_ratio",
1087 .data
= &sysctl_min_unmapped_ratio
,
1088 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1090 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1091 .strategy
= &sysctl_intvec
,
1093 .extra2
= &one_hundred
,
1096 .ctl_name
= VM_MIN_SLAB
,
1097 .procname
= "min_slab_ratio",
1098 .data
= &sysctl_min_slab_ratio
,
1099 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1101 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1102 .strategy
= &sysctl_intvec
,
1104 .extra2
= &one_hundred
,
1109 .ctl_name
= CTL_UNNUMBERED
,
1110 .procname
= "stat_interval",
1111 .data
= &sysctl_stat_interval
,
1112 .maxlen
= sizeof(sysctl_stat_interval
),
1114 .proc_handler
= &proc_dointvec_jiffies
,
1115 .strategy
= &sysctl_jiffies
,
1118 #ifdef CONFIG_SECURITY
1120 .ctl_name
= CTL_UNNUMBERED
,
1121 .procname
= "mmap_min_addr",
1122 .data
= &mmap_min_addr
,
1123 .maxlen
= sizeof(unsigned long),
1125 .proc_handler
= &proc_doulongvec_minmax
,
1130 .ctl_name
= CTL_UNNUMBERED
,
1131 .procname
= "numa_zonelist_order",
1132 .data
= &numa_zonelist_order
,
1133 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1135 .proc_handler
= &numa_zonelist_order_handler
,
1136 .strategy
= &sysctl_string
,
1139 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1140 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1142 .ctl_name
= VM_VDSO_ENABLED
,
1143 .procname
= "vdso_enabled",
1144 .data
= &vdso_enabled
,
1145 .maxlen
= sizeof(vdso_enabled
),
1147 .proc_handler
= &proc_dointvec
,
1148 .strategy
= &sysctl_intvec
,
1152 #ifdef CONFIG_HIGHMEM
1154 .ctl_name
= CTL_UNNUMBERED
,
1155 .procname
= "highmem_is_dirtyable",
1156 .data
= &vm_highmem_is_dirtyable
,
1157 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1159 .proc_handler
= &proc_dointvec_minmax
,
1160 .strategy
= &sysctl_intvec
,
1166 * NOTE: do not add new entries to this table unless you have read
1167 * Documentation/sysctl/ctl_unnumbered.txt
1172 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1173 static struct ctl_table binfmt_misc_table
[] = {
1178 static struct ctl_table fs_table
[] = {
1180 .ctl_name
= FS_NRINODE
,
1181 .procname
= "inode-nr",
1182 .data
= &inodes_stat
,
1183 .maxlen
= 2*sizeof(int),
1185 .proc_handler
= &proc_dointvec
,
1188 .ctl_name
= FS_STATINODE
,
1189 .procname
= "inode-state",
1190 .data
= &inodes_stat
,
1191 .maxlen
= 7*sizeof(int),
1193 .proc_handler
= &proc_dointvec
,
1196 .procname
= "file-nr",
1197 .data
= &files_stat
,
1198 .maxlen
= 3*sizeof(int),
1200 .proc_handler
= &proc_nr_files
,
1203 .ctl_name
= FS_MAXFILE
,
1204 .procname
= "file-max",
1205 .data
= &files_stat
.max_files
,
1206 .maxlen
= sizeof(int),
1208 .proc_handler
= &proc_dointvec
,
1211 .ctl_name
= CTL_UNNUMBERED
,
1212 .procname
= "nr_open",
1213 .data
= &sysctl_nr_open
,
1214 .maxlen
= sizeof(int),
1216 .proc_handler
= &proc_dointvec_minmax
,
1217 .extra1
= &sysctl_nr_open_min
,
1218 .extra2
= &sysctl_nr_open_max
,
1221 .ctl_name
= FS_DENTRY
,
1222 .procname
= "dentry-state",
1223 .data
= &dentry_stat
,
1224 .maxlen
= 6*sizeof(int),
1226 .proc_handler
= &proc_dointvec
,
1229 .ctl_name
= FS_OVERFLOWUID
,
1230 .procname
= "overflowuid",
1231 .data
= &fs_overflowuid
,
1232 .maxlen
= sizeof(int),
1234 .proc_handler
= &proc_dointvec_minmax
,
1235 .strategy
= &sysctl_intvec
,
1236 .extra1
= &minolduid
,
1237 .extra2
= &maxolduid
,
1240 .ctl_name
= FS_OVERFLOWGID
,
1241 .procname
= "overflowgid",
1242 .data
= &fs_overflowgid
,
1243 .maxlen
= sizeof(int),
1245 .proc_handler
= &proc_dointvec_minmax
,
1246 .strategy
= &sysctl_intvec
,
1247 .extra1
= &minolduid
,
1248 .extra2
= &maxolduid
,
1250 #ifdef CONFIG_FILE_LOCKING
1252 .ctl_name
= FS_LEASES
,
1253 .procname
= "leases-enable",
1254 .data
= &leases_enable
,
1255 .maxlen
= sizeof(int),
1257 .proc_handler
= &proc_dointvec
,
1260 #ifdef CONFIG_DNOTIFY
1262 .ctl_name
= FS_DIR_NOTIFY
,
1263 .procname
= "dir-notify-enable",
1264 .data
= &dir_notify_enable
,
1265 .maxlen
= sizeof(int),
1267 .proc_handler
= &proc_dointvec
,
1271 #ifdef CONFIG_FILE_LOCKING
1273 .ctl_name
= FS_LEASE_TIME
,
1274 .procname
= "lease-break-time",
1275 .data
= &lease_break_time
,
1276 .maxlen
= sizeof(int),
1278 .proc_handler
= &proc_dointvec_minmax
,
1279 .strategy
= &sysctl_intvec
,
1285 .procname
= "aio-nr",
1287 .maxlen
= sizeof(aio_nr
),
1289 .proc_handler
= &proc_doulongvec_minmax
,
1292 .procname
= "aio-max-nr",
1293 .data
= &aio_max_nr
,
1294 .maxlen
= sizeof(aio_max_nr
),
1296 .proc_handler
= &proc_doulongvec_minmax
,
1298 #ifdef CONFIG_INOTIFY_USER
1300 .ctl_name
= FS_INOTIFY
,
1301 .procname
= "inotify",
1303 .child
= inotify_table
,
1308 .ctl_name
= KERN_SETUID_DUMPABLE
,
1309 .procname
= "suid_dumpable",
1310 .data
= &suid_dumpable
,
1311 .maxlen
= sizeof(int),
1313 .proc_handler
= &proc_dointvec
,
1315 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1317 .ctl_name
= CTL_UNNUMBERED
,
1318 .procname
= "binfmt_misc",
1320 .child
= binfmt_misc_table
,
1324 * NOTE: do not add new entries to this table unless you have read
1325 * Documentation/sysctl/ctl_unnumbered.txt
1330 static struct ctl_table debug_table
[] = {
1331 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1333 .ctl_name
= CTL_UNNUMBERED
,
1334 .procname
= "exception-trace",
1335 .data
= &show_unhandled_signals
,
1336 .maxlen
= sizeof(int),
1338 .proc_handler
= proc_dointvec
1344 static struct ctl_table dev_table
[] = {
1348 static DEFINE_SPINLOCK(sysctl_lock
);
1350 /* called under sysctl_lock */
1351 static int use_table(struct ctl_table_header
*p
)
1353 if (unlikely(p
->unregistering
))
1359 /* called under sysctl_lock */
1360 static void unuse_table(struct ctl_table_header
*p
)
1363 if (unlikely(p
->unregistering
))
1364 complete(p
->unregistering
);
1367 /* called under sysctl_lock, will reacquire if has to wait */
1368 static void start_unregistering(struct ctl_table_header
*p
)
1371 * if p->used is 0, nobody will ever touch that entry again;
1372 * we'll eliminate all paths to it before dropping sysctl_lock
1374 if (unlikely(p
->used
)) {
1375 struct completion wait
;
1376 init_completion(&wait
);
1377 p
->unregistering
= &wait
;
1378 spin_unlock(&sysctl_lock
);
1379 wait_for_completion(&wait
);
1380 spin_lock(&sysctl_lock
);
1382 /* anything non-NULL; we'll never dereference it */
1383 p
->unregistering
= ERR_PTR(-EINVAL
);
1386 * do not remove from the list until nobody holds it; walking the
1387 * list in do_sysctl() relies on that.
1389 list_del_init(&p
->ctl_entry
);
1392 void sysctl_head_get(struct ctl_table_header
*head
)
1394 spin_lock(&sysctl_lock
);
1396 spin_unlock(&sysctl_lock
);
1399 void sysctl_head_put(struct ctl_table_header
*head
)
1401 spin_lock(&sysctl_lock
);
1404 spin_unlock(&sysctl_lock
);
1407 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1411 spin_lock(&sysctl_lock
);
1412 if (!use_table(head
))
1413 head
= ERR_PTR(-ENOENT
);
1414 spin_unlock(&sysctl_lock
);
1418 void sysctl_head_finish(struct ctl_table_header
*head
)
1422 spin_lock(&sysctl_lock
);
1424 spin_unlock(&sysctl_lock
);
1427 static struct ctl_table_set
*
1428 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1430 struct ctl_table_set
*set
= &root
->default_set
;
1432 set
= root
->lookup(root
, namespaces
);
1436 static struct list_head
*
1437 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1439 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1443 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1444 struct ctl_table_header
*prev
)
1446 struct ctl_table_root
*root
;
1447 struct list_head
*header_list
;
1448 struct ctl_table_header
*head
;
1449 struct list_head
*tmp
;
1451 spin_lock(&sysctl_lock
);
1454 tmp
= &prev
->ctl_entry
;
1458 tmp
= &root_table_header
.ctl_entry
;
1460 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1462 if (!use_table(head
))
1464 spin_unlock(&sysctl_lock
);
1469 header_list
= lookup_header_list(root
, namespaces
);
1470 if (tmp
!= header_list
)
1474 root
= list_entry(root
->root_list
.next
,
1475 struct ctl_table_root
, root_list
);
1476 if (root
== &sysctl_table_root
)
1478 header_list
= lookup_header_list(root
, namespaces
);
1479 } while (list_empty(header_list
));
1480 tmp
= header_list
->next
;
1483 spin_unlock(&sysctl_lock
);
1487 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1489 return __sysctl_head_next(current
->nsproxy
, prev
);
1492 void register_sysctl_root(struct ctl_table_root
*root
)
1494 spin_lock(&sysctl_lock
);
1495 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1496 spin_unlock(&sysctl_lock
);
1499 #ifdef CONFIG_SYSCTL_SYSCALL
1500 /* Perform the actual read/write of a sysctl table entry. */
1501 static int do_sysctl_strategy(struct ctl_table_root
*root
,
1502 struct ctl_table
*table
,
1503 int __user
*name
, int nlen
,
1504 void __user
*oldval
, size_t __user
*oldlenp
,
1505 void __user
*newval
, size_t newlen
)
1513 if (sysctl_perm(root
, table
, op
))
1516 if (table
->strategy
) {
1517 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1525 /* If there is no strategy routine, or if the strategy returns
1526 * zero, proceed with automatic r/w */
1527 if (table
->data
&& table
->maxlen
) {
1528 rc
= sysctl_data(table
, name
, nlen
, oldval
, oldlenp
,
1536 static int parse_table(int __user
*name
, int nlen
,
1537 void __user
*oldval
, size_t __user
*oldlenp
,
1538 void __user
*newval
, size_t newlen
,
1539 struct ctl_table_root
*root
,
1540 struct ctl_table
*table
)
1546 if (get_user(n
, name
))
1548 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1549 if (!table
->ctl_name
)
1551 if (n
== table
->ctl_name
) {
1554 if (sysctl_perm(root
, table
, MAY_EXEC
))
1558 table
= table
->child
;
1561 error
= do_sysctl_strategy(root
, table
, name
, nlen
,
1570 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1571 void __user
*newval
, size_t newlen
)
1573 struct ctl_table_header
*head
;
1574 int error
= -ENOTDIR
;
1576 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1580 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1584 for (head
= sysctl_head_next(NULL
); head
;
1585 head
= sysctl_head_next(head
)) {
1586 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1588 head
->root
, head
->ctl_table
);
1589 if (error
!= -ENOTDIR
) {
1590 sysctl_head_finish(head
);
1597 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1599 struct __sysctl_args tmp
;
1602 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1605 error
= deprecated_sysctl_warning(&tmp
);
1610 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1611 tmp
.newval
, tmp
.newlen
);
1616 #endif /* CONFIG_SYSCTL_SYSCALL */
1619 * sysctl_perm does NOT grant the superuser all rights automatically, because
1620 * some sysctl variables are readonly even to root.
1623 static int test_perm(int mode
, int op
)
1627 else if (in_egroup_p(0))
1629 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1634 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1639 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1643 if (root
->permissions
)
1644 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1648 return test_perm(mode
, op
);
1651 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1653 for (; table
->ctl_name
|| table
->procname
; table
++) {
1654 table
->parent
= parent
;
1656 sysctl_set_parent(table
, table
->child
);
1660 static __init
int sysctl_init(void)
1662 sysctl_set_parent(NULL
, root_table
);
1663 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1666 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1672 core_initcall(sysctl_init
);
1674 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1675 struct ctl_table
*table
)
1677 struct ctl_table
*p
;
1678 const char *s
= branch
->procname
;
1680 /* branch should have named subdirectory as its first element */
1681 if (!s
|| !branch
->child
)
1684 /* ... and nothing else */
1685 if (branch
[1].procname
|| branch
[1].ctl_name
)
1688 /* table should contain subdirectory with the same name */
1689 for (p
= table
; p
->procname
|| p
->ctl_name
; p
++) {
1692 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1698 /* see if attaching q to p would be an improvement */
1699 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1701 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1702 struct ctl_table
*next
;
1704 int not_in_parent
= !p
->attached_by
;
1706 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1707 if (by
== q
->attached_by
)
1709 if (to
== p
->attached_by
)
1715 if (is_better
&& not_in_parent
) {
1716 q
->attached_by
= by
;
1717 q
->attached_to
= to
;
1723 * __register_sysctl_paths - register a sysctl hierarchy
1724 * @root: List of sysctl headers to register on
1725 * @namespaces: Data to compute which lists of sysctl entries are visible
1726 * @path: The path to the directory the sysctl table is in.
1727 * @table: the top-level table structure
1729 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1730 * array. A completely 0 filled entry terminates the table.
1732 * The members of the &struct ctl_table structure are used as follows:
1734 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1735 * must be unique within that level of sysctl
1737 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1738 * enter a sysctl file
1740 * data - a pointer to data for use by proc_handler
1742 * maxlen - the maximum size in bytes of the data
1744 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1746 * child - a pointer to the child sysctl table if this entry is a directory, or
1749 * proc_handler - the text handler routine (described below)
1751 * strategy - the strategy routine (described below)
1753 * de - for internal use by the sysctl routines
1755 * extra1, extra2 - extra pointers usable by the proc handler routines
1757 * Leaf nodes in the sysctl tree will be represented by a single file
1758 * under /proc; non-leaf nodes will be represented by directories.
1760 * sysctl(2) can automatically manage read and write requests through
1761 * the sysctl table. The data and maxlen fields of the ctl_table
1762 * struct enable minimal validation of the values being written to be
1763 * performed, and the mode field allows minimal authentication.
1765 * More sophisticated management can be enabled by the provision of a
1766 * strategy routine with the table entry. This will be called before
1767 * any automatic read or write of the data is performed.
1769 * The strategy routine may return
1771 * < 0 - Error occurred (error is passed to user process)
1773 * 0 - OK - proceed with automatic read or write.
1775 * > 0 - OK - read or write has been done by the strategy routine, so
1776 * return immediately.
1778 * There must be a proc_handler routine for any terminal nodes
1779 * mirrored under /proc/sys (non-terminals are handled by a built-in
1780 * directory handler). Several default handlers are available to
1781 * cover common cases -
1783 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1784 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1785 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1787 * It is the handler's job to read the input buffer from user memory
1788 * and process it. The handler should return 0 on success.
1790 * This routine returns %NULL on a failure to register, and a pointer
1791 * to the table header on success.
1793 struct ctl_table_header
*__register_sysctl_paths(
1794 struct ctl_table_root
*root
,
1795 struct nsproxy
*namespaces
,
1796 const struct ctl_path
*path
, struct ctl_table
*table
)
1798 struct ctl_table_header
*header
;
1799 struct ctl_table
*new, **prevp
;
1800 unsigned int n
, npath
;
1801 struct ctl_table_set
*set
;
1803 /* Count the path components */
1804 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
1808 * For each path component, allocate a 2-element ctl_table array.
1809 * The first array element will be filled with the sysctl entry
1810 * for this, the second will be the sentinel (ctl_name == 0).
1812 * We allocate everything in one go so that we don't have to
1813 * worry about freeing additional memory in unregister_sysctl_table.
1815 header
= kzalloc(sizeof(struct ctl_table_header
) +
1816 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1820 new = (struct ctl_table
*) (header
+ 1);
1822 /* Now connect the dots */
1823 prevp
= &header
->ctl_table
;
1824 for (n
= 0; n
< npath
; ++n
, ++path
) {
1825 /* Copy the procname */
1826 new->procname
= path
->procname
;
1827 new->ctl_name
= path
->ctl_name
;
1831 prevp
= &new->child
;
1836 header
->ctl_table_arg
= table
;
1838 INIT_LIST_HEAD(&header
->ctl_entry
);
1840 header
->unregistering
= NULL
;
1841 header
->root
= root
;
1842 sysctl_set_parent(NULL
, header
->ctl_table
);
1844 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1845 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1850 spin_lock(&sysctl_lock
);
1851 header
->set
= lookup_header_set(root
, namespaces
);
1852 header
->attached_by
= header
->ctl_table
;
1853 header
->attached_to
= root_table
;
1854 header
->parent
= &root_table_header
;
1855 for (set
= header
->set
; set
; set
= set
->parent
) {
1856 struct ctl_table_header
*p
;
1857 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
1858 if (p
->unregistering
)
1860 try_attach(p
, header
);
1863 header
->parent
->count
++;
1864 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
1865 spin_unlock(&sysctl_lock
);
1871 * register_sysctl_table_path - register a sysctl table hierarchy
1872 * @path: The path to the directory the sysctl table is in.
1873 * @table: the top-level table structure
1875 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1876 * array. A completely 0 filled entry terminates the table.
1878 * See __register_sysctl_paths for more details.
1880 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1881 struct ctl_table
*table
)
1883 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1888 * register_sysctl_table - register a sysctl table hierarchy
1889 * @table: the top-level table structure
1891 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1892 * array. A completely 0 filled entry terminates the table.
1894 * See register_sysctl_paths for more details.
1896 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1898 static const struct ctl_path null_path
[] = { {} };
1900 return register_sysctl_paths(null_path
, table
);
1904 * unregister_sysctl_table - unregister a sysctl table hierarchy
1905 * @header: the header returned from register_sysctl_table
1907 * Unregisters the sysctl table and all children. proc entries may not
1908 * actually be removed until they are no longer used by anyone.
1910 void unregister_sysctl_table(struct ctl_table_header
* header
)
1917 spin_lock(&sysctl_lock
);
1918 start_unregistering(header
);
1919 if (!--header
->parent
->count
) {
1921 kfree(header
->parent
);
1923 if (!--header
->count
)
1925 spin_unlock(&sysctl_lock
);
1928 int sysctl_is_seen(struct ctl_table_header
*p
)
1930 struct ctl_table_set
*set
= p
->set
;
1932 spin_lock(&sysctl_lock
);
1933 if (p
->unregistering
)
1935 else if (!set
->is_seen
)
1938 res
= set
->is_seen(set
);
1939 spin_unlock(&sysctl_lock
);
1943 void setup_sysctl_set(struct ctl_table_set
*p
,
1944 struct ctl_table_set
*parent
,
1945 int (*is_seen
)(struct ctl_table_set
*))
1947 INIT_LIST_HEAD(&p
->list
);
1948 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
1949 p
->is_seen
= is_seen
;
1952 #else /* !CONFIG_SYSCTL */
1953 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1958 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1959 struct ctl_table
*table
)
1964 void unregister_sysctl_table(struct ctl_table_header
* table
)
1968 void setup_sysctl_set(struct ctl_table_set
*p
,
1969 struct ctl_table_set
*parent
,
1970 int (*is_seen
)(struct ctl_table_set
*))
1974 void sysctl_head_put(struct ctl_table_header
*head
)
1978 #endif /* CONFIG_SYSCTL */
1984 #ifdef CONFIG_PROC_SYSCTL
1986 static int _proc_do_string(void* data
, int maxlen
, int write
,
1987 struct file
*filp
, void __user
*buffer
,
1988 size_t *lenp
, loff_t
*ppos
)
1994 if (!data
|| !maxlen
|| !*lenp
) {
2002 while (len
< *lenp
) {
2003 if (get_user(c
, p
++))
2005 if (c
== 0 || c
== '\n')
2011 if(copy_from_user(data
, buffer
, len
))
2013 ((char *) data
)[len
] = 0;
2031 if(copy_to_user(buffer
, data
, len
))
2034 if(put_user('\n', ((char __user
*) buffer
) + len
))
2045 * proc_dostring - read a string sysctl
2046 * @table: the sysctl table
2047 * @write: %TRUE if this is a write to the sysctl file
2048 * @filp: the file structure
2049 * @buffer: the user buffer
2050 * @lenp: the size of the user buffer
2051 * @ppos: file position
2053 * Reads/writes a string from/to the user buffer. If the kernel
2054 * buffer provided is not large enough to hold the string, the
2055 * string is truncated. The copied string is %NULL-terminated.
2056 * If the string is being read by the user process, it is copied
2057 * and a newline '\n' is added. It is truncated if the buffer is
2060 * Returns 0 on success.
2062 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2063 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2065 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
2066 buffer
, lenp
, ppos
);
2070 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
2072 int write
, void *data
)
2075 *valp
= *negp
? -*lvalp
: *lvalp
;
2080 *lvalp
= (unsigned long)-val
;
2083 *lvalp
= (unsigned long)val
;
2089 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2090 int write
, struct file
*filp
, void __user
*buffer
,
2091 size_t *lenp
, loff_t
*ppos
,
2092 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2093 int write
, void *data
),
2096 #define TMPBUFLEN 21
2097 int *i
, vleft
, first
=1, neg
, val
;
2101 char buf
[TMPBUFLEN
], *p
;
2102 char __user
*s
= buffer
;
2104 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
2105 (*ppos
&& !write
)) {
2110 i
= (int *) tbl_data
;
2111 vleft
= table
->maxlen
/ sizeof(*i
);
2115 conv
= do_proc_dointvec_conv
;
2117 for (; left
&& vleft
--; i
++, first
=0) {
2132 if (len
> sizeof(buf
) - 1)
2133 len
= sizeof(buf
) - 1;
2134 if (copy_from_user(buf
, s
, len
))
2138 if (*p
== '-' && left
> 1) {
2142 if (*p
< '0' || *p
> '9')
2145 lval
= simple_strtoul(p
, &p
, 0);
2148 if ((len
< left
) && *p
&& !isspace(*p
))
2155 if (conv(&neg
, &lval
, i
, 1, data
))
2162 if (conv(&neg
, &lval
, i
, 0, data
))
2165 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2169 if(copy_to_user(s
, buf
, len
))
2176 if (!write
&& !first
&& left
) {
2177 if(put_user('\n', s
))
2184 if (get_user(c
, s
++))
2199 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2200 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2201 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2202 int write
, void *data
),
2205 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2206 buffer
, lenp
, ppos
, conv
, data
);
2210 * proc_dointvec - read a vector of integers
2211 * @table: the sysctl table
2212 * @write: %TRUE if this is a write to the sysctl file
2213 * @filp: the file structure
2214 * @buffer: the user buffer
2215 * @lenp: the size of the user buffer
2216 * @ppos: file position
2218 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2219 * values from/to the user buffer, treated as an ASCII string.
2221 * Returns 0 on success.
2223 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2224 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2226 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2231 * Taint values can only be increased
2232 * This means we can safely use a temporary.
2234 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2235 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2238 unsigned long tmptaint
= get_taint();
2241 if (write
&& !capable(CAP_SYS_ADMIN
))
2246 err
= proc_doulongvec_minmax(&t
, write
, filp
, buffer
, lenp
, ppos
);
2252 * Poor man's atomic or. Not worth adding a primitive
2253 * to everyone's atomic.h for this
2256 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2257 if ((tmptaint
>> i
) & 1)
2265 struct do_proc_dointvec_minmax_conv_param
{
2270 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2272 int write
, void *data
)
2274 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2276 int val
= *negp
? -*lvalp
: *lvalp
;
2277 if ((param
->min
&& *param
->min
> val
) ||
2278 (param
->max
&& *param
->max
< val
))
2285 *lvalp
= (unsigned long)-val
;
2288 *lvalp
= (unsigned long)val
;
2295 * proc_dointvec_minmax - read a vector of integers with min/max values
2296 * @table: the sysctl table
2297 * @write: %TRUE if this is a write to the sysctl file
2298 * @filp: the file structure
2299 * @buffer: the user buffer
2300 * @lenp: the size of the user buffer
2301 * @ppos: file position
2303 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2304 * values from/to the user buffer, treated as an ASCII string.
2306 * This routine will ensure the values are within the range specified by
2307 * table->extra1 (min) and table->extra2 (max).
2309 * Returns 0 on success.
2311 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2312 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2314 struct do_proc_dointvec_minmax_conv_param param
= {
2315 .min
= (int *) table
->extra1
,
2316 .max
= (int *) table
->extra2
,
2318 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2319 do_proc_dointvec_minmax_conv
, ¶m
);
2322 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2324 void __user
*buffer
,
2325 size_t *lenp
, loff_t
*ppos
,
2326 unsigned long convmul
,
2327 unsigned long convdiv
)
2329 #define TMPBUFLEN 21
2330 unsigned long *i
, *min
, *max
, val
;
2331 int vleft
, first
=1, neg
;
2333 char buf
[TMPBUFLEN
], *p
;
2334 char __user
*s
= buffer
;
2336 if (!data
|| !table
->maxlen
|| !*lenp
||
2337 (*ppos
&& !write
)) {
2342 i
= (unsigned long *) data
;
2343 min
= (unsigned long *) table
->extra1
;
2344 max
= (unsigned long *) table
->extra2
;
2345 vleft
= table
->maxlen
/ sizeof(unsigned long);
2348 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2363 if (len
> TMPBUFLEN
-1)
2365 if (copy_from_user(buf
, s
, len
))
2369 if (*p
== '-' && left
> 1) {
2373 if (*p
< '0' || *p
> '9')
2375 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2377 if ((len
< left
) && *p
&& !isspace(*p
))
2386 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2393 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2397 if(copy_to_user(s
, buf
, len
))
2404 if (!write
&& !first
&& left
) {
2405 if(put_user('\n', s
))
2412 if (get_user(c
, s
++))
2427 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2429 void __user
*buffer
,
2430 size_t *lenp
, loff_t
*ppos
,
2431 unsigned long convmul
,
2432 unsigned long convdiv
)
2434 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2435 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2439 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2440 * @table: the sysctl table
2441 * @write: %TRUE if this is a write to the sysctl file
2442 * @filp: the file structure
2443 * @buffer: the user buffer
2444 * @lenp: the size of the user buffer
2445 * @ppos: file position
2447 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2448 * values from/to the user buffer, treated as an ASCII string.
2450 * This routine will ensure the values are within the range specified by
2451 * table->extra1 (min) and table->extra2 (max).
2453 * Returns 0 on success.
2455 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2456 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2458 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2462 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2463 * @table: the sysctl table
2464 * @write: %TRUE if this is a write to the sysctl file
2465 * @filp: the file structure
2466 * @buffer: the user buffer
2467 * @lenp: the size of the user buffer
2468 * @ppos: file position
2470 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2471 * values from/to the user buffer, treated as an ASCII string. The values
2472 * are treated as milliseconds, and converted to jiffies when they are stored.
2474 * This routine will ensure the values are within the range specified by
2475 * table->extra1 (min) and table->extra2 (max).
2477 * Returns 0 on success.
2479 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2481 void __user
*buffer
,
2482 size_t *lenp
, loff_t
*ppos
)
2484 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2485 lenp
, ppos
, HZ
, 1000l);
2489 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2491 int write
, void *data
)
2494 if (*lvalp
> LONG_MAX
/ HZ
)
2496 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2502 lval
= (unsigned long)-val
;
2505 lval
= (unsigned long)val
;
2512 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2514 int write
, void *data
)
2517 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2519 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2525 lval
= (unsigned long)-val
;
2528 lval
= (unsigned long)val
;
2530 *lvalp
= jiffies_to_clock_t(lval
);
2535 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2537 int write
, void *data
)
2540 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2546 lval
= (unsigned long)-val
;
2549 lval
= (unsigned long)val
;
2551 *lvalp
= jiffies_to_msecs(lval
);
2557 * proc_dointvec_jiffies - read a vector of integers as seconds
2558 * @table: the sysctl table
2559 * @write: %TRUE if this is a write to the sysctl file
2560 * @filp: the file structure
2561 * @buffer: the user buffer
2562 * @lenp: the size of the user buffer
2563 * @ppos: file position
2565 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2566 * values from/to the user buffer, treated as an ASCII string.
2567 * The values read are assumed to be in seconds, and are converted into
2570 * Returns 0 on success.
2572 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2573 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2575 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2576 do_proc_dointvec_jiffies_conv
,NULL
);
2580 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2581 * @table: the sysctl table
2582 * @write: %TRUE if this is a write to the sysctl file
2583 * @filp: the file structure
2584 * @buffer: the user buffer
2585 * @lenp: the size of the user buffer
2586 * @ppos: pointer to the file position
2588 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2589 * values from/to the user buffer, treated as an ASCII string.
2590 * The values read are assumed to be in 1/USER_HZ seconds, and
2591 * are converted into jiffies.
2593 * Returns 0 on success.
2595 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2596 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2598 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2599 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2603 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2604 * @table: the sysctl table
2605 * @write: %TRUE if this is a write to the sysctl file
2606 * @filp: the file structure
2607 * @buffer: the user buffer
2608 * @lenp: the size of the user buffer
2609 * @ppos: file position
2610 * @ppos: the current position in the file
2612 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2613 * values from/to the user buffer, treated as an ASCII string.
2614 * The values read are assumed to be in 1/1000 seconds, and
2615 * are converted into jiffies.
2617 * Returns 0 on success.
2619 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2620 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2622 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2623 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2626 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2627 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2629 struct pid
*new_pid
;
2633 tmp
= pid_vnr(cad_pid
);
2635 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2636 lenp
, ppos
, NULL
, NULL
);
2640 new_pid
= find_get_pid(tmp
);
2644 put_pid(xchg(&cad_pid
, new_pid
));
2648 #else /* CONFIG_PROC_FS */
2650 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2651 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2656 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2657 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2662 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2663 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2668 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2669 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2674 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2675 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2680 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2681 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2686 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2687 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2692 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2694 void __user
*buffer
,
2695 size_t *lenp
, loff_t
*ppos
)
2701 #endif /* CONFIG_PROC_FS */
2704 #ifdef CONFIG_SYSCTL_SYSCALL
2706 * General sysctl support routines
2709 /* The generic sysctl data routine (used if no strategy routine supplied) */
2710 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2711 void __user
*oldval
, size_t __user
*oldlenp
,
2712 void __user
*newval
, size_t newlen
)
2716 /* Get out of I don't have a variable */
2717 if (!table
->data
|| !table
->maxlen
)
2720 if (oldval
&& oldlenp
) {
2721 if (get_user(len
, oldlenp
))
2724 if (len
> table
->maxlen
)
2725 len
= table
->maxlen
;
2726 if (copy_to_user(oldval
, table
->data
, len
))
2728 if (put_user(len
, oldlenp
))
2733 if (newval
&& newlen
) {
2734 if (newlen
> table
->maxlen
)
2735 newlen
= table
->maxlen
;
2737 if (copy_from_user(table
->data
, newval
, newlen
))
2743 /* The generic string strategy routine: */
2744 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2745 void __user
*oldval
, size_t __user
*oldlenp
,
2746 void __user
*newval
, size_t newlen
)
2748 if (!table
->data
|| !table
->maxlen
)
2751 if (oldval
&& oldlenp
) {
2753 if (get_user(bufsize
, oldlenp
))
2756 size_t len
= strlen(table
->data
), copied
;
2758 /* This shouldn't trigger for a well-formed sysctl */
2759 if (len
> table
->maxlen
)
2760 len
= table
->maxlen
;
2762 /* Copy up to a max of bufsize-1 bytes of the string */
2763 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2765 if (copy_to_user(oldval
, table
->data
, copied
) ||
2766 put_user(0, (char __user
*)(oldval
+ copied
)))
2768 if (put_user(len
, oldlenp
))
2772 if (newval
&& newlen
) {
2773 size_t len
= newlen
;
2774 if (len
> table
->maxlen
)
2775 len
= table
->maxlen
;
2776 if(copy_from_user(table
->data
, newval
, len
))
2778 if (len
== table
->maxlen
)
2780 ((char *) table
->data
)[len
] = 0;
2786 * This function makes sure that all of the integers in the vector
2787 * are between the minimum and maximum values given in the arrays
2788 * table->extra1 and table->extra2, respectively.
2790 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2791 void __user
*oldval
, size_t __user
*oldlenp
,
2792 void __user
*newval
, size_t newlen
)
2795 if (newval
&& newlen
) {
2796 int __user
*vec
= (int __user
*) newval
;
2797 int *min
= (int *) table
->extra1
;
2798 int *max
= (int *) table
->extra2
;
2802 if (newlen
% sizeof(int) != 0)
2805 if (!table
->extra1
&& !table
->extra2
)
2808 if (newlen
> table
->maxlen
)
2809 newlen
= table
->maxlen
;
2810 length
= newlen
/ sizeof(int);
2812 for (i
= 0; i
< length
; i
++) {
2814 if (get_user(value
, vec
+ i
))
2816 if (min
&& value
< min
[i
])
2818 if (max
&& value
> max
[i
])
2825 /* Strategy function to convert jiffies to seconds */
2826 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2827 void __user
*oldval
, size_t __user
*oldlenp
,
2828 void __user
*newval
, size_t newlen
)
2830 if (oldval
&& oldlenp
) {
2833 if (get_user(olen
, oldlenp
))
2838 if (olen
< sizeof(int))
2841 val
= *(int *)(table
->data
) / HZ
;
2842 if (put_user(val
, (int __user
*)oldval
))
2844 if (put_user(sizeof(int), oldlenp
))
2848 if (newval
&& newlen
) {
2850 if (newlen
!= sizeof(int))
2852 if (get_user(new, (int __user
*)newval
))
2854 *(int *)(table
->data
) = new*HZ
;
2859 /* Strategy function to convert jiffies to seconds */
2860 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2861 void __user
*oldval
, size_t __user
*oldlenp
,
2862 void __user
*newval
, size_t newlen
)
2864 if (oldval
&& oldlenp
) {
2867 if (get_user(olen
, oldlenp
))
2872 if (olen
< sizeof(int))
2875 val
= jiffies_to_msecs(*(int *)(table
->data
));
2876 if (put_user(val
, (int __user
*)oldval
))
2878 if (put_user(sizeof(int), oldlenp
))
2882 if (newval
&& newlen
) {
2884 if (newlen
!= sizeof(int))
2886 if (get_user(new, (int __user
*)newval
))
2888 *(int *)(table
->data
) = msecs_to_jiffies(new);
2895 #else /* CONFIG_SYSCTL_SYSCALL */
2898 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2900 struct __sysctl_args tmp
;
2903 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
2906 error
= deprecated_sysctl_warning(&tmp
);
2908 /* If no error reading the parameters then just -ENOSYS ... */
2915 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2916 void __user
*oldval
, size_t __user
*oldlenp
,
2917 void __user
*newval
, size_t newlen
)
2922 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2923 void __user
*oldval
, size_t __user
*oldlenp
,
2924 void __user
*newval
, size_t newlen
)
2929 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2930 void __user
*oldval
, size_t __user
*oldlenp
,
2931 void __user
*newval
, size_t newlen
)
2936 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2937 void __user
*oldval
, size_t __user
*oldlenp
,
2938 void __user
*newval
, size_t newlen
)
2943 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2944 void __user
*oldval
, size_t __user
*oldlenp
,
2945 void __user
*newval
, size_t newlen
)
2950 #endif /* CONFIG_SYSCTL_SYSCALL */
2952 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
2954 static int msg_count
;
2955 int name
[CTL_MAXNAME
];
2958 /* Check args->nlen. */
2959 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
2962 /* Read in the sysctl name for better debug message logging */
2963 for (i
= 0; i
< args
->nlen
; i
++)
2964 if (get_user(name
[i
], args
->name
+ i
))
2967 /* Ignore accesses to kernel.version */
2968 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
2971 if (msg_count
< 5) {
2974 "warning: process `%s' used the deprecated sysctl "
2975 "system call with ", current
->comm
);
2976 for (i
= 0; i
< args
->nlen
; i
++)
2977 printk("%d.", name
[i
]);
2984 * No sense putting this after each symbol definition, twice,
2985 * exception granted :-)
2987 EXPORT_SYMBOL(proc_dointvec
);
2988 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2989 EXPORT_SYMBOL(proc_dointvec_minmax
);
2990 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2991 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2992 EXPORT_SYMBOL(proc_dostring
);
2993 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2994 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2995 EXPORT_SYMBOL(register_sysctl_table
);
2996 EXPORT_SYMBOL(register_sysctl_paths
);
2997 EXPORT_SYMBOL(sysctl_intvec
);
2998 EXPORT_SYMBOL(sysctl_jiffies
);
2999 EXPORT_SYMBOL(sysctl_ms_jiffies
);
3000 EXPORT_SYMBOL(sysctl_string
);
3001 EXPORT_SYMBOL(sysctl_data
);
3002 EXPORT_SYMBOL(unregister_sysctl_table
);