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>
50 #include <asm/uaccess.h>
51 #include <asm/processor.h>
55 #include <asm/stacktrace.h>
59 static int deprecated_sysctl_warning(struct __sysctl_args
*args
);
61 #if defined(CONFIG_SYSCTL)
63 /* External variables not in a header file. */
65 extern int print_fatal_signals
;
66 extern int sysctl_overcommit_memory
;
67 extern int sysctl_overcommit_ratio
;
68 extern int sysctl_panic_on_oom
;
69 extern int sysctl_oom_kill_allocating_task
;
70 extern int sysctl_oom_dump_tasks
;
71 extern int max_threads
;
72 extern int core_uses_pid
;
73 extern int suid_dumpable
;
74 extern char core_pattern
[];
76 extern int min_free_kbytes
;
77 extern int pid_max_min
, pid_max_max
;
78 extern int sysctl_drop_caches
;
79 extern int percpu_pagelist_fraction
;
80 extern int compat_log
;
81 extern int maps_protect
;
82 extern int sysctl_stat_interval
;
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_DETECT_SOFTLOCKUP) || defined(CONFIG_HIGHMEM)
94 #ifdef CONFIG_DETECT_SOFTLOCKUP
95 static int sixty
= 60;
103 static int one_hundred
= 100;
105 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
106 static int maxolduid
= 65535;
107 static int minolduid
;
108 static int min_percpu_pagelist_fract
= 8;
110 static int ngroups_max
= NGROUPS_MAX
;
113 extern char modprobe_path
[];
115 #ifdef CONFIG_CHR_DEV_SG
116 extern int sg_big_buff
;
120 extern char reboot_command
[];
121 extern int stop_a_enabled
;
122 extern int scons_pwroff
;
126 extern int pwrsw_enabled
;
127 extern int unaligned_enabled
;
131 #ifdef CONFIG_MATHEMU
132 extern int sysctl_ieee_emulation_warnings
;
134 extern int sysctl_userprocess_debug
;
135 extern int spin_retry
;
138 extern int sysctl_hz_timer
;
140 #ifdef CONFIG_BSD_PROCESS_ACCT
141 extern int acct_parm
[];
145 extern int no_unaligned_warning
;
148 #ifdef CONFIG_RT_MUTEXES
149 extern int max_lock_depth
;
152 #ifdef CONFIG_PROC_SYSCTL
153 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
154 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
155 static int proc_dointvec_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
156 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
159 static struct ctl_table root_table
[];
160 static struct ctl_table_root sysctl_table_root
;
161 static struct ctl_table_header root_table_header
= {
162 .ctl_table
= root_table
,
163 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.header_list
),
164 .root
= &sysctl_table_root
,
166 static struct ctl_table_root sysctl_table_root
= {
167 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
168 .header_list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
171 static struct ctl_table kern_table
[];
172 static struct ctl_table vm_table
[];
173 static struct ctl_table fs_table
[];
174 static struct ctl_table debug_table
[];
175 static struct ctl_table dev_table
[];
176 extern struct ctl_table random_table
[];
177 #ifdef CONFIG_INOTIFY_USER
178 extern struct ctl_table inotify_table
[];
181 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
182 int sysctl_legacy_va_layout
;
185 extern int prove_locking
;
186 extern int lock_stat
;
188 /* The default sysctl tables: */
190 static struct ctl_table root_table
[] = {
192 .ctl_name
= CTL_KERN
,
193 .procname
= "kernel",
210 .ctl_name
= CTL_DEBUG
,
213 .child
= debug_table
,
222 * NOTE: do not add new entries to this table unless you have read
223 * Documentation/sysctl/ctl_unnumbered.txt
228 #ifdef CONFIG_SCHED_DEBUG
229 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
230 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
231 static int min_wakeup_granularity_ns
; /* 0 usecs */
232 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
235 static struct ctl_table kern_table
[] = {
236 #ifdef CONFIG_SCHED_DEBUG
238 .ctl_name
= CTL_UNNUMBERED
,
239 .procname
= "sched_min_granularity_ns",
240 .data
= &sysctl_sched_min_granularity
,
241 .maxlen
= sizeof(unsigned int),
243 .proc_handler
= &sched_nr_latency_handler
,
244 .strategy
= &sysctl_intvec
,
245 .extra1
= &min_sched_granularity_ns
,
246 .extra2
= &max_sched_granularity_ns
,
249 .ctl_name
= CTL_UNNUMBERED
,
250 .procname
= "sched_latency_ns",
251 .data
= &sysctl_sched_latency
,
252 .maxlen
= sizeof(unsigned int),
254 .proc_handler
= &sched_nr_latency_handler
,
255 .strategy
= &sysctl_intvec
,
256 .extra1
= &min_sched_granularity_ns
,
257 .extra2
= &max_sched_granularity_ns
,
260 .ctl_name
= CTL_UNNUMBERED
,
261 .procname
= "sched_wakeup_granularity_ns",
262 .data
= &sysctl_sched_wakeup_granularity
,
263 .maxlen
= sizeof(unsigned int),
265 .proc_handler
= &proc_dointvec_minmax
,
266 .strategy
= &sysctl_intvec
,
267 .extra1
= &min_wakeup_granularity_ns
,
268 .extra2
= &max_wakeup_granularity_ns
,
271 .ctl_name
= CTL_UNNUMBERED
,
272 .procname
= "sched_child_runs_first",
273 .data
= &sysctl_sched_child_runs_first
,
274 .maxlen
= sizeof(unsigned int),
276 .proc_handler
= &proc_dointvec
,
279 .ctl_name
= CTL_UNNUMBERED
,
280 .procname
= "sched_features",
281 .data
= &sysctl_sched_features
,
282 .maxlen
= sizeof(unsigned int),
284 .proc_handler
= &proc_dointvec
,
287 .ctl_name
= CTL_UNNUMBERED
,
288 .procname
= "sched_migration_cost",
289 .data
= &sysctl_sched_migration_cost
,
290 .maxlen
= sizeof(unsigned int),
292 .proc_handler
= &proc_dointvec
,
295 .ctl_name
= CTL_UNNUMBERED
,
296 .procname
= "sched_nr_migrate",
297 .data
= &sysctl_sched_nr_migrate
,
298 .maxlen
= sizeof(unsigned int),
300 .proc_handler
= &proc_dointvec
,
304 .ctl_name
= CTL_UNNUMBERED
,
305 .procname
= "sched_rt_period_us",
306 .data
= &sysctl_sched_rt_period
,
307 .maxlen
= sizeof(unsigned int),
309 .proc_handler
= &sched_rt_handler
,
312 .ctl_name
= CTL_UNNUMBERED
,
313 .procname
= "sched_rt_runtime_us",
314 .data
= &sysctl_sched_rt_runtime
,
315 .maxlen
= sizeof(int),
317 .proc_handler
= &sched_rt_handler
,
320 .ctl_name
= CTL_UNNUMBERED
,
321 .procname
= "sched_compat_yield",
322 .data
= &sysctl_sched_compat_yield
,
323 .maxlen
= sizeof(unsigned int),
325 .proc_handler
= &proc_dointvec
,
327 #ifdef CONFIG_PROVE_LOCKING
329 .ctl_name
= CTL_UNNUMBERED
,
330 .procname
= "prove_locking",
331 .data
= &prove_locking
,
332 .maxlen
= sizeof(int),
334 .proc_handler
= &proc_dointvec
,
337 #ifdef CONFIG_LOCK_STAT
339 .ctl_name
= CTL_UNNUMBERED
,
340 .procname
= "lock_stat",
342 .maxlen
= sizeof(int),
344 .proc_handler
= &proc_dointvec
,
348 .ctl_name
= KERN_PANIC
,
350 .data
= &panic_timeout
,
351 .maxlen
= sizeof(int),
353 .proc_handler
= &proc_dointvec
,
356 .ctl_name
= KERN_CORE_USES_PID
,
357 .procname
= "core_uses_pid",
358 .data
= &core_uses_pid
,
359 .maxlen
= sizeof(int),
361 .proc_handler
= &proc_dointvec
,
364 .ctl_name
= KERN_CORE_PATTERN
,
365 .procname
= "core_pattern",
366 .data
= core_pattern
,
367 .maxlen
= CORENAME_MAX_SIZE
,
369 .proc_handler
= &proc_dostring
,
370 .strategy
= &sysctl_string
,
372 #ifdef CONFIG_PROC_SYSCTL
374 .procname
= "tainted",
376 .maxlen
= sizeof(int),
378 .proc_handler
= &proc_dointvec_taint
,
381 #ifdef CONFIG_LATENCYTOP
383 .procname
= "latencytop",
384 .data
= &latencytop_enabled
,
385 .maxlen
= sizeof(int),
387 .proc_handler
= &proc_dointvec
,
390 #ifdef CONFIG_BLK_DEV_INITRD
392 .ctl_name
= KERN_REALROOTDEV
,
393 .procname
= "real-root-dev",
394 .data
= &real_root_dev
,
395 .maxlen
= sizeof(int),
397 .proc_handler
= &proc_dointvec
,
401 .ctl_name
= CTL_UNNUMBERED
,
402 .procname
= "print-fatal-signals",
403 .data
= &print_fatal_signals
,
404 .maxlen
= sizeof(int),
406 .proc_handler
= &proc_dointvec
,
410 .ctl_name
= KERN_SPARC_REBOOT
,
411 .procname
= "reboot-cmd",
412 .data
= reboot_command
,
415 .proc_handler
= &proc_dostring
,
416 .strategy
= &sysctl_string
,
419 .ctl_name
= KERN_SPARC_STOP_A
,
420 .procname
= "stop-a",
421 .data
= &stop_a_enabled
,
422 .maxlen
= sizeof (int),
424 .proc_handler
= &proc_dointvec
,
427 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
428 .procname
= "scons-poweroff",
429 .data
= &scons_pwroff
,
430 .maxlen
= sizeof (int),
432 .proc_handler
= &proc_dointvec
,
437 .ctl_name
= KERN_HPPA_PWRSW
,
438 .procname
= "soft-power",
439 .data
= &pwrsw_enabled
,
440 .maxlen
= sizeof (int),
442 .proc_handler
= &proc_dointvec
,
445 .ctl_name
= KERN_HPPA_UNALIGNED
,
446 .procname
= "unaligned-trap",
447 .data
= &unaligned_enabled
,
448 .maxlen
= sizeof (int),
450 .proc_handler
= &proc_dointvec
,
454 .ctl_name
= KERN_CTLALTDEL
,
455 .procname
= "ctrl-alt-del",
457 .maxlen
= sizeof(int),
459 .proc_handler
= &proc_dointvec
,
463 .ctl_name
= KERN_MODPROBE
,
464 .procname
= "modprobe",
465 .data
= &modprobe_path
,
466 .maxlen
= KMOD_PATH_LEN
,
468 .proc_handler
= &proc_dostring
,
469 .strategy
= &sysctl_string
,
472 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
474 .ctl_name
= KERN_HOTPLUG
,
475 .procname
= "hotplug",
476 .data
= &uevent_helper
,
477 .maxlen
= UEVENT_HELPER_PATH_LEN
,
479 .proc_handler
= &proc_dostring
,
480 .strategy
= &sysctl_string
,
483 #ifdef CONFIG_CHR_DEV_SG
485 .ctl_name
= KERN_SG_BIG_BUFF
,
486 .procname
= "sg-big-buff",
487 .data
= &sg_big_buff
,
488 .maxlen
= sizeof (int),
490 .proc_handler
= &proc_dointvec
,
493 #ifdef CONFIG_BSD_PROCESS_ACCT
495 .ctl_name
= KERN_ACCT
,
498 .maxlen
= 3*sizeof(int),
500 .proc_handler
= &proc_dointvec
,
503 #ifdef CONFIG_MAGIC_SYSRQ
505 .ctl_name
= KERN_SYSRQ
,
507 .data
= &__sysrq_enabled
,
508 .maxlen
= sizeof (int),
510 .proc_handler
= &proc_dointvec
,
513 #ifdef CONFIG_PROC_SYSCTL
515 .procname
= "cad_pid",
517 .maxlen
= sizeof (int),
519 .proc_handler
= &proc_do_cad_pid
,
523 .ctl_name
= KERN_MAX_THREADS
,
524 .procname
= "threads-max",
525 .data
= &max_threads
,
526 .maxlen
= sizeof(int),
528 .proc_handler
= &proc_dointvec
,
531 .ctl_name
= KERN_RANDOM
,
532 .procname
= "random",
534 .child
= random_table
,
537 .ctl_name
= KERN_OVERFLOWUID
,
538 .procname
= "overflowuid",
539 .data
= &overflowuid
,
540 .maxlen
= sizeof(int),
542 .proc_handler
= &proc_dointvec_minmax
,
543 .strategy
= &sysctl_intvec
,
544 .extra1
= &minolduid
,
545 .extra2
= &maxolduid
,
548 .ctl_name
= KERN_OVERFLOWGID
,
549 .procname
= "overflowgid",
550 .data
= &overflowgid
,
551 .maxlen
= sizeof(int),
553 .proc_handler
= &proc_dointvec_minmax
,
554 .strategy
= &sysctl_intvec
,
555 .extra1
= &minolduid
,
556 .extra2
= &maxolduid
,
559 #ifdef CONFIG_MATHEMU
561 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
562 .procname
= "ieee_emulation_warnings",
563 .data
= &sysctl_ieee_emulation_warnings
,
564 .maxlen
= sizeof(int),
566 .proc_handler
= &proc_dointvec
,
569 #ifdef CONFIG_NO_IDLE_HZ
571 .ctl_name
= KERN_HZ_TIMER
,
572 .procname
= "hz_timer",
573 .data
= &sysctl_hz_timer
,
574 .maxlen
= sizeof(int),
576 .proc_handler
= &proc_dointvec
,
580 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
581 .procname
= "userprocess_debug",
582 .data
= &sysctl_userprocess_debug
,
583 .maxlen
= sizeof(int),
585 .proc_handler
= &proc_dointvec
,
589 .ctl_name
= KERN_PIDMAX
,
590 .procname
= "pid_max",
592 .maxlen
= sizeof (int),
594 .proc_handler
= &proc_dointvec_minmax
,
595 .strategy
= sysctl_intvec
,
596 .extra1
= &pid_max_min
,
597 .extra2
= &pid_max_max
,
600 .ctl_name
= KERN_PANIC_ON_OOPS
,
601 .procname
= "panic_on_oops",
602 .data
= &panic_on_oops
,
603 .maxlen
= sizeof(int),
605 .proc_handler
= &proc_dointvec
,
607 #if defined CONFIG_PRINTK
609 .ctl_name
= KERN_PRINTK
,
610 .procname
= "printk",
611 .data
= &console_loglevel
,
612 .maxlen
= 4*sizeof(int),
614 .proc_handler
= &proc_dointvec
,
617 .ctl_name
= KERN_PRINTK_RATELIMIT
,
618 .procname
= "printk_ratelimit",
619 .data
= &printk_ratelimit_jiffies
,
620 .maxlen
= sizeof(int),
622 .proc_handler
= &proc_dointvec_jiffies
,
623 .strategy
= &sysctl_jiffies
,
626 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
627 .procname
= "printk_ratelimit_burst",
628 .data
= &printk_ratelimit_burst
,
629 .maxlen
= sizeof(int),
631 .proc_handler
= &proc_dointvec
,
635 .ctl_name
= KERN_NGROUPS_MAX
,
636 .procname
= "ngroups_max",
637 .data
= &ngroups_max
,
638 .maxlen
= sizeof (int),
640 .proc_handler
= &proc_dointvec
,
642 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
644 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
645 .procname
= "unknown_nmi_panic",
646 .data
= &unknown_nmi_panic
,
647 .maxlen
= sizeof (int),
649 .proc_handler
= &proc_dointvec
,
652 .procname
= "nmi_watchdog",
653 .data
= &nmi_watchdog_enabled
,
654 .maxlen
= sizeof (int),
656 .proc_handler
= &proc_nmi_enabled
,
659 #if defined(CONFIG_X86)
661 .ctl_name
= KERN_PANIC_ON_NMI
,
662 .procname
= "panic_on_unrecovered_nmi",
663 .data
= &panic_on_unrecovered_nmi
,
664 .maxlen
= sizeof(int),
666 .proc_handler
= &proc_dointvec
,
669 .ctl_name
= KERN_BOOTLOADER_TYPE
,
670 .procname
= "bootloader_type",
671 .data
= &bootloader_type
,
672 .maxlen
= sizeof (int),
674 .proc_handler
= &proc_dointvec
,
677 .ctl_name
= CTL_UNNUMBERED
,
678 .procname
= "kstack_depth_to_print",
679 .data
= &kstack_depth_to_print
,
680 .maxlen
= sizeof(int),
682 .proc_handler
= &proc_dointvec
,
685 .ctl_name
= CTL_UNNUMBERED
,
686 .procname
= "io_delay_type",
687 .data
= &io_delay_type
,
688 .maxlen
= sizeof(int),
690 .proc_handler
= &proc_dointvec
,
693 #if defined(CONFIG_MMU)
695 .ctl_name
= KERN_RANDOMIZE
,
696 .procname
= "randomize_va_space",
697 .data
= &randomize_va_space
,
698 .maxlen
= sizeof(int),
700 .proc_handler
= &proc_dointvec
,
703 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
705 .ctl_name
= KERN_SPIN_RETRY
,
706 .procname
= "spin_retry",
708 .maxlen
= sizeof (int),
710 .proc_handler
= &proc_dointvec
,
713 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
715 .procname
= "acpi_video_flags",
716 .data
= &acpi_realmode_flags
,
717 .maxlen
= sizeof (unsigned long),
719 .proc_handler
= &proc_doulongvec_minmax
,
724 .ctl_name
= KERN_IA64_UNALIGNED
,
725 .procname
= "ignore-unaligned-usertrap",
726 .data
= &no_unaligned_warning
,
727 .maxlen
= sizeof (int),
729 .proc_handler
= &proc_dointvec
,
732 #ifdef CONFIG_DETECT_SOFTLOCKUP
734 .ctl_name
= CTL_UNNUMBERED
,
735 .procname
= "softlockup_thresh",
736 .data
= &softlockup_thresh
,
737 .maxlen
= sizeof(unsigned long),
739 .proc_handler
= &proc_doulongvec_minmax
,
740 .strategy
= &sysctl_intvec
,
745 .ctl_name
= CTL_UNNUMBERED
,
746 .procname
= "hung_task_check_count",
747 .data
= &sysctl_hung_task_check_count
,
748 .maxlen
= sizeof(unsigned long),
750 .proc_handler
= &proc_doulongvec_minmax
,
751 .strategy
= &sysctl_intvec
,
754 .ctl_name
= CTL_UNNUMBERED
,
755 .procname
= "hung_task_timeout_secs",
756 .data
= &sysctl_hung_task_timeout_secs
,
757 .maxlen
= sizeof(unsigned long),
759 .proc_handler
= &proc_doulongvec_minmax
,
760 .strategy
= &sysctl_intvec
,
763 .ctl_name
= CTL_UNNUMBERED
,
764 .procname
= "hung_task_warnings",
765 .data
= &sysctl_hung_task_warnings
,
766 .maxlen
= sizeof(unsigned long),
768 .proc_handler
= &proc_doulongvec_minmax
,
769 .strategy
= &sysctl_intvec
,
774 .ctl_name
= KERN_COMPAT_LOG
,
775 .procname
= "compat-log",
777 .maxlen
= sizeof (int),
779 .proc_handler
= &proc_dointvec
,
782 #ifdef CONFIG_RT_MUTEXES
784 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
785 .procname
= "max_lock_depth",
786 .data
= &max_lock_depth
,
787 .maxlen
= sizeof(int),
789 .proc_handler
= &proc_dointvec
,
792 #ifdef CONFIG_PROC_FS
794 .ctl_name
= CTL_UNNUMBERED
,
795 .procname
= "maps_protect",
796 .data
= &maps_protect
,
797 .maxlen
= sizeof(int),
799 .proc_handler
= &proc_dointvec
,
803 .ctl_name
= CTL_UNNUMBERED
,
804 .procname
= "poweroff_cmd",
805 .data
= &poweroff_cmd
,
806 .maxlen
= POWEROFF_CMD_PATH_LEN
,
808 .proc_handler
= &proc_dostring
,
809 .strategy
= &sysctl_string
,
813 .ctl_name
= CTL_UNNUMBERED
,
816 .child
= key_sysctls
,
819 #ifdef CONFIG_RCU_TORTURE_TEST
821 .ctl_name
= CTL_UNNUMBERED
,
822 .procname
= "rcutorture_runnable",
823 .data
= &rcutorture_runnable
,
824 .maxlen
= sizeof(int),
826 .proc_handler
= &proc_dointvec
,
830 * NOTE: do not add new entries to this table unless you have read
831 * Documentation/sysctl/ctl_unnumbered.txt
836 static struct ctl_table vm_table
[] = {
838 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
839 .procname
= "overcommit_memory",
840 .data
= &sysctl_overcommit_memory
,
841 .maxlen
= sizeof(sysctl_overcommit_memory
),
843 .proc_handler
= &proc_dointvec
,
846 .ctl_name
= VM_PANIC_ON_OOM
,
847 .procname
= "panic_on_oom",
848 .data
= &sysctl_panic_on_oom
,
849 .maxlen
= sizeof(sysctl_panic_on_oom
),
851 .proc_handler
= &proc_dointvec
,
854 .ctl_name
= CTL_UNNUMBERED
,
855 .procname
= "oom_kill_allocating_task",
856 .data
= &sysctl_oom_kill_allocating_task
,
857 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
859 .proc_handler
= &proc_dointvec
,
862 .ctl_name
= CTL_UNNUMBERED
,
863 .procname
= "oom_dump_tasks",
864 .data
= &sysctl_oom_dump_tasks
,
865 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
867 .proc_handler
= &proc_dointvec
,
870 .ctl_name
= VM_OVERCOMMIT_RATIO
,
871 .procname
= "overcommit_ratio",
872 .data
= &sysctl_overcommit_ratio
,
873 .maxlen
= sizeof(sysctl_overcommit_ratio
),
875 .proc_handler
= &proc_dointvec
,
878 .ctl_name
= VM_PAGE_CLUSTER
,
879 .procname
= "page-cluster",
880 .data
= &page_cluster
,
881 .maxlen
= sizeof(int),
883 .proc_handler
= &proc_dointvec
,
886 .ctl_name
= VM_DIRTY_BACKGROUND
,
887 .procname
= "dirty_background_ratio",
888 .data
= &dirty_background_ratio
,
889 .maxlen
= sizeof(dirty_background_ratio
),
891 .proc_handler
= &proc_dointvec_minmax
,
892 .strategy
= &sysctl_intvec
,
894 .extra2
= &one_hundred
,
897 .ctl_name
= VM_DIRTY_RATIO
,
898 .procname
= "dirty_ratio",
899 .data
= &vm_dirty_ratio
,
900 .maxlen
= sizeof(vm_dirty_ratio
),
902 .proc_handler
= &dirty_ratio_handler
,
903 .strategy
= &sysctl_intvec
,
905 .extra2
= &one_hundred
,
908 .procname
= "dirty_writeback_centisecs",
909 .data
= &dirty_writeback_interval
,
910 .maxlen
= sizeof(dirty_writeback_interval
),
912 .proc_handler
= &dirty_writeback_centisecs_handler
,
915 .procname
= "dirty_expire_centisecs",
916 .data
= &dirty_expire_interval
,
917 .maxlen
= sizeof(dirty_expire_interval
),
919 .proc_handler
= &proc_dointvec_userhz_jiffies
,
922 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
923 .procname
= "nr_pdflush_threads",
924 .data
= &nr_pdflush_threads
,
925 .maxlen
= sizeof nr_pdflush_threads
,
926 .mode
= 0444 /* read-only*/,
927 .proc_handler
= &proc_dointvec
,
930 .ctl_name
= VM_SWAPPINESS
,
931 .procname
= "swappiness",
932 .data
= &vm_swappiness
,
933 .maxlen
= sizeof(vm_swappiness
),
935 .proc_handler
= &proc_dointvec_minmax
,
936 .strategy
= &sysctl_intvec
,
938 .extra2
= &one_hundred
,
940 #ifdef CONFIG_HUGETLB_PAGE
942 .procname
= "nr_hugepages",
943 .data
= &max_huge_pages
,
944 .maxlen
= sizeof(unsigned long),
946 .proc_handler
= &hugetlb_sysctl_handler
,
947 .extra1
= (void *)&hugetlb_zero
,
948 .extra2
= (void *)&hugetlb_infinity
,
951 .ctl_name
= VM_HUGETLB_GROUP
,
952 .procname
= "hugetlb_shm_group",
953 .data
= &sysctl_hugetlb_shm_group
,
954 .maxlen
= sizeof(gid_t
),
956 .proc_handler
= &proc_dointvec
,
959 .ctl_name
= CTL_UNNUMBERED
,
960 .procname
= "hugepages_treat_as_movable",
961 .data
= &hugepages_treat_as_movable
,
962 .maxlen
= sizeof(int),
964 .proc_handler
= &hugetlb_treat_movable_handler
,
967 .ctl_name
= CTL_UNNUMBERED
,
968 .procname
= "nr_overcommit_hugepages",
969 .data
= &sysctl_overcommit_huge_pages
,
970 .maxlen
= sizeof(sysctl_overcommit_huge_pages
),
972 .proc_handler
= &hugetlb_overcommit_handler
,
976 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
977 .procname
= "lowmem_reserve_ratio",
978 .data
= &sysctl_lowmem_reserve_ratio
,
979 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
981 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
982 .strategy
= &sysctl_intvec
,
985 .ctl_name
= VM_DROP_PAGECACHE
,
986 .procname
= "drop_caches",
987 .data
= &sysctl_drop_caches
,
988 .maxlen
= sizeof(int),
990 .proc_handler
= drop_caches_sysctl_handler
,
991 .strategy
= &sysctl_intvec
,
994 .ctl_name
= VM_MIN_FREE_KBYTES
,
995 .procname
= "min_free_kbytes",
996 .data
= &min_free_kbytes
,
997 .maxlen
= sizeof(min_free_kbytes
),
999 .proc_handler
= &min_free_kbytes_sysctl_handler
,
1000 .strategy
= &sysctl_intvec
,
1004 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
1005 .procname
= "percpu_pagelist_fraction",
1006 .data
= &percpu_pagelist_fraction
,
1007 .maxlen
= sizeof(percpu_pagelist_fraction
),
1009 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
1010 .strategy
= &sysctl_intvec
,
1011 .extra1
= &min_percpu_pagelist_fract
,
1015 .ctl_name
= VM_MAX_MAP_COUNT
,
1016 .procname
= "max_map_count",
1017 .data
= &sysctl_max_map_count
,
1018 .maxlen
= sizeof(sysctl_max_map_count
),
1020 .proc_handler
= &proc_dointvec
1024 .ctl_name
= VM_LAPTOP_MODE
,
1025 .procname
= "laptop_mode",
1026 .data
= &laptop_mode
,
1027 .maxlen
= sizeof(laptop_mode
),
1029 .proc_handler
= &proc_dointvec_jiffies
,
1030 .strategy
= &sysctl_jiffies
,
1033 .ctl_name
= VM_BLOCK_DUMP
,
1034 .procname
= "block_dump",
1035 .data
= &block_dump
,
1036 .maxlen
= sizeof(block_dump
),
1038 .proc_handler
= &proc_dointvec
,
1039 .strategy
= &sysctl_intvec
,
1043 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
1044 .procname
= "vfs_cache_pressure",
1045 .data
= &sysctl_vfs_cache_pressure
,
1046 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1048 .proc_handler
= &proc_dointvec
,
1049 .strategy
= &sysctl_intvec
,
1052 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1054 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
1055 .procname
= "legacy_va_layout",
1056 .data
= &sysctl_legacy_va_layout
,
1057 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1059 .proc_handler
= &proc_dointvec
,
1060 .strategy
= &sysctl_intvec
,
1066 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
1067 .procname
= "zone_reclaim_mode",
1068 .data
= &zone_reclaim_mode
,
1069 .maxlen
= sizeof(zone_reclaim_mode
),
1071 .proc_handler
= &proc_dointvec
,
1072 .strategy
= &sysctl_intvec
,
1076 .ctl_name
= VM_MIN_UNMAPPED
,
1077 .procname
= "min_unmapped_ratio",
1078 .data
= &sysctl_min_unmapped_ratio
,
1079 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1081 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
1082 .strategy
= &sysctl_intvec
,
1084 .extra2
= &one_hundred
,
1087 .ctl_name
= VM_MIN_SLAB
,
1088 .procname
= "min_slab_ratio",
1089 .data
= &sysctl_min_slab_ratio
,
1090 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1092 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
1093 .strategy
= &sysctl_intvec
,
1095 .extra2
= &one_hundred
,
1100 .ctl_name
= CTL_UNNUMBERED
,
1101 .procname
= "stat_interval",
1102 .data
= &sysctl_stat_interval
,
1103 .maxlen
= sizeof(sysctl_stat_interval
),
1105 .proc_handler
= &proc_dointvec_jiffies
,
1106 .strategy
= &sysctl_jiffies
,
1109 #ifdef CONFIG_SECURITY
1111 .ctl_name
= CTL_UNNUMBERED
,
1112 .procname
= "mmap_min_addr",
1113 .data
= &mmap_min_addr
,
1114 .maxlen
= sizeof(unsigned long),
1116 .proc_handler
= &proc_doulongvec_minmax
,
1121 .ctl_name
= CTL_UNNUMBERED
,
1122 .procname
= "numa_zonelist_order",
1123 .data
= &numa_zonelist_order
,
1124 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1126 .proc_handler
= &numa_zonelist_order_handler
,
1127 .strategy
= &sysctl_string
,
1130 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1131 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1133 .ctl_name
= VM_VDSO_ENABLED
,
1134 .procname
= "vdso_enabled",
1135 .data
= &vdso_enabled
,
1136 .maxlen
= sizeof(vdso_enabled
),
1138 .proc_handler
= &proc_dointvec
,
1139 .strategy
= &sysctl_intvec
,
1143 #ifdef CONFIG_HIGHMEM
1145 .ctl_name
= CTL_UNNUMBERED
,
1146 .procname
= "highmem_is_dirtyable",
1147 .data
= &vm_highmem_is_dirtyable
,
1148 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1150 .proc_handler
= &proc_dointvec_minmax
,
1151 .strategy
= &sysctl_intvec
,
1157 * NOTE: do not add new entries to this table unless you have read
1158 * Documentation/sysctl/ctl_unnumbered.txt
1163 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1164 static struct ctl_table binfmt_misc_table
[] = {
1169 static struct ctl_table fs_table
[] = {
1171 .ctl_name
= FS_NRINODE
,
1172 .procname
= "inode-nr",
1173 .data
= &inodes_stat
,
1174 .maxlen
= 2*sizeof(int),
1176 .proc_handler
= &proc_dointvec
,
1179 .ctl_name
= FS_STATINODE
,
1180 .procname
= "inode-state",
1181 .data
= &inodes_stat
,
1182 .maxlen
= 7*sizeof(int),
1184 .proc_handler
= &proc_dointvec
,
1187 .procname
= "file-nr",
1188 .data
= &files_stat
,
1189 .maxlen
= 3*sizeof(int),
1191 .proc_handler
= &proc_nr_files
,
1194 .ctl_name
= FS_MAXFILE
,
1195 .procname
= "file-max",
1196 .data
= &files_stat
.max_files
,
1197 .maxlen
= sizeof(int),
1199 .proc_handler
= &proc_dointvec
,
1202 .ctl_name
= CTL_UNNUMBERED
,
1203 .procname
= "nr_open",
1204 .data
= &sysctl_nr_open
,
1205 .maxlen
= sizeof(int),
1207 .proc_handler
= &proc_dointvec_minmax
,
1208 .extra1
= &sysctl_nr_open_min
,
1209 .extra2
= &sysctl_nr_open_max
,
1212 .ctl_name
= FS_DENTRY
,
1213 .procname
= "dentry-state",
1214 .data
= &dentry_stat
,
1215 .maxlen
= 6*sizeof(int),
1217 .proc_handler
= &proc_dointvec
,
1220 .ctl_name
= FS_OVERFLOWUID
,
1221 .procname
= "overflowuid",
1222 .data
= &fs_overflowuid
,
1223 .maxlen
= sizeof(int),
1225 .proc_handler
= &proc_dointvec_minmax
,
1226 .strategy
= &sysctl_intvec
,
1227 .extra1
= &minolduid
,
1228 .extra2
= &maxolduid
,
1231 .ctl_name
= FS_OVERFLOWGID
,
1232 .procname
= "overflowgid",
1233 .data
= &fs_overflowgid
,
1234 .maxlen
= sizeof(int),
1236 .proc_handler
= &proc_dointvec_minmax
,
1237 .strategy
= &sysctl_intvec
,
1238 .extra1
= &minolduid
,
1239 .extra2
= &maxolduid
,
1242 .ctl_name
= FS_LEASES
,
1243 .procname
= "leases-enable",
1244 .data
= &leases_enable
,
1245 .maxlen
= sizeof(int),
1247 .proc_handler
= &proc_dointvec
,
1249 #ifdef CONFIG_DNOTIFY
1251 .ctl_name
= FS_DIR_NOTIFY
,
1252 .procname
= "dir-notify-enable",
1253 .data
= &dir_notify_enable
,
1254 .maxlen
= sizeof(int),
1256 .proc_handler
= &proc_dointvec
,
1261 .ctl_name
= FS_LEASE_TIME
,
1262 .procname
= "lease-break-time",
1263 .data
= &lease_break_time
,
1264 .maxlen
= sizeof(int),
1266 .proc_handler
= &proc_dointvec_minmax
,
1267 .strategy
= &sysctl_intvec
,
1272 .procname
= "aio-nr",
1274 .maxlen
= sizeof(aio_nr
),
1276 .proc_handler
= &proc_doulongvec_minmax
,
1279 .procname
= "aio-max-nr",
1280 .data
= &aio_max_nr
,
1281 .maxlen
= sizeof(aio_max_nr
),
1283 .proc_handler
= &proc_doulongvec_minmax
,
1285 #ifdef CONFIG_INOTIFY_USER
1287 .ctl_name
= FS_INOTIFY
,
1288 .procname
= "inotify",
1290 .child
= inotify_table
,
1295 .ctl_name
= KERN_SETUID_DUMPABLE
,
1296 .procname
= "suid_dumpable",
1297 .data
= &suid_dumpable
,
1298 .maxlen
= sizeof(int),
1300 .proc_handler
= &proc_dointvec
,
1302 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1304 .ctl_name
= CTL_UNNUMBERED
,
1305 .procname
= "binfmt_misc",
1307 .child
= binfmt_misc_table
,
1311 * NOTE: do not add new entries to this table unless you have read
1312 * Documentation/sysctl/ctl_unnumbered.txt
1317 static struct ctl_table debug_table
[] = {
1318 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1320 .ctl_name
= CTL_UNNUMBERED
,
1321 .procname
= "exception-trace",
1322 .data
= &show_unhandled_signals
,
1323 .maxlen
= sizeof(int),
1325 .proc_handler
= proc_dointvec
1331 static struct ctl_table dev_table
[] = {
1335 static DEFINE_SPINLOCK(sysctl_lock
);
1337 /* called under sysctl_lock */
1338 static int use_table(struct ctl_table_header
*p
)
1340 if (unlikely(p
->unregistering
))
1346 /* called under sysctl_lock */
1347 static void unuse_table(struct ctl_table_header
*p
)
1350 if (unlikely(p
->unregistering
))
1351 complete(p
->unregistering
);
1354 /* called under sysctl_lock, will reacquire if has to wait */
1355 static void start_unregistering(struct ctl_table_header
*p
)
1358 * if p->used is 0, nobody will ever touch that entry again;
1359 * we'll eliminate all paths to it before dropping sysctl_lock
1361 if (unlikely(p
->used
)) {
1362 struct completion wait
;
1363 init_completion(&wait
);
1364 p
->unregistering
= &wait
;
1365 spin_unlock(&sysctl_lock
);
1366 wait_for_completion(&wait
);
1367 spin_lock(&sysctl_lock
);
1370 * do not remove from the list until nobody holds it; walking the
1371 * list in do_sysctl() relies on that.
1373 list_del_init(&p
->ctl_entry
);
1376 void sysctl_head_finish(struct ctl_table_header
*head
)
1380 spin_lock(&sysctl_lock
);
1382 spin_unlock(&sysctl_lock
);
1385 static struct list_head
*
1386 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1388 struct list_head
*header_list
;
1389 header_list
= &root
->header_list
;
1391 header_list
= root
->lookup(root
, namespaces
);
1395 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1396 struct ctl_table_header
*prev
)
1398 struct ctl_table_root
*root
;
1399 struct list_head
*header_list
;
1400 struct ctl_table_header
*head
;
1401 struct list_head
*tmp
;
1403 spin_lock(&sysctl_lock
);
1406 tmp
= &prev
->ctl_entry
;
1410 tmp
= &root_table_header
.ctl_entry
;
1412 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1414 if (!use_table(head
))
1416 spin_unlock(&sysctl_lock
);
1421 header_list
= lookup_header_list(root
, namespaces
);
1422 if (tmp
!= header_list
)
1426 root
= list_entry(root
->root_list
.next
,
1427 struct ctl_table_root
, root_list
);
1428 if (root
== &sysctl_table_root
)
1430 header_list
= lookup_header_list(root
, namespaces
);
1431 } while (list_empty(header_list
));
1432 tmp
= header_list
->next
;
1435 spin_unlock(&sysctl_lock
);
1439 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1441 return __sysctl_head_next(current
->nsproxy
, prev
);
1444 void register_sysctl_root(struct ctl_table_root
*root
)
1446 spin_lock(&sysctl_lock
);
1447 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1448 spin_unlock(&sysctl_lock
);
1451 #ifdef CONFIG_SYSCTL_SYSCALL
1452 /* Perform the actual read/write of a sysctl table entry. */
1453 static int do_sysctl_strategy(struct ctl_table_root
*root
,
1454 struct ctl_table
*table
,
1455 int __user
*name
, int nlen
,
1456 void __user
*oldval
, size_t __user
*oldlenp
,
1457 void __user
*newval
, size_t newlen
)
1465 if (sysctl_perm(root
, table
, op
))
1468 if (table
->strategy
) {
1469 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1477 /* If there is no strategy routine, or if the strategy returns
1478 * zero, proceed with automatic r/w */
1479 if (table
->data
&& table
->maxlen
) {
1480 rc
= sysctl_data(table
, name
, nlen
, oldval
, oldlenp
,
1488 static int parse_table(int __user
*name
, int nlen
,
1489 void __user
*oldval
, size_t __user
*oldlenp
,
1490 void __user
*newval
, size_t newlen
,
1491 struct ctl_table_root
*root
,
1492 struct ctl_table
*table
)
1498 if (get_user(n
, name
))
1500 for ( ; table
->ctl_name
|| table
->procname
; table
++) {
1501 if (!table
->ctl_name
)
1503 if (n
== table
->ctl_name
) {
1506 if (sysctl_perm(root
, table
, 001))
1510 table
= table
->child
;
1513 error
= do_sysctl_strategy(root
, table
, name
, nlen
,
1522 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1523 void __user
*newval
, size_t newlen
)
1525 struct ctl_table_header
*head
;
1526 int error
= -ENOTDIR
;
1528 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1532 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1536 for (head
= sysctl_head_next(NULL
); head
;
1537 head
= sysctl_head_next(head
)) {
1538 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1540 head
->root
, head
->ctl_table
);
1541 if (error
!= -ENOTDIR
) {
1542 sysctl_head_finish(head
);
1549 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1551 struct __sysctl_args tmp
;
1554 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1557 error
= deprecated_sysctl_warning(&tmp
);
1562 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1563 tmp
.newval
, tmp
.newlen
);
1568 #endif /* CONFIG_SYSCTL_SYSCALL */
1571 * sysctl_perm does NOT grant the superuser all rights automatically, because
1572 * some sysctl variables are readonly even to root.
1575 static int test_perm(int mode
, int op
)
1579 else if (in_egroup_p(0))
1581 if ((mode
& op
& 0007) == op
)
1586 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1591 error
= security_sysctl(table
, op
);
1595 if (root
->permissions
)
1596 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1600 return test_perm(mode
, op
);
1603 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1605 for (; table
->ctl_name
|| table
->procname
; table
++) {
1606 table
->parent
= parent
;
1608 sysctl_set_parent(table
, table
->child
);
1612 static __init
int sysctl_init(void)
1614 sysctl_set_parent(NULL
, root_table
);
1615 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1618 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1624 core_initcall(sysctl_init
);
1627 * __register_sysctl_paths - register a sysctl hierarchy
1628 * @root: List of sysctl headers to register on
1629 * @namespaces: Data to compute which lists of sysctl entries are visible
1630 * @path: The path to the directory the sysctl table is in.
1631 * @table: the top-level table structure
1633 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1634 * array. A completely 0 filled entry terminates the table.
1636 * The members of the &struct ctl_table structure are used as follows:
1638 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1639 * must be unique within that level of sysctl
1641 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1642 * enter a sysctl file
1644 * data - a pointer to data for use by proc_handler
1646 * maxlen - the maximum size in bytes of the data
1648 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1650 * child - a pointer to the child sysctl table if this entry is a directory, or
1653 * proc_handler - the text handler routine (described below)
1655 * strategy - the strategy routine (described below)
1657 * de - for internal use by the sysctl routines
1659 * extra1, extra2 - extra pointers usable by the proc handler routines
1661 * Leaf nodes in the sysctl tree will be represented by a single file
1662 * under /proc; non-leaf nodes will be represented by directories.
1664 * sysctl(2) can automatically manage read and write requests through
1665 * the sysctl table. The data and maxlen fields of the ctl_table
1666 * struct enable minimal validation of the values being written to be
1667 * performed, and the mode field allows minimal authentication.
1669 * More sophisticated management can be enabled by the provision of a
1670 * strategy routine with the table entry. This will be called before
1671 * any automatic read or write of the data is performed.
1673 * The strategy routine may return
1675 * < 0 - Error occurred (error is passed to user process)
1677 * 0 - OK - proceed with automatic read or write.
1679 * > 0 - OK - read or write has been done by the strategy routine, so
1680 * return immediately.
1682 * There must be a proc_handler routine for any terminal nodes
1683 * mirrored under /proc/sys (non-terminals are handled by a built-in
1684 * directory handler). Several default handlers are available to
1685 * cover common cases -
1687 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1688 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1689 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1691 * It is the handler's job to read the input buffer from user memory
1692 * and process it. The handler should return 0 on success.
1694 * This routine returns %NULL on a failure to register, and a pointer
1695 * to the table header on success.
1697 struct ctl_table_header
*__register_sysctl_paths(
1698 struct ctl_table_root
*root
,
1699 struct nsproxy
*namespaces
,
1700 const struct ctl_path
*path
, struct ctl_table
*table
)
1702 struct list_head
*header_list
;
1703 struct ctl_table_header
*header
;
1704 struct ctl_table
*new, **prevp
;
1705 unsigned int n
, npath
;
1707 /* Count the path components */
1708 for (npath
= 0; path
[npath
].ctl_name
|| path
[npath
].procname
; ++npath
)
1712 * For each path component, allocate a 2-element ctl_table array.
1713 * The first array element will be filled with the sysctl entry
1714 * for this, the second will be the sentinel (ctl_name == 0).
1716 * We allocate everything in one go so that we don't have to
1717 * worry about freeing additional memory in unregister_sysctl_table.
1719 header
= kzalloc(sizeof(struct ctl_table_header
) +
1720 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1724 new = (struct ctl_table
*) (header
+ 1);
1726 /* Now connect the dots */
1727 prevp
= &header
->ctl_table
;
1728 for (n
= 0; n
< npath
; ++n
, ++path
) {
1729 /* Copy the procname */
1730 new->procname
= path
->procname
;
1731 new->ctl_name
= path
->ctl_name
;
1735 prevp
= &new->child
;
1740 header
->ctl_table_arg
= table
;
1742 INIT_LIST_HEAD(&header
->ctl_entry
);
1744 header
->unregistering
= NULL
;
1745 header
->root
= root
;
1746 sysctl_set_parent(NULL
, header
->ctl_table
);
1747 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1748 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1753 spin_lock(&sysctl_lock
);
1754 header_list
= lookup_header_list(root
, namespaces
);
1755 list_add_tail(&header
->ctl_entry
, header_list
);
1756 spin_unlock(&sysctl_lock
);
1762 * register_sysctl_table_path - register a sysctl table hierarchy
1763 * @path: The path to the directory the sysctl table is in.
1764 * @table: the top-level table structure
1766 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1767 * array. A completely 0 filled entry terminates the table.
1769 * See __register_sysctl_paths for more details.
1771 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1772 struct ctl_table
*table
)
1774 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1779 * register_sysctl_table - register a sysctl table hierarchy
1780 * @table: the top-level table structure
1782 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1783 * array. A completely 0 filled entry terminates the table.
1785 * See register_sysctl_paths for more details.
1787 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1789 static const struct ctl_path null_path
[] = { {} };
1791 return register_sysctl_paths(null_path
, table
);
1795 * unregister_sysctl_table - unregister a sysctl table hierarchy
1796 * @header: the header returned from register_sysctl_table
1798 * Unregisters the sysctl table and all children. proc entries may not
1799 * actually be removed until they are no longer used by anyone.
1801 void unregister_sysctl_table(struct ctl_table_header
* header
)
1808 spin_lock(&sysctl_lock
);
1809 start_unregistering(header
);
1810 spin_unlock(&sysctl_lock
);
1814 #else /* !CONFIG_SYSCTL */
1815 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1820 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1821 struct ctl_table
*table
)
1826 void unregister_sysctl_table(struct ctl_table_header
* table
)
1830 #endif /* CONFIG_SYSCTL */
1836 #ifdef CONFIG_PROC_SYSCTL
1838 static int _proc_do_string(void* data
, int maxlen
, int write
,
1839 struct file
*filp
, void __user
*buffer
,
1840 size_t *lenp
, loff_t
*ppos
)
1846 if (!data
|| !maxlen
|| !*lenp
) {
1854 while (len
< *lenp
) {
1855 if (get_user(c
, p
++))
1857 if (c
== 0 || c
== '\n')
1863 if(copy_from_user(data
, buffer
, len
))
1865 ((char *) data
)[len
] = 0;
1883 if(copy_to_user(buffer
, data
, len
))
1886 if(put_user('\n', ((char __user
*) buffer
) + len
))
1897 * proc_dostring - read a string sysctl
1898 * @table: the sysctl table
1899 * @write: %TRUE if this is a write to the sysctl file
1900 * @filp: the file structure
1901 * @buffer: the user buffer
1902 * @lenp: the size of the user buffer
1903 * @ppos: file position
1905 * Reads/writes a string from/to the user buffer. If the kernel
1906 * buffer provided is not large enough to hold the string, the
1907 * string is truncated. The copied string is %NULL-terminated.
1908 * If the string is being read by the user process, it is copied
1909 * and a newline '\n' is added. It is truncated if the buffer is
1912 * Returns 0 on success.
1914 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
1915 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1917 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
1918 buffer
, lenp
, ppos
);
1922 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1924 int write
, void *data
)
1927 *valp
= *negp
? -*lvalp
: *lvalp
;
1932 *lvalp
= (unsigned long)-val
;
1935 *lvalp
= (unsigned long)val
;
1941 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
1942 int write
, struct file
*filp
, void __user
*buffer
,
1943 size_t *lenp
, loff_t
*ppos
,
1944 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1945 int write
, void *data
),
1948 #define TMPBUFLEN 21
1949 int *i
, vleft
, first
=1, neg
, val
;
1953 char buf
[TMPBUFLEN
], *p
;
1954 char __user
*s
= buffer
;
1956 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
1957 (*ppos
&& !write
)) {
1962 i
= (int *) tbl_data
;
1963 vleft
= table
->maxlen
/ sizeof(*i
);
1967 conv
= do_proc_dointvec_conv
;
1969 for (; left
&& vleft
--; i
++, first
=0) {
1984 if (len
> sizeof(buf
) - 1)
1985 len
= sizeof(buf
) - 1;
1986 if (copy_from_user(buf
, s
, len
))
1990 if (*p
== '-' && left
> 1) {
1994 if (*p
< '0' || *p
> '9')
1997 lval
= simple_strtoul(p
, &p
, 0);
2000 if ((len
< left
) && *p
&& !isspace(*p
))
2007 if (conv(&neg
, &lval
, i
, 1, data
))
2014 if (conv(&neg
, &lval
, i
, 0, data
))
2017 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2021 if(copy_to_user(s
, buf
, len
))
2028 if (!write
&& !first
&& left
) {
2029 if(put_user('\n', s
))
2036 if (get_user(c
, s
++))
2051 static int do_proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2052 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2053 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2054 int write
, void *data
),
2057 return __do_proc_dointvec(table
->data
, table
, write
, filp
,
2058 buffer
, lenp
, ppos
, conv
, data
);
2062 * proc_dointvec - read a vector of integers
2063 * @table: the sysctl table
2064 * @write: %TRUE if this is a write to the sysctl file
2065 * @filp: the file structure
2066 * @buffer: the user buffer
2067 * @lenp: the size of the user buffer
2068 * @ppos: file position
2070 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2071 * values from/to the user buffer, treated as an ASCII string.
2073 * Returns 0 on success.
2075 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2076 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2078 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2086 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
2088 int write
, void *data
)
2090 int op
= *(int *)data
;
2092 int val
= *negp
? -*lvalp
: *lvalp
;
2094 case OP_SET
: *valp
= val
; break;
2095 case OP_AND
: *valp
&= val
; break;
2096 case OP_OR
: *valp
|= val
; break;
2102 *lvalp
= (unsigned long)-val
;
2105 *lvalp
= (unsigned long)val
;
2112 * Taint values can only be increased
2114 static int proc_dointvec_taint(struct ctl_table
*table
, int write
, struct file
*filp
,
2115 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2119 if (write
&& !capable(CAP_SYS_ADMIN
))
2123 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2124 do_proc_dointvec_bset_conv
,&op
);
2127 struct do_proc_dointvec_minmax_conv_param
{
2132 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2134 int write
, void *data
)
2136 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2138 int val
= *negp
? -*lvalp
: *lvalp
;
2139 if ((param
->min
&& *param
->min
> val
) ||
2140 (param
->max
&& *param
->max
< val
))
2147 *lvalp
= (unsigned long)-val
;
2150 *lvalp
= (unsigned long)val
;
2157 * proc_dointvec_minmax - read a vector of integers with min/max values
2158 * @table: the sysctl table
2159 * @write: %TRUE if this is a write to the sysctl file
2160 * @filp: the file structure
2161 * @buffer: the user buffer
2162 * @lenp: the size of the user buffer
2163 * @ppos: file position
2165 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2166 * values from/to the user buffer, treated as an ASCII string.
2168 * This routine will ensure the values are within the range specified by
2169 * table->extra1 (min) and table->extra2 (max).
2171 * Returns 0 on success.
2173 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2174 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2176 struct do_proc_dointvec_minmax_conv_param param
= {
2177 .min
= (int *) table
->extra1
,
2178 .max
= (int *) table
->extra2
,
2180 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2181 do_proc_dointvec_minmax_conv
, ¶m
);
2184 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2186 void __user
*buffer
,
2187 size_t *lenp
, loff_t
*ppos
,
2188 unsigned long convmul
,
2189 unsigned long convdiv
)
2191 #define TMPBUFLEN 21
2192 unsigned long *i
, *min
, *max
, val
;
2193 int vleft
, first
=1, neg
;
2195 char buf
[TMPBUFLEN
], *p
;
2196 char __user
*s
= buffer
;
2198 if (!data
|| !table
->maxlen
|| !*lenp
||
2199 (*ppos
&& !write
)) {
2204 i
= (unsigned long *) data
;
2205 min
= (unsigned long *) table
->extra1
;
2206 max
= (unsigned long *) table
->extra2
;
2207 vleft
= table
->maxlen
/ sizeof(unsigned long);
2210 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2225 if (len
> TMPBUFLEN
-1)
2227 if (copy_from_user(buf
, s
, len
))
2231 if (*p
== '-' && left
> 1) {
2235 if (*p
< '0' || *p
> '9')
2237 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2239 if ((len
< left
) && *p
&& !isspace(*p
))
2248 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2255 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2259 if(copy_to_user(s
, buf
, len
))
2266 if (!write
&& !first
&& left
) {
2267 if(put_user('\n', s
))
2274 if (get_user(c
, s
++))
2289 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2291 void __user
*buffer
,
2292 size_t *lenp
, loff_t
*ppos
,
2293 unsigned long convmul
,
2294 unsigned long convdiv
)
2296 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2297 filp
, buffer
, lenp
, ppos
, convmul
, convdiv
);
2301 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2302 * @table: the sysctl table
2303 * @write: %TRUE if this is a write to the sysctl file
2304 * @filp: the file structure
2305 * @buffer: the user buffer
2306 * @lenp: the size of the user buffer
2307 * @ppos: file position
2309 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2310 * values from/to the user buffer, treated as an ASCII string.
2312 * This routine will ensure the values are within the range specified by
2313 * table->extra1 (min) and table->extra2 (max).
2315 * Returns 0 on success.
2317 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2318 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2320 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2324 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2325 * @table: the sysctl table
2326 * @write: %TRUE if this is a write to the sysctl file
2327 * @filp: the file structure
2328 * @buffer: the user buffer
2329 * @lenp: the size of the user buffer
2330 * @ppos: file position
2332 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2333 * values from/to the user buffer, treated as an ASCII string. The values
2334 * are treated as milliseconds, and converted to jiffies when they are stored.
2336 * This routine will ensure the values are within the range specified by
2337 * table->extra1 (min) and table->extra2 (max).
2339 * Returns 0 on success.
2341 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2343 void __user
*buffer
,
2344 size_t *lenp
, loff_t
*ppos
)
2346 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2347 lenp
, ppos
, HZ
, 1000l);
2351 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2353 int write
, void *data
)
2356 if (*lvalp
> LONG_MAX
/ HZ
)
2358 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2364 lval
= (unsigned long)-val
;
2367 lval
= (unsigned long)val
;
2374 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2376 int write
, void *data
)
2379 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2381 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2387 lval
= (unsigned long)-val
;
2390 lval
= (unsigned long)val
;
2392 *lvalp
= jiffies_to_clock_t(lval
);
2397 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2399 int write
, void *data
)
2402 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2408 lval
= (unsigned long)-val
;
2411 lval
= (unsigned long)val
;
2413 *lvalp
= jiffies_to_msecs(lval
);
2419 * proc_dointvec_jiffies - read a vector of integers as seconds
2420 * @table: the sysctl table
2421 * @write: %TRUE if this is a write to the sysctl file
2422 * @filp: the file structure
2423 * @buffer: the user buffer
2424 * @lenp: the size of the user buffer
2425 * @ppos: file position
2427 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2428 * values from/to the user buffer, treated as an ASCII string.
2429 * The values read are assumed to be in seconds, and are converted into
2432 * Returns 0 on success.
2434 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2435 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2437 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2438 do_proc_dointvec_jiffies_conv
,NULL
);
2442 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2443 * @table: the sysctl table
2444 * @write: %TRUE if this is a write to the sysctl file
2445 * @filp: the file structure
2446 * @buffer: the user buffer
2447 * @lenp: the size of the user buffer
2448 * @ppos: pointer to the file position
2450 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2451 * values from/to the user buffer, treated as an ASCII string.
2452 * The values read are assumed to be in 1/USER_HZ seconds, and
2453 * are converted into jiffies.
2455 * Returns 0 on success.
2457 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2458 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2460 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2461 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2465 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2466 * @table: the sysctl table
2467 * @write: %TRUE if this is a write to the sysctl file
2468 * @filp: the file structure
2469 * @buffer: the user buffer
2470 * @lenp: the size of the user buffer
2471 * @ppos: file position
2472 * @ppos: the current position in the file
2474 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2475 * values from/to the user buffer, treated as an ASCII string.
2476 * The values read are assumed to be in 1/1000 seconds, and
2477 * are converted into jiffies.
2479 * Returns 0 on success.
2481 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2482 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2484 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2485 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2488 static int proc_do_cad_pid(struct ctl_table
*table
, int write
, struct file
*filp
,
2489 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2491 struct pid
*new_pid
;
2495 tmp
= pid_vnr(cad_pid
);
2497 r
= __do_proc_dointvec(&tmp
, table
, write
, filp
, buffer
,
2498 lenp
, ppos
, NULL
, NULL
);
2502 new_pid
= find_get_pid(tmp
);
2506 put_pid(xchg(&cad_pid
, new_pid
));
2510 #else /* CONFIG_PROC_FS */
2512 int proc_dostring(struct ctl_table
*table
, int write
, struct file
*filp
,
2513 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2518 int proc_dointvec(struct ctl_table
*table
, int write
, struct file
*filp
,
2519 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2524 int proc_dointvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2525 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2530 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2531 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2536 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2537 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2542 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
, struct file
*filp
,
2543 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2548 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
, struct file
*filp
,
2549 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2554 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2556 void __user
*buffer
,
2557 size_t *lenp
, loff_t
*ppos
)
2563 #endif /* CONFIG_PROC_FS */
2566 #ifdef CONFIG_SYSCTL_SYSCALL
2568 * General sysctl support routines
2571 /* The generic sysctl data routine (used if no strategy routine supplied) */
2572 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2573 void __user
*oldval
, size_t __user
*oldlenp
,
2574 void __user
*newval
, size_t newlen
)
2578 /* Get out of I don't have a variable */
2579 if (!table
->data
|| !table
->maxlen
)
2582 if (oldval
&& oldlenp
) {
2583 if (get_user(len
, oldlenp
))
2586 if (len
> table
->maxlen
)
2587 len
= table
->maxlen
;
2588 if (copy_to_user(oldval
, table
->data
, len
))
2590 if (put_user(len
, oldlenp
))
2595 if (newval
&& newlen
) {
2596 if (newlen
> table
->maxlen
)
2597 newlen
= table
->maxlen
;
2599 if (copy_from_user(table
->data
, newval
, newlen
))
2605 /* The generic string strategy routine: */
2606 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2607 void __user
*oldval
, size_t __user
*oldlenp
,
2608 void __user
*newval
, size_t newlen
)
2610 if (!table
->data
|| !table
->maxlen
)
2613 if (oldval
&& oldlenp
) {
2615 if (get_user(bufsize
, oldlenp
))
2618 size_t len
= strlen(table
->data
), copied
;
2620 /* This shouldn't trigger for a well-formed sysctl */
2621 if (len
> table
->maxlen
)
2622 len
= table
->maxlen
;
2624 /* Copy up to a max of bufsize-1 bytes of the string */
2625 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2627 if (copy_to_user(oldval
, table
->data
, copied
) ||
2628 put_user(0, (char __user
*)(oldval
+ copied
)))
2630 if (put_user(len
, oldlenp
))
2634 if (newval
&& newlen
) {
2635 size_t len
= newlen
;
2636 if (len
> table
->maxlen
)
2637 len
= table
->maxlen
;
2638 if(copy_from_user(table
->data
, newval
, len
))
2640 if (len
== table
->maxlen
)
2642 ((char *) table
->data
)[len
] = 0;
2648 * This function makes sure that all of the integers in the vector
2649 * are between the minimum and maximum values given in the arrays
2650 * table->extra1 and table->extra2, respectively.
2652 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2653 void __user
*oldval
, size_t __user
*oldlenp
,
2654 void __user
*newval
, size_t newlen
)
2657 if (newval
&& newlen
) {
2658 int __user
*vec
= (int __user
*) newval
;
2659 int *min
= (int *) table
->extra1
;
2660 int *max
= (int *) table
->extra2
;
2664 if (newlen
% sizeof(int) != 0)
2667 if (!table
->extra1
&& !table
->extra2
)
2670 if (newlen
> table
->maxlen
)
2671 newlen
= table
->maxlen
;
2672 length
= newlen
/ sizeof(int);
2674 for (i
= 0; i
< length
; i
++) {
2676 if (get_user(value
, vec
+ i
))
2678 if (min
&& value
< min
[i
])
2680 if (max
&& value
> max
[i
])
2687 /* Strategy function to convert jiffies to seconds */
2688 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2689 void __user
*oldval
, size_t __user
*oldlenp
,
2690 void __user
*newval
, size_t newlen
)
2692 if (oldval
&& oldlenp
) {
2695 if (get_user(olen
, oldlenp
))
2700 if (olen
< sizeof(int))
2703 val
= *(int *)(table
->data
) / HZ
;
2704 if (put_user(val
, (int __user
*)oldval
))
2706 if (put_user(sizeof(int), oldlenp
))
2710 if (newval
&& newlen
) {
2712 if (newlen
!= sizeof(int))
2714 if (get_user(new, (int __user
*)newval
))
2716 *(int *)(table
->data
) = new*HZ
;
2721 /* Strategy function to convert jiffies to seconds */
2722 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2723 void __user
*oldval
, size_t __user
*oldlenp
,
2724 void __user
*newval
, size_t newlen
)
2726 if (oldval
&& oldlenp
) {
2729 if (get_user(olen
, oldlenp
))
2734 if (olen
< sizeof(int))
2737 val
= jiffies_to_msecs(*(int *)(table
->data
));
2738 if (put_user(val
, (int __user
*)oldval
))
2740 if (put_user(sizeof(int), oldlenp
))
2744 if (newval
&& newlen
) {
2746 if (newlen
!= sizeof(int))
2748 if (get_user(new, (int __user
*)newval
))
2750 *(int *)(table
->data
) = msecs_to_jiffies(new);
2757 #else /* CONFIG_SYSCTL_SYSCALL */
2760 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2762 struct __sysctl_args tmp
;
2765 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
2768 error
= deprecated_sysctl_warning(&tmp
);
2770 /* If no error reading the parameters then just -ENOSYS ... */
2777 int sysctl_data(struct ctl_table
*table
, int __user
*name
, int nlen
,
2778 void __user
*oldval
, size_t __user
*oldlenp
,
2779 void __user
*newval
, size_t newlen
)
2784 int sysctl_string(struct ctl_table
*table
, int __user
*name
, int nlen
,
2785 void __user
*oldval
, size_t __user
*oldlenp
,
2786 void __user
*newval
, size_t newlen
)
2791 int sysctl_intvec(struct ctl_table
*table
, int __user
*name
, int nlen
,
2792 void __user
*oldval
, size_t __user
*oldlenp
,
2793 void __user
*newval
, size_t newlen
)
2798 int sysctl_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2799 void __user
*oldval
, size_t __user
*oldlenp
,
2800 void __user
*newval
, size_t newlen
)
2805 int sysctl_ms_jiffies(struct ctl_table
*table
, int __user
*name
, int nlen
,
2806 void __user
*oldval
, size_t __user
*oldlenp
,
2807 void __user
*newval
, size_t newlen
)
2812 #endif /* CONFIG_SYSCTL_SYSCALL */
2814 static int deprecated_sysctl_warning(struct __sysctl_args
*args
)
2816 static int msg_count
;
2817 int name
[CTL_MAXNAME
];
2820 /* Check args->nlen. */
2821 if (args
->nlen
< 0 || args
->nlen
> CTL_MAXNAME
)
2824 /* Read in the sysctl name for better debug message logging */
2825 for (i
= 0; i
< args
->nlen
; i
++)
2826 if (get_user(name
[i
], args
->name
+ i
))
2829 /* Ignore accesses to kernel.version */
2830 if ((args
->nlen
== 2) && (name
[0] == CTL_KERN
) && (name
[1] == KERN_VERSION
))
2833 if (msg_count
< 5) {
2836 "warning: process `%s' used the deprecated sysctl "
2837 "system call with ", current
->comm
);
2838 for (i
= 0; i
< args
->nlen
; i
++)
2839 printk("%d.", name
[i
]);
2846 * No sense putting this after each symbol definition, twice,
2847 * exception granted :-)
2849 EXPORT_SYMBOL(proc_dointvec
);
2850 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2851 EXPORT_SYMBOL(proc_dointvec_minmax
);
2852 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2853 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2854 EXPORT_SYMBOL(proc_dostring
);
2855 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2856 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2857 EXPORT_SYMBOL(register_sysctl_table
);
2858 EXPORT_SYMBOL(register_sysctl_paths
);
2859 EXPORT_SYMBOL(sysctl_intvec
);
2860 EXPORT_SYMBOL(sysctl_jiffies
);
2861 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2862 EXPORT_SYMBOL(sysctl_string
);
2863 EXPORT_SYMBOL(sysctl_data
);
2864 EXPORT_SYMBOL(unregister_sysctl_table
);