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
;
86 extern int sysctl_nr_trim_pages
;
88 #ifdef CONFIG_RCU_TORTURE_TEST
89 extern int rcutorture_runnable
;
90 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
92 /* Constants used for minimum and maximum */
93 #ifdef CONFIG_DETECT_SOFTLOCKUP
94 static int sixty
= 60;
95 static int neg_one
= -1;
98 #if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING)
104 static unsigned long one_ul
= 1;
105 static int one_hundred
= 100;
107 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
108 static int maxolduid
= 65535;
109 static int minolduid
;
110 static int min_percpu_pagelist_fract
= 8;
112 static int ngroups_max
= NGROUPS_MAX
;
114 #ifdef CONFIG_MODULES
115 extern char modprobe_path
[];
117 #ifdef CONFIG_FB_CON_DECOR
118 extern char fbcon_decor_path
[];
120 #ifdef CONFIG_CHR_DEV_SG
121 extern int sg_big_buff
;
125 #include <asm/system.h>
128 #ifdef CONFIG_SPARC64
129 extern int sysctl_tsb_ratio
;
133 extern int pwrsw_enabled
;
134 extern int unaligned_enabled
;
138 #ifdef CONFIG_MATHEMU
139 extern int sysctl_ieee_emulation_warnings
;
141 extern int sysctl_userprocess_debug
;
142 extern int spin_retry
;
145 #ifdef CONFIG_BSD_PROCESS_ACCT
146 extern int acct_parm
[];
150 extern int no_unaligned_warning
;
151 extern int unaligned_dump_stack
;
154 #ifdef CONFIG_RT_MUTEXES
155 extern int max_lock_depth
;
158 #ifdef CONFIG_PROC_SYSCTL
159 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
160 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
161 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
162 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
165 static struct ctl_table root_table
[];
166 static struct ctl_table_root sysctl_table_root
;
167 static struct ctl_table_header root_table_header
= {
169 .ctl_table
= root_table
,
170 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),
171 .root
= &sysctl_table_root
,
172 .set
= &sysctl_table_root
.default_set
,
174 static struct ctl_table_root sysctl_table_root
= {
175 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
176 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
179 static struct ctl_table kern_table
[];
180 static struct ctl_table vm_table
[];
181 static struct ctl_table fs_table
[];
182 static struct ctl_table debug_table
[];
183 static struct ctl_table dev_table
[];
184 extern struct ctl_table random_table
[];
185 #ifdef CONFIG_INOTIFY_USER
186 extern struct ctl_table inotify_table
[];
189 extern struct ctl_table epoll_table
[];
192 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
193 int sysctl_legacy_va_layout
;
196 extern int prove_locking
;
197 extern int lock_stat
;
199 /* The default sysctl tables: */
201 static struct ctl_table root_table
[] = {
203 .ctl_name
= CTL_KERN
,
204 .procname
= "kernel",
221 .ctl_name
= CTL_DEBUG
,
224 .child
= debug_table
,
232 #ifdef CONFIG_FB_CON_DECOR
234 .ctl_name
= CTL_UNNUMBERED
,
235 .procname
= "fbcondecor",
236 .data
= &fbcon_decor_path
,
237 .maxlen
= KMOD_PATH_LEN
,
239 .proc_handler
= &proc_dostring
,
240 .strategy
= &sysctl_string
,
245 * NOTE: do not add new entries to this table unless you have read
246 * Documentation/sysctl/ctl_unnumbered.txt
251 #ifdef CONFIG_SCHED_DEBUG
252 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
253 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
254 static int min_wakeup_granularity_ns
; /* 0 usecs */
255 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
258 static struct ctl_table kern_table
[] = {
259 #ifdef CONFIG_SCHED_DEBUG
261 .ctl_name
= CTL_UNNUMBERED
,
262 .procname
= "sched_min_granularity_ns",
263 .data
= &sysctl_sched_min_granularity
,
264 .maxlen
= sizeof(unsigned int),
266 .proc_handler
= &sched_nr_latency_handler
,
267 .strategy
= &sysctl_intvec
,
268 .extra1
= &min_sched_granularity_ns
,
269 .extra2
= &max_sched_granularity_ns
,
272 .ctl_name
= CTL_UNNUMBERED
,
273 .procname
= "sched_latency_ns",
274 .data
= &sysctl_sched_latency
,
275 .maxlen
= sizeof(unsigned int),
277 .proc_handler
= &sched_nr_latency_handler
,
278 .strategy
= &sysctl_intvec
,
279 .extra1
= &min_sched_granularity_ns
,
280 .extra2
= &max_sched_granularity_ns
,
283 .ctl_name
= CTL_UNNUMBERED
,
284 .procname
= "sched_wakeup_granularity_ns",
285 .data
= &sysctl_sched_wakeup_granularity
,
286 .maxlen
= sizeof(unsigned int),
288 .proc_handler
= &proc_dointvec_minmax
,
289 .strategy
= &sysctl_intvec
,
290 .extra1
= &min_wakeup_granularity_ns
,
291 .extra2
= &max_wakeup_granularity_ns
,
294 .ctl_name
= CTL_UNNUMBERED
,
295 .procname
= "sched_shares_ratelimit",
296 .data
= &sysctl_sched_shares_ratelimit
,
297 .maxlen
= sizeof(unsigned int),
299 .proc_handler
= &proc_dointvec
,
302 .ctl_name
= CTL_UNNUMBERED
,
303 .procname
= "sched_shares_thresh",
304 .data
= &sysctl_sched_shares_thresh
,
305 .maxlen
= sizeof(unsigned int),
307 .proc_handler
= &proc_dointvec_minmax
,
308 .strategy
= &sysctl_intvec
,
312 .ctl_name
= CTL_UNNUMBERED
,
313 .procname
= "sched_child_runs_first",
314 .data
= &sysctl_sched_child_runs_first
,
315 .maxlen
= sizeof(unsigned int),
317 .proc_handler
= &proc_dointvec
,
320 .ctl_name
= CTL_UNNUMBERED
,
321 .procname
= "sched_features",
322 .data
= &sysctl_sched_features
,
323 .maxlen
= sizeof(unsigned int),
325 .proc_handler
= &proc_dointvec
,
328 .ctl_name
= CTL_UNNUMBERED
,
329 .procname
= "sched_migration_cost",
330 .data
= &sysctl_sched_migration_cost
,
331 .maxlen
= sizeof(unsigned int),
333 .proc_handler
= &proc_dointvec
,
336 .ctl_name
= CTL_UNNUMBERED
,
337 .procname
= "sched_nr_migrate",
338 .data
= &sysctl_sched_nr_migrate
,
339 .maxlen
= sizeof(unsigned int),
341 .proc_handler
= &proc_dointvec
,
345 .ctl_name
= CTL_UNNUMBERED
,
346 .procname
= "sched_rt_period_us",
347 .data
= &sysctl_sched_rt_period
,
348 .maxlen
= sizeof(unsigned int),
350 .proc_handler
= &sched_rt_handler
,
353 .ctl_name
= CTL_UNNUMBERED
,
354 .procname
= "sched_rt_runtime_us",
355 .data
= &sysctl_sched_rt_runtime
,
356 .maxlen
= sizeof(int),
358 .proc_handler
= &sched_rt_handler
,
361 .ctl_name
= CTL_UNNUMBERED
,
362 .procname
= "sched_compat_yield",
363 .data
= &sysctl_sched_compat_yield
,
364 .maxlen
= sizeof(unsigned int),
366 .proc_handler
= &proc_dointvec
,
368 #ifdef CONFIG_PROVE_LOCKING
370 .ctl_name
= CTL_UNNUMBERED
,
371 .procname
= "prove_locking",
372 .data
= &prove_locking
,
373 .maxlen
= sizeof(int),
375 .proc_handler
= &proc_dointvec
,
378 #ifdef CONFIG_LOCK_STAT
380 .ctl_name
= CTL_UNNUMBERED
,
381 .procname
= "lock_stat",
383 .maxlen
= sizeof(int),
385 .proc_handler
= &proc_dointvec
,
389 .ctl_name
= KERN_PANIC
,
391 .data
= &panic_timeout
,
392 .maxlen
= sizeof(int),
394 .proc_handler
= &proc_dointvec
,
397 .ctl_name
= KERN_CORE_USES_PID
,
398 .procname
= "core_uses_pid",
399 .data
= &core_uses_pid
,
400 .maxlen
= sizeof(int),
402 .proc_handler
= &proc_dointvec
,
405 .ctl_name
= KERN_CORE_PATTERN
,
406 .procname
= "core_pattern",
407 .data
= core_pattern
,
408 .maxlen
= CORENAME_MAX_SIZE
,
410 .proc_handler
= &proc_dostring
,
411 .strategy
= &sysctl_string
,
413 #ifdef CONFIG_PROC_SYSCTL
415 .procname
= "tainted",
416 .maxlen
= sizeof(long),
418 .proc_handler
= &proc_taint
,
421 #ifdef CONFIG_LATENCYTOP
423 .procname
= "latencytop",
424 .data
= &latencytop_enabled
,
425 .maxlen
= sizeof(int),
427 .proc_handler
= &proc_dointvec
,
430 #ifdef CONFIG_BLK_DEV_INITRD
432 .ctl_name
= KERN_REALROOTDEV
,
433 .procname
= "real-root-dev",
434 .data
= &real_root_dev
,
435 .maxlen
= sizeof(int),
437 .proc_handler
= &proc_dointvec
,
441 .ctl_name
= CTL_UNNUMBERED
,
442 .procname
= "print-fatal-signals",
443 .data
= &print_fatal_signals
,
444 .maxlen
= sizeof(int),
446 .proc_handler
= &proc_dointvec
,
450 .ctl_name
= KERN_SPARC_REBOOT
,
451 .procname
= "reboot-cmd",
452 .data
= reboot_command
,
455 .proc_handler
= &proc_dostring
,
456 .strategy
= &sysctl_string
,
459 .ctl_name
= KERN_SPARC_STOP_A
,
460 .procname
= "stop-a",
461 .data
= &stop_a_enabled
,
462 .maxlen
= sizeof (int),
464 .proc_handler
= &proc_dointvec
,
467 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
468 .procname
= "scons-poweroff",
469 .data
= &scons_pwroff
,
470 .maxlen
= sizeof (int),
472 .proc_handler
= &proc_dointvec
,
475 #ifdef CONFIG_SPARC64
477 .ctl_name
= CTL_UNNUMBERED
,
478 .procname
= "tsb-ratio",
479 .data
= &sysctl_tsb_ratio
,
480 .maxlen
= sizeof (int),
482 .proc_handler
= &proc_dointvec
,
487 .ctl_name
= KERN_HPPA_PWRSW
,
488 .procname
= "soft-power",
489 .data
= &pwrsw_enabled
,
490 .maxlen
= sizeof (int),
492 .proc_handler
= &proc_dointvec
,
495 .ctl_name
= KERN_HPPA_UNALIGNED
,
496 .procname
= "unaligned-trap",
497 .data
= &unaligned_enabled
,
498 .maxlen
= sizeof (int),
500 .proc_handler
= &proc_dointvec
,
504 .ctl_name
= KERN_CTLALTDEL
,
505 .procname
= "ctrl-alt-del",
507 .maxlen
= sizeof(int),
509 .proc_handler
= &proc_dointvec
,
511 #ifdef CONFIG_FUNCTION_TRACER
513 .ctl_name
= CTL_UNNUMBERED
,
514 .procname
= "ftrace_enabled",
515 .data
= &ftrace_enabled
,
516 .maxlen
= sizeof(int),
518 .proc_handler
= &ftrace_enable_sysctl
,
521 #ifdef CONFIG_STACK_TRACER
523 .ctl_name
= CTL_UNNUMBERED
,
524 .procname
= "stack_tracer_enabled",
525 .data
= &stack_tracer_enabled
,
526 .maxlen
= sizeof(int),
528 .proc_handler
= &stack_trace_sysctl
,
531 #ifdef CONFIG_TRACING
533 .ctl_name
= CTL_UNNUMBERED
,
534 .procname
= "ftrace_dump_on_oops",
535 .data
= &ftrace_dump_on_oops
,
536 .maxlen
= sizeof(int),
538 .proc_handler
= &proc_dointvec
,
541 #ifdef CONFIG_MODULES
543 .ctl_name
= KERN_MODPROBE
,
544 .procname
= "modprobe",
545 .data
= &modprobe_path
,
546 .maxlen
= KMOD_PATH_LEN
,
548 .proc_handler
= &proc_dostring
,
549 .strategy
= &sysctl_string
,
552 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
554 .ctl_name
= KERN_HOTPLUG
,
555 .procname
= "hotplug",
556 .data
= &uevent_helper
,
557 .maxlen
= UEVENT_HELPER_PATH_LEN
,
559 .proc_handler
= &proc_dostring
,
560 .strategy
= &sysctl_string
,
563 #ifdef CONFIG_CHR_DEV_SG
565 .ctl_name
= KERN_SG_BIG_BUFF
,
566 .procname
= "sg-big-buff",
567 .data
= &sg_big_buff
,
568 .maxlen
= sizeof (int),
570 .proc_handler
= &proc_dointvec
,
573 #ifdef CONFIG_BSD_PROCESS_ACCT
575 .ctl_name
= KERN_ACCT
,
578 .maxlen
= 3*sizeof(int),
580 .proc_handler
= &proc_dointvec
,
583 #ifdef CONFIG_MAGIC_SYSRQ
585 .ctl_name
= KERN_SYSRQ
,
587 .data
= &__sysrq_enabled
,
588 .maxlen
= sizeof (int),
590 .proc_handler
= &proc_dointvec
,
593 #ifdef CONFIG_PROC_SYSCTL
595 .procname
= "cad_pid",
597 .maxlen
= sizeof (int),
599 .proc_handler
= &proc_do_cad_pid
,
603 .ctl_name
= KERN_MAX_THREADS
,
604 .procname
= "threads-max",
605 .data
= &max_threads
,
606 .maxlen
= sizeof(int),
608 .proc_handler
= &proc_dointvec
,
611 .ctl_name
= KERN_RANDOM
,
612 .procname
= "random",
614 .child
= random_table
,
617 .ctl_name
= KERN_OVERFLOWUID
,
618 .procname
= "overflowuid",
619 .data
= &overflowuid
,
620 .maxlen
= sizeof(int),
622 .proc_handler
= &proc_dointvec_minmax
,
623 .strategy
= &sysctl_intvec
,
624 .extra1
= &minolduid
,
625 .extra2
= &maxolduid
,
628 .ctl_name
= KERN_OVERFLOWGID
,
629 .procname
= "overflowgid",
630 .data
= &overflowgid
,
631 .maxlen
= sizeof(int),
633 .proc_handler
= &proc_dointvec_minmax
,
634 .strategy
= &sysctl_intvec
,
635 .extra1
= &minolduid
,
636 .extra2
= &maxolduid
,
639 #ifdef CONFIG_MATHEMU
641 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
642 .procname
= "ieee_emulation_warnings",
643 .data
= &sysctl_ieee_emulation_warnings
,
644 .maxlen
= sizeof(int),
646 .proc_handler
= &proc_dointvec
,
650 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
651 .procname
= "userprocess_debug",
652 .data
= &sysctl_userprocess_debug
,
653 .maxlen
= sizeof(int),
655 .proc_handler
= &proc_dointvec
,
659 .ctl_name
= KERN_PIDMAX
,
660 .procname
= "pid_max",
662 .maxlen
= sizeof (int),
664 .proc_handler
= &proc_dointvec_minmax
,
665 .strategy
= sysctl_intvec
,
666 .extra1
= &pid_max_min
,
667 .extra2
= &pid_max_max
,
670 .ctl_name
= KERN_PANIC_ON_OOPS
,
671 .procname
= "panic_on_oops",
672 .data
= &panic_on_oops
,
673 .maxlen
= sizeof(int),
675 .proc_handler
= &proc_dointvec
,
677 #if defined CONFIG_PRINTK
679 .ctl_name
= KERN_PRINTK
,
680 .procname
= "printk",
681 .data
= &console_loglevel
,
682 .maxlen
= 4*sizeof(int),
684 .proc_handler
= &proc_dointvec
,
687 .ctl_name
= KERN_PRINTK_RATELIMIT
,
688 .procname
= "printk_ratelimit",
689 .data
= &printk_ratelimit_state
.interval
,
690 .maxlen
= sizeof(int),
692 .proc_handler
= &proc_dointvec_jiffies
,
693 .strategy
= &sysctl_jiffies
,
696 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
697 .procname
= "printk_ratelimit_burst",
698 .data
= &printk_ratelimit_state
.burst
,
699 .maxlen
= sizeof(int),
701 .proc_handler
= &proc_dointvec
,
705 .ctl_name
= KERN_NGROUPS_MAX
,
706 .procname
= "ngroups_max",
707 .data
= &ngroups_max
,
708 .maxlen
= sizeof (int),
710 .proc_handler
= &proc_dointvec
,
712 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
714 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
715 .procname
= "unknown_nmi_panic",
716 .data
= &unknown_nmi_panic
,
717 .maxlen
= sizeof (int),
719 .proc_handler
= &proc_dointvec
,
722 .procname
= "nmi_watchdog",
723 .data
= &nmi_watchdog_enabled
,
724 .maxlen
= sizeof (int),
726 .proc_handler
= &proc_nmi_enabled
,
729 #if defined(CONFIG_X86)
731 .ctl_name
= KERN_PANIC_ON_NMI
,
732 .procname
= "panic_on_unrecovered_nmi",
733 .data
= &panic_on_unrecovered_nmi
,
734 .maxlen
= sizeof(int),
736 .proc_handler
= &proc_dointvec
,
739 .ctl_name
= KERN_BOOTLOADER_TYPE
,
740 .procname
= "bootloader_type",
741 .data
= &bootloader_type
,
742 .maxlen
= sizeof (int),
744 .proc_handler
= &proc_dointvec
,
747 .ctl_name
= CTL_UNNUMBERED
,
748 .procname
= "kstack_depth_to_print",
749 .data
= &kstack_depth_to_print
,
750 .maxlen
= sizeof(int),
752 .proc_handler
= &proc_dointvec
,
755 .ctl_name
= CTL_UNNUMBERED
,
756 .procname
= "io_delay_type",
757 .data
= &io_delay_type
,
758 .maxlen
= sizeof(int),
760 .proc_handler
= &proc_dointvec
,
763 #if defined(CONFIG_MMU)
765 .ctl_name
= KERN_RANDOMIZE
,
766 .procname
= "randomize_va_space",
767 .data
= &randomize_va_space
,
768 .maxlen
= sizeof(int),
770 .proc_handler
= &proc_dointvec
,
773 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
775 .ctl_name
= KERN_SPIN_RETRY
,
776 .procname
= "spin_retry",
778 .maxlen
= sizeof (int),
780 .proc_handler
= &proc_dointvec
,
783 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
785 .procname
= "acpi_video_flags",
786 .data
= &acpi_realmode_flags
,
787 .maxlen
= sizeof (unsigned long),
789 .proc_handler
= &proc_doulongvec_minmax
,
794 .ctl_name
= KERN_IA64_UNALIGNED
,
795 .procname
= "ignore-unaligned-usertrap",
796 .data
= &no_unaligned_warning
,
797 .maxlen
= sizeof (int),
799 .proc_handler
= &proc_dointvec
,
802 .ctl_name
= CTL_UNNUMBERED
,
803 .procname
= "unaligned-dump-stack",
804 .data
= &unaligned_dump_stack
,
805 .maxlen
= sizeof (int),
807 .proc_handler
= &proc_dointvec
,
810 #ifdef CONFIG_DETECT_SOFTLOCKUP
812 .ctl_name
= CTL_UNNUMBERED
,
813 .procname
= "softlockup_panic",
814 .data
= &softlockup_panic
,
815 .maxlen
= sizeof(int),
817 .proc_handler
= &proc_dointvec_minmax
,
818 .strategy
= &sysctl_intvec
,
823 .ctl_name
= CTL_UNNUMBERED
,
824 .procname
= "softlockup_thresh",
825 .data
= &softlockup_thresh
,
826 .maxlen
= sizeof(int),
828 .proc_handler
= &proc_dosoftlockup_thresh
,
829 .strategy
= &sysctl_intvec
,
834 .ctl_name
= CTL_UNNUMBERED
,
835 .procname
= "hung_task_check_count",
836 .data
= &sysctl_hung_task_check_count
,
837 .maxlen
= sizeof(unsigned long),
839 .proc_handler
= &proc_doulongvec_minmax
,
840 .strategy
= &sysctl_intvec
,
843 .ctl_name
= CTL_UNNUMBERED
,
844 .procname
= "hung_task_timeout_secs",
845 .data
= &sysctl_hung_task_timeout_secs
,
846 .maxlen
= sizeof(unsigned long),
848 .proc_handler
= &proc_doulongvec_minmax
,
849 .strategy
= &sysctl_intvec
,
852 .ctl_name
= CTL_UNNUMBERED
,
853 .procname
= "hung_task_warnings",
854 .data
= &sysctl_hung_task_warnings
,
855 .maxlen
= sizeof(unsigned long),
857 .proc_handler
= &proc_doulongvec_minmax
,
858 .strategy
= &sysctl_intvec
,
863 .ctl_name
= KERN_COMPAT_LOG
,
864 .procname
= "compat-log",
866 .maxlen
= sizeof (int),
868 .proc_handler
= &proc_dointvec
,
871 #ifdef CONFIG_RT_MUTEXES
873 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
874 .procname
= "max_lock_depth",
875 .data
= &max_lock_depth
,
876 .maxlen
= sizeof(int),
878 .proc_handler
= &proc_dointvec
,
882 .ctl_name
= CTL_UNNUMBERED
,
883 .procname
= "poweroff_cmd",
884 .data
= &poweroff_cmd
,
885 .maxlen
= POWEROFF_CMD_PATH_LEN
,
887 .proc_handler
= &proc_dostring
,
888 .strategy
= &sysctl_string
,
892 .ctl_name
= CTL_UNNUMBERED
,
895 .child
= key_sysctls
,
898 #ifdef CONFIG_RCU_TORTURE_TEST
900 .ctl_name
= CTL_UNNUMBERED
,
901 .procname
= "rcutorture_runnable",
902 .data
= &rcutorture_runnable
,
903 .maxlen
= sizeof(int),
905 .proc_handler
= &proc_dointvec
,
908 #ifdef CONFIG_UNEVICTABLE_LRU
910 .ctl_name
= CTL_UNNUMBERED
,
911 .procname
= "scan_unevictable_pages",
912 .data
= &scan_unevictable_pages
,
913 .maxlen
= sizeof(scan_unevictable_pages
),
915 .proc_handler
= &scan_unevictable_handler
,
919 * NOTE: do not add new entries to this table unless you have read
920 * Documentation/sysctl/ctl_unnumbered.txt
925 static struct ctl_table vm_table
[] = {
927 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
928 .procname
= "overcommit_memory",
929 .data
= &sysctl_overcommit_memory
,
930 .maxlen
= sizeof(sysctl_overcommit_memory
),
932 .proc_handler
= &proc_dointvec
,
935 .ctl_name
= VM_PANIC_ON_OOM
,
936 .procname
= "panic_on_oom",
937 .data
= &sysctl_panic_on_oom
,
938 .maxlen
= sizeof(sysctl_panic_on_oom
),
940 .proc_handler
= &proc_dointvec
,
943 .ctl_name
= CTL_UNNUMBERED
,
944 .procname
= "oom_kill_allocating_task",
945 .data
= &sysctl_oom_kill_allocating_task
,
946 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
948 .proc_handler
= &proc_dointvec
,
951 .ctl_name
= CTL_UNNUMBERED
,
952 .procname
= "oom_dump_tasks",
953 .data
= &sysctl_oom_dump_tasks
,
954 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
956 .proc_handler
= &proc_dointvec
,
959 .ctl_name
= VM_OVERCOMMIT_RATIO
,
960 .procname
= "overcommit_ratio",
961 .data
= &sysctl_overcommit_ratio
,
962 .maxlen
= sizeof(sysctl_overcommit_ratio
),
964 .proc_handler
= &proc_dointvec
,
967 .ctl_name
= VM_PAGE_CLUSTER
,
968 .procname
= "page-cluster",
969 .data
= &page_cluster
,
970 .maxlen
= sizeof(int),
972 .proc_handler
= &proc_dointvec
,
975 .ctl_name
= VM_DIRTY_BACKGROUND
,
976 .procname
= "dirty_background_ratio",
977 .data
= &dirty_background_ratio
,
978 .maxlen
= sizeof(dirty_background_ratio
),
980 .proc_handler
= &dirty_background_ratio_handler
,
981 .strategy
= &sysctl_intvec
,
983 .extra2
= &one_hundred
,
986 .ctl_name
= CTL_UNNUMBERED
,
987 .procname
= "dirty_background_bytes",
988 .data
= &dirty_background_bytes
,
989 .maxlen
= sizeof(dirty_background_bytes
),
991 .proc_handler
= &dirty_background_bytes_handler
,
992 .strategy
= &sysctl_intvec
,
996 .ctl_name
= VM_DIRTY_RATIO
,
997 .procname
= "dirty_ratio",
998 .data
= &vm_dirty_ratio
,
999 .maxlen
= sizeof(vm_dirty_ratio
),
1001 .proc_handler
= &dirty_ratio_handler
,
1002 .strategy
= &sysctl_intvec
,
1004 .extra2
= &one_hundred
,
1007 .ctl_name
= CTL_UNNUMBERED
,
1008 .procname
= "dirty_bytes",
1009 .data
= &vm_dirty_bytes
,
1010 .maxlen
= sizeof(vm_dirty_bytes
),
1012 .proc_handler
= &dirty_bytes_handler
,
1013 .strategy
= &sysctl_intvec
,
1017 .procname
= "dirty_writeback_centisecs",
1018 .data
= &dirty_writeback_interval
,
1019 .maxlen
= sizeof(dirty_writeback_interval
),
1021 .proc_handler
= &dirty_writeback_centisecs_handler
,
1024 .procname
= "dirty_expire_centisecs",
1025 .data
= &dirty_expire_interval
,
1026 .maxlen
= sizeof(dirty_expire_interval
),
1028 .proc_handler
= &proc_dointvec_userhz_jiffies
,
1031 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
1032 .procname
= "nr_pdflush_threads",
1033 .data
= &nr_pdflush_threads
,
1034 .maxlen
= sizeof nr_pdflush_threads
,
1035 .mode
= 0444 /* read-only*/,
1036 .proc_handler
= &proc_dointvec
,
1039 .ctl_name
= VM_SWAPPINESS
,
1040 .procname
= "swappiness",
1041 .data
= &vm_swappiness
,
1042 .maxlen
= sizeof(vm_swappiness
),
1044 .proc_handler
= &proc_dointvec_minmax
,
1045 .strategy
= &sysctl_intvec
,
1047 .extra2
= &one_hundred
,
1049 #ifdef CONFIG_HUGETLB_PAGE
1051 .procname
= "nr_hugepages",
1053 .maxlen
= sizeof(unsigned long),
1055 .proc_handler
= &hugetlb_sysctl_handler
,
1056 .extra1
= (void *)&hugetlb_zero
,
1057 .extra2
= (void *)&hugetlb_infinity
,
1060 .ctl_name
= VM_HUGETLB_GROUP
,
1061 .procname
= "hugetlb_shm_group",
1062 .data
= &sysctl_hugetlb_shm_group
,
1063 .maxlen
= sizeof(gid_t
),
1065 .proc_handler
= &proc_dointvec
,
1068 .ctl_name
= CTL_UNNUMBERED
,
1069 .procname
= "hugepages_treat_as_movable",
1070 .data
= &hugepages_treat_as_movable
,
1071 .maxlen
= sizeof(int),
1073 .proc_handler
= &hugetlb_treat_movable_handler
,
1076 .ctl_name
= CTL_UNNUMBERED
,
1077 .procname
= "nr_overcommit_hugepages",
1079 .maxlen
= sizeof(unsigned long),
1081 .proc_handler
= &hugetlb_overcommit_handler
,
1082 .extra1
= (void *)&hugetlb_zero
,
1083 .extra2
= (void *)&hugetlb_infinity
,
1087 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
1088 .procname
= "lowmem_reserve_ratio",
1089 .data
= &sysctl_lowmem_reserve_ratio
,
1090 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1092 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
1093 .strategy
= &sysctl_intvec
,
1096 .ctl_name
= VM_DROP_PAGECACHE
,
1097 .procname
= "drop_caches",
1098 .data
= &sysctl_drop_caches
,
1099 .maxlen
= sizeof(int),
1101 .proc_handler
= drop_caches_sysctl_handler
,
1102 .strategy
= &sysctl_intvec
,
1105 .ctl_name
= VM_MIN_FREE_KBYTES
,
1106 .procname
= "min_free_kbytes",
1107 .data
= &min_free_kbytes
,
1108 .maxlen
= sizeof(min_free_kbytes
),
1110 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1111 .strategy
= &sysctl_intvec
,
1115 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1116 .procname
= "percpu_pagelist_fraction",
1117 .data
= &percpu_pagelist_fraction
,
1118 .maxlen
= sizeof(percpu_pagelist_fraction
),
1120 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1121 .strategy
= &sysctl_intvec
,
1122 .extra1
= &min_percpu_pagelist_fract
,
1126 .ctl_name
= VM_MAX_MAP_COUNT
,
1127 .procname
= "max_map_count",
1128 .data
= &sysctl_max_map_count
,
1129 .maxlen
= sizeof(sysctl_max_map_count
),
1131 .proc_handler
= &proc_dointvec
1135 .ctl_name
= CTL_UNNUMBERED
,
1136 .procname
= "nr_trim_pages",
1137 .data
= &sysctl_nr_trim_pages
,
1138 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1140 .proc_handler
= &proc_dointvec_minmax
,
1141 .strategy
= &sysctl_intvec
,
1146 .ctl_name
= VM_LAPTOP_MODE
,
1147 .procname
= "laptop_mode",
1148 .data
= &laptop_mode
,
1149 .maxlen
= sizeof(laptop_mode
),
1151 .proc_handler
= &proc_dointvec_jiffies
,
1152 .strategy
= &sysctl_jiffies
,
1155 .ctl_name
= VM_BLOCK_DUMP
,
1156 .procname
= "block_dump",
1157 .data
= &block_dump
,
1158 .maxlen
= sizeof(block_dump
),
1160 .proc_handler
= &proc_dointvec
,
1161 .strategy
= &sysctl_intvec
,
1165 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1166 .procname
= "vfs_cache_pressure",
1167 .data
= &sysctl_vfs_cache_pressure
,
1168 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1170 .proc_handler
= &proc_dointvec
,
1171 .strategy
= &sysctl_intvec
,
1174 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1176 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1177 .procname
= "legacy_va_layout",
1178 .data
= &sysctl_legacy_va_layout
,
1179 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1181 .proc_handler
= &proc_dointvec
,
1182 .strategy
= &sysctl_intvec
,
1188 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1189 .procname
= "zone_reclaim_mode",
1190 .data
= &zone_reclaim_mode
,
1191 .maxlen
= sizeof(zone_reclaim_mode
),
1193 .proc_handler
= &proc_dointvec
,
1194 .strategy
= &sysctl_intvec
,
1198 .ctl_name
= VM_MIN_UNMAPPED
,
1199 .procname
= "min_unmapped_ratio",
1200 .data
= &sysctl_min_unmapped_ratio
,
1201 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1203 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1204 .strategy
= &sysctl_intvec
,
1206 .extra2
= &one_hundred
,
1209 .ctl_name
= VM_MIN_SLAB
,
1210 .procname
= "min_slab_ratio",
1211 .data
= &sysctl_min_slab_ratio
,
1212 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1214 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1215 .strategy
= &sysctl_intvec
,
1217 .extra2
= &one_hundred
,
1222 .ctl_name
= CTL_UNNUMBERED
,
1223 .procname
= "stat_interval",
1224 .data
= &sysctl_stat_interval
,
1225 .maxlen
= sizeof(sysctl_stat_interval
),
1227 .proc_handler
= &proc_dointvec_jiffies
,
1228 .strategy
= &sysctl_jiffies
,
1231 #ifdef CONFIG_SECURITY
1233 .ctl_name
= CTL_UNNUMBERED
,
1234 .procname
= "mmap_min_addr",
1235 .data
= &mmap_min_addr
,
1236 .maxlen
= sizeof(unsigned long),
1238 .proc_handler
= &proc_doulongvec_minmax
,
1243 .ctl_name
= CTL_UNNUMBERED
,
1244 .procname
= "numa_zonelist_order",
1245 .data
= &numa_zonelist_order
,
1246 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1248 .proc_handler
= &numa_zonelist_order_handler
,
1249 .strategy
= &sysctl_string
,
1252 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1253 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1255 .ctl_name
= VM_VDSO_ENABLED
,
1256 .procname
= "vdso_enabled",
1257 .data
= &vdso_enabled
,
1258 .maxlen
= sizeof(vdso_enabled
),
1260 .proc_handler
= &proc_dointvec
,
1261 .strategy
= &sysctl_intvec
,
1265 #ifdef CONFIG_HIGHMEM
1267 .ctl_name
= CTL_UNNUMBERED
,
1268 .procname
= "highmem_is_dirtyable",
1269 .data
= &vm_highmem_is_dirtyable
,
1270 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1272 .proc_handler
= &proc_dointvec_minmax
,
1273 .strategy
= &sysctl_intvec
,
1279 * NOTE: do not add new entries to this table unless you have read
1280 * Documentation/sysctl/ctl_unnumbered.txt
1285 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1286 static struct ctl_table binfmt_misc_table
[] = {
1291 static struct ctl_table fs_table
[] = {
1293 .ctl_name
= FS_NRINODE
,
1294 .procname
= "inode-nr",
1295 .data
= &inodes_stat
,
1296 .maxlen
= 2*sizeof(int),
1298 .proc_handler
= &proc_dointvec
,
1301 .ctl_name
= FS_STATINODE
,
1302 .procname
= "inode-state",
1303 .data
= &inodes_stat
,
1304 .maxlen
= 7*sizeof(int),
1306 .proc_handler
= &proc_dointvec
,
1309 .procname
= "file-nr",
1310 .data
= &files_stat
,
1311 .maxlen
= 3*sizeof(int),
1313 .proc_handler
= &proc_nr_files
,
1316 .ctl_name
= FS_MAXFILE
,
1317 .procname
= "file-max",
1318 .data
= &files_stat
.max_files
,
1319 .maxlen
= sizeof(int),
1321 .proc_handler
= &proc_dointvec
,
1324 .ctl_name
= CTL_UNNUMBERED
,
1325 .procname
= "nr_open",
1326 .data
= &sysctl_nr_open
,
1327 .maxlen
= sizeof(int),
1329 .proc_handler
= &proc_dointvec_minmax
,
1330 .extra1
= &sysctl_nr_open_min
,
1331 .extra2
= &sysctl_nr_open_max
,
1334 .ctl_name
= FS_DENTRY
,
1335 .procname
= "dentry-state",
1336 .data
= &dentry_stat
,
1337 .maxlen
= 6*sizeof(int),
1339 .proc_handler
= &proc_dointvec
,
1342 .ctl_name
= FS_OVERFLOWUID
,
1343 .procname
= "overflowuid",
1344 .data
= &fs_overflowuid
,
1345 .maxlen
= sizeof(int),
1347 .proc_handler
= &proc_dointvec_minmax
,
1348 .strategy
= &sysctl_intvec
,
1349 .extra1
= &minolduid
,
1350 .extra2
= &maxolduid
,
1353 .ctl_name
= FS_OVERFLOWGID
,
1354 .procname
= "overflowgid",
1355 .data
= &fs_overflowgid
,
1356 .maxlen
= sizeof(int),
1358 .proc_handler
= &proc_dointvec_minmax
,
1359 .strategy
= &sysctl_intvec
,
1360 .extra1
= &minolduid
,
1361 .extra2
= &maxolduid
,
1363 #ifdef CONFIG_FILE_LOCKING
1365 .ctl_name
= FS_LEASES
,
1366 .procname
= "leases-enable",
1367 .data
= &leases_enable
,
1368 .maxlen
= sizeof(int),
1370 .proc_handler
= &proc_dointvec
,
1373 #ifdef CONFIG_DNOTIFY
1375 .ctl_name
= FS_DIR_NOTIFY
,
1376 .procname
= "dir-notify-enable",
1377 .data
= &dir_notify_enable
,
1378 .maxlen
= sizeof(int),
1380 .proc_handler
= &proc_dointvec
,
1384 #ifdef CONFIG_FILE_LOCKING
1386 .ctl_name
= FS_LEASE_TIME
,
1387 .procname
= "lease-break-time",
1388 .data
= &lease_break_time
,
1389 .maxlen
= sizeof(int),
1391 .proc_handler
= &proc_dointvec_minmax
,
1392 .strategy
= &sysctl_intvec
,
1399 .procname
= "aio-nr",
1401 .maxlen
= sizeof(aio_nr
),
1403 .proc_handler
= &proc_doulongvec_minmax
,
1406 .procname
= "aio-max-nr",
1407 .data
= &aio_max_nr
,
1408 .maxlen
= sizeof(aio_max_nr
),
1410 .proc_handler
= &proc_doulongvec_minmax
,
1412 #endif /* CONFIG_AIO */
1413 #ifdef CONFIG_INOTIFY_USER
1415 .ctl_name
= FS_INOTIFY
,
1416 .procname
= "inotify",
1418 .child
= inotify_table
,
1423 .procname
= "epoll",
1425 .child
= epoll_table
,
1430 .ctl_name
= KERN_SETUID_DUMPABLE
,
1431 .procname
= "suid_dumpable",
1432 .data
= &suid_dumpable
,
1433 .maxlen
= sizeof(int),
1435 .proc_handler
= &proc_dointvec
,
1437 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1439 .ctl_name
= CTL_UNNUMBERED
,
1440 .procname
= "binfmt_misc",
1442 .child
= binfmt_misc_table
,
1446 * NOTE: do not add new entries to this table unless you have read
1447 * Documentation/sysctl/ctl_unnumbered.txt
1452 static struct ctl_table debug_table
[] = {
1453 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1455 .ctl_name
= CTL_UNNUMBERED
,
1456 .procname
= "exception-trace",
1457 .data
= &show_unhandled_signals
,
1458 .maxlen
= sizeof(int),
1460 .proc_handler
= proc_dointvec
1466 static struct ctl_table dev_table
[] = {
1470 static DEFINE_SPINLOCK(sysctl_lock
);
1472 /* called under sysctl_lock */
1473 static int use_table(struct ctl_table_header
*p
)
1475 if (unlikely(p
->unregistering
))
1481 /* called under sysctl_lock */
1482 static void unuse_table(struct ctl_table_header
*p
)
1485 if (unlikely(p
->unregistering
))
1486 complete(p
->unregistering
);
1489 /* called under sysctl_lock, will reacquire if has to wait */
1490 static void start_unregistering(struct ctl_table_header
*p
)
1493 * if p->used is 0, nobody will ever touch that entry again;
1494 * we'll eliminate all paths to it before dropping sysctl_lock
1496 if (unlikely(p
->used
)) {
1497 struct completion wait
;
1498 init_completion(&wait
);
1499 p
->unregistering
= &wait
;
1500 spin_unlock(&sysctl_lock
);
1501 wait_for_completion(&wait
);
1502 spin_lock(&sysctl_lock
);
1504 /* anything non-NULL; we'll never dereference it */
1505 p
->unregistering
= ERR_PTR(-EINVAL
);
1508 * do not remove from the list until nobody holds it; walking the
1509 * list in do_sysctl() relies on that.
1511 list_del_init(&p
->ctl_entry
);
1514 void sysctl_head_get(struct ctl_table_header
*head
)
1516 spin_lock(&sysctl_lock
);
1518 spin_unlock(&sysctl_lock
);
1521 void sysctl_head_put(struct ctl_table_header
*head
)
1523 spin_lock(&sysctl_lock
);
1526 spin_unlock(&sysctl_lock
);
1529 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1533 spin_lock(&sysctl_lock
);
1534 if (!use_table(head
))
1535 head
= ERR_PTR(-ENOENT
);
1536 spin_unlock(&sysctl_lock
);
1540 void sysctl_head_finish(struct ctl_table_header
*head
)
1544 spin_lock(&sysctl_lock
);
1546 spin_unlock(&sysctl_lock
);
1549 static struct ctl_table_set
*
1550 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1552 struct ctl_table_set
*set
= &root
->default_set
;
1554 set
= root
->lookup(root
, namespaces
);
1558 static struct list_head
*
1559 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1561 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1565 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1566 struct ctl_table_header
*prev
)
1568 struct ctl_table_root
*root
;
1569 struct list_head
*header_list
;
1570 struct ctl_table_header
*head
;
1571 struct list_head
*tmp
;
1573 spin_lock(&sysctl_lock
);
1576 tmp
= &prev
->ctl_entry
;
1580 tmp
= &root_table_header
.ctl_entry
;
1582 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1584 if (!use_table(head
))
1586 spin_unlock(&sysctl_lock
);
1591 header_list
= lookup_header_list(root
, namespaces
);
1592 if (tmp
!= header_list
)
1596 root
= list_entry(root
->root_list
.next
,
1597 struct ctl_table_root
, root_list
);
1598 if (root
== &sysctl_table_root
)
1600 header_list
= lookup_header_list(root
, namespaces
);
1601 } while (list_empty(header_list
));
1602 tmp
= header_list
->next
;
1605 spin_unlock(&sysctl_lock
);
1609 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1611 return __sysctl_head_next(current
->nsproxy
, prev
);
1614 void register_sysctl_root(struct ctl_table_root
*root
)
1616 spin_lock(&sysctl_lock
);
1617 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1618 spin_unlock(&sysctl_lock
);
1621 #ifdef CONFIG_SYSCTL_SYSCALL
1622 /* Perform the actual read/write of a sysctl table entry. */
1623 static int do_sysctl_strategy(struct ctl_table_root
*root
,
1624 struct ctl_table
*table
,
1625 void __user
*oldval
, size_t __user
*oldlenp
,
1626 void __user
*newval
, size_t newlen
)
1634 if (sysctl_perm(root
, table
, op
))
1637 if (table
->strategy
) {
1638 rc
= table
->strategy(table
, oldval
, oldlenp
, newval
, newlen
);
1645 /* If there is no strategy routine, or if the strategy returns
1646 * zero, proceed with automatic r/w */
1647 if (table
->data
&& table
->maxlen
) {
1648 rc
= sysctl_data(table
, oldval
, oldlenp
, newval
, newlen
);
1655 static int parse_table(int __user
*name
, int nlen
,
1656 void __user
*oldval
, size_t __user
*oldlenp
,
1657 void __user
*newval
, size_t newlen
,
1658 struct ctl_table_root
*root
,
1659 struct ctl_table
*table
)
1665 if (get_user(n
, name
))
1667 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1668 if (!table
->ctl_name
)
1670 if (n
== table
->ctl_name
) {
1673 if (sysctl_perm(root
, table
, MAY_EXEC
))
1677 table
= table
->child
;
1680 error
= do_sysctl_strategy(root
, table
,
1689 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1690 void __user
*newval
, size_t newlen
)
1692 struct ctl_table_header
*head
;
1693 int error
= -ENOTDIR
;
1695 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1699 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1703 for (head
= sysctl_head_next(NULL
); head
;
1704 head
= sysctl_head_next(head
)) {
1705 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1707 head
->root
, head
->ctl_table
);
1708 if (error
!= -ENOTDIR
) {
1709 sysctl_head_finish(head
);
1716 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
1718 struct __sysctl_args tmp
;
1721 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1724 error
= deprecated_sysctl_warning(&tmp
);
1729 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1730 tmp
.newval
, tmp
.newlen
);
1735 #endif /* CONFIG_SYSCTL_SYSCALL */
1738 * sysctl_perm does NOT grant the superuser all rights automatically, because
1739 * some sysctl variables are readonly even to root.
1742 static int test_perm(int mode
, int op
)
1744 if (!current_euid())
1746 else if (in_egroup_p(0))
1748 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1753 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1758 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1762 if (root
->permissions
)
1763 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1767 return test_perm(mode
, op
);
1770 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1772 for (; table
->ctl_name
|| table
->procname
; table
++) {
1773 table
->parent
= parent
;
1775 sysctl_set_parent(table
, table
->child
);
1779 static __init
int sysctl_init(void)
1781 sysctl_set_parent(NULL
, root_table
);
1782 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1785 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1791 core_initcall(sysctl_init
);
1793 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1794 struct ctl_table
*table
)
1796 struct ctl_table
*p
;
1797 const char *s
= branch
->procname
;
1799 /* branch should have named subdirectory as its first element */
1800 if (!s
|| !branch
->child
)
1803 /* ... and nothing else */
1804 if (branch
[1].procname
|| branch
[1].ctl_name
)
1807 /* table should contain subdirectory with the same name */
1808 for (p
= table
; p
->procname
|| p
->ctl_name
; p
++) {
1811 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1817 /* see if attaching q to p would be an improvement */
1818 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1820 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1821 struct ctl_table
*next
;
1823 int not_in_parent
= !p
->attached_by
;
1825 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1826 if (by
== q
->attached_by
)
1828 if (to
== p
->attached_by
)
1834 if (is_better
&& not_in_parent
) {
1835 q
->attached_by
= by
;
1836 q
->attached_to
= to
;
1842 * __register_sysctl_paths - register a sysctl hierarchy
1843 * @root: List of sysctl headers to register on
1844 * @namespaces: Data to compute which lists of sysctl entries are visible
1845 * @path: The path to the directory the sysctl table is in.
1846 * @table: the top-level table structure
1848 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1849 * array. A completely 0 filled entry terminates the table.
1851 * The members of the &struct ctl_table structure are used as follows:
1853 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1854 * must be unique within that level of sysctl
1856 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1857 * enter a sysctl file
1859 * data - a pointer to data for use by proc_handler
1861 * maxlen - the maximum size in bytes of the data
1863 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1865 * child - a pointer to the child sysctl table if this entry is a directory, or
1868 * proc_handler - the text handler routine (described below)
1870 * strategy - the strategy routine (described below)
1872 * de - for internal use by the sysctl routines
1874 * extra1, extra2 - extra pointers usable by the proc handler routines
1876 * Leaf nodes in the sysctl tree will be represented by a single file
1877 * under /proc; non-leaf nodes will be represented by directories.
1879 * sysctl(2) can automatically manage read and write requests through
1880 * the sysctl table. The data and maxlen fields of the ctl_table
1881 * struct enable minimal validation of the values being written to be
1882 * performed, and the mode field allows minimal authentication.
1884 * More sophisticated management can be enabled by the provision of a
1885 * strategy routine with the table entry. This will be called before
1886 * any automatic read or write of the data is performed.
1888 * The strategy routine may return
1890 * < 0 - Error occurred (error is passed to user process)
1892 * 0 - OK - proceed with automatic read or write.
1894 * > 0 - OK - read or write has been done by the strategy routine, so
1895 * return immediately.
1897 * There must be a proc_handler routine for any terminal nodes
1898 * mirrored under /proc/sys (non-terminals are handled by a built-in
1899 * directory handler). Several default handlers are available to
1900 * cover common cases -
1902 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1903 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1904 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1906 * It is the handler's job to read the input buffer from user memory
1907 * and process it. The handler should return 0 on success.
1909 * This routine returns %NULL on a failure to register, and a pointer
1910 * to the table header on success.
1912 struct ctl_table_header
*__register_sysctl_paths(
1913 struct ctl_table_root
*root
,
1914 struct nsproxy
*namespaces
,
1915 const struct ctl_path
*path
, struct ctl_table
*table
)
1917 struct ctl_table_header
*header
;
1918 struct ctl_table
*new, **prevp
;
1919 unsigned int n
, npath
;
1920 struct ctl_table_set
*set
;
1922 /* Count the path components */
1923 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
1927 * For each path component, allocate a 2-element ctl_table array.
1928 * The first array element will be filled with the sysctl entry
1929 * for this, the second will be the sentinel (ctl_name == 0).
1931 * We allocate everything in one go so that we don't have to
1932 * worry about freeing additional memory in unregister_sysctl_table.
1934 header
= kzalloc(sizeof(struct ctl_table_header
) +
1935 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1939 new = (struct ctl_table
*) (header
+ 1);
1941 /* Now connect the dots */
1942 prevp
= &header
->ctl_table
;
1943 for (n
= 0; n
< npath
; ++n
, ++path
) {
1944 /* Copy the procname */
1945 new->procname
= path
->procname
;
1946 new->ctl_name
= path
->ctl_name
;
1950 prevp
= &new->child
;
1955 header
->ctl_table_arg
= table
;
1957 INIT_LIST_HEAD(&header
->ctl_entry
);
1959 header
->unregistering
= NULL
;
1960 header
->root
= root
;
1961 sysctl_set_parent(NULL
, header
->ctl_table
);
1963 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1964 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1969 spin_lock(&sysctl_lock
);
1970 header
->set
= lookup_header_set(root
, namespaces
);
1971 header
->attached_by
= header
->ctl_table
;
1972 header
->attached_to
= root_table
;
1973 header
->parent
= &root_table_header
;
1974 for (set
= header
->set
; set
; set
= set
->parent
) {
1975 struct ctl_table_header
*p
;
1976 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
1977 if (p
->unregistering
)
1979 try_attach(p
, header
);
1982 header
->parent
->count
++;
1983 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
1984 spin_unlock(&sysctl_lock
);
1990 * register_sysctl_table_path - register a sysctl table hierarchy
1991 * @path: The path to the directory the sysctl table is in.
1992 * @table: the top-level table structure
1994 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1995 * array. A completely 0 filled entry terminates the table.
1997 * See __register_sysctl_paths for more details.
1999 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2000 struct ctl_table
*table
)
2002 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
2007 * register_sysctl_table - register a sysctl table hierarchy
2008 * @table: the top-level table structure
2010 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2011 * array. A completely 0 filled entry terminates the table.
2013 * See register_sysctl_paths for more details.
2015 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
2017 static const struct ctl_path null_path
[] = { {} };
2019 return register_sysctl_paths(null_path
, table
);
2023 * unregister_sysctl_table - unregister a sysctl table hierarchy
2024 * @header: the header returned from register_sysctl_table
2026 * Unregisters the sysctl table and all children. proc entries may not
2027 * actually be removed until they are no longer used by anyone.
2029 void unregister_sysctl_table(struct ctl_table_header
* header
)
2036 spin_lock(&sysctl_lock
);
2037 start_unregistering(header
);
2038 if (!--header
->parent
->count
) {
2040 kfree(header
->parent
);
2042 if (!--header
->count
)
2044 spin_unlock(&sysctl_lock
);
2047 int sysctl_is_seen(struct ctl_table_header
*p
)
2049 struct ctl_table_set
*set
= p
->set
;
2051 spin_lock(&sysctl_lock
);
2052 if (p
->unregistering
)
2054 else if (!set
->is_seen
)
2057 res
= set
->is_seen(set
);
2058 spin_unlock(&sysctl_lock
);
2062 void setup_sysctl_set(struct ctl_table_set
*p
,
2063 struct ctl_table_set
*parent
,
2064 int (*is_seen
)(struct ctl_table_set
*))
2066 INIT_LIST_HEAD(&p
->list
);
2067 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
2068 p
->is_seen
= is_seen
;
2071 #else /* !CONFIG_SYSCTL */
2072 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
2077 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2078 struct ctl_table
*table
)
2083 void unregister_sysctl_table(struct ctl_table_header
* table
)
2087 void setup_sysctl_set(struct ctl_table_set
*p
,
2088 struct ctl_table_set
*parent
,
2089 int (*is_seen
)(struct ctl_table_set
*))
2093 void sysctl_head_put(struct ctl_table_header
*head
)
2097 #endif /* CONFIG_SYSCTL */
2103 #ifdef CONFIG_PROC_SYSCTL
2105 static int _proc_do_string(void* data
, int maxlen
, int write
,
2106 struct file
*filp
, void __user
*buffer
,
2107 size_t *lenp
, loff_t
*ppos
)
2113 if (!data
|| !maxlen
|| !*lenp
) {
2121 while (len
< *lenp
) {
2122 if (get_user(c
, p
++))
2124 if (c
== 0 || c
== '\n')
2130 if(copy_from_user(data
, buffer
, len
))
2132 ((char *) data
)[len
] = 0;
2150 if(copy_to_user(buffer
, data
, len
))
2153 if(put_user('\n', ((char __user
*) buffer
) + len
))
2164 * proc_dostring - read a string sysctl
2165 * @table: the sysctl table
2166 * @write: %TRUE if this is a write to the sysctl file
2167 * @filp: the file structure
2168 * @buffer: the user buffer
2169 * @lenp: the size of the user buffer
2170 * @ppos: file position
2172 * Reads/writes a string from/to the user buffer. If the kernel
2173 * buffer provided is not large enough to hold the string, the
2174 * string is truncated. The copied string is %NULL-terminated.
2175 * If the string is being read by the user process, it is copied
2176 * and a newline '\n' is added. It is truncated if the buffer is
2179 * Returns 0 on success.
2181 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2182 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2184 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
2185 buffer
, lenp
, ppos
);
2189 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
2191 int write
, void *data
)
2194 *valp
= *negp
? -*lvalp
: *lvalp
;
2199 *lvalp
= (unsigned long)-val
;
2202 *lvalp
= (unsigned long)val
;
2208 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2209 int write
, struct file
*filp
, void __user
*buffer
,
2210 size_t *lenp
, loff_t
*ppos
,
2211 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2212 int write
, void *data
),
2215 #define TMPBUFLEN 21
2216 int *i
, vleft
, first
=1, neg
, val
;
2220 char buf
[TMPBUFLEN
], *p
;
2221 char __user
*s
= buffer
;
2223 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
2224 (*ppos
&& !write
)) {
2229 i
= (int *) tbl_data
;
2230 vleft
= table
->maxlen
/ sizeof(*i
);
2234 conv
= do_proc_dointvec_conv
;
2236 for (; left
&& vleft
--; i
++, first
=0) {
2251 if (len
> sizeof(buf
) - 1)
2252 len
= sizeof(buf
) - 1;
2253 if (copy_from_user(buf
, s
, len
))
2257 if (*p
== '-' && left
> 1) {
2261 if (*p
< '0' || *p
> '9')
2264 lval
= simple_strtoul(p
, &p
, 0);
2267 if ((len
< left
) && *p
&& !isspace(*p
))
2274 if (conv(&neg
, &lval
, i
, 1, data
))
2281 if (conv(&neg
, &lval
, i
, 0, data
))
2284 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2288 if(copy_to_user(s
, buf
, len
))
2295 if (!write
&& !first
&& left
) {
2296 if(put_user('\n', s
))
2303 if (get_user(c
, s
++))
2318 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2319 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2320 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2321 int write
, void *data
),
2324 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2325 buffer
, lenp
, ppos
, conv
, data
);
2329 * proc_dointvec - read a vector of integers
2330 * @table: the sysctl table
2331 * @write: %TRUE if this is a write to the sysctl file
2332 * @filp: the file structure
2333 * @buffer: the user buffer
2334 * @lenp: the size of the user buffer
2335 * @ppos: file position
2337 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2338 * values from/to the user buffer, treated as an ASCII string.
2340 * Returns 0 on success.
2342 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2343 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2345 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2350 * Taint values can only be increased
2351 * This means we can safely use a temporary.
2353 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2354 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2357 unsigned long tmptaint
= get_taint();
2360 if (write
&& !capable(CAP_SYS_ADMIN
))
2365 err
= proc_doulongvec_minmax(&t
, write
, filp
, buffer
, lenp
, ppos
);
2371 * Poor man's atomic or. Not worth adding a primitive
2372 * to everyone's atomic.h for this
2375 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2376 if ((tmptaint
>> i
) & 1)
2384 struct do_proc_dointvec_minmax_conv_param
{
2389 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2391 int write
, void *data
)
2393 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2395 int val
= *negp
? -*lvalp
: *lvalp
;
2396 if ((param
->min
&& *param
->min
> val
) ||
2397 (param
->max
&& *param
->max
< val
))
2404 *lvalp
= (unsigned long)-val
;
2407 *lvalp
= (unsigned long)val
;
2414 * proc_dointvec_minmax - read a vector of integers with min/max values
2415 * @table: the sysctl table
2416 * @write: %TRUE if this is a write to the sysctl file
2417 * @filp: the file structure
2418 * @buffer: the user buffer
2419 * @lenp: the size of the user buffer
2420 * @ppos: file position
2422 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2423 * values from/to the user buffer, treated as an ASCII string.
2425 * This routine will ensure the values are within the range specified by
2426 * table->extra1 (min) and table->extra2 (max).
2428 * Returns 0 on success.
2430 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2431 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2433 struct do_proc_dointvec_minmax_conv_param param
= {
2434 .min
= (int *) table
->extra1
,
2435 .max
= (int *) table
->extra2
,
2437 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2438 do_proc_dointvec_minmax_conv
, ¶m
);
2441 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2443 void __user
*buffer
,
2444 size_t *lenp
, loff_t
*ppos
,
2445 unsigned long convmul
,
2446 unsigned long convdiv
)
2448 #define TMPBUFLEN 21
2449 unsigned long *i
, *min
, *max
, val
;
2450 int vleft
, first
=1, neg
;
2452 char buf
[TMPBUFLEN
], *p
;
2453 char __user
*s
= buffer
;
2455 if (!data
|| !table
->maxlen
|| !*lenp
||
2456 (*ppos
&& !write
)) {
2461 i
= (unsigned long *) data
;
2462 min
= (unsigned long *) table
->extra1
;
2463 max
= (unsigned long *) table
->extra2
;
2464 vleft
= table
->maxlen
/ sizeof(unsigned long);
2467 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2482 if (len
> TMPBUFLEN
-1)
2484 if (copy_from_user(buf
, s
, len
))
2488 if (*p
== '-' && left
> 1) {
2492 if (*p
< '0' || *p
> '9')
2494 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2496 if ((len
< left
) && *p
&& !isspace(*p
))
2505 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2512 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2516 if(copy_to_user(s
, buf
, len
))
2523 if (!write
&& !first
&& left
) {
2524 if(put_user('\n', s
))
2531 if (get_user(c
, s
++))
2546 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2548 void __user
*buffer
,
2549 size_t *lenp
, loff_t
*ppos
,
2550 unsigned long convmul
,
2551 unsigned long convdiv
)
2553 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2554 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2558 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2559 * @table: the sysctl table
2560 * @write: %TRUE if this is a write to the sysctl file
2561 * @filp: the file structure
2562 * @buffer: the user buffer
2563 * @lenp: the size of the user buffer
2564 * @ppos: file position
2566 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2567 * values from/to the user buffer, treated as an ASCII string.
2569 * This routine will ensure the values are within the range specified by
2570 * table->extra1 (min) and table->extra2 (max).
2572 * Returns 0 on success.
2574 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2575 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2577 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2581 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2582 * @table: the sysctl table
2583 * @write: %TRUE if this is a write to the sysctl file
2584 * @filp: the file structure
2585 * @buffer: the user buffer
2586 * @lenp: the size of the user buffer
2587 * @ppos: file position
2589 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2590 * values from/to the user buffer, treated as an ASCII string. The values
2591 * are treated as milliseconds, and converted to jiffies when they are stored.
2593 * This routine will ensure the values are within the range specified by
2594 * table->extra1 (min) and table->extra2 (max).
2596 * Returns 0 on success.
2598 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2600 void __user
*buffer
,
2601 size_t *lenp
, loff_t
*ppos
)
2603 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2604 lenp
, ppos
, HZ
, 1000l);
2608 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2610 int write
, void *data
)
2613 if (*lvalp
> LONG_MAX
/ HZ
)
2615 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2621 lval
= (unsigned long)-val
;
2624 lval
= (unsigned long)val
;
2631 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2633 int write
, void *data
)
2636 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2638 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2644 lval
= (unsigned long)-val
;
2647 lval
= (unsigned long)val
;
2649 *lvalp
= jiffies_to_clock_t(lval
);
2654 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2656 int write
, void *data
)
2659 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2665 lval
= (unsigned long)-val
;
2668 lval
= (unsigned long)val
;
2670 *lvalp
= jiffies_to_msecs(lval
);
2676 * proc_dointvec_jiffies - read a vector of integers as seconds
2677 * @table: the sysctl table
2678 * @write: %TRUE if this is a write to the sysctl file
2679 * @filp: the file structure
2680 * @buffer: the user buffer
2681 * @lenp: the size of the user buffer
2682 * @ppos: file position
2684 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2685 * values from/to the user buffer, treated as an ASCII string.
2686 * The values read are assumed to be in seconds, and are converted into
2689 * Returns 0 on success.
2691 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2692 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2694 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2695 do_proc_dointvec_jiffies_conv
,NULL
);
2699 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2700 * @table: the sysctl table
2701 * @write: %TRUE if this is a write to the sysctl file
2702 * @filp: the file structure
2703 * @buffer: the user buffer
2704 * @lenp: the size of the user buffer
2705 * @ppos: pointer to the file position
2707 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2708 * values from/to the user buffer, treated as an ASCII string.
2709 * The values read are assumed to be in 1/USER_HZ seconds, and
2710 * are converted into jiffies.
2712 * Returns 0 on success.
2714 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2715 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2717 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2718 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2722 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2723 * @table: the sysctl table
2724 * @write: %TRUE if this is a write to the sysctl file
2725 * @filp: the file structure
2726 * @buffer: the user buffer
2727 * @lenp: the size of the user buffer
2728 * @ppos: file position
2729 * @ppos: the current position in the file
2731 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2732 * values from/to the user buffer, treated as an ASCII string.
2733 * The values read are assumed to be in 1/1000 seconds, and
2734 * are converted into jiffies.
2736 * Returns 0 on success.
2738 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2739 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2741 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2742 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2745 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2746 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2748 struct pid
*new_pid
;
2752 tmp
= pid_vnr(cad_pid
);
2754 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2755 lenp
, ppos
, NULL
, NULL
);
2759 new_pid
= find_get_pid(tmp
);
2763 put_pid(xchg(&cad_pid
, new_pid
));
2767 #else /* CONFIG_PROC_FS */
2769 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2770 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2775 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2776 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2781 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2782 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2787 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2788 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2793 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2794 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2799 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2800 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2805 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2806 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2811 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2813 void __user
*buffer
,
2814 size_t *lenp
, loff_t
*ppos
)
2820 #endif /* CONFIG_PROC_FS */
2823 #ifdef CONFIG_SYSCTL_SYSCALL
2825 * General sysctl support routines
2828 /* The generic sysctl data routine (used if no strategy routine supplied) */
2829 int sysctl_data(struct ctl_table
*table
,
2830 void __user
*oldval
, size_t __user
*oldlenp
,
2831 void __user
*newval
, size_t newlen
)
2835 /* Get out of I don't have a variable */
2836 if (!table
->data
|| !table
->maxlen
)
2839 if (oldval
&& oldlenp
) {
2840 if (get_user(len
, oldlenp
))
2843 if (len
> table
->maxlen
)
2844 len
= table
->maxlen
;
2845 if (copy_to_user(oldval
, table
->data
, len
))
2847 if (put_user(len
, oldlenp
))
2852 if (newval
&& newlen
) {
2853 if (newlen
> table
->maxlen
)
2854 newlen
= table
->maxlen
;
2856 if (copy_from_user(table
->data
, newval
, newlen
))
2862 /* The generic string strategy routine: */
2863 int sysctl_string(struct ctl_table
*table
,
2864 void __user
*oldval
, size_t __user
*oldlenp
,
2865 void __user
*newval
, size_t newlen
)
2867 if (!table
->data
|| !table
->maxlen
)
2870 if (oldval
&& oldlenp
) {
2872 if (get_user(bufsize
, oldlenp
))
2875 size_t len
= strlen(table
->data
), copied
;
2877 /* This shouldn't trigger for a well-formed sysctl */
2878 if (len
> table
->maxlen
)
2879 len
= table
->maxlen
;
2881 /* Copy up to a max of bufsize-1 bytes of the string */
2882 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2884 if (copy_to_user(oldval
, table
->data
, copied
) ||
2885 put_user(0, (char __user
*)(oldval
+ copied
)))
2887 if (put_user(len
, oldlenp
))
2891 if (newval
&& newlen
) {
2892 size_t len
= newlen
;
2893 if (len
> table
->maxlen
)
2894 len
= table
->maxlen
;
2895 if(copy_from_user(table
->data
, newval
, len
))
2897 if (len
== table
->maxlen
)
2899 ((char *) table
->data
)[len
] = 0;
2905 * This function makes sure that all of the integers in the vector
2906 * are between the minimum and maximum values given in the arrays
2907 * table->extra1 and table->extra2, respectively.
2909 int sysctl_intvec(struct ctl_table
*table
,
2910 void __user
*oldval
, size_t __user
*oldlenp
,
2911 void __user
*newval
, size_t newlen
)
2914 if (newval
&& newlen
) {
2915 int __user
*vec
= (int __user
*) newval
;
2916 int *min
= (int *) table
->extra1
;
2917 int *max
= (int *) table
->extra2
;
2921 if (newlen
% sizeof(int) != 0)
2924 if (!table
->extra1
&& !table
->extra2
)
2927 if (newlen
> table
->maxlen
)
2928 newlen
= table
->maxlen
;
2929 length
= newlen
/ sizeof(int);
2931 for (i
= 0; i
< length
; i
++) {
2933 if (get_user(value
, vec
+ i
))
2935 if (min
&& value
< min
[i
])
2937 if (max
&& value
> max
[i
])
2944 /* Strategy function to convert jiffies to seconds */
2945 int sysctl_jiffies(struct ctl_table
*table
,
2946 void __user
*oldval
, size_t __user
*oldlenp
,
2947 void __user
*newval
, size_t newlen
)
2949 if (oldval
&& oldlenp
) {
2952 if (get_user(olen
, oldlenp
))
2957 if (olen
< sizeof(int))
2960 val
= *(int *)(table
->data
) / HZ
;
2961 if (put_user(val
, (int __user
*)oldval
))
2963 if (put_user(sizeof(int), oldlenp
))
2967 if (newval
&& newlen
) {
2969 if (newlen
!= sizeof(int))
2971 if (get_user(new, (int __user
*)newval
))
2973 *(int *)(table
->data
) = new*HZ
;
2978 /* Strategy function to convert jiffies to seconds */
2979 int sysctl_ms_jiffies(struct ctl_table
*table
,
2980 void __user
*oldval
, size_t __user
*oldlenp
,
2981 void __user
*newval
, size_t newlen
)
2983 if (oldval
&& oldlenp
) {
2986 if (get_user(olen
, oldlenp
))
2991 if (olen
< sizeof(int))
2994 val
= jiffies_to_msecs(*(int *)(table
->data
));
2995 if (put_user(val
, (int __user
*)oldval
))
2997 if (put_user(sizeof(int), oldlenp
))
3001 if (newval
&& newlen
) {
3003 if (newlen
!= sizeof(int))
3005 if (get_user(new, (int __user
*)newval
))
3007 *(int *)(table
->data
) = msecs_to_jiffies(new);
3014 #else /* CONFIG_SYSCTL_SYSCALL */
3017 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
3019 struct __sysctl_args tmp
;
3022 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
3025 error
= deprecated_sysctl_warning(&tmp
);
3027 /* If no error reading the parameters then just -ENOSYS ... */
3034 int sysctl_data(struct ctl_table
*table
,
3035 void __user
*oldval
, size_t __user
*oldlenp
,
3036 void __user
*newval
, size_t newlen
)
3041 int sysctl_string(struct ctl_table
*table
,
3042 void __user
*oldval
, size_t __user
*oldlenp
,
3043 void __user
*newval
, size_t newlen
)
3048 int sysctl_intvec(struct ctl_table
*table
,
3049 void __user
*oldval
, size_t __user
*oldlenp
,
3050 void __user
*newval
, size_t newlen
)
3055 int sysctl_jiffies(struct ctl_table
*table
,
3056 void __user
*oldval
, size_t __user
*oldlenp
,
3057 void __user
*newval
, size_t newlen
)
3062 int sysctl_ms_jiffies(struct ctl_table
*table
,
3063 void __user
*oldval
, size_t __user
*oldlenp
,
3064 void __user
*newval
, size_t newlen
)
3069 #endif /* CONFIG_SYSCTL_SYSCALL */
3071 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
3073 static int msg_count
;
3074 int name
[CTL_MAXNAME
];
3077 /* Check args->nlen. */
3078 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
3081 /* Read in the sysctl name for better debug message logging */
3082 for (i
= 0; i
< args
->nlen
; i
++)
3083 if (get_user(name
[i
], args
->name
+ i
))
3086 /* Ignore accesses to kernel.version */
3087 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
3090 if (msg_count
< 5) {
3093 "warning: process `%s' used the deprecated sysctl "
3094 "system call with ", current
->comm
);
3095 for (i
= 0; i
< args
->nlen
; i
++)
3096 printk("%d.", name
[i
]);
3103 * No sense putting this after each symbol definition, twice,
3104 * exception granted :-)
3106 EXPORT_SYMBOL(proc_dointvec
);
3107 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3108 EXPORT_SYMBOL(proc_dointvec_minmax
);
3109 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3110 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3111 EXPORT_SYMBOL(proc_dostring
);
3112 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3113 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
3114 EXPORT_SYMBOL(register_sysctl_table
);
3115 EXPORT_SYMBOL(register_sysctl_paths
);
3116 EXPORT_SYMBOL(sysctl_intvec
);
3117 EXPORT_SYMBOL(sysctl_jiffies
);
3118 EXPORT_SYMBOL(sysctl_ms_jiffies
);
3119 EXPORT_SYMBOL(sysctl_string
);
3120 EXPORT_SYMBOL(sysctl_data
);
3121 EXPORT_SYMBOL(unregister_sysctl_table
);