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 int min_sched_granularity_ns = 100000; /* 100 usecs */
229 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
230 static int min_wakeup_granularity_ns; /* 0 usecs */
231 static int 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,
305 .ctl_name = CTL_UNNUMBERED,
306 .procname = "sched_nr_migrate",
307 .data = &sysctl_sched_nr_migrate,
308 .maxlen = sizeof(unsigned int),
310 .proc_handler = &proc_dointvec,
312 #if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_SMP)
314 .ctl_name = CTL_UNNUMBERED,
315 .procname = "sched_min_bal_int_shares",
316 .data = &sysctl_sched_min_bal_int_shares,
317 .maxlen = sizeof(unsigned int),
319 .proc_handler = &proc_dointvec,
322 .ctl_name = CTL_UNNUMBERED,
323 .procname = "sched_max_bal_int_shares",
324 .data = &sysctl_sched_max_bal_int_shares,
325 .maxlen = sizeof(unsigned int),
327 .proc_handler = &proc_dointvec,
332 .ctl_name = CTL_UNNUMBERED,
333 .procname = "sched_compat_yield",
334 .data = &sysctl_sched_compat_yield,
335 .maxlen = sizeof(unsigned int),
337 .proc_handler = &proc_dointvec,
339 #ifdef CONFIG_PROVE_LOCKING
341 .ctl_name = CTL_UNNUMBERED,
342 .procname = "prove_locking",
343 .data = &prove_locking,
344 .maxlen = sizeof(int),
346 .proc_handler = &proc_dointvec,
349 #ifdef CONFIG_LOCK_STAT
351 .ctl_name = CTL_UNNUMBERED,
352 .procname = "lock_stat",
354 .maxlen = sizeof(int),
356 .proc_handler = &proc_dointvec,
360 .ctl_name = KERN_PANIC,
362 .data = &panic_timeout,
363 .maxlen = sizeof(int),
365 .proc_handler = &proc_dointvec,
368 .ctl_name = KERN_CORE_USES_PID,
369 .procname = "core_uses_pid",
370 .data = &core_uses_pid,
371 .maxlen = sizeof(int),
373 .proc_handler = &proc_dointvec,
375 #ifdef CONFIG_AUDITSYSCALL
377 .ctl_name = CTL_UNNUMBERED,
378 .procname = "audit_argv_kb",
379 .data = &audit_argv_kb,
380 .maxlen = sizeof(int),
382 .proc_handler = &proc_dointvec,
386 .ctl_name = KERN_CORE_PATTERN,
387 .procname = "core_pattern",
388 .data = core_pattern,
389 .maxlen = CORENAME_MAX_SIZE,
391 .proc_handler = &proc_dostring,
392 .strategy = &sysctl_string,
394 #ifdef CONFIG_PROC_SYSCTL
396 .procname = "tainted",
398 .maxlen = sizeof(int),
400 .proc_handler = &proc_dointvec_taint,
403 #ifdef CONFIG_SECURITY_CAPABILITIES
405 .procname = "cap-bound",
407 .maxlen = sizeof(kernel_cap_t),
409 .proc_handler = &proc_dointvec_bset,
411 #endif /* def CONFIG_SECURITY_CAPABILITIES */
412 #ifdef CONFIG_BLK_DEV_INITRD
414 .ctl_name = KERN_REALROOTDEV,
415 .procname = "real-root-dev",
416 .data = &real_root_dev,
417 .maxlen = sizeof(int),
419 .proc_handler = &proc_dointvec,
423 .ctl_name = CTL_UNNUMBERED,
424 .procname = "print-fatal-signals",
425 .data = &print_fatal_signals,
426 .maxlen = sizeof(int),
428 .proc_handler = &proc_dointvec,
432 .ctl_name = KERN_SPARC_REBOOT,
433 .procname = "reboot-cmd",
434 .data = reboot_command,
437 .proc_handler = &proc_dostring,
438 .strategy = &sysctl_string,
441 .ctl_name = KERN_SPARC_STOP_A,
442 .procname = "stop-a",
443 .data = &stop_a_enabled,
444 .maxlen = sizeof (int),
446 .proc_handler = &proc_dointvec,
449 .ctl_name = KERN_SPARC_SCONS_PWROFF,
450 .procname = "scons-poweroff",
451 .data = &scons_pwroff,
452 .maxlen = sizeof (int),
454 .proc_handler = &proc_dointvec,
459 .ctl_name = KERN_HPPA_PWRSW,
460 .procname = "soft-power",
461 .data = &pwrsw_enabled,
462 .maxlen = sizeof (int),
464 .proc_handler = &proc_dointvec,
467 .ctl_name = KERN_HPPA_UNALIGNED,
468 .procname = "unaligned-trap",
469 .data = &unaligned_enabled,
470 .maxlen = sizeof (int),
472 .proc_handler = &proc_dointvec,
476 .ctl_name = KERN_CTLALTDEL,
477 .procname = "ctrl-alt-del",
479 .maxlen = sizeof(int),
481 .proc_handler = &proc_dointvec,
484 .ctl_name = KERN_PRINTK,
485 .procname = "printk",
486 .data = &console_loglevel,
487 .maxlen = 4*sizeof(int),
489 .proc_handler = &proc_dointvec,
493 .ctl_name = KERN_MODPROBE,
494 .procname = "modprobe",
495 .data = &modprobe_path,
496 .maxlen = KMOD_PATH_LEN,
498 .proc_handler = &proc_dostring,
499 .strategy = &sysctl_string,
502 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
504 .ctl_name = KERN_HOTPLUG,
505 .procname = "hotplug",
506 .data = &uevent_helper,
507 .maxlen = UEVENT_HELPER_PATH_LEN,
509 .proc_handler = &proc_dostring,
510 .strategy = &sysctl_string,
513 #ifdef CONFIG_CHR_DEV_SG
515 .ctl_name = KERN_SG_BIG_BUFF,
516 .procname = "sg-big-buff",
517 .data = &sg_big_buff,
518 .maxlen = sizeof (int),
520 .proc_handler = &proc_dointvec,
523 #ifdef CONFIG_BSD_PROCESS_ACCT
525 .ctl_name = KERN_ACCT,
528 .maxlen = 3*sizeof(int),
530 .proc_handler = &proc_dointvec,
533 #ifdef CONFIG_MAGIC_SYSRQ
535 .ctl_name = KERN_SYSRQ,
537 .data = &__sysrq_enabled,
538 .maxlen = sizeof (int),
540 .proc_handler = &proc_dointvec,
543 #ifdef CONFIG_PROC_SYSCTL
545 .procname = "cad_pid",
547 .maxlen = sizeof (int),
549 .proc_handler = &proc_do_cad_pid,
553 .ctl_name = KERN_MAX_THREADS,
554 .procname = "threads-max",
555 .data = &max_threads,
556 .maxlen = sizeof(int),
558 .proc_handler = &proc_dointvec,
561 .ctl_name = KERN_RANDOM,
562 .procname = "random",
564 .child = random_table,
567 .ctl_name = KERN_OVERFLOWUID,
568 .procname = "overflowuid",
569 .data = &overflowuid,
570 .maxlen = sizeof(int),
572 .proc_handler = &proc_dointvec_minmax,
573 .strategy = &sysctl_intvec,
574 .extra1 = &minolduid,
575 .extra2 = &maxolduid,
578 .ctl_name = KERN_OVERFLOWGID,
579 .procname = "overflowgid",
580 .data = &overflowgid,
581 .maxlen = sizeof(int),
583 .proc_handler = &proc_dointvec_minmax,
584 .strategy = &sysctl_intvec,
585 .extra1 = &minolduid,
586 .extra2 = &maxolduid,
589 #ifdef CONFIG_MATHEMU
591 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
592 .procname = "ieee_emulation_warnings",
593 .data = &sysctl_ieee_emulation_warnings,
594 .maxlen = sizeof(int),
596 .proc_handler = &proc_dointvec,
599 #ifdef CONFIG_NO_IDLE_HZ
601 .ctl_name = KERN_HZ_TIMER,
602 .procname = "hz_timer",
603 .data = &sysctl_hz_timer,
604 .maxlen = sizeof(int),
606 .proc_handler = &proc_dointvec,
610 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
611 .procname = "userprocess_debug",
612 .data = &sysctl_userprocess_debug,
613 .maxlen = sizeof(int),
615 .proc_handler = &proc_dointvec,
619 .ctl_name = KERN_PIDMAX,
620 .procname = "pid_max",
622 .maxlen = sizeof (int),
624 .proc_handler = &proc_dointvec_minmax,
625 .strategy = sysctl_intvec,
626 .extra1 = &pid_max_min,
627 .extra2 = &pid_max_max,
630 .ctl_name = KERN_PANIC_ON_OOPS,
631 .procname = "panic_on_oops",
632 .data = &panic_on_oops,
633 .maxlen = sizeof(int),
635 .proc_handler = &proc_dointvec,
638 .ctl_name = KERN_PRINTK_RATELIMIT,
639 .procname = "printk_ratelimit",
640 .data = &printk_ratelimit_jiffies,
641 .maxlen = sizeof(int),
643 .proc_handler = &proc_dointvec_jiffies,
644 .strategy = &sysctl_jiffies,
647 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
648 .procname = "printk_ratelimit_burst",
649 .data = &printk_ratelimit_burst,
650 .maxlen = sizeof(int),
652 .proc_handler = &proc_dointvec,
655 .ctl_name = KERN_NGROUPS_MAX,
656 .procname = "ngroups_max",
657 .data = &ngroups_max,
658 .maxlen = sizeof (int),
660 .proc_handler = &proc_dointvec,
662 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
664 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
665 .procname = "unknown_nmi_panic",
666 .data = &unknown_nmi_panic,
667 .maxlen = sizeof (int),
669 .proc_handler = &proc_dointvec,
672 .procname = "nmi_watchdog",
673 .data = &nmi_watchdog_enabled,
674 .maxlen = sizeof (int),
676 .proc_handler = &proc_nmi_enabled,
679 #if defined(CONFIG_X86)
681 .ctl_name = KERN_PANIC_ON_NMI,
682 .procname = "panic_on_unrecovered_nmi",
683 .data = &panic_on_unrecovered_nmi,
684 .maxlen = sizeof(int),
686 .proc_handler = &proc_dointvec,
689 .ctl_name = KERN_BOOTLOADER_TYPE,
690 .procname = "bootloader_type",
691 .data = &bootloader_type,
692 .maxlen = sizeof (int),
694 .proc_handler = &proc_dointvec,
697 .ctl_name = CTL_UNNUMBERED,
698 .procname = "kstack_depth_to_print",
699 .data = &kstack_depth_to_print,
700 .maxlen = sizeof(int),
702 .proc_handler = &proc_dointvec,
705 #if defined(CONFIG_MMU)
707 .ctl_name = KERN_RANDOMIZE,
708 .procname = "randomize_va_space",
709 .data = &randomize_va_space,
710 .maxlen = sizeof(int),
712 .proc_handler = &proc_dointvec,
715 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
717 .ctl_name = KERN_SPIN_RETRY,
718 .procname = "spin_retry",
720 .maxlen = sizeof (int),
722 .proc_handler = &proc_dointvec,
725 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
727 .procname = "acpi_video_flags",
728 .data = &acpi_realmode_flags,
729 .maxlen = sizeof (unsigned long),
731 .proc_handler = &proc_doulongvec_minmax,
736 .ctl_name = KERN_IA64_UNALIGNED,
737 .procname = "ignore-unaligned-usertrap",
738 .data = &no_unaligned_warning,
739 .maxlen = sizeof (int),
741 .proc_handler = &proc_dointvec,
744 #ifdef CONFIG_DETECT_SOFTLOCKUP
746 .ctl_name = CTL_UNNUMBERED,
747 .procname = "softlockup_thresh",
748 .data = &softlockup_thresh,
749 .maxlen = sizeof(int),
751 .proc_handler = &proc_dointvec_minmax,
752 .strategy = &sysctl_intvec,
757 .ctl_name = CTL_UNNUMBERED,
758 .procname = "hung_task_check_count",
759 .data = &sysctl_hung_task_check_count,
760 .maxlen = sizeof(int),
762 .proc_handler = &proc_dointvec_minmax,
763 .strategy = &sysctl_intvec,
766 .ctl_name = CTL_UNNUMBERED,
767 .procname = "hung_task_timeout_secs",
768 .data = &sysctl_hung_task_timeout_secs,
769 .maxlen = sizeof(int),
771 .proc_handler = &proc_dointvec_minmax,
772 .strategy = &sysctl_intvec,
775 .ctl_name = CTL_UNNUMBERED,
776 .procname = "hung_task_warnings",
777 .data = &sysctl_hung_task_warnings,
778 .maxlen = sizeof(int),
780 .proc_handler = &proc_dointvec_minmax,
781 .strategy = &sysctl_intvec,
786 .ctl_name = KERN_COMPAT_LOG,
787 .procname = "compat-log",
789 .maxlen = sizeof (int),
791 .proc_handler = &proc_dointvec,
794 #ifdef CONFIG_RT_MUTEXES
796 .ctl_name = KERN_MAX_LOCK_DEPTH,
797 .procname = "max_lock_depth",
798 .data = &max_lock_depth,
799 .maxlen = sizeof(int),
801 .proc_handler = &proc_dointvec,
804 #ifdef CONFIG_PROC_FS
806 .ctl_name = CTL_UNNUMBERED,
807 .procname = "maps_protect",
808 .data = &maps_protect,
809 .maxlen = sizeof(int),
811 .proc_handler = &proc_dointvec,
815 .ctl_name = CTL_UNNUMBERED,
816 .procname = "poweroff_cmd",
817 .data = &poweroff_cmd,
818 .maxlen = POWEROFF_CMD_PATH_LEN,
820 .proc_handler = &proc_dostring,
821 .strategy = &sysctl_string,
824 * NOTE: do not add new entries to this table unless you have read
825 * Documentation/sysctl/ctl_unnumbered.txt
830 static struct ctl_table vm_table[] = {
832 .ctl_name = VM_OVERCOMMIT_MEMORY,
833 .procname = "overcommit_memory",
834 .data = &sysctl_overcommit_memory,
835 .maxlen = sizeof(sysctl_overcommit_memory),
837 .proc_handler = &proc_dointvec,
840 .ctl_name = VM_PANIC_ON_OOM,
841 .procname = "panic_on_oom",
842 .data = &sysctl_panic_on_oom,
843 .maxlen = sizeof(sysctl_panic_on_oom),
845 .proc_handler = &proc_dointvec,
848 .ctl_name = CTL_UNNUMBERED,
849 .procname = "oom_kill_allocating_task",
850 .data = &sysctl_oom_kill_allocating_task,
851 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
853 .proc_handler = &proc_dointvec,
856 .ctl_name = VM_OVERCOMMIT_RATIO,
857 .procname = "overcommit_ratio",
858 .data = &sysctl_overcommit_ratio,
859 .maxlen = sizeof(sysctl_overcommit_ratio),
861 .proc_handler = &proc_dointvec,
864 .ctl_name = VM_PAGE_CLUSTER,
865 .procname = "page-cluster",
866 .data = &page_cluster,
867 .maxlen = sizeof(int),
869 .proc_handler = &proc_dointvec,
872 .ctl_name = VM_DIRTY_BACKGROUND,
873 .procname = "dirty_background_ratio",
874 .data = &dirty_background_ratio,
875 .maxlen = sizeof(dirty_background_ratio),
877 .proc_handler = &proc_dointvec_minmax,
878 .strategy = &sysctl_intvec,
880 .extra2 = &one_hundred,
883 .ctl_name = VM_DIRTY_RATIO,
884 .procname = "dirty_ratio",
885 .data = &vm_dirty_ratio,
886 .maxlen = sizeof(vm_dirty_ratio),
888 .proc_handler = &dirty_ratio_handler,
889 .strategy = &sysctl_intvec,
891 .extra2 = &one_hundred,
894 .procname = "dirty_writeback_centisecs",
895 .data = &dirty_writeback_interval,
896 .maxlen = sizeof(dirty_writeback_interval),
898 .proc_handler = &dirty_writeback_centisecs_handler,
901 .procname = "dirty_expire_centisecs",
902 .data = &dirty_expire_interval,
903 .maxlen = sizeof(dirty_expire_interval),
905 .proc_handler = &proc_dointvec_userhz_jiffies,
908 .ctl_name = VM_NR_PDFLUSH_THREADS,
909 .procname = "nr_pdflush_threads",
910 .data = &nr_pdflush_threads,
911 .maxlen = sizeof nr_pdflush_threads,
912 .mode = 0444 /* read-only*/,
913 .proc_handler = &proc_dointvec,
916 .ctl_name = VM_SWAPPINESS,
917 .procname = "swappiness",
918 .data = &vm_swappiness,
919 .maxlen = sizeof(vm_swappiness),
921 .proc_handler = &proc_dointvec_minmax,
922 .strategy = &sysctl_intvec,
924 .extra2 = &one_hundred,
926 #ifdef CONFIG_HUGETLB_PAGE
928 .procname = "nr_hugepages",
929 .data = &max_huge_pages,
930 .maxlen = sizeof(unsigned long),
932 .proc_handler = &hugetlb_sysctl_handler,
933 .extra1 = (void *)&hugetlb_zero,
934 .extra2 = (void *)&hugetlb_infinity,
937 .ctl_name = VM_HUGETLB_GROUP,
938 .procname = "hugetlb_shm_group",
939 .data = &sysctl_hugetlb_shm_group,
940 .maxlen = sizeof(gid_t),
942 .proc_handler = &proc_dointvec,
945 .ctl_name = CTL_UNNUMBERED,
946 .procname = "hugepages_treat_as_movable",
947 .data = &hugepages_treat_as_movable,
948 .maxlen = sizeof(int),
950 .proc_handler = &hugetlb_treat_movable_handler,
953 .ctl_name = CTL_UNNUMBERED,
954 .procname = "nr_overcommit_hugepages",
955 .data = &nr_overcommit_huge_pages,
956 .maxlen = sizeof(nr_overcommit_huge_pages),
958 .proc_handler = &proc_doulongvec_minmax,
962 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
963 .procname = "lowmem_reserve_ratio",
964 .data = &sysctl_lowmem_reserve_ratio,
965 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
967 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
968 .strategy = &sysctl_intvec,
971 .ctl_name = VM_DROP_PAGECACHE,
972 .procname = "drop_caches",
973 .data = &sysctl_drop_caches,
974 .maxlen = sizeof(int),
976 .proc_handler = drop_caches_sysctl_handler,
977 .strategy = &sysctl_intvec,
980 .ctl_name = VM_MIN_FREE_KBYTES,
981 .procname = "min_free_kbytes",
982 .data = &min_free_kbytes,
983 .maxlen = sizeof(min_free_kbytes),
985 .proc_handler = &min_free_kbytes_sysctl_handler,
986 .strategy = &sysctl_intvec,
990 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
991 .procname = "percpu_pagelist_fraction",
992 .data = &percpu_pagelist_fraction,
993 .maxlen = sizeof(percpu_pagelist_fraction),
995 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
996 .strategy = &sysctl_intvec,
997 .extra1 = &min_percpu_pagelist_fract,
1001 .ctl_name = VM_MAX_MAP_COUNT,
1002 .procname = "max_map_count",
1003 .data = &sysctl_max_map_count,
1004 .maxlen = sizeof(sysctl_max_map_count),
1006 .proc_handler = &proc_dointvec
1010 .ctl_name = VM_LAPTOP_MODE,
1011 .procname = "laptop_mode",
1012 .data = &laptop_mode,
1013 .maxlen = sizeof(laptop_mode),
1015 .proc_handler = &proc_dointvec_jiffies,
1016 .strategy = &sysctl_jiffies,
1019 .ctl_name = VM_BLOCK_DUMP,
1020 .procname = "block_dump",
1021 .data = &block_dump,
1022 .maxlen = sizeof(block_dump),
1024 .proc_handler = &proc_dointvec,
1025 .strategy = &sysctl_intvec,
1029 .ctl_name = VM_VFS_CACHE_PRESSURE,
1030 .procname = "vfs_cache_pressure",
1031 .data = &sysctl_vfs_cache_pressure,
1032 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1034 .proc_handler = &proc_dointvec,
1035 .strategy = &sysctl_intvec,
1038 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1040 .ctl_name = VM_LEGACY_VA_LAYOUT,
1041 .procname = "legacy_va_layout",
1042 .data = &sysctl_legacy_va_layout,
1043 .maxlen = sizeof(sysctl_legacy_va_layout),
1045 .proc_handler = &proc_dointvec,
1046 .strategy = &sysctl_intvec,
1052 .ctl_name = VM_ZONE_RECLAIM_MODE,
1053 .procname = "zone_reclaim_mode",
1054 .data = &zone_reclaim_mode,
1055 .maxlen = sizeof(zone_reclaim_mode),
1057 .proc_handler = &proc_dointvec,
1058 .strategy = &sysctl_intvec,
1062 .ctl_name = VM_MIN_UNMAPPED,
1063 .procname = "min_unmapped_ratio",
1064 .data = &sysctl_min_unmapped_ratio,
1065 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1067 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1068 .strategy = &sysctl_intvec,
1070 .extra2 = &one_hundred,
1073 .ctl_name = VM_MIN_SLAB,
1074 .procname = "min_slab_ratio",
1075 .data = &sysctl_min_slab_ratio,
1076 .maxlen = sizeof(sysctl_min_slab_ratio),
1078 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1079 .strategy = &sysctl_intvec,
1081 .extra2 = &one_hundred,
1086 .ctl_name = CTL_UNNUMBERED,
1087 .procname = "stat_interval",
1088 .data = &sysctl_stat_interval,
1089 .maxlen = sizeof(sysctl_stat_interval),
1091 .proc_handler = &proc_dointvec_jiffies,
1092 .strategy = &sysctl_jiffies,
1095 #ifdef CONFIG_SECURITY
1097 .ctl_name = CTL_UNNUMBERED,
1098 .procname = "mmap_min_addr",
1099 .data = &mmap_min_addr,
1100 .maxlen = sizeof(unsigned long),
1102 .proc_handler = &proc_doulongvec_minmax,
1107 .ctl_name = CTL_UNNUMBERED,
1108 .procname = "numa_zonelist_order",
1109 .data = &numa_zonelist_order,
1110 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1112 .proc_handler = &numa_zonelist_order_handler,
1113 .strategy = &sysctl_string,
1116 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1117 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1119 .ctl_name = VM_VDSO_ENABLED,
1120 .procname = "vdso_enabled",
1121 .data = &vdso_enabled,
1122 .maxlen = sizeof(vdso_enabled),
1124 .proc_handler = &proc_dointvec,
1125 .strategy = &sysctl_intvec,
1130 * NOTE: do not add new entries to this table unless you have read
1131 * Documentation/sysctl/ctl_unnumbered.txt
1136 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1137 static struct ctl_table binfmt_misc_table[] = {
1142 static struct ctl_table fs_table[] = {
1144 .ctl_name = FS_NRINODE,
1145 .procname = "inode-nr",
1146 .data = &inodes_stat,
1147 .maxlen = 2*sizeof(int),
1149 .proc_handler = &proc_dointvec,
1152 .ctl_name = FS_STATINODE,
1153 .procname = "inode-state",
1154 .data = &inodes_stat,
1155 .maxlen = 7*sizeof(int),
1157 .proc_handler = &proc_dointvec,
1160 .procname = "file-nr",
1161 .data = &files_stat,
1162 .maxlen = 3*sizeof(int),
1164 .proc_handler = &proc_nr_files,
1167 .ctl_name = FS_MAXFILE,
1168 .procname = "file-max",
1169 .data = &files_stat.max_files,
1170 .maxlen = sizeof(int),
1172 .proc_handler = &proc_dointvec,
1175 .ctl_name = FS_DENTRY,
1176 .procname = "dentry-state",
1177 .data = &dentry_stat,
1178 .maxlen = 6*sizeof(int),
1180 .proc_handler = &proc_dointvec,
1183 .ctl_name = FS_OVERFLOWUID,
1184 .procname = "overflowuid",
1185 .data = &fs_overflowuid,
1186 .maxlen = sizeof(int),
1188 .proc_handler = &proc_dointvec_minmax,
1189 .strategy = &sysctl_intvec,
1190 .extra1 = &minolduid,
1191 .extra2 = &maxolduid,
1194 .ctl_name = FS_OVERFLOWGID,
1195 .procname = "overflowgid",
1196 .data = &fs_overflowgid,
1197 .maxlen = sizeof(int),
1199 .proc_handler = &proc_dointvec_minmax,
1200 .strategy = &sysctl_intvec,
1201 .extra1 = &minolduid,
1202 .extra2 = &maxolduid,
1205 .ctl_name = FS_LEASES,
1206 .procname = "leases-enable",
1207 .data = &leases_enable,
1208 .maxlen = sizeof(int),
1210 .proc_handler = &proc_dointvec,
1212 #ifdef CONFIG_DNOTIFY
1214 .ctl_name = FS_DIR_NOTIFY,
1215 .procname = "dir-notify-enable",
1216 .data = &dir_notify_enable,
1217 .maxlen = sizeof(int),
1219 .proc_handler = &proc_dointvec,
1224 .ctl_name = FS_LEASE_TIME,
1225 .procname = "lease-break-time",
1226 .data = &lease_break_time,
1227 .maxlen = sizeof(int),
1229 .proc_handler = &proc_dointvec_minmax,
1230 .strategy = &sysctl_intvec,
1235 .procname = "aio-nr",
1237 .maxlen = sizeof(aio_nr),
1239 .proc_handler = &proc_doulongvec_minmax,
1242 .procname = "aio-max-nr",
1243 .data = &aio_max_nr,
1244 .maxlen = sizeof(aio_max_nr),
1246 .proc_handler = &proc_doulongvec_minmax,
1248 #ifdef CONFIG_INOTIFY_USER
1250 .ctl_name = FS_INOTIFY,
1251 .procname = "inotify",
1253 .child = inotify_table,
1258 .ctl_name = KERN_SETUID_DUMPABLE,
1259 .procname = "suid_dumpable",
1260 .data = &suid_dumpable,
1261 .maxlen = sizeof(int),
1263 .proc_handler = &proc_dointvec,
1265 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1267 .ctl_name = CTL_UNNUMBERED,
1268 .procname = "binfmt_misc",
1270 .child = binfmt_misc_table,
1274 * NOTE: do not add new entries to this table unless you have read
1275 * Documentation/sysctl/ctl_unnumbered.txt
1280 static struct ctl_table debug_table[] = {
1281 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1283 .ctl_name = CTL_UNNUMBERED,
1284 .procname = "exception-trace",
1285 .data = &show_unhandled_signals,
1286 .maxlen = sizeof(int),
1288 .proc_handler = proc_dointvec
1294 static struct ctl_table dev_table[] = {
1298 static DEFINE_SPINLOCK(sysctl_lock);
1300 /* called under sysctl_lock */
1301 static int use_table(struct ctl_table_header *p)
1303 if (unlikely(p->unregistering))
1309 /* called under sysctl_lock */
1310 static void unuse_table(struct ctl_table_header *p)
1313 if (unlikely(p->unregistering))
1314 complete(p->unregistering);
1317 /* called under sysctl_lock, will reacquire if has to wait */
1318 static void start_unregistering(struct ctl_table_header *p)
1321 * if p->used is 0, nobody will ever touch that entry again;
1322 * we'll eliminate all paths to it before dropping sysctl_lock
1324 if (unlikely(p->used)) {
1325 struct completion wait;
1326 init_completion(&wait);
1327 p->unregistering = &wait;
1328 spin_unlock(&sysctl_lock);
1329 wait_for_completion(&wait);
1330 spin_lock(&sysctl_lock);
1333 * do not remove from the list until nobody holds it; walking the
1334 * list in do_sysctl() relies on that.
1336 list_del_init(&p->ctl_entry);
1339 void sysctl_head_finish(struct ctl_table_header *head)
1343 spin_lock(&sysctl_lock);
1345 spin_unlock(&sysctl_lock);
1348 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1350 struct ctl_table_header *head;
1351 struct list_head *tmp;
1352 spin_lock(&sysctl_lock);
1354 tmp = &prev->ctl_entry;
1358 tmp = &root_table_header.ctl_entry;
1360 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1362 if (!use_table(head))
1364 spin_unlock(&sysctl_lock);
1368 if (tmp == &root_table_header.ctl_entry)
1371 spin_unlock(&sysctl_lock);
1375 #ifdef CONFIG_SYSCTL_SYSCALL
1376 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1377 void __user *newval, size_t newlen)
1379 struct ctl_table_header *head;
1380 int error = -ENOTDIR;
1382 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1386 if (!oldlenp || get_user(old_len, oldlenp))
1390 for (head = sysctl_head_next(NULL); head;
1391 head = sysctl_head_next(head)) {
1392 error = parse_table(name, nlen, oldval, oldlenp,
1393 newval, newlen, head->ctl_table);
1394 if (error != -ENOTDIR) {
1395 sysctl_head_finish(head);
1402 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1404 struct __sysctl_args tmp;
1407 if (copy_from_user(&tmp, args, sizeof(tmp)))
1410 error = deprecated_sysctl_warning(&tmp);
1415 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1416 tmp.newval, tmp.newlen);
1421 #endif /* CONFIG_SYSCTL_SYSCALL */
1424 * sysctl_perm does NOT grant the superuser all rights automatically, because
1425 * some sysctl variables are readonly even to root.
1428 static int test_perm(int mode, int op)
1432 else if (in_egroup_p(0))
1434 if ((mode & op & 0007) == op)
1439 int sysctl_perm(struct ctl_table *table, int op)
1442 error = security_sysctl(table, op);
1445 return test_perm(table->mode, op);
1448 #ifdef CONFIG_SYSCTL_SYSCALL
1449 static int parse_table(int __user *name, int nlen,
1450 void __user *oldval, size_t __user *oldlenp,
1451 void __user *newval, size_t newlen,
1452 struct ctl_table *table)
1458 if (get_user(n, name))
1460 for ( ; table->ctl_name || table->procname; table++) {
1461 if (!table->ctl_name)
1463 if (n == table->ctl_name) {
1466 if (sysctl_perm(table, 001))
1470 table = table->child;
1473 error = do_sysctl_strategy(table, name, nlen,
1482 /* Perform the actual read/write of a sysctl table entry. */
1483 int do_sysctl_strategy (struct ctl_table *table,
1484 int __user *name, int nlen,
1485 void __user *oldval, size_t __user *oldlenp,
1486 void __user *newval, size_t newlen)
1494 if (sysctl_perm(table, op))
1497 if (table->strategy) {
1498 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1506 /* If there is no strategy routine, or if the strategy returns
1507 * zero, proceed with automatic r/w */
1508 if (table->data && table->maxlen) {
1509 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1516 #endif /* CONFIG_SYSCTL_SYSCALL */
1518 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1520 for (; table->ctl_name || table->procname; table++) {
1521 table->parent = parent;
1523 sysctl_set_parent(table, table->child);
1527 static __init int sysctl_init(void)
1530 sysctl_set_parent(NULL, root_table);
1531 err = sysctl_check_table(root_table);
1535 core_initcall(sysctl_init);
1538 * register_sysctl_table - register a sysctl hierarchy
1539 * @table: the top-level table structure
1541 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1542 * array. An entry with a ctl_name of 0 terminates the table.
1544 * The members of the &struct ctl_table structure are used as follows:
1546 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1547 * must be unique within that level of sysctl
1549 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1550 * enter a sysctl file
1552 * data - a pointer to data for use by proc_handler
1554 * maxlen - the maximum size in bytes of the data
1556 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1558 * child - a pointer to the child sysctl table if this entry is a directory, or
1561 * proc_handler - the text handler routine (described below)
1563 * strategy - the strategy routine (described below)
1565 * de - for internal use by the sysctl routines
1567 * extra1, extra2 - extra pointers usable by the proc handler routines
1569 * Leaf nodes in the sysctl tree will be represented by a single file
1570 * under /proc; non-leaf nodes will be represented by directories.
1572 * sysctl(2) can automatically manage read and write requests through
1573 * the sysctl table. The data and maxlen fields of the ctl_table
1574 * struct enable minimal validation of the values being written to be
1575 * performed, and the mode field allows minimal authentication.
1577 * More sophisticated management can be enabled by the provision of a
1578 * strategy routine with the table entry. This will be called before
1579 * any automatic read or write of the data is performed.
1581 * The strategy routine may return
1583 * < 0 - Error occurred (error is passed to user process)
1585 * 0 - OK - proceed with automatic read or write.
1587 * > 0 - OK - read or write has been done by the strategy routine, so
1588 * return immediately.
1590 * There must be a proc_handler routine for any terminal nodes
1591 * mirrored under /proc/sys (non-terminals are handled by a built-in
1592 * directory handler). Several default handlers are available to
1593 * cover common cases -
1595 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1596 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1597 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1599 * It is the handler's job to read the input buffer from user memory
1600 * and process it. The handler should return 0 on success.
1602 * This routine returns %NULL on a failure to register, and a pointer
1603 * to the table header on success.
1605 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1607 struct ctl_table_header *tmp;
1608 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1611 tmp->ctl_table = table;
1612 INIT_LIST_HEAD(&tmp->ctl_entry);
1614 tmp->unregistering = NULL;
1615 sysctl_set_parent(NULL, table);
1616 if (sysctl_check_table(tmp->ctl_table)) {
1620 spin_lock(&sysctl_lock);
1621 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1622 spin_unlock(&sysctl_lock);
1627 * unregister_sysctl_table - unregister a sysctl table hierarchy
1628 * @header: the header returned from register_sysctl_table
1630 * Unregisters the sysctl table and all children. proc entries may not
1631 * actually be removed until they are no longer used by anyone.
1633 void unregister_sysctl_table(struct ctl_table_header * header)
1640 spin_lock(&sysctl_lock);
1641 start_unregistering(header);
1642 spin_unlock(&sysctl_lock);
1646 #else /* !CONFIG_SYSCTL */
1647 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1652 void unregister_sysctl_table(struct ctl_table_header * table)
1656 #endif /* CONFIG_SYSCTL */
1662 #ifdef CONFIG_PROC_SYSCTL
1664 static int _proc_do_string(void* data, int maxlen, int write,
1665 struct file *filp, void __user *buffer,
1666 size_t *lenp, loff_t *ppos)
1672 if (!data || !maxlen || !*lenp) {
1680 while (len < *lenp) {
1681 if (get_user(c, p++))
1683 if (c == 0 || c == '\n')
1689 if(copy_from_user(data, buffer, len))
1691 ((char *) data)[len] = 0;
1709 if(copy_to_user(buffer, data, len))
1712 if(put_user('\n', ((char __user *) buffer) + len))
1723 * proc_dostring - read a string sysctl
1724 * @table: the sysctl table
1725 * @write: %TRUE if this is a write to the sysctl file
1726 * @filp: the file structure
1727 * @buffer: the user buffer
1728 * @lenp: the size of the user buffer
1729 * @ppos: file position
1731 * Reads/writes a string from/to the user buffer. If the kernel
1732 * buffer provided is not large enough to hold the string, the
1733 * string is truncated. The copied string is %NULL-terminated.
1734 * If the string is being read by the user process, it is copied
1735 * and a newline '\n' is added. It is truncated if the buffer is
1738 * Returns 0 on success.
1740 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
1741 void __user *buffer, size_t *lenp, loff_t *ppos)
1743 return _proc_do_string(table->data, table->maxlen, write, filp,
1744 buffer, lenp, ppos);
1748 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1750 int write, void *data)
1753 *valp = *negp ? -*lvalp : *lvalp;
1758 *lvalp = (unsigned long)-val;
1761 *lvalp = (unsigned long)val;
1767 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1768 int write, struct file *filp, void __user *buffer,
1769 size_t *lenp, loff_t *ppos,
1770 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1771 int write, void *data),
1774 #define TMPBUFLEN 21
1775 int *i, vleft, first=1, neg, val;
1779 char buf[TMPBUFLEN], *p;
1780 char __user *s = buffer;
1782 if (!tbl_data || !table->maxlen || !*lenp ||
1783 (*ppos && !write)) {
1788 i = (int *) tbl_data;
1789 vleft = table->maxlen / sizeof(*i);
1793 conv = do_proc_dointvec_conv;
1795 for (; left && vleft--; i++, first=0) {
1810 if (len > sizeof(buf) - 1)
1811 len = sizeof(buf) - 1;
1812 if (copy_from_user(buf, s, len))
1816 if (*p == '-' && left > 1) {
1820 if (*p < '0' || *p > '9')
1823 lval = simple_strtoul(p, &p, 0);
1826 if ((len < left) && *p && !isspace(*p))
1833 if (conv(&neg, &lval, i, 1, data))
1840 if (conv(&neg, &lval, i, 0, data))
1843 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1847 if(copy_to_user(s, buf, len))
1854 if (!write && !first && left) {
1855 if(put_user('\n', s))
1862 if (get_user(c, s++))
1877 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
1878 void __user *buffer, size_t *lenp, loff_t *ppos,
1879 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1880 int write, void *data),
1883 return __do_proc_dointvec(table->data, table, write, filp,
1884 buffer, lenp, ppos, conv, data);
1888 * proc_dointvec - read a vector of integers
1889 * @table: the sysctl table
1890 * @write: %TRUE if this is a write to the sysctl file
1891 * @filp: the file structure
1892 * @buffer: the user buffer
1893 * @lenp: the size of the user buffer
1894 * @ppos: file position
1896 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1897 * values from/to the user buffer, treated as an ASCII string.
1899 * Returns 0 on success.
1901 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
1902 void __user *buffer, size_t *lenp, loff_t *ppos)
1904 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1912 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1914 int write, void *data)
1916 int op = *(int *)data;
1918 int val = *negp ? -*lvalp : *lvalp;
1920 case OP_SET: *valp = val; break;
1921 case OP_AND: *valp &= val; break;
1922 case OP_OR: *valp |= val; break;
1928 *lvalp = (unsigned long)-val;
1931 *lvalp = (unsigned long)val;
1937 #ifdef CONFIG_SECURITY_CAPABILITIES
1939 * init may raise the set.
1942 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
1943 void __user *buffer, size_t *lenp, loff_t *ppos)
1947 if (write && !capable(CAP_SYS_MODULE)) {
1951 op = is_global_init(current) ? OP_SET : OP_AND;
1952 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1953 do_proc_dointvec_bset_conv,&op);
1955 #endif /* def CONFIG_SECURITY_CAPABILITIES */
1958 * Taint values can only be increased
1960 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
1961 void __user *buffer, size_t *lenp, loff_t *ppos)
1965 if (write && !capable(CAP_SYS_ADMIN))
1969 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1970 do_proc_dointvec_bset_conv,&op);
1973 struct do_proc_dointvec_minmax_conv_param {
1978 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1980 int write, void *data)
1982 struct do_proc_dointvec_minmax_conv_param *param = data;
1984 int val = *negp ? -*lvalp : *lvalp;
1985 if ((param->min && *param->min > val) ||
1986 (param->max && *param->max < val))
1993 *lvalp = (unsigned long)-val;
1996 *lvalp = (unsigned long)val;
2003 * proc_dointvec_minmax - read a vector of integers with min/max values
2004 * @table: the sysctl table
2005 * @write: %TRUE if this is a write to the sysctl file
2006 * @filp: the file structure
2007 * @buffer: the user buffer
2008 * @lenp: the size of the user buffer
2009 * @ppos: file position
2011 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2012 * values from/to the user buffer, treated as an ASCII string.
2014 * This routine will ensure the values are within the range specified by
2015 * table->extra1 (min) and table->extra2 (max).
2017 * Returns 0 on success.
2019 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2020 void __user *buffer, size_t *lenp, loff_t *ppos)
2022 struct do_proc_dointvec_minmax_conv_param param = {
2023 .min = (int *) table->extra1,
2024 .max = (int *) table->extra2,
2026 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2027 do_proc_dointvec_minmax_conv, ¶m);
2030 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2032 void __user *buffer,
2033 size_t *lenp, loff_t *ppos,
2034 unsigned long convmul,
2035 unsigned long convdiv)
2037 #define TMPBUFLEN 21
2038 unsigned long *i, *min, *max, val;
2039 int vleft, first=1, neg;
2041 char buf[TMPBUFLEN], *p;
2042 char __user *s = buffer;
2044 if (!data || !table->maxlen || !*lenp ||
2045 (*ppos && !write)) {
2050 i = (unsigned long *) data;
2051 min = (unsigned long *) table->extra1;
2052 max = (unsigned long *) table->extra2;
2053 vleft = table->maxlen / sizeof(unsigned long);
2056 for (; left && vleft--; i++, min++, max++, first=0) {
2071 if (len > TMPBUFLEN-1)
2073 if (copy_from_user(buf, s, len))
2077 if (*p == '-' && left > 1) {
2081 if (*p < '0' || *p > '9')
2083 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2085 if ((len < left) && *p && !isspace(*p))
2094 if ((min && val < *min) || (max && val > *max))
2101 sprintf(p, "%lu", convdiv * (*i) / convmul);
2105 if(copy_to_user(s, buf, len))
2112 if (!write && !first && left) {
2113 if(put_user('\n', s))
2120 if (get_user(c, s++))
2135 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2137 void __user *buffer,
2138 size_t *lenp, loff_t *ppos,
2139 unsigned long convmul,
2140 unsigned long convdiv)
2142 return __do_proc_doulongvec_minmax(table->data, table, write,
2143 filp, buffer, lenp, ppos, convmul, convdiv);
2147 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2148 * @table: the sysctl table
2149 * @write: %TRUE if this is a write to the sysctl file
2150 * @filp: the file structure
2151 * @buffer: the user buffer
2152 * @lenp: the size of the user buffer
2153 * @ppos: file position
2155 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2156 * values from/to the user buffer, treated as an ASCII string.
2158 * This routine will ensure the values are within the range specified by
2159 * table->extra1 (min) and table->extra2 (max).
2161 * Returns 0 on success.
2163 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2164 void __user *buffer, size_t *lenp, loff_t *ppos)
2166 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2170 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2171 * @table: the sysctl table
2172 * @write: %TRUE if this is a write to the sysctl file
2173 * @filp: the file structure
2174 * @buffer: the user buffer
2175 * @lenp: the size of the user buffer
2176 * @ppos: file position
2178 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2179 * values from/to the user buffer, treated as an ASCII string. The values
2180 * are treated as milliseconds, and converted to jiffies when they are stored.
2182 * This routine will ensure the values are within the range specified by
2183 * table->extra1 (min) and table->extra2 (max).
2185 * Returns 0 on success.
2187 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2189 void __user *buffer,
2190 size_t *lenp, loff_t *ppos)
2192 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2193 lenp, ppos, HZ, 1000l);
2197 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2199 int write, void *data)
2202 if (*lvalp > LONG_MAX / HZ)
2204 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2210 lval = (unsigned long)-val;
2213 lval = (unsigned long)val;
2220 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2222 int write, void *data)
2225 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2227 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2233 lval = (unsigned long)-val;
2236 lval = (unsigned long)val;
2238 *lvalp = jiffies_to_clock_t(lval);
2243 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2245 int write, void *data)
2248 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2254 lval = (unsigned long)-val;
2257 lval = (unsigned long)val;
2259 *lvalp = jiffies_to_msecs(lval);
2265 * proc_dointvec_jiffies - read a vector of integers as seconds
2266 * @table: the sysctl table
2267 * @write: %TRUE if this is a write to the sysctl file
2268 * @filp: the file structure
2269 * @buffer: the user buffer
2270 * @lenp: the size of the user buffer
2271 * @ppos: file position
2273 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2274 * values from/to the user buffer, treated as an ASCII string.
2275 * The values read are assumed to be in seconds, and are converted into
2278 * Returns 0 on success.
2280 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2281 void __user *buffer, size_t *lenp, loff_t *ppos)
2283 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2284 do_proc_dointvec_jiffies_conv,NULL);
2288 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2289 * @table: the sysctl table
2290 * @write: %TRUE if this is a write to the sysctl file
2291 * @filp: the file structure
2292 * @buffer: the user buffer
2293 * @lenp: the size of the user buffer
2294 * @ppos: pointer to the file position
2296 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2297 * values from/to the user buffer, treated as an ASCII string.
2298 * The values read are assumed to be in 1/USER_HZ seconds, and
2299 * are converted into jiffies.
2301 * Returns 0 on success.
2303 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2304 void __user *buffer, size_t *lenp, loff_t *ppos)
2306 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2307 do_proc_dointvec_userhz_jiffies_conv,NULL);
2311 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2312 * @table: the sysctl table
2313 * @write: %TRUE if this is a write to the sysctl file
2314 * @filp: the file structure
2315 * @buffer: the user buffer
2316 * @lenp: the size of the user buffer
2317 * @ppos: file position
2318 * @ppos: the current position in the file
2320 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2321 * values from/to the user buffer, treated as an ASCII string.
2322 * The values read are assumed to be in 1/1000 seconds, and
2323 * are converted into jiffies.
2325 * Returns 0 on success.
2327 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2328 void __user *buffer, size_t *lenp, loff_t *ppos)
2330 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2331 do_proc_dointvec_ms_jiffies_conv, NULL);
2334 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2335 void __user *buffer, size_t *lenp, loff_t *ppos)
2337 struct pid *new_pid;
2341 tmp = pid_nr_ns(cad_pid, current->nsproxy->pid_ns);
2343 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2344 lenp, ppos, NULL, NULL);
2348 new_pid = find_get_pid(tmp);
2352 put_pid(xchg(&cad_pid, new_pid));
2356 #else /* CONFIG_PROC_FS */
2358 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2359 void __user *buffer, size_t *lenp, loff_t *ppos)
2364 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2365 void __user *buffer, size_t *lenp, loff_t *ppos)
2370 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
2371 void __user *buffer, size_t *lenp, loff_t *ppos)
2376 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2377 void __user *buffer, size_t *lenp, loff_t *ppos)
2382 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2383 void __user *buffer, size_t *lenp, loff_t *ppos)
2388 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2389 void __user *buffer, size_t *lenp, loff_t *ppos)
2394 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2395 void __user *buffer, size_t *lenp, loff_t *ppos)
2400 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2401 void __user *buffer, size_t *lenp, loff_t *ppos)
2406 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2408 void __user *buffer,
2409 size_t *lenp, loff_t *ppos)
2415 #endif /* CONFIG_PROC_FS */
2418 #ifdef CONFIG_SYSCTL_SYSCALL
2420 * General sysctl support routines
2423 /* The generic sysctl data routine (used if no strategy routine supplied) */
2424 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2425 void __user *oldval, size_t __user *oldlenp,
2426 void __user *newval, size_t newlen)
2430 /* Get out of I don't have a variable */
2431 if (!table->data || !table->maxlen)
2434 if (oldval && oldlenp) {
2435 if (get_user(len, oldlenp))
2438 if (len > table->maxlen)
2439 len = table->maxlen;
2440 if (copy_to_user(oldval, table->data, len))
2442 if (put_user(len, oldlenp))
2447 if (newval && newlen) {
2448 if (newlen > table->maxlen)
2449 newlen = table->maxlen;
2451 if (copy_from_user(table->data, newval, newlen))
2457 /* The generic string strategy routine: */
2458 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2459 void __user *oldval, size_t __user *oldlenp,
2460 void __user *newval, size_t newlen)
2462 if (!table->data || !table->maxlen)
2465 if (oldval && oldlenp) {
2467 if (get_user(bufsize, oldlenp))
2470 size_t len = strlen(table->data), copied;
2472 /* This shouldn't trigger for a well-formed sysctl */
2473 if (len > table->maxlen)
2474 len = table->maxlen;
2476 /* Copy up to a max of bufsize-1 bytes of the string */
2477 copied = (len >= bufsize) ? bufsize - 1 : len;
2479 if (copy_to_user(oldval, table->data, copied) ||
2480 put_user(0, (char __user *)(oldval + copied)))
2482 if (put_user(len, oldlenp))
2486 if (newval && newlen) {
2487 size_t len = newlen;
2488 if (len > table->maxlen)
2489 len = table->maxlen;
2490 if(copy_from_user(table->data, newval, len))
2492 if (len == table->maxlen)
2494 ((char *) table->data)[len] = 0;
2500 * This function makes sure that all of the integers in the vector
2501 * are between the minimum and maximum values given in the arrays
2502 * table->extra1 and table->extra2, respectively.
2504 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2505 void __user *oldval, size_t __user *oldlenp,
2506 void __user *newval, size_t newlen)
2509 if (newval && newlen) {
2510 int __user *vec = (int __user *) newval;
2511 int *min = (int *) table->extra1;
2512 int *max = (int *) table->extra2;
2516 if (newlen % sizeof(int) != 0)
2519 if (!table->extra1 && !table->extra2)
2522 if (newlen > table->maxlen)
2523 newlen = table->maxlen;
2524 length = newlen / sizeof(int);
2526 for (i = 0; i < length; i++) {
2528 if (get_user(value, vec + i))
2530 if (min && value < min[i])
2532 if (max && value > max[i])
2539 /* Strategy function to convert jiffies to seconds */
2540 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2541 void __user *oldval, size_t __user *oldlenp,
2542 void __user *newval, size_t newlen)
2544 if (oldval && oldlenp) {
2547 if (get_user(olen, oldlenp))
2552 if (olen < sizeof(int))
2555 val = *(int *)(table->data) / HZ;
2556 if (put_user(val, (int __user *)oldval))
2558 if (put_user(sizeof(int), oldlenp))
2562 if (newval && newlen) {
2564 if (newlen != sizeof(int))
2566 if (get_user(new, (int __user *)newval))
2568 *(int *)(table->data) = new*HZ;
2573 /* Strategy function to convert jiffies to seconds */
2574 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2575 void __user *oldval, size_t __user *oldlenp,
2576 void __user *newval, size_t newlen)
2578 if (oldval && oldlenp) {
2581 if (get_user(olen, oldlenp))
2586 if (olen < sizeof(int))
2589 val = jiffies_to_msecs(*(int *)(table->data));
2590 if (put_user(val, (int __user *)oldval))
2592 if (put_user(sizeof(int), oldlenp))
2596 if (newval && newlen) {
2598 if (newlen != sizeof(int))
2600 if (get_user(new, (int __user *)newval))
2602 *(int *)(table->data) = msecs_to_jiffies(new);
2609 #else /* CONFIG_SYSCTL_SYSCALL */
2612 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2614 struct __sysctl_args tmp;
2617 if (copy_from_user(&tmp, args, sizeof(tmp)))
2620 error = deprecated_sysctl_warning(&tmp);
2622 /* If no error reading the parameters then just -ENOSYS ... */
2629 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2630 void __user *oldval, size_t __user *oldlenp,
2631 void __user *newval, size_t newlen)
2636 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2637 void __user *oldval, size_t __user *oldlenp,
2638 void __user *newval, size_t newlen)
2643 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2644 void __user *oldval, size_t __user *oldlenp,
2645 void __user *newval, size_t newlen)
2650 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2651 void __user *oldval, size_t __user *oldlenp,
2652 void __user *newval, size_t newlen)
2657 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2658 void __user *oldval, size_t __user *oldlenp,
2659 void __user *newval, size_t newlen)
2664 #endif /* CONFIG_SYSCTL_SYSCALL */
2666 static int deprecated_sysctl_warning(struct __sysctl_args *args)
2668 static int msg_count;
2669 int name[CTL_MAXNAME];
2672 /* Check args->nlen. */
2673 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2676 /* Read in the sysctl name for better debug message logging */
2677 for (i = 0; i < args->nlen; i++)
2678 if (get_user(name[i], args->name + i))
2681 /* Ignore accesses to kernel.version */
2682 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2685 if (msg_count < 5) {
2688 "warning: process `%s' used the deprecated sysctl "
2689 "system call with ", current->comm);
2690 for (i = 0; i < args->nlen; i++)
2691 printk("%d.", name[i]);
2698 * No sense putting this after each symbol definition, twice,
2699 * exception granted :-)
2701 EXPORT_SYMBOL(proc_dointvec);
2702 EXPORT_SYMBOL(proc_dointvec_jiffies);
2703 EXPORT_SYMBOL(proc_dointvec_minmax);
2704 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2705 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2706 EXPORT_SYMBOL(proc_dostring);
2707 EXPORT_SYMBOL(proc_doulongvec_minmax);
2708 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2709 EXPORT_SYMBOL(register_sysctl_table);
2710 EXPORT_SYMBOL(sysctl_intvec);
2711 EXPORT_SYMBOL(sysctl_jiffies);
2712 EXPORT_SYMBOL(sysctl_ms_jiffies);
2713 EXPORT_SYMBOL(sysctl_string);
2714 EXPORT_SYMBOL(sysctl_data);
2715 EXPORT_SYMBOL(unregister_sysctl_table);