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/security.h>
41 #include <linux/initrd.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>
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 max_threads;
70 extern int core_uses_pid;
71 extern int suid_dumpable;
72 extern char core_pattern[];
74 extern int min_free_kbytes;
75 extern int printk_ratelimit_jiffies;
76 extern int printk_ratelimit_burst;
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 audit_argv_kb;
85 /* Constants used for minimum and maximum */
86 #ifdef CONFIG_DETECT_SOFTLOCKUP
88 static int sixty = 60;
96 static int one_hundred = 100;
98 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
99 static int maxolduid = 65535;
100 static int minolduid;
101 static int min_percpu_pagelist_fract = 8;
103 static int ngroups_max = NGROUPS_MAX;
106 extern char modprobe_path[];
108 #ifdef CONFIG_CHR_DEV_SG
109 extern int sg_big_buff;
113 extern char reboot_command [];
114 extern int stop_a_enabled;
115 extern int scons_pwroff;
119 extern int pwrsw_enabled;
120 extern int unaligned_enabled;
124 #ifdef CONFIG_MATHEMU
125 extern int sysctl_ieee_emulation_warnings;
127 extern int sysctl_userprocess_debug;
128 extern int spin_retry;
131 extern int sysctl_hz_timer;
133 #ifdef CONFIG_BSD_PROCESS_ACCT
134 extern int acct_parm[];
138 extern int no_unaligned_warning;
141 #ifdef CONFIG_RT_MUTEXES
142 extern int max_lock_depth;
145 #ifdef CONFIG_SYSCTL_SYSCALL
146 static int parse_table(int __user *, int, void __user *, size_t __user *,
147 void __user *, size_t, struct ctl_table *);
151 #ifdef CONFIG_PROC_SYSCTL
152 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
153 void __user *buffer, size_t *lenp, loff_t *ppos);
154 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
155 void __user *buffer, size_t *lenp, loff_t *ppos);
158 static struct ctl_table root_table[];
159 static struct ctl_table_header root_table_header =
160 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
162 static struct ctl_table kern_table[];
163 static struct ctl_table vm_table[];
164 static struct ctl_table fs_table[];
165 static struct ctl_table debug_table[];
166 static struct ctl_table dev_table[];
167 extern struct ctl_table random_table[];
168 #ifdef CONFIG_INOTIFY_USER
169 extern struct ctl_table inotify_table[];
172 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
173 int sysctl_legacy_va_layout;
176 extern int prove_locking;
177 extern int lock_stat;
179 /* The default sysctl tables: */
181 static struct ctl_table root_table[] = {
183 .ctl_name = CTL_KERN,
184 .procname = "kernel",
209 .ctl_name = CTL_DEBUG,
212 .child = debug_table,
221 * NOTE: do not add new entries to this table unless you have read
222 * Documentation/sysctl/ctl_unnumbered.txt
227 #ifdef CONFIG_SCHED_DEBUG
228 static unsigned long min_sched_granularity_ns = 100000; /* 100 usecs */
229 static unsigned long max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
230 static unsigned long min_wakeup_granularity_ns; /* 0 usecs */
231 static unsigned long max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
234 static struct ctl_table kern_table[] = {
235 #ifdef CONFIG_SCHED_DEBUG
237 .ctl_name = CTL_UNNUMBERED,
238 .procname = "sched_min_granularity_ns",
239 .data = &sysctl_sched_min_granularity,
240 .maxlen = sizeof(unsigned int),
242 .proc_handler = &sched_nr_latency_handler,
243 .strategy = &sysctl_intvec,
244 .extra1 = &min_sched_granularity_ns,
245 .extra2 = &max_sched_granularity_ns,
248 .ctl_name = CTL_UNNUMBERED,
249 .procname = "sched_latency_ns",
250 .data = &sysctl_sched_latency,
251 .maxlen = sizeof(unsigned int),
253 .proc_handler = &sched_nr_latency_handler,
254 .strategy = &sysctl_intvec,
255 .extra1 = &min_sched_granularity_ns,
256 .extra2 = &max_sched_granularity_ns,
259 .ctl_name = CTL_UNNUMBERED,
260 .procname = "sched_wakeup_granularity_ns",
261 .data = &sysctl_sched_wakeup_granularity,
262 .maxlen = sizeof(unsigned int),
264 .proc_handler = &proc_dointvec_minmax,
265 .strategy = &sysctl_intvec,
266 .extra1 = &min_wakeup_granularity_ns,
267 .extra2 = &max_wakeup_granularity_ns,
270 .ctl_name = CTL_UNNUMBERED,
271 .procname = "sched_batch_wakeup_granularity_ns",
272 .data = &sysctl_sched_batch_wakeup_granularity,
273 .maxlen = sizeof(unsigned int),
275 .proc_handler = &proc_dointvec_minmax,
276 .strategy = &sysctl_intvec,
277 .extra1 = &min_wakeup_granularity_ns,
278 .extra2 = &max_wakeup_granularity_ns,
281 .ctl_name = CTL_UNNUMBERED,
282 .procname = "sched_child_runs_first",
283 .data = &sysctl_sched_child_runs_first,
284 .maxlen = sizeof(unsigned int),
286 .proc_handler = &proc_dointvec,
289 .ctl_name = CTL_UNNUMBERED,
290 .procname = "sched_features",
291 .data = &sysctl_sched_features,
292 .maxlen = sizeof(unsigned int),
294 .proc_handler = &proc_dointvec,
297 .ctl_name = CTL_UNNUMBERED,
298 .procname = "sched_migration_cost",
299 .data = &sysctl_sched_migration_cost,
300 .maxlen = sizeof(unsigned int),
302 .proc_handler = &proc_dointvec,
306 .ctl_name = CTL_UNNUMBERED,
307 .procname = "sched_compat_yield",
308 .data = &sysctl_sched_compat_yield,
309 .maxlen = sizeof(unsigned int),
311 .proc_handler = &proc_dointvec,
313 #ifdef CONFIG_PROVE_LOCKING
315 .ctl_name = CTL_UNNUMBERED,
316 .procname = "prove_locking",
317 .data = &prove_locking,
318 .maxlen = sizeof(int),
320 .proc_handler = &proc_dointvec,
323 #ifdef CONFIG_LOCK_STAT
325 .ctl_name = CTL_UNNUMBERED,
326 .procname = "lock_stat",
328 .maxlen = sizeof(int),
330 .proc_handler = &proc_dointvec,
334 .ctl_name = KERN_PANIC,
336 .data = &panic_timeout,
337 .maxlen = sizeof(int),
339 .proc_handler = &proc_dointvec,
342 .ctl_name = KERN_CORE_USES_PID,
343 .procname = "core_uses_pid",
344 .data = &core_uses_pid,
345 .maxlen = sizeof(int),
347 .proc_handler = &proc_dointvec,
349 #ifdef CONFIG_AUDITSYSCALL
351 .ctl_name = CTL_UNNUMBERED,
352 .procname = "audit_argv_kb",
353 .data = &audit_argv_kb,
354 .maxlen = sizeof(int),
356 .proc_handler = &proc_dointvec,
360 .ctl_name = KERN_CORE_PATTERN,
361 .procname = "core_pattern",
362 .data = core_pattern,
363 .maxlen = CORENAME_MAX_SIZE,
365 .proc_handler = &proc_dostring,
366 .strategy = &sysctl_string,
368 #ifdef CONFIG_PROC_SYSCTL
370 .procname = "tainted",
372 .maxlen = sizeof(int),
374 .proc_handler = &proc_dointvec_taint,
377 #ifdef CONFIG_SECURITY_CAPABILITIES
379 .procname = "cap-bound",
381 .maxlen = sizeof(kernel_cap_t),
383 .proc_handler = &proc_dointvec_bset,
385 #endif /* def CONFIG_SECURITY_CAPABILITIES */
386 #ifdef CONFIG_BLK_DEV_INITRD
388 .ctl_name = KERN_REALROOTDEV,
389 .procname = "real-root-dev",
390 .data = &real_root_dev,
391 .maxlen = sizeof(int),
393 .proc_handler = &proc_dointvec,
397 .ctl_name = CTL_UNNUMBERED,
398 .procname = "print-fatal-signals",
399 .data = &print_fatal_signals,
400 .maxlen = sizeof(int),
402 .proc_handler = &proc_dointvec,
406 .ctl_name = KERN_SPARC_REBOOT,
407 .procname = "reboot-cmd",
408 .data = reboot_command,
411 .proc_handler = &proc_dostring,
412 .strategy = &sysctl_string,
415 .ctl_name = KERN_SPARC_STOP_A,
416 .procname = "stop-a",
417 .data = &stop_a_enabled,
418 .maxlen = sizeof (int),
420 .proc_handler = &proc_dointvec,
423 .ctl_name = KERN_SPARC_SCONS_PWROFF,
424 .procname = "scons-poweroff",
425 .data = &scons_pwroff,
426 .maxlen = sizeof (int),
428 .proc_handler = &proc_dointvec,
433 .ctl_name = KERN_HPPA_PWRSW,
434 .procname = "soft-power",
435 .data = &pwrsw_enabled,
436 .maxlen = sizeof (int),
438 .proc_handler = &proc_dointvec,
441 .ctl_name = KERN_HPPA_UNALIGNED,
442 .procname = "unaligned-trap",
443 .data = &unaligned_enabled,
444 .maxlen = sizeof (int),
446 .proc_handler = &proc_dointvec,
450 .ctl_name = KERN_CTLALTDEL,
451 .procname = "ctrl-alt-del",
453 .maxlen = sizeof(int),
455 .proc_handler = &proc_dointvec,
458 .ctl_name = KERN_PRINTK,
459 .procname = "printk",
460 .data = &console_loglevel,
461 .maxlen = 4*sizeof(int),
463 .proc_handler = &proc_dointvec,
467 .ctl_name = KERN_MODPROBE,
468 .procname = "modprobe",
469 .data = &modprobe_path,
470 .maxlen = KMOD_PATH_LEN,
472 .proc_handler = &proc_dostring,
473 .strategy = &sysctl_string,
476 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
478 .ctl_name = KERN_HOTPLUG,
479 .procname = "hotplug",
480 .data = &uevent_helper,
481 .maxlen = UEVENT_HELPER_PATH_LEN,
483 .proc_handler = &proc_dostring,
484 .strategy = &sysctl_string,
487 #ifdef CONFIG_CHR_DEV_SG
489 .ctl_name = KERN_SG_BIG_BUFF,
490 .procname = "sg-big-buff",
491 .data = &sg_big_buff,
492 .maxlen = sizeof (int),
494 .proc_handler = &proc_dointvec,
497 #ifdef CONFIG_BSD_PROCESS_ACCT
499 .ctl_name = KERN_ACCT,
502 .maxlen = 3*sizeof(int),
504 .proc_handler = &proc_dointvec,
507 #ifdef CONFIG_MAGIC_SYSRQ
509 .ctl_name = KERN_SYSRQ,
511 .data = &__sysrq_enabled,
512 .maxlen = sizeof (int),
514 .proc_handler = &proc_dointvec,
517 #ifdef CONFIG_PROC_SYSCTL
519 .procname = "cad_pid",
521 .maxlen = sizeof (int),
523 .proc_handler = &proc_do_cad_pid,
527 .ctl_name = KERN_MAX_THREADS,
528 .procname = "threads-max",
529 .data = &max_threads,
530 .maxlen = sizeof(int),
532 .proc_handler = &proc_dointvec,
535 .ctl_name = KERN_RANDOM,
536 .procname = "random",
538 .child = random_table,
541 .ctl_name = KERN_OVERFLOWUID,
542 .procname = "overflowuid",
543 .data = &overflowuid,
544 .maxlen = sizeof(int),
546 .proc_handler = &proc_dointvec_minmax,
547 .strategy = &sysctl_intvec,
548 .extra1 = &minolduid,
549 .extra2 = &maxolduid,
552 .ctl_name = KERN_OVERFLOWGID,
553 .procname = "overflowgid",
554 .data = &overflowgid,
555 .maxlen = sizeof(int),
557 .proc_handler = &proc_dointvec_minmax,
558 .strategy = &sysctl_intvec,
559 .extra1 = &minolduid,
560 .extra2 = &maxolduid,
563 #ifdef CONFIG_MATHEMU
565 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
566 .procname = "ieee_emulation_warnings",
567 .data = &sysctl_ieee_emulation_warnings,
568 .maxlen = sizeof(int),
570 .proc_handler = &proc_dointvec,
573 #ifdef CONFIG_NO_IDLE_HZ
575 .ctl_name = KERN_HZ_TIMER,
576 .procname = "hz_timer",
577 .data = &sysctl_hz_timer,
578 .maxlen = sizeof(int),
580 .proc_handler = &proc_dointvec,
584 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
585 .procname = "userprocess_debug",
586 .data = &sysctl_userprocess_debug,
587 .maxlen = sizeof(int),
589 .proc_handler = &proc_dointvec,
593 .ctl_name = KERN_PIDMAX,
594 .procname = "pid_max",
596 .maxlen = sizeof (int),
598 .proc_handler = &proc_dointvec_minmax,
599 .strategy = sysctl_intvec,
600 .extra1 = &pid_max_min,
601 .extra2 = &pid_max_max,
604 .ctl_name = KERN_PANIC_ON_OOPS,
605 .procname = "panic_on_oops",
606 .data = &panic_on_oops,
607 .maxlen = sizeof(int),
609 .proc_handler = &proc_dointvec,
612 .ctl_name = KERN_PRINTK_RATELIMIT,
613 .procname = "printk_ratelimit",
614 .data = &printk_ratelimit_jiffies,
615 .maxlen = sizeof(int),
617 .proc_handler = &proc_dointvec_jiffies,
618 .strategy = &sysctl_jiffies,
621 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
622 .procname = "printk_ratelimit_burst",
623 .data = &printk_ratelimit_burst,
624 .maxlen = sizeof(int),
626 .proc_handler = &proc_dointvec,
629 .ctl_name = KERN_NGROUPS_MAX,
630 .procname = "ngroups_max",
631 .data = &ngroups_max,
632 .maxlen = sizeof (int),
634 .proc_handler = &proc_dointvec,
636 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
638 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
639 .procname = "unknown_nmi_panic",
640 .data = &unknown_nmi_panic,
641 .maxlen = sizeof (int),
643 .proc_handler = &proc_dointvec,
646 .procname = "nmi_watchdog",
647 .data = &nmi_watchdog_enabled,
648 .maxlen = sizeof (int),
650 .proc_handler = &proc_nmi_enabled,
653 #if defined(CONFIG_X86)
655 .ctl_name = KERN_PANIC_ON_NMI,
656 .procname = "panic_on_unrecovered_nmi",
657 .data = &panic_on_unrecovered_nmi,
658 .maxlen = sizeof(int),
660 .proc_handler = &proc_dointvec,
663 .ctl_name = KERN_BOOTLOADER_TYPE,
664 .procname = "bootloader_type",
665 .data = &bootloader_type,
666 .maxlen = sizeof (int),
668 .proc_handler = &proc_dointvec,
671 .ctl_name = CTL_UNNUMBERED,
672 .procname = "kstack_depth_to_print",
673 .data = &kstack_depth_to_print,
674 .maxlen = sizeof(int),
676 .proc_handler = &proc_dointvec,
679 #if defined(CONFIG_MMU)
681 .ctl_name = KERN_RANDOMIZE,
682 .procname = "randomize_va_space",
683 .data = &randomize_va_space,
684 .maxlen = sizeof(int),
686 .proc_handler = &proc_dointvec,
689 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
691 .ctl_name = KERN_SPIN_RETRY,
692 .procname = "spin_retry",
694 .maxlen = sizeof (int),
696 .proc_handler = &proc_dointvec,
699 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
701 .procname = "acpi_video_flags",
702 .data = &acpi_realmode_flags,
703 .maxlen = sizeof (unsigned long),
705 .proc_handler = &proc_doulongvec_minmax,
710 .ctl_name = KERN_IA64_UNALIGNED,
711 .procname = "ignore-unaligned-usertrap",
712 .data = &no_unaligned_warning,
713 .maxlen = sizeof (int),
715 .proc_handler = &proc_dointvec,
718 #ifdef CONFIG_DETECT_SOFTLOCKUP
720 .ctl_name = CTL_UNNUMBERED,
721 .procname = "softlockup_thresh",
722 .data = &softlockup_thresh,
723 .maxlen = sizeof(int),
725 .proc_handler = &proc_dointvec_minmax,
726 .strategy = &sysctl_intvec,
733 .ctl_name = KERN_COMPAT_LOG,
734 .procname = "compat-log",
736 .maxlen = sizeof (int),
738 .proc_handler = &proc_dointvec,
741 #ifdef CONFIG_RT_MUTEXES
743 .ctl_name = KERN_MAX_LOCK_DEPTH,
744 .procname = "max_lock_depth",
745 .data = &max_lock_depth,
746 .maxlen = sizeof(int),
748 .proc_handler = &proc_dointvec,
751 #ifdef CONFIG_PROC_FS
753 .ctl_name = CTL_UNNUMBERED,
754 .procname = "maps_protect",
755 .data = &maps_protect,
756 .maxlen = sizeof(int),
758 .proc_handler = &proc_dointvec,
762 .ctl_name = CTL_UNNUMBERED,
763 .procname = "poweroff_cmd",
764 .data = &poweroff_cmd,
765 .maxlen = POWEROFF_CMD_PATH_LEN,
767 .proc_handler = &proc_dostring,
768 .strategy = &sysctl_string,
771 * NOTE: do not add new entries to this table unless you have read
772 * Documentation/sysctl/ctl_unnumbered.txt
777 static struct ctl_table vm_table[] = {
779 .ctl_name = VM_OVERCOMMIT_MEMORY,
780 .procname = "overcommit_memory",
781 .data = &sysctl_overcommit_memory,
782 .maxlen = sizeof(sysctl_overcommit_memory),
784 .proc_handler = &proc_dointvec,
787 .ctl_name = VM_PANIC_ON_OOM,
788 .procname = "panic_on_oom",
789 .data = &sysctl_panic_on_oom,
790 .maxlen = sizeof(sysctl_panic_on_oom),
792 .proc_handler = &proc_dointvec,
795 .ctl_name = CTL_UNNUMBERED,
796 .procname = "oom_kill_allocating_task",
797 .data = &sysctl_oom_kill_allocating_task,
798 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
800 .proc_handler = &proc_dointvec,
803 .ctl_name = VM_OVERCOMMIT_RATIO,
804 .procname = "overcommit_ratio",
805 .data = &sysctl_overcommit_ratio,
806 .maxlen = sizeof(sysctl_overcommit_ratio),
808 .proc_handler = &proc_dointvec,
811 .ctl_name = VM_PAGE_CLUSTER,
812 .procname = "page-cluster",
813 .data = &page_cluster,
814 .maxlen = sizeof(int),
816 .proc_handler = &proc_dointvec,
819 .ctl_name = VM_DIRTY_BACKGROUND,
820 .procname = "dirty_background_ratio",
821 .data = &dirty_background_ratio,
822 .maxlen = sizeof(dirty_background_ratio),
824 .proc_handler = &proc_dointvec_minmax,
825 .strategy = &sysctl_intvec,
827 .extra2 = &one_hundred,
830 .ctl_name = VM_DIRTY_RATIO,
831 .procname = "dirty_ratio",
832 .data = &vm_dirty_ratio,
833 .maxlen = sizeof(vm_dirty_ratio),
835 .proc_handler = &dirty_ratio_handler,
836 .strategy = &sysctl_intvec,
838 .extra2 = &one_hundred,
841 .procname = "dirty_writeback_centisecs",
842 .data = &dirty_writeback_interval,
843 .maxlen = sizeof(dirty_writeback_interval),
845 .proc_handler = &dirty_writeback_centisecs_handler,
848 .procname = "dirty_expire_centisecs",
849 .data = &dirty_expire_interval,
850 .maxlen = sizeof(dirty_expire_interval),
852 .proc_handler = &proc_dointvec_userhz_jiffies,
855 .ctl_name = VM_NR_PDFLUSH_THREADS,
856 .procname = "nr_pdflush_threads",
857 .data = &nr_pdflush_threads,
858 .maxlen = sizeof nr_pdflush_threads,
859 .mode = 0444 /* read-only*/,
860 .proc_handler = &proc_dointvec,
863 .ctl_name = VM_SWAPPINESS,
864 .procname = "swappiness",
865 .data = &vm_swappiness,
866 .maxlen = sizeof(vm_swappiness),
868 .proc_handler = &proc_dointvec_minmax,
869 .strategy = &sysctl_intvec,
871 .extra2 = &one_hundred,
873 #ifdef CONFIG_HUGETLB_PAGE
875 .procname = "nr_hugepages",
876 .data = &max_huge_pages,
877 .maxlen = sizeof(unsigned long),
879 .proc_handler = &hugetlb_sysctl_handler,
880 .extra1 = (void *)&hugetlb_zero,
881 .extra2 = (void *)&hugetlb_infinity,
884 .ctl_name = VM_HUGETLB_GROUP,
885 .procname = "hugetlb_shm_group",
886 .data = &sysctl_hugetlb_shm_group,
887 .maxlen = sizeof(gid_t),
889 .proc_handler = &proc_dointvec,
892 .ctl_name = CTL_UNNUMBERED,
893 .procname = "hugepages_treat_as_movable",
894 .data = &hugepages_treat_as_movable,
895 .maxlen = sizeof(int),
897 .proc_handler = &hugetlb_treat_movable_handler,
900 .ctl_name = CTL_UNNUMBERED,
901 .procname = "hugetlb_dynamic_pool",
902 .data = &hugetlb_dynamic_pool,
903 .maxlen = sizeof(hugetlb_dynamic_pool),
905 .proc_handler = &proc_dointvec,
909 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
910 .procname = "lowmem_reserve_ratio",
911 .data = &sysctl_lowmem_reserve_ratio,
912 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
914 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
915 .strategy = &sysctl_intvec,
918 .ctl_name = VM_DROP_PAGECACHE,
919 .procname = "drop_caches",
920 .data = &sysctl_drop_caches,
921 .maxlen = sizeof(int),
923 .proc_handler = drop_caches_sysctl_handler,
924 .strategy = &sysctl_intvec,
927 .ctl_name = VM_MIN_FREE_KBYTES,
928 .procname = "min_free_kbytes",
929 .data = &min_free_kbytes,
930 .maxlen = sizeof(min_free_kbytes),
932 .proc_handler = &min_free_kbytes_sysctl_handler,
933 .strategy = &sysctl_intvec,
937 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
938 .procname = "percpu_pagelist_fraction",
939 .data = &percpu_pagelist_fraction,
940 .maxlen = sizeof(percpu_pagelist_fraction),
942 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
943 .strategy = &sysctl_intvec,
944 .extra1 = &min_percpu_pagelist_fract,
948 .ctl_name = VM_MAX_MAP_COUNT,
949 .procname = "max_map_count",
950 .data = &sysctl_max_map_count,
951 .maxlen = sizeof(sysctl_max_map_count),
953 .proc_handler = &proc_dointvec
957 .ctl_name = VM_LAPTOP_MODE,
958 .procname = "laptop_mode",
959 .data = &laptop_mode,
960 .maxlen = sizeof(laptop_mode),
962 .proc_handler = &proc_dointvec_jiffies,
963 .strategy = &sysctl_jiffies,
966 .ctl_name = VM_BLOCK_DUMP,
967 .procname = "block_dump",
969 .maxlen = sizeof(block_dump),
971 .proc_handler = &proc_dointvec,
972 .strategy = &sysctl_intvec,
976 .ctl_name = VM_VFS_CACHE_PRESSURE,
977 .procname = "vfs_cache_pressure",
978 .data = &sysctl_vfs_cache_pressure,
979 .maxlen = sizeof(sysctl_vfs_cache_pressure),
981 .proc_handler = &proc_dointvec,
982 .strategy = &sysctl_intvec,
985 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
987 .ctl_name = VM_LEGACY_VA_LAYOUT,
988 .procname = "legacy_va_layout",
989 .data = &sysctl_legacy_va_layout,
990 .maxlen = sizeof(sysctl_legacy_va_layout),
992 .proc_handler = &proc_dointvec,
993 .strategy = &sysctl_intvec,
999 .ctl_name = VM_ZONE_RECLAIM_MODE,
1000 .procname = "zone_reclaim_mode",
1001 .data = &zone_reclaim_mode,
1002 .maxlen = sizeof(zone_reclaim_mode),
1004 .proc_handler = &proc_dointvec,
1005 .strategy = &sysctl_intvec,
1009 .ctl_name = VM_MIN_UNMAPPED,
1010 .procname = "min_unmapped_ratio",
1011 .data = &sysctl_min_unmapped_ratio,
1012 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1014 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1015 .strategy = &sysctl_intvec,
1017 .extra2 = &one_hundred,
1020 .ctl_name = VM_MIN_SLAB,
1021 .procname = "min_slab_ratio",
1022 .data = &sysctl_min_slab_ratio,
1023 .maxlen = sizeof(sysctl_min_slab_ratio),
1025 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1026 .strategy = &sysctl_intvec,
1028 .extra2 = &one_hundred,
1033 .ctl_name = CTL_UNNUMBERED,
1034 .procname = "stat_interval",
1035 .data = &sysctl_stat_interval,
1036 .maxlen = sizeof(sysctl_stat_interval),
1038 .proc_handler = &proc_dointvec_jiffies,
1039 .strategy = &sysctl_jiffies,
1042 #ifdef CONFIG_SECURITY
1044 .ctl_name = CTL_UNNUMBERED,
1045 .procname = "mmap_min_addr",
1046 .data = &mmap_min_addr,
1047 .maxlen = sizeof(unsigned long),
1049 .proc_handler = &proc_doulongvec_minmax,
1054 .ctl_name = CTL_UNNUMBERED,
1055 .procname = "numa_zonelist_order",
1056 .data = &numa_zonelist_order,
1057 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1059 .proc_handler = &numa_zonelist_order_handler,
1060 .strategy = &sysctl_string,
1063 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1064 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1066 .ctl_name = VM_VDSO_ENABLED,
1067 .procname = "vdso_enabled",
1068 .data = &vdso_enabled,
1069 .maxlen = sizeof(vdso_enabled),
1071 .proc_handler = &proc_dointvec,
1072 .strategy = &sysctl_intvec,
1077 * NOTE: do not add new entries to this table unless you have read
1078 * Documentation/sysctl/ctl_unnumbered.txt
1083 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1084 static struct ctl_table binfmt_misc_table[] = {
1089 static struct ctl_table fs_table[] = {
1091 .ctl_name = FS_NRINODE,
1092 .procname = "inode-nr",
1093 .data = &inodes_stat,
1094 .maxlen = 2*sizeof(int),
1096 .proc_handler = &proc_dointvec,
1099 .ctl_name = FS_STATINODE,
1100 .procname = "inode-state",
1101 .data = &inodes_stat,
1102 .maxlen = 7*sizeof(int),
1104 .proc_handler = &proc_dointvec,
1107 .procname = "file-nr",
1108 .data = &files_stat,
1109 .maxlen = 3*sizeof(int),
1111 .proc_handler = &proc_nr_files,
1114 .ctl_name = FS_MAXFILE,
1115 .procname = "file-max",
1116 .data = &files_stat.max_files,
1117 .maxlen = sizeof(int),
1119 .proc_handler = &proc_dointvec,
1122 .ctl_name = FS_DENTRY,
1123 .procname = "dentry-state",
1124 .data = &dentry_stat,
1125 .maxlen = 6*sizeof(int),
1127 .proc_handler = &proc_dointvec,
1130 .ctl_name = FS_OVERFLOWUID,
1131 .procname = "overflowuid",
1132 .data = &fs_overflowuid,
1133 .maxlen = sizeof(int),
1135 .proc_handler = &proc_dointvec_minmax,
1136 .strategy = &sysctl_intvec,
1137 .extra1 = &minolduid,
1138 .extra2 = &maxolduid,
1141 .ctl_name = FS_OVERFLOWGID,
1142 .procname = "overflowgid",
1143 .data = &fs_overflowgid,
1144 .maxlen = sizeof(int),
1146 .proc_handler = &proc_dointvec_minmax,
1147 .strategy = &sysctl_intvec,
1148 .extra1 = &minolduid,
1149 .extra2 = &maxolduid,
1152 .ctl_name = FS_LEASES,
1153 .procname = "leases-enable",
1154 .data = &leases_enable,
1155 .maxlen = sizeof(int),
1157 .proc_handler = &proc_dointvec,
1159 #ifdef CONFIG_DNOTIFY
1161 .ctl_name = FS_DIR_NOTIFY,
1162 .procname = "dir-notify-enable",
1163 .data = &dir_notify_enable,
1164 .maxlen = sizeof(int),
1166 .proc_handler = &proc_dointvec,
1171 .ctl_name = FS_LEASE_TIME,
1172 .procname = "lease-break-time",
1173 .data = &lease_break_time,
1174 .maxlen = sizeof(int),
1176 .proc_handler = &proc_dointvec_minmax,
1177 .strategy = &sysctl_intvec,
1182 .procname = "aio-nr",
1184 .maxlen = sizeof(aio_nr),
1186 .proc_handler = &proc_doulongvec_minmax,
1189 .procname = "aio-max-nr",
1190 .data = &aio_max_nr,
1191 .maxlen = sizeof(aio_max_nr),
1193 .proc_handler = &proc_doulongvec_minmax,
1195 #ifdef CONFIG_INOTIFY_USER
1197 .ctl_name = FS_INOTIFY,
1198 .procname = "inotify",
1200 .child = inotify_table,
1205 .ctl_name = KERN_SETUID_DUMPABLE,
1206 .procname = "suid_dumpable",
1207 .data = &suid_dumpable,
1208 .maxlen = sizeof(int),
1210 .proc_handler = &proc_dointvec,
1212 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1214 .ctl_name = CTL_UNNUMBERED,
1215 .procname = "binfmt_misc",
1217 .child = binfmt_misc_table,
1221 * NOTE: do not add new entries to this table unless you have read
1222 * Documentation/sysctl/ctl_unnumbered.txt
1227 static struct ctl_table debug_table[] = {
1228 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1230 .ctl_name = CTL_UNNUMBERED,
1231 .procname = "exception-trace",
1232 .data = &show_unhandled_signals,
1233 .maxlen = sizeof(int),
1235 .proc_handler = proc_dointvec
1241 static struct ctl_table dev_table[] = {
1245 static DEFINE_SPINLOCK(sysctl_lock);
1247 /* called under sysctl_lock */
1248 static int use_table(struct ctl_table_header *p)
1250 if (unlikely(p->unregistering))
1256 /* called under sysctl_lock */
1257 static void unuse_table(struct ctl_table_header *p)
1260 if (unlikely(p->unregistering))
1261 complete(p->unregistering);
1264 /* called under sysctl_lock, will reacquire if has to wait */
1265 static void start_unregistering(struct ctl_table_header *p)
1268 * if p->used is 0, nobody will ever touch that entry again;
1269 * we'll eliminate all paths to it before dropping sysctl_lock
1271 if (unlikely(p->used)) {
1272 struct completion wait;
1273 init_completion(&wait);
1274 p->unregistering = &wait;
1275 spin_unlock(&sysctl_lock);
1276 wait_for_completion(&wait);
1277 spin_lock(&sysctl_lock);
1280 * do not remove from the list until nobody holds it; walking the
1281 * list in do_sysctl() relies on that.
1283 list_del_init(&p->ctl_entry);
1286 void sysctl_head_finish(struct ctl_table_header *head)
1290 spin_lock(&sysctl_lock);
1292 spin_unlock(&sysctl_lock);
1295 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1297 struct ctl_table_header *head;
1298 struct list_head *tmp;
1299 spin_lock(&sysctl_lock);
1301 tmp = &prev->ctl_entry;
1305 tmp = &root_table_header.ctl_entry;
1307 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1309 if (!use_table(head))
1311 spin_unlock(&sysctl_lock);
1315 if (tmp == &root_table_header.ctl_entry)
1318 spin_unlock(&sysctl_lock);
1322 #ifdef CONFIG_SYSCTL_SYSCALL
1323 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1324 void __user *newval, size_t newlen)
1326 struct ctl_table_header *head;
1327 int error = -ENOTDIR;
1329 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1333 if (!oldlenp || get_user(old_len, oldlenp))
1337 for (head = sysctl_head_next(NULL); head;
1338 head = sysctl_head_next(head)) {
1339 error = parse_table(name, nlen, oldval, oldlenp,
1340 newval, newlen, head->ctl_table);
1341 if (error != -ENOTDIR) {
1342 sysctl_head_finish(head);
1349 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1351 struct __sysctl_args tmp;
1354 if (copy_from_user(&tmp, args, sizeof(tmp)))
1357 error = deprecated_sysctl_warning(&tmp);
1362 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1363 tmp.newval, tmp.newlen);
1368 #endif /* CONFIG_SYSCTL_SYSCALL */
1371 * sysctl_perm does NOT grant the superuser all rights automatically, because
1372 * some sysctl variables are readonly even to root.
1375 static int test_perm(int mode, int op)
1379 else if (in_egroup_p(0))
1381 if ((mode & op & 0007) == op)
1386 int sysctl_perm(struct ctl_table *table, int op)
1389 error = security_sysctl(table, op);
1392 return test_perm(table->mode, op);
1395 #ifdef CONFIG_SYSCTL_SYSCALL
1396 static int parse_table(int __user *name, int nlen,
1397 void __user *oldval, size_t __user *oldlenp,
1398 void __user *newval, size_t newlen,
1399 struct ctl_table *table)
1405 if (get_user(n, name))
1407 for ( ; table->ctl_name || table->procname; table++) {
1408 if (!table->ctl_name)
1410 if (n == table->ctl_name) {
1413 if (sysctl_perm(table, 001))
1417 table = table->child;
1420 error = do_sysctl_strategy(table, name, nlen,
1429 /* Perform the actual read/write of a sysctl table entry. */
1430 int do_sysctl_strategy (struct ctl_table *table,
1431 int __user *name, int nlen,
1432 void __user *oldval, size_t __user *oldlenp,
1433 void __user *newval, size_t newlen)
1441 if (sysctl_perm(table, op))
1444 if (table->strategy) {
1445 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1453 /* If there is no strategy routine, or if the strategy returns
1454 * zero, proceed with automatic r/w */
1455 if (table->data && table->maxlen) {
1456 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1463 #endif /* CONFIG_SYSCTL_SYSCALL */
1465 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1467 for (; table->ctl_name || table->procname; table++) {
1468 table->parent = parent;
1470 sysctl_set_parent(table, table->child);
1474 static __init int sysctl_init(void)
1477 sysctl_set_parent(NULL, root_table);
1478 err = sysctl_check_table(root_table);
1482 core_initcall(sysctl_init);
1485 * register_sysctl_table - register a sysctl hierarchy
1486 * @table: the top-level table structure
1488 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1489 * array. An entry with a ctl_name of 0 terminates the table.
1491 * The members of the &struct ctl_table structure are used as follows:
1493 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1494 * must be unique within that level of sysctl
1496 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1497 * enter a sysctl file
1499 * data - a pointer to data for use by proc_handler
1501 * maxlen - the maximum size in bytes of the data
1503 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1505 * child - a pointer to the child sysctl table if this entry is a directory, or
1508 * proc_handler - the text handler routine (described below)
1510 * strategy - the strategy routine (described below)
1512 * de - for internal use by the sysctl routines
1514 * extra1, extra2 - extra pointers usable by the proc handler routines
1516 * Leaf nodes in the sysctl tree will be represented by a single file
1517 * under /proc; non-leaf nodes will be represented by directories.
1519 * sysctl(2) can automatically manage read and write requests through
1520 * the sysctl table. The data and maxlen fields of the ctl_table
1521 * struct enable minimal validation of the values being written to be
1522 * performed, and the mode field allows minimal authentication.
1524 * More sophisticated management can be enabled by the provision of a
1525 * strategy routine with the table entry. This will be called before
1526 * any automatic read or write of the data is performed.
1528 * The strategy routine may return
1530 * < 0 - Error occurred (error is passed to user process)
1532 * 0 - OK - proceed with automatic read or write.
1534 * > 0 - OK - read or write has been done by the strategy routine, so
1535 * return immediately.
1537 * There must be a proc_handler routine for any terminal nodes
1538 * mirrored under /proc/sys (non-terminals are handled by a built-in
1539 * directory handler). Several default handlers are available to
1540 * cover common cases -
1542 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1543 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1544 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1546 * It is the handler's job to read the input buffer from user memory
1547 * and process it. The handler should return 0 on success.
1549 * This routine returns %NULL on a failure to register, and a pointer
1550 * to the table header on success.
1552 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1554 struct ctl_table_header *tmp;
1555 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1558 tmp->ctl_table = table;
1559 INIT_LIST_HEAD(&tmp->ctl_entry);
1561 tmp->unregistering = NULL;
1562 sysctl_set_parent(NULL, table);
1563 if (sysctl_check_table(tmp->ctl_table)) {
1567 spin_lock(&sysctl_lock);
1568 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1569 spin_unlock(&sysctl_lock);
1574 * unregister_sysctl_table - unregister a sysctl table hierarchy
1575 * @header: the header returned from register_sysctl_table
1577 * Unregisters the sysctl table and all children. proc entries may not
1578 * actually be removed until they are no longer used by anyone.
1580 void unregister_sysctl_table(struct ctl_table_header * header)
1583 spin_lock(&sysctl_lock);
1584 start_unregistering(header);
1585 spin_unlock(&sysctl_lock);
1589 #else /* !CONFIG_SYSCTL */
1590 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1595 void unregister_sysctl_table(struct ctl_table_header * table)
1599 #endif /* CONFIG_SYSCTL */
1605 #ifdef CONFIG_PROC_SYSCTL
1607 static int _proc_do_string(void* data, int maxlen, int write,
1608 struct file *filp, void __user *buffer,
1609 size_t *lenp, loff_t *ppos)
1615 if (!data || !maxlen || !*lenp) {
1623 while (len < *lenp) {
1624 if (get_user(c, p++))
1626 if (c == 0 || c == '\n')
1632 if(copy_from_user(data, buffer, len))
1634 ((char *) data)[len] = 0;
1652 if(copy_to_user(buffer, data, len))
1655 if(put_user('\n', ((char __user *) buffer) + len))
1666 * proc_dostring - read a string sysctl
1667 * @table: the sysctl table
1668 * @write: %TRUE if this is a write to the sysctl file
1669 * @filp: the file structure
1670 * @buffer: the user buffer
1671 * @lenp: the size of the user buffer
1672 * @ppos: file position
1674 * Reads/writes a string from/to the user buffer. If the kernel
1675 * buffer provided is not large enough to hold the string, the
1676 * string is truncated. The copied string is %NULL-terminated.
1677 * If the string is being read by the user process, it is copied
1678 * and a newline '\n' is added. It is truncated if the buffer is
1681 * Returns 0 on success.
1683 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
1684 void __user *buffer, size_t *lenp, loff_t *ppos)
1686 return _proc_do_string(table->data, table->maxlen, write, filp,
1687 buffer, lenp, ppos);
1691 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1693 int write, void *data)
1696 *valp = *negp ? -*lvalp : *lvalp;
1701 *lvalp = (unsigned long)-val;
1704 *lvalp = (unsigned long)val;
1710 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1711 int write, struct file *filp, void __user *buffer,
1712 size_t *lenp, loff_t *ppos,
1713 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1714 int write, void *data),
1717 #define TMPBUFLEN 21
1718 int *i, vleft, first=1, neg, val;
1722 char buf[TMPBUFLEN], *p;
1723 char __user *s = buffer;
1725 if (!tbl_data || !table->maxlen || !*lenp ||
1726 (*ppos && !write)) {
1731 i = (int *) tbl_data;
1732 vleft = table->maxlen / sizeof(*i);
1736 conv = do_proc_dointvec_conv;
1738 for (; left && vleft--; i++, first=0) {
1753 if (len > sizeof(buf) - 1)
1754 len = sizeof(buf) - 1;
1755 if (copy_from_user(buf, s, len))
1759 if (*p == '-' && left > 1) {
1763 if (*p < '0' || *p > '9')
1766 lval = simple_strtoul(p, &p, 0);
1769 if ((len < left) && *p && !isspace(*p))
1776 if (conv(&neg, &lval, i, 1, data))
1783 if (conv(&neg, &lval, i, 0, data))
1786 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1790 if(copy_to_user(s, buf, len))
1797 if (!write && !first && left) {
1798 if(put_user('\n', s))
1805 if (get_user(c, s++))
1820 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
1821 void __user *buffer, size_t *lenp, loff_t *ppos,
1822 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1823 int write, void *data),
1826 return __do_proc_dointvec(table->data, table, write, filp,
1827 buffer, lenp, ppos, conv, data);
1831 * proc_dointvec - read a vector of integers
1832 * @table: the sysctl table
1833 * @write: %TRUE if this is a write to the sysctl file
1834 * @filp: the file structure
1835 * @buffer: the user buffer
1836 * @lenp: the size of the user buffer
1837 * @ppos: file position
1839 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1840 * values from/to the user buffer, treated as an ASCII string.
1842 * Returns 0 on success.
1844 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
1845 void __user *buffer, size_t *lenp, loff_t *ppos)
1847 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1855 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1857 int write, void *data)
1859 int op = *(int *)data;
1861 int val = *negp ? -*lvalp : *lvalp;
1863 case OP_SET: *valp = val; break;
1864 case OP_AND: *valp &= val; break;
1865 case OP_OR: *valp |= val; break;
1871 *lvalp = (unsigned long)-val;
1874 *lvalp = (unsigned long)val;
1880 #ifdef CONFIG_SECURITY_CAPABILITIES
1882 * init may raise the set.
1885 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
1886 void __user *buffer, size_t *lenp, loff_t *ppos)
1890 if (write && !capable(CAP_SYS_MODULE)) {
1894 op = is_global_init(current) ? OP_SET : OP_AND;
1895 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1896 do_proc_dointvec_bset_conv,&op);
1898 #endif /* def CONFIG_SECURITY_CAPABILITIES */
1901 * Taint values can only be increased
1903 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
1904 void __user *buffer, size_t *lenp, loff_t *ppos)
1908 if (write && !capable(CAP_SYS_ADMIN))
1912 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1913 do_proc_dointvec_bset_conv,&op);
1916 struct do_proc_dointvec_minmax_conv_param {
1921 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1923 int write, void *data)
1925 struct do_proc_dointvec_minmax_conv_param *param = data;
1927 int val = *negp ? -*lvalp : *lvalp;
1928 if ((param->min && *param->min > val) ||
1929 (param->max && *param->max < val))
1936 *lvalp = (unsigned long)-val;
1939 *lvalp = (unsigned long)val;
1946 * proc_dointvec_minmax - read a vector of integers with min/max values
1947 * @table: the sysctl table
1948 * @write: %TRUE if this is a write to the sysctl file
1949 * @filp: the file structure
1950 * @buffer: the user buffer
1951 * @lenp: the size of the user buffer
1952 * @ppos: file position
1954 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1955 * values from/to the user buffer, treated as an ASCII string.
1957 * This routine will ensure the values are within the range specified by
1958 * table->extra1 (min) and table->extra2 (max).
1960 * Returns 0 on success.
1962 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
1963 void __user *buffer, size_t *lenp, loff_t *ppos)
1965 struct do_proc_dointvec_minmax_conv_param param = {
1966 .min = (int *) table->extra1,
1967 .max = (int *) table->extra2,
1969 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1970 do_proc_dointvec_minmax_conv, ¶m);
1973 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
1975 void __user *buffer,
1976 size_t *lenp, loff_t *ppos,
1977 unsigned long convmul,
1978 unsigned long convdiv)
1980 #define TMPBUFLEN 21
1981 unsigned long *i, *min, *max, val;
1982 int vleft, first=1, neg;
1984 char buf[TMPBUFLEN], *p;
1985 char __user *s = buffer;
1987 if (!data || !table->maxlen || !*lenp ||
1988 (*ppos && !write)) {
1993 i = (unsigned long *) data;
1994 min = (unsigned long *) table->extra1;
1995 max = (unsigned long *) table->extra2;
1996 vleft = table->maxlen / sizeof(unsigned long);
1999 for (; left && vleft--; i++, min++, max++, first=0) {
2014 if (len > TMPBUFLEN-1)
2016 if (copy_from_user(buf, s, len))
2020 if (*p == '-' && left > 1) {
2024 if (*p < '0' || *p > '9')
2026 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2028 if ((len < left) && *p && !isspace(*p))
2037 if ((min && val < *min) || (max && val > *max))
2044 sprintf(p, "%lu", convdiv * (*i) / convmul);
2048 if(copy_to_user(s, buf, len))
2055 if (!write && !first && left) {
2056 if(put_user('\n', s))
2063 if (get_user(c, s++))
2078 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2080 void __user *buffer,
2081 size_t *lenp, loff_t *ppos,
2082 unsigned long convmul,
2083 unsigned long convdiv)
2085 return __do_proc_doulongvec_minmax(table->data, table, write,
2086 filp, buffer, lenp, ppos, convmul, convdiv);
2090 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2091 * @table: the sysctl table
2092 * @write: %TRUE if this is a write to the sysctl file
2093 * @filp: the file structure
2094 * @buffer: the user buffer
2095 * @lenp: the size of the user buffer
2096 * @ppos: file position
2098 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2099 * values from/to the user buffer, treated as an ASCII string.
2101 * This routine will ensure the values are within the range specified by
2102 * table->extra1 (min) and table->extra2 (max).
2104 * Returns 0 on success.
2106 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2107 void __user *buffer, size_t *lenp, loff_t *ppos)
2109 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2113 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2114 * @table: the sysctl table
2115 * @write: %TRUE if this is a write to the sysctl file
2116 * @filp: the file structure
2117 * @buffer: the user buffer
2118 * @lenp: the size of the user buffer
2119 * @ppos: file position
2121 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2122 * values from/to the user buffer, treated as an ASCII string. The values
2123 * are treated as milliseconds, and converted to jiffies when they are stored.
2125 * This routine will ensure the values are within the range specified by
2126 * table->extra1 (min) and table->extra2 (max).
2128 * Returns 0 on success.
2130 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2132 void __user *buffer,
2133 size_t *lenp, loff_t *ppos)
2135 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2136 lenp, ppos, HZ, 1000l);
2140 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2142 int write, void *data)
2145 if (*lvalp > LONG_MAX / HZ)
2147 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2153 lval = (unsigned long)-val;
2156 lval = (unsigned long)val;
2163 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2165 int write, void *data)
2168 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2170 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2176 lval = (unsigned long)-val;
2179 lval = (unsigned long)val;
2181 *lvalp = jiffies_to_clock_t(lval);
2186 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2188 int write, void *data)
2191 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2197 lval = (unsigned long)-val;
2200 lval = (unsigned long)val;
2202 *lvalp = jiffies_to_msecs(lval);
2208 * proc_dointvec_jiffies - read a vector of integers as seconds
2209 * @table: the sysctl table
2210 * @write: %TRUE if this is a write to the sysctl file
2211 * @filp: the file structure
2212 * @buffer: the user buffer
2213 * @lenp: the size of the user buffer
2214 * @ppos: file position
2216 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2217 * values from/to the user buffer, treated as an ASCII string.
2218 * The values read are assumed to be in seconds, and are converted into
2221 * Returns 0 on success.
2223 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2224 void __user *buffer, size_t *lenp, loff_t *ppos)
2226 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2227 do_proc_dointvec_jiffies_conv,NULL);
2231 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2232 * @table: the sysctl table
2233 * @write: %TRUE if this is a write to the sysctl file
2234 * @filp: the file structure
2235 * @buffer: the user buffer
2236 * @lenp: the size of the user buffer
2237 * @ppos: pointer to the file position
2239 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2240 * values from/to the user buffer, treated as an ASCII string.
2241 * The values read are assumed to be in 1/USER_HZ seconds, and
2242 * are converted into jiffies.
2244 * Returns 0 on success.
2246 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2247 void __user *buffer, size_t *lenp, loff_t *ppos)
2249 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2250 do_proc_dointvec_userhz_jiffies_conv,NULL);
2254 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2255 * @table: the sysctl table
2256 * @write: %TRUE if this is a write to the sysctl file
2257 * @filp: the file structure
2258 * @buffer: the user buffer
2259 * @lenp: the size of the user buffer
2260 * @ppos: file position
2261 * @ppos: the current position in the file
2263 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2264 * values from/to the user buffer, treated as an ASCII string.
2265 * The values read are assumed to be in 1/1000 seconds, and
2266 * are converted into jiffies.
2268 * Returns 0 on success.
2270 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2271 void __user *buffer, size_t *lenp, loff_t *ppos)
2273 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2274 do_proc_dointvec_ms_jiffies_conv, NULL);
2277 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2278 void __user *buffer, size_t *lenp, loff_t *ppos)
2280 struct pid *new_pid;
2284 tmp = pid_nr_ns(cad_pid, current->nsproxy->pid_ns);
2286 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2287 lenp, ppos, NULL, NULL);
2291 new_pid = find_get_pid(tmp);
2295 put_pid(xchg(&cad_pid, new_pid));
2299 #else /* CONFIG_PROC_FS */
2301 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2302 void __user *buffer, size_t *lenp, loff_t *ppos)
2307 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2308 void __user *buffer, size_t *lenp, loff_t *ppos)
2313 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
2314 void __user *buffer, size_t *lenp, loff_t *ppos)
2319 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2320 void __user *buffer, size_t *lenp, loff_t *ppos)
2325 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2326 void __user *buffer, size_t *lenp, loff_t *ppos)
2331 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2332 void __user *buffer, size_t *lenp, loff_t *ppos)
2337 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2338 void __user *buffer, size_t *lenp, loff_t *ppos)
2343 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2344 void __user *buffer, size_t *lenp, loff_t *ppos)
2349 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2351 void __user *buffer,
2352 size_t *lenp, loff_t *ppos)
2358 #endif /* CONFIG_PROC_FS */
2361 #ifdef CONFIG_SYSCTL_SYSCALL
2363 * General sysctl support routines
2366 /* The generic sysctl data routine (used if no strategy routine supplied) */
2367 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2368 void __user *oldval, size_t __user *oldlenp,
2369 void __user *newval, size_t newlen)
2373 /* Get out of I don't have a variable */
2374 if (!table->data || !table->maxlen)
2377 if (oldval && oldlenp) {
2378 if (get_user(len, oldlenp))
2381 if (len > table->maxlen)
2382 len = table->maxlen;
2383 if (copy_to_user(oldval, table->data, len))
2385 if (put_user(len, oldlenp))
2390 if (newval && newlen) {
2391 if (newlen > table->maxlen)
2392 newlen = table->maxlen;
2394 if (copy_from_user(table->data, newval, newlen))
2400 /* The generic string strategy routine: */
2401 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2402 void __user *oldval, size_t __user *oldlenp,
2403 void __user *newval, size_t newlen)
2405 if (!table->data || !table->maxlen)
2408 if (oldval && oldlenp) {
2410 if (get_user(bufsize, oldlenp))
2413 size_t len = strlen(table->data), copied;
2415 /* This shouldn't trigger for a well-formed sysctl */
2416 if (len > table->maxlen)
2417 len = table->maxlen;
2419 /* Copy up to a max of bufsize-1 bytes of the string */
2420 copied = (len >= bufsize) ? bufsize - 1 : len;
2422 if (copy_to_user(oldval, table->data, copied) ||
2423 put_user(0, (char __user *)(oldval + copied)))
2425 if (put_user(len, oldlenp))
2429 if (newval && newlen) {
2430 size_t len = newlen;
2431 if (len > table->maxlen)
2432 len = table->maxlen;
2433 if(copy_from_user(table->data, newval, len))
2435 if (len == table->maxlen)
2437 ((char *) table->data)[len] = 0;
2443 * This function makes sure that all of the integers in the vector
2444 * are between the minimum and maximum values given in the arrays
2445 * table->extra1 and table->extra2, respectively.
2447 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2448 void __user *oldval, size_t __user *oldlenp,
2449 void __user *newval, size_t newlen)
2452 if (newval && newlen) {
2453 int __user *vec = (int __user *) newval;
2454 int *min = (int *) table->extra1;
2455 int *max = (int *) table->extra2;
2459 if (newlen % sizeof(int) != 0)
2462 if (!table->extra1 && !table->extra2)
2465 if (newlen > table->maxlen)
2466 newlen = table->maxlen;
2467 length = newlen / sizeof(int);
2469 for (i = 0; i < length; i++) {
2471 if (get_user(value, vec + i))
2473 if (min && value < min[i])
2475 if (max && value > max[i])
2482 /* Strategy function to convert jiffies to seconds */
2483 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2484 void __user *oldval, size_t __user *oldlenp,
2485 void __user *newval, size_t newlen)
2487 if (oldval && oldlenp) {
2490 if (get_user(olen, oldlenp))
2495 if (olen < sizeof(int))
2498 val = *(int *)(table->data) / HZ;
2499 if (put_user(val, (int __user *)oldval))
2501 if (put_user(sizeof(int), oldlenp))
2505 if (newval && newlen) {
2507 if (newlen != sizeof(int))
2509 if (get_user(new, (int __user *)newval))
2511 *(int *)(table->data) = new*HZ;
2516 /* Strategy function to convert jiffies to seconds */
2517 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2518 void __user *oldval, size_t __user *oldlenp,
2519 void __user *newval, size_t newlen)
2521 if (oldval && oldlenp) {
2524 if (get_user(olen, oldlenp))
2529 if (olen < sizeof(int))
2532 val = jiffies_to_msecs(*(int *)(table->data));
2533 if (put_user(val, (int __user *)oldval))
2535 if (put_user(sizeof(int), oldlenp))
2539 if (newval && newlen) {
2541 if (newlen != sizeof(int))
2543 if (get_user(new, (int __user *)newval))
2545 *(int *)(table->data) = msecs_to_jiffies(new);
2552 #else /* CONFIG_SYSCTL_SYSCALL */
2555 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2557 struct __sysctl_args tmp;
2560 if (copy_from_user(&tmp, args, sizeof(tmp)))
2563 error = deprecated_sysctl_warning(&tmp);
2565 /* If no error reading the parameters then just -ENOSYS ... */
2572 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2573 void __user *oldval, size_t __user *oldlenp,
2574 void __user *newval, size_t newlen)
2579 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2580 void __user *oldval, size_t __user *oldlenp,
2581 void __user *newval, size_t newlen)
2586 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2587 void __user *oldval, size_t __user *oldlenp,
2588 void __user *newval, size_t newlen)
2593 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2594 void __user *oldval, size_t __user *oldlenp,
2595 void __user *newval, size_t newlen)
2600 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2601 void __user *oldval, size_t __user *oldlenp,
2602 void __user *newval, size_t newlen)
2607 #endif /* CONFIG_SYSCTL_SYSCALL */
2609 static int deprecated_sysctl_warning(struct __sysctl_args *args)
2611 static int msg_count;
2612 int name[CTL_MAXNAME];
2615 /* Read in the sysctl name for better debug message logging */
2616 for (i = 0; i < args->nlen; i++)
2617 if (get_user(name[i], args->name + i))
2620 /* Ignore accesses to kernel.version */
2621 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2624 if (msg_count < 5) {
2627 "warning: process `%s' used the deprecated sysctl "
2628 "system call with ", current->comm);
2629 for (i = 0; i < args->nlen; i++)
2630 printk("%d.", name[i]);
2637 * No sense putting this after each symbol definition, twice,
2638 * exception granted :-)
2640 EXPORT_SYMBOL(proc_dointvec);
2641 EXPORT_SYMBOL(proc_dointvec_jiffies);
2642 EXPORT_SYMBOL(proc_dointvec_minmax);
2643 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2644 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2645 EXPORT_SYMBOL(proc_dostring);
2646 EXPORT_SYMBOL(proc_doulongvec_minmax);
2647 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2648 EXPORT_SYMBOL(register_sysctl_table);
2649 EXPORT_SYMBOL(sysctl_intvec);
2650 EXPORT_SYMBOL(sysctl_jiffies);
2651 EXPORT_SYMBOL(sysctl_ms_jiffies);
2652 EXPORT_SYMBOL(sysctl_string);
2653 EXPORT_SYMBOL(sysctl_data);
2654 EXPORT_SYMBOL(unregister_sysctl_table);