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/nfs_fs.h>
47 #include <linux/acpi.h>
48 #include <linux/reboot.h>
49 #include <linux/ftrace.h>
51 #include <asm/uaccess.h>
52 #include <asm/processor.h>
56 #include <asm/stacktrace.h>
60 static int deprecated_sysctl_warning(struct __sysctl_args
*args
);
62 #if defined(CONFIG_SYSCTL)
64 /* External variables not in a header file. */
66 extern int print_fatal_signals
;
67 extern int sysctl_overcommit_memory
;
68 extern int sysctl_overcommit_ratio
;
69 extern int sysctl_panic_on_oom
;
70 extern int sysctl_oom_kill_allocating_task
;
71 extern int sysctl_oom_dump_tasks
;
72 extern int max_threads
;
73 extern int core_uses_pid
;
74 extern int suid_dumpable
;
75 extern char core_pattern
[];
77 extern int min_free_kbytes
;
78 extern int pid_max_min
, pid_max_max
;
79 extern int sysctl_drop_caches
;
80 extern int percpu_pagelist_fraction
;
81 extern int compat_log
;
82 extern int maps_protect
;
83 extern int sysctl_stat_interval
;
84 extern int latencytop_enabled
;
85 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
87 /* Constants used for minimum and maximum */
88 #if defined(CONFIG_HIGHMEM) || defined(CONFIG_DETECT_SOFTLOCKUP)
92 #ifdef CONFIG_DETECT_SOFTLOCKUP
93 static int sixty
= 60;
94 static int neg_one
= -1;
102 static int one_hundred
= 100;
104 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
105 static int maxolduid
= 65535;
106 static int minolduid
;
107 static int min_percpu_pagelist_fract
= 8;
109 static int ngroups_max
= NGROUPS_MAX
;
112 extern char modprobe_path
[];
114 #ifdef CONFIG_CHR_DEV_SG
115 extern int sg_big_buff
;
119 extern char reboot_command
[];
120 extern int stop_a_enabled
;
121 extern int scons_pwroff
;
125 extern int pwrsw_enabled
;
126 extern int unaligned_enabled
;
130 #ifdef CONFIG_MATHEMU
131 extern int sysctl_ieee_emulation_warnings
;
133 extern int sysctl_userprocess_debug
;
134 extern int spin_retry
;
137 #ifdef CONFIG_BSD_PROCESS_ACCT
138 extern int acct_parm
[];
142 extern int no_unaligned_warning
;
145 #ifdef CONFIG_RT_MUTEXES
146 extern int max_lock_depth
;
149 #ifdef CONFIG_PROC_SYSCTL
150 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
151 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
152 static int proc_dointvec_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
153 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
156 static struct ctl_table root_table
[];
157 static struct ctl_table_root sysctl_table_root
;
158 static struct ctl_table_header root_table_header
= {
159 .ctl_table
= root_table
,
160 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.header_list
),
161 .root
= &sysctl_table_root
,
163 static struct ctl_table_root sysctl_table_root
= {
164 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
165 .header_list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
168 static struct ctl_table kern_table
[];
169 static struct ctl_table vm_table
[];
170 static struct ctl_table fs_table
[];
171 static struct ctl_table debug_table
[];
172 static struct ctl_table dev_table
[];
173 extern struct ctl_table random_table
[];
174 #ifdef CONFIG_INOTIFY_USER
175 extern struct ctl_table inotify_table
[];
178 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
179 int sysctl_legacy_va_layout
;
182 extern int prove_locking
;
183 extern int lock_stat
;
185 /* The default sysctl tables: */
187 static struct ctl_table root_table
[] = {
189 .ctl_name
= CTL_KERN
,
190 .procname
= "kernel",
207 .ctl_name
= CTL_DEBUG
,
210 .child
= debug_table
,
219 * NOTE: do not add new entries to this table unless you have read
220 * Documentation/sysctl/ctl_unnumbered.txt
225 #ifdef CONFIG_SCHED_DEBUG
226 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
227 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
228 static int min_wakeup_granularity_ns
; /* 0 usecs */
229 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
232 static struct ctl_table kern_table
[] = {
233 #ifdef CONFIG_SCHED_DEBUG
235 .ctl_name
= CTL_UNNUMBERED
,
236 .procname
= "sched_min_granularity_ns",
237 .data
= &sysctl_sched_min_granularity
,
238 .maxlen
= sizeof(unsigned int),
240 .proc_handler
= &sched_nr_latency_handler
,
241 .strategy
= &sysctl_intvec
,
242 .extra1
= &min_sched_granularity_ns
,
243 .extra2
= &max_sched_granularity_ns
,
246 .ctl_name
= CTL_UNNUMBERED
,
247 .procname
= "sched_latency_ns",
248 .data
= &sysctl_sched_latency
,
249 .maxlen
= sizeof(unsigned int),
251 .proc_handler
= &sched_nr_latency_handler
,
252 .strategy
= &sysctl_intvec
,
253 .extra1
= &min_sched_granularity_ns
,
254 .extra2
= &max_sched_granularity_ns
,
257 .ctl_name
= CTL_UNNUMBERED
,
258 .procname
= "sched_wakeup_granularity_ns",
259 .data
= &sysctl_sched_wakeup_granularity
,
260 .maxlen
= sizeof(unsigned int),
262 .proc_handler
= &proc_dointvec_minmax
,
263 .strategy
= &sysctl_intvec
,
264 .extra1
= &min_wakeup_granularity_ns
,
265 .extra2
= &max_wakeup_granularity_ns
,
268 .ctl_name
= CTL_UNNUMBERED
,
269 .procname
= "sched_shares_ratelimit",
270 .data
= &sysctl_sched_shares_ratelimit
,
271 .maxlen
= sizeof(unsigned int),
273 .proc_handler
= &proc_dointvec
,
276 .ctl_name
= CTL_UNNUMBERED
,
277 .procname
= "sched_child_runs_first",
278 .data
= &sysctl_sched_child_runs_first
,
279 .maxlen
= sizeof(unsigned int),
281 .proc_handler
= &proc_dointvec
,
284 .ctl_name
= CTL_UNNUMBERED
,
285 .procname
= "sched_features",
286 .data
= &sysctl_sched_features
,
287 .maxlen
= sizeof(unsigned int),
289 .proc_handler
= &proc_dointvec
,
292 .ctl_name
= CTL_UNNUMBERED
,
293 .procname
= "sched_migration_cost",
294 .data
= &sysctl_sched_migration_cost
,
295 .maxlen
= sizeof(unsigned int),
297 .proc_handler
= &proc_dointvec
,
300 .ctl_name
= CTL_UNNUMBERED
,
301 .procname
= "sched_nr_migrate",
302 .data
= &sysctl_sched_nr_migrate
,
303 .maxlen
= sizeof(unsigned int),
305 .proc_handler
= &proc_dointvec
,
309 .ctl_name
= CTL_UNNUMBERED
,
310 .procname
= "sched_rt_period_us",
311 .data
= &sysctl_sched_rt_period
,
312 .maxlen
= sizeof(unsigned int),
314 .proc_handler
= &sched_rt_handler
,
317 .ctl_name
= CTL_UNNUMBERED
,
318 .procname
= "sched_rt_runtime_us",
319 .data
= &sysctl_sched_rt_runtime
,
320 .maxlen
= sizeof(int),
322 .proc_handler
= &sched_rt_handler
,
325 .ctl_name
= CTL_UNNUMBERED
,
326 .procname
= "sched_compat_yield",
327 .data
= &sysctl_sched_compat_yield
,
328 .maxlen
= sizeof(unsigned int),
330 .proc_handler
= &proc_dointvec
,
332 #ifdef CONFIG_PROVE_LOCKING
334 .ctl_name
= CTL_UNNUMBERED
,
335 .procname
= "prove_locking",
336 .data
= &prove_locking
,
337 .maxlen
= sizeof(int),
339 .proc_handler
= &proc_dointvec
,
342 #ifdef CONFIG_LOCK_STAT
344 .ctl_name
= CTL_UNNUMBERED
,
345 .procname
= "lock_stat",
347 .maxlen
= sizeof(int),
349 .proc_handler
= &proc_dointvec
,
353 .ctl_name
= KERN_PANIC
,
355 .data
= &panic_timeout
,
356 .maxlen
= sizeof(int),
358 .proc_handler
= &proc_dointvec
,
361 .ctl_name
= KERN_CORE_USES_PID
,
362 .procname
= "core_uses_pid",
363 .data
= &core_uses_pid
,
364 .maxlen
= sizeof(int),
366 .proc_handler
= &proc_dointvec
,
369 .ctl_name
= KERN_CORE_PATTERN
,
370 .procname
= "core_pattern",
371 .data
= core_pattern
,
372 .maxlen
= CORENAME_MAX_SIZE
,
374 .proc_handler
= &proc_dostring
,
375 .strategy
= &sysctl_string
,
377 #ifdef CONFIG_PROC_SYSCTL
379 .procname
= "tainted",
381 .maxlen
= sizeof(int),
383 .proc_handler
= &proc_dointvec_taint
,
386 #ifdef CONFIG_LATENCYTOP
388 .procname
= "latencytop",
389 .data
= &latencytop_enabled
,
390 .maxlen
= sizeof(int),
392 .proc_handler
= &proc_dointvec
,
395 #ifdef CONFIG_BLK_DEV_INITRD
397 .ctl_name
= KERN_REALROOTDEV
,
398 .procname
= "real-root-dev",
399 .data
= &real_root_dev
,
400 .maxlen
= sizeof(int),
402 .proc_handler
= &proc_dointvec
,
406 .ctl_name
= CTL_UNNUMBERED
,
407 .procname
= "print-fatal-signals",
408 .data
= &print_fatal_signals
,
409 .maxlen
= sizeof(int),
411 .proc_handler
= &proc_dointvec
,
415 .ctl_name
= KERN_SPARC_REBOOT
,
416 .procname
= "reboot-cmd",
417 .data
= reboot_command
,
420 .proc_handler
= &proc_dostring
,
421 .strategy
= &sysctl_string
,
424 .ctl_name
= KERN_SPARC_STOP_A
,
425 .procname
= "stop-a",
426 .data
= &stop_a_enabled
,
427 .maxlen
= sizeof (int),
429 .proc_handler
= &proc_dointvec
,
432 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
433 .procname
= "scons-poweroff",
434 .data
= &scons_pwroff
,
435 .maxlen
= sizeof (int),
437 .proc_handler
= &proc_dointvec
,
442 .ctl_name
= KERN_HPPA_PWRSW
,
443 .procname
= "soft-power",
444 .data
= &pwrsw_enabled
,
445 .maxlen
= sizeof (int),
447 .proc_handler
= &proc_dointvec
,
450 .ctl_name
= KERN_HPPA_UNALIGNED
,
451 .procname
= "unaligned-trap",
452 .data
= &unaligned_enabled
,
453 .maxlen
= sizeof (int),
455 .proc_handler
= &proc_dointvec
,
459 .ctl_name
= KERN_CTLALTDEL
,
460 .procname
= "ctrl-alt-del",
462 .maxlen
= sizeof(int),
464 .proc_handler
= &proc_dointvec
,
468 .ctl_name
= CTL_UNNUMBERED
,
469 .procname
= "ftrace_enabled",
470 .data
= &ftrace_enabled
,
471 .maxlen
= sizeof(int),
473 .proc_handler
= &ftrace_enable_sysctl
,
478 .ctl_name
= KERN_MODPROBE
,
479 .procname
= "modprobe",
480 .data
= &modprobe_path
,
481 .maxlen
= KMOD_PATH_LEN
,
483 .proc_handler
= &proc_dostring
,
484 .strategy
= &sysctl_string
,
487 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
489 .ctl_name
= KERN_HOTPLUG
,
490 .procname
= "hotplug",
491 .data
= &uevent_helper
,
492 .maxlen
= UEVENT_HELPER_PATH_LEN
,
494 .proc_handler
= &proc_dostring
,
495 .strategy
= &sysctl_string
,
498 #ifdef CONFIG_CHR_DEV_SG
500 .ctl_name
= KERN_SG_BIG_BUFF
,
501 .procname
= "sg-big-buff",
502 .data
= &sg_big_buff
,
503 .maxlen
= sizeof (int),
505 .proc_handler
= &proc_dointvec
,
508 #ifdef CONFIG_BSD_PROCESS_ACCT
510 .ctl_name
= KERN_ACCT
,
513 .maxlen
= 3*sizeof(int),
515 .proc_handler
= &proc_dointvec
,
518 #ifdef CONFIG_MAGIC_SYSRQ
520 .ctl_name
= KERN_SYSRQ
,
522 .data
= &__sysrq_enabled
,
523 .maxlen
= sizeof (int),
525 .proc_handler
= &proc_dointvec
,
528 #ifdef CONFIG_PROC_SYSCTL
530 .procname
= "cad_pid",
532 .maxlen
= sizeof (int),
534 .proc_handler
= &proc_do_cad_pid
,
538 .ctl_name
= KERN_MAX_THREADS
,
539 .procname
= "threads-max",
540 .data
= &max_threads
,
541 .maxlen
= sizeof(int),
543 .proc_handler
= &proc_dointvec
,
546 .ctl_name
= KERN_RANDOM
,
547 .procname
= "random",
549 .child
= random_table
,
552 .ctl_name
= KERN_OVERFLOWUID
,
553 .procname
= "overflowuid",
554 .data
= &overflowuid
,
555 .maxlen
= sizeof(int),
557 .proc_handler
= &proc_dointvec_minmax
,
558 .strategy
= &sysctl_intvec
,
559 .extra1
= &minolduid
,
560 .extra2
= &maxolduid
,
563 .ctl_name
= KERN_OVERFLOWGID
,
564 .procname
= "overflowgid",
565 .data
= &overflowgid
,
566 .maxlen
= sizeof(int),
568 .proc_handler
= &proc_dointvec_minmax
,
569 .strategy
= &sysctl_intvec
,
570 .extra1
= &minolduid
,
571 .extra2
= &maxolduid
,
574 #ifdef CONFIG_MATHEMU
576 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
577 .procname
= "ieee_emulation_warnings",
578 .data
= &sysctl_ieee_emulation_warnings
,
579 .maxlen
= sizeof(int),
581 .proc_handler
= &proc_dointvec
,
585 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
586 .procname
= "userprocess_debug",
587 .data
= &sysctl_userprocess_debug
,
588 .maxlen
= sizeof(int),
590 .proc_handler
= &proc_dointvec
,
594 .ctl_name
= KERN_PIDMAX
,
595 .procname
= "pid_max",
597 .maxlen
= sizeof (int),
599 .proc_handler
= &proc_dointvec_minmax
,
600 .strategy
= sysctl_intvec
,
601 .extra1
= &pid_max_min
,
602 .extra2
= &pid_max_max
,
605 .ctl_name
= KERN_PANIC_ON_OOPS
,
606 .procname
= "panic_on_oops",
607 .data
= &panic_on_oops
,
608 .maxlen
= sizeof(int),
610 .proc_handler
= &proc_dointvec
,
612 #if defined CONFIG_PRINTK
614 .ctl_name
= KERN_PRINTK
,
615 .procname
= "printk",
616 .data
= &console_loglevel
,
617 .maxlen
= 4*sizeof(int),
619 .proc_handler
= &proc_dointvec
,
622 .ctl_name
= KERN_PRINTK_RATELIMIT
,
623 .procname
= "printk_ratelimit",
624 .data
= &printk_ratelimit_jiffies
,
625 .maxlen
= sizeof(int),
627 .proc_handler
= &proc_dointvec_jiffies
,
628 .strategy
= &sysctl_jiffies
,
631 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
632 .procname
= "printk_ratelimit_burst",
633 .data
= &printk_ratelimit_burst
,
634 .maxlen
= sizeof(int),
636 .proc_handler
= &proc_dointvec
,
640 .ctl_name
= KERN_NGROUPS_MAX
,
641 .procname
= "ngroups_max",
642 .data
= &ngroups_max
,
643 .maxlen
= sizeof (int),
645 .proc_handler
= &proc_dointvec
,
647 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
649 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
650 .procname
= "unknown_nmi_panic",
651 .data
= &unknown_nmi_panic
,
652 .maxlen
= sizeof (int),
654 .proc_handler
= &proc_dointvec
,
657 .procname
= "nmi_watchdog",
658 .data
= &nmi_watchdog_enabled
,
659 .maxlen
= sizeof (int),
661 .proc_handler
= &proc_nmi_enabled
,
664 #if defined(CONFIG_X86)
666 .ctl_name
= KERN_PANIC_ON_NMI
,
667 .procname
= "panic_on_unrecovered_nmi",
668 .data
= &panic_on_unrecovered_nmi
,
669 .maxlen
= sizeof(int),
671 .proc_handler
= &proc_dointvec
,
674 .ctl_name
= KERN_BOOTLOADER_TYPE
,
675 .procname
= "bootloader_type",
676 .data
= &bootloader_type
,
677 .maxlen
= sizeof (int),
679 .proc_handler
= &proc_dointvec
,
682 .ctl_name
= CTL_UNNUMBERED
,
683 .procname
= "kstack_depth_to_print",
684 .data
= &kstack_depth_to_print
,
685 .maxlen
= sizeof(int),
687 .proc_handler
= &proc_dointvec
,
690 .ctl_name
= CTL_UNNUMBERED
,
691 .procname
= "io_delay_type",
692 .data
= &io_delay_type
,
693 .maxlen
= sizeof(int),
695 .proc_handler
= &proc_dointvec
,
698 #if defined(CONFIG_MMU)
700 .ctl_name
= KERN_RANDOMIZE
,
701 .procname
= "randomize_va_space",
702 .data
= &randomize_va_space
,
703 .maxlen
= sizeof(int),
705 .proc_handler
= &proc_dointvec
,
708 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
710 .ctl_name
= KERN_SPIN_RETRY
,
711 .procname
= "spin_retry",
713 .maxlen
= sizeof (int),
715 .proc_handler
= &proc_dointvec
,
718 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
720 .procname
= "acpi_video_flags",
721 .data
= &acpi_realmode_flags
,
722 .maxlen
= sizeof (unsigned long),
724 .proc_handler
= &proc_doulongvec_minmax
,
729 .ctl_name
= KERN_IA64_UNALIGNED
,
730 .procname
= "ignore-unaligned-usertrap",
731 .data
= &no_unaligned_warning
,
732 .maxlen
= sizeof (int),
734 .proc_handler
= &proc_dointvec
,
737 #ifdef CONFIG_DETECT_SOFTLOCKUP
739 .ctl_name
= CTL_UNNUMBERED
,
740 .procname
= "softlockup_panic",
741 .data
= &softlockup_panic
,
742 .maxlen
= sizeof(int),
744 .proc_handler
= &proc_dointvec_minmax
,
745 .strategy
= &sysctl_intvec
,
750 .ctl_name
= CTL_UNNUMBERED
,
751 .procname
= "softlockup_thresh",
752 .data
= &softlockup_thresh
,
753 .maxlen
= sizeof(int),
755 .proc_handler
= &proc_dointvec_minmax
,
756 .strategy
= &sysctl_intvec
,
761 .ctl_name
= CTL_UNNUMBERED
,
762 .procname
= "hung_task_check_count",
763 .data
= &sysctl_hung_task_check_count
,
764 .maxlen
= sizeof(unsigned long),
766 .proc_handler
= &proc_doulongvec_minmax
,
767 .strategy
= &sysctl_intvec
,
770 .ctl_name
= CTL_UNNUMBERED
,
771 .procname
= "hung_task_timeout_secs",
772 .data
= &sysctl_hung_task_timeout_secs
,
773 .maxlen
= sizeof(unsigned long),
775 .proc_handler
= &proc_doulongvec_minmax
,
776 .strategy
= &sysctl_intvec
,
779 .ctl_name
= CTL_UNNUMBERED
,
780 .procname
= "hung_task_warnings",
781 .data
= &sysctl_hung_task_warnings
,
782 .maxlen
= sizeof(unsigned long),
784 .proc_handler
= &proc_doulongvec_minmax
,
785 .strategy
= &sysctl_intvec
,
790 .ctl_name
= KERN_COMPAT_LOG
,
791 .procname
= "compat-log",
793 .maxlen
= sizeof (int),
795 .proc_handler
= &proc_dointvec
,
798 #ifdef CONFIG_RT_MUTEXES
800 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
801 .procname
= "max_lock_depth",
802 .data
= &max_lock_depth
,
803 .maxlen
= sizeof(int),
805 .proc_handler
= &proc_dointvec
,
808 #ifdef CONFIG_PROC_FS
810 .ctl_name
= CTL_UNNUMBERED
,
811 .procname
= "maps_protect",
812 .data
= &maps_protect
,
813 .maxlen
= sizeof(int),
815 .proc_handler
= &proc_dointvec
,
819 .ctl_name
= CTL_UNNUMBERED
,
820 .procname
= "poweroff_cmd",
821 .data
= &poweroff_cmd
,
822 .maxlen
= POWEROFF_CMD_PATH_LEN
,
824 .proc_handler
= &proc_dostring
,
825 .strategy
= &sysctl_string
,
829 .ctl_name
= CTL_UNNUMBERED
,
832 .child
= key_sysctls
,
836 * NOTE: do not add new entries to this table unless you have read
837 * Documentation/sysctl/ctl_unnumbered.txt
842 static struct ctl_table vm_table
[] = {
844 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
845 .procname
= "overcommit_memory",
846 .data
= &sysctl_overcommit_memory
,
847 .maxlen
= sizeof(sysctl_overcommit_memory
),
849 .proc_handler
= &proc_dointvec
,
852 .ctl_name
= VM_PANIC_ON_OOM
,
853 .procname
= "panic_on_oom",
854 .data
= &sysctl_panic_on_oom
,
855 .maxlen
= sizeof(sysctl_panic_on_oom
),
857 .proc_handler
= &proc_dointvec
,
860 .ctl_name
= CTL_UNNUMBERED
,
861 .procname
= "oom_kill_allocating_task",
862 .data
= &sysctl_oom_kill_allocating_task
,
863 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
865 .proc_handler
= &proc_dointvec
,
868 .ctl_name
= CTL_UNNUMBERED
,
869 .procname
= "oom_dump_tasks",
870 .data
= &sysctl_oom_dump_tasks
,
871 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
873 .proc_handler
= &proc_dointvec
,
876 .ctl_name
= VM_OVERCOMMIT_RATIO
,
877 .procname
= "overcommit_ratio",
878 .data
= &sysctl_overcommit_ratio
,
879 .maxlen
= sizeof(sysctl_overcommit_ratio
),
881 .proc_handler
= &proc_dointvec
,
884 .ctl_name
= VM_PAGE_CLUSTER
,
885 .procname
= "page-cluster",
886 .data
= &page_cluster
,
887 .maxlen
= sizeof(int),
889 .proc_handler
= &proc_dointvec
,
892 .ctl_name
= VM_DIRTY_BACKGROUND
,
893 .procname
= "dirty_background_ratio",
894 .data
= &dirty_background_ratio
,
895 .maxlen
= sizeof(dirty_background_ratio
),
897 .proc_handler
= &proc_dointvec_minmax
,
898 .strategy
= &sysctl_intvec
,
900 .extra2
= &one_hundred
,
903 .ctl_name
= VM_DIRTY_RATIO
,
904 .procname
= "dirty_ratio",
905 .data
= &vm_dirty_ratio
,
906 .maxlen
= sizeof(vm_dirty_ratio
),
908 .proc_handler
= &dirty_ratio_handler
,
909 .strategy
= &sysctl_intvec
,
911 .extra2
= &one_hundred
,
914 .procname
= "dirty_writeback_centisecs",
915 .data
= &dirty_writeback_interval
,
916 .maxlen
= sizeof(dirty_writeback_interval
),
918 .proc_handler
= &dirty_writeback_centisecs_handler
,
921 .procname
= "dirty_expire_centisecs",
922 .data
= &dirty_expire_interval
,
923 .maxlen
= sizeof(dirty_expire_interval
),
925 .proc_handler
= &proc_dointvec_userhz_jiffies
,
928 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
929 .procname
= "nr_pdflush_threads",
930 .data
= &nr_pdflush_threads
,
931 .maxlen
= sizeof nr_pdflush_threads
,
932 .mode
= 0444 /* read-only*/,
933 .proc_handler
= &proc_dointvec
,
936 .ctl_name
= VM_SWAPPINESS
,
937 .procname
= "swappiness",
938 .data
= &vm_swappiness
,
939 .maxlen
= sizeof(vm_swappiness
),
941 .proc_handler
= &proc_dointvec_minmax
,
942 .strategy
= &sysctl_intvec
,
944 .extra2
= &one_hundred
,
946 #ifdef CONFIG_HUGETLB_PAGE
948 .procname
= "nr_hugepages",
949 .data
= &max_huge_pages
,
950 .maxlen
= sizeof(unsigned long),
952 .proc_handler
= &hugetlb_sysctl_handler
,
953 .extra1
= (void *)&hugetlb_zero
,
954 .extra2
= (void *)&hugetlb_infinity
,
957 .ctl_name
= VM_HUGETLB_GROUP
,
958 .procname
= "hugetlb_shm_group",
959 .data
= &sysctl_hugetlb_shm_group
,
960 .maxlen
= sizeof(gid_t
),
962 .proc_handler
= &proc_dointvec
,
965 .ctl_name
= CTL_UNNUMBERED
,
966 .procname
= "hugepages_treat_as_movable",
967 .data
= &hugepages_treat_as_movable
,
968 .maxlen
= sizeof(int),
970 .proc_handler
= &hugetlb_treat_movable_handler
,
973 .ctl_name
= CTL_UNNUMBERED
,
974 .procname
= "nr_overcommit_hugepages",
975 .data
= &sysctl_overcommit_huge_pages
,
976 .maxlen
= sizeof(sysctl_overcommit_huge_pages
),
978 .proc_handler
= &hugetlb_overcommit_handler
,
982 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
983 .procname
= "lowmem_reserve_ratio",
984 .data
= &sysctl_lowmem_reserve_ratio
,
985 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
987 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
988 .strategy
= &sysctl_intvec
,
991 .ctl_name
= VM_DROP_PAGECACHE
,
992 .procname
= "drop_caches",
993 .data
= &sysctl_drop_caches
,
994 .maxlen
= sizeof(int),
996 .proc_handler
= drop_caches_sysctl_handler
,
997 .strategy
= &sysctl_intvec
,
1000 .ctl_name
= VM_MIN_FREE_KBYTES
,
1001 .procname
= "min_free_kbytes",
1002 .data
= &min_free_kbytes
,
1003 .maxlen
= sizeof(min_free_kbytes
),
1005 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1006 .strategy
= &sysctl_intvec
,
1010 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1011 .procname
= "percpu_pagelist_fraction",
1012 .data
= &percpu_pagelist_fraction
,
1013 .maxlen
= sizeof(percpu_pagelist_fraction
),
1015 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1016 .strategy
= &sysctl_intvec
,
1017 .extra1
= &min_percpu_pagelist_fract
,
1021 .ctl_name
= VM_MAX_MAP_COUNT
,
1022 .procname
= "max_map_count",
1023 .data
= &sysctl_max_map_count
,
1024 .maxlen
= sizeof(sysctl_max_map_count
),
1026 .proc_handler
= &proc_dointvec
1030 .ctl_name
= VM_LAPTOP_MODE
,
1031 .procname
= "laptop_mode",
1032 .data
= &laptop_mode
,
1033 .maxlen
= sizeof(laptop_mode
),
1035 .proc_handler
= &proc_dointvec_jiffies
,
1036 .strategy
= &sysctl_jiffies
,
1039 .ctl_name
= VM_BLOCK_DUMP
,
1040 .procname
= "block_dump",
1041 .data
= &block_dump
,
1042 .maxlen
= sizeof(block_dump
),
1044 .proc_handler
= &proc_dointvec
,
1045 .strategy
= &sysctl_intvec
,
1049 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1050 .procname
= "vfs_cache_pressure",
1051 .data
= &sysctl_vfs_cache_pressure
,
1052 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1054 .proc_handler
= &proc_dointvec
,
1055 .strategy
= &sysctl_intvec
,
1058 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1060 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1061 .procname
= "legacy_va_layout",
1062 .data
= &sysctl_legacy_va_layout
,
1063 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1065 .proc_handler
= &proc_dointvec
,
1066 .strategy
= &sysctl_intvec
,
1072 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1073 .procname
= "zone_reclaim_mode",
1074 .data
= &zone_reclaim_mode
,
1075 .maxlen
= sizeof(zone_reclaim_mode
),
1077 .proc_handler
= &proc_dointvec
,
1078 .strategy
= &sysctl_intvec
,
1082 .ctl_name
= VM_MIN_UNMAPPED
,
1083 .procname
= "min_unmapped_ratio",
1084 .data
= &sysctl_min_unmapped_ratio
,
1085 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1087 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1088 .strategy
= &sysctl_intvec
,
1090 .extra2
= &one_hundred
,
1093 .ctl_name
= VM_MIN_SLAB
,
1094 .procname
= "min_slab_ratio",
1095 .data
= &sysctl_min_slab_ratio
,
1096 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1098 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1099 .strategy
= &sysctl_intvec
,
1101 .extra2
= &one_hundred
,
1106 .ctl_name
= CTL_UNNUMBERED
,
1107 .procname
= "stat_interval",
1108 .data
= &sysctl_stat_interval
,
1109 .maxlen
= sizeof(sysctl_stat_interval
),
1111 .proc_handler
= &proc_dointvec_jiffies
,
1112 .strategy
= &sysctl_jiffies
,
1115 #ifdef CONFIG_SECURITY
1117 .ctl_name
= CTL_UNNUMBERED
,
1118 .procname
= "mmap_min_addr",
1119 .data
= &mmap_min_addr
,
1120 .maxlen
= sizeof(unsigned long),
1122 .proc_handler
= &proc_doulongvec_minmax
,
1127 .ctl_name
= CTL_UNNUMBERED
,
1128 .procname
= "numa_zonelist_order",
1129 .data
= &numa_zonelist_order
,
1130 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1132 .proc_handler
= &numa_zonelist_order_handler
,
1133 .strategy
= &sysctl_string
,
1136 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1137 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1139 .ctl_name
= VM_VDSO_ENABLED
,
1140 .procname
= "vdso_enabled",
1141 .data
= &vdso_enabled
,
1142 .maxlen
= sizeof(vdso_enabled
),
1144 .proc_handler
= &proc_dointvec
,
1145 .strategy
= &sysctl_intvec
,
1149 #ifdef CONFIG_HIGHMEM
1151 .ctl_name
= CTL_UNNUMBERED
,
1152 .procname
= "highmem_is_dirtyable",
1153 .data
= &vm_highmem_is_dirtyable
,
1154 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1156 .proc_handler
= &proc_dointvec_minmax
,
1157 .strategy
= &sysctl_intvec
,
1163 * NOTE: do not add new entries to this table unless you have read
1164 * Documentation/sysctl/ctl_unnumbered.txt
1169 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1170 static struct ctl_table binfmt_misc_table
[] = {
1175 static struct ctl_table fs_table
[] = {
1177 .ctl_name
= FS_NRINODE
,
1178 .procname
= "inode-nr",
1179 .data
= &inodes_stat
,
1180 .maxlen
= 2*sizeof(int),
1182 .proc_handler
= &proc_dointvec
,
1185 .ctl_name
= FS_STATINODE
,
1186 .procname
= "inode-state",
1187 .data
= &inodes_stat
,
1188 .maxlen
= 7*sizeof(int),
1190 .proc_handler
= &proc_dointvec
,
1193 .procname
= "file-nr",
1194 .data
= &files_stat
,
1195 .maxlen
= 3*sizeof(int),
1197 .proc_handler
= &proc_nr_files
,
1200 .ctl_name
= FS_MAXFILE
,
1201 .procname
= "file-max",
1202 .data
= &files_stat
.max_files
,
1203 .maxlen
= sizeof(int),
1205 .proc_handler
= &proc_dointvec
,
1208 .ctl_name
= CTL_UNNUMBERED
,
1209 .procname
= "nr_open",
1210 .data
= &sysctl_nr_open
,
1211 .maxlen
= sizeof(int),
1213 .proc_handler
= &proc_dointvec_minmax
,
1214 .extra1
= &sysctl_nr_open_min
,
1215 .extra2
= &sysctl_nr_open_max
,
1218 .ctl_name
= FS_DENTRY
,
1219 .procname
= "dentry-state",
1220 .data
= &dentry_stat
,
1221 .maxlen
= 6*sizeof(int),
1223 .proc_handler
= &proc_dointvec
,
1226 .ctl_name
= FS_OVERFLOWUID
,
1227 .procname
= "overflowuid",
1228 .data
= &fs_overflowuid
,
1229 .maxlen
= sizeof(int),
1231 .proc_handler
= &proc_dointvec_minmax
,
1232 .strategy
= &sysctl_intvec
,
1233 .extra1
= &minolduid
,
1234 .extra2
= &maxolduid
,
1237 .ctl_name
= FS_OVERFLOWGID
,
1238 .procname
= "overflowgid",
1239 .data
= &fs_overflowgid
,
1240 .maxlen
= sizeof(int),
1242 .proc_handler
= &proc_dointvec_minmax
,
1243 .strategy
= &sysctl_intvec
,
1244 .extra1
= &minolduid
,
1245 .extra2
= &maxolduid
,
1248 .ctl_name
= FS_LEASES
,
1249 .procname
= "leases-enable",
1250 .data
= &leases_enable
,
1251 .maxlen
= sizeof(int),
1253 .proc_handler
= &proc_dointvec
,
1255 #ifdef CONFIG_DNOTIFY
1257 .ctl_name
= FS_DIR_NOTIFY
,
1258 .procname
= "dir-notify-enable",
1259 .data
= &dir_notify_enable
,
1260 .maxlen
= sizeof(int),
1262 .proc_handler
= &proc_dointvec
,
1267 .ctl_name
= FS_LEASE_TIME
,
1268 .procname
= "lease-break-time",
1269 .data
= &lease_break_time
,
1270 .maxlen
= sizeof(int),
1272 .proc_handler
= &proc_dointvec_minmax
,
1273 .strategy
= &sysctl_intvec
,
1278 .procname
= "aio-nr",
1280 .maxlen
= sizeof(aio_nr
),
1282 .proc_handler
= &proc_doulongvec_minmax
,
1285 .procname
= "aio-max-nr",
1286 .data
= &aio_max_nr
,
1287 .maxlen
= sizeof(aio_max_nr
),
1289 .proc_handler
= &proc_doulongvec_minmax
,
1291 #ifdef CONFIG_INOTIFY_USER
1293 .ctl_name
= FS_INOTIFY
,
1294 .procname
= "inotify",
1296 .child
= inotify_table
,
1301 .ctl_name
= KERN_SETUID_DUMPABLE
,
1302 .procname
= "suid_dumpable",
1303 .data
= &suid_dumpable
,
1304 .maxlen
= sizeof(int),
1306 .proc_handler
= &proc_dointvec
,
1308 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1310 .ctl_name
= CTL_UNNUMBERED
,
1311 .procname
= "binfmt_misc",
1313 .child
= binfmt_misc_table
,
1317 * NOTE: do not add new entries to this table unless you have read
1318 * Documentation/sysctl/ctl_unnumbered.txt
1323 static struct ctl_table debug_table
[] = {
1324 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1326 .ctl_name
= CTL_UNNUMBERED
,
1327 .procname
= "exception-trace",
1328 .data
= &show_unhandled_signals
,
1329 .maxlen
= sizeof(int),
1331 .proc_handler
= proc_dointvec
1337 static struct ctl_table dev_table
[] = {
1341 static DEFINE_SPINLOCK(sysctl_lock
);
1343 /* called under sysctl_lock */
1344 static int use_table(struct ctl_table_header
*p
)
1346 if (unlikely(p
->unregistering
))
1352 /* called under sysctl_lock */
1353 static void unuse_table(struct ctl_table_header
*p
)
1356 if (unlikely(p
->unregistering
))
1357 complete(p
->unregistering
);
1360 /* called under sysctl_lock, will reacquire if has to wait */
1361 static void start_unregistering(struct ctl_table_header
*p
)
1364 * if p->used is 0, nobody will ever touch that entry again;
1365 * we'll eliminate all paths to it before dropping sysctl_lock
1367 if (unlikely(p
->used
)) {
1368 struct completion wait
;
1369 init_completion(&wait
);
1370 p
->unregistering
= &wait
;
1371 spin_unlock(&sysctl_lock
);
1372 wait_for_completion(&wait
);
1373 spin_lock(&sysctl_lock
);
1376 * do not remove from the list until nobody holds it; walking the
1377 * list in do_sysctl() relies on that.
1379 list_del_init(&p
->ctl_entry
);
1382 void sysctl_head_finish(struct ctl_table_header
*head
)
1386 spin_lock(&sysctl_lock
);
1388 spin_unlock(&sysctl_lock
);
1391 static struct list_head
*
1392 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1394 struct list_head
*header_list
;
1395 header_list
= &root
->header_list
;
1397 header_list
= root
->lookup(root
, namespaces
);
1401 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1402 struct ctl_table_header
*prev
)
1404 struct ctl_table_root
*root
;
1405 struct list_head
*header_list
;
1406 struct ctl_table_header
*head
;
1407 struct list_head
*tmp
;
1409 spin_lock(&sysctl_lock
);
1412 tmp
= &prev
->ctl_entry
;
1416 tmp
= &root_table_header
.ctl_entry
;
1418 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1420 if (!use_table(head
))
1422 spin_unlock(&sysctl_lock
);
1427 header_list
= lookup_header_list(root
, namespaces
);
1428 if (tmp
!= header_list
)
1432 root
= list_entry(root
->root_list
.next
,
1433 struct ctl_table_root
, root_list
);
1434 if (root
== &sysctl_table_root
)
1436 header_list
= lookup_header_list(root
, namespaces
);
1437 } while (list_empty(header_list
));
1438 tmp
= header_list
->next
;
1441 spin_unlock(&sysctl_lock
);
1445 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1447 return __sysctl_head_next(current
->nsproxy
, prev
);
1450 void register_sysctl_root(struct ctl_table_root
*root
)
1452 spin_lock(&sysctl_lock
);
1453 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1454 spin_unlock(&sysctl_lock
);
1457 #ifdef CONFIG_SYSCTL_SYSCALL
1458 /* Perform the actual read/write of a sysctl table entry. */
1459 static int do_sysctl_strategy(struct ctl_table_root
*root
,
1460 struct ctl_table
*table
,
1461 int __user
*name
, int nlen
,
1462 void __user
*oldval
, size_t __user
*oldlenp
,
1463 void __user
*newval
, size_t newlen
)
1471 if (sysctl_perm(root
, table
, op
))
1474 if (table
->strategy
) {
1475 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1483 /* If there is no strategy routine, or if the strategy returns
1484 * zero, proceed with automatic r/w */
1485 if (table
->data
&& table
->maxlen
) {
1486 rc
= sysctl_data(table
, name
, nlen
, oldval
, oldlenp
,
1494 static int parse_table(int __user
*name
, int nlen
,
1495 void __user
*oldval
, size_t __user
*oldlenp
,
1496 void __user
*newval
, size_t newlen
,
1497 struct ctl_table_root
*root
,
1498 struct ctl_table
*table
)
1504 if (get_user(n
, name
))
1506 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1507 if (!table
->ctl_name
)
1509 if (n
== table
->ctl_name
) {
1512 if (sysctl_perm(root
, table
, 001))
1516 table
= table
->child
;
1519 error
= do_sysctl_strategy(root
, table
, name
, nlen
,
1528 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1529 void __user
*newval
, size_t newlen
)
1531 struct ctl_table_header
*head
;
1532 int error
= -ENOTDIR
;
1534 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1538 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1542 for (head
= sysctl_head_next(NULL
); head
;
1543 head
= sysctl_head_next(head
)) {
1544 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1546 head
->root
, head
->ctl_table
);
1547 if (error
!= -ENOTDIR
) {
1548 sysctl_head_finish(head
);
1555 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1557 struct __sysctl_args tmp
;
1560 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1563 error
= deprecated_sysctl_warning(&tmp
);
1568 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1569 tmp
.newval
, tmp
.newlen
);
1574 #endif /* CONFIG_SYSCTL_SYSCALL */
1577 * sysctl_perm does NOT grant the superuser all rights automatically, because
1578 * some sysctl variables are readonly even to root.
1581 static int test_perm(int mode
, int op
)
1585 else if (in_egroup_p(0))
1587 if ((mode
& op
& 0007) == op
)
1592 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1597 error
= security_sysctl(table
, op
);
1601 if (root
->permissions
)
1602 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1606 return test_perm(mode
, op
);
1609 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1611 for (; table
->ctl_name
|| table
->procname
; table
++) {
1612 table
->parent
= parent
;
1614 sysctl_set_parent(table
, table
->child
);
1618 static __init
int sysctl_init(void)
1620 sysctl_set_parent(NULL
, root_table
);
1621 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1624 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1630 core_initcall(sysctl_init
);
1633 * __register_sysctl_paths - register a sysctl hierarchy
1634 * @root: List of sysctl headers to register on
1635 * @namespaces: Data to compute which lists of sysctl entries are visible
1636 * @path: The path to the directory the sysctl table is in.
1637 * @table: the top-level table structure
1639 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1640 * array. A completely 0 filled entry terminates the table.
1642 * The members of the &struct ctl_table structure are used as follows:
1644 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1645 * must be unique within that level of sysctl
1647 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1648 * enter a sysctl file
1650 * data - a pointer to data for use by proc_handler
1652 * maxlen - the maximum size in bytes of the data
1654 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1656 * child - a pointer to the child sysctl table if this entry is a directory, or
1659 * proc_handler - the text handler routine (described below)
1661 * strategy - the strategy routine (described below)
1663 * de - for internal use by the sysctl routines
1665 * extra1, extra2 - extra pointers usable by the proc handler routines
1667 * Leaf nodes in the sysctl tree will be represented by a single file
1668 * under /proc; non-leaf nodes will be represented by directories.
1670 * sysctl(2) can automatically manage read and write requests through
1671 * the sysctl table. The data and maxlen fields of the ctl_table
1672 * struct enable minimal validation of the values being written to be
1673 * performed, and the mode field allows minimal authentication.
1675 * More sophisticated management can be enabled by the provision of a
1676 * strategy routine with the table entry. This will be called before
1677 * any automatic read or write of the data is performed.
1679 * The strategy routine may return
1681 * < 0 - Error occurred (error is passed to user process)
1683 * 0 - OK - proceed with automatic read or write.
1685 * > 0 - OK - read or write has been done by the strategy routine, so
1686 * return immediately.
1688 * There must be a proc_handler routine for any terminal nodes
1689 * mirrored under /proc/sys (non-terminals are handled by a built-in
1690 * directory handler). Several default handlers are available to
1691 * cover common cases -
1693 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1694 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1695 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1697 * It is the handler's job to read the input buffer from user memory
1698 * and process it. The handler should return 0 on success.
1700 * This routine returns %NULL on a failure to register, and a pointer
1701 * to the table header on success.
1703 struct ctl_table_header
*__register_sysctl_paths(
1704 struct ctl_table_root
*root
,
1705 struct nsproxy
*namespaces
,
1706 const struct ctl_path
*path
, struct ctl_table
*table
)
1708 struct list_head
*header_list
;
1709 struct ctl_table_header
*header
;
1710 struct ctl_table
*new, **prevp
;
1711 unsigned int n
, npath
;
1713 /* Count the path components */
1714 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
1718 * For each path component, allocate a 2-element ctl_table array.
1719 * The first array element will be filled with the sysctl entry
1720 * for this, the second will be the sentinel (ctl_name == 0).
1722 * We allocate everything in one go so that we don't have to
1723 * worry about freeing additional memory in unregister_sysctl_table.
1725 header
= kzalloc(sizeof(struct ctl_table_header
) +
1726 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1730 new = (struct ctl_table
*) (header
+ 1);
1732 /* Now connect the dots */
1733 prevp
= &header
->ctl_table
;
1734 for (n
= 0; n
< npath
; ++n
, ++path
) {
1735 /* Copy the procname */
1736 new->procname
= path
->procname
;
1737 new->ctl_name
= path
->ctl_name
;
1741 prevp
= &new->child
;
1746 header
->ctl_table_arg
= table
;
1748 INIT_LIST_HEAD(&header
->ctl_entry
);
1750 header
->unregistering
= NULL
;
1751 header
->root
= root
;
1752 sysctl_set_parent(NULL
, header
->ctl_table
);
1753 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1754 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1759 spin_lock(&sysctl_lock
);
1760 header_list
= lookup_header_list(root
, namespaces
);
1761 list_add_tail(&header
->ctl_entry
, header_list
);
1762 spin_unlock(&sysctl_lock
);
1768 * register_sysctl_table_path - register a sysctl table hierarchy
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 * See __register_sysctl_paths for more details.
1777 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1778 struct ctl_table
*table
)
1780 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1785 * register_sysctl_table - register a sysctl table hierarchy
1786 * @table: the top-level table structure
1788 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1789 * array. A completely 0 filled entry terminates the table.
1791 * See register_sysctl_paths for more details.
1793 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1795 static const struct ctl_path null_path
[] = { {} };
1797 return register_sysctl_paths(null_path
, table
);
1801 * unregister_sysctl_table - unregister a sysctl table hierarchy
1802 * @header: the header returned from register_sysctl_table
1804 * Unregisters the sysctl table and all children. proc entries may not
1805 * actually be removed until they are no longer used by anyone.
1807 void unregister_sysctl_table(struct ctl_table_header
* header
)
1814 spin_lock(&sysctl_lock
);
1815 start_unregistering(header
);
1816 spin_unlock(&sysctl_lock
);
1820 #else /* !CONFIG_SYSCTL */
1821 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1826 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1827 struct ctl_table
*table
)
1832 void unregister_sysctl_table(struct ctl_table_header
* table
)
1836 #endif /* CONFIG_SYSCTL */
1842 #ifdef CONFIG_PROC_SYSCTL
1844 static int _proc_do_string(void* data
, int maxlen
, int write
,
1845 struct file
*filp
, void __user
*buffer
,
1846 size_t *lenp
, loff_t
*ppos
)
1852 if (!data
|| !maxlen
|| !*lenp
) {
1860 while (len
< *lenp
) {
1861 if (get_user(c
, p
++))
1863 if (c
== 0 || c
== '\n')
1869 if(copy_from_user(data
, buffer
, len
))
1871 ((char *) data
)[len
] = 0;
1889 if(copy_to_user(buffer
, data
, len
))
1892 if(put_user('\n', ((char __user
*) buffer
) + len
))
1903 * proc_dostring - read a string sysctl
1904 * @table: the sysctl table
1905 * @write: %TRUE if this is a write to the sysctl file
1906 * @filp: the file structure
1907 * @buffer: the user buffer
1908 * @lenp: the size of the user buffer
1909 * @ppos: file position
1911 * Reads/writes a string from/to the user buffer. If the kernel
1912 * buffer provided is not large enough to hold the string, the
1913 * string is truncated. The copied string is %NULL-terminated.
1914 * If the string is being read by the user process, it is copied
1915 * and a newline '\n' is added. It is truncated if the buffer is
1918 * Returns 0 on success.
1920 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
1921 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1923 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
1924 buffer
, lenp
, ppos
);
1928 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1930 int write
, void *data
)
1933 *valp
= *negp
? -*lvalp
: *lvalp
;
1938 *lvalp
= (unsigned long)-val
;
1941 *lvalp
= (unsigned long)val
;
1947 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1948 int write
, struct file
*filp
, void __user
*buffer
,
1949 size_t *lenp
, loff_t
*ppos
,
1950 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1951 int write
, void *data
),
1954 #define TMPBUFLEN 21
1955 int *i
, vleft
, first
=1, neg
, val
;
1959 char buf
[TMPBUFLEN
], *p
;
1960 char __user
*s
= buffer
;
1962 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
1963 (*ppos
&& !write
)) {
1968 i
= (int *) tbl_data
;
1969 vleft
= table
->maxlen
/ sizeof(*i
);
1973 conv
= do_proc_dointvec_conv
;
1975 for (; left
&& vleft
--; i
++, first
=0) {
1990 if (len
> sizeof(buf
) - 1)
1991 len
= sizeof(buf
) - 1;
1992 if (copy_from_user(buf
, s
, len
))
1996 if (*p
== '-' && left
> 1) {
2000 if (*p
< '0' || *p
> '9')
2003 lval
= simple_strtoul(p
, &p
, 0);
2006 if ((len
< left
) && *p
&& !isspace(*p
))
2013 if (conv(&neg
, &lval
, i
, 1, data
))
2020 if (conv(&neg
, &lval
, i
, 0, data
))
2023 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2027 if(copy_to_user(s
, buf
, len
))
2034 if (!write
&& !first
&& left
) {
2035 if(put_user('\n', s
))
2042 if (get_user(c
, s
++))
2057 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2058 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2059 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2060 int write
, void *data
),
2063 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2064 buffer
, lenp
, ppos
, conv
, data
);
2068 * proc_dointvec - read a vector of integers
2069 * @table: the sysctl table
2070 * @write: %TRUE if this is a write to the sysctl file
2071 * @filp: the file structure
2072 * @buffer: the user buffer
2073 * @lenp: the size of the user buffer
2074 * @ppos: file position
2076 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2077 * values from/to the user buffer, treated as an ASCII string.
2079 * Returns 0 on success.
2081 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2082 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2084 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2092 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
2094 int write
, void *data
)
2096 int op
= *(int *)data
;
2098 int val
= *negp
? -*lvalp
: *lvalp
;
2100 case OP_SET
: *valp
= val
; break;
2101 case OP_AND
: *valp
&= val
; break;
2102 case OP_OR
: *valp
|= val
; break;
2108 *lvalp
= (unsigned long)-val
;
2111 *lvalp
= (unsigned long)val
;
2118 * Taint values can only be increased
2120 static int proc_dointvec_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2121 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2125 if (write
&& !capable(CAP_SYS_ADMIN
))
2129 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2130 do_proc_dointvec_bset_conv
,&op
);
2133 struct do_proc_dointvec_minmax_conv_param
{
2138 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2140 int write
, void *data
)
2142 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2144 int val
= *negp
? -*lvalp
: *lvalp
;
2145 if ((param
->min
&& *param
->min
> val
) ||
2146 (param
->max
&& *param
->max
< val
))
2153 *lvalp
= (unsigned long)-val
;
2156 *lvalp
= (unsigned long)val
;
2163 * proc_dointvec_minmax - read a vector of integers with min/max values
2164 * @table: the sysctl table
2165 * @write: %TRUE if this is a write to the sysctl file
2166 * @filp: the file structure
2167 * @buffer: the user buffer
2168 * @lenp: the size of the user buffer
2169 * @ppos: file position
2171 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2172 * values from/to the user buffer, treated as an ASCII string.
2174 * This routine will ensure the values are within the range specified by
2175 * table->extra1 (min) and table->extra2 (max).
2177 * Returns 0 on success.
2179 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2180 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2182 struct do_proc_dointvec_minmax_conv_param param
= {
2183 .min
= (int *) table
->extra1
,
2184 .max
= (int *) table
->extra2
,
2186 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2187 do_proc_dointvec_minmax_conv
, ¶m
);
2190 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2192 void __user
*buffer
,
2193 size_t *lenp
, loff_t
*ppos
,
2194 unsigned long convmul
,
2195 unsigned long convdiv
)
2197 #define TMPBUFLEN 21
2198 unsigned long *i
, *min
, *max
, val
;
2199 int vleft
, first
=1, neg
;
2201 char buf
[TMPBUFLEN
], *p
;
2202 char __user
*s
= buffer
;
2204 if (!data
|| !table
->maxlen
|| !*lenp
||
2205 (*ppos
&& !write
)) {
2210 i
= (unsigned long *) data
;
2211 min
= (unsigned long *) table
->extra1
;
2212 max
= (unsigned long *) table
->extra2
;
2213 vleft
= table
->maxlen
/ sizeof(unsigned long);
2216 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2231 if (len
> TMPBUFLEN
-1)
2233 if (copy_from_user(buf
, s
, len
))
2237 if (*p
== '-' && left
> 1) {
2241 if (*p
< '0' || *p
> '9')
2243 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2245 if ((len
< left
) && *p
&& !isspace(*p
))
2254 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2261 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2265 if(copy_to_user(s
, buf
, len
))
2272 if (!write
&& !first
&& left
) {
2273 if(put_user('\n', s
))
2280 if (get_user(c
, s
++))
2295 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2297 void __user
*buffer
,
2298 size_t *lenp
, loff_t
*ppos
,
2299 unsigned long convmul
,
2300 unsigned long convdiv
)
2302 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2303 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2307 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2308 * @table: the sysctl table
2309 * @write: %TRUE if this is a write to the sysctl file
2310 * @filp: the file structure
2311 * @buffer: the user buffer
2312 * @lenp: the size of the user buffer
2313 * @ppos: file position
2315 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2316 * values from/to the user buffer, treated as an ASCII string.
2318 * This routine will ensure the values are within the range specified by
2319 * table->extra1 (min) and table->extra2 (max).
2321 * Returns 0 on success.
2323 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2324 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2326 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2330 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2331 * @table: the sysctl table
2332 * @write: %TRUE if this is a write to the sysctl file
2333 * @filp: the file structure
2334 * @buffer: the user buffer
2335 * @lenp: the size of the user buffer
2336 * @ppos: file position
2338 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2339 * values from/to the user buffer, treated as an ASCII string. The values
2340 * are treated as milliseconds, and converted to jiffies when they are stored.
2342 * This routine will ensure the values are within the range specified by
2343 * table->extra1 (min) and table->extra2 (max).
2345 * Returns 0 on success.
2347 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2349 void __user
*buffer
,
2350 size_t *lenp
, loff_t
*ppos
)
2352 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2353 lenp
, ppos
, HZ
, 1000l);
2357 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2359 int write
, void *data
)
2362 if (*lvalp
> LONG_MAX
/ HZ
)
2364 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2370 lval
= (unsigned long)-val
;
2373 lval
= (unsigned long)val
;
2380 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2382 int write
, void *data
)
2385 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2387 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2393 lval
= (unsigned long)-val
;
2396 lval
= (unsigned long)val
;
2398 *lvalp
= jiffies_to_clock_t(lval
);
2403 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2405 int write
, void *data
)
2408 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2414 lval
= (unsigned long)-val
;
2417 lval
= (unsigned long)val
;
2419 *lvalp
= jiffies_to_msecs(lval
);
2425 * proc_dointvec_jiffies - read a vector of integers as seconds
2426 * @table: the sysctl table
2427 * @write: %TRUE if this is a write to the sysctl file
2428 * @filp: the file structure
2429 * @buffer: the user buffer
2430 * @lenp: the size of the user buffer
2431 * @ppos: file position
2433 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2434 * values from/to the user buffer, treated as an ASCII string.
2435 * The values read are assumed to be in seconds, and are converted into
2438 * Returns 0 on success.
2440 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2441 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2443 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2444 do_proc_dointvec_jiffies_conv
,NULL
);
2448 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2449 * @table: the sysctl table
2450 * @write: %TRUE if this is a write to the sysctl file
2451 * @filp: the file structure
2452 * @buffer: the user buffer
2453 * @lenp: the size of the user buffer
2454 * @ppos: pointer to the file position
2456 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2457 * values from/to the user buffer, treated as an ASCII string.
2458 * The values read are assumed to be in 1/USER_HZ seconds, and
2459 * are converted into jiffies.
2461 * Returns 0 on success.
2463 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2464 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2466 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2467 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2471 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2472 * @table: the sysctl table
2473 * @write: %TRUE if this is a write to the sysctl file
2474 * @filp: the file structure
2475 * @buffer: the user buffer
2476 * @lenp: the size of the user buffer
2477 * @ppos: file position
2478 * @ppos: the current position in the file
2480 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2481 * values from/to the user buffer, treated as an ASCII string.
2482 * The values read are assumed to be in 1/1000 seconds, and
2483 * are converted into jiffies.
2485 * Returns 0 on success.
2487 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2488 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2490 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2491 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2494 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2495 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2497 struct pid
*new_pid
;
2501 tmp
= pid_vnr(cad_pid
);
2503 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2504 lenp
, ppos
, NULL
, NULL
);
2508 new_pid
= find_get_pid(tmp
);
2512 put_pid(xchg(&cad_pid
, new_pid
));
2516 #else /* CONFIG_PROC_FS */
2518 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2519 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2524 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2525 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2530 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2531 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2536 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2537 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2542 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2543 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2548 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2549 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2554 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2555 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2560 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2562 void __user
*buffer
,
2563 size_t *lenp
, loff_t
*ppos
)
2569 #endif /* CONFIG_PROC_FS */
2572 #ifdef CONFIG_SYSCTL_SYSCALL
2574 * General sysctl support routines
2577 /* The generic sysctl data routine (used if no strategy routine supplied) */
2578 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2579 void __user
*oldval
, size_t __user
*oldlenp
,
2580 void __user
*newval
, size_t newlen
)
2584 /* Get out of I don't have a variable */
2585 if (!table
->data
|| !table
->maxlen
)
2588 if (oldval
&& oldlenp
) {
2589 if (get_user(len
, oldlenp
))
2592 if (len
> table
->maxlen
)
2593 len
= table
->maxlen
;
2594 if (copy_to_user(oldval
, table
->data
, len
))
2596 if (put_user(len
, oldlenp
))
2601 if (newval
&& newlen
) {
2602 if (newlen
> table
->maxlen
)
2603 newlen
= table
->maxlen
;
2605 if (copy_from_user(table
->data
, newval
, newlen
))
2611 /* The generic string strategy routine: */
2612 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2613 void __user
*oldval
, size_t __user
*oldlenp
,
2614 void __user
*newval
, size_t newlen
)
2616 if (!table
->data
|| !table
->maxlen
)
2619 if (oldval
&& oldlenp
) {
2621 if (get_user(bufsize
, oldlenp
))
2624 size_t len
= strlen(table
->data
), copied
;
2626 /* This shouldn't trigger for a well-formed sysctl */
2627 if (len
> table
->maxlen
)
2628 len
= table
->maxlen
;
2630 /* Copy up to a max of bufsize-1 bytes of the string */
2631 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2633 if (copy_to_user(oldval
, table
->data
, copied
) ||
2634 put_user(0, (char __user
*)(oldval
+ copied
)))
2636 if (put_user(len
, oldlenp
))
2640 if (newval
&& newlen
) {
2641 size_t len
= newlen
;
2642 if (len
> table
->maxlen
)
2643 len
= table
->maxlen
;
2644 if(copy_from_user(table
->data
, newval
, len
))
2646 if (len
== table
->maxlen
)
2648 ((char *) table
->data
)[len
] = 0;
2654 * This function makes sure that all of the integers in the vector
2655 * are between the minimum and maximum values given in the arrays
2656 * table->extra1 and table->extra2, respectively.
2658 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2659 void __user
*oldval
, size_t __user
*oldlenp
,
2660 void __user
*newval
, size_t newlen
)
2663 if (newval
&& newlen
) {
2664 int __user
*vec
= (int __user
*) newval
;
2665 int *min
= (int *) table
->extra1
;
2666 int *max
= (int *) table
->extra2
;
2670 if (newlen
% sizeof(int) != 0)
2673 if (!table
->extra1
&& !table
->extra2
)
2676 if (newlen
> table
->maxlen
)
2677 newlen
= table
->maxlen
;
2678 length
= newlen
/ sizeof(int);
2680 for (i
= 0; i
< length
; i
++) {
2682 if (get_user(value
, vec
+ i
))
2684 if (min
&& value
< min
[i
])
2686 if (max
&& value
> max
[i
])
2693 /* Strategy function to convert jiffies to seconds */
2694 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2695 void __user
*oldval
, size_t __user
*oldlenp
,
2696 void __user
*newval
, size_t newlen
)
2698 if (oldval
&& oldlenp
) {
2701 if (get_user(olen
, oldlenp
))
2706 if (olen
< sizeof(int))
2709 val
= *(int *)(table
->data
) / HZ
;
2710 if (put_user(val
, (int __user
*)oldval
))
2712 if (put_user(sizeof(int), oldlenp
))
2716 if (newval
&& newlen
) {
2718 if (newlen
!= sizeof(int))
2720 if (get_user(new, (int __user
*)newval
))
2722 *(int *)(table
->data
) = new*HZ
;
2727 /* Strategy function to convert jiffies to seconds */
2728 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2729 void __user
*oldval
, size_t __user
*oldlenp
,
2730 void __user
*newval
, size_t newlen
)
2732 if (oldval
&& oldlenp
) {
2735 if (get_user(olen
, oldlenp
))
2740 if (olen
< sizeof(int))
2743 val
= jiffies_to_msecs(*(int *)(table
->data
));
2744 if (put_user(val
, (int __user
*)oldval
))
2746 if (put_user(sizeof(int), oldlenp
))
2750 if (newval
&& newlen
) {
2752 if (newlen
!= sizeof(int))
2754 if (get_user(new, (int __user
*)newval
))
2756 *(int *)(table
->data
) = msecs_to_jiffies(new);
2763 #else /* CONFIG_SYSCTL_SYSCALL */
2766 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2768 struct __sysctl_args tmp
;
2771 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
2774 error
= deprecated_sysctl_warning(&tmp
);
2776 /* If no error reading the parameters then just -ENOSYS ... */
2783 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2784 void __user
*oldval
, size_t __user
*oldlenp
,
2785 void __user
*newval
, size_t newlen
)
2790 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2791 void __user
*oldval
, size_t __user
*oldlenp
,
2792 void __user
*newval
, size_t newlen
)
2797 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2798 void __user
*oldval
, size_t __user
*oldlenp
,
2799 void __user
*newval
, size_t newlen
)
2804 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2805 void __user
*oldval
, size_t __user
*oldlenp
,
2806 void __user
*newval
, size_t newlen
)
2811 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2812 void __user
*oldval
, size_t __user
*oldlenp
,
2813 void __user
*newval
, size_t newlen
)
2818 #endif /* CONFIG_SYSCTL_SYSCALL */
2820 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
2822 static int msg_count
;
2823 int name
[CTL_MAXNAME
];
2826 /* Check args->nlen. */
2827 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
2830 /* Read in the sysctl name for better debug message logging */
2831 for (i
= 0; i
< args
->nlen
; i
++)
2832 if (get_user(name
[i
], args
->name
+ i
))
2835 /* Ignore accesses to kernel.version */
2836 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
2839 if (msg_count
< 5) {
2842 "warning: process `%s' used the deprecated sysctl "
2843 "system call with ", current
->comm
);
2844 for (i
= 0; i
< args
->nlen
; i
++)
2845 printk("%d.", name
[i
]);
2852 * No sense putting this after each symbol definition, twice,
2853 * exception granted :-)
2855 EXPORT_SYMBOL(proc_dointvec
);
2856 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2857 EXPORT_SYMBOL(proc_dointvec_minmax
);
2858 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2859 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2860 EXPORT_SYMBOL(proc_dostring
);
2861 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2862 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2863 EXPORT_SYMBOL(register_sysctl_table
);
2864 EXPORT_SYMBOL(register_sysctl_paths
);
2865 EXPORT_SYMBOL(sysctl_intvec
);
2866 EXPORT_SYMBOL(sysctl_jiffies
);
2867 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2868 EXPORT_SYMBOL(sysctl_string
);
2869 EXPORT_SYMBOL(sysctl_data
);
2870 EXPORT_SYMBOL(unregister_sysctl_table
);