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/kmemcheck.h>
31 #include <linux/smp_lock.h>
33 #include <linux/init.h>
34 #include <linux/kernel.h>
35 #include <linux/kobject.h>
36 #include <linux/net.h>
37 #include <linux/sysrq.h>
38 #include <linux/highuid.h>
39 #include <linux/writeback.h>
40 #include <linux/hugetlb.h>
41 #include <linux/initrd.h>
42 #include <linux/key.h>
43 #include <linux/times.h>
44 #include <linux/limits.h>
45 #include <linux/dcache.h>
46 #include <linux/syscalls.h>
47 #include <linux/vmstat.h>
48 #include <linux/nfs_fs.h>
49 #include <linux/acpi.h>
50 #include <linux/reboot.h>
51 #include <linux/ftrace.h>
52 #include <linux/security.h>
53 #include <linux/slow-work.h>
54 #include <linux/perf_counter.h>
56 #include <asm/uaccess.h>
57 #include <asm/processor.h>
61 #include <asm/stacktrace.h>
65 static int deprecated_sysctl_warning(struct __sysctl_args
*args
);
67 #if defined(CONFIG_SYSCTL)
69 /* External variables not in a header file. */
71 extern int print_fatal_signals
;
72 extern int sysctl_overcommit_memory
;
73 extern int sysctl_overcommit_ratio
;
74 extern int sysctl_panic_on_oom
;
75 extern int sysctl_oom_kill_allocating_task
;
76 extern int sysctl_oom_dump_tasks
;
77 extern int max_threads
;
78 extern int core_uses_pid
;
79 extern int suid_dumpable
;
80 extern char core_pattern
[];
82 extern int min_free_kbytes
;
83 extern int pid_max_min
, pid_max_max
;
84 extern int sysctl_drop_caches
;
85 extern int percpu_pagelist_fraction
;
86 extern int compat_log
;
87 extern int latencytop_enabled
;
88 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
90 extern int sysctl_nr_trim_pages
;
92 #ifdef CONFIG_RCU_TORTURE_TEST
93 extern int rcutorture_runnable
;
94 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
96 /* Constants used for minimum and maximum */
97 #ifdef CONFIG_DETECT_SOFTLOCKUP
98 static int sixty
= 60;
99 static int neg_one
= -1;
103 static int __maybe_unused one
= 1;
104 static int __maybe_unused two
= 2;
105 static unsigned long one_ul
= 1;
106 static int one_hundred
= 100;
108 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
109 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
111 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
112 static int maxolduid
= 65535;
113 static int minolduid
;
114 static int min_percpu_pagelist_fract
= 8;
116 static int ngroups_max
= NGROUPS_MAX
;
118 #ifdef CONFIG_MODULES
119 extern char modprobe_path
[];
120 extern int modules_disabled
;
122 #ifdef CONFIG_CHR_DEV_SG
123 extern int sg_big_buff
;
127 #include <asm/system.h>
130 #ifdef CONFIG_SPARC64
131 extern int sysctl_tsb_ratio
;
135 extern int pwrsw_enabled
;
136 extern int unaligned_enabled
;
140 #ifdef CONFIG_MATHEMU
141 extern int sysctl_ieee_emulation_warnings
;
143 extern int sysctl_userprocess_debug
;
144 extern int spin_retry
;
147 #ifdef CONFIG_BSD_PROCESS_ACCT
148 extern int acct_parm
[];
152 extern int no_unaligned_warning
;
153 extern int unaligned_dump_stack
;
156 #ifdef CONFIG_RT_MUTEXES
157 extern int max_lock_depth
;
160 #ifdef CONFIG_PROC_SYSCTL
161 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
162 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
163 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
164 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
167 static struct ctl_table root_table
[];
168 static struct ctl_table_root sysctl_table_root
;
169 static struct ctl_table_header root_table_header
= {
171 .ctl_table
= root_table
,
172 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),
173 .root
= &sysctl_table_root
,
174 .set
= &sysctl_table_root
.default_set
,
176 static struct ctl_table_root sysctl_table_root
= {
177 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
178 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
181 static struct ctl_table kern_table
[];
182 static struct ctl_table vm_table
[];
183 static struct ctl_table fs_table
[];
184 static struct ctl_table debug_table
[];
185 static struct ctl_table dev_table
[];
186 extern struct ctl_table random_table
[];
187 #ifdef CONFIG_INOTIFY_USER
188 extern struct ctl_table inotify_table
[];
191 extern struct ctl_table epoll_table
[];
194 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
195 int sysctl_legacy_va_layout
;
198 extern int prove_locking
;
199 extern int lock_stat
;
201 /* The default sysctl tables: */
203 static struct ctl_table root_table
[] = {
205 .ctl_name
= CTL_KERN
,
206 .procname
= "kernel",
223 .ctl_name
= CTL_DEBUG
,
226 .child
= debug_table
,
235 * NOTE: do not add new entries to this table unless you have read
236 * Documentation/sysctl/ctl_unnumbered.txt
241 #ifdef CONFIG_SCHED_DEBUG
242 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
243 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
244 static int min_wakeup_granularity_ns
; /* 0 usecs */
245 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
248 static struct ctl_table kern_table
[] = {
249 #ifdef CONFIG_SCHED_DEBUG
251 .ctl_name
= CTL_UNNUMBERED
,
252 .procname
= "sched_min_granularity_ns",
253 .data
= &sysctl_sched_min_granularity
,
254 .maxlen
= sizeof(unsigned int),
256 .proc_handler
= &sched_nr_latency_handler
,
257 .strategy
= &sysctl_intvec
,
258 .extra1
= &min_sched_granularity_ns
,
259 .extra2
= &max_sched_granularity_ns
,
262 .ctl_name
= CTL_UNNUMBERED
,
263 .procname
= "sched_latency_ns",
264 .data
= &sysctl_sched_latency
,
265 .maxlen
= sizeof(unsigned int),
267 .proc_handler
= &sched_nr_latency_handler
,
268 .strategy
= &sysctl_intvec
,
269 .extra1
= &min_sched_granularity_ns
,
270 .extra2
= &max_sched_granularity_ns
,
273 .ctl_name
= CTL_UNNUMBERED
,
274 .procname
= "sched_wakeup_granularity_ns",
275 .data
= &sysctl_sched_wakeup_granularity
,
276 .maxlen
= sizeof(unsigned int),
278 .proc_handler
= &proc_dointvec_minmax
,
279 .strategy
= &sysctl_intvec
,
280 .extra1
= &min_wakeup_granularity_ns
,
281 .extra2
= &max_wakeup_granularity_ns
,
284 .ctl_name
= CTL_UNNUMBERED
,
285 .procname
= "sched_shares_ratelimit",
286 .data
= &sysctl_sched_shares_ratelimit
,
287 .maxlen
= sizeof(unsigned int),
289 .proc_handler
= &proc_dointvec
,
292 .ctl_name
= CTL_UNNUMBERED
,
293 .procname
= "sched_shares_thresh",
294 .data
= &sysctl_sched_shares_thresh
,
295 .maxlen
= sizeof(unsigned int),
297 .proc_handler
= &proc_dointvec_minmax
,
298 .strategy
= &sysctl_intvec
,
302 .ctl_name
= CTL_UNNUMBERED
,
303 .procname
= "sched_child_runs_first",
304 .data
= &sysctl_sched_child_runs_first
,
305 .maxlen
= sizeof(unsigned int),
307 .proc_handler
= &proc_dointvec
,
310 .ctl_name
= CTL_UNNUMBERED
,
311 .procname
= "sched_features",
312 .data
= &sysctl_sched_features
,
313 .maxlen
= sizeof(unsigned int),
315 .proc_handler
= &proc_dointvec
,
318 .ctl_name
= CTL_UNNUMBERED
,
319 .procname
= "sched_migration_cost",
320 .data
= &sysctl_sched_migration_cost
,
321 .maxlen
= sizeof(unsigned int),
323 .proc_handler
= &proc_dointvec
,
326 .ctl_name
= CTL_UNNUMBERED
,
327 .procname
= "sched_nr_migrate",
328 .data
= &sysctl_sched_nr_migrate
,
329 .maxlen
= sizeof(unsigned int),
331 .proc_handler
= &proc_dointvec
,
334 .ctl_name
= CTL_UNNUMBERED
,
335 .procname
= "timer_migration",
336 .data
= &sysctl_timer_migration
,
337 .maxlen
= sizeof(unsigned int),
339 .proc_handler
= &proc_dointvec_minmax
,
340 .strategy
= &sysctl_intvec
,
346 .ctl_name
= CTL_UNNUMBERED
,
347 .procname
= "sched_rt_period_us",
348 .data
= &sysctl_sched_rt_period
,
349 .maxlen
= sizeof(unsigned int),
351 .proc_handler
= &sched_rt_handler
,
354 .ctl_name
= CTL_UNNUMBERED
,
355 .procname
= "sched_rt_runtime_us",
356 .data
= &sysctl_sched_rt_runtime
,
357 .maxlen
= sizeof(int),
359 .proc_handler
= &sched_rt_handler
,
362 .ctl_name
= CTL_UNNUMBERED
,
363 .procname
= "sched_compat_yield",
364 .data
= &sysctl_sched_compat_yield
,
365 .maxlen
= sizeof(unsigned int),
367 .proc_handler
= &proc_dointvec
,
369 #ifdef CONFIG_PROVE_LOCKING
371 .ctl_name
= CTL_UNNUMBERED
,
372 .procname
= "prove_locking",
373 .data
= &prove_locking
,
374 .maxlen
= sizeof(int),
376 .proc_handler
= &proc_dointvec
,
379 #ifdef CONFIG_LOCK_STAT
381 .ctl_name
= CTL_UNNUMBERED
,
382 .procname
= "lock_stat",
384 .maxlen
= sizeof(int),
386 .proc_handler
= &proc_dointvec
,
390 .ctl_name
= KERN_PANIC
,
392 .data
= &panic_timeout
,
393 .maxlen
= sizeof(int),
395 .proc_handler
= &proc_dointvec
,
398 .ctl_name
= KERN_CORE_USES_PID
,
399 .procname
= "core_uses_pid",
400 .data
= &core_uses_pid
,
401 .maxlen
= sizeof(int),
403 .proc_handler
= &proc_dointvec
,
406 .ctl_name
= KERN_CORE_PATTERN
,
407 .procname
= "core_pattern",
408 .data
= core_pattern
,
409 .maxlen
= CORENAME_MAX_SIZE
,
411 .proc_handler
= &proc_dostring
,
412 .strategy
= &sysctl_string
,
414 #ifdef CONFIG_PROC_SYSCTL
416 .procname
= "tainted",
417 .maxlen
= sizeof(long),
419 .proc_handler
= &proc_taint
,
422 #ifdef CONFIG_LATENCYTOP
424 .procname
= "latencytop",
425 .data
= &latencytop_enabled
,
426 .maxlen
= sizeof(int),
428 .proc_handler
= &proc_dointvec
,
431 #ifdef CONFIG_BLK_DEV_INITRD
433 .ctl_name
= KERN_REALROOTDEV
,
434 .procname
= "real-root-dev",
435 .data
= &real_root_dev
,
436 .maxlen
= sizeof(int),
438 .proc_handler
= &proc_dointvec
,
442 .ctl_name
= CTL_UNNUMBERED
,
443 .procname
= "print-fatal-signals",
444 .data
= &print_fatal_signals
,
445 .maxlen
= sizeof(int),
447 .proc_handler
= &proc_dointvec
,
451 .ctl_name
= KERN_SPARC_REBOOT
,
452 .procname
= "reboot-cmd",
453 .data
= reboot_command
,
456 .proc_handler
= &proc_dostring
,
457 .strategy
= &sysctl_string
,
460 .ctl_name
= KERN_SPARC_STOP_A
,
461 .procname
= "stop-a",
462 .data
= &stop_a_enabled
,
463 .maxlen
= sizeof (int),
465 .proc_handler
= &proc_dointvec
,
468 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
469 .procname
= "scons-poweroff",
470 .data
= &scons_pwroff
,
471 .maxlen
= sizeof (int),
473 .proc_handler
= &proc_dointvec
,
476 #ifdef CONFIG_SPARC64
478 .ctl_name
= CTL_UNNUMBERED
,
479 .procname
= "tsb-ratio",
480 .data
= &sysctl_tsb_ratio
,
481 .maxlen
= sizeof (int),
483 .proc_handler
= &proc_dointvec
,
488 .ctl_name
= KERN_HPPA_PWRSW
,
489 .procname
= "soft-power",
490 .data
= &pwrsw_enabled
,
491 .maxlen
= sizeof (int),
493 .proc_handler
= &proc_dointvec
,
496 .ctl_name
= KERN_HPPA_UNALIGNED
,
497 .procname
= "unaligned-trap",
498 .data
= &unaligned_enabled
,
499 .maxlen
= sizeof (int),
501 .proc_handler
= &proc_dointvec
,
505 .ctl_name
= KERN_CTLALTDEL
,
506 .procname
= "ctrl-alt-del",
508 .maxlen
= sizeof(int),
510 .proc_handler
= &proc_dointvec
,
512 #ifdef CONFIG_FUNCTION_TRACER
514 .ctl_name
= CTL_UNNUMBERED
,
515 .procname
= "ftrace_enabled",
516 .data
= &ftrace_enabled
,
517 .maxlen
= sizeof(int),
519 .proc_handler
= &ftrace_enable_sysctl
,
522 #ifdef CONFIG_STACK_TRACER
524 .ctl_name
= CTL_UNNUMBERED
,
525 .procname
= "stack_tracer_enabled",
526 .data
= &stack_tracer_enabled
,
527 .maxlen
= sizeof(int),
529 .proc_handler
= &stack_trace_sysctl
,
532 #ifdef CONFIG_TRACING
534 .ctl_name
= CTL_UNNUMBERED
,
535 .procname
= "ftrace_dump_on_oops",
536 .data
= &ftrace_dump_on_oops
,
537 .maxlen
= sizeof(int),
539 .proc_handler
= &proc_dointvec
,
542 #ifdef CONFIG_MODULES
544 .ctl_name
= KERN_MODPROBE
,
545 .procname
= "modprobe",
546 .data
= &modprobe_path
,
547 .maxlen
= KMOD_PATH_LEN
,
549 .proc_handler
= &proc_dostring
,
550 .strategy
= &sysctl_string
,
553 .ctl_name
= CTL_UNNUMBERED
,
554 .procname
= "modules_disabled",
555 .data
= &modules_disabled
,
556 .maxlen
= sizeof(int),
558 /* only handle a transition from default "0" to "1" */
559 .proc_handler
= &proc_dointvec_minmax
,
564 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
566 .ctl_name
= KERN_HOTPLUG
,
567 .procname
= "hotplug",
568 .data
= &uevent_helper
,
569 .maxlen
= UEVENT_HELPER_PATH_LEN
,
571 .proc_handler
= &proc_dostring
,
572 .strategy
= &sysctl_string
,
575 #ifdef CONFIG_CHR_DEV_SG
577 .ctl_name
= KERN_SG_BIG_BUFF
,
578 .procname
= "sg-big-buff",
579 .data
= &sg_big_buff
,
580 .maxlen
= sizeof (int),
582 .proc_handler
= &proc_dointvec
,
585 #ifdef CONFIG_BSD_PROCESS_ACCT
587 .ctl_name
= KERN_ACCT
,
590 .maxlen
= 3*sizeof(int),
592 .proc_handler
= &proc_dointvec
,
595 #ifdef CONFIG_MAGIC_SYSRQ
597 .ctl_name
= KERN_SYSRQ
,
599 .data
= &__sysrq_enabled
,
600 .maxlen
= sizeof (int),
602 .proc_handler
= &proc_dointvec
,
605 #ifdef CONFIG_PROC_SYSCTL
607 .procname
= "cad_pid",
609 .maxlen
= sizeof (int),
611 .proc_handler
= &proc_do_cad_pid
,
615 .ctl_name
= KERN_MAX_THREADS
,
616 .procname
= "threads-max",
617 .data
= &max_threads
,
618 .maxlen
= sizeof(int),
620 .proc_handler
= &proc_dointvec
,
623 .ctl_name
= KERN_RANDOM
,
624 .procname
= "random",
626 .child
= random_table
,
629 .ctl_name
= KERN_OVERFLOWUID
,
630 .procname
= "overflowuid",
631 .data
= &overflowuid
,
632 .maxlen
= sizeof(int),
634 .proc_handler
= &proc_dointvec_minmax
,
635 .strategy
= &sysctl_intvec
,
636 .extra1
= &minolduid
,
637 .extra2
= &maxolduid
,
640 .ctl_name
= KERN_OVERFLOWGID
,
641 .procname
= "overflowgid",
642 .data
= &overflowgid
,
643 .maxlen
= sizeof(int),
645 .proc_handler
= &proc_dointvec_minmax
,
646 .strategy
= &sysctl_intvec
,
647 .extra1
= &minolduid
,
648 .extra2
= &maxolduid
,
651 #ifdef CONFIG_MATHEMU
653 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
654 .procname
= "ieee_emulation_warnings",
655 .data
= &sysctl_ieee_emulation_warnings
,
656 .maxlen
= sizeof(int),
658 .proc_handler
= &proc_dointvec
,
662 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
663 .procname
= "userprocess_debug",
664 .data
= &sysctl_userprocess_debug
,
665 .maxlen
= sizeof(int),
667 .proc_handler
= &proc_dointvec
,
671 .ctl_name
= KERN_PIDMAX
,
672 .procname
= "pid_max",
674 .maxlen
= sizeof (int),
676 .proc_handler
= &proc_dointvec_minmax
,
677 .strategy
= sysctl_intvec
,
678 .extra1
= &pid_max_min
,
679 .extra2
= &pid_max_max
,
682 .ctl_name
= KERN_PANIC_ON_OOPS
,
683 .procname
= "panic_on_oops",
684 .data
= &panic_on_oops
,
685 .maxlen
= sizeof(int),
687 .proc_handler
= &proc_dointvec
,
689 #if defined CONFIG_PRINTK
691 .ctl_name
= KERN_PRINTK
,
692 .procname
= "printk",
693 .data
= &console_loglevel
,
694 .maxlen
= 4*sizeof(int),
696 .proc_handler
= &proc_dointvec
,
699 .ctl_name
= KERN_PRINTK_RATELIMIT
,
700 .procname
= "printk_ratelimit",
701 .data
= &printk_ratelimit_state
.interval
,
702 .maxlen
= sizeof(int),
704 .proc_handler
= &proc_dointvec_jiffies
,
705 .strategy
= &sysctl_jiffies
,
708 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
709 .procname
= "printk_ratelimit_burst",
710 .data
= &printk_ratelimit_state
.burst
,
711 .maxlen
= sizeof(int),
713 .proc_handler
= &proc_dointvec
,
717 .ctl_name
= KERN_NGROUPS_MAX
,
718 .procname
= "ngroups_max",
719 .data
= &ngroups_max
,
720 .maxlen
= sizeof (int),
722 .proc_handler
= &proc_dointvec
,
724 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
726 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
727 .procname
= "unknown_nmi_panic",
728 .data
= &unknown_nmi_panic
,
729 .maxlen
= sizeof (int),
731 .proc_handler
= &proc_dointvec
,
734 .procname
= "nmi_watchdog",
735 .data
= &nmi_watchdog_enabled
,
736 .maxlen
= sizeof (int),
738 .proc_handler
= &proc_nmi_enabled
,
741 #if defined(CONFIG_X86)
743 .ctl_name
= KERN_PANIC_ON_NMI
,
744 .procname
= "panic_on_unrecovered_nmi",
745 .data
= &panic_on_unrecovered_nmi
,
746 .maxlen
= sizeof(int),
748 .proc_handler
= &proc_dointvec
,
751 .ctl_name
= CTL_UNNUMBERED
,
752 .procname
= "panic_on_io_nmi",
753 .data
= &panic_on_io_nmi
,
754 .maxlen
= sizeof(int),
756 .proc_handler
= &proc_dointvec
,
759 .ctl_name
= KERN_BOOTLOADER_TYPE
,
760 .procname
= "bootloader_type",
761 .data
= &bootloader_type
,
762 .maxlen
= sizeof (int),
764 .proc_handler
= &proc_dointvec
,
767 .ctl_name
= CTL_UNNUMBERED
,
768 .procname
= "bootloader_version",
769 .data
= &bootloader_version
,
770 .maxlen
= sizeof (int),
772 .proc_handler
= &proc_dointvec
,
775 .ctl_name
= CTL_UNNUMBERED
,
776 .procname
= "kstack_depth_to_print",
777 .data
= &kstack_depth_to_print
,
778 .maxlen
= sizeof(int),
780 .proc_handler
= &proc_dointvec
,
783 .ctl_name
= CTL_UNNUMBERED
,
784 .procname
= "io_delay_type",
785 .data
= &io_delay_type
,
786 .maxlen
= sizeof(int),
788 .proc_handler
= &proc_dointvec
,
791 #if defined(CONFIG_MMU)
793 .ctl_name
= KERN_RANDOMIZE
,
794 .procname
= "randomize_va_space",
795 .data
= &randomize_va_space
,
796 .maxlen
= sizeof(int),
798 .proc_handler
= &proc_dointvec
,
801 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
803 .ctl_name
= KERN_SPIN_RETRY
,
804 .procname
= "spin_retry",
806 .maxlen
= sizeof (int),
808 .proc_handler
= &proc_dointvec
,
811 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
813 .procname
= "acpi_video_flags",
814 .data
= &acpi_realmode_flags
,
815 .maxlen
= sizeof (unsigned long),
817 .proc_handler
= &proc_doulongvec_minmax
,
822 .ctl_name
= KERN_IA64_UNALIGNED
,
823 .procname
= "ignore-unaligned-usertrap",
824 .data
= &no_unaligned_warning
,
825 .maxlen
= sizeof (int),
827 .proc_handler
= &proc_dointvec
,
830 .ctl_name
= CTL_UNNUMBERED
,
831 .procname
= "unaligned-dump-stack",
832 .data
= &unaligned_dump_stack
,
833 .maxlen
= sizeof (int),
835 .proc_handler
= &proc_dointvec
,
838 #ifdef CONFIG_DETECT_SOFTLOCKUP
840 .ctl_name
= CTL_UNNUMBERED
,
841 .procname
= "softlockup_panic",
842 .data
= &softlockup_panic
,
843 .maxlen
= sizeof(int),
845 .proc_handler
= &proc_dointvec_minmax
,
846 .strategy
= &sysctl_intvec
,
851 .ctl_name
= CTL_UNNUMBERED
,
852 .procname
= "softlockup_thresh",
853 .data
= &softlockup_thresh
,
854 .maxlen
= sizeof(int),
856 .proc_handler
= &proc_dosoftlockup_thresh
,
857 .strategy
= &sysctl_intvec
,
862 #ifdef CONFIG_DETECT_HUNG_TASK
864 .ctl_name
= CTL_UNNUMBERED
,
865 .procname
= "hung_task_panic",
866 .data
= &sysctl_hung_task_panic
,
867 .maxlen
= sizeof(int),
869 .proc_handler
= &proc_dointvec_minmax
,
870 .strategy
= &sysctl_intvec
,
875 .ctl_name
= CTL_UNNUMBERED
,
876 .procname
= "hung_task_check_count",
877 .data
= &sysctl_hung_task_check_count
,
878 .maxlen
= sizeof(unsigned long),
880 .proc_handler
= &proc_doulongvec_minmax
,
881 .strategy
= &sysctl_intvec
,
884 .ctl_name
= CTL_UNNUMBERED
,
885 .procname
= "hung_task_timeout_secs",
886 .data
= &sysctl_hung_task_timeout_secs
,
887 .maxlen
= sizeof(unsigned long),
889 .proc_handler
= &proc_dohung_task_timeout_secs
,
890 .strategy
= &sysctl_intvec
,
893 .ctl_name
= CTL_UNNUMBERED
,
894 .procname
= "hung_task_warnings",
895 .data
= &sysctl_hung_task_warnings
,
896 .maxlen
= sizeof(unsigned long),
898 .proc_handler
= &proc_doulongvec_minmax
,
899 .strategy
= &sysctl_intvec
,
904 .ctl_name
= KERN_COMPAT_LOG
,
905 .procname
= "compat-log",
907 .maxlen
= sizeof (int),
909 .proc_handler
= &proc_dointvec
,
912 #ifdef CONFIG_RT_MUTEXES
914 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
915 .procname
= "max_lock_depth",
916 .data
= &max_lock_depth
,
917 .maxlen
= sizeof(int),
919 .proc_handler
= &proc_dointvec
,
923 .ctl_name
= CTL_UNNUMBERED
,
924 .procname
= "poweroff_cmd",
925 .data
= &poweroff_cmd
,
926 .maxlen
= POWEROFF_CMD_PATH_LEN
,
928 .proc_handler
= &proc_dostring
,
929 .strategy
= &sysctl_string
,
933 .ctl_name
= CTL_UNNUMBERED
,
936 .child
= key_sysctls
,
939 #ifdef CONFIG_RCU_TORTURE_TEST
941 .ctl_name
= CTL_UNNUMBERED
,
942 .procname
= "rcutorture_runnable",
943 .data
= &rcutorture_runnable
,
944 .maxlen
= sizeof(int),
946 .proc_handler
= &proc_dointvec
,
949 #ifdef CONFIG_SLOW_WORK
951 .ctl_name
= CTL_UNNUMBERED
,
952 .procname
= "slow-work",
954 .child
= slow_work_sysctls
,
957 #ifdef CONFIG_PERF_COUNTERS
959 .ctl_name
= CTL_UNNUMBERED
,
960 .procname
= "perf_counter_paranoid",
961 .data
= &sysctl_perf_counter_paranoid
,
962 .maxlen
= sizeof(sysctl_perf_counter_paranoid
),
964 .proc_handler
= &proc_dointvec
,
967 .ctl_name
= CTL_UNNUMBERED
,
968 .procname
= "perf_counter_mlock_kb",
969 .data
= &sysctl_perf_counter_mlock
,
970 .maxlen
= sizeof(sysctl_perf_counter_mlock
),
972 .proc_handler
= &proc_dointvec
,
975 .ctl_name
= CTL_UNNUMBERED
,
976 .procname
= "perf_counter_max_sample_rate",
977 .data
= &sysctl_perf_counter_sample_rate
,
978 .maxlen
= sizeof(sysctl_perf_counter_sample_rate
),
980 .proc_handler
= &proc_dointvec
,
983 #ifdef CONFIG_KMEMCHECK
985 .ctl_name
= CTL_UNNUMBERED
,
986 .procname
= "kmemcheck",
987 .data
= &kmemcheck_enabled
,
988 .maxlen
= sizeof(int),
990 .proc_handler
= &proc_dointvec
,
995 * NOTE: do not add new entries to this table unless you have read
996 * Documentation/sysctl/ctl_unnumbered.txt
1001 static struct ctl_table vm_table
[] = {
1003 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
1004 .procname
= "overcommit_memory",
1005 .data
= &sysctl_overcommit_memory
,
1006 .maxlen
= sizeof(sysctl_overcommit_memory
),
1008 .proc_handler
= &proc_dointvec
,
1011 .ctl_name
= VM_PANIC_ON_OOM
,
1012 .procname
= "panic_on_oom",
1013 .data
= &sysctl_panic_on_oom
,
1014 .maxlen
= sizeof(sysctl_panic_on_oom
),
1016 .proc_handler
= &proc_dointvec
,
1019 .ctl_name
= CTL_UNNUMBERED
,
1020 .procname
= "oom_kill_allocating_task",
1021 .data
= &sysctl_oom_kill_allocating_task
,
1022 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1024 .proc_handler
= &proc_dointvec
,
1027 .ctl_name
= CTL_UNNUMBERED
,
1028 .procname
= "oom_dump_tasks",
1029 .data
= &sysctl_oom_dump_tasks
,
1030 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1032 .proc_handler
= &proc_dointvec
,
1035 .ctl_name
= VM_OVERCOMMIT_RATIO
,
1036 .procname
= "overcommit_ratio",
1037 .data
= &sysctl_overcommit_ratio
,
1038 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1040 .proc_handler
= &proc_dointvec
,
1043 .ctl_name
= VM_PAGE_CLUSTER
,
1044 .procname
= "page-cluster",
1045 .data
= &page_cluster
,
1046 .maxlen
= sizeof(int),
1048 .proc_handler
= &proc_dointvec
,
1051 .ctl_name
= VM_DIRTY_BACKGROUND
,
1052 .procname
= "dirty_background_ratio",
1053 .data
= &dirty_background_ratio
,
1054 .maxlen
= sizeof(dirty_background_ratio
),
1056 .proc_handler
= &dirty_background_ratio_handler
,
1057 .strategy
= &sysctl_intvec
,
1059 .extra2
= &one_hundred
,
1062 .ctl_name
= CTL_UNNUMBERED
,
1063 .procname
= "dirty_background_bytes",
1064 .data
= &dirty_background_bytes
,
1065 .maxlen
= sizeof(dirty_background_bytes
),
1067 .proc_handler
= &dirty_background_bytes_handler
,
1068 .strategy
= &sysctl_intvec
,
1072 .ctl_name
= VM_DIRTY_RATIO
,
1073 .procname
= "dirty_ratio",
1074 .data
= &vm_dirty_ratio
,
1075 .maxlen
= sizeof(vm_dirty_ratio
),
1077 .proc_handler
= &dirty_ratio_handler
,
1078 .strategy
= &sysctl_intvec
,
1080 .extra2
= &one_hundred
,
1083 .ctl_name
= CTL_UNNUMBERED
,
1084 .procname
= "dirty_bytes",
1085 .data
= &vm_dirty_bytes
,
1086 .maxlen
= sizeof(vm_dirty_bytes
),
1088 .proc_handler
= &dirty_bytes_handler
,
1089 .strategy
= &sysctl_intvec
,
1090 .extra1
= &dirty_bytes_min
,
1093 .procname
= "dirty_writeback_centisecs",
1094 .data
= &dirty_writeback_interval
,
1095 .maxlen
= sizeof(dirty_writeback_interval
),
1097 .proc_handler
= &dirty_writeback_centisecs_handler
,
1100 .procname
= "dirty_expire_centisecs",
1101 .data
= &dirty_expire_interval
,
1102 .maxlen
= sizeof(dirty_expire_interval
),
1104 .proc_handler
= &proc_dointvec
,
1107 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
1108 .procname
= "nr_pdflush_threads",
1109 .data
= &nr_pdflush_threads
,
1110 .maxlen
= sizeof nr_pdflush_threads
,
1111 .mode
= 0444 /* read-only*/,
1112 .proc_handler
= &proc_dointvec
,
1115 .ctl_name
= VM_SWAPPINESS
,
1116 .procname
= "swappiness",
1117 .data
= &vm_swappiness
,
1118 .maxlen
= sizeof(vm_swappiness
),
1120 .proc_handler
= &proc_dointvec_minmax
,
1121 .strategy
= &sysctl_intvec
,
1123 .extra2
= &one_hundred
,
1125 #ifdef CONFIG_HUGETLB_PAGE
1127 .procname
= "nr_hugepages",
1129 .maxlen
= sizeof(unsigned long),
1131 .proc_handler
= &hugetlb_sysctl_handler
,
1132 .extra1
= (void *)&hugetlb_zero
,
1133 .extra2
= (void *)&hugetlb_infinity
,
1136 .ctl_name
= VM_HUGETLB_GROUP
,
1137 .procname
= "hugetlb_shm_group",
1138 .data
= &sysctl_hugetlb_shm_group
,
1139 .maxlen
= sizeof(gid_t
),
1141 .proc_handler
= &proc_dointvec
,
1144 .ctl_name
= CTL_UNNUMBERED
,
1145 .procname
= "hugepages_treat_as_movable",
1146 .data
= &hugepages_treat_as_movable
,
1147 .maxlen
= sizeof(int),
1149 .proc_handler
= &hugetlb_treat_movable_handler
,
1152 .ctl_name
= CTL_UNNUMBERED
,
1153 .procname
= "nr_overcommit_hugepages",
1155 .maxlen
= sizeof(unsigned long),
1157 .proc_handler
= &hugetlb_overcommit_handler
,
1158 .extra1
= (void *)&hugetlb_zero
,
1159 .extra2
= (void *)&hugetlb_infinity
,
1163 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
1164 .procname
= "lowmem_reserve_ratio",
1165 .data
= &sysctl_lowmem_reserve_ratio
,
1166 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1168 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
1169 .strategy
= &sysctl_intvec
,
1172 .ctl_name
= VM_DROP_PAGECACHE
,
1173 .procname
= "drop_caches",
1174 .data
= &sysctl_drop_caches
,
1175 .maxlen
= sizeof(int),
1177 .proc_handler
= drop_caches_sysctl_handler
,
1178 .strategy
= &sysctl_intvec
,
1181 .ctl_name
= VM_MIN_FREE_KBYTES
,
1182 .procname
= "min_free_kbytes",
1183 .data
= &min_free_kbytes
,
1184 .maxlen
= sizeof(min_free_kbytes
),
1186 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1187 .strategy
= &sysctl_intvec
,
1191 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1192 .procname
= "percpu_pagelist_fraction",
1193 .data
= &percpu_pagelist_fraction
,
1194 .maxlen
= sizeof(percpu_pagelist_fraction
),
1196 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1197 .strategy
= &sysctl_intvec
,
1198 .extra1
= &min_percpu_pagelist_fract
,
1202 .ctl_name
= VM_MAX_MAP_COUNT
,
1203 .procname
= "max_map_count",
1204 .data
= &sysctl_max_map_count
,
1205 .maxlen
= sizeof(sysctl_max_map_count
),
1207 .proc_handler
= &proc_dointvec
1211 .ctl_name
= CTL_UNNUMBERED
,
1212 .procname
= "nr_trim_pages",
1213 .data
= &sysctl_nr_trim_pages
,
1214 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1216 .proc_handler
= &proc_dointvec_minmax
,
1217 .strategy
= &sysctl_intvec
,
1222 .ctl_name
= VM_LAPTOP_MODE
,
1223 .procname
= "laptop_mode",
1224 .data
= &laptop_mode
,
1225 .maxlen
= sizeof(laptop_mode
),
1227 .proc_handler
= &proc_dointvec_jiffies
,
1228 .strategy
= &sysctl_jiffies
,
1231 .ctl_name
= VM_BLOCK_DUMP
,
1232 .procname
= "block_dump",
1233 .data
= &block_dump
,
1234 .maxlen
= sizeof(block_dump
),
1236 .proc_handler
= &proc_dointvec
,
1237 .strategy
= &sysctl_intvec
,
1241 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1242 .procname
= "vfs_cache_pressure",
1243 .data
= &sysctl_vfs_cache_pressure
,
1244 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1246 .proc_handler
= &proc_dointvec
,
1247 .strategy
= &sysctl_intvec
,
1250 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1252 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1253 .procname
= "legacy_va_layout",
1254 .data
= &sysctl_legacy_va_layout
,
1255 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1257 .proc_handler
= &proc_dointvec
,
1258 .strategy
= &sysctl_intvec
,
1264 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1265 .procname
= "zone_reclaim_mode",
1266 .data
= &zone_reclaim_mode
,
1267 .maxlen
= sizeof(zone_reclaim_mode
),
1269 .proc_handler
= &proc_dointvec
,
1270 .strategy
= &sysctl_intvec
,
1274 .ctl_name
= VM_MIN_UNMAPPED
,
1275 .procname
= "min_unmapped_ratio",
1276 .data
= &sysctl_min_unmapped_ratio
,
1277 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1279 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1280 .strategy
= &sysctl_intvec
,
1282 .extra2
= &one_hundred
,
1285 .ctl_name
= VM_MIN_SLAB
,
1286 .procname
= "min_slab_ratio",
1287 .data
= &sysctl_min_slab_ratio
,
1288 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1290 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1291 .strategy
= &sysctl_intvec
,
1293 .extra2
= &one_hundred
,
1298 .ctl_name
= CTL_UNNUMBERED
,
1299 .procname
= "stat_interval",
1300 .data
= &sysctl_stat_interval
,
1301 .maxlen
= sizeof(sysctl_stat_interval
),
1303 .proc_handler
= &proc_dointvec_jiffies
,
1304 .strategy
= &sysctl_jiffies
,
1308 .ctl_name
= CTL_UNNUMBERED
,
1309 .procname
= "mmap_min_addr",
1310 .data
= &dac_mmap_min_addr
,
1311 .maxlen
= sizeof(unsigned long),
1313 .proc_handler
= &mmap_min_addr_handler
,
1317 .ctl_name
= CTL_UNNUMBERED
,
1318 .procname
= "numa_zonelist_order",
1319 .data
= &numa_zonelist_order
,
1320 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1322 .proc_handler
= &numa_zonelist_order_handler
,
1323 .strategy
= &sysctl_string
,
1326 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1327 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1329 .ctl_name
= VM_VDSO_ENABLED
,
1330 .procname
= "vdso_enabled",
1331 .data
= &vdso_enabled
,
1332 .maxlen
= sizeof(vdso_enabled
),
1334 .proc_handler
= &proc_dointvec
,
1335 .strategy
= &sysctl_intvec
,
1339 #ifdef CONFIG_HIGHMEM
1341 .ctl_name
= CTL_UNNUMBERED
,
1342 .procname
= "highmem_is_dirtyable",
1343 .data
= &vm_highmem_is_dirtyable
,
1344 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1346 .proc_handler
= &proc_dointvec_minmax
,
1347 .strategy
= &sysctl_intvec
,
1353 .ctl_name
= CTL_UNNUMBERED
,
1354 .procname
= "scan_unevictable_pages",
1355 .data
= &scan_unevictable_pages
,
1356 .maxlen
= sizeof(scan_unevictable_pages
),
1358 .proc_handler
= &scan_unevictable_handler
,
1361 * NOTE: do not add new entries to this table unless you have read
1362 * Documentation/sysctl/ctl_unnumbered.txt
1367 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1368 static struct ctl_table binfmt_misc_table
[] = {
1373 static struct ctl_table fs_table
[] = {
1375 .ctl_name
= FS_NRINODE
,
1376 .procname
= "inode-nr",
1377 .data
= &inodes_stat
,
1378 .maxlen
= 2*sizeof(int),
1380 .proc_handler
= &proc_dointvec
,
1383 .ctl_name
= FS_STATINODE
,
1384 .procname
= "inode-state",
1385 .data
= &inodes_stat
,
1386 .maxlen
= 7*sizeof(int),
1388 .proc_handler
= &proc_dointvec
,
1391 .procname
= "file-nr",
1392 .data
= &files_stat
,
1393 .maxlen
= 3*sizeof(int),
1395 .proc_handler
= &proc_nr_files
,
1398 .ctl_name
= FS_MAXFILE
,
1399 .procname
= "file-max",
1400 .data
= &files_stat
.max_files
,
1401 .maxlen
= sizeof(int),
1403 .proc_handler
= &proc_dointvec
,
1406 .ctl_name
= CTL_UNNUMBERED
,
1407 .procname
= "nr_open",
1408 .data
= &sysctl_nr_open
,
1409 .maxlen
= sizeof(int),
1411 .proc_handler
= &proc_dointvec_minmax
,
1412 .extra1
= &sysctl_nr_open_min
,
1413 .extra2
= &sysctl_nr_open_max
,
1416 .ctl_name
= FS_DENTRY
,
1417 .procname
= "dentry-state",
1418 .data
= &dentry_stat
,
1419 .maxlen
= 6*sizeof(int),
1421 .proc_handler
= &proc_dointvec
,
1424 .ctl_name
= FS_OVERFLOWUID
,
1425 .procname
= "overflowuid",
1426 .data
= &fs_overflowuid
,
1427 .maxlen
= sizeof(int),
1429 .proc_handler
= &proc_dointvec_minmax
,
1430 .strategy
= &sysctl_intvec
,
1431 .extra1
= &minolduid
,
1432 .extra2
= &maxolduid
,
1435 .ctl_name
= FS_OVERFLOWGID
,
1436 .procname
= "overflowgid",
1437 .data
= &fs_overflowgid
,
1438 .maxlen
= sizeof(int),
1440 .proc_handler
= &proc_dointvec_minmax
,
1441 .strategy
= &sysctl_intvec
,
1442 .extra1
= &minolduid
,
1443 .extra2
= &maxolduid
,
1445 #ifdef CONFIG_FILE_LOCKING
1447 .ctl_name
= FS_LEASES
,
1448 .procname
= "leases-enable",
1449 .data
= &leases_enable
,
1450 .maxlen
= sizeof(int),
1452 .proc_handler
= &proc_dointvec
,
1455 #ifdef CONFIG_DNOTIFY
1457 .ctl_name
= FS_DIR_NOTIFY
,
1458 .procname
= "dir-notify-enable",
1459 .data
= &dir_notify_enable
,
1460 .maxlen
= sizeof(int),
1462 .proc_handler
= &proc_dointvec
,
1466 #ifdef CONFIG_FILE_LOCKING
1468 .ctl_name
= FS_LEASE_TIME
,
1469 .procname
= "lease-break-time",
1470 .data
= &lease_break_time
,
1471 .maxlen
= sizeof(int),
1473 .proc_handler
= &proc_dointvec
,
1478 .procname
= "aio-nr",
1480 .maxlen
= sizeof(aio_nr
),
1482 .proc_handler
= &proc_doulongvec_minmax
,
1485 .procname
= "aio-max-nr",
1486 .data
= &aio_max_nr
,
1487 .maxlen
= sizeof(aio_max_nr
),
1489 .proc_handler
= &proc_doulongvec_minmax
,
1491 #endif /* CONFIG_AIO */
1492 #ifdef CONFIG_INOTIFY_USER
1494 .ctl_name
= FS_INOTIFY
,
1495 .procname
= "inotify",
1497 .child
= inotify_table
,
1502 .procname
= "epoll",
1504 .child
= epoll_table
,
1509 .ctl_name
= KERN_SETUID_DUMPABLE
,
1510 .procname
= "suid_dumpable",
1511 .data
= &suid_dumpable
,
1512 .maxlen
= sizeof(int),
1514 .proc_handler
= &proc_dointvec_minmax
,
1515 .strategy
= &sysctl_intvec
,
1519 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1521 .ctl_name
= CTL_UNNUMBERED
,
1522 .procname
= "binfmt_misc",
1524 .child
= binfmt_misc_table
,
1528 * NOTE: do not add new entries to this table unless you have read
1529 * Documentation/sysctl/ctl_unnumbered.txt
1534 static struct ctl_table debug_table
[] = {
1535 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1537 .ctl_name
= CTL_UNNUMBERED
,
1538 .procname
= "exception-trace",
1539 .data
= &show_unhandled_signals
,
1540 .maxlen
= sizeof(int),
1542 .proc_handler
= proc_dointvec
1548 static struct ctl_table dev_table
[] = {
1552 static DEFINE_SPINLOCK(sysctl_lock
);
1554 /* called under sysctl_lock */
1555 static int use_table(struct ctl_table_header
*p
)
1557 if (unlikely(p
->unregistering
))
1563 /* called under sysctl_lock */
1564 static void unuse_table(struct ctl_table_header
*p
)
1567 if (unlikely(p
->unregistering
))
1568 complete(p
->unregistering
);
1571 /* called under sysctl_lock, will reacquire if has to wait */
1572 static void start_unregistering(struct ctl_table_header
*p
)
1575 * if p->used is 0, nobody will ever touch that entry again;
1576 * we'll eliminate all paths to it before dropping sysctl_lock
1578 if (unlikely(p
->used
)) {
1579 struct completion wait
;
1580 init_completion(&wait
);
1581 p
->unregistering
= &wait
;
1582 spin_unlock(&sysctl_lock
);
1583 wait_for_completion(&wait
);
1584 spin_lock(&sysctl_lock
);
1586 /* anything non-NULL; we'll never dereference it */
1587 p
->unregistering
= ERR_PTR(-EINVAL
);
1590 * do not remove from the list until nobody holds it; walking the
1591 * list in do_sysctl() relies on that.
1593 list_del_init(&p
->ctl_entry
);
1596 void sysctl_head_get(struct ctl_table_header
*head
)
1598 spin_lock(&sysctl_lock
);
1600 spin_unlock(&sysctl_lock
);
1603 void sysctl_head_put(struct ctl_table_header
*head
)
1605 spin_lock(&sysctl_lock
);
1608 spin_unlock(&sysctl_lock
);
1611 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1615 spin_lock(&sysctl_lock
);
1616 if (!use_table(head
))
1617 head
= ERR_PTR(-ENOENT
);
1618 spin_unlock(&sysctl_lock
);
1622 void sysctl_head_finish(struct ctl_table_header
*head
)
1626 spin_lock(&sysctl_lock
);
1628 spin_unlock(&sysctl_lock
);
1631 static struct ctl_table_set
*
1632 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1634 struct ctl_table_set
*set
= &root
->default_set
;
1636 set
= root
->lookup(root
, namespaces
);
1640 static struct list_head
*
1641 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1643 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1647 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1648 struct ctl_table_header
*prev
)
1650 struct ctl_table_root
*root
;
1651 struct list_head
*header_list
;
1652 struct ctl_table_header
*head
;
1653 struct list_head
*tmp
;
1655 spin_lock(&sysctl_lock
);
1658 tmp
= &prev
->ctl_entry
;
1662 tmp
= &root_table_header
.ctl_entry
;
1664 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1666 if (!use_table(head
))
1668 spin_unlock(&sysctl_lock
);
1673 header_list
= lookup_header_list(root
, namespaces
);
1674 if (tmp
!= header_list
)
1678 root
= list_entry(root
->root_list
.next
,
1679 struct ctl_table_root
, root_list
);
1680 if (root
== &sysctl_table_root
)
1682 header_list
= lookup_header_list(root
, namespaces
);
1683 } while (list_empty(header_list
));
1684 tmp
= header_list
->next
;
1687 spin_unlock(&sysctl_lock
);
1691 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1693 return __sysctl_head_next(current
->nsproxy
, prev
);
1696 void register_sysctl_root(struct ctl_table_root
*root
)
1698 spin_lock(&sysctl_lock
);
1699 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1700 spin_unlock(&sysctl_lock
);
1703 #ifdef CONFIG_SYSCTL_SYSCALL
1704 /* Perform the actual read/write of a sysctl table entry. */
1705 static int do_sysctl_strategy(struct ctl_table_root
*root
,
1706 struct ctl_table
*table
,
1707 void __user
*oldval
, size_t __user
*oldlenp
,
1708 void __user
*newval
, size_t newlen
)
1716 if (sysctl_perm(root
, table
, op
))
1719 if (table
->strategy
) {
1720 rc
= table
->strategy(table
, oldval
, oldlenp
, newval
, newlen
);
1727 /* If there is no strategy routine, or if the strategy returns
1728 * zero, proceed with automatic r/w */
1729 if (table
->data
&& table
->maxlen
) {
1730 rc
= sysctl_data(table
, oldval
, oldlenp
, newval
, newlen
);
1737 static int parse_table(int __user
*name
, int nlen
,
1738 void __user
*oldval
, size_t __user
*oldlenp
,
1739 void __user
*newval
, size_t newlen
,
1740 struct ctl_table_root
*root
,
1741 struct ctl_table
*table
)
1747 if (get_user(n
, name
))
1749 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1750 if (!table
->ctl_name
)
1752 if (n
== table
->ctl_name
) {
1755 if (sysctl_perm(root
, table
, MAY_EXEC
))
1759 table
= table
->child
;
1762 error
= do_sysctl_strategy(root
, table
,
1771 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1772 void __user
*newval
, size_t newlen
)
1774 struct ctl_table_header
*head
;
1775 int error
= -ENOTDIR
;
1777 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1781 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1785 for (head
= sysctl_head_next(NULL
); head
;
1786 head
= sysctl_head_next(head
)) {
1787 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1789 head
->root
, head
->ctl_table
);
1790 if (error
!= -ENOTDIR
) {
1791 sysctl_head_finish(head
);
1798 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
1800 struct __sysctl_args tmp
;
1803 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1806 error
= deprecated_sysctl_warning(&tmp
);
1811 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1812 tmp
.newval
, tmp
.newlen
);
1817 #endif /* CONFIG_SYSCTL_SYSCALL */
1820 * sysctl_perm does NOT grant the superuser all rights automatically, because
1821 * some sysctl variables are readonly even to root.
1824 static int test_perm(int mode
, int op
)
1826 if (!current_euid())
1828 else if (in_egroup_p(0))
1830 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1835 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1840 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1844 if (root
->permissions
)
1845 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1849 return test_perm(mode
, op
);
1852 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1854 for (; table
->ctl_name
|| table
->procname
; table
++) {
1855 table
->parent
= parent
;
1857 sysctl_set_parent(table
, table
->child
);
1861 static __init
int sysctl_init(void)
1863 sysctl_set_parent(NULL
, root_table
);
1864 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1867 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1873 core_initcall(sysctl_init
);
1875 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1876 struct ctl_table
*table
)
1878 struct ctl_table
*p
;
1879 const char *s
= branch
->procname
;
1881 /* branch should have named subdirectory as its first element */
1882 if (!s
|| !branch
->child
)
1885 /* ... and nothing else */
1886 if (branch
[1].procname
|| branch
[1].ctl_name
)
1889 /* table should contain subdirectory with the same name */
1890 for (p
= table
; p
->procname
|| p
->ctl_name
; p
++) {
1893 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1899 /* see if attaching q to p would be an improvement */
1900 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1902 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1903 struct ctl_table
*next
;
1905 int not_in_parent
= !p
->attached_by
;
1907 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1908 if (by
== q
->attached_by
)
1910 if (to
== p
->attached_by
)
1916 if (is_better
&& not_in_parent
) {
1917 q
->attached_by
= by
;
1918 q
->attached_to
= to
;
1924 * __register_sysctl_paths - register a sysctl hierarchy
1925 * @root: List of sysctl headers to register on
1926 * @namespaces: Data to compute which lists of sysctl entries are visible
1927 * @path: The path to the directory the sysctl table is in.
1928 * @table: the top-level table structure
1930 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1931 * array. A completely 0 filled entry terminates the table.
1933 * The members of the &struct ctl_table structure are used as follows:
1935 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1936 * must be unique within that level of sysctl
1938 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1939 * enter a sysctl file
1941 * data - a pointer to data for use by proc_handler
1943 * maxlen - the maximum size in bytes of the data
1945 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1947 * child - a pointer to the child sysctl table if this entry is a directory, or
1950 * proc_handler - the text handler routine (described below)
1952 * strategy - the strategy routine (described below)
1954 * de - for internal use by the sysctl routines
1956 * extra1, extra2 - extra pointers usable by the proc handler routines
1958 * Leaf nodes in the sysctl tree will be represented by a single file
1959 * under /proc; non-leaf nodes will be represented by directories.
1961 * sysctl(2) can automatically manage read and write requests through
1962 * the sysctl table. The data and maxlen fields of the ctl_table
1963 * struct enable minimal validation of the values being written to be
1964 * performed, and the mode field allows minimal authentication.
1966 * More sophisticated management can be enabled by the provision of a
1967 * strategy routine with the table entry. This will be called before
1968 * any automatic read or write of the data is performed.
1970 * The strategy routine may return
1972 * < 0 - Error occurred (error is passed to user process)
1974 * 0 - OK - proceed with automatic read or write.
1976 * > 0 - OK - read or write has been done by the strategy routine, so
1977 * return immediately.
1979 * There must be a proc_handler routine for any terminal nodes
1980 * mirrored under /proc/sys (non-terminals are handled by a built-in
1981 * directory handler). Several default handlers are available to
1982 * cover common cases -
1984 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1985 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1986 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1988 * It is the handler's job to read the input buffer from user memory
1989 * and process it. The handler should return 0 on success.
1991 * This routine returns %NULL on a failure to register, and a pointer
1992 * to the table header on success.
1994 struct ctl_table_header
*__register_sysctl_paths(
1995 struct ctl_table_root
*root
,
1996 struct nsproxy
*namespaces
,
1997 const struct ctl_path
*path
, struct ctl_table
*table
)
1999 struct ctl_table_header
*header
;
2000 struct ctl_table
*new, **prevp
;
2001 unsigned int n
, npath
;
2002 struct ctl_table_set
*set
;
2004 /* Count the path components */
2005 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
2009 * For each path component, allocate a 2-element ctl_table array.
2010 * The first array element will be filled with the sysctl entry
2011 * for this, the second will be the sentinel (ctl_name == 0).
2013 * We allocate everything in one go so that we don't have to
2014 * worry about freeing additional memory in unregister_sysctl_table.
2016 header
= kzalloc(sizeof(struct ctl_table_header
) +
2017 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
2021 new = (struct ctl_table
*) (header
+ 1);
2023 /* Now connect the dots */
2024 prevp
= &header
->ctl_table
;
2025 for (n
= 0; n
< npath
; ++n
, ++path
) {
2026 /* Copy the procname */
2027 new->procname
= path
->procname
;
2028 new->ctl_name
= path
->ctl_name
;
2032 prevp
= &new->child
;
2037 header
->ctl_table_arg
= table
;
2039 INIT_LIST_HEAD(&header
->ctl_entry
);
2041 header
->unregistering
= NULL
;
2042 header
->root
= root
;
2043 sysctl_set_parent(NULL
, header
->ctl_table
);
2045 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
2046 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
2051 spin_lock(&sysctl_lock
);
2052 header
->set
= lookup_header_set(root
, namespaces
);
2053 header
->attached_by
= header
->ctl_table
;
2054 header
->attached_to
= root_table
;
2055 header
->parent
= &root_table_header
;
2056 for (set
= header
->set
; set
; set
= set
->parent
) {
2057 struct ctl_table_header
*p
;
2058 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
2059 if (p
->unregistering
)
2061 try_attach(p
, header
);
2064 header
->parent
->count
++;
2065 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
2066 spin_unlock(&sysctl_lock
);
2072 * register_sysctl_table_path - register a sysctl table hierarchy
2073 * @path: The path to the directory the sysctl table is in.
2074 * @table: the top-level table structure
2076 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2077 * array. A completely 0 filled entry terminates the table.
2079 * See __register_sysctl_paths for more details.
2081 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2082 struct ctl_table
*table
)
2084 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
2089 * register_sysctl_table - register a sysctl table hierarchy
2090 * @table: the top-level table structure
2092 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2093 * array. A completely 0 filled entry terminates the table.
2095 * See register_sysctl_paths for more details.
2097 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
2099 static const struct ctl_path null_path
[] = { {} };
2101 return register_sysctl_paths(null_path
, table
);
2105 * unregister_sysctl_table - unregister a sysctl table hierarchy
2106 * @header: the header returned from register_sysctl_table
2108 * Unregisters the sysctl table and all children. proc entries may not
2109 * actually be removed until they are no longer used by anyone.
2111 void unregister_sysctl_table(struct ctl_table_header
* header
)
2118 spin_lock(&sysctl_lock
);
2119 start_unregistering(header
);
2120 if (!--header
->parent
->count
) {
2122 kfree(header
->parent
);
2124 if (!--header
->count
)
2126 spin_unlock(&sysctl_lock
);
2129 int sysctl_is_seen(struct ctl_table_header
*p
)
2131 struct ctl_table_set
*set
= p
->set
;
2133 spin_lock(&sysctl_lock
);
2134 if (p
->unregistering
)
2136 else if (!set
->is_seen
)
2139 res
= set
->is_seen(set
);
2140 spin_unlock(&sysctl_lock
);
2144 void setup_sysctl_set(struct ctl_table_set
*p
,
2145 struct ctl_table_set
*parent
,
2146 int (*is_seen
)(struct ctl_table_set
*))
2148 INIT_LIST_HEAD(&p
->list
);
2149 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
2150 p
->is_seen
= is_seen
;
2153 #else /* !CONFIG_SYSCTL */
2154 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
2159 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2160 struct ctl_table
*table
)
2165 void unregister_sysctl_table(struct ctl_table_header
* table
)
2169 void setup_sysctl_set(struct ctl_table_set
*p
,
2170 struct ctl_table_set
*parent
,
2171 int (*is_seen
)(struct ctl_table_set
*))
2175 void sysctl_head_put(struct ctl_table_header
*head
)
2179 #endif /* CONFIG_SYSCTL */
2185 #ifdef CONFIG_PROC_SYSCTL
2187 static int _proc_do_string(void* data
, int maxlen
, int write
,
2188 struct file
*filp
, void __user
*buffer
,
2189 size_t *lenp
, loff_t
*ppos
)
2195 if (!data
|| !maxlen
|| !*lenp
) {
2203 while (len
< *lenp
) {
2204 if (get_user(c
, p
++))
2206 if (c
== 0 || c
== '\n')
2212 if(copy_from_user(data
, buffer
, len
))
2214 ((char *) data
)[len
] = 0;
2232 if(copy_to_user(buffer
, data
, len
))
2235 if(put_user('\n', ((char __user
*) buffer
) + len
))
2246 * proc_dostring - read a string sysctl
2247 * @table: the sysctl table
2248 * @write: %TRUE if this is a write to the sysctl file
2249 * @filp: the file structure
2250 * @buffer: the user buffer
2251 * @lenp: the size of the user buffer
2252 * @ppos: file position
2254 * Reads/writes a string from/to the user buffer. If the kernel
2255 * buffer provided is not large enough to hold the string, the
2256 * string is truncated. The copied string is %NULL-terminated.
2257 * If the string is being read by the user process, it is copied
2258 * and a newline '\n' is added. It is truncated if the buffer is
2261 * Returns 0 on success.
2263 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2264 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2266 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
2267 buffer
, lenp
, ppos
);
2271 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
2273 int write
, void *data
)
2276 *valp
= *negp
? -*lvalp
: *lvalp
;
2281 *lvalp
= (unsigned long)-val
;
2284 *lvalp
= (unsigned long)val
;
2290 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2291 int write
, struct file
*filp
, void __user
*buffer
,
2292 size_t *lenp
, loff_t
*ppos
,
2293 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2294 int write
, void *data
),
2297 #define TMPBUFLEN 21
2298 int *i
, vleft
, first
= 1, neg
;
2302 char buf
[TMPBUFLEN
], *p
;
2303 char __user
*s
= buffer
;
2305 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
2306 (*ppos
&& !write
)) {
2311 i
= (int *) tbl_data
;
2312 vleft
= table
->maxlen
/ sizeof(*i
);
2316 conv
= do_proc_dointvec_conv
;
2318 for (; left
&& vleft
--; i
++, first
=0) {
2333 if (len
> sizeof(buf
) - 1)
2334 len
= sizeof(buf
) - 1;
2335 if (copy_from_user(buf
, s
, len
))
2339 if (*p
== '-' && left
> 1) {
2343 if (*p
< '0' || *p
> '9')
2346 lval
= simple_strtoul(p
, &p
, 0);
2349 if ((len
< left
) && *p
&& !isspace(*p
))
2354 if (conv(&neg
, &lval
, i
, 1, data
))
2361 if (conv(&neg
, &lval
, i
, 0, data
))
2364 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2368 if(copy_to_user(s
, buf
, len
))
2375 if (!write
&& !first
&& left
) {
2376 if(put_user('\n', s
))
2383 if (get_user(c
, s
++))
2398 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2399 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2400 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2401 int write
, void *data
),
2404 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2405 buffer
, lenp
, ppos
, conv
, data
);
2409 * proc_dointvec - read a vector of integers
2410 * @table: the sysctl table
2411 * @write: %TRUE if this is a write to the sysctl file
2412 * @filp: the file structure
2413 * @buffer: the user buffer
2414 * @lenp: the size of the user buffer
2415 * @ppos: file position
2417 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2418 * values from/to the user buffer, treated as an ASCII string.
2420 * Returns 0 on success.
2422 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2423 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2425 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2430 * Taint values can only be increased
2431 * This means we can safely use a temporary.
2433 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2434 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2437 unsigned long tmptaint
= get_taint();
2440 if (write
&& !capable(CAP_SYS_ADMIN
))
2445 err
= proc_doulongvec_minmax(&t
, write
, filp
, buffer
, lenp
, ppos
);
2451 * Poor man's atomic or. Not worth adding a primitive
2452 * to everyone's atomic.h for this
2455 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2456 if ((tmptaint
>> i
) & 1)
2464 struct do_proc_dointvec_minmax_conv_param
{
2469 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2471 int write
, void *data
)
2473 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2475 int val
= *negp
? -*lvalp
: *lvalp
;
2476 if ((param
->min
&& *param
->min
> val
) ||
2477 (param
->max
&& *param
->max
< val
))
2484 *lvalp
= (unsigned long)-val
;
2487 *lvalp
= (unsigned long)val
;
2494 * proc_dointvec_minmax - read a vector of integers with min/max values
2495 * @table: the sysctl table
2496 * @write: %TRUE if this is a write to the sysctl file
2497 * @filp: the file structure
2498 * @buffer: the user buffer
2499 * @lenp: the size of the user buffer
2500 * @ppos: file position
2502 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2503 * values from/to the user buffer, treated as an ASCII string.
2505 * This routine will ensure the values are within the range specified by
2506 * table->extra1 (min) and table->extra2 (max).
2508 * Returns 0 on success.
2510 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2511 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2513 struct do_proc_dointvec_minmax_conv_param param
= {
2514 .min
= (int *) table
->extra1
,
2515 .max
= (int *) table
->extra2
,
2517 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2518 do_proc_dointvec_minmax_conv
, ¶m
);
2521 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2523 void __user
*buffer
,
2524 size_t *lenp
, loff_t
*ppos
,
2525 unsigned long convmul
,
2526 unsigned long convdiv
)
2528 #define TMPBUFLEN 21
2529 unsigned long *i
, *min
, *max
, val
;
2530 int vleft
, first
=1, neg
;
2532 char buf
[TMPBUFLEN
], *p
;
2533 char __user
*s
= buffer
;
2535 if (!data
|| !table
->maxlen
|| !*lenp
||
2536 (*ppos
&& !write
)) {
2541 i
= (unsigned long *) data
;
2542 min
= (unsigned long *) table
->extra1
;
2543 max
= (unsigned long *) table
->extra2
;
2544 vleft
= table
->maxlen
/ sizeof(unsigned long);
2547 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2562 if (len
> TMPBUFLEN
-1)
2564 if (copy_from_user(buf
, s
, len
))
2568 if (*p
== '-' && left
> 1) {
2572 if (*p
< '0' || *p
> '9')
2574 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2576 if ((len
< left
) && *p
&& !isspace(*p
))
2585 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2592 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2596 if(copy_to_user(s
, buf
, len
))
2603 if (!write
&& !first
&& left
) {
2604 if(put_user('\n', s
))
2611 if (get_user(c
, s
++))
2626 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2628 void __user
*buffer
,
2629 size_t *lenp
, loff_t
*ppos
,
2630 unsigned long convmul
,
2631 unsigned long convdiv
)
2633 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2634 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2638 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2639 * @table: the sysctl table
2640 * @write: %TRUE if this is a write to the sysctl file
2641 * @filp: the file structure
2642 * @buffer: the user buffer
2643 * @lenp: the size of the user buffer
2644 * @ppos: file position
2646 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2647 * values from/to the user buffer, treated as an ASCII string.
2649 * This routine will ensure the values are within the range specified by
2650 * table->extra1 (min) and table->extra2 (max).
2652 * Returns 0 on success.
2654 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2655 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2657 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2661 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2662 * @table: the sysctl table
2663 * @write: %TRUE if this is a write to the sysctl file
2664 * @filp: the file structure
2665 * @buffer: the user buffer
2666 * @lenp: the size of the user buffer
2667 * @ppos: file position
2669 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2670 * values from/to the user buffer, treated as an ASCII string. The values
2671 * are treated as milliseconds, and converted to jiffies when they are stored.
2673 * This routine will ensure the values are within the range specified by
2674 * table->extra1 (min) and table->extra2 (max).
2676 * Returns 0 on success.
2678 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2680 void __user
*buffer
,
2681 size_t *lenp
, loff_t
*ppos
)
2683 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2684 lenp
, ppos
, HZ
, 1000l);
2688 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2690 int write
, void *data
)
2693 if (*lvalp
> LONG_MAX
/ HZ
)
2695 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2701 lval
= (unsigned long)-val
;
2704 lval
= (unsigned long)val
;
2711 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2713 int write
, void *data
)
2716 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2718 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2724 lval
= (unsigned long)-val
;
2727 lval
= (unsigned long)val
;
2729 *lvalp
= jiffies_to_clock_t(lval
);
2734 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2736 int write
, void *data
)
2739 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2745 lval
= (unsigned long)-val
;
2748 lval
= (unsigned long)val
;
2750 *lvalp
= jiffies_to_msecs(lval
);
2756 * proc_dointvec_jiffies - read a vector of integers as seconds
2757 * @table: the sysctl table
2758 * @write: %TRUE if this is a write to the sysctl file
2759 * @filp: the file structure
2760 * @buffer: the user buffer
2761 * @lenp: the size of the user buffer
2762 * @ppos: file position
2764 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2765 * values from/to the user buffer, treated as an ASCII string.
2766 * The values read are assumed to be in seconds, and are converted into
2769 * Returns 0 on success.
2771 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2772 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2774 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2775 do_proc_dointvec_jiffies_conv
,NULL
);
2779 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2780 * @table: the sysctl table
2781 * @write: %TRUE if this is a write to the sysctl file
2782 * @filp: the file structure
2783 * @buffer: the user buffer
2784 * @lenp: the size of the user buffer
2785 * @ppos: pointer to the file position
2787 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2788 * values from/to the user buffer, treated as an ASCII string.
2789 * The values read are assumed to be in 1/USER_HZ seconds, and
2790 * are converted into jiffies.
2792 * Returns 0 on success.
2794 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2795 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2797 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2798 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2802 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2803 * @table: the sysctl table
2804 * @write: %TRUE if this is a write to the sysctl file
2805 * @filp: the file structure
2806 * @buffer: the user buffer
2807 * @lenp: the size of the user buffer
2808 * @ppos: file position
2809 * @ppos: the current position in the file
2811 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2812 * values from/to the user buffer, treated as an ASCII string.
2813 * The values read are assumed to be in 1/1000 seconds, and
2814 * are converted into jiffies.
2816 * Returns 0 on success.
2818 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2819 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2821 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2822 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2825 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2826 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2828 struct pid
*new_pid
;
2832 tmp
= pid_vnr(cad_pid
);
2834 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2835 lenp
, ppos
, NULL
, NULL
);
2839 new_pid
= find_get_pid(tmp
);
2843 put_pid(xchg(&cad_pid
, new_pid
));
2847 #else /* CONFIG_PROC_FS */
2849 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2850 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2855 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2856 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2861 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2862 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2867 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2868 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2873 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2874 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2879 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2880 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2885 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2886 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2891 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2893 void __user
*buffer
,
2894 size_t *lenp
, loff_t
*ppos
)
2900 #endif /* CONFIG_PROC_FS */
2903 #ifdef CONFIG_SYSCTL_SYSCALL
2905 * General sysctl support routines
2908 /* The generic sysctl data routine (used if no strategy routine supplied) */
2909 int sysctl_data(struct ctl_table
*table
,
2910 void __user
*oldval
, size_t __user
*oldlenp
,
2911 void __user
*newval
, size_t newlen
)
2915 /* Get out of I don't have a variable */
2916 if (!table
->data
|| !table
->maxlen
)
2919 if (oldval
&& oldlenp
) {
2920 if (get_user(len
, oldlenp
))
2923 if (len
> table
->maxlen
)
2924 len
= table
->maxlen
;
2925 if (copy_to_user(oldval
, table
->data
, len
))
2927 if (put_user(len
, oldlenp
))
2932 if (newval
&& newlen
) {
2933 if (newlen
> table
->maxlen
)
2934 newlen
= table
->maxlen
;
2936 if (copy_from_user(table
->data
, newval
, newlen
))
2942 /* The generic string strategy routine: */
2943 int sysctl_string(struct ctl_table
*table
,
2944 void __user
*oldval
, size_t __user
*oldlenp
,
2945 void __user
*newval
, size_t newlen
)
2947 if (!table
->data
|| !table
->maxlen
)
2950 if (oldval
&& oldlenp
) {
2952 if (get_user(bufsize
, oldlenp
))
2955 size_t len
= strlen(table
->data
), copied
;
2957 /* This shouldn't trigger for a well-formed sysctl */
2958 if (len
> table
->maxlen
)
2959 len
= table
->maxlen
;
2961 /* Copy up to a max of bufsize-1 bytes of the string */
2962 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2964 if (copy_to_user(oldval
, table
->data
, copied
) ||
2965 put_user(0, (char __user
*)(oldval
+ copied
)))
2967 if (put_user(len
, oldlenp
))
2971 if (newval
&& newlen
) {
2972 size_t len
= newlen
;
2973 if (len
> table
->maxlen
)
2974 len
= table
->maxlen
;
2975 if(copy_from_user(table
->data
, newval
, len
))
2977 if (len
== table
->maxlen
)
2979 ((char *) table
->data
)[len
] = 0;
2985 * This function makes sure that all of the integers in the vector
2986 * are between the minimum and maximum values given in the arrays
2987 * table->extra1 and table->extra2, respectively.
2989 int sysctl_intvec(struct ctl_table
*table
,
2990 void __user
*oldval
, size_t __user
*oldlenp
,
2991 void __user
*newval
, size_t newlen
)
2994 if (newval
&& newlen
) {
2995 int __user
*vec
= (int __user
*) newval
;
2996 int *min
= (int *) table
->extra1
;
2997 int *max
= (int *) table
->extra2
;
3001 if (newlen
% sizeof(int) != 0)
3004 if (!table
->extra1
&& !table
->extra2
)
3007 if (newlen
> table
->maxlen
)
3008 newlen
= table
->maxlen
;
3009 length
= newlen
/ sizeof(int);
3011 for (i
= 0; i
< length
; i
++) {
3013 if (get_user(value
, vec
+ i
))
3015 if (min
&& value
< min
[i
])
3017 if (max
&& value
> max
[i
])
3024 /* Strategy function to convert jiffies to seconds */
3025 int sysctl_jiffies(struct ctl_table
*table
,
3026 void __user
*oldval
, size_t __user
*oldlenp
,
3027 void __user
*newval
, size_t newlen
)
3029 if (oldval
&& oldlenp
) {
3032 if (get_user(olen
, oldlenp
))
3037 if (olen
< sizeof(int))
3040 val
= *(int *)(table
->data
) / HZ
;
3041 if (put_user(val
, (int __user
*)oldval
))
3043 if (put_user(sizeof(int), oldlenp
))
3047 if (newval
&& newlen
) {
3049 if (newlen
!= sizeof(int))
3051 if (get_user(new, (int __user
*)newval
))
3053 *(int *)(table
->data
) = new*HZ
;
3058 /* Strategy function to convert jiffies to seconds */
3059 int sysctl_ms_jiffies(struct ctl_table
*table
,
3060 void __user
*oldval
, size_t __user
*oldlenp
,
3061 void __user
*newval
, size_t newlen
)
3063 if (oldval
&& oldlenp
) {
3066 if (get_user(olen
, oldlenp
))
3071 if (olen
< sizeof(int))
3074 val
= jiffies_to_msecs(*(int *)(table
->data
));
3075 if (put_user(val
, (int __user
*)oldval
))
3077 if (put_user(sizeof(int), oldlenp
))
3081 if (newval
&& newlen
) {
3083 if (newlen
!= sizeof(int))
3085 if (get_user(new, (int __user
*)newval
))
3087 *(int *)(table
->data
) = msecs_to_jiffies(new);
3094 #else /* CONFIG_SYSCTL_SYSCALL */
3097 SYSCALL_DEFINE1(sysctl
, struct __sysctl_args __user
*, args
)
3099 struct __sysctl_args tmp
;
3102 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
3105 error
= deprecated_sysctl_warning(&tmp
);
3107 /* If no error reading the parameters then just -ENOSYS ... */
3114 int sysctl_data(struct ctl_table
*table
,
3115 void __user
*oldval
, size_t __user
*oldlenp
,
3116 void __user
*newval
, size_t newlen
)
3121 int sysctl_string(struct ctl_table
*table
,
3122 void __user
*oldval
, size_t __user
*oldlenp
,
3123 void __user
*newval
, size_t newlen
)
3128 int sysctl_intvec(struct ctl_table
*table
,
3129 void __user
*oldval
, size_t __user
*oldlenp
,
3130 void __user
*newval
, size_t newlen
)
3135 int sysctl_jiffies(struct ctl_table
*table
,
3136 void __user
*oldval
, size_t __user
*oldlenp
,
3137 void __user
*newval
, size_t newlen
)
3142 int sysctl_ms_jiffies(struct ctl_table
*table
,
3143 void __user
*oldval
, size_t __user
*oldlenp
,
3144 void __user
*newval
, size_t newlen
)
3149 #endif /* CONFIG_SYSCTL_SYSCALL */
3151 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
3153 static int msg_count
;
3154 int name
[CTL_MAXNAME
];
3157 /* Check args->nlen. */
3158 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
3161 /* Read in the sysctl name for better debug message logging */
3162 for (i
= 0; i
< args
->nlen
; i
++)
3163 if (get_user(name
[i
], args
->name
+ i
))
3166 /* Ignore accesses to kernel.version */
3167 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
3170 if (msg_count
< 5) {
3173 "warning: process `%s' used the deprecated sysctl "
3174 "system call with ", current
->comm
);
3175 for (i
= 0; i
< args
->nlen
; i
++)
3176 printk("%d.", name
[i
]);
3183 * No sense putting this after each symbol definition, twice,
3184 * exception granted :-)
3186 EXPORT_SYMBOL(proc_dointvec
);
3187 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3188 EXPORT_SYMBOL(proc_dointvec_minmax
);
3189 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3190 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3191 EXPORT_SYMBOL(proc_dostring
);
3192 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3193 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
3194 EXPORT_SYMBOL(register_sysctl_table
);
3195 EXPORT_SYMBOL(register_sysctl_paths
);
3196 EXPORT_SYMBOL(sysctl_intvec
);
3197 EXPORT_SYMBOL(sysctl_jiffies
);
3198 EXPORT_SYMBOL(sysctl_ms_jiffies
);
3199 EXPORT_SYMBOL(sysctl_string
);
3200 EXPORT_SYMBOL(sysctl_data
);
3201 EXPORT_SYMBOL(unregister_sysctl_table
);