2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/proc_fs.h>
27 #include <linux/security.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/hugetlb.h>
40 #include <linux/initrd.h>
41 #include <linux/key.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/vmstat.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/acpi.h>
49 #include <linux/reboot.h>
50 #include <linux/ftrace.h>
52 #include <asm/uaccess.h>
53 #include <asm/processor.h>
57 #include <asm/stacktrace.h>
61 static int deprecated_sysctl_warning(struct __sysctl_args
*args
);
63 #if defined(CONFIG_SYSCTL)
65 /* External variables not in a header file. */
67 extern int print_fatal_signals
;
68 extern int sysctl_overcommit_memory
;
69 extern int sysctl_overcommit_ratio
;
70 extern int sysctl_panic_on_oom
;
71 extern int sysctl_oom_kill_allocating_task
;
72 extern int sysctl_oom_dump_tasks
;
73 extern int max_threads
;
74 extern int core_uses_pid
;
75 extern int suid_dumpable
;
76 extern char core_pattern
[];
78 extern int min_free_kbytes
;
79 extern int pid_max_min
, pid_max_max
;
80 extern int sysctl_drop_caches
;
81 extern int percpu_pagelist_fraction
;
82 extern int compat_log
;
83 extern int latencytop_enabled
;
84 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
85 #ifdef CONFIG_RCU_TORTURE_TEST
86 extern int rcutorture_runnable
;
87 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
89 /* Constants used for minimum and maximum */
90 #if defined(CONFIG_HIGHMEM) || defined(CONFIG_DETECT_SOFTLOCKUP)
94 #ifdef CONFIG_DETECT_SOFTLOCKUP
95 static int sixty
= 60;
96 static int neg_one
= -1;
99 #if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING)
104 static int one_hundred
= 100;
106 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
107 static int maxolduid
= 65535;
108 static int minolduid
;
109 static int min_percpu_pagelist_fract
= 8;
111 static int ngroups_max
= NGROUPS_MAX
;
113 #ifdef CONFIG_MODULES
114 extern char modprobe_path
[];
116 #ifdef CONFIG_CHR_DEV_SG
117 extern int sg_big_buff
;
121 #include <asm/system.h>
124 #ifdef CONFIG_SPARC64
125 extern int sysctl_tsb_ratio
;
129 extern int pwrsw_enabled
;
130 extern int unaligned_enabled
;
134 #ifdef CONFIG_MATHEMU
135 extern int sysctl_ieee_emulation_warnings
;
137 extern int sysctl_userprocess_debug
;
138 extern int spin_retry
;
141 #ifdef CONFIG_BSD_PROCESS_ACCT
142 extern int acct_parm
[];
146 extern int no_unaligned_warning
;
149 #ifdef CONFIG_RT_MUTEXES
150 extern int max_lock_depth
;
153 #ifdef CONFIG_PROC_SYSCTL
154 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
155 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
156 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
157 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
160 static struct ctl_table root_table
[];
161 static struct ctl_table_root sysctl_table_root
;
162 static struct ctl_table_header root_table_header
= {
164 .ctl_table
= root_table
,
165 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),
166 .root
= &sysctl_table_root
,
167 .set
= &sysctl_table_root
.default_set
,
169 static struct ctl_table_root sysctl_table_root
= {
170 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
171 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
174 static struct ctl_table kern_table
[];
175 static struct ctl_table vm_table
[];
176 static struct ctl_table fs_table
[];
177 static struct ctl_table debug_table
[];
178 static struct ctl_table dev_table
[];
179 extern struct ctl_table random_table
[];
180 #ifdef CONFIG_INOTIFY_USER
181 extern struct ctl_table inotify_table
[];
184 extern struct ctl_table epoll_table
[];
187 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
188 int sysctl_legacy_va_layout
;
191 extern int prove_locking
;
192 extern int lock_stat
;
194 /* The default sysctl tables: */
196 static struct ctl_table root_table
[] = {
198 .ctl_name
= CTL_KERN
,
199 .procname
= "kernel",
216 .ctl_name
= CTL_DEBUG
,
219 .child
= debug_table
,
228 * NOTE: do not add new entries to this table unless you have read
229 * Documentation/sysctl/ctl_unnumbered.txt
234 #ifdef CONFIG_SCHED_DEBUG
235 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
236 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
237 static int min_wakeup_granularity_ns
; /* 0 usecs */
238 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
241 static struct ctl_table kern_table
[] = {
242 #ifdef CONFIG_SCHED_DEBUG
244 .ctl_name
= CTL_UNNUMBERED
,
245 .procname
= "sched_min_granularity_ns",
246 .data
= &sysctl_sched_min_granularity
,
247 .maxlen
= sizeof(unsigned int),
249 .proc_handler
= &sched_nr_latency_handler
,
250 .strategy
= &sysctl_intvec
,
251 .extra1
= &min_sched_granularity_ns
,
252 .extra2
= &max_sched_granularity_ns
,
255 .ctl_name
= CTL_UNNUMBERED
,
256 .procname
= "sched_latency_ns",
257 .data
= &sysctl_sched_latency
,
258 .maxlen
= sizeof(unsigned int),
260 .proc_handler
= &sched_nr_latency_handler
,
261 .strategy
= &sysctl_intvec
,
262 .extra1
= &min_sched_granularity_ns
,
263 .extra2
= &max_sched_granularity_ns
,
266 .ctl_name
= CTL_UNNUMBERED
,
267 .procname
= "sched_wakeup_granularity_ns",
268 .data
= &sysctl_sched_wakeup_granularity
,
269 .maxlen
= sizeof(unsigned int),
271 .proc_handler
= &proc_dointvec_minmax
,
272 .strategy
= &sysctl_intvec
,
273 .extra1
= &min_wakeup_granularity_ns
,
274 .extra2
= &max_wakeup_granularity_ns
,
277 .ctl_name
= CTL_UNNUMBERED
,
278 .procname
= "sched_shares_ratelimit",
279 .data
= &sysctl_sched_shares_ratelimit
,
280 .maxlen
= sizeof(unsigned int),
282 .proc_handler
= &proc_dointvec
,
285 .ctl_name
= CTL_UNNUMBERED
,
286 .procname
= "sched_shares_thresh",
287 .data
= &sysctl_sched_shares_thresh
,
288 .maxlen
= sizeof(unsigned int),
290 .proc_handler
= &proc_dointvec_minmax
,
291 .strategy
= &sysctl_intvec
,
295 .ctl_name
= CTL_UNNUMBERED
,
296 .procname
= "sched_child_runs_first",
297 .data
= &sysctl_sched_child_runs_first
,
298 .maxlen
= sizeof(unsigned int),
300 .proc_handler
= &proc_dointvec
,
303 .ctl_name
= CTL_UNNUMBERED
,
304 .procname
= "sched_features",
305 .data
= &sysctl_sched_features
,
306 .maxlen
= sizeof(unsigned int),
308 .proc_handler
= &proc_dointvec
,
311 .ctl_name
= CTL_UNNUMBERED
,
312 .procname
= "sched_migration_cost",
313 .data
= &sysctl_sched_migration_cost
,
314 .maxlen
= sizeof(unsigned int),
316 .proc_handler
= &proc_dointvec
,
319 .ctl_name
= CTL_UNNUMBERED
,
320 .procname
= "sched_nr_migrate",
321 .data
= &sysctl_sched_nr_migrate
,
322 .maxlen
= sizeof(unsigned int),
324 .proc_handler
= &proc_dointvec
,
328 .ctl_name
= CTL_UNNUMBERED
,
329 .procname
= "sched_rt_period_us",
330 .data
= &sysctl_sched_rt_period
,
331 .maxlen
= sizeof(unsigned int),
333 .proc_handler
= &sched_rt_handler
,
336 .ctl_name
= CTL_UNNUMBERED
,
337 .procname
= "sched_rt_runtime_us",
338 .data
= &sysctl_sched_rt_runtime
,
339 .maxlen
= sizeof(int),
341 .proc_handler
= &sched_rt_handler
,
344 .ctl_name
= CTL_UNNUMBERED
,
345 .procname
= "sched_compat_yield",
346 .data
= &sysctl_sched_compat_yield
,
347 .maxlen
= sizeof(unsigned int),
349 .proc_handler
= &proc_dointvec
,
351 #ifdef CONFIG_PROVE_LOCKING
353 .ctl_name
= CTL_UNNUMBERED
,
354 .procname
= "prove_locking",
355 .data
= &prove_locking
,
356 .maxlen
= sizeof(int),
358 .proc_handler
= &proc_dointvec
,
361 #ifdef CONFIG_LOCK_STAT
363 .ctl_name
= CTL_UNNUMBERED
,
364 .procname
= "lock_stat",
366 .maxlen
= sizeof(int),
368 .proc_handler
= &proc_dointvec
,
372 .ctl_name
= KERN_PANIC
,
374 .data
= &panic_timeout
,
375 .maxlen
= sizeof(int),
377 .proc_handler
= &proc_dointvec
,
380 .ctl_name
= KERN_CORE_USES_PID
,
381 .procname
= "core_uses_pid",
382 .data
= &core_uses_pid
,
383 .maxlen
= sizeof(int),
385 .proc_handler
= &proc_dointvec
,
388 .ctl_name
= KERN_CORE_PATTERN
,
389 .procname
= "core_pattern",
390 .data
= core_pattern
,
391 .maxlen
= CORENAME_MAX_SIZE
,
393 .proc_handler
= &proc_dostring
,
394 .strategy
= &sysctl_string
,
396 #ifdef CONFIG_PROC_SYSCTL
398 .procname
= "tainted",
399 .maxlen
= sizeof(long),
401 .proc_handler
= &proc_taint
,
404 #ifdef CONFIG_LATENCYTOP
406 .procname
= "latencytop",
407 .data
= &latencytop_enabled
,
408 .maxlen
= sizeof(int),
410 .proc_handler
= &proc_dointvec
,
413 #ifdef CONFIG_BLK_DEV_INITRD
415 .ctl_name
= KERN_REALROOTDEV
,
416 .procname
= "real-root-dev",
417 .data
= &real_root_dev
,
418 .maxlen
= sizeof(int),
420 .proc_handler
= &proc_dointvec
,
424 .ctl_name
= CTL_UNNUMBERED
,
425 .procname
= "print-fatal-signals",
426 .data
= &print_fatal_signals
,
427 .maxlen
= sizeof(int),
429 .proc_handler
= &proc_dointvec
,
433 .ctl_name
= KERN_SPARC_REBOOT
,
434 .procname
= "reboot-cmd",
435 .data
= reboot_command
,
438 .proc_handler
= &proc_dostring
,
439 .strategy
= &sysctl_string
,
442 .ctl_name
= KERN_SPARC_STOP_A
,
443 .procname
= "stop-a",
444 .data
= &stop_a_enabled
,
445 .maxlen
= sizeof (int),
447 .proc_handler
= &proc_dointvec
,
450 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
451 .procname
= "scons-poweroff",
452 .data
= &scons_pwroff
,
453 .maxlen
= sizeof (int),
455 .proc_handler
= &proc_dointvec
,
458 #ifdef CONFIG_SPARC64
460 .ctl_name
= CTL_UNNUMBERED
,
461 .procname
= "tsb-ratio",
462 .data
= &sysctl_tsb_ratio
,
463 .maxlen
= sizeof (int),
465 .proc_handler
= &proc_dointvec
,
470 .ctl_name
= KERN_HPPA_PWRSW
,
471 .procname
= "soft-power",
472 .data
= &pwrsw_enabled
,
473 .maxlen
= sizeof (int),
475 .proc_handler
= &proc_dointvec
,
478 .ctl_name
= KERN_HPPA_UNALIGNED
,
479 .procname
= "unaligned-trap",
480 .data
= &unaligned_enabled
,
481 .maxlen
= sizeof (int),
483 .proc_handler
= &proc_dointvec
,
487 .ctl_name
= KERN_CTLALTDEL
,
488 .procname
= "ctrl-alt-del",
490 .maxlen
= sizeof(int),
492 .proc_handler
= &proc_dointvec
,
494 #ifdef CONFIG_FUNCTION_TRACER
496 .ctl_name
= CTL_UNNUMBERED
,
497 .procname
= "ftrace_enabled",
498 .data
= &ftrace_enabled
,
499 .maxlen
= sizeof(int),
501 .proc_handler
= &ftrace_enable_sysctl
,
504 #ifdef CONFIG_MODULES
506 .ctl_name
= KERN_MODPROBE
,
507 .procname
= "modprobe",
508 .data
= &modprobe_path
,
509 .maxlen
= KMOD_PATH_LEN
,
511 .proc_handler
= &proc_dostring
,
512 .strategy
= &sysctl_string
,
515 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
517 .ctl_name
= KERN_HOTPLUG
,
518 .procname
= "hotplug",
519 .data
= &uevent_helper
,
520 .maxlen
= UEVENT_HELPER_PATH_LEN
,
522 .proc_handler
= &proc_dostring
,
523 .strategy
= &sysctl_string
,
526 #ifdef CONFIG_CHR_DEV_SG
528 .ctl_name
= KERN_SG_BIG_BUFF
,
529 .procname
= "sg-big-buff",
530 .data
= &sg_big_buff
,
531 .maxlen
= sizeof (int),
533 .proc_handler
= &proc_dointvec
,
536 #ifdef CONFIG_BSD_PROCESS_ACCT
538 .ctl_name
= KERN_ACCT
,
541 .maxlen
= 3*sizeof(int),
543 .proc_handler
= &proc_dointvec
,
546 #ifdef CONFIG_MAGIC_SYSRQ
548 .ctl_name
= KERN_SYSRQ
,
550 .data
= &__sysrq_enabled
,
551 .maxlen
= sizeof (int),
553 .proc_handler
= &proc_dointvec
,
556 #ifdef CONFIG_PROC_SYSCTL
558 .procname
= "cad_pid",
560 .maxlen
= sizeof (int),
562 .proc_handler
= &proc_do_cad_pid
,
566 .ctl_name
= KERN_MAX_THREADS
,
567 .procname
= "threads-max",
568 .data
= &max_threads
,
569 .maxlen
= sizeof(int),
571 .proc_handler
= &proc_dointvec
,
574 .ctl_name
= KERN_RANDOM
,
575 .procname
= "random",
577 .child
= random_table
,
580 .ctl_name
= KERN_OVERFLOWUID
,
581 .procname
= "overflowuid",
582 .data
= &overflowuid
,
583 .maxlen
= sizeof(int),
585 .proc_handler
= &proc_dointvec_minmax
,
586 .strategy
= &sysctl_intvec
,
587 .extra1
= &minolduid
,
588 .extra2
= &maxolduid
,
591 .ctl_name
= KERN_OVERFLOWGID
,
592 .procname
= "overflowgid",
593 .data
= &overflowgid
,
594 .maxlen
= sizeof(int),
596 .proc_handler
= &proc_dointvec_minmax
,
597 .strategy
= &sysctl_intvec
,
598 .extra1
= &minolduid
,
599 .extra2
= &maxolduid
,
602 #ifdef CONFIG_MATHEMU
604 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
605 .procname
= "ieee_emulation_warnings",
606 .data
= &sysctl_ieee_emulation_warnings
,
607 .maxlen
= sizeof(int),
609 .proc_handler
= &proc_dointvec
,
613 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
614 .procname
= "userprocess_debug",
615 .data
= &sysctl_userprocess_debug
,
616 .maxlen
= sizeof(int),
618 .proc_handler
= &proc_dointvec
,
622 .ctl_name
= KERN_PIDMAX
,
623 .procname
= "pid_max",
625 .maxlen
= sizeof (int),
627 .proc_handler
= &proc_dointvec_minmax
,
628 .strategy
= sysctl_intvec
,
629 .extra1
= &pid_max_min
,
630 .extra2
= &pid_max_max
,
633 .ctl_name
= KERN_PANIC_ON_OOPS
,
634 .procname
= "panic_on_oops",
635 .data
= &panic_on_oops
,
636 .maxlen
= sizeof(int),
638 .proc_handler
= &proc_dointvec
,
640 #if defined CONFIG_PRINTK
642 .ctl_name
= KERN_PRINTK
,
643 .procname
= "printk",
644 .data
= &console_loglevel
,
645 .maxlen
= 4*sizeof(int),
647 .proc_handler
= &proc_dointvec
,
650 .ctl_name
= KERN_PRINTK_RATELIMIT
,
651 .procname
= "printk_ratelimit",
652 .data
= &printk_ratelimit_state
.interval
,
653 .maxlen
= sizeof(int),
655 .proc_handler
= &proc_dointvec_jiffies
,
656 .strategy
= &sysctl_jiffies
,
659 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
660 .procname
= "printk_ratelimit_burst",
661 .data
= &printk_ratelimit_state
.burst
,
662 .maxlen
= sizeof(int),
664 .proc_handler
= &proc_dointvec
,
668 .ctl_name
= KERN_NGROUPS_MAX
,
669 .procname
= "ngroups_max",
670 .data
= &ngroups_max
,
671 .maxlen
= sizeof (int),
673 .proc_handler
= &proc_dointvec
,
675 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
677 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
678 .procname
= "unknown_nmi_panic",
679 .data
= &unknown_nmi_panic
,
680 .maxlen
= sizeof (int),
682 .proc_handler
= &proc_dointvec
,
685 .procname
= "nmi_watchdog",
686 .data
= &nmi_watchdog_enabled
,
687 .maxlen
= sizeof (int),
689 .proc_handler
= &proc_nmi_enabled
,
692 #if defined(CONFIG_X86)
694 .ctl_name
= KERN_PANIC_ON_NMI
,
695 .procname
= "panic_on_unrecovered_nmi",
696 .data
= &panic_on_unrecovered_nmi
,
697 .maxlen
= sizeof(int),
699 .proc_handler
= &proc_dointvec
,
702 .ctl_name
= KERN_BOOTLOADER_TYPE
,
703 .procname
= "bootloader_type",
704 .data
= &bootloader_type
,
705 .maxlen
= sizeof (int),
707 .proc_handler
= &proc_dointvec
,
710 .ctl_name
= CTL_UNNUMBERED
,
711 .procname
= "kstack_depth_to_print",
712 .data
= &kstack_depth_to_print
,
713 .maxlen
= sizeof(int),
715 .proc_handler
= &proc_dointvec
,
718 .ctl_name
= CTL_UNNUMBERED
,
719 .procname
= "io_delay_type",
720 .data
= &io_delay_type
,
721 .maxlen
= sizeof(int),
723 .proc_handler
= &proc_dointvec
,
726 #if defined(CONFIG_MMU)
728 .ctl_name
= KERN_RANDOMIZE
,
729 .procname
= "randomize_va_space",
730 .data
= &randomize_va_space
,
731 .maxlen
= sizeof(int),
733 .proc_handler
= &proc_dointvec
,
736 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
738 .ctl_name
= KERN_SPIN_RETRY
,
739 .procname
= "spin_retry",
741 .maxlen
= sizeof (int),
743 .proc_handler
= &proc_dointvec
,
746 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
748 .procname
= "acpi_video_flags",
749 .data
= &acpi_realmode_flags
,
750 .maxlen
= sizeof (unsigned long),
752 .proc_handler
= &proc_doulongvec_minmax
,
757 .ctl_name
= KERN_IA64_UNALIGNED
,
758 .procname
= "ignore-unaligned-usertrap",
759 .data
= &no_unaligned_warning
,
760 .maxlen
= sizeof (int),
762 .proc_handler
= &proc_dointvec
,
765 #ifdef CONFIG_DETECT_SOFTLOCKUP
767 .ctl_name
= CTL_UNNUMBERED
,
768 .procname
= "softlockup_panic",
769 .data
= &softlockup_panic
,
770 .maxlen
= sizeof(int),
772 .proc_handler
= &proc_dointvec_minmax
,
773 .strategy
= &sysctl_intvec
,
778 .ctl_name
= CTL_UNNUMBERED
,
779 .procname
= "softlockup_thresh",
780 .data
= &softlockup_thresh
,
781 .maxlen
= sizeof(int),
783 .proc_handler
= &proc_dointvec_minmax
,
784 .strategy
= &sysctl_intvec
,
789 .ctl_name
= CTL_UNNUMBERED
,
790 .procname
= "hung_task_check_count",
791 .data
= &sysctl_hung_task_check_count
,
792 .maxlen
= sizeof(unsigned long),
794 .proc_handler
= &proc_doulongvec_minmax
,
795 .strategy
= &sysctl_intvec
,
798 .ctl_name
= CTL_UNNUMBERED
,
799 .procname
= "hung_task_timeout_secs",
800 .data
= &sysctl_hung_task_timeout_secs
,
801 .maxlen
= sizeof(unsigned long),
803 .proc_handler
= &proc_doulongvec_minmax
,
804 .strategy
= &sysctl_intvec
,
807 .ctl_name
= CTL_UNNUMBERED
,
808 .procname
= "hung_task_warnings",
809 .data
= &sysctl_hung_task_warnings
,
810 .maxlen
= sizeof(unsigned long),
812 .proc_handler
= &proc_doulongvec_minmax
,
813 .strategy
= &sysctl_intvec
,
818 .ctl_name
= KERN_COMPAT_LOG
,
819 .procname
= "compat-log",
821 .maxlen
= sizeof (int),
823 .proc_handler
= &proc_dointvec
,
826 #ifdef CONFIG_RT_MUTEXES
828 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
829 .procname
= "max_lock_depth",
830 .data
= &max_lock_depth
,
831 .maxlen
= sizeof(int),
833 .proc_handler
= &proc_dointvec
,
837 .ctl_name
= CTL_UNNUMBERED
,
838 .procname
= "poweroff_cmd",
839 .data
= &poweroff_cmd
,
840 .maxlen
= POWEROFF_CMD_PATH_LEN
,
842 .proc_handler
= &proc_dostring
,
843 .strategy
= &sysctl_string
,
847 .ctl_name
= CTL_UNNUMBERED
,
850 .child
= key_sysctls
,
853 #ifdef CONFIG_RCU_TORTURE_TEST
855 .ctl_name
= CTL_UNNUMBERED
,
856 .procname
= "rcutorture_runnable",
857 .data
= &rcutorture_runnable
,
858 .maxlen
= sizeof(int),
860 .proc_handler
= &proc_dointvec
,
863 #ifdef CONFIG_UNEVICTABLE_LRU
865 .ctl_name
= CTL_UNNUMBERED
,
866 .procname
= "scan_unevictable_pages",
867 .data
= &scan_unevictable_pages
,
868 .maxlen
= sizeof(scan_unevictable_pages
),
870 .proc_handler
= &scan_unevictable_handler
,
874 * NOTE: do not add new entries to this table unless you have read
875 * Documentation/sysctl/ctl_unnumbered.txt
880 static struct ctl_table vm_table
[] = {
882 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
883 .procname
= "overcommit_memory",
884 .data
= &sysctl_overcommit_memory
,
885 .maxlen
= sizeof(sysctl_overcommit_memory
),
887 .proc_handler
= &proc_dointvec
,
890 .ctl_name
= VM_PANIC_ON_OOM
,
891 .procname
= "panic_on_oom",
892 .data
= &sysctl_panic_on_oom
,
893 .maxlen
= sizeof(sysctl_panic_on_oom
),
895 .proc_handler
= &proc_dointvec
,
898 .ctl_name
= CTL_UNNUMBERED
,
899 .procname
= "oom_kill_allocating_task",
900 .data
= &sysctl_oom_kill_allocating_task
,
901 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
903 .proc_handler
= &proc_dointvec
,
906 .ctl_name
= CTL_UNNUMBERED
,
907 .procname
= "oom_dump_tasks",
908 .data
= &sysctl_oom_dump_tasks
,
909 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
911 .proc_handler
= &proc_dointvec
,
914 .ctl_name
= VM_OVERCOMMIT_RATIO
,
915 .procname
= "overcommit_ratio",
916 .data
= &sysctl_overcommit_ratio
,
917 .maxlen
= sizeof(sysctl_overcommit_ratio
),
919 .proc_handler
= &proc_dointvec
,
922 .ctl_name
= VM_PAGE_CLUSTER
,
923 .procname
= "page-cluster",
924 .data
= &page_cluster
,
925 .maxlen
= sizeof(int),
927 .proc_handler
= &proc_dointvec
,
930 .ctl_name
= VM_DIRTY_BACKGROUND
,
931 .procname
= "dirty_background_ratio",
932 .data
= &dirty_background_ratio
,
933 .maxlen
= sizeof(dirty_background_ratio
),
935 .proc_handler
= &proc_dointvec_minmax
,
936 .strategy
= &sysctl_intvec
,
938 .extra2
= &one_hundred
,
941 .ctl_name
= VM_DIRTY_RATIO
,
942 .procname
= "dirty_ratio",
943 .data
= &vm_dirty_ratio
,
944 .maxlen
= sizeof(vm_dirty_ratio
),
946 .proc_handler
= &dirty_ratio_handler
,
947 .strategy
= &sysctl_intvec
,
949 .extra2
= &one_hundred
,
952 .procname
= "dirty_writeback_centisecs",
953 .data
= &dirty_writeback_interval
,
954 .maxlen
= sizeof(dirty_writeback_interval
),
956 .proc_handler
= &dirty_writeback_centisecs_handler
,
959 .procname
= "dirty_expire_centisecs",
960 .data
= &dirty_expire_interval
,
961 .maxlen
= sizeof(dirty_expire_interval
),
963 .proc_handler
= &proc_dointvec_userhz_jiffies
,
966 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
967 .procname
= "nr_pdflush_threads",
968 .data
= &nr_pdflush_threads
,
969 .maxlen
= sizeof nr_pdflush_threads
,
970 .mode
= 0444 /* read-only*/,
971 .proc_handler
= &proc_dointvec
,
974 .ctl_name
= VM_SWAPPINESS
,
975 .procname
= "swappiness",
976 .data
= &vm_swappiness
,
977 .maxlen
= sizeof(vm_swappiness
),
979 .proc_handler
= &proc_dointvec_minmax
,
980 .strategy
= &sysctl_intvec
,
982 .extra2
= &one_hundred
,
984 #ifdef CONFIG_HUGETLB_PAGE
986 .procname
= "nr_hugepages",
988 .maxlen
= sizeof(unsigned long),
990 .proc_handler
= &hugetlb_sysctl_handler
,
991 .extra1
= (void *)&hugetlb_zero
,
992 .extra2
= (void *)&hugetlb_infinity
,
995 .ctl_name
= VM_HUGETLB_GROUP
,
996 .procname
= "hugetlb_shm_group",
997 .data
= &sysctl_hugetlb_shm_group
,
998 .maxlen
= sizeof(gid_t
),
1000 .proc_handler
= &proc_dointvec
,
1003 .ctl_name
= CTL_UNNUMBERED
,
1004 .procname
= "hugepages_treat_as_movable",
1005 .data
= &hugepages_treat_as_movable
,
1006 .maxlen
= sizeof(int),
1008 .proc_handler
= &hugetlb_treat_movable_handler
,
1011 .ctl_name
= CTL_UNNUMBERED
,
1012 .procname
= "nr_overcommit_hugepages",
1014 .maxlen
= sizeof(unsigned long),
1016 .proc_handler
= &hugetlb_overcommit_handler
,
1017 .extra1
= (void *)&hugetlb_zero
,
1018 .extra2
= (void *)&hugetlb_infinity
,
1022 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
1023 .procname
= "lowmem_reserve_ratio",
1024 .data
= &sysctl_lowmem_reserve_ratio
,
1025 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1027 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
1028 .strategy
= &sysctl_intvec
,
1031 .ctl_name
= VM_DROP_PAGECACHE
,
1032 .procname
= "drop_caches",
1033 .data
= &sysctl_drop_caches
,
1034 .maxlen
= sizeof(int),
1036 .proc_handler
= drop_caches_sysctl_handler
,
1037 .strategy
= &sysctl_intvec
,
1040 .ctl_name
= VM_MIN_FREE_KBYTES
,
1041 .procname
= "min_free_kbytes",
1042 .data
= &min_free_kbytes
,
1043 .maxlen
= sizeof(min_free_kbytes
),
1045 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1046 .strategy
= &sysctl_intvec
,
1050 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1051 .procname
= "percpu_pagelist_fraction",
1052 .data
= &percpu_pagelist_fraction
,
1053 .maxlen
= sizeof(percpu_pagelist_fraction
),
1055 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1056 .strategy
= &sysctl_intvec
,
1057 .extra1
= &min_percpu_pagelist_fract
,
1061 .ctl_name
= VM_MAX_MAP_COUNT
,
1062 .procname
= "max_map_count",
1063 .data
= &sysctl_max_map_count
,
1064 .maxlen
= sizeof(sysctl_max_map_count
),
1066 .proc_handler
= &proc_dointvec
1070 .ctl_name
= VM_LAPTOP_MODE
,
1071 .procname
= "laptop_mode",
1072 .data
= &laptop_mode
,
1073 .maxlen
= sizeof(laptop_mode
),
1075 .proc_handler
= &proc_dointvec_jiffies
,
1076 .strategy
= &sysctl_jiffies
,
1079 .ctl_name
= VM_BLOCK_DUMP
,
1080 .procname
= "block_dump",
1081 .data
= &block_dump
,
1082 .maxlen
= sizeof(block_dump
),
1084 .proc_handler
= &proc_dointvec
,
1085 .strategy
= &sysctl_intvec
,
1089 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1090 .procname
= "vfs_cache_pressure",
1091 .data
= &sysctl_vfs_cache_pressure
,
1092 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1094 .proc_handler
= &proc_dointvec
,
1095 .strategy
= &sysctl_intvec
,
1098 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1100 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1101 .procname
= "legacy_va_layout",
1102 .data
= &sysctl_legacy_va_layout
,
1103 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1105 .proc_handler
= &proc_dointvec
,
1106 .strategy
= &sysctl_intvec
,
1112 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1113 .procname
= "zone_reclaim_mode",
1114 .data
= &zone_reclaim_mode
,
1115 .maxlen
= sizeof(zone_reclaim_mode
),
1117 .proc_handler
= &proc_dointvec
,
1118 .strategy
= &sysctl_intvec
,
1122 .ctl_name
= VM_MIN_UNMAPPED
,
1123 .procname
= "min_unmapped_ratio",
1124 .data
= &sysctl_min_unmapped_ratio
,
1125 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1127 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1128 .strategy
= &sysctl_intvec
,
1130 .extra2
= &one_hundred
,
1133 .ctl_name
= VM_MIN_SLAB
,
1134 .procname
= "min_slab_ratio",
1135 .data
= &sysctl_min_slab_ratio
,
1136 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1138 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1139 .strategy
= &sysctl_intvec
,
1141 .extra2
= &one_hundred
,
1146 .ctl_name
= CTL_UNNUMBERED
,
1147 .procname
= "stat_interval",
1148 .data
= &sysctl_stat_interval
,
1149 .maxlen
= sizeof(sysctl_stat_interval
),
1151 .proc_handler
= &proc_dointvec_jiffies
,
1152 .strategy
= &sysctl_jiffies
,
1155 #ifdef CONFIG_SECURITY
1157 .ctl_name
= CTL_UNNUMBERED
,
1158 .procname
= "mmap_min_addr",
1159 .data
= &mmap_min_addr
,
1160 .maxlen
= sizeof(unsigned long),
1162 .proc_handler
= &proc_doulongvec_minmax
,
1167 .ctl_name
= CTL_UNNUMBERED
,
1168 .procname
= "numa_zonelist_order",
1169 .data
= &numa_zonelist_order
,
1170 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1172 .proc_handler
= &numa_zonelist_order_handler
,
1173 .strategy
= &sysctl_string
,
1176 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1177 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1179 .ctl_name
= VM_VDSO_ENABLED
,
1180 .procname
= "vdso_enabled",
1181 .data
= &vdso_enabled
,
1182 .maxlen
= sizeof(vdso_enabled
),
1184 .proc_handler
= &proc_dointvec
,
1185 .strategy
= &sysctl_intvec
,
1189 #ifdef CONFIG_HIGHMEM
1191 .ctl_name
= CTL_UNNUMBERED
,
1192 .procname
= "highmem_is_dirtyable",
1193 .data
= &vm_highmem_is_dirtyable
,
1194 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1196 .proc_handler
= &proc_dointvec_minmax
,
1197 .strategy
= &sysctl_intvec
,
1203 * NOTE: do not add new entries to this table unless you have read
1204 * Documentation/sysctl/ctl_unnumbered.txt
1209 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1210 static struct ctl_table binfmt_misc_table
[] = {
1215 static struct ctl_table fs_table
[] = {
1217 .ctl_name
= FS_NRINODE
,
1218 .procname
= "inode-nr",
1219 .data
= &inodes_stat
,
1220 .maxlen
= 2*sizeof(int),
1222 .proc_handler
= &proc_dointvec
,
1225 .ctl_name
= FS_STATINODE
,
1226 .procname
= "inode-state",
1227 .data
= &inodes_stat
,
1228 .maxlen
= 7*sizeof(int),
1230 .proc_handler
= &proc_dointvec
,
1233 .procname
= "file-nr",
1234 .data
= &files_stat
,
1235 .maxlen
= 3*sizeof(int),
1237 .proc_handler
= &proc_nr_files
,
1240 .ctl_name
= FS_MAXFILE
,
1241 .procname
= "file-max",
1242 .data
= &files_stat
.max_files
,
1243 .maxlen
= sizeof(int),
1245 .proc_handler
= &proc_dointvec
,
1248 .ctl_name
= CTL_UNNUMBERED
,
1249 .procname
= "nr_open",
1250 .data
= &sysctl_nr_open
,
1251 .maxlen
= sizeof(int),
1253 .proc_handler
= &proc_dointvec_minmax
,
1254 .extra1
= &sysctl_nr_open_min
,
1255 .extra2
= &sysctl_nr_open_max
,
1258 .ctl_name
= FS_DENTRY
,
1259 .procname
= "dentry-state",
1260 .data
= &dentry_stat
,
1261 .maxlen
= 6*sizeof(int),
1263 .proc_handler
= &proc_dointvec
,
1266 .ctl_name
= FS_OVERFLOWUID
,
1267 .procname
= "overflowuid",
1268 .data
= &fs_overflowuid
,
1269 .maxlen
= sizeof(int),
1271 .proc_handler
= &proc_dointvec_minmax
,
1272 .strategy
= &sysctl_intvec
,
1273 .extra1
= &minolduid
,
1274 .extra2
= &maxolduid
,
1277 .ctl_name
= FS_OVERFLOWGID
,
1278 .procname
= "overflowgid",
1279 .data
= &fs_overflowgid
,
1280 .maxlen
= sizeof(int),
1282 .proc_handler
= &proc_dointvec_minmax
,
1283 .strategy
= &sysctl_intvec
,
1284 .extra1
= &minolduid
,
1285 .extra2
= &maxolduid
,
1287 #ifdef CONFIG_FILE_LOCKING
1289 .ctl_name
= FS_LEASES
,
1290 .procname
= "leases-enable",
1291 .data
= &leases_enable
,
1292 .maxlen
= sizeof(int),
1294 .proc_handler
= &proc_dointvec
,
1297 #ifdef CONFIG_DNOTIFY
1299 .ctl_name
= FS_DIR_NOTIFY
,
1300 .procname
= "dir-notify-enable",
1301 .data
= &dir_notify_enable
,
1302 .maxlen
= sizeof(int),
1304 .proc_handler
= &proc_dointvec
,
1308 #ifdef CONFIG_FILE_LOCKING
1310 .ctl_name
= FS_LEASE_TIME
,
1311 .procname
= "lease-break-time",
1312 .data
= &lease_break_time
,
1313 .maxlen
= sizeof(int),
1315 .proc_handler
= &proc_dointvec_minmax
,
1316 .strategy
= &sysctl_intvec
,
1323 .procname
= "aio-nr",
1325 .maxlen
= sizeof(aio_nr
),
1327 .proc_handler
= &proc_doulongvec_minmax
,
1330 .procname
= "aio-max-nr",
1331 .data
= &aio_max_nr
,
1332 .maxlen
= sizeof(aio_max_nr
),
1334 .proc_handler
= &proc_doulongvec_minmax
,
1336 #endif /* CONFIG_AIO */
1337 #ifdef CONFIG_INOTIFY_USER
1339 .ctl_name
= FS_INOTIFY
,
1340 .procname
= "inotify",
1342 .child
= inotify_table
,
1347 .procname
= "epoll",
1349 .child
= epoll_table
,
1354 .ctl_name
= KERN_SETUID_DUMPABLE
,
1355 .procname
= "suid_dumpable",
1356 .data
= &suid_dumpable
,
1357 .maxlen
= sizeof(int),
1359 .proc_handler
= &proc_dointvec
,
1361 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1363 .ctl_name
= CTL_UNNUMBERED
,
1364 .procname
= "binfmt_misc",
1366 .child
= binfmt_misc_table
,
1370 * NOTE: do not add new entries to this table unless you have read
1371 * Documentation/sysctl/ctl_unnumbered.txt
1376 static struct ctl_table debug_table
[] = {
1377 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1379 .ctl_name
= CTL_UNNUMBERED
,
1380 .procname
= "exception-trace",
1381 .data
= &show_unhandled_signals
,
1382 .maxlen
= sizeof(int),
1384 .proc_handler
= proc_dointvec
1390 static struct ctl_table dev_table
[] = {
1394 static DEFINE_SPINLOCK(sysctl_lock
);
1396 /* called under sysctl_lock */
1397 static int use_table(struct ctl_table_header
*p
)
1399 if (unlikely(p
->unregistering
))
1405 /* called under sysctl_lock */
1406 static void unuse_table(struct ctl_table_header
*p
)
1409 if (unlikely(p
->unregistering
))
1410 complete(p
->unregistering
);
1413 /* called under sysctl_lock, will reacquire if has to wait */
1414 static void start_unregistering(struct ctl_table_header
*p
)
1417 * if p->used is 0, nobody will ever touch that entry again;
1418 * we'll eliminate all paths to it before dropping sysctl_lock
1420 if (unlikely(p
->used
)) {
1421 struct completion wait
;
1422 init_completion(&wait
);
1423 p
->unregistering
= &wait
;
1424 spin_unlock(&sysctl_lock
);
1425 wait_for_completion(&wait
);
1426 spin_lock(&sysctl_lock
);
1428 /* anything non-NULL; we'll never dereference it */
1429 p
->unregistering
= ERR_PTR(-EINVAL
);
1432 * do not remove from the list until nobody holds it; walking the
1433 * list in do_sysctl() relies on that.
1435 list_del_init(&p
->ctl_entry
);
1438 void sysctl_head_get(struct ctl_table_header
*head
)
1440 spin_lock(&sysctl_lock
);
1442 spin_unlock(&sysctl_lock
);
1445 void sysctl_head_put(struct ctl_table_header
*head
)
1447 spin_lock(&sysctl_lock
);
1450 spin_unlock(&sysctl_lock
);
1453 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1457 spin_lock(&sysctl_lock
);
1458 if (!use_table(head
))
1459 head
= ERR_PTR(-ENOENT
);
1460 spin_unlock(&sysctl_lock
);
1464 void sysctl_head_finish(struct ctl_table_header
*head
)
1468 spin_lock(&sysctl_lock
);
1470 spin_unlock(&sysctl_lock
);
1473 static struct ctl_table_set
*
1474 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1476 struct ctl_table_set
*set
= &root
->default_set
;
1478 set
= root
->lookup(root
, namespaces
);
1482 static struct list_head
*
1483 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1485 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1489 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1490 struct ctl_table_header
*prev
)
1492 struct ctl_table_root
*root
;
1493 struct list_head
*header_list
;
1494 struct ctl_table_header
*head
;
1495 struct list_head
*tmp
;
1497 spin_lock(&sysctl_lock
);
1500 tmp
= &prev
->ctl_entry
;
1504 tmp
= &root_table_header
.ctl_entry
;
1506 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1508 if (!use_table(head
))
1510 spin_unlock(&sysctl_lock
);
1515 header_list
= lookup_header_list(root
, namespaces
);
1516 if (tmp
!= header_list
)
1520 root
= list_entry(root
->root_list
.next
,
1521 struct ctl_table_root
, root_list
);
1522 if (root
== &sysctl_table_root
)
1524 header_list
= lookup_header_list(root
, namespaces
);
1525 } while (list_empty(header_list
));
1526 tmp
= header_list
->next
;
1529 spin_unlock(&sysctl_lock
);
1533 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1535 return __sysctl_head_next(current
->nsproxy
, prev
);
1538 void register_sysctl_root(struct ctl_table_root
*root
)
1540 spin_lock(&sysctl_lock
);
1541 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1542 spin_unlock(&sysctl_lock
);
1545 #ifdef CONFIG_SYSCTL_SYSCALL
1546 /* Perform the actual read/write of a sysctl table entry. */
1547 static int do_sysctl_strategy(struct ctl_table_root
*root
,
1548 struct ctl_table
*table
,
1549 void __user
*oldval
, size_t __user
*oldlenp
,
1550 void __user
*newval
, size_t newlen
)
1558 if (sysctl_perm(root
, table
, op
))
1561 if (table
->strategy
) {
1562 rc
= table
->strategy(table
, oldval
, oldlenp
, newval
, newlen
);
1569 /* If there is no strategy routine, or if the strategy returns
1570 * zero, proceed with automatic r/w */
1571 if (table
->data
&& table
->maxlen
) {
1572 rc
= sysctl_data(table
, oldval
, oldlenp
, newval
, newlen
);
1579 static int parse_table(int __user
*name
, int nlen
,
1580 void __user
*oldval
, size_t __user
*oldlenp
,
1581 void __user
*newval
, size_t newlen
,
1582 struct ctl_table_root
*root
,
1583 struct ctl_table
*table
)
1589 if (get_user(n
, name
))
1591 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1592 if (!table
->ctl_name
)
1594 if (n
== table
->ctl_name
) {
1597 if (sysctl_perm(root
, table
, MAY_EXEC
))
1601 table
= table
->child
;
1604 error
= do_sysctl_strategy(root
, table
,
1613 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1614 void __user
*newval
, size_t newlen
)
1616 struct ctl_table_header
*head
;
1617 int error
= -ENOTDIR
;
1619 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1623 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1627 for (head
= sysctl_head_next(NULL
); head
;
1628 head
= sysctl_head_next(head
)) {
1629 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1631 head
->root
, head
->ctl_table
);
1632 if (error
!= -ENOTDIR
) {
1633 sysctl_head_finish(head
);
1640 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1642 struct __sysctl_args tmp
;
1645 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1648 error
= deprecated_sysctl_warning(&tmp
);
1653 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1654 tmp
.newval
, tmp
.newlen
);
1659 #endif /* CONFIG_SYSCTL_SYSCALL */
1662 * sysctl_perm does NOT grant the superuser all rights automatically, because
1663 * some sysctl variables are readonly even to root.
1666 static int test_perm(int mode
, int op
)
1670 else if (in_egroup_p(0))
1672 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1677 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1682 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1686 if (root
->permissions
)
1687 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1691 return test_perm(mode
, op
);
1694 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1696 for (; table
->ctl_name
|| table
->procname
; table
++) {
1697 table
->parent
= parent
;
1699 sysctl_set_parent(table
, table
->child
);
1703 static __init
int sysctl_init(void)
1705 sysctl_set_parent(NULL
, root_table
);
1706 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1709 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1715 core_initcall(sysctl_init
);
1717 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1718 struct ctl_table
*table
)
1720 struct ctl_table
*p
;
1721 const char *s
= branch
->procname
;
1723 /* branch should have named subdirectory as its first element */
1724 if (!s
|| !branch
->child
)
1727 /* ... and nothing else */
1728 if (branch
[1].procname
|| branch
[1].ctl_name
)
1731 /* table should contain subdirectory with the same name */
1732 for (p
= table
; p
->procname
|| p
->ctl_name
; p
++) {
1735 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1741 /* see if attaching q to p would be an improvement */
1742 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1744 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1745 struct ctl_table
*next
;
1747 int not_in_parent
= !p
->attached_by
;
1749 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1750 if (by
== q
->attached_by
)
1752 if (to
== p
->attached_by
)
1758 if (is_better
&& not_in_parent
) {
1759 q
->attached_by
= by
;
1760 q
->attached_to
= to
;
1766 * __register_sysctl_paths - register a sysctl hierarchy
1767 * @root: List of sysctl headers to register on
1768 * @namespaces: Data to compute which lists of sysctl entries are visible
1769 * @path: The path to the directory the sysctl table is in.
1770 * @table: the top-level table structure
1772 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1773 * array. A completely 0 filled entry terminates the table.
1775 * The members of the &struct ctl_table structure are used as follows:
1777 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1778 * must be unique within that level of sysctl
1780 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1781 * enter a sysctl file
1783 * data - a pointer to data for use by proc_handler
1785 * maxlen - the maximum size in bytes of the data
1787 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1789 * child - a pointer to the child sysctl table if this entry is a directory, or
1792 * proc_handler - the text handler routine (described below)
1794 * strategy - the strategy routine (described below)
1796 * de - for internal use by the sysctl routines
1798 * extra1, extra2 - extra pointers usable by the proc handler routines
1800 * Leaf nodes in the sysctl tree will be represented by a single file
1801 * under /proc; non-leaf nodes will be represented by directories.
1803 * sysctl(2) can automatically manage read and write requests through
1804 * the sysctl table. The data and maxlen fields of the ctl_table
1805 * struct enable minimal validation of the values being written to be
1806 * performed, and the mode field allows minimal authentication.
1808 * More sophisticated management can be enabled by the provision of a
1809 * strategy routine with the table entry. This will be called before
1810 * any automatic read or write of the data is performed.
1812 * The strategy routine may return
1814 * < 0 - Error occurred (error is passed to user process)
1816 * 0 - OK - proceed with automatic read or write.
1818 * > 0 - OK - read or write has been done by the strategy routine, so
1819 * return immediately.
1821 * There must be a proc_handler routine for any terminal nodes
1822 * mirrored under /proc/sys (non-terminals are handled by a built-in
1823 * directory handler). Several default handlers are available to
1824 * cover common cases -
1826 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1827 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1828 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1830 * It is the handler's job to read the input buffer from user memory
1831 * and process it. The handler should return 0 on success.
1833 * This routine returns %NULL on a failure to register, and a pointer
1834 * to the table header on success.
1836 struct ctl_table_header
*__register_sysctl_paths(
1837 struct ctl_table_root
*root
,
1838 struct nsproxy
*namespaces
,
1839 const struct ctl_path
*path
, struct ctl_table
*table
)
1841 struct ctl_table_header
*header
;
1842 struct ctl_table
*new, **prevp
;
1843 unsigned int n
, npath
;
1844 struct ctl_table_set
*set
;
1846 /* Count the path components */
1847 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
1851 * For each path component, allocate a 2-element ctl_table array.
1852 * The first array element will be filled with the sysctl entry
1853 * for this, the second will be the sentinel (ctl_name == 0).
1855 * We allocate everything in one go so that we don't have to
1856 * worry about freeing additional memory in unregister_sysctl_table.
1858 header
= kzalloc(sizeof(struct ctl_table_header
) +
1859 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1863 new = (struct ctl_table
*) (header
+ 1);
1865 /* Now connect the dots */
1866 prevp
= &header
->ctl_table
;
1867 for (n
= 0; n
< npath
; ++n
, ++path
) {
1868 /* Copy the procname */
1869 new->procname
= path
->procname
;
1870 new->ctl_name
= path
->ctl_name
;
1874 prevp
= &new->child
;
1879 header
->ctl_table_arg
= table
;
1881 INIT_LIST_HEAD(&header
->ctl_entry
);
1883 header
->unregistering
= NULL
;
1884 header
->root
= root
;
1885 sysctl_set_parent(NULL
, header
->ctl_table
);
1887 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1888 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1893 spin_lock(&sysctl_lock
);
1894 header
->set
= lookup_header_set(root
, namespaces
);
1895 header
->attached_by
= header
->ctl_table
;
1896 header
->attached_to
= root_table
;
1897 header
->parent
= &root_table_header
;
1898 for (set
= header
->set
; set
; set
= set
->parent
) {
1899 struct ctl_table_header
*p
;
1900 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
1901 if (p
->unregistering
)
1903 try_attach(p
, header
);
1906 header
->parent
->count
++;
1907 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
1908 spin_unlock(&sysctl_lock
);
1914 * register_sysctl_table_path - register a sysctl table hierarchy
1915 * @path: The path to the directory the sysctl table is in.
1916 * @table: the top-level table structure
1918 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1919 * array. A completely 0 filled entry terminates the table.
1921 * See __register_sysctl_paths for more details.
1923 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1924 struct ctl_table
*table
)
1926 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1931 * register_sysctl_table - register a sysctl table hierarchy
1932 * @table: the top-level table structure
1934 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1935 * array. A completely 0 filled entry terminates the table.
1937 * See register_sysctl_paths for more details.
1939 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1941 static const struct ctl_path null_path
[] = { {} };
1943 return register_sysctl_paths(null_path
, table
);
1947 * unregister_sysctl_table - unregister a sysctl table hierarchy
1948 * @header: the header returned from register_sysctl_table
1950 * Unregisters the sysctl table and all children. proc entries may not
1951 * actually be removed until they are no longer used by anyone.
1953 void unregister_sysctl_table(struct ctl_table_header
* header
)
1960 spin_lock(&sysctl_lock
);
1961 start_unregistering(header
);
1962 if (!--header
->parent
->count
) {
1964 kfree(header
->parent
);
1966 if (!--header
->count
)
1968 spin_unlock(&sysctl_lock
);
1971 int sysctl_is_seen(struct ctl_table_header
*p
)
1973 struct ctl_table_set
*set
= p
->set
;
1975 spin_lock(&sysctl_lock
);
1976 if (p
->unregistering
)
1978 else if (!set
->is_seen
)
1981 res
= set
->is_seen(set
);
1982 spin_unlock(&sysctl_lock
);
1986 void setup_sysctl_set(struct ctl_table_set
*p
,
1987 struct ctl_table_set
*parent
,
1988 int (*is_seen
)(struct ctl_table_set
*))
1990 INIT_LIST_HEAD(&p
->list
);
1991 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
1992 p
->is_seen
= is_seen
;
1995 #else /* !CONFIG_SYSCTL */
1996 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
2001 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2002 struct ctl_table
*table
)
2007 void unregister_sysctl_table(struct ctl_table_header
* table
)
2011 void setup_sysctl_set(struct ctl_table_set
*p
,
2012 struct ctl_table_set
*parent
,
2013 int (*is_seen
)(struct ctl_table_set
*))
2017 void sysctl_head_put(struct ctl_table_header
*head
)
2021 #endif /* CONFIG_SYSCTL */
2027 #ifdef CONFIG_PROC_SYSCTL
2029 static int _proc_do_string(void* data
, int maxlen
, int write
,
2030 struct file
*filp
, void __user
*buffer
,
2031 size_t *lenp
, loff_t
*ppos
)
2037 if (!data
|| !maxlen
|| !*lenp
) {
2045 while (len
< *lenp
) {
2046 if (get_user(c
, p
++))
2048 if (c
== 0 || c
== '\n')
2054 if(copy_from_user(data
, buffer
, len
))
2056 ((char *) data
)[len
] = 0;
2074 if(copy_to_user(buffer
, data
, len
))
2077 if(put_user('\n', ((char __user
*) buffer
) + len
))
2088 * proc_dostring - read a string sysctl
2089 * @table: the sysctl table
2090 * @write: %TRUE if this is a write to the sysctl file
2091 * @filp: the file structure
2092 * @buffer: the user buffer
2093 * @lenp: the size of the user buffer
2094 * @ppos: file position
2096 * Reads/writes a string from/to the user buffer. If the kernel
2097 * buffer provided is not large enough to hold the string, the
2098 * string is truncated. The copied string is %NULL-terminated.
2099 * If the string is being read by the user process, it is copied
2100 * and a newline '\n' is added. It is truncated if the buffer is
2103 * Returns 0 on success.
2105 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2106 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2108 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
2109 buffer
, lenp
, ppos
);
2113 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
2115 int write
, void *data
)
2118 *valp
= *negp
? -*lvalp
: *lvalp
;
2123 *lvalp
= (unsigned long)-val
;
2126 *lvalp
= (unsigned long)val
;
2132 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2133 int write
, struct file
*filp
, void __user
*buffer
,
2134 size_t *lenp
, loff_t
*ppos
,
2135 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2136 int write
, void *data
),
2139 #define TMPBUFLEN 21
2140 int *i
, vleft
, first
=1, neg
, val
;
2144 char buf
[TMPBUFLEN
], *p
;
2145 char __user
*s
= buffer
;
2147 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
2148 (*ppos
&& !write
)) {
2153 i
= (int *) tbl_data
;
2154 vleft
= table
->maxlen
/ sizeof(*i
);
2158 conv
= do_proc_dointvec_conv
;
2160 for (; left
&& vleft
--; i
++, first
=0) {
2175 if (len
> sizeof(buf
) - 1)
2176 len
= sizeof(buf
) - 1;
2177 if (copy_from_user(buf
, s
, len
))
2181 if (*p
== '-' && left
> 1) {
2185 if (*p
< '0' || *p
> '9')
2188 lval
= simple_strtoul(p
, &p
, 0);
2191 if ((len
< left
) && *p
&& !isspace(*p
))
2198 if (conv(&neg
, &lval
, i
, 1, data
))
2205 if (conv(&neg
, &lval
, i
, 0, data
))
2208 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2212 if(copy_to_user(s
, buf
, len
))
2219 if (!write
&& !first
&& left
) {
2220 if(put_user('\n', s
))
2227 if (get_user(c
, s
++))
2242 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2243 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2244 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2245 int write
, void *data
),
2248 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2249 buffer
, lenp
, ppos
, conv
, data
);
2253 * proc_dointvec - read a vector of integers
2254 * @table: the sysctl table
2255 * @write: %TRUE if this is a write to the sysctl file
2256 * @filp: the file structure
2257 * @buffer: the user buffer
2258 * @lenp: the size of the user buffer
2259 * @ppos: file position
2261 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2262 * values from/to the user buffer, treated as an ASCII string.
2264 * Returns 0 on success.
2266 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2267 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2269 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2274 * Taint values can only be increased
2275 * This means we can safely use a temporary.
2277 static int proc_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2278 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2281 unsigned long tmptaint
= get_taint();
2284 if (write
&& !capable(CAP_SYS_ADMIN
))
2289 err
= proc_doulongvec_minmax(&t
, write
, filp
, buffer
, lenp
, ppos
);
2295 * Poor man's atomic or. Not worth adding a primitive
2296 * to everyone's atomic.h for this
2299 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2300 if ((tmptaint
>> i
) & 1)
2308 struct do_proc_dointvec_minmax_conv_param
{
2313 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2315 int write
, void *data
)
2317 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2319 int val
= *negp
? -*lvalp
: *lvalp
;
2320 if ((param
->min
&& *param
->min
> val
) ||
2321 (param
->max
&& *param
->max
< val
))
2328 *lvalp
= (unsigned long)-val
;
2331 *lvalp
= (unsigned long)val
;
2338 * proc_dointvec_minmax - read a vector of integers with min/max values
2339 * @table: the sysctl table
2340 * @write: %TRUE if this is a write to the sysctl file
2341 * @filp: the file structure
2342 * @buffer: the user buffer
2343 * @lenp: the size of the user buffer
2344 * @ppos: file position
2346 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2347 * values from/to the user buffer, treated as an ASCII string.
2349 * This routine will ensure the values are within the range specified by
2350 * table->extra1 (min) and table->extra2 (max).
2352 * Returns 0 on success.
2354 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2355 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2357 struct do_proc_dointvec_minmax_conv_param param
= {
2358 .min
= (int *) table
->extra1
,
2359 .max
= (int *) table
->extra2
,
2361 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2362 do_proc_dointvec_minmax_conv
, ¶m
);
2365 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2367 void __user
*buffer
,
2368 size_t *lenp
, loff_t
*ppos
,
2369 unsigned long convmul
,
2370 unsigned long convdiv
)
2372 #define TMPBUFLEN 21
2373 unsigned long *i
, *min
, *max
, val
;
2374 int vleft
, first
=1, neg
;
2376 char buf
[TMPBUFLEN
], *p
;
2377 char __user
*s
= buffer
;
2379 if (!data
|| !table
->maxlen
|| !*lenp
||
2380 (*ppos
&& !write
)) {
2385 i
= (unsigned long *) data
;
2386 min
= (unsigned long *) table
->extra1
;
2387 max
= (unsigned long *) table
->extra2
;
2388 vleft
= table
->maxlen
/ sizeof(unsigned long);
2391 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2406 if (len
> TMPBUFLEN
-1)
2408 if (copy_from_user(buf
, s
, len
))
2412 if (*p
== '-' && left
> 1) {
2416 if (*p
< '0' || *p
> '9')
2418 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2420 if ((len
< left
) && *p
&& !isspace(*p
))
2429 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2436 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2440 if(copy_to_user(s
, buf
, len
))
2447 if (!write
&& !first
&& left
) {
2448 if(put_user('\n', s
))
2455 if (get_user(c
, s
++))
2470 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2472 void __user
*buffer
,
2473 size_t *lenp
, loff_t
*ppos
,
2474 unsigned long convmul
,
2475 unsigned long convdiv
)
2477 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2478 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2482 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2483 * @table: the sysctl table
2484 * @write: %TRUE if this is a write to the sysctl file
2485 * @filp: the file structure
2486 * @buffer: the user buffer
2487 * @lenp: the size of the user buffer
2488 * @ppos: file position
2490 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2491 * values from/to the user buffer, treated as an ASCII string.
2493 * This routine will ensure the values are within the range specified by
2494 * table->extra1 (min) and table->extra2 (max).
2496 * Returns 0 on success.
2498 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2499 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2501 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2505 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2506 * @table: the sysctl table
2507 * @write: %TRUE if this is a write to the sysctl file
2508 * @filp: the file structure
2509 * @buffer: the user buffer
2510 * @lenp: the size of the user buffer
2511 * @ppos: file position
2513 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2514 * values from/to the user buffer, treated as an ASCII string. The values
2515 * are treated as milliseconds, and converted to jiffies when they are stored.
2517 * This routine will ensure the values are within the range specified by
2518 * table->extra1 (min) and table->extra2 (max).
2520 * Returns 0 on success.
2522 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2524 void __user
*buffer
,
2525 size_t *lenp
, loff_t
*ppos
)
2527 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2528 lenp
, ppos
, HZ
, 1000l);
2532 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2534 int write
, void *data
)
2537 if (*lvalp
> LONG_MAX
/ HZ
)
2539 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2545 lval
= (unsigned long)-val
;
2548 lval
= (unsigned long)val
;
2555 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2557 int write
, void *data
)
2560 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2562 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2568 lval
= (unsigned long)-val
;
2571 lval
= (unsigned long)val
;
2573 *lvalp
= jiffies_to_clock_t(lval
);
2578 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2580 int write
, void *data
)
2583 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2589 lval
= (unsigned long)-val
;
2592 lval
= (unsigned long)val
;
2594 *lvalp
= jiffies_to_msecs(lval
);
2600 * proc_dointvec_jiffies - read a vector of integers as seconds
2601 * @table: the sysctl table
2602 * @write: %TRUE if this is a write to the sysctl file
2603 * @filp: the file structure
2604 * @buffer: the user buffer
2605 * @lenp: the size of the user buffer
2606 * @ppos: file position
2608 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2609 * values from/to the user buffer, treated as an ASCII string.
2610 * The values read are assumed to be in seconds, and are converted into
2613 * Returns 0 on success.
2615 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2616 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2618 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2619 do_proc_dointvec_jiffies_conv
,NULL
);
2623 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2624 * @table: the sysctl table
2625 * @write: %TRUE if this is a write to the sysctl file
2626 * @filp: the file structure
2627 * @buffer: the user buffer
2628 * @lenp: the size of the user buffer
2629 * @ppos: pointer to the file position
2631 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2632 * values from/to the user buffer, treated as an ASCII string.
2633 * The values read are assumed to be in 1/USER_HZ seconds, and
2634 * are converted into jiffies.
2636 * Returns 0 on success.
2638 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2639 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2641 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2642 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2646 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2647 * @table: the sysctl table
2648 * @write: %TRUE if this is a write to the sysctl file
2649 * @filp: the file structure
2650 * @buffer: the user buffer
2651 * @lenp: the size of the user buffer
2652 * @ppos: file position
2653 * @ppos: the current position in the file
2655 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2656 * values from/to the user buffer, treated as an ASCII string.
2657 * The values read are assumed to be in 1/1000 seconds, and
2658 * are converted into jiffies.
2660 * Returns 0 on success.
2662 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2663 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2665 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2666 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2669 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2670 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2672 struct pid
*new_pid
;
2676 tmp
= pid_vnr(cad_pid
);
2678 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2679 lenp
, ppos
, NULL
, NULL
);
2683 new_pid
= find_get_pid(tmp
);
2687 put_pid(xchg(&cad_pid
, new_pid
));
2691 #else /* CONFIG_PROC_FS */
2693 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2694 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2699 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2700 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2705 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2706 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2711 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2712 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2717 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2718 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2723 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2724 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2729 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2730 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2735 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2737 void __user
*buffer
,
2738 size_t *lenp
, loff_t
*ppos
)
2744 #endif /* CONFIG_PROC_FS */
2747 #ifdef CONFIG_SYSCTL_SYSCALL
2749 * General sysctl support routines
2752 /* The generic sysctl data routine (used if no strategy routine supplied) */
2753 int sysctl_data(struct ctl_table
*table
,
2754 void __user
*oldval
, size_t __user
*oldlenp
,
2755 void __user
*newval
, size_t newlen
)
2759 /* Get out of I don't have a variable */
2760 if (!table
->data
|| !table
->maxlen
)
2763 if (oldval
&& oldlenp
) {
2764 if (get_user(len
, oldlenp
))
2767 if (len
> table
->maxlen
)
2768 len
= table
->maxlen
;
2769 if (copy_to_user(oldval
, table
->data
, len
))
2771 if (put_user(len
, oldlenp
))
2776 if (newval
&& newlen
) {
2777 if (newlen
> table
->maxlen
)
2778 newlen
= table
->maxlen
;
2780 if (copy_from_user(table
->data
, newval
, newlen
))
2786 /* The generic string strategy routine: */
2787 int sysctl_string(struct ctl_table
*table
,
2788 void __user
*oldval
, size_t __user
*oldlenp
,
2789 void __user
*newval
, size_t newlen
)
2791 if (!table
->data
|| !table
->maxlen
)
2794 if (oldval
&& oldlenp
) {
2796 if (get_user(bufsize
, oldlenp
))
2799 size_t len
= strlen(table
->data
), copied
;
2801 /* This shouldn't trigger for a well-formed sysctl */
2802 if (len
> table
->maxlen
)
2803 len
= table
->maxlen
;
2805 /* Copy up to a max of bufsize-1 bytes of the string */
2806 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2808 if (copy_to_user(oldval
, table
->data
, copied
) ||
2809 put_user(0, (char __user
*)(oldval
+ copied
)))
2811 if (put_user(len
, oldlenp
))
2815 if (newval
&& newlen
) {
2816 size_t len
= newlen
;
2817 if (len
> table
->maxlen
)
2818 len
= table
->maxlen
;
2819 if(copy_from_user(table
->data
, newval
, len
))
2821 if (len
== table
->maxlen
)
2823 ((char *) table
->data
)[len
] = 0;
2829 * This function makes sure that all of the integers in the vector
2830 * are between the minimum and maximum values given in the arrays
2831 * table->extra1 and table->extra2, respectively.
2833 int sysctl_intvec(struct ctl_table
*table
,
2834 void __user
*oldval
, size_t __user
*oldlenp
,
2835 void __user
*newval
, size_t newlen
)
2838 if (newval
&& newlen
) {
2839 int __user
*vec
= (int __user
*) newval
;
2840 int *min
= (int *) table
->extra1
;
2841 int *max
= (int *) table
->extra2
;
2845 if (newlen
% sizeof(int) != 0)
2848 if (!table
->extra1
&& !table
->extra2
)
2851 if (newlen
> table
->maxlen
)
2852 newlen
= table
->maxlen
;
2853 length
= newlen
/ sizeof(int);
2855 for (i
= 0; i
< length
; i
++) {
2857 if (get_user(value
, vec
+ i
))
2859 if (min
&& value
< min
[i
])
2861 if (max
&& value
> max
[i
])
2868 /* Strategy function to convert jiffies to seconds */
2869 int sysctl_jiffies(struct ctl_table
*table
,
2870 void __user
*oldval
, size_t __user
*oldlenp
,
2871 void __user
*newval
, size_t newlen
)
2873 if (oldval
&& oldlenp
) {
2876 if (get_user(olen
, oldlenp
))
2881 if (olen
< sizeof(int))
2884 val
= *(int *)(table
->data
) / HZ
;
2885 if (put_user(val
, (int __user
*)oldval
))
2887 if (put_user(sizeof(int), oldlenp
))
2891 if (newval
&& newlen
) {
2893 if (newlen
!= sizeof(int))
2895 if (get_user(new, (int __user
*)newval
))
2897 *(int *)(table
->data
) = new*HZ
;
2902 /* Strategy function to convert jiffies to seconds */
2903 int sysctl_ms_jiffies(struct ctl_table
*table
,
2904 void __user
*oldval
, size_t __user
*oldlenp
,
2905 void __user
*newval
, size_t newlen
)
2907 if (oldval
&& oldlenp
) {
2910 if (get_user(olen
, oldlenp
))
2915 if (olen
< sizeof(int))
2918 val
= jiffies_to_msecs(*(int *)(table
->data
));
2919 if (put_user(val
, (int __user
*)oldval
))
2921 if (put_user(sizeof(int), oldlenp
))
2925 if (newval
&& newlen
) {
2927 if (newlen
!= sizeof(int))
2929 if (get_user(new, (int __user
*)newval
))
2931 *(int *)(table
->data
) = msecs_to_jiffies(new);
2938 #else /* CONFIG_SYSCTL_SYSCALL */
2941 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2943 struct __sysctl_args tmp
;
2946 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
2949 error
= deprecated_sysctl_warning(&tmp
);
2951 /* If no error reading the parameters then just -ENOSYS ... */
2958 int sysctl_data(struct ctl_table
*table
,
2959 void __user
*oldval
, size_t __user
*oldlenp
,
2960 void __user
*newval
, size_t newlen
)
2965 int sysctl_string(struct ctl_table
*table
,
2966 void __user
*oldval
, size_t __user
*oldlenp
,
2967 void __user
*newval
, size_t newlen
)
2972 int sysctl_intvec(struct ctl_table
*table
,
2973 void __user
*oldval
, size_t __user
*oldlenp
,
2974 void __user
*newval
, size_t newlen
)
2979 int sysctl_jiffies(struct ctl_table
*table
,
2980 void __user
*oldval
, size_t __user
*oldlenp
,
2981 void __user
*newval
, size_t newlen
)
2986 int sysctl_ms_jiffies(struct ctl_table
*table
,
2987 void __user
*oldval
, size_t __user
*oldlenp
,
2988 void __user
*newval
, size_t newlen
)
2993 #endif /* CONFIG_SYSCTL_SYSCALL */
2995 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
2997 static int msg_count
;
2998 int name
[CTL_MAXNAME
];
3001 /* Check args->nlen. */
3002 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
3005 /* Read in the sysctl name for better debug message logging */
3006 for (i
= 0; i
< args
->nlen
; i
++)
3007 if (get_user(name
[i
], args
->name
+ i
))
3010 /* Ignore accesses to kernel.version */
3011 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
3014 if (msg_count
< 5) {
3017 "warning: process `%s' used the deprecated sysctl "
3018 "system call with ", current
->comm
);
3019 for (i
= 0; i
< args
->nlen
; i
++)
3020 printk("%d.", name
[i
]);
3027 * No sense putting this after each symbol definition, twice,
3028 * exception granted :-)
3030 EXPORT_SYMBOL(proc_dointvec
);
3031 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3032 EXPORT_SYMBOL(proc_dointvec_minmax
);
3033 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3034 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3035 EXPORT_SYMBOL(proc_dostring
);
3036 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3037 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
3038 EXPORT_SYMBOL(register_sysctl_table
);
3039 EXPORT_SYMBOL(register_sysctl_paths
);
3040 EXPORT_SYMBOL(sysctl_intvec
);
3041 EXPORT_SYMBOL(sysctl_jiffies
);
3042 EXPORT_SYMBOL(sysctl_ms_jiffies
);
3043 EXPORT_SYMBOL(sysctl_string
);
3044 EXPORT_SYMBOL(sysctl_data
);
3045 EXPORT_SYMBOL(unregister_sysctl_table
);