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/times.h>
42 #include <linux/limits.h>
43 #include <linux/dcache.h>
44 #include <linux/syscalls.h>
45 #include <linux/nfs_fs.h>
46 #include <linux/acpi.h>
47 #include <linux/reboot.h>
49 #include <asm/uaccess.h>
50 #include <asm/processor.h>
54 #include <asm/stacktrace.h>
58 static int deprecated_sysctl_warning(struct __sysctl_args *args);
60 #if defined(CONFIG_SYSCTL)
62 /* External variables not in a header file. */
64 extern int print_fatal_signals;
65 extern int sysctl_overcommit_memory;
66 extern int sysctl_overcommit_ratio;
67 extern int sysctl_panic_on_oom;
68 extern int sysctl_oom_kill_allocating_task;
69 extern int sysctl_oom_dump_tasks;
70 extern int max_threads;
71 extern int core_uses_pid;
72 extern int suid_dumpable;
73 extern char core_pattern[];
75 extern int min_free_kbytes;
76 extern int pid_max_min, pid_max_max;
77 extern int sysctl_drop_caches;
78 extern int percpu_pagelist_fraction;
79 extern int compat_log;
80 extern int maps_protect;
81 extern int sysctl_stat_interval;
82 extern int latencytop_enabled;
84 /* Constants used for minimum and maximum */
85 #if defined(CONFIG_DETECT_SOFTLOCKUP) || defined(CONFIG_HIGHMEM)
89 #ifdef CONFIG_DETECT_SOFTLOCKUP
90 static int sixty = 60;
98 static int one_hundred = 100;
100 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
101 static int maxolduid = 65535;
102 static int minolduid;
103 static int min_percpu_pagelist_fract = 8;
105 static int ngroups_max = NGROUPS_MAX;
108 extern char modprobe_path[];
110 #ifdef CONFIG_CHR_DEV_SG
111 extern int sg_big_buff;
115 extern char reboot_command [];
116 extern int stop_a_enabled;
117 extern int scons_pwroff;
121 extern int pwrsw_enabled;
122 extern int unaligned_enabled;
126 #ifdef CONFIG_MATHEMU
127 extern int sysctl_ieee_emulation_warnings;
129 extern int sysctl_userprocess_debug;
130 extern int spin_retry;
133 extern int sysctl_hz_timer;
135 #ifdef CONFIG_BSD_PROCESS_ACCT
136 extern int acct_parm[];
140 extern int no_unaligned_warning;
143 #ifdef CONFIG_RT_MUTEXES
144 extern int max_lock_depth;
147 #ifdef CONFIG_SYSCTL_SYSCALL
148 static int parse_table(int __user *, int, void __user *, size_t __user *,
149 void __user *, size_t, struct ctl_table *);
153 #ifdef CONFIG_PROC_SYSCTL
154 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
155 void __user *buffer, size_t *lenp, loff_t *ppos);
156 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
157 void __user *buffer, size_t *lenp, loff_t *ppos);
160 static struct ctl_table root_table[];
161 static struct ctl_table_root sysctl_table_root;
162 static struct ctl_table_header root_table_header = {
163 .ctl_table = root_table,
164 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.header_list),
165 .root = &sysctl_table_root,
167 static struct ctl_table_root sysctl_table_root = {
168 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
169 .header_list = LIST_HEAD_INIT(root_table_header.ctl_entry),
172 static struct ctl_table kern_table[];
173 static struct ctl_table vm_table[];
174 static struct ctl_table fs_table[];
175 static struct ctl_table debug_table[];
176 static struct ctl_table dev_table[];
177 extern struct ctl_table random_table[];
178 #ifdef CONFIG_INOTIFY_USER
179 extern struct ctl_table inotify_table[];
182 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
183 int sysctl_legacy_va_layout;
186 extern int prove_locking;
187 extern int lock_stat;
189 /* The default sysctl tables: */
191 static struct ctl_table root_table[] = {
193 .ctl_name = CTL_KERN,
194 .procname = "kernel",
211 .ctl_name = CTL_DEBUG,
214 .child = debug_table,
223 * NOTE: do not add new entries to this table unless you have read
224 * Documentation/sysctl/ctl_unnumbered.txt
229 #ifdef CONFIG_SCHED_DEBUG
230 static int min_sched_granularity_ns = 100000; /* 100 usecs */
231 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
232 static int min_wakeup_granularity_ns; /* 0 usecs */
233 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
236 static struct ctl_table kern_table[] = {
237 #ifdef CONFIG_SCHED_DEBUG
239 .ctl_name = CTL_UNNUMBERED,
240 .procname = "sched_min_granularity_ns",
241 .data = &sysctl_sched_min_granularity,
242 .maxlen = sizeof(unsigned int),
244 .proc_handler = &sched_nr_latency_handler,
245 .strategy = &sysctl_intvec,
246 .extra1 = &min_sched_granularity_ns,
247 .extra2 = &max_sched_granularity_ns,
250 .ctl_name = CTL_UNNUMBERED,
251 .procname = "sched_latency_ns",
252 .data = &sysctl_sched_latency,
253 .maxlen = sizeof(unsigned int),
255 .proc_handler = &sched_nr_latency_handler,
256 .strategy = &sysctl_intvec,
257 .extra1 = &min_sched_granularity_ns,
258 .extra2 = &max_sched_granularity_ns,
261 .ctl_name = CTL_UNNUMBERED,
262 .procname = "sched_wakeup_granularity_ns",
263 .data = &sysctl_sched_wakeup_granularity,
264 .maxlen = sizeof(unsigned int),
266 .proc_handler = &proc_dointvec_minmax,
267 .strategy = &sysctl_intvec,
268 .extra1 = &min_wakeup_granularity_ns,
269 .extra2 = &max_wakeup_granularity_ns,
272 .ctl_name = CTL_UNNUMBERED,
273 .procname = "sched_child_runs_first",
274 .data = &sysctl_sched_child_runs_first,
275 .maxlen = sizeof(unsigned int),
277 .proc_handler = &proc_dointvec,
280 .ctl_name = CTL_UNNUMBERED,
281 .procname = "sched_features",
282 .data = &sysctl_sched_features,
283 .maxlen = sizeof(unsigned int),
285 .proc_handler = &proc_dointvec,
288 .ctl_name = CTL_UNNUMBERED,
289 .procname = "sched_migration_cost",
290 .data = &sysctl_sched_migration_cost,
291 .maxlen = sizeof(unsigned int),
293 .proc_handler = &proc_dointvec,
296 .ctl_name = CTL_UNNUMBERED,
297 .procname = "sched_nr_migrate",
298 .data = &sysctl_sched_nr_migrate,
299 .maxlen = sizeof(unsigned int),
301 .proc_handler = &proc_dointvec,
305 .ctl_name = CTL_UNNUMBERED,
306 .procname = "sched_rt_period_us",
307 .data = &sysctl_sched_rt_period,
308 .maxlen = sizeof(unsigned int),
310 .proc_handler = &sched_rt_handler,
313 .ctl_name = CTL_UNNUMBERED,
314 .procname = "sched_rt_runtime_us",
315 .data = &sysctl_sched_rt_runtime,
316 .maxlen = sizeof(int),
318 .proc_handler = &sched_rt_handler,
321 .ctl_name = CTL_UNNUMBERED,
322 .procname = "sched_compat_yield",
323 .data = &sysctl_sched_compat_yield,
324 .maxlen = sizeof(unsigned int),
326 .proc_handler = &proc_dointvec,
328 #ifdef CONFIG_PROVE_LOCKING
330 .ctl_name = CTL_UNNUMBERED,
331 .procname = "prove_locking",
332 .data = &prove_locking,
333 .maxlen = sizeof(int),
335 .proc_handler = &proc_dointvec,
338 #ifdef CONFIG_LOCK_STAT
340 .ctl_name = CTL_UNNUMBERED,
341 .procname = "lock_stat",
343 .maxlen = sizeof(int),
345 .proc_handler = &proc_dointvec,
349 .ctl_name = KERN_PANIC,
351 .data = &panic_timeout,
352 .maxlen = sizeof(int),
354 .proc_handler = &proc_dointvec,
357 .ctl_name = KERN_CORE_USES_PID,
358 .procname = "core_uses_pid",
359 .data = &core_uses_pid,
360 .maxlen = sizeof(int),
362 .proc_handler = &proc_dointvec,
365 .ctl_name = KERN_CORE_PATTERN,
366 .procname = "core_pattern",
367 .data = core_pattern,
368 .maxlen = CORENAME_MAX_SIZE,
370 .proc_handler = &proc_dostring,
371 .strategy = &sysctl_string,
373 #ifdef CONFIG_PROC_SYSCTL
375 .procname = "tainted",
377 .maxlen = sizeof(int),
379 .proc_handler = &proc_dointvec_taint,
382 #ifdef CONFIG_LATENCYTOP
384 .procname = "latencytop",
385 .data = &latencytop_enabled,
386 .maxlen = sizeof(int),
388 .proc_handler = &proc_dointvec,
391 #ifdef CONFIG_BLK_DEV_INITRD
393 .ctl_name = KERN_REALROOTDEV,
394 .procname = "real-root-dev",
395 .data = &real_root_dev,
396 .maxlen = sizeof(int),
398 .proc_handler = &proc_dointvec,
402 .ctl_name = CTL_UNNUMBERED,
403 .procname = "print-fatal-signals",
404 .data = &print_fatal_signals,
405 .maxlen = sizeof(int),
407 .proc_handler = &proc_dointvec,
411 .ctl_name = KERN_SPARC_REBOOT,
412 .procname = "reboot-cmd",
413 .data = reboot_command,
416 .proc_handler = &proc_dostring,
417 .strategy = &sysctl_string,
420 .ctl_name = KERN_SPARC_STOP_A,
421 .procname = "stop-a",
422 .data = &stop_a_enabled,
423 .maxlen = sizeof (int),
425 .proc_handler = &proc_dointvec,
428 .ctl_name = KERN_SPARC_SCONS_PWROFF,
429 .procname = "scons-poweroff",
430 .data = &scons_pwroff,
431 .maxlen = sizeof (int),
433 .proc_handler = &proc_dointvec,
438 .ctl_name = KERN_HPPA_PWRSW,
439 .procname = "soft-power",
440 .data = &pwrsw_enabled,
441 .maxlen = sizeof (int),
443 .proc_handler = &proc_dointvec,
446 .ctl_name = KERN_HPPA_UNALIGNED,
447 .procname = "unaligned-trap",
448 .data = &unaligned_enabled,
449 .maxlen = sizeof (int),
451 .proc_handler = &proc_dointvec,
455 .ctl_name = KERN_CTLALTDEL,
456 .procname = "ctrl-alt-del",
458 .maxlen = sizeof(int),
460 .proc_handler = &proc_dointvec,
464 .ctl_name = KERN_MODPROBE,
465 .procname = "modprobe",
466 .data = &modprobe_path,
467 .maxlen = KMOD_PATH_LEN,
469 .proc_handler = &proc_dostring,
470 .strategy = &sysctl_string,
473 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
475 .ctl_name = KERN_HOTPLUG,
476 .procname = "hotplug",
477 .data = &uevent_helper,
478 .maxlen = UEVENT_HELPER_PATH_LEN,
480 .proc_handler = &proc_dostring,
481 .strategy = &sysctl_string,
484 #ifdef CONFIG_CHR_DEV_SG
486 .ctl_name = KERN_SG_BIG_BUFF,
487 .procname = "sg-big-buff",
488 .data = &sg_big_buff,
489 .maxlen = sizeof (int),
491 .proc_handler = &proc_dointvec,
494 #ifdef CONFIG_BSD_PROCESS_ACCT
496 .ctl_name = KERN_ACCT,
499 .maxlen = 3*sizeof(int),
501 .proc_handler = &proc_dointvec,
504 #ifdef CONFIG_MAGIC_SYSRQ
506 .ctl_name = KERN_SYSRQ,
508 .data = &__sysrq_enabled,
509 .maxlen = sizeof (int),
511 .proc_handler = &proc_dointvec,
514 #ifdef CONFIG_PROC_SYSCTL
516 .procname = "cad_pid",
518 .maxlen = sizeof (int),
520 .proc_handler = &proc_do_cad_pid,
524 .ctl_name = KERN_MAX_THREADS,
525 .procname = "threads-max",
526 .data = &max_threads,
527 .maxlen = sizeof(int),
529 .proc_handler = &proc_dointvec,
532 .ctl_name = KERN_RANDOM,
533 .procname = "random",
535 .child = random_table,
538 .ctl_name = KERN_OVERFLOWUID,
539 .procname = "overflowuid",
540 .data = &overflowuid,
541 .maxlen = sizeof(int),
543 .proc_handler = &proc_dointvec_minmax,
544 .strategy = &sysctl_intvec,
545 .extra1 = &minolduid,
546 .extra2 = &maxolduid,
549 .ctl_name = KERN_OVERFLOWGID,
550 .procname = "overflowgid",
551 .data = &overflowgid,
552 .maxlen = sizeof(int),
554 .proc_handler = &proc_dointvec_minmax,
555 .strategy = &sysctl_intvec,
556 .extra1 = &minolduid,
557 .extra2 = &maxolduid,
560 #ifdef CONFIG_MATHEMU
562 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
563 .procname = "ieee_emulation_warnings",
564 .data = &sysctl_ieee_emulation_warnings,
565 .maxlen = sizeof(int),
567 .proc_handler = &proc_dointvec,
570 #ifdef CONFIG_NO_IDLE_HZ
572 .ctl_name = KERN_HZ_TIMER,
573 .procname = "hz_timer",
574 .data = &sysctl_hz_timer,
575 .maxlen = sizeof(int),
577 .proc_handler = &proc_dointvec,
581 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
582 .procname = "userprocess_debug",
583 .data = &sysctl_userprocess_debug,
584 .maxlen = sizeof(int),
586 .proc_handler = &proc_dointvec,
590 .ctl_name = KERN_PIDMAX,
591 .procname = "pid_max",
593 .maxlen = sizeof (int),
595 .proc_handler = &proc_dointvec_minmax,
596 .strategy = sysctl_intvec,
597 .extra1 = &pid_max_min,
598 .extra2 = &pid_max_max,
601 .ctl_name = KERN_PANIC_ON_OOPS,
602 .procname = "panic_on_oops",
603 .data = &panic_on_oops,
604 .maxlen = sizeof(int),
606 .proc_handler = &proc_dointvec,
608 #if defined CONFIG_PRINTK
610 .ctl_name = KERN_PRINTK,
611 .procname = "printk",
612 .data = &console_loglevel,
613 .maxlen = 4*sizeof(int),
615 .proc_handler = &proc_dointvec,
618 .ctl_name = KERN_PRINTK_RATELIMIT,
619 .procname = "printk_ratelimit",
620 .data = &printk_ratelimit_jiffies,
621 .maxlen = sizeof(int),
623 .proc_handler = &proc_dointvec_jiffies,
624 .strategy = &sysctl_jiffies,
627 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
628 .procname = "printk_ratelimit_burst",
629 .data = &printk_ratelimit_burst,
630 .maxlen = sizeof(int),
632 .proc_handler = &proc_dointvec,
636 .ctl_name = KERN_NGROUPS_MAX,
637 .procname = "ngroups_max",
638 .data = &ngroups_max,
639 .maxlen = sizeof (int),
641 .proc_handler = &proc_dointvec,
643 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
645 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
646 .procname = "unknown_nmi_panic",
647 .data = &unknown_nmi_panic,
648 .maxlen = sizeof (int),
650 .proc_handler = &proc_dointvec,
653 .procname = "nmi_watchdog",
654 .data = &nmi_watchdog_enabled,
655 .maxlen = sizeof (int),
657 .proc_handler = &proc_nmi_enabled,
660 #if defined(CONFIG_X86)
662 .ctl_name = KERN_PANIC_ON_NMI,
663 .procname = "panic_on_unrecovered_nmi",
664 .data = &panic_on_unrecovered_nmi,
665 .maxlen = sizeof(int),
667 .proc_handler = &proc_dointvec,
670 .ctl_name = KERN_BOOTLOADER_TYPE,
671 .procname = "bootloader_type",
672 .data = &bootloader_type,
673 .maxlen = sizeof (int),
675 .proc_handler = &proc_dointvec,
678 .ctl_name = CTL_UNNUMBERED,
679 .procname = "kstack_depth_to_print",
680 .data = &kstack_depth_to_print,
681 .maxlen = sizeof(int),
683 .proc_handler = &proc_dointvec,
686 .ctl_name = CTL_UNNUMBERED,
687 .procname = "io_delay_type",
688 .data = &io_delay_type,
689 .maxlen = sizeof(int),
691 .proc_handler = &proc_dointvec,
694 #if defined(CONFIG_MMU)
696 .ctl_name = KERN_RANDOMIZE,
697 .procname = "randomize_va_space",
698 .data = &randomize_va_space,
699 .maxlen = sizeof(int),
701 .proc_handler = &proc_dointvec,
704 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
706 .ctl_name = KERN_SPIN_RETRY,
707 .procname = "spin_retry",
709 .maxlen = sizeof (int),
711 .proc_handler = &proc_dointvec,
714 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
716 .procname = "acpi_video_flags",
717 .data = &acpi_realmode_flags,
718 .maxlen = sizeof (unsigned long),
720 .proc_handler = &proc_doulongvec_minmax,
725 .ctl_name = KERN_IA64_UNALIGNED,
726 .procname = "ignore-unaligned-usertrap",
727 .data = &no_unaligned_warning,
728 .maxlen = sizeof (int),
730 .proc_handler = &proc_dointvec,
733 #ifdef CONFIG_DETECT_SOFTLOCKUP
735 .ctl_name = CTL_UNNUMBERED,
736 .procname = "softlockup_thresh",
737 .data = &softlockup_thresh,
738 .maxlen = sizeof(unsigned long),
740 .proc_handler = &proc_doulongvec_minmax,
741 .strategy = &sysctl_intvec,
746 .ctl_name = CTL_UNNUMBERED,
747 .procname = "hung_task_check_count",
748 .data = &sysctl_hung_task_check_count,
749 .maxlen = sizeof(unsigned long),
751 .proc_handler = &proc_doulongvec_minmax,
752 .strategy = &sysctl_intvec,
755 .ctl_name = CTL_UNNUMBERED,
756 .procname = "hung_task_timeout_secs",
757 .data = &sysctl_hung_task_timeout_secs,
758 .maxlen = sizeof(unsigned long),
760 .proc_handler = &proc_doulongvec_minmax,
761 .strategy = &sysctl_intvec,
764 .ctl_name = CTL_UNNUMBERED,
765 .procname = "hung_task_warnings",
766 .data = &sysctl_hung_task_warnings,
767 .maxlen = sizeof(unsigned long),
769 .proc_handler = &proc_doulongvec_minmax,
770 .strategy = &sysctl_intvec,
775 .ctl_name = KERN_COMPAT_LOG,
776 .procname = "compat-log",
778 .maxlen = sizeof (int),
780 .proc_handler = &proc_dointvec,
783 #ifdef CONFIG_RT_MUTEXES
785 .ctl_name = KERN_MAX_LOCK_DEPTH,
786 .procname = "max_lock_depth",
787 .data = &max_lock_depth,
788 .maxlen = sizeof(int),
790 .proc_handler = &proc_dointvec,
793 #ifdef CONFIG_PROC_FS
795 .ctl_name = CTL_UNNUMBERED,
796 .procname = "maps_protect",
797 .data = &maps_protect,
798 .maxlen = sizeof(int),
800 .proc_handler = &proc_dointvec,
804 .ctl_name = CTL_UNNUMBERED,
805 .procname = "poweroff_cmd",
806 .data = &poweroff_cmd,
807 .maxlen = POWEROFF_CMD_PATH_LEN,
809 .proc_handler = &proc_dostring,
810 .strategy = &sysctl_string,
813 * NOTE: do not add new entries to this table unless you have read
814 * Documentation/sysctl/ctl_unnumbered.txt
819 static struct ctl_table vm_table[] = {
821 .ctl_name = VM_OVERCOMMIT_MEMORY,
822 .procname = "overcommit_memory",
823 .data = &sysctl_overcommit_memory,
824 .maxlen = sizeof(sysctl_overcommit_memory),
826 .proc_handler = &proc_dointvec,
829 .ctl_name = VM_PANIC_ON_OOM,
830 .procname = "panic_on_oom",
831 .data = &sysctl_panic_on_oom,
832 .maxlen = sizeof(sysctl_panic_on_oom),
834 .proc_handler = &proc_dointvec,
837 .ctl_name = CTL_UNNUMBERED,
838 .procname = "oom_kill_allocating_task",
839 .data = &sysctl_oom_kill_allocating_task,
840 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
842 .proc_handler = &proc_dointvec,
845 .ctl_name = CTL_UNNUMBERED,
846 .procname = "oom_dump_tasks",
847 .data = &sysctl_oom_dump_tasks,
848 .maxlen = sizeof(sysctl_oom_dump_tasks),
850 .proc_handler = &proc_dointvec,
853 .ctl_name = VM_OVERCOMMIT_RATIO,
854 .procname = "overcommit_ratio",
855 .data = &sysctl_overcommit_ratio,
856 .maxlen = sizeof(sysctl_overcommit_ratio),
858 .proc_handler = &proc_dointvec,
861 .ctl_name = VM_PAGE_CLUSTER,
862 .procname = "page-cluster",
863 .data = &page_cluster,
864 .maxlen = sizeof(int),
866 .proc_handler = &proc_dointvec,
869 .ctl_name = VM_DIRTY_BACKGROUND,
870 .procname = "dirty_background_ratio",
871 .data = &dirty_background_ratio,
872 .maxlen = sizeof(dirty_background_ratio),
874 .proc_handler = &proc_dointvec_minmax,
875 .strategy = &sysctl_intvec,
877 .extra2 = &one_hundred,
880 .ctl_name = VM_DIRTY_RATIO,
881 .procname = "dirty_ratio",
882 .data = &vm_dirty_ratio,
883 .maxlen = sizeof(vm_dirty_ratio),
885 .proc_handler = &dirty_ratio_handler,
886 .strategy = &sysctl_intvec,
888 .extra2 = &one_hundred,
891 .procname = "dirty_writeback_centisecs",
892 .data = &dirty_writeback_interval,
893 .maxlen = sizeof(dirty_writeback_interval),
895 .proc_handler = &dirty_writeback_centisecs_handler,
898 .procname = "dirty_expire_centisecs",
899 .data = &dirty_expire_interval,
900 .maxlen = sizeof(dirty_expire_interval),
902 .proc_handler = &proc_dointvec_userhz_jiffies,
905 .ctl_name = VM_NR_PDFLUSH_THREADS,
906 .procname = "nr_pdflush_threads",
907 .data = &nr_pdflush_threads,
908 .maxlen = sizeof nr_pdflush_threads,
909 .mode = 0444 /* read-only*/,
910 .proc_handler = &proc_dointvec,
913 .ctl_name = VM_SWAPPINESS,
914 .procname = "swappiness",
915 .data = &vm_swappiness,
916 .maxlen = sizeof(vm_swappiness),
918 .proc_handler = &proc_dointvec_minmax,
919 .strategy = &sysctl_intvec,
921 .extra2 = &one_hundred,
923 #ifdef CONFIG_HUGETLB_PAGE
925 .procname = "nr_hugepages",
926 .data = &max_huge_pages,
927 .maxlen = sizeof(unsigned long),
929 .proc_handler = &hugetlb_sysctl_handler,
930 .extra1 = (void *)&hugetlb_zero,
931 .extra2 = (void *)&hugetlb_infinity,
934 .ctl_name = VM_HUGETLB_GROUP,
935 .procname = "hugetlb_shm_group",
936 .data = &sysctl_hugetlb_shm_group,
937 .maxlen = sizeof(gid_t),
939 .proc_handler = &proc_dointvec,
942 .ctl_name = CTL_UNNUMBERED,
943 .procname = "hugepages_treat_as_movable",
944 .data = &hugepages_treat_as_movable,
945 .maxlen = sizeof(int),
947 .proc_handler = &hugetlb_treat_movable_handler,
950 .ctl_name = CTL_UNNUMBERED,
951 .procname = "nr_overcommit_hugepages",
952 .data = &sysctl_overcommit_huge_pages,
953 .maxlen = sizeof(sysctl_overcommit_huge_pages),
955 .proc_handler = &hugetlb_overcommit_handler,
959 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
960 .procname = "lowmem_reserve_ratio",
961 .data = &sysctl_lowmem_reserve_ratio,
962 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
964 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
965 .strategy = &sysctl_intvec,
968 .ctl_name = VM_DROP_PAGECACHE,
969 .procname = "drop_caches",
970 .data = &sysctl_drop_caches,
971 .maxlen = sizeof(int),
973 .proc_handler = drop_caches_sysctl_handler,
974 .strategy = &sysctl_intvec,
977 .ctl_name = VM_MIN_FREE_KBYTES,
978 .procname = "min_free_kbytes",
979 .data = &min_free_kbytes,
980 .maxlen = sizeof(min_free_kbytes),
982 .proc_handler = &min_free_kbytes_sysctl_handler,
983 .strategy = &sysctl_intvec,
987 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
988 .procname = "percpu_pagelist_fraction",
989 .data = &percpu_pagelist_fraction,
990 .maxlen = sizeof(percpu_pagelist_fraction),
992 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
993 .strategy = &sysctl_intvec,
994 .extra1 = &min_percpu_pagelist_fract,
998 .ctl_name = VM_MAX_MAP_COUNT,
999 .procname = "max_map_count",
1000 .data = &sysctl_max_map_count,
1001 .maxlen = sizeof(sysctl_max_map_count),
1003 .proc_handler = &proc_dointvec
1007 .ctl_name = VM_LAPTOP_MODE,
1008 .procname = "laptop_mode",
1009 .data = &laptop_mode,
1010 .maxlen = sizeof(laptop_mode),
1012 .proc_handler = &proc_dointvec_jiffies,
1013 .strategy = &sysctl_jiffies,
1016 .ctl_name = VM_BLOCK_DUMP,
1017 .procname = "block_dump",
1018 .data = &block_dump,
1019 .maxlen = sizeof(block_dump),
1021 .proc_handler = &proc_dointvec,
1022 .strategy = &sysctl_intvec,
1026 .ctl_name = VM_VFS_CACHE_PRESSURE,
1027 .procname = "vfs_cache_pressure",
1028 .data = &sysctl_vfs_cache_pressure,
1029 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1031 .proc_handler = &proc_dointvec,
1032 .strategy = &sysctl_intvec,
1035 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1037 .ctl_name = VM_LEGACY_VA_LAYOUT,
1038 .procname = "legacy_va_layout",
1039 .data = &sysctl_legacy_va_layout,
1040 .maxlen = sizeof(sysctl_legacy_va_layout),
1042 .proc_handler = &proc_dointvec,
1043 .strategy = &sysctl_intvec,
1049 .ctl_name = VM_ZONE_RECLAIM_MODE,
1050 .procname = "zone_reclaim_mode",
1051 .data = &zone_reclaim_mode,
1052 .maxlen = sizeof(zone_reclaim_mode),
1054 .proc_handler = &proc_dointvec,
1055 .strategy = &sysctl_intvec,
1059 .ctl_name = VM_MIN_UNMAPPED,
1060 .procname = "min_unmapped_ratio",
1061 .data = &sysctl_min_unmapped_ratio,
1062 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1064 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1065 .strategy = &sysctl_intvec,
1067 .extra2 = &one_hundred,
1070 .ctl_name = VM_MIN_SLAB,
1071 .procname = "min_slab_ratio",
1072 .data = &sysctl_min_slab_ratio,
1073 .maxlen = sizeof(sysctl_min_slab_ratio),
1075 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1076 .strategy = &sysctl_intvec,
1078 .extra2 = &one_hundred,
1083 .ctl_name = CTL_UNNUMBERED,
1084 .procname = "stat_interval",
1085 .data = &sysctl_stat_interval,
1086 .maxlen = sizeof(sysctl_stat_interval),
1088 .proc_handler = &proc_dointvec_jiffies,
1089 .strategy = &sysctl_jiffies,
1092 #ifdef CONFIG_SECURITY
1094 .ctl_name = CTL_UNNUMBERED,
1095 .procname = "mmap_min_addr",
1096 .data = &mmap_min_addr,
1097 .maxlen = sizeof(unsigned long),
1099 .proc_handler = &proc_doulongvec_minmax,
1104 .ctl_name = CTL_UNNUMBERED,
1105 .procname = "numa_zonelist_order",
1106 .data = &numa_zonelist_order,
1107 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1109 .proc_handler = &numa_zonelist_order_handler,
1110 .strategy = &sysctl_string,
1113 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1114 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1116 .ctl_name = VM_VDSO_ENABLED,
1117 .procname = "vdso_enabled",
1118 .data = &vdso_enabled,
1119 .maxlen = sizeof(vdso_enabled),
1121 .proc_handler = &proc_dointvec,
1122 .strategy = &sysctl_intvec,
1126 #ifdef CONFIG_HIGHMEM
1128 .ctl_name = CTL_UNNUMBERED,
1129 .procname = "highmem_is_dirtyable",
1130 .data = &vm_highmem_is_dirtyable,
1131 .maxlen = sizeof(vm_highmem_is_dirtyable),
1133 .proc_handler = &proc_dointvec_minmax,
1134 .strategy = &sysctl_intvec,
1140 * NOTE: do not add new entries to this table unless you have read
1141 * Documentation/sysctl/ctl_unnumbered.txt
1146 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1147 static struct ctl_table binfmt_misc_table[] = {
1152 static struct ctl_table fs_table[] = {
1154 .ctl_name = FS_NRINODE,
1155 .procname = "inode-nr",
1156 .data = &inodes_stat,
1157 .maxlen = 2*sizeof(int),
1159 .proc_handler = &proc_dointvec,
1162 .ctl_name = FS_STATINODE,
1163 .procname = "inode-state",
1164 .data = &inodes_stat,
1165 .maxlen = 7*sizeof(int),
1167 .proc_handler = &proc_dointvec,
1170 .procname = "file-nr",
1171 .data = &files_stat,
1172 .maxlen = 3*sizeof(int),
1174 .proc_handler = &proc_nr_files,
1177 .ctl_name = FS_MAXFILE,
1178 .procname = "file-max",
1179 .data = &files_stat.max_files,
1180 .maxlen = sizeof(int),
1182 .proc_handler = &proc_dointvec,
1185 .ctl_name = CTL_UNNUMBERED,
1186 .procname = "nr_open",
1187 .data = &sysctl_nr_open,
1188 .maxlen = sizeof(int),
1190 .proc_handler = &proc_dointvec,
1193 .ctl_name = FS_DENTRY,
1194 .procname = "dentry-state",
1195 .data = &dentry_stat,
1196 .maxlen = 6*sizeof(int),
1198 .proc_handler = &proc_dointvec,
1201 .ctl_name = FS_OVERFLOWUID,
1202 .procname = "overflowuid",
1203 .data = &fs_overflowuid,
1204 .maxlen = sizeof(int),
1206 .proc_handler = &proc_dointvec_minmax,
1207 .strategy = &sysctl_intvec,
1208 .extra1 = &minolduid,
1209 .extra2 = &maxolduid,
1212 .ctl_name = FS_OVERFLOWGID,
1213 .procname = "overflowgid",
1214 .data = &fs_overflowgid,
1215 .maxlen = sizeof(int),
1217 .proc_handler = &proc_dointvec_minmax,
1218 .strategy = &sysctl_intvec,
1219 .extra1 = &minolduid,
1220 .extra2 = &maxolduid,
1223 .ctl_name = FS_LEASES,
1224 .procname = "leases-enable",
1225 .data = &leases_enable,
1226 .maxlen = sizeof(int),
1228 .proc_handler = &proc_dointvec,
1230 #ifdef CONFIG_DNOTIFY
1232 .ctl_name = FS_DIR_NOTIFY,
1233 .procname = "dir-notify-enable",
1234 .data = &dir_notify_enable,
1235 .maxlen = sizeof(int),
1237 .proc_handler = &proc_dointvec,
1242 .ctl_name = FS_LEASE_TIME,
1243 .procname = "lease-break-time",
1244 .data = &lease_break_time,
1245 .maxlen = sizeof(int),
1247 .proc_handler = &proc_dointvec_minmax,
1248 .strategy = &sysctl_intvec,
1253 .procname = "aio-nr",
1255 .maxlen = sizeof(aio_nr),
1257 .proc_handler = &proc_doulongvec_minmax,
1260 .procname = "aio-max-nr",
1261 .data = &aio_max_nr,
1262 .maxlen = sizeof(aio_max_nr),
1264 .proc_handler = &proc_doulongvec_minmax,
1266 #ifdef CONFIG_INOTIFY_USER
1268 .ctl_name = FS_INOTIFY,
1269 .procname = "inotify",
1271 .child = inotify_table,
1276 .ctl_name = KERN_SETUID_DUMPABLE,
1277 .procname = "suid_dumpable",
1278 .data = &suid_dumpable,
1279 .maxlen = sizeof(int),
1281 .proc_handler = &proc_dointvec,
1283 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1285 .ctl_name = CTL_UNNUMBERED,
1286 .procname = "binfmt_misc",
1288 .child = binfmt_misc_table,
1292 * NOTE: do not add new entries to this table unless you have read
1293 * Documentation/sysctl/ctl_unnumbered.txt
1298 static struct ctl_table debug_table[] = {
1299 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1301 .ctl_name = CTL_UNNUMBERED,
1302 .procname = "exception-trace",
1303 .data = &show_unhandled_signals,
1304 .maxlen = sizeof(int),
1306 .proc_handler = proc_dointvec
1312 static struct ctl_table dev_table[] = {
1316 static DEFINE_SPINLOCK(sysctl_lock);
1318 /* called under sysctl_lock */
1319 static int use_table(struct ctl_table_header *p)
1321 if (unlikely(p->unregistering))
1327 /* called under sysctl_lock */
1328 static void unuse_table(struct ctl_table_header *p)
1331 if (unlikely(p->unregistering))
1332 complete(p->unregistering);
1335 /* called under sysctl_lock, will reacquire if has to wait */
1336 static void start_unregistering(struct ctl_table_header *p)
1339 * if p->used is 0, nobody will ever touch that entry again;
1340 * we'll eliminate all paths to it before dropping sysctl_lock
1342 if (unlikely(p->used)) {
1343 struct completion wait;
1344 init_completion(&wait);
1345 p->unregistering = &wait;
1346 spin_unlock(&sysctl_lock);
1347 wait_for_completion(&wait);
1348 spin_lock(&sysctl_lock);
1351 * do not remove from the list until nobody holds it; walking the
1352 * list in do_sysctl() relies on that.
1354 list_del_init(&p->ctl_entry);
1357 void sysctl_head_finish(struct ctl_table_header *head)
1361 spin_lock(&sysctl_lock);
1363 spin_unlock(&sysctl_lock);
1366 static struct list_head *
1367 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1369 struct list_head *header_list;
1370 header_list = &root->header_list;
1372 header_list = root->lookup(root, namespaces);
1376 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1377 struct ctl_table_header *prev)
1379 struct ctl_table_root *root;
1380 struct list_head *header_list;
1381 struct ctl_table_header *head;
1382 struct list_head *tmp;
1384 spin_lock(&sysctl_lock);
1387 tmp = &prev->ctl_entry;
1391 tmp = &root_table_header.ctl_entry;
1393 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1395 if (!use_table(head))
1397 spin_unlock(&sysctl_lock);
1402 header_list = lookup_header_list(root, namespaces);
1403 if (tmp != header_list)
1407 root = list_entry(root->root_list.next,
1408 struct ctl_table_root, root_list);
1409 if (root == &sysctl_table_root)
1411 header_list = lookup_header_list(root, namespaces);
1412 } while (list_empty(header_list));
1413 tmp = header_list->next;
1416 spin_unlock(&sysctl_lock);
1420 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1422 return __sysctl_head_next(current->nsproxy, prev);
1425 void register_sysctl_root(struct ctl_table_root *root)
1427 spin_lock(&sysctl_lock);
1428 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1429 spin_unlock(&sysctl_lock);
1432 #ifdef CONFIG_SYSCTL_SYSCALL
1433 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1434 void __user *newval, size_t newlen)
1436 struct ctl_table_header *head;
1437 int error = -ENOTDIR;
1439 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1443 if (!oldlenp || get_user(old_len, oldlenp))
1447 for (head = sysctl_head_next(NULL); head;
1448 head = sysctl_head_next(head)) {
1449 error = parse_table(name, nlen, oldval, oldlenp,
1450 newval, newlen, head->ctl_table);
1451 if (error != -ENOTDIR) {
1452 sysctl_head_finish(head);
1459 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1461 struct __sysctl_args tmp;
1464 if (copy_from_user(&tmp, args, sizeof(tmp)))
1467 error = deprecated_sysctl_warning(&tmp);
1472 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1473 tmp.newval, tmp.newlen);
1478 #endif /* CONFIG_SYSCTL_SYSCALL */
1481 * sysctl_perm does NOT grant the superuser all rights automatically, because
1482 * some sysctl variables are readonly even to root.
1485 static int test_perm(int mode, int op)
1489 else if (in_egroup_p(0))
1491 if ((mode & op & 0007) == op)
1496 int sysctl_perm(struct ctl_table *table, int op)
1499 error = security_sysctl(table, op);
1502 return test_perm(table->mode, op);
1505 #ifdef CONFIG_SYSCTL_SYSCALL
1506 static int parse_table(int __user *name, int nlen,
1507 void __user *oldval, size_t __user *oldlenp,
1508 void __user *newval, size_t newlen,
1509 struct ctl_table *table)
1515 if (get_user(n, name))
1517 for ( ; table->ctl_name || table->procname; table++) {
1518 if (!table->ctl_name)
1520 if (n == table->ctl_name) {
1523 if (sysctl_perm(table, 001))
1527 table = table->child;
1530 error = do_sysctl_strategy(table, name, nlen,
1539 /* Perform the actual read/write of a sysctl table entry. */
1540 int do_sysctl_strategy (struct ctl_table *table,
1541 int __user *name, int nlen,
1542 void __user *oldval, size_t __user *oldlenp,
1543 void __user *newval, size_t newlen)
1551 if (sysctl_perm(table, op))
1554 if (table->strategy) {
1555 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1563 /* If there is no strategy routine, or if the strategy returns
1564 * zero, proceed with automatic r/w */
1565 if (table->data && table->maxlen) {
1566 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1573 #endif /* CONFIG_SYSCTL_SYSCALL */
1575 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1577 for (; table->ctl_name || table->procname; table++) {
1578 table->parent = parent;
1580 sysctl_set_parent(table, table->child);
1584 static __init int sysctl_init(void)
1587 sysctl_set_parent(NULL, root_table);
1588 err = sysctl_check_table(current->nsproxy, root_table);
1592 core_initcall(sysctl_init);
1595 * __register_sysctl_paths - register a sysctl hierarchy
1596 * @root: List of sysctl headers to register on
1597 * @namespaces: Data to compute which lists of sysctl entries are visible
1598 * @path: The path to the directory the sysctl table is in.
1599 * @table: the top-level table structure
1601 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1602 * array. A completely 0 filled entry terminates the table.
1604 * The members of the &struct ctl_table structure are used as follows:
1606 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1607 * must be unique within that level of sysctl
1609 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1610 * enter a sysctl file
1612 * data - a pointer to data for use by proc_handler
1614 * maxlen - the maximum size in bytes of the data
1616 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1618 * child - a pointer to the child sysctl table if this entry is a directory, or
1621 * proc_handler - the text handler routine (described below)
1623 * strategy - the strategy routine (described below)
1625 * de - for internal use by the sysctl routines
1627 * extra1, extra2 - extra pointers usable by the proc handler routines
1629 * Leaf nodes in the sysctl tree will be represented by a single file
1630 * under /proc; non-leaf nodes will be represented by directories.
1632 * sysctl(2) can automatically manage read and write requests through
1633 * the sysctl table. The data and maxlen fields of the ctl_table
1634 * struct enable minimal validation of the values being written to be
1635 * performed, and the mode field allows minimal authentication.
1637 * More sophisticated management can be enabled by the provision of a
1638 * strategy routine with the table entry. This will be called before
1639 * any automatic read or write of the data is performed.
1641 * The strategy routine may return
1643 * < 0 - Error occurred (error is passed to user process)
1645 * 0 - OK - proceed with automatic read or write.
1647 * > 0 - OK - read or write has been done by the strategy routine, so
1648 * return immediately.
1650 * There must be a proc_handler routine for any terminal nodes
1651 * mirrored under /proc/sys (non-terminals are handled by a built-in
1652 * directory handler). Several default handlers are available to
1653 * cover common cases -
1655 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1656 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1657 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1659 * It is the handler's job to read the input buffer from user memory
1660 * and process it. The handler should return 0 on success.
1662 * This routine returns %NULL on a failure to register, and a pointer
1663 * to the table header on success.
1665 struct ctl_table_header *__register_sysctl_paths(
1666 struct ctl_table_root *root,
1667 struct nsproxy *namespaces,
1668 const struct ctl_path *path, struct ctl_table *table)
1670 struct list_head *header_list;
1671 struct ctl_table_header *header;
1672 struct ctl_table *new, **prevp;
1673 unsigned int n, npath;
1675 /* Count the path components */
1676 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1680 * For each path component, allocate a 2-element ctl_table array.
1681 * The first array element will be filled with the sysctl entry
1682 * for this, the second will be the sentinel (ctl_name == 0).
1684 * We allocate everything in one go so that we don't have to
1685 * worry about freeing additional memory in unregister_sysctl_table.
1687 header = kzalloc(sizeof(struct ctl_table_header) +
1688 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1692 new = (struct ctl_table *) (header + 1);
1694 /* Now connect the dots */
1695 prevp = &header->ctl_table;
1696 for (n = 0; n < npath; ++n, ++path) {
1697 /* Copy the procname */
1698 new->procname = path->procname;
1699 new->ctl_name = path->ctl_name;
1703 prevp = &new->child;
1708 header->ctl_table_arg = table;
1710 INIT_LIST_HEAD(&header->ctl_entry);
1712 header->unregistering = NULL;
1713 header->root = root;
1714 sysctl_set_parent(NULL, header->ctl_table);
1715 if (sysctl_check_table(namespaces, header->ctl_table)) {
1719 spin_lock(&sysctl_lock);
1720 header_list = lookup_header_list(root, namespaces);
1721 list_add_tail(&header->ctl_entry, header_list);
1722 spin_unlock(&sysctl_lock);
1728 * register_sysctl_table_path - register a sysctl table hierarchy
1729 * @path: The path to the directory the sysctl table is in.
1730 * @table: the top-level table structure
1732 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1733 * array. A completely 0 filled entry terminates the table.
1735 * See __register_sysctl_paths for more details.
1737 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1738 struct ctl_table *table)
1740 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1745 * register_sysctl_table - register a sysctl table hierarchy
1746 * @table: the top-level table structure
1748 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1749 * array. A completely 0 filled entry terminates the table.
1751 * See register_sysctl_paths for more details.
1753 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1755 static const struct ctl_path null_path[] = { {} };
1757 return register_sysctl_paths(null_path, table);
1761 * unregister_sysctl_table - unregister a sysctl table hierarchy
1762 * @header: the header returned from register_sysctl_table
1764 * Unregisters the sysctl table and all children. proc entries may not
1765 * actually be removed until they are no longer used by anyone.
1767 void unregister_sysctl_table(struct ctl_table_header * header)
1774 spin_lock(&sysctl_lock);
1775 start_unregistering(header);
1776 spin_unlock(&sysctl_lock);
1780 #else /* !CONFIG_SYSCTL */
1781 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1786 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1787 struct ctl_table *table)
1792 void unregister_sysctl_table(struct ctl_table_header * table)
1796 #endif /* CONFIG_SYSCTL */
1802 #ifdef CONFIG_PROC_SYSCTL
1804 static int _proc_do_string(void* data, int maxlen, int write,
1805 struct file *filp, void __user *buffer,
1806 size_t *lenp, loff_t *ppos)
1812 if (!data || !maxlen || !*lenp) {
1820 while (len < *lenp) {
1821 if (get_user(c, p++))
1823 if (c == 0 || c == '\n')
1829 if(copy_from_user(data, buffer, len))
1831 ((char *) data)[len] = 0;
1849 if(copy_to_user(buffer, data, len))
1852 if(put_user('\n', ((char __user *) buffer) + len))
1863 * proc_dostring - read a string sysctl
1864 * @table: the sysctl table
1865 * @write: %TRUE if this is a write to the sysctl file
1866 * @filp: the file structure
1867 * @buffer: the user buffer
1868 * @lenp: the size of the user buffer
1869 * @ppos: file position
1871 * Reads/writes a string from/to the user buffer. If the kernel
1872 * buffer provided is not large enough to hold the string, the
1873 * string is truncated. The copied string is %NULL-terminated.
1874 * If the string is being read by the user process, it is copied
1875 * and a newline '\n' is added. It is truncated if the buffer is
1878 * Returns 0 on success.
1880 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
1881 void __user *buffer, size_t *lenp, loff_t *ppos)
1883 return _proc_do_string(table->data, table->maxlen, write, filp,
1884 buffer, lenp, ppos);
1888 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1890 int write, void *data)
1893 *valp = *negp ? -*lvalp : *lvalp;
1898 *lvalp = (unsigned long)-val;
1901 *lvalp = (unsigned long)val;
1907 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1908 int write, struct file *filp, void __user *buffer,
1909 size_t *lenp, loff_t *ppos,
1910 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1911 int write, void *data),
1914 #define TMPBUFLEN 21
1915 int *i, vleft, first=1, neg, val;
1919 char buf[TMPBUFLEN], *p;
1920 char __user *s = buffer;
1922 if (!tbl_data || !table->maxlen || !*lenp ||
1923 (*ppos && !write)) {
1928 i = (int *) tbl_data;
1929 vleft = table->maxlen / sizeof(*i);
1933 conv = do_proc_dointvec_conv;
1935 for (; left && vleft--; i++, first=0) {
1950 if (len > sizeof(buf) - 1)
1951 len = sizeof(buf) - 1;
1952 if (copy_from_user(buf, s, len))
1956 if (*p == '-' && left > 1) {
1960 if (*p < '0' || *p > '9')
1963 lval = simple_strtoul(p, &p, 0);
1966 if ((len < left) && *p && !isspace(*p))
1973 if (conv(&neg, &lval, i, 1, data))
1980 if (conv(&neg, &lval, i, 0, data))
1983 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1987 if(copy_to_user(s, buf, len))
1994 if (!write && !first && left) {
1995 if(put_user('\n', s))
2002 if (get_user(c, s++))
2017 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2018 void __user *buffer, size_t *lenp, loff_t *ppos,
2019 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2020 int write, void *data),
2023 return __do_proc_dointvec(table->data, table, write, filp,
2024 buffer, lenp, ppos, conv, data);
2028 * proc_dointvec - read a vector of integers
2029 * @table: the sysctl table
2030 * @write: %TRUE if this is a write to the sysctl file
2031 * @filp: the file structure
2032 * @buffer: the user buffer
2033 * @lenp: the size of the user buffer
2034 * @ppos: file position
2036 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2037 * values from/to the user buffer, treated as an ASCII string.
2039 * Returns 0 on success.
2041 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2042 void __user *buffer, size_t *lenp, loff_t *ppos)
2044 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2052 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2054 int write, void *data)
2056 int op = *(int *)data;
2058 int val = *negp ? -*lvalp : *lvalp;
2060 case OP_SET: *valp = val; break;
2061 case OP_AND: *valp &= val; break;
2062 case OP_OR: *valp |= val; break;
2068 *lvalp = (unsigned long)-val;
2071 *lvalp = (unsigned long)val;
2078 * Taint values can only be increased
2080 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
2081 void __user *buffer, size_t *lenp, loff_t *ppos)
2085 if (write && !capable(CAP_SYS_ADMIN))
2089 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2090 do_proc_dointvec_bset_conv,&op);
2093 struct do_proc_dointvec_minmax_conv_param {
2098 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2100 int write, void *data)
2102 struct do_proc_dointvec_minmax_conv_param *param = data;
2104 int val = *negp ? -*lvalp : *lvalp;
2105 if ((param->min && *param->min > val) ||
2106 (param->max && *param->max < val))
2113 *lvalp = (unsigned long)-val;
2116 *lvalp = (unsigned long)val;
2123 * proc_dointvec_minmax - read a vector of integers with min/max values
2124 * @table: the sysctl table
2125 * @write: %TRUE if this is a write to the sysctl file
2126 * @filp: the file structure
2127 * @buffer: the user buffer
2128 * @lenp: the size of the user buffer
2129 * @ppos: file position
2131 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2132 * values from/to the user buffer, treated as an ASCII string.
2134 * This routine will ensure the values are within the range specified by
2135 * table->extra1 (min) and table->extra2 (max).
2137 * Returns 0 on success.
2139 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2140 void __user *buffer, size_t *lenp, loff_t *ppos)
2142 struct do_proc_dointvec_minmax_conv_param param = {
2143 .min = (int *) table->extra1,
2144 .max = (int *) table->extra2,
2146 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2147 do_proc_dointvec_minmax_conv, ¶m);
2150 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2152 void __user *buffer,
2153 size_t *lenp, loff_t *ppos,
2154 unsigned long convmul,
2155 unsigned long convdiv)
2157 #define TMPBUFLEN 21
2158 unsigned long *i, *min, *max, val;
2159 int vleft, first=1, neg;
2161 char buf[TMPBUFLEN], *p;
2162 char __user *s = buffer;
2164 if (!data || !table->maxlen || !*lenp ||
2165 (*ppos && !write)) {
2170 i = (unsigned long *) data;
2171 min = (unsigned long *) table->extra1;
2172 max = (unsigned long *) table->extra2;
2173 vleft = table->maxlen / sizeof(unsigned long);
2176 for (; left && vleft--; i++, min++, max++, first=0) {
2191 if (len > TMPBUFLEN-1)
2193 if (copy_from_user(buf, s, len))
2197 if (*p == '-' && left > 1) {
2201 if (*p < '0' || *p > '9')
2203 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2205 if ((len < left) && *p && !isspace(*p))
2214 if ((min && val < *min) || (max && val > *max))
2221 sprintf(p, "%lu", convdiv * (*i) / convmul);
2225 if(copy_to_user(s, buf, len))
2232 if (!write && !first && left) {
2233 if(put_user('\n', s))
2240 if (get_user(c, s++))
2255 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2257 void __user *buffer,
2258 size_t *lenp, loff_t *ppos,
2259 unsigned long convmul,
2260 unsigned long convdiv)
2262 return __do_proc_doulongvec_minmax(table->data, table, write,
2263 filp, buffer, lenp, ppos, convmul, convdiv);
2267 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2268 * @table: the sysctl table
2269 * @write: %TRUE if this is a write to the sysctl file
2270 * @filp: the file structure
2271 * @buffer: the user buffer
2272 * @lenp: the size of the user buffer
2273 * @ppos: file position
2275 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2276 * values from/to the user buffer, treated as an ASCII string.
2278 * This routine will ensure the values are within the range specified by
2279 * table->extra1 (min) and table->extra2 (max).
2281 * Returns 0 on success.
2283 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2284 void __user *buffer, size_t *lenp, loff_t *ppos)
2286 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2290 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2291 * @table: the sysctl table
2292 * @write: %TRUE if this is a write to the sysctl file
2293 * @filp: the file structure
2294 * @buffer: the user buffer
2295 * @lenp: the size of the user buffer
2296 * @ppos: file position
2298 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2299 * values from/to the user buffer, treated as an ASCII string. The values
2300 * are treated as milliseconds, and converted to jiffies when they are stored.
2302 * This routine will ensure the values are within the range specified by
2303 * table->extra1 (min) and table->extra2 (max).
2305 * Returns 0 on success.
2307 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2309 void __user *buffer,
2310 size_t *lenp, loff_t *ppos)
2312 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2313 lenp, ppos, HZ, 1000l);
2317 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2319 int write, void *data)
2322 if (*lvalp > LONG_MAX / HZ)
2324 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2330 lval = (unsigned long)-val;
2333 lval = (unsigned long)val;
2340 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2342 int write, void *data)
2345 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2347 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2353 lval = (unsigned long)-val;
2356 lval = (unsigned long)val;
2358 *lvalp = jiffies_to_clock_t(lval);
2363 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2365 int write, void *data)
2368 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2374 lval = (unsigned long)-val;
2377 lval = (unsigned long)val;
2379 *lvalp = jiffies_to_msecs(lval);
2385 * proc_dointvec_jiffies - read a vector of integers as seconds
2386 * @table: the sysctl table
2387 * @write: %TRUE if this is a write to the sysctl file
2388 * @filp: the file structure
2389 * @buffer: the user buffer
2390 * @lenp: the size of the user buffer
2391 * @ppos: file position
2393 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2394 * values from/to the user buffer, treated as an ASCII string.
2395 * The values read are assumed to be in seconds, and are converted into
2398 * Returns 0 on success.
2400 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2401 void __user *buffer, size_t *lenp, loff_t *ppos)
2403 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2404 do_proc_dointvec_jiffies_conv,NULL);
2408 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2409 * @table: the sysctl table
2410 * @write: %TRUE if this is a write to the sysctl file
2411 * @filp: the file structure
2412 * @buffer: the user buffer
2413 * @lenp: the size of the user buffer
2414 * @ppos: pointer to the file position
2416 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2417 * values from/to the user buffer, treated as an ASCII string.
2418 * The values read are assumed to be in 1/USER_HZ seconds, and
2419 * are converted into jiffies.
2421 * Returns 0 on success.
2423 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2424 void __user *buffer, size_t *lenp, loff_t *ppos)
2426 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2427 do_proc_dointvec_userhz_jiffies_conv,NULL);
2431 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2432 * @table: the sysctl table
2433 * @write: %TRUE if this is a write to the sysctl file
2434 * @filp: the file structure
2435 * @buffer: the user buffer
2436 * @lenp: the size of the user buffer
2437 * @ppos: file position
2438 * @ppos: the current position in the file
2440 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2441 * values from/to the user buffer, treated as an ASCII string.
2442 * The values read are assumed to be in 1/1000 seconds, and
2443 * are converted into jiffies.
2445 * Returns 0 on success.
2447 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2448 void __user *buffer, size_t *lenp, loff_t *ppos)
2450 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2451 do_proc_dointvec_ms_jiffies_conv, NULL);
2454 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2455 void __user *buffer, size_t *lenp, loff_t *ppos)
2457 struct pid *new_pid;
2461 tmp = pid_vnr(cad_pid);
2463 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2464 lenp, ppos, NULL, NULL);
2468 new_pid = find_get_pid(tmp);
2472 put_pid(xchg(&cad_pid, new_pid));
2476 #else /* CONFIG_PROC_FS */
2478 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2479 void __user *buffer, size_t *lenp, loff_t *ppos)
2484 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2485 void __user *buffer, size_t *lenp, loff_t *ppos)
2490 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2491 void __user *buffer, size_t *lenp, loff_t *ppos)
2496 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2497 void __user *buffer, size_t *lenp, loff_t *ppos)
2502 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2503 void __user *buffer, size_t *lenp, loff_t *ppos)
2508 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2509 void __user *buffer, size_t *lenp, loff_t *ppos)
2514 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2515 void __user *buffer, size_t *lenp, loff_t *ppos)
2520 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2522 void __user *buffer,
2523 size_t *lenp, loff_t *ppos)
2529 #endif /* CONFIG_PROC_FS */
2532 #ifdef CONFIG_SYSCTL_SYSCALL
2534 * General sysctl support routines
2537 /* The generic sysctl data routine (used if no strategy routine supplied) */
2538 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2539 void __user *oldval, size_t __user *oldlenp,
2540 void __user *newval, size_t newlen)
2544 /* Get out of I don't have a variable */
2545 if (!table->data || !table->maxlen)
2548 if (oldval && oldlenp) {
2549 if (get_user(len, oldlenp))
2552 if (len > table->maxlen)
2553 len = table->maxlen;
2554 if (copy_to_user(oldval, table->data, len))
2556 if (put_user(len, oldlenp))
2561 if (newval && newlen) {
2562 if (newlen > table->maxlen)
2563 newlen = table->maxlen;
2565 if (copy_from_user(table->data, newval, newlen))
2571 /* The generic string strategy routine: */
2572 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2573 void __user *oldval, size_t __user *oldlenp,
2574 void __user *newval, size_t newlen)
2576 if (!table->data || !table->maxlen)
2579 if (oldval && oldlenp) {
2581 if (get_user(bufsize, oldlenp))
2584 size_t len = strlen(table->data), copied;
2586 /* This shouldn't trigger for a well-formed sysctl */
2587 if (len > table->maxlen)
2588 len = table->maxlen;
2590 /* Copy up to a max of bufsize-1 bytes of the string */
2591 copied = (len >= bufsize) ? bufsize - 1 : len;
2593 if (copy_to_user(oldval, table->data, copied) ||
2594 put_user(0, (char __user *)(oldval + copied)))
2596 if (put_user(len, oldlenp))
2600 if (newval && newlen) {
2601 size_t len = newlen;
2602 if (len > table->maxlen)
2603 len = table->maxlen;
2604 if(copy_from_user(table->data, newval, len))
2606 if (len == table->maxlen)
2608 ((char *) table->data)[len] = 0;
2614 * This function makes sure that all of the integers in the vector
2615 * are between the minimum and maximum values given in the arrays
2616 * table->extra1 and table->extra2, respectively.
2618 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2619 void __user *oldval, size_t __user *oldlenp,
2620 void __user *newval, size_t newlen)
2623 if (newval && newlen) {
2624 int __user *vec = (int __user *) newval;
2625 int *min = (int *) table->extra1;
2626 int *max = (int *) table->extra2;
2630 if (newlen % sizeof(int) != 0)
2633 if (!table->extra1 && !table->extra2)
2636 if (newlen > table->maxlen)
2637 newlen = table->maxlen;
2638 length = newlen / sizeof(int);
2640 for (i = 0; i < length; i++) {
2642 if (get_user(value, vec + i))
2644 if (min && value < min[i])
2646 if (max && value > max[i])
2653 /* Strategy function to convert jiffies to seconds */
2654 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2655 void __user *oldval, size_t __user *oldlenp,
2656 void __user *newval, size_t newlen)
2658 if (oldval && oldlenp) {
2661 if (get_user(olen, oldlenp))
2666 if (olen < sizeof(int))
2669 val = *(int *)(table->data) / HZ;
2670 if (put_user(val, (int __user *)oldval))
2672 if (put_user(sizeof(int), oldlenp))
2676 if (newval && newlen) {
2678 if (newlen != sizeof(int))
2680 if (get_user(new, (int __user *)newval))
2682 *(int *)(table->data) = new*HZ;
2687 /* Strategy function to convert jiffies to seconds */
2688 int sysctl_ms_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 = jiffies_to_msecs(*(int *)(table->data));
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) = msecs_to_jiffies(new);
2723 #else /* CONFIG_SYSCTL_SYSCALL */
2726 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2728 struct __sysctl_args tmp;
2731 if (copy_from_user(&tmp, args, sizeof(tmp)))
2734 error = deprecated_sysctl_warning(&tmp);
2736 /* If no error reading the parameters then just -ENOSYS ... */
2743 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2744 void __user *oldval, size_t __user *oldlenp,
2745 void __user *newval, size_t newlen)
2750 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2751 void __user *oldval, size_t __user *oldlenp,
2752 void __user *newval, size_t newlen)
2757 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2758 void __user *oldval, size_t __user *oldlenp,
2759 void __user *newval, size_t newlen)
2764 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2765 void __user *oldval, size_t __user *oldlenp,
2766 void __user *newval, size_t newlen)
2771 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2772 void __user *oldval, size_t __user *oldlenp,
2773 void __user *newval, size_t newlen)
2778 #endif /* CONFIG_SYSCTL_SYSCALL */
2780 static int deprecated_sysctl_warning(struct __sysctl_args *args)
2782 static int msg_count;
2783 int name[CTL_MAXNAME];
2786 /* Check args->nlen. */
2787 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2790 /* Read in the sysctl name for better debug message logging */
2791 for (i = 0; i < args->nlen; i++)
2792 if (get_user(name[i], args->name + i))
2795 /* Ignore accesses to kernel.version */
2796 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2799 if (msg_count < 5) {
2802 "warning: process `%s' used the deprecated sysctl "
2803 "system call with ", current->comm);
2804 for (i = 0; i < args->nlen; i++)
2805 printk("%d.", name[i]);
2812 * No sense putting this after each symbol definition, twice,
2813 * exception granted :-)
2815 EXPORT_SYMBOL(proc_dointvec);
2816 EXPORT_SYMBOL(proc_dointvec_jiffies);
2817 EXPORT_SYMBOL(proc_dointvec_minmax);
2818 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2819 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2820 EXPORT_SYMBOL(proc_dostring);
2821 EXPORT_SYMBOL(proc_doulongvec_minmax);
2822 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2823 EXPORT_SYMBOL(register_sysctl_table);
2824 EXPORT_SYMBOL(register_sysctl_paths);
2825 EXPORT_SYMBOL(sysctl_intvec);
2826 EXPORT_SYMBOL(sysctl_jiffies);
2827 EXPORT_SYMBOL(sysctl_ms_jiffies);
2828 EXPORT_SYMBOL(sysctl_string);
2829 EXPORT_SYMBOL(sysctl_data);
2830 EXPORT_SYMBOL(unregister_sysctl_table);