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;
85 /* Constants used for minimum and maximum */
86 #if defined(CONFIG_DETECT_SOFTLOCKUP) || defined(CONFIG_HIGHMEM)
90 #ifdef CONFIG_DETECT_SOFTLOCKUP
91 static int sixty = 60;
99 static int one_hundred = 100;
101 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
102 static int maxolduid = 65535;
103 static int minolduid;
104 static int min_percpu_pagelist_fract = 8;
106 static int ngroups_max = NGROUPS_MAX;
109 extern char modprobe_path[];
111 #ifdef CONFIG_CHR_DEV_SG
112 extern int sg_big_buff;
116 extern char reboot_command [];
117 extern int stop_a_enabled;
118 extern int scons_pwroff;
122 extern int pwrsw_enabled;
123 extern int unaligned_enabled;
127 #ifdef CONFIG_MATHEMU
128 extern int sysctl_ieee_emulation_warnings;
130 extern int sysctl_userprocess_debug;
131 extern int spin_retry;
134 #ifdef CONFIG_BSD_PROCESS_ACCT
135 extern int acct_parm[];
139 extern int no_unaligned_warning;
142 #ifdef CONFIG_RT_MUTEXES
143 extern int max_lock_depth;
146 #ifdef CONFIG_PROC_SYSCTL
147 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
148 void __user *buffer, size_t *lenp, loff_t *ppos);
149 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
150 void __user *buffer, size_t *lenp, loff_t *ppos);
153 static struct ctl_table root_table[];
154 static struct ctl_table_root sysctl_table_root;
155 static struct ctl_table_header root_table_header = {
156 .ctl_table = root_table,
157 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.header_list),
158 .root = &sysctl_table_root,
160 static struct ctl_table_root sysctl_table_root = {
161 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
162 .header_list = LIST_HEAD_INIT(root_table_header.ctl_entry),
165 static struct ctl_table kern_table[];
166 static struct ctl_table vm_table[];
167 static struct ctl_table fs_table[];
168 static struct ctl_table debug_table[];
169 static struct ctl_table dev_table[];
170 extern struct ctl_table random_table[];
171 #ifdef CONFIG_INOTIFY_USER
172 extern struct ctl_table inotify_table[];
175 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
176 int sysctl_legacy_va_layout;
179 extern int prove_locking;
180 extern int lock_stat;
182 /* The default sysctl tables: */
184 static struct ctl_table root_table[] = {
186 .ctl_name = CTL_KERN,
187 .procname = "kernel",
204 .ctl_name = CTL_DEBUG,
207 .child = debug_table,
216 * NOTE: do not add new entries to this table unless you have read
217 * Documentation/sysctl/ctl_unnumbered.txt
222 #ifdef CONFIG_SCHED_DEBUG
223 static int min_sched_granularity_ns = 100000; /* 100 usecs */
224 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
225 static int min_wakeup_granularity_ns; /* 0 usecs */
226 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
229 static struct ctl_table kern_table[] = {
230 #ifdef CONFIG_SCHED_DEBUG
232 .ctl_name = CTL_UNNUMBERED,
233 .procname = "sched_min_granularity_ns",
234 .data = &sysctl_sched_min_granularity,
235 .maxlen = sizeof(unsigned int),
237 .proc_handler = &sched_nr_latency_handler,
238 .strategy = &sysctl_intvec,
239 .extra1 = &min_sched_granularity_ns,
240 .extra2 = &max_sched_granularity_ns,
243 .ctl_name = CTL_UNNUMBERED,
244 .procname = "sched_latency_ns",
245 .data = &sysctl_sched_latency,
246 .maxlen = sizeof(unsigned int),
248 .proc_handler = &sched_nr_latency_handler,
249 .strategy = &sysctl_intvec,
250 .extra1 = &min_sched_granularity_ns,
251 .extra2 = &max_sched_granularity_ns,
254 .ctl_name = CTL_UNNUMBERED,
255 .procname = "sched_wakeup_granularity_ns",
256 .data = &sysctl_sched_wakeup_granularity,
257 .maxlen = sizeof(unsigned int),
259 .proc_handler = &proc_dointvec_minmax,
260 .strategy = &sysctl_intvec,
261 .extra1 = &min_wakeup_granularity_ns,
262 .extra2 = &max_wakeup_granularity_ns,
265 .ctl_name = CTL_UNNUMBERED,
266 .procname = "sched_child_runs_first",
267 .data = &sysctl_sched_child_runs_first,
268 .maxlen = sizeof(unsigned int),
270 .proc_handler = &proc_dointvec,
273 .ctl_name = CTL_UNNUMBERED,
274 .procname = "sched_features",
275 .data = &sysctl_sched_features,
276 .maxlen = sizeof(unsigned int),
278 .proc_handler = &proc_dointvec,
281 .ctl_name = CTL_UNNUMBERED,
282 .procname = "sched_migration_cost",
283 .data = &sysctl_sched_migration_cost,
284 .maxlen = sizeof(unsigned int),
286 .proc_handler = &proc_dointvec,
289 .ctl_name = CTL_UNNUMBERED,
290 .procname = "sched_nr_migrate",
291 .data = &sysctl_sched_nr_migrate,
292 .maxlen = sizeof(unsigned int),
294 .proc_handler = &proc_dointvec,
298 .ctl_name = CTL_UNNUMBERED,
299 .procname = "sched_rt_period_us",
300 .data = &sysctl_sched_rt_period,
301 .maxlen = sizeof(unsigned int),
303 .proc_handler = &sched_rt_handler,
306 .ctl_name = CTL_UNNUMBERED,
307 .procname = "sched_rt_runtime_us",
308 .data = &sysctl_sched_rt_runtime,
309 .maxlen = sizeof(int),
311 .proc_handler = &sched_rt_handler,
314 .ctl_name = CTL_UNNUMBERED,
315 .procname = "sched_compat_yield",
316 .data = &sysctl_sched_compat_yield,
317 .maxlen = sizeof(unsigned int),
319 .proc_handler = &proc_dointvec,
321 #ifdef CONFIG_PROVE_LOCKING
323 .ctl_name = CTL_UNNUMBERED,
324 .procname = "prove_locking",
325 .data = &prove_locking,
326 .maxlen = sizeof(int),
328 .proc_handler = &proc_dointvec,
331 #ifdef CONFIG_LOCK_STAT
333 .ctl_name = CTL_UNNUMBERED,
334 .procname = "lock_stat",
336 .maxlen = sizeof(int),
338 .proc_handler = &proc_dointvec,
342 .ctl_name = KERN_PANIC,
344 .data = &panic_timeout,
345 .maxlen = sizeof(int),
347 .proc_handler = &proc_dointvec,
350 .ctl_name = KERN_CORE_USES_PID,
351 .procname = "core_uses_pid",
352 .data = &core_uses_pid,
353 .maxlen = sizeof(int),
355 .proc_handler = &proc_dointvec,
358 .ctl_name = KERN_CORE_PATTERN,
359 .procname = "core_pattern",
360 .data = core_pattern,
361 .maxlen = CORENAME_MAX_SIZE,
363 .proc_handler = &proc_dostring,
364 .strategy = &sysctl_string,
366 #ifdef CONFIG_PROC_SYSCTL
368 .procname = "tainted",
370 .maxlen = sizeof(int),
372 .proc_handler = &proc_dointvec_taint,
375 #ifdef CONFIG_LATENCYTOP
377 .procname = "latencytop",
378 .data = &latencytop_enabled,
379 .maxlen = sizeof(int),
381 .proc_handler = &proc_dointvec,
384 #ifdef CONFIG_BLK_DEV_INITRD
386 .ctl_name = KERN_REALROOTDEV,
387 .procname = "real-root-dev",
388 .data = &real_root_dev,
389 .maxlen = sizeof(int),
391 .proc_handler = &proc_dointvec,
395 .ctl_name = CTL_UNNUMBERED,
396 .procname = "print-fatal-signals",
397 .data = &print_fatal_signals,
398 .maxlen = sizeof(int),
400 .proc_handler = &proc_dointvec,
404 .ctl_name = KERN_SPARC_REBOOT,
405 .procname = "reboot-cmd",
406 .data = reboot_command,
409 .proc_handler = &proc_dostring,
410 .strategy = &sysctl_string,
413 .ctl_name = KERN_SPARC_STOP_A,
414 .procname = "stop-a",
415 .data = &stop_a_enabled,
416 .maxlen = sizeof (int),
418 .proc_handler = &proc_dointvec,
421 .ctl_name = KERN_SPARC_SCONS_PWROFF,
422 .procname = "scons-poweroff",
423 .data = &scons_pwroff,
424 .maxlen = sizeof (int),
426 .proc_handler = &proc_dointvec,
431 .ctl_name = KERN_HPPA_PWRSW,
432 .procname = "soft-power",
433 .data = &pwrsw_enabled,
434 .maxlen = sizeof (int),
436 .proc_handler = &proc_dointvec,
439 .ctl_name = KERN_HPPA_UNALIGNED,
440 .procname = "unaligned-trap",
441 .data = &unaligned_enabled,
442 .maxlen = sizeof (int),
444 .proc_handler = &proc_dointvec,
448 .ctl_name = KERN_CTLALTDEL,
449 .procname = "ctrl-alt-del",
451 .maxlen = sizeof(int),
453 .proc_handler = &proc_dointvec,
457 .ctl_name = KERN_MODPROBE,
458 .procname = "modprobe",
459 .data = &modprobe_path,
460 .maxlen = KMOD_PATH_LEN,
462 .proc_handler = &proc_dostring,
463 .strategy = &sysctl_string,
466 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
468 .ctl_name = KERN_HOTPLUG,
469 .procname = "hotplug",
470 .data = &uevent_helper,
471 .maxlen = UEVENT_HELPER_PATH_LEN,
473 .proc_handler = &proc_dostring,
474 .strategy = &sysctl_string,
477 #ifdef CONFIG_CHR_DEV_SG
479 .ctl_name = KERN_SG_BIG_BUFF,
480 .procname = "sg-big-buff",
481 .data = &sg_big_buff,
482 .maxlen = sizeof (int),
484 .proc_handler = &proc_dointvec,
487 #ifdef CONFIG_BSD_PROCESS_ACCT
489 .ctl_name = KERN_ACCT,
492 .maxlen = 3*sizeof(int),
494 .proc_handler = &proc_dointvec,
497 #ifdef CONFIG_MAGIC_SYSRQ
499 .ctl_name = KERN_SYSRQ,
501 .data = &__sysrq_enabled,
502 .maxlen = sizeof (int),
504 .proc_handler = &proc_dointvec,
507 #ifdef CONFIG_PROC_SYSCTL
509 .procname = "cad_pid",
511 .maxlen = sizeof (int),
513 .proc_handler = &proc_do_cad_pid,
517 .ctl_name = KERN_MAX_THREADS,
518 .procname = "threads-max",
519 .data = &max_threads,
520 .maxlen = sizeof(int),
522 .proc_handler = &proc_dointvec,
525 .ctl_name = KERN_RANDOM,
526 .procname = "random",
528 .child = random_table,
531 .ctl_name = KERN_OVERFLOWUID,
532 .procname = "overflowuid",
533 .data = &overflowuid,
534 .maxlen = sizeof(int),
536 .proc_handler = &proc_dointvec_minmax,
537 .strategy = &sysctl_intvec,
538 .extra1 = &minolduid,
539 .extra2 = &maxolduid,
542 .ctl_name = KERN_OVERFLOWGID,
543 .procname = "overflowgid",
544 .data = &overflowgid,
545 .maxlen = sizeof(int),
547 .proc_handler = &proc_dointvec_minmax,
548 .strategy = &sysctl_intvec,
549 .extra1 = &minolduid,
550 .extra2 = &maxolduid,
553 #ifdef CONFIG_MATHEMU
555 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
556 .procname = "ieee_emulation_warnings",
557 .data = &sysctl_ieee_emulation_warnings,
558 .maxlen = sizeof(int),
560 .proc_handler = &proc_dointvec,
564 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
565 .procname = "userprocess_debug",
566 .data = &sysctl_userprocess_debug,
567 .maxlen = sizeof(int),
569 .proc_handler = &proc_dointvec,
573 .ctl_name = KERN_PIDMAX,
574 .procname = "pid_max",
576 .maxlen = sizeof (int),
578 .proc_handler = &proc_dointvec_minmax,
579 .strategy = sysctl_intvec,
580 .extra1 = &pid_max_min,
581 .extra2 = &pid_max_max,
584 .ctl_name = KERN_PANIC_ON_OOPS,
585 .procname = "panic_on_oops",
586 .data = &panic_on_oops,
587 .maxlen = sizeof(int),
589 .proc_handler = &proc_dointvec,
591 #if defined CONFIG_PRINTK
593 .ctl_name = KERN_PRINTK,
594 .procname = "printk",
595 .data = &console_loglevel,
596 .maxlen = 4*sizeof(int),
598 .proc_handler = &proc_dointvec,
601 .ctl_name = KERN_PRINTK_RATELIMIT,
602 .procname = "printk_ratelimit",
603 .data = &printk_ratelimit_jiffies,
604 .maxlen = sizeof(int),
606 .proc_handler = &proc_dointvec_jiffies,
607 .strategy = &sysctl_jiffies,
610 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
611 .procname = "printk_ratelimit_burst",
612 .data = &printk_ratelimit_burst,
613 .maxlen = sizeof(int),
615 .proc_handler = &proc_dointvec,
619 .ctl_name = KERN_NGROUPS_MAX,
620 .procname = "ngroups_max",
621 .data = &ngroups_max,
622 .maxlen = sizeof (int),
624 .proc_handler = &proc_dointvec,
626 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
628 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
629 .procname = "unknown_nmi_panic",
630 .data = &unknown_nmi_panic,
631 .maxlen = sizeof (int),
633 .proc_handler = &proc_dointvec,
636 .procname = "nmi_watchdog",
637 .data = &nmi_watchdog_enabled,
638 .maxlen = sizeof (int),
640 .proc_handler = &proc_nmi_enabled,
643 #if defined(CONFIG_X86)
645 .ctl_name = KERN_PANIC_ON_NMI,
646 .procname = "panic_on_unrecovered_nmi",
647 .data = &panic_on_unrecovered_nmi,
648 .maxlen = sizeof(int),
650 .proc_handler = &proc_dointvec,
653 .ctl_name = KERN_BOOTLOADER_TYPE,
654 .procname = "bootloader_type",
655 .data = &bootloader_type,
656 .maxlen = sizeof (int),
658 .proc_handler = &proc_dointvec,
661 .ctl_name = CTL_UNNUMBERED,
662 .procname = "kstack_depth_to_print",
663 .data = &kstack_depth_to_print,
664 .maxlen = sizeof(int),
666 .proc_handler = &proc_dointvec,
669 .ctl_name = CTL_UNNUMBERED,
670 .procname = "io_delay_type",
671 .data = &io_delay_type,
672 .maxlen = sizeof(int),
674 .proc_handler = &proc_dointvec,
677 #if defined(CONFIG_MMU)
679 .ctl_name = KERN_RANDOMIZE,
680 .procname = "randomize_va_space",
681 .data = &randomize_va_space,
682 .maxlen = sizeof(int),
684 .proc_handler = &proc_dointvec,
687 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
689 .ctl_name = KERN_SPIN_RETRY,
690 .procname = "spin_retry",
692 .maxlen = sizeof (int),
694 .proc_handler = &proc_dointvec,
697 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
699 .procname = "acpi_video_flags",
700 .data = &acpi_realmode_flags,
701 .maxlen = sizeof (unsigned long),
703 .proc_handler = &proc_doulongvec_minmax,
708 .ctl_name = KERN_IA64_UNALIGNED,
709 .procname = "ignore-unaligned-usertrap",
710 .data = &no_unaligned_warning,
711 .maxlen = sizeof (int),
713 .proc_handler = &proc_dointvec,
716 #ifdef CONFIG_DETECT_SOFTLOCKUP
718 .ctl_name = CTL_UNNUMBERED,
719 .procname = "softlockup_thresh",
720 .data = &softlockup_thresh,
721 .maxlen = sizeof(unsigned long),
723 .proc_handler = &proc_doulongvec_minmax,
724 .strategy = &sysctl_intvec,
729 .ctl_name = CTL_UNNUMBERED,
730 .procname = "hung_task_check_count",
731 .data = &sysctl_hung_task_check_count,
732 .maxlen = sizeof(unsigned long),
734 .proc_handler = &proc_doulongvec_minmax,
735 .strategy = &sysctl_intvec,
738 .ctl_name = CTL_UNNUMBERED,
739 .procname = "hung_task_timeout_secs",
740 .data = &sysctl_hung_task_timeout_secs,
741 .maxlen = sizeof(unsigned long),
743 .proc_handler = &proc_doulongvec_minmax,
744 .strategy = &sysctl_intvec,
747 .ctl_name = CTL_UNNUMBERED,
748 .procname = "hung_task_warnings",
749 .data = &sysctl_hung_task_warnings,
750 .maxlen = sizeof(unsigned long),
752 .proc_handler = &proc_doulongvec_minmax,
753 .strategy = &sysctl_intvec,
758 .ctl_name = KERN_COMPAT_LOG,
759 .procname = "compat-log",
761 .maxlen = sizeof (int),
763 .proc_handler = &proc_dointvec,
766 #ifdef CONFIG_RT_MUTEXES
768 .ctl_name = KERN_MAX_LOCK_DEPTH,
769 .procname = "max_lock_depth",
770 .data = &max_lock_depth,
771 .maxlen = sizeof(int),
773 .proc_handler = &proc_dointvec,
776 #ifdef CONFIG_PROC_FS
778 .ctl_name = CTL_UNNUMBERED,
779 .procname = "maps_protect",
780 .data = &maps_protect,
781 .maxlen = sizeof(int),
783 .proc_handler = &proc_dointvec,
787 .ctl_name = CTL_UNNUMBERED,
788 .procname = "poweroff_cmd",
789 .data = &poweroff_cmd,
790 .maxlen = POWEROFF_CMD_PATH_LEN,
792 .proc_handler = &proc_dostring,
793 .strategy = &sysctl_string,
797 .ctl_name = CTL_UNNUMBERED,
800 .child = key_sysctls,
804 * NOTE: do not add new entries to this table unless you have read
805 * Documentation/sysctl/ctl_unnumbered.txt
810 static struct ctl_table vm_table[] = {
812 .ctl_name = VM_OVERCOMMIT_MEMORY,
813 .procname = "overcommit_memory",
814 .data = &sysctl_overcommit_memory,
815 .maxlen = sizeof(sysctl_overcommit_memory),
817 .proc_handler = &proc_dointvec,
820 .ctl_name = VM_PANIC_ON_OOM,
821 .procname = "panic_on_oom",
822 .data = &sysctl_panic_on_oom,
823 .maxlen = sizeof(sysctl_panic_on_oom),
825 .proc_handler = &proc_dointvec,
828 .ctl_name = CTL_UNNUMBERED,
829 .procname = "oom_kill_allocating_task",
830 .data = &sysctl_oom_kill_allocating_task,
831 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
833 .proc_handler = &proc_dointvec,
836 .ctl_name = CTL_UNNUMBERED,
837 .procname = "oom_dump_tasks",
838 .data = &sysctl_oom_dump_tasks,
839 .maxlen = sizeof(sysctl_oom_dump_tasks),
841 .proc_handler = &proc_dointvec,
844 .ctl_name = VM_OVERCOMMIT_RATIO,
845 .procname = "overcommit_ratio",
846 .data = &sysctl_overcommit_ratio,
847 .maxlen = sizeof(sysctl_overcommit_ratio),
849 .proc_handler = &proc_dointvec,
852 .ctl_name = VM_PAGE_CLUSTER,
853 .procname = "page-cluster",
854 .data = &page_cluster,
855 .maxlen = sizeof(int),
857 .proc_handler = &proc_dointvec,
860 .ctl_name = VM_DIRTY_BACKGROUND,
861 .procname = "dirty_background_ratio",
862 .data = &dirty_background_ratio,
863 .maxlen = sizeof(dirty_background_ratio),
865 .proc_handler = &proc_dointvec_minmax,
866 .strategy = &sysctl_intvec,
868 .extra2 = &one_hundred,
871 .ctl_name = VM_DIRTY_RATIO,
872 .procname = "dirty_ratio",
873 .data = &vm_dirty_ratio,
874 .maxlen = sizeof(vm_dirty_ratio),
876 .proc_handler = &dirty_ratio_handler,
877 .strategy = &sysctl_intvec,
879 .extra2 = &one_hundred,
882 .procname = "dirty_writeback_centisecs",
883 .data = &dirty_writeback_interval,
884 .maxlen = sizeof(dirty_writeback_interval),
886 .proc_handler = &dirty_writeback_centisecs_handler,
889 .procname = "dirty_expire_centisecs",
890 .data = &dirty_expire_interval,
891 .maxlen = sizeof(dirty_expire_interval),
893 .proc_handler = &proc_dointvec_userhz_jiffies,
896 .ctl_name = VM_NR_PDFLUSH_THREADS,
897 .procname = "nr_pdflush_threads",
898 .data = &nr_pdflush_threads,
899 .maxlen = sizeof nr_pdflush_threads,
900 .mode = 0444 /* read-only*/,
901 .proc_handler = &proc_dointvec,
904 .ctl_name = VM_SWAPPINESS,
905 .procname = "swappiness",
906 .data = &vm_swappiness,
907 .maxlen = sizeof(vm_swappiness),
909 .proc_handler = &proc_dointvec_minmax,
910 .strategy = &sysctl_intvec,
912 .extra2 = &one_hundred,
914 #ifdef CONFIG_HUGETLB_PAGE
916 .procname = "nr_hugepages",
917 .data = &max_huge_pages,
918 .maxlen = sizeof(unsigned long),
920 .proc_handler = &hugetlb_sysctl_handler,
921 .extra1 = (void *)&hugetlb_zero,
922 .extra2 = (void *)&hugetlb_infinity,
925 .ctl_name = VM_HUGETLB_GROUP,
926 .procname = "hugetlb_shm_group",
927 .data = &sysctl_hugetlb_shm_group,
928 .maxlen = sizeof(gid_t),
930 .proc_handler = &proc_dointvec,
933 .ctl_name = CTL_UNNUMBERED,
934 .procname = "hugepages_treat_as_movable",
935 .data = &hugepages_treat_as_movable,
936 .maxlen = sizeof(int),
938 .proc_handler = &hugetlb_treat_movable_handler,
941 .ctl_name = CTL_UNNUMBERED,
942 .procname = "nr_overcommit_hugepages",
943 .data = &sysctl_overcommit_huge_pages,
944 .maxlen = sizeof(sysctl_overcommit_huge_pages),
946 .proc_handler = &hugetlb_overcommit_handler,
950 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
951 .procname = "lowmem_reserve_ratio",
952 .data = &sysctl_lowmem_reserve_ratio,
953 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
955 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
956 .strategy = &sysctl_intvec,
959 .ctl_name = VM_DROP_PAGECACHE,
960 .procname = "drop_caches",
961 .data = &sysctl_drop_caches,
962 .maxlen = sizeof(int),
964 .proc_handler = drop_caches_sysctl_handler,
965 .strategy = &sysctl_intvec,
968 .ctl_name = VM_MIN_FREE_KBYTES,
969 .procname = "min_free_kbytes",
970 .data = &min_free_kbytes,
971 .maxlen = sizeof(min_free_kbytes),
973 .proc_handler = &min_free_kbytes_sysctl_handler,
974 .strategy = &sysctl_intvec,
978 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
979 .procname = "percpu_pagelist_fraction",
980 .data = &percpu_pagelist_fraction,
981 .maxlen = sizeof(percpu_pagelist_fraction),
983 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
984 .strategy = &sysctl_intvec,
985 .extra1 = &min_percpu_pagelist_fract,
989 .ctl_name = VM_MAX_MAP_COUNT,
990 .procname = "max_map_count",
991 .data = &sysctl_max_map_count,
992 .maxlen = sizeof(sysctl_max_map_count),
994 .proc_handler = &proc_dointvec
998 .ctl_name = VM_LAPTOP_MODE,
999 .procname = "laptop_mode",
1000 .data = &laptop_mode,
1001 .maxlen = sizeof(laptop_mode),
1003 .proc_handler = &proc_dointvec_jiffies,
1004 .strategy = &sysctl_jiffies,
1007 .ctl_name = VM_BLOCK_DUMP,
1008 .procname = "block_dump",
1009 .data = &block_dump,
1010 .maxlen = sizeof(block_dump),
1012 .proc_handler = &proc_dointvec,
1013 .strategy = &sysctl_intvec,
1017 .ctl_name = VM_VFS_CACHE_PRESSURE,
1018 .procname = "vfs_cache_pressure",
1019 .data = &sysctl_vfs_cache_pressure,
1020 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1022 .proc_handler = &proc_dointvec,
1023 .strategy = &sysctl_intvec,
1026 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1028 .ctl_name = VM_LEGACY_VA_LAYOUT,
1029 .procname = "legacy_va_layout",
1030 .data = &sysctl_legacy_va_layout,
1031 .maxlen = sizeof(sysctl_legacy_va_layout),
1033 .proc_handler = &proc_dointvec,
1034 .strategy = &sysctl_intvec,
1040 .ctl_name = VM_ZONE_RECLAIM_MODE,
1041 .procname = "zone_reclaim_mode",
1042 .data = &zone_reclaim_mode,
1043 .maxlen = sizeof(zone_reclaim_mode),
1045 .proc_handler = &proc_dointvec,
1046 .strategy = &sysctl_intvec,
1050 .ctl_name = VM_MIN_UNMAPPED,
1051 .procname = "min_unmapped_ratio",
1052 .data = &sysctl_min_unmapped_ratio,
1053 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1055 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1056 .strategy = &sysctl_intvec,
1058 .extra2 = &one_hundred,
1061 .ctl_name = VM_MIN_SLAB,
1062 .procname = "min_slab_ratio",
1063 .data = &sysctl_min_slab_ratio,
1064 .maxlen = sizeof(sysctl_min_slab_ratio),
1066 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1067 .strategy = &sysctl_intvec,
1069 .extra2 = &one_hundred,
1074 .ctl_name = CTL_UNNUMBERED,
1075 .procname = "stat_interval",
1076 .data = &sysctl_stat_interval,
1077 .maxlen = sizeof(sysctl_stat_interval),
1079 .proc_handler = &proc_dointvec_jiffies,
1080 .strategy = &sysctl_jiffies,
1083 #ifdef CONFIG_SECURITY
1085 .ctl_name = CTL_UNNUMBERED,
1086 .procname = "mmap_min_addr",
1087 .data = &mmap_min_addr,
1088 .maxlen = sizeof(unsigned long),
1090 .proc_handler = &proc_doulongvec_minmax,
1095 .ctl_name = CTL_UNNUMBERED,
1096 .procname = "numa_zonelist_order",
1097 .data = &numa_zonelist_order,
1098 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1100 .proc_handler = &numa_zonelist_order_handler,
1101 .strategy = &sysctl_string,
1104 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1105 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1107 .ctl_name = VM_VDSO_ENABLED,
1108 .procname = "vdso_enabled",
1109 .data = &vdso_enabled,
1110 .maxlen = sizeof(vdso_enabled),
1112 .proc_handler = &proc_dointvec,
1113 .strategy = &sysctl_intvec,
1117 #ifdef CONFIG_HIGHMEM
1119 .ctl_name = CTL_UNNUMBERED,
1120 .procname = "highmem_is_dirtyable",
1121 .data = &vm_highmem_is_dirtyable,
1122 .maxlen = sizeof(vm_highmem_is_dirtyable),
1124 .proc_handler = &proc_dointvec_minmax,
1125 .strategy = &sysctl_intvec,
1131 * NOTE: do not add new entries to this table unless you have read
1132 * Documentation/sysctl/ctl_unnumbered.txt
1137 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1138 static struct ctl_table binfmt_misc_table[] = {
1143 static struct ctl_table fs_table[] = {
1145 .ctl_name = FS_NRINODE,
1146 .procname = "inode-nr",
1147 .data = &inodes_stat,
1148 .maxlen = 2*sizeof(int),
1150 .proc_handler = &proc_dointvec,
1153 .ctl_name = FS_STATINODE,
1154 .procname = "inode-state",
1155 .data = &inodes_stat,
1156 .maxlen = 7*sizeof(int),
1158 .proc_handler = &proc_dointvec,
1161 .procname = "file-nr",
1162 .data = &files_stat,
1163 .maxlen = 3*sizeof(int),
1165 .proc_handler = &proc_nr_files,
1168 .ctl_name = FS_MAXFILE,
1169 .procname = "file-max",
1170 .data = &files_stat.max_files,
1171 .maxlen = sizeof(int),
1173 .proc_handler = &proc_dointvec,
1176 .ctl_name = CTL_UNNUMBERED,
1177 .procname = "nr_open",
1178 .data = &sysctl_nr_open,
1179 .maxlen = sizeof(int),
1181 .proc_handler = &proc_dointvec,
1184 .ctl_name = FS_DENTRY,
1185 .procname = "dentry-state",
1186 .data = &dentry_stat,
1187 .maxlen = 6*sizeof(int),
1189 .proc_handler = &proc_dointvec,
1192 .ctl_name = FS_OVERFLOWUID,
1193 .procname = "overflowuid",
1194 .data = &fs_overflowuid,
1195 .maxlen = sizeof(int),
1197 .proc_handler = &proc_dointvec_minmax,
1198 .strategy = &sysctl_intvec,
1199 .extra1 = &minolduid,
1200 .extra2 = &maxolduid,
1203 .ctl_name = FS_OVERFLOWGID,
1204 .procname = "overflowgid",
1205 .data = &fs_overflowgid,
1206 .maxlen = sizeof(int),
1208 .proc_handler = &proc_dointvec_minmax,
1209 .strategy = &sysctl_intvec,
1210 .extra1 = &minolduid,
1211 .extra2 = &maxolduid,
1214 .ctl_name = FS_LEASES,
1215 .procname = "leases-enable",
1216 .data = &leases_enable,
1217 .maxlen = sizeof(int),
1219 .proc_handler = &proc_dointvec,
1221 #ifdef CONFIG_DNOTIFY
1223 .ctl_name = FS_DIR_NOTIFY,
1224 .procname = "dir-notify-enable",
1225 .data = &dir_notify_enable,
1226 .maxlen = sizeof(int),
1228 .proc_handler = &proc_dointvec,
1233 .ctl_name = FS_LEASE_TIME,
1234 .procname = "lease-break-time",
1235 .data = &lease_break_time,
1236 .maxlen = sizeof(int),
1238 .proc_handler = &proc_dointvec_minmax,
1239 .strategy = &sysctl_intvec,
1244 .procname = "aio-nr",
1246 .maxlen = sizeof(aio_nr),
1248 .proc_handler = &proc_doulongvec_minmax,
1251 .procname = "aio-max-nr",
1252 .data = &aio_max_nr,
1253 .maxlen = sizeof(aio_max_nr),
1255 .proc_handler = &proc_doulongvec_minmax,
1257 #ifdef CONFIG_INOTIFY_USER
1259 .ctl_name = FS_INOTIFY,
1260 .procname = "inotify",
1262 .child = inotify_table,
1267 .ctl_name = KERN_SETUID_DUMPABLE,
1268 .procname = "suid_dumpable",
1269 .data = &suid_dumpable,
1270 .maxlen = sizeof(int),
1272 .proc_handler = &proc_dointvec,
1274 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1276 .ctl_name = CTL_UNNUMBERED,
1277 .procname = "binfmt_misc",
1279 .child = binfmt_misc_table,
1283 * NOTE: do not add new entries to this table unless you have read
1284 * Documentation/sysctl/ctl_unnumbered.txt
1289 static struct ctl_table debug_table[] = {
1290 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1292 .ctl_name = CTL_UNNUMBERED,
1293 .procname = "exception-trace",
1294 .data = &show_unhandled_signals,
1295 .maxlen = sizeof(int),
1297 .proc_handler = proc_dointvec
1303 static struct ctl_table dev_table[] = {
1307 static DEFINE_SPINLOCK(sysctl_lock);
1309 /* called under sysctl_lock */
1310 static int use_table(struct ctl_table_header *p)
1312 if (unlikely(p->unregistering))
1318 /* called under sysctl_lock */
1319 static void unuse_table(struct ctl_table_header *p)
1322 if (unlikely(p->unregistering))
1323 complete(p->unregistering);
1326 /* called under sysctl_lock, will reacquire if has to wait */
1327 static void start_unregistering(struct ctl_table_header *p)
1330 * if p->used is 0, nobody will ever touch that entry again;
1331 * we'll eliminate all paths to it before dropping sysctl_lock
1333 if (unlikely(p->used)) {
1334 struct completion wait;
1335 init_completion(&wait);
1336 p->unregistering = &wait;
1337 spin_unlock(&sysctl_lock);
1338 wait_for_completion(&wait);
1339 spin_lock(&sysctl_lock);
1342 * do not remove from the list until nobody holds it; walking the
1343 * list in do_sysctl() relies on that.
1345 list_del_init(&p->ctl_entry);
1348 void sysctl_head_finish(struct ctl_table_header *head)
1352 spin_lock(&sysctl_lock);
1354 spin_unlock(&sysctl_lock);
1357 static struct list_head *
1358 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1360 struct list_head *header_list;
1361 header_list = &root->header_list;
1363 header_list = root->lookup(root, namespaces);
1367 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1368 struct ctl_table_header *prev)
1370 struct ctl_table_root *root;
1371 struct list_head *header_list;
1372 struct ctl_table_header *head;
1373 struct list_head *tmp;
1375 spin_lock(&sysctl_lock);
1378 tmp = &prev->ctl_entry;
1382 tmp = &root_table_header.ctl_entry;
1384 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1386 if (!use_table(head))
1388 spin_unlock(&sysctl_lock);
1393 header_list = lookup_header_list(root, namespaces);
1394 if (tmp != header_list)
1398 root = list_entry(root->root_list.next,
1399 struct ctl_table_root, root_list);
1400 if (root == &sysctl_table_root)
1402 header_list = lookup_header_list(root, namespaces);
1403 } while (list_empty(header_list));
1404 tmp = header_list->next;
1407 spin_unlock(&sysctl_lock);
1411 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1413 return __sysctl_head_next(current->nsproxy, prev);
1416 void register_sysctl_root(struct ctl_table_root *root)
1418 spin_lock(&sysctl_lock);
1419 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1420 spin_unlock(&sysctl_lock);
1423 #ifdef CONFIG_SYSCTL_SYSCALL
1424 /* Perform the actual read/write of a sysctl table entry. */
1425 static int do_sysctl_strategy(struct ctl_table_root *root,
1426 struct ctl_table *table,
1427 int __user *name, int nlen,
1428 void __user *oldval, size_t __user *oldlenp,
1429 void __user *newval, size_t newlen)
1437 if (sysctl_perm(root, table, op))
1440 if (table->strategy) {
1441 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1449 /* If there is no strategy routine, or if the strategy returns
1450 * zero, proceed with automatic r/w */
1451 if (table->data && table->maxlen) {
1452 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1460 static int parse_table(int __user *name, int nlen,
1461 void __user *oldval, size_t __user *oldlenp,
1462 void __user *newval, size_t newlen,
1463 struct ctl_table_root *root,
1464 struct ctl_table *table)
1470 if (get_user(n, name))
1472 for ( ; table->ctl_name || table->procname; table++) {
1473 if (!table->ctl_name)
1475 if (n == table->ctl_name) {
1478 if (sysctl_perm(root, table, 001))
1482 table = table->child;
1485 error = do_sysctl_strategy(root, table, name, nlen,
1494 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1495 void __user *newval, size_t newlen)
1497 struct ctl_table_header *head;
1498 int error = -ENOTDIR;
1500 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1504 if (!oldlenp || get_user(old_len, oldlenp))
1508 for (head = sysctl_head_next(NULL); head;
1509 head = sysctl_head_next(head)) {
1510 error = parse_table(name, nlen, oldval, oldlenp,
1512 head->root, head->ctl_table);
1513 if (error != -ENOTDIR) {
1514 sysctl_head_finish(head);
1521 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1523 struct __sysctl_args tmp;
1526 if (copy_from_user(&tmp, args, sizeof(tmp)))
1529 error = deprecated_sysctl_warning(&tmp);
1534 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1535 tmp.newval, tmp.newlen);
1540 #endif /* CONFIG_SYSCTL_SYSCALL */
1543 * sysctl_perm does NOT grant the superuser all rights automatically, because
1544 * some sysctl variables are readonly even to root.
1547 static int test_perm(int mode, int op)
1551 else if (in_egroup_p(0))
1553 if ((mode & op & 0007) == op)
1558 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1563 error = security_sysctl(table, op);
1567 if (root->permissions)
1568 mode = root->permissions(root, current->nsproxy, table);
1572 return test_perm(mode, op);
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)
1586 sysctl_set_parent(NULL, root_table);
1587 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1590 err = sysctl_check_table(current->nsproxy, root_table);
1596 core_initcall(sysctl_init);
1599 * __register_sysctl_paths - register a sysctl hierarchy
1600 * @root: List of sysctl headers to register on
1601 * @namespaces: Data to compute which lists of sysctl entries are visible
1602 * @path: The path to the directory the sysctl table is in.
1603 * @table: the top-level table structure
1605 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1606 * array. A completely 0 filled entry terminates the table.
1608 * The members of the &struct ctl_table structure are used as follows:
1610 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1611 * must be unique within that level of sysctl
1613 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1614 * enter a sysctl file
1616 * data - a pointer to data for use by proc_handler
1618 * maxlen - the maximum size in bytes of the data
1620 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1622 * child - a pointer to the child sysctl table if this entry is a directory, or
1625 * proc_handler - the text handler routine (described below)
1627 * strategy - the strategy routine (described below)
1629 * de - for internal use by the sysctl routines
1631 * extra1, extra2 - extra pointers usable by the proc handler routines
1633 * Leaf nodes in the sysctl tree will be represented by a single file
1634 * under /proc; non-leaf nodes will be represented by directories.
1636 * sysctl(2) can automatically manage read and write requests through
1637 * the sysctl table. The data and maxlen fields of the ctl_table
1638 * struct enable minimal validation of the values being written to be
1639 * performed, and the mode field allows minimal authentication.
1641 * More sophisticated management can be enabled by the provision of a
1642 * strategy routine with the table entry. This will be called before
1643 * any automatic read or write of the data is performed.
1645 * The strategy routine may return
1647 * < 0 - Error occurred (error is passed to user process)
1649 * 0 - OK - proceed with automatic read or write.
1651 * > 0 - OK - read or write has been done by the strategy routine, so
1652 * return immediately.
1654 * There must be a proc_handler routine for any terminal nodes
1655 * mirrored under /proc/sys (non-terminals are handled by a built-in
1656 * directory handler). Several default handlers are available to
1657 * cover common cases -
1659 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1660 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1661 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1663 * It is the handler's job to read the input buffer from user memory
1664 * and process it. The handler should return 0 on success.
1666 * This routine returns %NULL on a failure to register, and a pointer
1667 * to the table header on success.
1669 struct ctl_table_header *__register_sysctl_paths(
1670 struct ctl_table_root *root,
1671 struct nsproxy *namespaces,
1672 const struct ctl_path *path, struct ctl_table *table)
1674 struct list_head *header_list;
1675 struct ctl_table_header *header;
1676 struct ctl_table *new, **prevp;
1677 unsigned int n, npath;
1679 /* Count the path components */
1680 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1684 * For each path component, allocate a 2-element ctl_table array.
1685 * The first array element will be filled with the sysctl entry
1686 * for this, the second will be the sentinel (ctl_name == 0).
1688 * We allocate everything in one go so that we don't have to
1689 * worry about freeing additional memory in unregister_sysctl_table.
1691 header = kzalloc(sizeof(struct ctl_table_header) +
1692 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1696 new = (struct ctl_table *) (header + 1);
1698 /* Now connect the dots */
1699 prevp = &header->ctl_table;
1700 for (n = 0; n < npath; ++n, ++path) {
1701 /* Copy the procname */
1702 new->procname = path->procname;
1703 new->ctl_name = path->ctl_name;
1707 prevp = &new->child;
1712 header->ctl_table_arg = table;
1714 INIT_LIST_HEAD(&header->ctl_entry);
1716 header->unregistering = NULL;
1717 header->root = root;
1718 sysctl_set_parent(NULL, header->ctl_table);
1719 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1720 if (sysctl_check_table(namespaces, header->ctl_table)) {
1725 spin_lock(&sysctl_lock);
1726 header_list = lookup_header_list(root, namespaces);
1727 list_add_tail(&header->ctl_entry, header_list);
1728 spin_unlock(&sysctl_lock);
1734 * register_sysctl_table_path - register a sysctl table hierarchy
1735 * @path: The path to the directory the sysctl table is in.
1736 * @table: the top-level table structure
1738 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1739 * array. A completely 0 filled entry terminates the table.
1741 * See __register_sysctl_paths for more details.
1743 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1744 struct ctl_table *table)
1746 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1751 * register_sysctl_table - register a sysctl table hierarchy
1752 * @table: the top-level table structure
1754 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1755 * array. A completely 0 filled entry terminates the table.
1757 * See register_sysctl_paths for more details.
1759 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1761 static const struct ctl_path null_path[] = { {} };
1763 return register_sysctl_paths(null_path, table);
1767 * unregister_sysctl_table - unregister a sysctl table hierarchy
1768 * @header: the header returned from register_sysctl_table
1770 * Unregisters the sysctl table and all children. proc entries may not
1771 * actually be removed until they are no longer used by anyone.
1773 void unregister_sysctl_table(struct ctl_table_header * header)
1780 spin_lock(&sysctl_lock);
1781 start_unregistering(header);
1782 spin_unlock(&sysctl_lock);
1786 #else /* !CONFIG_SYSCTL */
1787 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1792 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1793 struct ctl_table *table)
1798 void unregister_sysctl_table(struct ctl_table_header * table)
1802 #endif /* CONFIG_SYSCTL */
1808 #ifdef CONFIG_PROC_SYSCTL
1810 static int _proc_do_string(void* data, int maxlen, int write,
1811 struct file *filp, void __user *buffer,
1812 size_t *lenp, loff_t *ppos)
1818 if (!data || !maxlen || !*lenp) {
1826 while (len < *lenp) {
1827 if (get_user(c, p++))
1829 if (c == 0 || c == '\n')
1835 if(copy_from_user(data, buffer, len))
1837 ((char *) data)[len] = 0;
1855 if(copy_to_user(buffer, data, len))
1858 if(put_user('\n', ((char __user *) buffer) + len))
1869 * proc_dostring - read a string sysctl
1870 * @table: the sysctl table
1871 * @write: %TRUE if this is a write to the sysctl file
1872 * @filp: the file structure
1873 * @buffer: the user buffer
1874 * @lenp: the size of the user buffer
1875 * @ppos: file position
1877 * Reads/writes a string from/to the user buffer. If the kernel
1878 * buffer provided is not large enough to hold the string, the
1879 * string is truncated. The copied string is %NULL-terminated.
1880 * If the string is being read by the user process, it is copied
1881 * and a newline '\n' is added. It is truncated if the buffer is
1884 * Returns 0 on success.
1886 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
1887 void __user *buffer, size_t *lenp, loff_t *ppos)
1889 return _proc_do_string(table->data, table->maxlen, write, filp,
1890 buffer, lenp, ppos);
1894 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1896 int write, void *data)
1899 *valp = *negp ? -*lvalp : *lvalp;
1904 *lvalp = (unsigned long)-val;
1907 *lvalp = (unsigned long)val;
1913 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1914 int write, struct file *filp, void __user *buffer,
1915 size_t *lenp, loff_t *ppos,
1916 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1917 int write, void *data),
1920 #define TMPBUFLEN 21
1921 int *i, vleft, first=1, neg, val;
1925 char buf[TMPBUFLEN], *p;
1926 char __user *s = buffer;
1928 if (!tbl_data || !table->maxlen || !*lenp ||
1929 (*ppos && !write)) {
1934 i = (int *) tbl_data;
1935 vleft = table->maxlen / sizeof(*i);
1939 conv = do_proc_dointvec_conv;
1941 for (; left && vleft--; i++, first=0) {
1956 if (len > sizeof(buf) - 1)
1957 len = sizeof(buf) - 1;
1958 if (copy_from_user(buf, s, len))
1962 if (*p == '-' && left > 1) {
1966 if (*p < '0' || *p > '9')
1969 lval = simple_strtoul(p, &p, 0);
1972 if ((len < left) && *p && !isspace(*p))
1979 if (conv(&neg, &lval, i, 1, data))
1986 if (conv(&neg, &lval, i, 0, data))
1989 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1993 if(copy_to_user(s, buf, len))
2000 if (!write && !first && left) {
2001 if(put_user('\n', s))
2008 if (get_user(c, s++))
2023 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2024 void __user *buffer, size_t *lenp, loff_t *ppos,
2025 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2026 int write, void *data),
2029 return __do_proc_dointvec(table->data, table, write, filp,
2030 buffer, lenp, ppos, conv, data);
2034 * proc_dointvec - read a vector of integers
2035 * @table: the sysctl table
2036 * @write: %TRUE if this is a write to the sysctl file
2037 * @filp: the file structure
2038 * @buffer: the user buffer
2039 * @lenp: the size of the user buffer
2040 * @ppos: file position
2042 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2043 * values from/to the user buffer, treated as an ASCII string.
2045 * Returns 0 on success.
2047 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2048 void __user *buffer, size_t *lenp, loff_t *ppos)
2050 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2058 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2060 int write, void *data)
2062 int op = *(int *)data;
2064 int val = *negp ? -*lvalp : *lvalp;
2066 case OP_SET: *valp = val; break;
2067 case OP_AND: *valp &= val; break;
2068 case OP_OR: *valp |= val; break;
2074 *lvalp = (unsigned long)-val;
2077 *lvalp = (unsigned long)val;
2084 * Taint values can only be increased
2086 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
2087 void __user *buffer, size_t *lenp, loff_t *ppos)
2091 if (write && !capable(CAP_SYS_ADMIN))
2095 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2096 do_proc_dointvec_bset_conv,&op);
2099 struct do_proc_dointvec_minmax_conv_param {
2104 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2106 int write, void *data)
2108 struct do_proc_dointvec_minmax_conv_param *param = data;
2110 int val = *negp ? -*lvalp : *lvalp;
2111 if ((param->min && *param->min > val) ||
2112 (param->max && *param->max < val))
2119 *lvalp = (unsigned long)-val;
2122 *lvalp = (unsigned long)val;
2129 * proc_dointvec_minmax - read a vector of integers with min/max values
2130 * @table: the sysctl table
2131 * @write: %TRUE if this is a write to the sysctl file
2132 * @filp: the file structure
2133 * @buffer: the user buffer
2134 * @lenp: the size of the user buffer
2135 * @ppos: file position
2137 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2138 * values from/to the user buffer, treated as an ASCII string.
2140 * This routine will ensure the values are within the range specified by
2141 * table->extra1 (min) and table->extra2 (max).
2143 * Returns 0 on success.
2145 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2146 void __user *buffer, size_t *lenp, loff_t *ppos)
2148 struct do_proc_dointvec_minmax_conv_param param = {
2149 .min = (int *) table->extra1,
2150 .max = (int *) table->extra2,
2152 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2153 do_proc_dointvec_minmax_conv, ¶m);
2156 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2158 void __user *buffer,
2159 size_t *lenp, loff_t *ppos,
2160 unsigned long convmul,
2161 unsigned long convdiv)
2163 #define TMPBUFLEN 21
2164 unsigned long *i, *min, *max, val;
2165 int vleft, first=1, neg;
2167 char buf[TMPBUFLEN], *p;
2168 char __user *s = buffer;
2170 if (!data || !table->maxlen || !*lenp ||
2171 (*ppos && !write)) {
2176 i = (unsigned long *) data;
2177 min = (unsigned long *) table->extra1;
2178 max = (unsigned long *) table->extra2;
2179 vleft = table->maxlen / sizeof(unsigned long);
2182 for (; left && vleft--; i++, min++, max++, first=0) {
2197 if (len > TMPBUFLEN-1)
2199 if (copy_from_user(buf, s, len))
2203 if (*p == '-' && left > 1) {
2207 if (*p < '0' || *p > '9')
2209 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2211 if ((len < left) && *p && !isspace(*p))
2220 if ((min && val < *min) || (max && val > *max))
2227 sprintf(p, "%lu", convdiv * (*i) / convmul);
2231 if(copy_to_user(s, buf, len))
2238 if (!write && !first && left) {
2239 if(put_user('\n', s))
2246 if (get_user(c, s++))
2261 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2263 void __user *buffer,
2264 size_t *lenp, loff_t *ppos,
2265 unsigned long convmul,
2266 unsigned long convdiv)
2268 return __do_proc_doulongvec_minmax(table->data, table, write,
2269 filp, buffer, lenp, ppos, convmul, convdiv);
2273 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2274 * @table: the sysctl table
2275 * @write: %TRUE if this is a write to the sysctl file
2276 * @filp: the file structure
2277 * @buffer: the user buffer
2278 * @lenp: the size of the user buffer
2279 * @ppos: file position
2281 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2282 * values from/to the user buffer, treated as an ASCII string.
2284 * This routine will ensure the values are within the range specified by
2285 * table->extra1 (min) and table->extra2 (max).
2287 * Returns 0 on success.
2289 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2290 void __user *buffer, size_t *lenp, loff_t *ppos)
2292 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2296 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2297 * @table: the sysctl table
2298 * @write: %TRUE if this is a write to the sysctl file
2299 * @filp: the file structure
2300 * @buffer: the user buffer
2301 * @lenp: the size of the user buffer
2302 * @ppos: file position
2304 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2305 * values from/to the user buffer, treated as an ASCII string. The values
2306 * are treated as milliseconds, and converted to jiffies when they are stored.
2308 * This routine will ensure the values are within the range specified by
2309 * table->extra1 (min) and table->extra2 (max).
2311 * Returns 0 on success.
2313 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2315 void __user *buffer,
2316 size_t *lenp, loff_t *ppos)
2318 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2319 lenp, ppos, HZ, 1000l);
2323 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2325 int write, void *data)
2328 if (*lvalp > LONG_MAX / HZ)
2330 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2336 lval = (unsigned long)-val;
2339 lval = (unsigned long)val;
2346 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2348 int write, void *data)
2351 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2353 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2359 lval = (unsigned long)-val;
2362 lval = (unsigned long)val;
2364 *lvalp = jiffies_to_clock_t(lval);
2369 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2371 int write, void *data)
2374 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2380 lval = (unsigned long)-val;
2383 lval = (unsigned long)val;
2385 *lvalp = jiffies_to_msecs(lval);
2391 * proc_dointvec_jiffies - read a vector of integers as seconds
2392 * @table: the sysctl table
2393 * @write: %TRUE if this is a write to the sysctl file
2394 * @filp: the file structure
2395 * @buffer: the user buffer
2396 * @lenp: the size of the user buffer
2397 * @ppos: file position
2399 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2400 * values from/to the user buffer, treated as an ASCII string.
2401 * The values read are assumed to be in seconds, and are converted into
2404 * Returns 0 on success.
2406 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2407 void __user *buffer, size_t *lenp, loff_t *ppos)
2409 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2410 do_proc_dointvec_jiffies_conv,NULL);
2414 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2415 * @table: the sysctl table
2416 * @write: %TRUE if this is a write to the sysctl file
2417 * @filp: the file structure
2418 * @buffer: the user buffer
2419 * @lenp: the size of the user buffer
2420 * @ppos: pointer to the file position
2422 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2423 * values from/to the user buffer, treated as an ASCII string.
2424 * The values read are assumed to be in 1/USER_HZ seconds, and
2425 * are converted into jiffies.
2427 * Returns 0 on success.
2429 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2430 void __user *buffer, size_t *lenp, loff_t *ppos)
2432 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2433 do_proc_dointvec_userhz_jiffies_conv,NULL);
2437 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2438 * @table: the sysctl table
2439 * @write: %TRUE if this is a write to the sysctl file
2440 * @filp: the file structure
2441 * @buffer: the user buffer
2442 * @lenp: the size of the user buffer
2443 * @ppos: file position
2444 * @ppos: the current position in the file
2446 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2447 * values from/to the user buffer, treated as an ASCII string.
2448 * The values read are assumed to be in 1/1000 seconds, and
2449 * are converted into jiffies.
2451 * Returns 0 on success.
2453 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2454 void __user *buffer, size_t *lenp, loff_t *ppos)
2456 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2457 do_proc_dointvec_ms_jiffies_conv, NULL);
2460 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2461 void __user *buffer, size_t *lenp, loff_t *ppos)
2463 struct pid *new_pid;
2467 tmp = pid_vnr(cad_pid);
2469 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2470 lenp, ppos, NULL, NULL);
2474 new_pid = find_get_pid(tmp);
2478 put_pid(xchg(&cad_pid, new_pid));
2482 #else /* CONFIG_PROC_FS */
2484 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2485 void __user *buffer, size_t *lenp, loff_t *ppos)
2490 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2491 void __user *buffer, size_t *lenp, loff_t *ppos)
2496 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2497 void __user *buffer, size_t *lenp, loff_t *ppos)
2502 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2503 void __user *buffer, size_t *lenp, loff_t *ppos)
2508 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2509 void __user *buffer, size_t *lenp, loff_t *ppos)
2514 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2515 void __user *buffer, size_t *lenp, loff_t *ppos)
2520 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2521 void __user *buffer, size_t *lenp, loff_t *ppos)
2526 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2528 void __user *buffer,
2529 size_t *lenp, loff_t *ppos)
2535 #endif /* CONFIG_PROC_FS */
2538 #ifdef CONFIG_SYSCTL_SYSCALL
2540 * General sysctl support routines
2543 /* The generic sysctl data routine (used if no strategy routine supplied) */
2544 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2545 void __user *oldval, size_t __user *oldlenp,
2546 void __user *newval, size_t newlen)
2550 /* Get out of I don't have a variable */
2551 if (!table->data || !table->maxlen)
2554 if (oldval && oldlenp) {
2555 if (get_user(len, oldlenp))
2558 if (len > table->maxlen)
2559 len = table->maxlen;
2560 if (copy_to_user(oldval, table->data, len))
2562 if (put_user(len, oldlenp))
2567 if (newval && newlen) {
2568 if (newlen > table->maxlen)
2569 newlen = table->maxlen;
2571 if (copy_from_user(table->data, newval, newlen))
2577 /* The generic string strategy routine: */
2578 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2579 void __user *oldval, size_t __user *oldlenp,
2580 void __user *newval, size_t newlen)
2582 if (!table->data || !table->maxlen)
2585 if (oldval && oldlenp) {
2587 if (get_user(bufsize, oldlenp))
2590 size_t len = strlen(table->data), copied;
2592 /* This shouldn't trigger for a well-formed sysctl */
2593 if (len > table->maxlen)
2594 len = table->maxlen;
2596 /* Copy up to a max of bufsize-1 bytes of the string */
2597 copied = (len >= bufsize) ? bufsize - 1 : len;
2599 if (copy_to_user(oldval, table->data, copied) ||
2600 put_user(0, (char __user *)(oldval + copied)))
2602 if (put_user(len, oldlenp))
2606 if (newval && newlen) {
2607 size_t len = newlen;
2608 if (len > table->maxlen)
2609 len = table->maxlen;
2610 if(copy_from_user(table->data, newval, len))
2612 if (len == table->maxlen)
2614 ((char *) table->data)[len] = 0;
2620 * This function makes sure that all of the integers in the vector
2621 * are between the minimum and maximum values given in the arrays
2622 * table->extra1 and table->extra2, respectively.
2624 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2625 void __user *oldval, size_t __user *oldlenp,
2626 void __user *newval, size_t newlen)
2629 if (newval && newlen) {
2630 int __user *vec = (int __user *) newval;
2631 int *min = (int *) table->extra1;
2632 int *max = (int *) table->extra2;
2636 if (newlen % sizeof(int) != 0)
2639 if (!table->extra1 && !table->extra2)
2642 if (newlen > table->maxlen)
2643 newlen = table->maxlen;
2644 length = newlen / sizeof(int);
2646 for (i = 0; i < length; i++) {
2648 if (get_user(value, vec + i))
2650 if (min && value < min[i])
2652 if (max && value > max[i])
2659 /* Strategy function to convert jiffies to seconds */
2660 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2661 void __user *oldval, size_t __user *oldlenp,
2662 void __user *newval, size_t newlen)
2664 if (oldval && oldlenp) {
2667 if (get_user(olen, oldlenp))
2672 if (olen < sizeof(int))
2675 val = *(int *)(table->data) / HZ;
2676 if (put_user(val, (int __user *)oldval))
2678 if (put_user(sizeof(int), oldlenp))
2682 if (newval && newlen) {
2684 if (newlen != sizeof(int))
2686 if (get_user(new, (int __user *)newval))
2688 *(int *)(table->data) = new*HZ;
2693 /* Strategy function to convert jiffies to seconds */
2694 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2695 void __user *oldval, size_t __user *oldlenp,
2696 void __user *newval, size_t newlen)
2698 if (oldval && oldlenp) {
2701 if (get_user(olen, oldlenp))
2706 if (olen < sizeof(int))
2709 val = jiffies_to_msecs(*(int *)(table->data));
2710 if (put_user(val, (int __user *)oldval))
2712 if (put_user(sizeof(int), oldlenp))
2716 if (newval && newlen) {
2718 if (newlen != sizeof(int))
2720 if (get_user(new, (int __user *)newval))
2722 *(int *)(table->data) = msecs_to_jiffies(new);
2729 #else /* CONFIG_SYSCTL_SYSCALL */
2732 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2734 struct __sysctl_args tmp;
2737 if (copy_from_user(&tmp, args, sizeof(tmp)))
2740 error = deprecated_sysctl_warning(&tmp);
2742 /* If no error reading the parameters then just -ENOSYS ... */
2749 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2750 void __user *oldval, size_t __user *oldlenp,
2751 void __user *newval, size_t newlen)
2756 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2757 void __user *oldval, size_t __user *oldlenp,
2758 void __user *newval, size_t newlen)
2763 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2764 void __user *oldval, size_t __user *oldlenp,
2765 void __user *newval, size_t newlen)
2770 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2771 void __user *oldval, size_t __user *oldlenp,
2772 void __user *newval, size_t newlen)
2777 int sysctl_ms_jiffies(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 #endif /* CONFIG_SYSCTL_SYSCALL */
2786 static int deprecated_sysctl_warning(struct __sysctl_args *args)
2788 static int msg_count;
2789 int name[CTL_MAXNAME];
2792 /* Check args->nlen. */
2793 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2796 /* Read in the sysctl name for better debug message logging */
2797 for (i = 0; i < args->nlen; i++)
2798 if (get_user(name[i], args->name + i))
2801 /* Ignore accesses to kernel.version */
2802 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2805 if (msg_count < 5) {
2808 "warning: process `%s' used the deprecated sysctl "
2809 "system call with ", current->comm);
2810 for (i = 0; i < args->nlen; i++)
2811 printk("%d.", name[i]);
2818 * No sense putting this after each symbol definition, twice,
2819 * exception granted :-)
2821 EXPORT_SYMBOL(proc_dointvec);
2822 EXPORT_SYMBOL(proc_dointvec_jiffies);
2823 EXPORT_SYMBOL(proc_dointvec_minmax);
2824 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2825 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2826 EXPORT_SYMBOL(proc_dostring);
2827 EXPORT_SYMBOL(proc_doulongvec_minmax);
2828 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2829 EXPORT_SYMBOL(register_sysctl_table);
2830 EXPORT_SYMBOL(register_sysctl_paths);
2831 EXPORT_SYMBOL(sysctl_intvec);
2832 EXPORT_SYMBOL(sysctl_jiffies);
2833 EXPORT_SYMBOL(sysctl_ms_jiffies);
2834 EXPORT_SYMBOL(sysctl_string);
2835 EXPORT_SYMBOL(sysctl_data);
2836 EXPORT_SYMBOL(unregister_sysctl_table);