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>
51 #include <linux/slow-work.h>
52 #include <linux/perf_counter.h>
54 #include <asm/uaccess.h>
55 #include <asm/processor.h>
59 #include <asm/stacktrace.h>
63 static int deprecated_sysctl_warning(struct __sysctl_args
*args
);
65 #if defined(CONFIG_SYSCTL)
67 /* External variables not in a header file. */
69 extern int print_fatal_signals
;
70 extern int sysctl_overcommit_memory
;
71 extern int sysctl_overcommit_ratio
;
72 extern int sysctl_panic_on_oom
;
73 extern int sysctl_oom_kill_allocating_task
;
74 extern int sysctl_oom_dump_tasks
;
75 extern int max_threads
;
76 extern int core_uses_pid
;
77 extern int suid_dumpable
;
78 extern char core_pattern
[];
80 extern int min_free_kbytes
;
81 extern int pid_max_min
, pid_max_max
;
82 extern int sysctl_drop_caches
;
83 extern int percpu_pagelist_fraction
;
84 extern int compat_log
;
85 extern int latencytop_enabled
;
86 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
88 extern int sysctl_nr_trim_pages
;
90 #ifdef CONFIG_RCU_TORTURE_TEST
91 extern int rcutorture_runnable
;
92 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
94 /* Constants used for minimum and maximum */
95 #ifdef CONFIG_DETECT_SOFTLOCKUP
96 static int sixty
= 60;
97 static int neg_one
= -1;
101 static int __maybe_unused one
= 1;
102 static int __maybe_unused two
= 2;
103 static unsigned long one_ul
= 1;
104 static int one_hundred
= 100;
106 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
107 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
109 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
110 static int maxolduid
= 65535;
111 static int minolduid
;
112 static int min_percpu_pagelist_fract
= 8;
114 static int ngroups_max
= NGROUPS_MAX
;
116 #ifdef CONFIG_MODULES
117 extern char modprobe_path
[];
118 extern int modules_disabled
;
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
,
233 * NOTE: do not add new entries to this table unless you have read
234 * Documentation/sysctl/ctl_unnumbered.txt
239 #ifdef CONFIG_SCHED_DEBUG
240 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
241 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
242 static int min_wakeup_granularity_ns
; /* 0 usecs */
243 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
246 static struct ctl_table kern_table
[] = {
247 #ifdef CONFIG_SCHED_DEBUG
249 .ctl_name
= CTL_UNNUMBERED
,
250 .procname
= "sched_min_granularity_ns",
251 .data
= &sysctl_sched_min_granularity
,
252 .maxlen
= sizeof(unsigned int),
254 .proc_handler
= &sched_nr_latency_handler
,
255 .strategy
= &sysctl_intvec
,
256 .extra1
= &min_sched_granularity_ns
,
257 .extra2
= &max_sched_granularity_ns
,
260 .ctl_name
= CTL_UNNUMBERED
,
261 .procname
= "sched_latency_ns",
262 .data
= &sysctl_sched_latency
,
263 .maxlen
= sizeof(unsigned int),
265 .proc_handler
= &sched_nr_latency_handler
,
266 .strategy
= &sysctl_intvec
,
267 .extra1
= &min_sched_granularity_ns
,
268 .extra2
= &max_sched_granularity_ns
,
271 .ctl_name
= CTL_UNNUMBERED
,
272 .procname
= "sched_wakeup_granularity_ns",
273 .data
= &sysctl_sched_wakeup_granularity
,
274 .maxlen
= sizeof(unsigned int),
276 .proc_handler
= &proc_dointvec_minmax
,
277 .strategy
= &sysctl_intvec
,
278 .extra1
= &min_wakeup_granularity_ns
,
279 .extra2
= &max_wakeup_granularity_ns
,
282 .ctl_name
= CTL_UNNUMBERED
,
283 .procname
= "sched_shares_ratelimit",
284 .data
= &sysctl_sched_shares_ratelimit
,
285 .maxlen
= sizeof(unsigned int),
287 .proc_handler
= &proc_dointvec
,
290 .ctl_name
= CTL_UNNUMBERED
,
291 .procname
= "sched_shares_thresh",
292 .data
= &sysctl_sched_shares_thresh
,
293 .maxlen
= sizeof(unsigned int),
295 .proc_handler
= &proc_dointvec_minmax
,
296 .strategy
= &sysctl_intvec
,
300 .ctl_name
= CTL_UNNUMBERED
,
301 .procname
= "sched_child_runs_first",
302 .data
= &sysctl_sched_child_runs_first
,
303 .maxlen
= sizeof(unsigned int),
305 .proc_handler
= &proc_dointvec
,
308 .ctl_name
= CTL_UNNUMBERED
,
309 .procname
= "sched_features",
310 .data
= &sysctl_sched_features
,
311 .maxlen
= sizeof(unsigned int),
313 .proc_handler
= &proc_dointvec
,
316 .ctl_name
= CTL_UNNUMBERED
,
317 .procname
= "sched_migration_cost",
318 .data
= &sysctl_sched_migration_cost
,
319 .maxlen
= sizeof(unsigned int),
321 .proc_handler
= &proc_dointvec
,
324 .ctl_name
= CTL_UNNUMBERED
,
325 .procname
= "sched_nr_migrate",
326 .data
= &sysctl_sched_nr_migrate
,
327 .maxlen
= sizeof(unsigned int),
329 .proc_handler
= &proc_dointvec
,
332 .ctl_name
= CTL_UNNUMBERED
,
333 .procname
= "timer_migration",
334 .data
= &sysctl_timer_migration
,
335 .maxlen
= sizeof(unsigned int),
337 .proc_handler
= &proc_dointvec
,
341 .ctl_name
= CTL_UNNUMBERED
,
342 .procname
= "sched_rt_period_us",
343 .data
= &sysctl_sched_rt_period
,
344 .maxlen
= sizeof(unsigned int),
346 .proc_handler
= &sched_rt_handler
,
349 .ctl_name
= CTL_UNNUMBERED
,
350 .procname
= "sched_rt_runtime_us",
351 .data
= &sysctl_sched_rt_runtime
,
352 .maxlen
= sizeof(int),
354 .proc_handler
= &sched_rt_handler
,
357 .ctl_name
= CTL_UNNUMBERED
,
358 .procname
= "sched_compat_yield",
359 .data
= &sysctl_sched_compat_yield
,
360 .maxlen
= sizeof(unsigned int),
362 .proc_handler
= &proc_dointvec
,
364 #ifdef CONFIG_PROVE_LOCKING
366 .ctl_name
= CTL_UNNUMBERED
,
367 .procname
= "prove_locking",
368 .data
= &prove_locking
,
369 .maxlen
= sizeof(int),
371 .proc_handler
= &proc_dointvec
,
374 #ifdef CONFIG_LOCK_STAT
376 .ctl_name
= CTL_UNNUMBERED
,
377 .procname
= "lock_stat",
379 .maxlen
= sizeof(int),
381 .proc_handler
= &proc_dointvec
,
385 .ctl_name
= KERN_PANIC
,
387 .data
= &panic_timeout
,
388 .maxlen
= sizeof(int),
390 .proc_handler
= &proc_dointvec
,
393 .ctl_name
= KERN_CORE_USES_PID
,
394 .procname
= "core_uses_pid",
395 .data
= &core_uses_pid
,
396 .maxlen
= sizeof(int),
398 .proc_handler
= &proc_dointvec
,
401 .ctl_name
= KERN_CORE_PATTERN
,
402 .procname
= "core_pattern",
403 .data
= core_pattern
,
404 .maxlen
= CORENAME_MAX_SIZE
,
406 .proc_handler
= &proc_dostring
,
407 .strategy
= &sysctl_string
,
409 #ifdef CONFIG_PROC_SYSCTL
411 .procname
= "tainted",
412 .maxlen
= sizeof(long),
414 .proc_handler
= &proc_taint
,
417 #ifdef CONFIG_LATENCYTOP
419 .procname
= "latencytop",
420 .data
= &latencytop_enabled
,
421 .maxlen
= sizeof(int),
423 .proc_handler
= &proc_dointvec
,
426 #ifdef CONFIG_BLK_DEV_INITRD
428 .ctl_name
= KERN_REALROOTDEV
,
429 .procname
= "real-root-dev",
430 .data
= &real_root_dev
,
431 .maxlen
= sizeof(int),
433 .proc_handler
= &proc_dointvec
,
437 .ctl_name
= CTL_UNNUMBERED
,
438 .procname
= "print-fatal-signals",
439 .data
= &print_fatal_signals
,
440 .maxlen
= sizeof(int),
442 .proc_handler
= &proc_dointvec
,
446 .ctl_name
= KERN_SPARC_REBOOT
,
447 .procname
= "reboot-cmd",
448 .data
= reboot_command
,
451 .proc_handler
= &proc_dostring
,
452 .strategy
= &sysctl_string
,
455 .ctl_name
= KERN_SPARC_STOP_A
,
456 .procname
= "stop-a",
457 .data
= &stop_a_enabled
,
458 .maxlen
= sizeof (int),
460 .proc_handler
= &proc_dointvec
,
463 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
464 .procname
= "scons-poweroff",
465 .data
= &scons_pwroff
,
466 .maxlen
= sizeof (int),
468 .proc_handler
= &proc_dointvec
,
471 #ifdef CONFIG_SPARC64
473 .ctl_name
= CTL_UNNUMBERED
,
474 .procname
= "tsb-ratio",
475 .data
= &sysctl_tsb_ratio
,
476 .maxlen
= sizeof (int),
478 .proc_handler
= &proc_dointvec
,
483 .ctl_name
= KERN_HPPA_PWRSW
,
484 .procname
= "soft-power",
485 .data
= &pwrsw_enabled
,
486 .maxlen
= sizeof (int),
488 .proc_handler
= &proc_dointvec
,
491 .ctl_name
= KERN_HPPA_UNALIGNED
,
492 .procname
= "unaligned-trap",
493 .data
= &unaligned_enabled
,
494 .maxlen
= sizeof (int),
496 .proc_handler
= &proc_dointvec
,
500 .ctl_name
= KERN_CTLALTDEL
,
501 .procname
= "ctrl-alt-del",
503 .maxlen
= sizeof(int),
505 .proc_handler
= &proc_dointvec
,
507 #ifdef CONFIG_FUNCTION_TRACER
509 .ctl_name
= CTL_UNNUMBERED
,
510 .procname
= "ftrace_enabled",
511 .data
= &ftrace_enabled
,
512 .maxlen
= sizeof(int),
514 .proc_handler
= &ftrace_enable_sysctl
,
517 #ifdef CONFIG_STACK_TRACER
519 .ctl_name
= CTL_UNNUMBERED
,
520 .procname
= "stack_tracer_enabled",
521 .data
= &stack_tracer_enabled
,
522 .maxlen
= sizeof(int),
524 .proc_handler
= &stack_trace_sysctl
,
527 #ifdef CONFIG_TRACING
529 .ctl_name
= CTL_UNNUMBERED
,
530 .procname
= "ftrace_dump_on_oops",
531 .data
= &ftrace_dump_on_oops
,
532 .maxlen
= sizeof(int),
534 .proc_handler
= &proc_dointvec
,
537 #ifdef CONFIG_MODULES
539 .ctl_name
= KERN_MODPROBE
,
540 .procname
= "modprobe",
541 .data
= &modprobe_path
,
542 .maxlen
= KMOD_PATH_LEN
,
544 .proc_handler
= &proc_dostring
,
545 .strategy
= &sysctl_string
,
548 .ctl_name
= CTL_UNNUMBERED
,
549 .procname
= "modules_disabled",
550 .data
= &modules_disabled
,
551 .maxlen
= sizeof(int),
553 /* only handle a transition from default "0" to "1" */
554 .proc_handler
= &proc_dointvec_minmax
,
559 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
561 .ctl_name
= KERN_HOTPLUG
,
562 .procname
= "hotplug",
563 .data
= &uevent_helper
,
564 .maxlen
= UEVENT_HELPER_PATH_LEN
,
566 .proc_handler
= &proc_dostring
,
567 .strategy
= &sysctl_string
,
570 #ifdef CONFIG_CHR_DEV_SG
572 .ctl_name
= KERN_SG_BIG_BUFF
,
573 .procname
= "sg-big-buff",
574 .data
= &sg_big_buff
,
575 .maxlen
= sizeof (int),
577 .proc_handler
= &proc_dointvec
,
580 #ifdef CONFIG_BSD_PROCESS_ACCT
582 .ctl_name
= KERN_ACCT
,
585 .maxlen
= 3*sizeof(int),
587 .proc_handler
= &proc_dointvec
,
590 #ifdef CONFIG_MAGIC_SYSRQ
592 .ctl_name
= KERN_SYSRQ
,
594 .data
= &__sysrq_enabled
,
595 .maxlen
= sizeof (int),
597 .proc_handler
= &proc_dointvec
,
600 #ifdef CONFIG_PROC_SYSCTL
602 .procname
= "cad_pid",
604 .maxlen
= sizeof (int),
606 .proc_handler
= &proc_do_cad_pid
,
610 .ctl_name
= KERN_MAX_THREADS
,
611 .procname
= "threads-max",
612 .data
= &max_threads
,
613 .maxlen
= sizeof(int),
615 .proc_handler
= &proc_dointvec
,
618 .ctl_name
= KERN_RANDOM
,
619 .procname
= "random",
621 .child
= random_table
,
624 .ctl_name
= KERN_OVERFLOWUID
,
625 .procname
= "overflowuid",
626 .data
= &overflowuid
,
627 .maxlen
= sizeof(int),
629 .proc_handler
= &proc_dointvec_minmax
,
630 .strategy
= &sysctl_intvec
,
631 .extra1
= &minolduid
,
632 .extra2
= &maxolduid
,
635 .ctl_name
= KERN_OVERFLOWGID
,
636 .procname
= "overflowgid",
637 .data
= &overflowgid
,
638 .maxlen
= sizeof(int),
640 .proc_handler
= &proc_dointvec_minmax
,
641 .strategy
= &sysctl_intvec
,
642 .extra1
= &minolduid
,
643 .extra2
= &maxolduid
,
646 #ifdef CONFIG_MATHEMU
648 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
649 .procname
= "ieee_emulation_warnings",
650 .data
= &sysctl_ieee_emulation_warnings
,
651 .maxlen
= sizeof(int),
653 .proc_handler
= &proc_dointvec
,
657 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
658 .procname
= "userprocess_debug",
659 .data
= &sysctl_userprocess_debug
,
660 .maxlen
= sizeof(int),
662 .proc_handler
= &proc_dointvec
,
666 .ctl_name
= KERN_PIDMAX
,
667 .procname
= "pid_max",
669 .maxlen
= sizeof (int),
671 .proc_handler
= &proc_dointvec_minmax
,
672 .strategy
= sysctl_intvec
,
673 .extra1
= &pid_max_min
,
674 .extra2
= &pid_max_max
,
677 .ctl_name
= KERN_PANIC_ON_OOPS
,
678 .procname
= "panic_on_oops",
679 .data
= &panic_on_oops
,
680 .maxlen
= sizeof(int),
682 .proc_handler
= &proc_dointvec
,
684 #if defined CONFIG_PRINTK
686 .ctl_name
= KERN_PRINTK
,
687 .procname
= "printk",
688 .data
= &console_loglevel
,
689 .maxlen
= 4*sizeof(int),
691 .proc_handler
= &proc_dointvec
,
694 .ctl_name
= KERN_PRINTK_RATELIMIT
,
695 .procname
= "printk_ratelimit",
696 .data
= &printk_ratelimit_state
.interval
,
697 .maxlen
= sizeof(int),
699 .proc_handler
= &proc_dointvec_jiffies
,
700 .strategy
= &sysctl_jiffies
,
703 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
704 .procname
= "printk_ratelimit_burst",
705 .data
= &printk_ratelimit_state
.burst
,
706 .maxlen
= sizeof(int),
708 .proc_handler
= &proc_dointvec
,
712 .ctl_name
= KERN_NGROUPS_MAX
,
713 .procname
= "ngroups_max",
714 .data
= &ngroups_max
,
715 .maxlen
= sizeof (int),
717 .proc_handler
= &proc_dointvec
,
719 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
721 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
722 .procname
= "unknown_nmi_panic",
723 .data
= &unknown_nmi_panic
,
724 .maxlen
= sizeof (int),
726 .proc_handler
= &proc_dointvec
,
729 .procname
= "nmi_watchdog",
730 .data
= &nmi_watchdog_enabled
,
731 .maxlen
= sizeof (int),
733 .proc_handler
= &proc_nmi_enabled
,
736 #if defined(CONFIG_X86)
738 .ctl_name
= KERN_PANIC_ON_NMI
,
739 .procname
= "panic_on_unrecovered_nmi",
740 .data
= &panic_on_unrecovered_nmi
,
741 .maxlen
= sizeof(int),
743 .proc_handler
= &proc_dointvec
,
746 .ctl_name
= KERN_BOOTLOADER_TYPE
,
747 .procname
= "bootloader_type",
748 .data
= &bootloader_type
,
749 .maxlen
= sizeof (int),
751 .proc_handler
= &proc_dointvec
,
754 .ctl_name
= CTL_UNNUMBERED
,
755 .procname
= "bootloader_version",
756 .data
= &bootloader_version
,
757 .maxlen
= sizeof (int),
759 .proc_handler
= &proc_dointvec
,
762 .ctl_name
= CTL_UNNUMBERED
,
763 .procname
= "kstack_depth_to_print",
764 .data
= &kstack_depth_to_print
,
765 .maxlen
= sizeof(int),
767 .proc_handler
= &proc_dointvec
,
770 .ctl_name
= CTL_UNNUMBERED
,
771 .procname
= "io_delay_type",
772 .data
= &io_delay_type
,
773 .maxlen
= sizeof(int),
775 .proc_handler
= &proc_dointvec
,
778 #if defined(CONFIG_MMU)
780 .ctl_name
= KERN_RANDOMIZE
,
781 .procname
= "randomize_va_space",
782 .data
= &randomize_va_space
,
783 .maxlen
= sizeof(int),
785 .proc_handler
= &proc_dointvec
,
788 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
790 .ctl_name
= KERN_SPIN_RETRY
,
791 .procname
= "spin_retry",
793 .maxlen
= sizeof (int),
795 .proc_handler
= &proc_dointvec
,
798 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
800 .procname
= "acpi_video_flags",
801 .data
= &acpi_realmode_flags
,
802 .maxlen
= sizeof (unsigned long),
804 .proc_handler
= &proc_doulongvec_minmax
,
809 .ctl_name
= KERN_IA64_UNALIGNED
,
810 .procname
= "ignore-unaligned-usertrap",
811 .data
= &no_unaligned_warning
,
812 .maxlen
= sizeof (int),
814 .proc_handler
= &proc_dointvec
,
817 .ctl_name
= CTL_UNNUMBERED
,
818 .procname
= "unaligned-dump-stack",
819 .data
= &unaligned_dump_stack
,
820 .maxlen
= sizeof (int),
822 .proc_handler
= &proc_dointvec
,
825 #ifdef CONFIG_DETECT_SOFTLOCKUP
827 .ctl_name
= CTL_UNNUMBERED
,
828 .procname
= "softlockup_panic",
829 .data
= &softlockup_panic
,
830 .maxlen
= sizeof(int),
832 .proc_handler
= &proc_dointvec_minmax
,
833 .strategy
= &sysctl_intvec
,
838 .ctl_name
= CTL_UNNUMBERED
,
839 .procname
= "softlockup_thresh",
840 .data
= &softlockup_thresh
,
841 .maxlen
= sizeof(int),
843 .proc_handler
= &proc_dosoftlockup_thresh
,
844 .strategy
= &sysctl_intvec
,
849 #ifdef CONFIG_DETECT_HUNG_TASK
851 .ctl_name
= CTL_UNNUMBERED
,
852 .procname
= "hung_task_panic",
853 .data
= &sysctl_hung_task_panic
,
854 .maxlen
= sizeof(int),
856 .proc_handler
= &proc_dointvec_minmax
,
857 .strategy
= &sysctl_intvec
,
862 .ctl_name
= CTL_UNNUMBERED
,
863 .procname
= "hung_task_check_count",
864 .data
= &sysctl_hung_task_check_count
,
865 .maxlen
= sizeof(unsigned long),
867 .proc_handler
= &proc_doulongvec_minmax
,
868 .strategy
= &sysctl_intvec
,
871 .ctl_name
= CTL_UNNUMBERED
,
872 .procname
= "hung_task_timeout_secs",
873 .data
= &sysctl_hung_task_timeout_secs
,
874 .maxlen
= sizeof(unsigned long),
876 .proc_handler
= &proc_dohung_task_timeout_secs
,
877 .strategy
= &sysctl_intvec
,
880 .ctl_name
= CTL_UNNUMBERED
,
881 .procname
= "hung_task_warnings",
882 .data
= &sysctl_hung_task_warnings
,
883 .maxlen
= sizeof(unsigned long),
885 .proc_handler
= &proc_doulongvec_minmax
,
886 .strategy
= &sysctl_intvec
,
891 .ctl_name
= KERN_COMPAT_LOG
,
892 .procname
= "compat-log",
894 .maxlen
= sizeof (int),
896 .proc_handler
= &proc_dointvec
,
899 #ifdef CONFIG_RT_MUTEXES
901 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
902 .procname
= "max_lock_depth",
903 .data
= &max_lock_depth
,
904 .maxlen
= sizeof(int),
906 .proc_handler
= &proc_dointvec
,
910 .ctl_name
= CTL_UNNUMBERED
,
911 .procname
= "poweroff_cmd",
912 .data
= &poweroff_cmd
,
913 .maxlen
= POWEROFF_CMD_PATH_LEN
,
915 .proc_handler
= &proc_dostring
,
916 .strategy
= &sysctl_string
,
920 .ctl_name
= CTL_UNNUMBERED
,
923 .child
= key_sysctls
,
926 #ifdef CONFIG_RCU_TORTURE_TEST
928 .ctl_name
= CTL_UNNUMBERED
,
929 .procname
= "rcutorture_runnable",
930 .data
= &rcutorture_runnable
,
931 .maxlen
= sizeof(int),
933 .proc_handler
= &proc_dointvec
,
936 #ifdef CONFIG_SLOW_WORK
938 .ctl_name
= CTL_UNNUMBERED
,
939 .procname
= "slow-work",
941 .child
= slow_work_sysctls
,
944 #ifdef CONFIG_PERF_COUNTERS
946 .ctl_name
= CTL_UNNUMBERED
,
947 .procname
= "perf_counter_paranoid",
948 .data
= &sysctl_perf_counter_paranoid
,
949 .maxlen
= sizeof(sysctl_perf_counter_paranoid
),
951 .proc_handler
= &proc_dointvec
,
954 .ctl_name
= CTL_UNNUMBERED
,
955 .procname
= "perf_counter_mlock_kb",
956 .data
= &sysctl_perf_counter_mlock
,
957 .maxlen
= sizeof(sysctl_perf_counter_mlock
),
959 .proc_handler
= &proc_dointvec
,
962 .ctl_name
= CTL_UNNUMBERED
,
963 .procname
= "perf_counter_max_sample_rate",
964 .data
= &sysctl_perf_counter_sample_rate
,
965 .maxlen
= sizeof(sysctl_perf_counter_sample_rate
),
967 .proc_handler
= &proc_dointvec
,
971 * NOTE: do not add new entries to this table unless you have read
972 * Documentation/sysctl/ctl_unnumbered.txt
977 static struct ctl_table vm_table
[] = {
979 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
980 .procname
= "overcommit_memory",
981 .data
= &sysctl_overcommit_memory
,
982 .maxlen
= sizeof(sysctl_overcommit_memory
),
984 .proc_handler
= &proc_dointvec
,
987 .ctl_name
= VM_PANIC_ON_OOM
,
988 .procname
= "panic_on_oom",
989 .data
= &sysctl_panic_on_oom
,
990 .maxlen
= sizeof(sysctl_panic_on_oom
),
992 .proc_handler
= &proc_dointvec
,
995 .ctl_name
= CTL_UNNUMBERED
,
996 .procname
= "oom_kill_allocating_task",
997 .data
= &sysctl_oom_kill_allocating_task
,
998 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1000 .proc_handler
= &proc_dointvec
,
1003 .ctl_name
= CTL_UNNUMBERED
,
1004 .procname
= "oom_dump_tasks",
1005 .data
= &sysctl_oom_dump_tasks
,
1006 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1008 .proc_handler
= &proc_dointvec
,
1011 .ctl_name
= VM_OVERCOMMIT_RATIO
,
1012 .procname
= "overcommit_ratio",
1013 .data
= &sysctl_overcommit_ratio
,
1014 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1016 .proc_handler
= &proc_dointvec
,
1019 .ctl_name
= VM_PAGE_CLUSTER
,
1020 .procname
= "page-cluster",
1021 .data
= &page_cluster
,
1022 .maxlen
= sizeof(int),
1024 .proc_handler
= &proc_dointvec
,
1027 .ctl_name
= VM_DIRTY_BACKGROUND
,
1028 .procname
= "dirty_background_ratio",
1029 .data
= &dirty_background_ratio
,
1030 .maxlen
= sizeof(dirty_background_ratio
),
1032 .proc_handler
= &dirty_background_ratio_handler
,
1033 .strategy
= &sysctl_intvec
,
1035 .extra2
= &one_hundred
,
1038 .ctl_name
= CTL_UNNUMBERED
,
1039 .procname
= "dirty_background_bytes",
1040 .data
= &dirty_background_bytes
,
1041 .maxlen
= sizeof(dirty_background_bytes
),
1043 .proc_handler
= &dirty_background_bytes_handler
,
1044 .strategy
= &sysctl_intvec
,
1048 .ctl_name
= VM_DIRTY_RATIO
,
1049 .procname
= "dirty_ratio",
1050 .data
= &vm_dirty_ratio
,
1051 .maxlen
= sizeof(vm_dirty_ratio
),
1053 .proc_handler
= &dirty_ratio_handler
,
1054 .strategy
= &sysctl_intvec
,
1056 .extra2
= &one_hundred
,
1059 .ctl_name
= CTL_UNNUMBERED
,
1060 .procname
= "dirty_bytes",
1061 .data
= &vm_dirty_bytes
,
1062 .maxlen
= sizeof(vm_dirty_bytes
),
1064 .proc_handler
= &dirty_bytes_handler
,
1065 .strategy
= &sysctl_intvec
,
1066 .extra1
= &dirty_bytes_min
,
1069 .procname
= "dirty_writeback_centisecs",
1070 .data
= &dirty_writeback_interval
,
1071 .maxlen
= sizeof(dirty_writeback_interval
),
1073 .proc_handler
= &dirty_writeback_centisecs_handler
,
1076 .procname
= "dirty_expire_centisecs",
1077 .data
= &dirty_expire_interval
,
1078 .maxlen
= sizeof(dirty_expire_interval
),
1080 .proc_handler
= &proc_dointvec
,
1083 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
1084 .procname
= "nr_pdflush_threads",
1085 .data
= &nr_pdflush_threads
,
1086 .maxlen
= sizeof nr_pdflush_threads
,
1087 .mode
= 0444 /* read-only*/,
1088 .proc_handler
= &proc_dointvec
,
1091 .ctl_name
= VM_SWAPPINESS
,
1092 .procname
= "swappiness",
1093 .data
= &vm_swappiness
,
1094 .maxlen
= sizeof(vm_swappiness
),
1096 .proc_handler
= &proc_dointvec_minmax
,
1097 .strategy
= &sysctl_intvec
,
1099 .extra2
= &one_hundred
,
1101 #ifdef CONFIG_HUGETLB_PAGE
1103 .procname
= "nr_hugepages",
1105 .maxlen
= sizeof(unsigned long),
1107 .proc_handler
= &hugetlb_sysctl_handler
,
1108 .extra1
= (void *)&hugetlb_zero
,
1109 .extra2
= (void *)&hugetlb_infinity
,
1112 .ctl_name
= VM_HUGETLB_GROUP
,
1113 .procname
= "hugetlb_shm_group",
1114 .data
= &sysctl_hugetlb_shm_group
,
1115 .maxlen
= sizeof(gid_t
),
1117 .proc_handler
= &proc_dointvec
,
1120 .ctl_name
= CTL_UNNUMBERED
,
1121 .procname
= "hugepages_treat_as_movable",
1122 .data
= &hugepages_treat_as_movable
,
1123 .maxlen
= sizeof(int),
1125 .proc_handler
= &hugetlb_treat_movable_handler
,
1128 .ctl_name
= CTL_UNNUMBERED
,
1129 .procname
= "nr_overcommit_hugepages",
1131 .maxlen
= sizeof(unsigned long),
1133 .proc_handler
= &hugetlb_overcommit_handler
,
1134 .extra1
= (void *)&hugetlb_zero
,
1135 .extra2
= (void *)&hugetlb_infinity
,
1139 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
1140 .procname
= "lowmem_reserve_ratio",
1141 .data
= &sysctl_lowmem_reserve_ratio
,
1142 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1144 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
1145 .strategy
= &sysctl_intvec
,
1148 .ctl_name
= VM_DROP_PAGECACHE
,
1149 .procname
= "drop_caches",
1150 .data
= &sysctl_drop_caches
,
1151 .maxlen
= sizeof(int),
1153 .proc_handler
= drop_caches_sysctl_handler
,
1154 .strategy
= &sysctl_intvec
,
1157 .ctl_name
= VM_MIN_FREE_KBYTES
,
1158 .procname
= "min_free_kbytes",
1159 .data
= &min_free_kbytes
,
1160 .maxlen
= sizeof(min_free_kbytes
),
1162 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1163 .strategy
= &sysctl_intvec
,
1167 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1168 .procname
= "percpu_pagelist_fraction",
1169 .data
= &percpu_pagelist_fraction
,
1170 .maxlen
= sizeof(percpu_pagelist_fraction
),
1172 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1173 .strategy
= &sysctl_intvec
,
1174 .extra1
= &min_percpu_pagelist_fract
,
1178 .ctl_name
= VM_MAX_MAP_COUNT
,
1179 .procname
= "max_map_count",
1180 .data
= &sysctl_max_map_count
,
1181 .maxlen
= sizeof(sysctl_max_map_count
),
1183 .proc_handler
= &proc_dointvec
1187 .ctl_name
= CTL_UNNUMBERED
,
1188 .procname
= "nr_trim_pages",
1189 .data
= &sysctl_nr_trim_pages
,
1190 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1192 .proc_handler
= &proc_dointvec_minmax
,
1193 .strategy
= &sysctl_intvec
,
1198 .ctl_name
= VM_LAPTOP_MODE
,
1199 .procname
= "laptop_mode",
1200 .data
= &laptop_mode
,
1201 .maxlen
= sizeof(laptop_mode
),
1203 .proc_handler
= &proc_dointvec_jiffies
,
1204 .strategy
= &sysctl_jiffies
,
1207 .ctl_name
= VM_BLOCK_DUMP
,
1208 .procname
= "block_dump",
1209 .data
= &block_dump
,
1210 .maxlen
= sizeof(block_dump
),
1212 .proc_handler
= &proc_dointvec
,
1213 .strategy
= &sysctl_intvec
,
1217 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1218 .procname
= "vfs_cache_pressure",
1219 .data
= &sysctl_vfs_cache_pressure
,
1220 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1222 .proc_handler
= &proc_dointvec
,
1223 .strategy
= &sysctl_intvec
,
1226 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1228 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1229 .procname
= "legacy_va_layout",
1230 .data
= &sysctl_legacy_va_layout
,
1231 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1233 .proc_handler
= &proc_dointvec
,
1234 .strategy
= &sysctl_intvec
,
1240 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1241 .procname
= "zone_reclaim_mode",
1242 .data
= &zone_reclaim_mode
,
1243 .maxlen
= sizeof(zone_reclaim_mode
),
1245 .proc_handler
= &proc_dointvec
,
1246 .strategy
= &sysctl_intvec
,
1250 .ctl_name
= VM_MIN_UNMAPPED
,
1251 .procname
= "min_unmapped_ratio",
1252 .data
= &sysctl_min_unmapped_ratio
,
1253 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1255 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1256 .strategy
= &sysctl_intvec
,
1258 .extra2
= &one_hundred
,
1261 .ctl_name
= VM_MIN_SLAB
,
1262 .procname
= "min_slab_ratio",
1263 .data
= &sysctl_min_slab_ratio
,
1264 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1266 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1267 .strategy
= &sysctl_intvec
,
1269 .extra2
= &one_hundred
,
1274 .ctl_name
= CTL_UNNUMBERED
,
1275 .procname
= "stat_interval",
1276 .data
= &sysctl_stat_interval
,
1277 .maxlen
= sizeof(sysctl_stat_interval
),
1279 .proc_handler
= &proc_dointvec_jiffies
,
1280 .strategy
= &sysctl_jiffies
,
1284 .ctl_name
= CTL_UNNUMBERED
,
1285 .procname
= "mmap_min_addr",
1286 .data
= &mmap_min_addr
,
1287 .maxlen
= sizeof(unsigned long),
1289 .proc_handler
= &proc_doulongvec_minmax
,
1293 .ctl_name
= CTL_UNNUMBERED
,
1294 .procname
= "numa_zonelist_order",
1295 .data
= &numa_zonelist_order
,
1296 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1298 .proc_handler
= &numa_zonelist_order_handler
,
1299 .strategy
= &sysctl_string
,
1302 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1303 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1305 .ctl_name
= VM_VDSO_ENABLED
,
1306 .procname
= "vdso_enabled",
1307 .data
= &vdso_enabled
,
1308 .maxlen
= sizeof(vdso_enabled
),
1310 .proc_handler
= &proc_dointvec
,
1311 .strategy
= &sysctl_intvec
,
1315 #ifdef CONFIG_HIGHMEM
1317 .ctl_name
= CTL_UNNUMBERED
,
1318 .procname
= "highmem_is_dirtyable",
1319 .data
= &vm_highmem_is_dirtyable
,
1320 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1322 .proc_handler
= &proc_dointvec_minmax
,
1323 .strategy
= &sysctl_intvec
,
1328 #ifdef CONFIG_UNEVICTABLE_LRU
1330 .ctl_name
= CTL_UNNUMBERED
,
1331 .procname
= "scan_unevictable_pages",
1332 .data
= &scan_unevictable_pages
,
1333 .maxlen
= sizeof(scan_unevictable_pages
),
1335 .proc_handler
= &scan_unevictable_handler
,
1339 * NOTE: do not add new entries to this table unless you have read
1340 * Documentation/sysctl/ctl_unnumbered.txt
1345 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1346 static struct ctl_table binfmt_misc_table
[] = {
1351 static struct ctl_table fs_table
[] = {
1353 .ctl_name
= FS_NRINODE
,
1354 .procname
= "inode-nr",
1355 .data
= &inodes_stat
,
1356 .maxlen
= 2*sizeof(int),
1358 .proc_handler
= &proc_dointvec
,
1361 .ctl_name
= FS_STATINODE
,
1362 .procname
= "inode-state",
1363 .data
= &inodes_stat
,
1364 .maxlen
= 7*sizeof(int),
1366 .proc_handler
= &proc_dointvec
,
1369 .procname
= "file-nr",
1370 .data
= &files_stat
,
1371 .maxlen
= 3*sizeof(int),
1373 .proc_handler
= &proc_nr_files
,
1376 .ctl_name
= FS_MAXFILE
,
1377 .procname
= "file-max",
1378 .data
= &files_stat
.max_files
,
1379 .maxlen
= sizeof(int),
1381 .proc_handler
= &proc_dointvec
,
1384 .ctl_name
= CTL_UNNUMBERED
,
1385 .procname
= "nr_open",
1386 .data
= &sysctl_nr_open
,
1387 .maxlen
= sizeof(int),
1389 .proc_handler
= &proc_dointvec_minmax
,
1390 .extra1
= &sysctl_nr_open_min
,
1391 .extra2
= &sysctl_nr_open_max
,
1394 .ctl_name
= FS_DENTRY
,
1395 .procname
= "dentry-state",
1396 .data
= &dentry_stat
,
1397 .maxlen
= 6*sizeof(int),
1399 .proc_handler
= &proc_dointvec
,
1402 .ctl_name
= FS_OVERFLOWUID
,
1403 .procname
= "overflowuid",
1404 .data
= &fs_overflowuid
,
1405 .maxlen
= sizeof(int),
1407 .proc_handler
= &proc_dointvec_minmax
,
1408 .strategy
= &sysctl_intvec
,
1409 .extra1
= &minolduid
,
1410 .extra2
= &maxolduid
,
1413 .ctl_name
= FS_OVERFLOWGID
,
1414 .procname
= "overflowgid",
1415 .data
= &fs_overflowgid
,
1416 .maxlen
= sizeof(int),
1418 .proc_handler
= &proc_dointvec_minmax
,
1419 .strategy
= &sysctl_intvec
,
1420 .extra1
= &minolduid
,
1421 .extra2
= &maxolduid
,
1423 #ifdef CONFIG_FILE_LOCKING
1425 .ctl_name
= FS_LEASES
,
1426 .procname
= "leases-enable",
1427 .data
= &leases_enable
,
1428 .maxlen
= sizeof(int),
1430 .proc_handler
= &proc_dointvec
,
1433 #ifdef CONFIG_DNOTIFY
1435 .ctl_name
= FS_DIR_NOTIFY
,
1436 .procname
= "dir-notify-enable",
1437 .data
= &dir_notify_enable
,
1438 .maxlen
= sizeof(int),
1440 .proc_handler
= &proc_dointvec
,
1444 #ifdef CONFIG_FILE_LOCKING
1446 .ctl_name
= FS_LEASE_TIME
,
1447 .procname
= "lease-break-time",
1448 .data
= &lease_break_time
,
1449 .maxlen
= sizeof(int),
1451 .proc_handler
= &proc_dointvec
,
1456 .procname
= "aio-nr",
1458 .maxlen
= sizeof(aio_nr
),
1460 .proc_handler
= &proc_doulongvec_minmax
,
1463 .procname
= "aio-max-nr",
1464 .data
= &aio_max_nr
,
1465 .maxlen
= sizeof(aio_max_nr
),
1467 .proc_handler
= &proc_doulongvec_minmax
,
1469 #endif /* CONFIG_AIO */
1470 #ifdef CONFIG_INOTIFY_USER
1472 .ctl_name
= FS_INOTIFY
,
1473 .procname
= "inotify",
1475 .child
= inotify_table
,
1480 .procname
= "epoll",
1482 .child
= epoll_table
,
1487 .ctl_name
= KERN_SETUID_DUMPABLE
,
1488 .procname
= "suid_dumpable",
1489 .data
= &suid_dumpable
,
1490 .maxlen
= sizeof(int),
1492 .proc_handler
= &proc_dointvec_minmax
,
1493 .strategy
= &sysctl_intvec
,
1497 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1499 .ctl_name
= CTL_UNNUMBERED
,
1500 .procname
= "binfmt_misc",
1502 .child
= binfmt_misc_table
,
1506 * NOTE: do not add new entries to this table unless you have read
1507 * Documentation/sysctl/ctl_unnumbered.txt
1512 static struct ctl_table debug_table
[] = {
1513 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1515 .ctl_name
= CTL_UNNUMBERED
,
1516 .procname
= "exception-trace",
1517 .data
= &show_unhandled_signals
,
1518 .maxlen
= sizeof(int),
1520 .proc_handler
= proc_dointvec
1526 static struct ctl_table dev_table
[] = {
1530 static DEFINE_SPINLOCK(sysctl_lock
);
1532 /* called under sysctl_lock */
1533 static int use_table(struct ctl_table_header
*p
)
1535 if (unlikely(p
->unregistering
))
1541 /* called under sysctl_lock */
1542 static void unuse_table(struct ctl_table_header
*p
)
1545 if (unlikely(p
->unregistering
))
1546 complete(p
->unregistering
);
1549 /* called under sysctl_lock, will reacquire if has to wait */
1550 static void start_unregistering(struct ctl_table_header
*p
)
1553 * if p->used is 0, nobody will ever touch that entry again;
1554 * we'll eliminate all paths to it before dropping sysctl_lock
1556 if (unlikely(p
->used
)) {
1557 struct completion wait
;
1558 init_completion(&wait
);
1559 p
->unregistering
= &wait
;
1560 spin_unlock(&sysctl_lock
);
1561 wait_for_completion(&wait
);
1562 spin_lock(&sysctl_lock
);
1564 /* anything non-NULL; we'll never dereference it */
1565 p
->unregistering
= ERR_PTR(-EINVAL
);
1568 * do not remove from the list until nobody holds it; walking the
1569 * list in do_sysctl() relies on that.
1571 list_del_init(&p
->ctl_entry
);
1574 void sysctl_head_get(struct ctl_table_header
*head
)
1576 spin_lock(&sysctl_lock
);
1578 spin_unlock(&sysctl_lock
);
1581 void sysctl_head_put(struct ctl_table_header
*head
)
1583 spin_lock(&sysctl_lock
);
1586 spin_unlock(&sysctl_lock
);
1589 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1593 spin_lock(&sysctl_lock
);
1594 if (!use_table(head
))
1595 head
= ERR_PTR(-ENOENT
);
1596 spin_unlock(&sysctl_lock
);
1600 void sysctl_head_finish(struct ctl_table_header
*head
)
1604 spin_lock(&sysctl_lock
);
1606 spin_unlock(&sysctl_lock
);
1609 static struct ctl_table_set
*
1610 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1612 struct ctl_table_set
*set
= &root
->default_set
;
1614 set
= root
->lookup(root
, namespaces
);
1618 static struct list_head
*
1619 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1621 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1625 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1626 struct ctl_table_header
*prev
)
1628 struct ctl_table_root
*root
;
1629 struct list_head
*header_list
;
1630 struct ctl_table_header
*head
;
1631 struct list_head
*tmp
;
1633 spin_lock(&sysctl_lock
);
1636 tmp
= &prev
->ctl_entry
;
1640 tmp
= &root_table_header
.ctl_entry
;
1642 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1644 if (!use_table(head
))
1646 spin_unlock(&sysctl_lock
);
1651 header_list
= lookup_header_list(root
, namespaces
);
1652 if (tmp
!= header_list
)
1656 root
= list_entry(root
->root_list
.next
,
1657 struct ctl_table_root
, root_list
);
1658 if (root
== &sysctl_table_root
)
1660 header_list
= lookup_header_list(root
, namespaces
);
1661 } while (list_empty(header_list
));
1662 tmp
= header_list
->next
;
1665 spin_unlock(&sysctl_lock
);
1669 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1671 return __sysctl_head_next(current
->nsproxy
, prev
);
1674 void register_sysctl_root(struct ctl_table_root
*root
)
1676 spin_lock(&sysctl_lock
);
1677 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1678 spin_unlock(&sysctl_lock
);
1681 #ifdef CONFIG_SYSCTL_SYSCALL
1682 /* Perform the actual read/write of a sysctl table entry. */
1683 static int do_sysctl_strategy(struct ctl_table_root
*root
,
1684 struct ctl_table
*table
,
1685 void __user
*oldval
, size_t __user
*oldlenp
,
1686 void __user
*newval
, size_t newlen
)
1694 if (sysctl_perm(root
, table
, op
))
1697 if (table
->strategy
) {
1698 rc
= table
->strategy(table
, oldval
, oldlenp
, newval
, newlen
);
1705 /* If there is no strategy routine, or if the strategy returns
1706 * zero, proceed with automatic r/w */
1707 if (table
->data
&& table
->maxlen
) {
1708 rc
= sysctl_data(table
, oldval
, oldlenp
, newval
, newlen
);
1715 static int parse_table(int __user
*name
, int nlen
,
1716 void __user
*oldval
, size_t __user
*oldlenp
,
1717 void __user
*newval
, size_t newlen
,
1718 struct ctl_table_root
*root
,
1719 struct ctl_table
*table
)
1725 if (get_user(n
, name
))
1727 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1728 if (!table
->ctl_name
)
1730 if (n
== table
->ctl_name
) {
1733 if (sysctl_perm(root
, table
, MAY_EXEC
))
1737 table
= table
->child
;
1740 error
= do_sysctl_strategy(root
, table
,
1749 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1750 void __user
*newval
, size_t newlen
)
1752 struct ctl_table_header
*head
;
1753 int error
= -ENOTDIR
;
1755 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1759 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1763 for (head
= sysctl_head_next(NULL
); head
;
1764 head
= sysctl_head_next(head
)) {
1765 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1767 head
->root
, head
->ctl_table
);
1768 if (error
!= -ENOTDIR
) {
1769 sysctl_head_finish(head
);
1776 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
1778 struct __sysctl_args tmp
;
1781 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1784 error
= deprecated_sysctl_warning(&tmp
);
1789 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1790 tmp
.newval
, tmp
.newlen
);
1795 #endif /* CONFIG_SYSCTL_SYSCALL */
1798 * sysctl_perm does NOT grant the superuser all rights automatically, because
1799 * some sysctl variables are readonly even to root.
1802 static int test_perm(int mode
, int op
)
1804 if (!current_euid())
1806 else if (in_egroup_p(0))
1808 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1813 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1818 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1822 if (root
->permissions
)
1823 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1827 return test_perm(mode
, op
);
1830 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1832 for (; table
->ctl_name
|| table
->procname
; table
++) {
1833 table
->parent
= parent
;
1835 sysctl_set_parent(table
, table
->child
);
1839 static __init
int sysctl_init(void)
1841 sysctl_set_parent(NULL
, root_table
);
1842 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1845 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1851 core_initcall(sysctl_init
);
1853 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1854 struct ctl_table
*table
)
1856 struct ctl_table
*p
;
1857 const char *s
= branch
->procname
;
1859 /* branch should have named subdirectory as its first element */
1860 if (!s
|| !branch
->child
)
1863 /* ... and nothing else */
1864 if (branch
[1].procname
|| branch
[1].ctl_name
)
1867 /* table should contain subdirectory with the same name */
1868 for (p
= table
; p
->procname
|| p
->ctl_name
; p
++) {
1871 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1877 /* see if attaching q to p would be an improvement */
1878 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1880 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1881 struct ctl_table
*next
;
1883 int not_in_parent
= !p
->attached_by
;
1885 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1886 if (by
== q
->attached_by
)
1888 if (to
== p
->attached_by
)
1894 if (is_better
&& not_in_parent
) {
1895 q
->attached_by
= by
;
1896 q
->attached_to
= to
;
1902 * __register_sysctl_paths - register a sysctl hierarchy
1903 * @root: List of sysctl headers to register on
1904 * @namespaces: Data to compute which lists of sysctl entries are visible
1905 * @path: The path to the directory the sysctl table is in.
1906 * @table: the top-level table structure
1908 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1909 * array. A completely 0 filled entry terminates the table.
1911 * The members of the &struct ctl_table structure are used as follows:
1913 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1914 * must be unique within that level of sysctl
1916 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1917 * enter a sysctl file
1919 * data - a pointer to data for use by proc_handler
1921 * maxlen - the maximum size in bytes of the data
1923 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1925 * child - a pointer to the child sysctl table if this entry is a directory, or
1928 * proc_handler - the text handler routine (described below)
1930 * strategy - the strategy routine (described below)
1932 * de - for internal use by the sysctl routines
1934 * extra1, extra2 - extra pointers usable by the proc handler routines
1936 * Leaf nodes in the sysctl tree will be represented by a single file
1937 * under /proc; non-leaf nodes will be represented by directories.
1939 * sysctl(2) can automatically manage read and write requests through
1940 * the sysctl table. The data and maxlen fields of the ctl_table
1941 * struct enable minimal validation of the values being written to be
1942 * performed, and the mode field allows minimal authentication.
1944 * More sophisticated management can be enabled by the provision of a
1945 * strategy routine with the table entry. This will be called before
1946 * any automatic read or write of the data is performed.
1948 * The strategy routine may return
1950 * < 0 - Error occurred (error is passed to user process)
1952 * 0 - OK - proceed with automatic read or write.
1954 * > 0 - OK - read or write has been done by the strategy routine, so
1955 * return immediately.
1957 * There must be a proc_handler routine for any terminal nodes
1958 * mirrored under /proc/sys (non-terminals are handled by a built-in
1959 * directory handler). Several default handlers are available to
1960 * cover common cases -
1962 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1963 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1964 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1966 * It is the handler's job to read the input buffer from user memory
1967 * and process it. The handler should return 0 on success.
1969 * This routine returns %NULL on a failure to register, and a pointer
1970 * to the table header on success.
1972 struct ctl_table_header
*__register_sysctl_paths(
1973 struct ctl_table_root
*root
,
1974 struct nsproxy
*namespaces
,
1975 const struct ctl_path
*path
, struct ctl_table
*table
)
1977 struct ctl_table_header
*header
;
1978 struct ctl_table
*new, **prevp
;
1979 unsigned int n
, npath
;
1980 struct ctl_table_set
*set
;
1982 /* Count the path components */
1983 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
1987 * For each path component, allocate a 2-element ctl_table array.
1988 * The first array element will be filled with the sysctl entry
1989 * for this, the second will be the sentinel (ctl_name == 0).
1991 * We allocate everything in one go so that we don't have to
1992 * worry about freeing additional memory in unregister_sysctl_table.
1994 header
= kzalloc(sizeof(struct ctl_table_header
) +
1995 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1999 new = (struct ctl_table
*) (header
+ 1);
2001 /* Now connect the dots */
2002 prevp
= &header
->ctl_table
;
2003 for (n
= 0; n
< npath
; ++n
, ++path
) {
2004 /* Copy the procname */
2005 new->procname
= path
->procname
;
2006 new->ctl_name
= path
->ctl_name
;
2010 prevp
= &new->child
;
2015 header
->ctl_table_arg
= table
;
2017 INIT_LIST_HEAD(&header
->ctl_entry
);
2019 header
->unregistering
= NULL
;
2020 header
->root
= root
;
2021 sysctl_set_parent(NULL
, header
->ctl_table
);
2023 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
2024 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
2029 spin_lock(&sysctl_lock
);
2030 header
->set
= lookup_header_set(root
, namespaces
);
2031 header
->attached_by
= header
->ctl_table
;
2032 header
->attached_to
= root_table
;
2033 header
->parent
= &root_table_header
;
2034 for (set
= header
->set
; set
; set
= set
->parent
) {
2035 struct ctl_table_header
*p
;
2036 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
2037 if (p
->unregistering
)
2039 try_attach(p
, header
);
2042 header
->parent
->count
++;
2043 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
2044 spin_unlock(&sysctl_lock
);
2050 * register_sysctl_table_path - register a sysctl table hierarchy
2051 * @path: The path to the directory the sysctl table is in.
2052 * @table: the top-level table structure
2054 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2055 * array. A completely 0 filled entry terminates the table.
2057 * See __register_sysctl_paths for more details.
2059 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2060 struct ctl_table
*table
)
2062 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
2067 * register_sysctl_table - register a sysctl table hierarchy
2068 * @table: the top-level table structure
2070 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2071 * array. A completely 0 filled entry terminates the table.
2073 * See register_sysctl_paths for more details.
2075 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
2077 static const struct ctl_path null_path
[] = { {} };
2079 return register_sysctl_paths(null_path
, table
);
2083 * unregister_sysctl_table - unregister a sysctl table hierarchy
2084 * @header: the header returned from register_sysctl_table
2086 * Unregisters the sysctl table and all children. proc entries may not
2087 * actually be removed until they are no longer used by anyone.
2089 void unregister_sysctl_table(struct ctl_table_header
* header
)
2096 spin_lock(&sysctl_lock
);
2097 start_unregistering(header
);
2098 if (!--header
->parent
->count
) {
2100 kfree(header
->parent
);
2102 if (!--header
->count
)
2104 spin_unlock(&sysctl_lock
);
2107 int sysctl_is_seen(struct ctl_table_header
*p
)
2109 struct ctl_table_set
*set
= p
->set
;
2111 spin_lock(&sysctl_lock
);
2112 if (p
->unregistering
)
2114 else if (!set
->is_seen
)
2117 res
= set
->is_seen(set
);
2118 spin_unlock(&sysctl_lock
);
2122 void setup_sysctl_set(struct ctl_table_set
*p
,
2123 struct ctl_table_set
*parent
,
2124 int (*is_seen
)(struct ctl_table_set
*))
2126 INIT_LIST_HEAD(&p
->list
);
2127 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
2128 p
->is_seen
= is_seen
;
2131 #else /* !CONFIG_SYSCTL */
2132 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
2137 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2138 struct ctl_table
*table
)
2143 void unregister_sysctl_table(struct ctl_table_header
* table
)
2147 void setup_sysctl_set(struct ctl_table_set
*p
,
2148 struct ctl_table_set
*parent
,
2149 int (*is_seen
)(struct ctl_table_set
*))
2153 void sysctl_head_put(struct ctl_table_header
*head
)
2157 #endif /* CONFIG_SYSCTL */
2163 #ifdef CONFIG_PROC_SYSCTL
2165 static int _proc_do_string(void* data
, int maxlen
, int write
,
2166 struct file
*filp
, void __user
*buffer
,
2167 size_t *lenp
, loff_t
*ppos
)
2173 if (!data
|| !maxlen
|| !*lenp
) {
2181 while (len
< *lenp
) {
2182 if (get_user(c
, p
++))
2184 if (c
== 0 || c
== '\n')
2190 if(copy_from_user(data
, buffer
, len
))
2192 ((char *) data
)[len
] = 0;
2210 if(copy_to_user(buffer
, data
, len
))
2213 if(put_user('\n', ((char __user
*) buffer
) + len
))
2224 * proc_dostring - read a string sysctl
2225 * @table: the sysctl table
2226 * @write: %TRUE if this is a write to the sysctl file
2227 * @filp: the file structure
2228 * @buffer: the user buffer
2229 * @lenp: the size of the user buffer
2230 * @ppos: file position
2232 * Reads/writes a string from/to the user buffer. If the kernel
2233 * buffer provided is not large enough to hold the string, the
2234 * string is truncated. The copied string is %NULL-terminated.
2235 * If the string is being read by the user process, it is copied
2236 * and a newline '\n' is added. It is truncated if the buffer is
2239 * Returns 0 on success.
2241 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2242 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2244 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
2245 buffer
, lenp
, ppos
);
2249 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
2251 int write
, void *data
)
2254 *valp
= *negp
? -*lvalp
: *lvalp
;
2259 *lvalp
= (unsigned long)-val
;
2262 *lvalp
= (unsigned long)val
;
2268 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2269 int write
, struct file
*filp
, void __user
*buffer
,
2270 size_t *lenp
, loff_t
*ppos
,
2271 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2272 int write
, void *data
),
2275 #define TMPBUFLEN 21
2276 int *i
, vleft
, first
=1, neg
, val
;
2280 char buf
[TMPBUFLEN
], *p
;
2281 char __user
*s
= buffer
;
2283 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
2284 (*ppos
&& !write
)) {
2289 i
= (int *) tbl_data
;
2290 vleft
= table
->maxlen
/ sizeof(*i
);
2294 conv
= do_proc_dointvec_conv
;
2296 for (; left
&& vleft
--; i
++, first
=0) {
2311 if (len
> sizeof(buf
) - 1)
2312 len
= sizeof(buf
) - 1;
2313 if (copy_from_user(buf
, s
, len
))
2317 if (*p
== '-' && left
> 1) {
2321 if (*p
< '0' || *p
> '9')
2324 lval
= simple_strtoul(p
, &p
, 0);
2327 if ((len
< left
) && *p
&& !isspace(*p
))
2334 if (conv(&neg
, &lval
, i
, 1, data
))
2341 if (conv(&neg
, &lval
, i
, 0, data
))
2344 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2348 if(copy_to_user(s
, buf
, len
))
2355 if (!write
&& !first
&& left
) {
2356 if(put_user('\n', s
))
2363 if (get_user(c
, s
++))
2378 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2379 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2380 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2381 int write
, void *data
),
2384 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2385 buffer
, lenp
, ppos
, conv
, data
);
2389 * proc_dointvec - read a vector of integers
2390 * @table: the sysctl table
2391 * @write: %TRUE if this is a write to the sysctl file
2392 * @filp: the file structure
2393 * @buffer: the user buffer
2394 * @lenp: the size of the user buffer
2395 * @ppos: file position
2397 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2398 * values from/to the user buffer, treated as an ASCII string.
2400 * Returns 0 on success.
2402 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2403 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2405 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2410 * Taint values can only be increased
2411 * This means we can safely use a temporary.
2413 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2414 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2417 unsigned long tmptaint
= get_taint();
2420 if (write
&& !capable(CAP_SYS_ADMIN
))
2425 err
= proc_doulongvec_minmax(&t
, write
, filp
, buffer
, lenp
, ppos
);
2431 * Poor man's atomic or. Not worth adding a primitive
2432 * to everyone's atomic.h for this
2435 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2436 if ((tmptaint
>> i
) & 1)
2444 struct do_proc_dointvec_minmax_conv_param
{
2449 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2451 int write
, void *data
)
2453 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2455 int val
= *negp
? -*lvalp
: *lvalp
;
2456 if ((param
->min
&& *param
->min
> val
) ||
2457 (param
->max
&& *param
->max
< val
))
2464 *lvalp
= (unsigned long)-val
;
2467 *lvalp
= (unsigned long)val
;
2474 * proc_dointvec_minmax - read a vector of integers with min/max values
2475 * @table: the sysctl table
2476 * @write: %TRUE if this is a write to the sysctl file
2477 * @filp: the file structure
2478 * @buffer: the user buffer
2479 * @lenp: the size of the user buffer
2480 * @ppos: file position
2482 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2483 * values from/to the user buffer, treated as an ASCII string.
2485 * This routine will ensure the values are within the range specified by
2486 * table->extra1 (min) and table->extra2 (max).
2488 * Returns 0 on success.
2490 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2491 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2493 struct do_proc_dointvec_minmax_conv_param param
= {
2494 .min
= (int *) table
->extra1
,
2495 .max
= (int *) table
->extra2
,
2497 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2498 do_proc_dointvec_minmax_conv
, ¶m
);
2501 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2503 void __user
*buffer
,
2504 size_t *lenp
, loff_t
*ppos
,
2505 unsigned long convmul
,
2506 unsigned long convdiv
)
2508 #define TMPBUFLEN 21
2509 unsigned long *i
, *min
, *max
, val
;
2510 int vleft
, first
=1, neg
;
2512 char buf
[TMPBUFLEN
], *p
;
2513 char __user
*s
= buffer
;
2515 if (!data
|| !table
->maxlen
|| !*lenp
||
2516 (*ppos
&& !write
)) {
2521 i
= (unsigned long *) data
;
2522 min
= (unsigned long *) table
->extra1
;
2523 max
= (unsigned long *) table
->extra2
;
2524 vleft
= table
->maxlen
/ sizeof(unsigned long);
2527 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2542 if (len
> TMPBUFLEN
-1)
2544 if (copy_from_user(buf
, s
, len
))
2548 if (*p
== '-' && left
> 1) {
2552 if (*p
< '0' || *p
> '9')
2554 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2556 if ((len
< left
) && *p
&& !isspace(*p
))
2565 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2572 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2576 if(copy_to_user(s
, buf
, len
))
2583 if (!write
&& !first
&& left
) {
2584 if(put_user('\n', s
))
2591 if (get_user(c
, s
++))
2606 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2608 void __user
*buffer
,
2609 size_t *lenp
, loff_t
*ppos
,
2610 unsigned long convmul
,
2611 unsigned long convdiv
)
2613 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2614 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2618 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2619 * @table: the sysctl table
2620 * @write: %TRUE if this is a write to the sysctl file
2621 * @filp: the file structure
2622 * @buffer: the user buffer
2623 * @lenp: the size of the user buffer
2624 * @ppos: file position
2626 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2627 * values from/to the user buffer, treated as an ASCII string.
2629 * This routine will ensure the values are within the range specified by
2630 * table->extra1 (min) and table->extra2 (max).
2632 * Returns 0 on success.
2634 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2635 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2637 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2641 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2642 * @table: the sysctl table
2643 * @write: %TRUE if this is a write to the sysctl file
2644 * @filp: the file structure
2645 * @buffer: the user buffer
2646 * @lenp: the size of the user buffer
2647 * @ppos: file position
2649 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2650 * values from/to the user buffer, treated as an ASCII string. The values
2651 * are treated as milliseconds, and converted to jiffies when they are stored.
2653 * This routine will ensure the values are within the range specified by
2654 * table->extra1 (min) and table->extra2 (max).
2656 * Returns 0 on success.
2658 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2660 void __user
*buffer
,
2661 size_t *lenp
, loff_t
*ppos
)
2663 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2664 lenp
, ppos
, HZ
, 1000l);
2668 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2670 int write
, void *data
)
2673 if (*lvalp
> LONG_MAX
/ HZ
)
2675 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2681 lval
= (unsigned long)-val
;
2684 lval
= (unsigned long)val
;
2691 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2693 int write
, void *data
)
2696 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2698 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2704 lval
= (unsigned long)-val
;
2707 lval
= (unsigned long)val
;
2709 *lvalp
= jiffies_to_clock_t(lval
);
2714 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2716 int write
, void *data
)
2719 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2725 lval
= (unsigned long)-val
;
2728 lval
= (unsigned long)val
;
2730 *lvalp
= jiffies_to_msecs(lval
);
2736 * proc_dointvec_jiffies - read a vector of integers as seconds
2737 * @table: the sysctl table
2738 * @write: %TRUE if this is a write to the sysctl file
2739 * @filp: the file structure
2740 * @buffer: the user buffer
2741 * @lenp: the size of the user buffer
2742 * @ppos: file position
2744 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2745 * values from/to the user buffer, treated as an ASCII string.
2746 * The values read are assumed to be in seconds, and are converted into
2749 * Returns 0 on success.
2751 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2752 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2754 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2755 do_proc_dointvec_jiffies_conv
,NULL
);
2759 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2760 * @table: the sysctl table
2761 * @write: %TRUE if this is a write to the sysctl file
2762 * @filp: the file structure
2763 * @buffer: the user buffer
2764 * @lenp: the size of the user buffer
2765 * @ppos: pointer to the file position
2767 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2768 * values from/to the user buffer, treated as an ASCII string.
2769 * The values read are assumed to be in 1/USER_HZ seconds, and
2770 * are converted into jiffies.
2772 * Returns 0 on success.
2774 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2775 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2777 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2778 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2782 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2783 * @table: the sysctl table
2784 * @write: %TRUE if this is a write to the sysctl file
2785 * @filp: the file structure
2786 * @buffer: the user buffer
2787 * @lenp: the size of the user buffer
2788 * @ppos: file position
2789 * @ppos: the current position in the file
2791 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2792 * values from/to the user buffer, treated as an ASCII string.
2793 * The values read are assumed to be in 1/1000 seconds, and
2794 * are converted into jiffies.
2796 * Returns 0 on success.
2798 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2799 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2801 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2802 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2805 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2806 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2808 struct pid
*new_pid
;
2812 tmp
= pid_vnr(cad_pid
);
2814 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2815 lenp
, ppos
, NULL
, NULL
);
2819 new_pid
= find_get_pid(tmp
);
2823 put_pid(xchg(&cad_pid
, new_pid
));
2827 #else /* CONFIG_PROC_FS */
2829 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2830 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2835 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2836 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2841 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2842 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2847 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2848 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2853 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2854 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2859 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2860 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2865 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2866 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2871 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2873 void __user
*buffer
,
2874 size_t *lenp
, loff_t
*ppos
)
2880 #endif /* CONFIG_PROC_FS */
2883 #ifdef CONFIG_SYSCTL_SYSCALL
2885 * General sysctl support routines
2888 /* The generic sysctl data routine (used if no strategy routine supplied) */
2889 int sysctl_data(struct ctl_table
*table
,
2890 void __user
*oldval
, size_t __user
*oldlenp
,
2891 void __user
*newval
, size_t newlen
)
2895 /* Get out of I don't have a variable */
2896 if (!table
->data
|| !table
->maxlen
)
2899 if (oldval
&& oldlenp
) {
2900 if (get_user(len
, oldlenp
))
2903 if (len
> table
->maxlen
)
2904 len
= table
->maxlen
;
2905 if (copy_to_user(oldval
, table
->data
, len
))
2907 if (put_user(len
, oldlenp
))
2912 if (newval
&& newlen
) {
2913 if (newlen
> table
->maxlen
)
2914 newlen
= table
->maxlen
;
2916 if (copy_from_user(table
->data
, newval
, newlen
))
2922 /* The generic string strategy routine: */
2923 int sysctl_string(struct ctl_table
*table
,
2924 void __user
*oldval
, size_t __user
*oldlenp
,
2925 void __user
*newval
, size_t newlen
)
2927 if (!table
->data
|| !table
->maxlen
)
2930 if (oldval
&& oldlenp
) {
2932 if (get_user(bufsize
, oldlenp
))
2935 size_t len
= strlen(table
->data
), copied
;
2937 /* This shouldn't trigger for a well-formed sysctl */
2938 if (len
> table
->maxlen
)
2939 len
= table
->maxlen
;
2941 /* Copy up to a max of bufsize-1 bytes of the string */
2942 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2944 if (copy_to_user(oldval
, table
->data
, copied
) ||
2945 put_user(0, (char __user
*)(oldval
+ copied
)))
2947 if (put_user(len
, oldlenp
))
2951 if (newval
&& newlen
) {
2952 size_t len
= newlen
;
2953 if (len
> table
->maxlen
)
2954 len
= table
->maxlen
;
2955 if(copy_from_user(table
->data
, newval
, len
))
2957 if (len
== table
->maxlen
)
2959 ((char *) table
->data
)[len
] = 0;
2965 * This function makes sure that all of the integers in the vector
2966 * are between the minimum and maximum values given in the arrays
2967 * table->extra1 and table->extra2, respectively.
2969 int sysctl_intvec(struct ctl_table
*table
,
2970 void __user
*oldval
, size_t __user
*oldlenp
,
2971 void __user
*newval
, size_t newlen
)
2974 if (newval
&& newlen
) {
2975 int __user
*vec
= (int __user
*) newval
;
2976 int *min
= (int *) table
->extra1
;
2977 int *max
= (int *) table
->extra2
;
2981 if (newlen
% sizeof(int) != 0)
2984 if (!table
->extra1
&& !table
->extra2
)
2987 if (newlen
> table
->maxlen
)
2988 newlen
= table
->maxlen
;
2989 length
= newlen
/ sizeof(int);
2991 for (i
= 0; i
< length
; i
++) {
2993 if (get_user(value
, vec
+ i
))
2995 if (min
&& value
< min
[i
])
2997 if (max
&& value
> max
[i
])
3004 /* Strategy function to convert jiffies to seconds */
3005 int sysctl_jiffies(struct ctl_table
*table
,
3006 void __user
*oldval
, size_t __user
*oldlenp
,
3007 void __user
*newval
, size_t newlen
)
3009 if (oldval
&& oldlenp
) {
3012 if (get_user(olen
, oldlenp
))
3017 if (olen
< sizeof(int))
3020 val
= *(int *)(table
->data
) / HZ
;
3021 if (put_user(val
, (int __user
*)oldval
))
3023 if (put_user(sizeof(int), oldlenp
))
3027 if (newval
&& newlen
) {
3029 if (newlen
!= sizeof(int))
3031 if (get_user(new, (int __user
*)newval
))
3033 *(int *)(table
->data
) = new*HZ
;
3038 /* Strategy function to convert jiffies to seconds */
3039 int sysctl_ms_jiffies(struct ctl_table
*table
,
3040 void __user
*oldval
, size_t __user
*oldlenp
,
3041 void __user
*newval
, size_t newlen
)
3043 if (oldval
&& oldlenp
) {
3046 if (get_user(olen
, oldlenp
))
3051 if (olen
< sizeof(int))
3054 val
= jiffies_to_msecs(*(int *)(table
->data
));
3055 if (put_user(val
, (int __user
*)oldval
))
3057 if (put_user(sizeof(int), oldlenp
))
3061 if (newval
&& newlen
) {
3063 if (newlen
!= sizeof(int))
3065 if (get_user(new, (int __user
*)newval
))
3067 *(int *)(table
->data
) = msecs_to_jiffies(new);
3074 #else /* CONFIG_SYSCTL_SYSCALL */
3077 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
3079 struct __sysctl_args tmp
;
3082 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
3085 error
= deprecated_sysctl_warning(&tmp
);
3087 /* If no error reading the parameters then just -ENOSYS ... */
3094 int sysctl_data(struct ctl_table
*table
,
3095 void __user
*oldval
, size_t __user
*oldlenp
,
3096 void __user
*newval
, size_t newlen
)
3101 int sysctl_string(struct ctl_table
*table
,
3102 void __user
*oldval
, size_t __user
*oldlenp
,
3103 void __user
*newval
, size_t newlen
)
3108 int sysctl_intvec(struct ctl_table
*table
,
3109 void __user
*oldval
, size_t __user
*oldlenp
,
3110 void __user
*newval
, size_t newlen
)
3115 int sysctl_jiffies(struct ctl_table
*table
,
3116 void __user
*oldval
, size_t __user
*oldlenp
,
3117 void __user
*newval
, size_t newlen
)
3122 int sysctl_ms_jiffies(struct ctl_table
*table
,
3123 void __user
*oldval
, size_t __user
*oldlenp
,
3124 void __user
*newval
, size_t newlen
)
3129 #endif /* CONFIG_SYSCTL_SYSCALL */
3131 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
3133 static int msg_count
;
3134 int name
[CTL_MAXNAME
];
3137 /* Check args->nlen. */
3138 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
3141 /* Read in the sysctl name for better debug message logging */
3142 for (i
= 0; i
< args
->nlen
; i
++)
3143 if (get_user(name
[i
], args
->name
+ i
))
3146 /* Ignore accesses to kernel.version */
3147 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
3150 if (msg_count
< 5) {
3153 "warning: process `%s' used the deprecated sysctl "
3154 "system call with ", current
->comm
);
3155 for (i
= 0; i
< args
->nlen
; i
++)
3156 printk("%d.", name
[i
]);
3163 * No sense putting this after each symbol definition, twice,
3164 * exception granted :-)
3166 EXPORT_SYMBOL(proc_dointvec
);
3167 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3168 EXPORT_SYMBOL(proc_dointvec_minmax
);
3169 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3170 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3171 EXPORT_SYMBOL(proc_dostring
);
3172 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3173 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
3174 EXPORT_SYMBOL(register_sysctl_table
);
3175 EXPORT_SYMBOL(register_sysctl_paths
);
3176 EXPORT_SYMBOL(sysctl_intvec
);
3177 EXPORT_SYMBOL(sysctl_jiffies
);
3178 EXPORT_SYMBOL(sysctl_ms_jiffies
);
3179 EXPORT_SYMBOL(sysctl_string
);
3180 EXPORT_SYMBOL(sysctl_data
);
3181 EXPORT_SYMBOL(unregister_sysctl_table
);