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/bitmap.h>
27 #include <linux/signal.h>
28 #include <linux/printk.h>
29 #include <linux/proc_fs.h>
30 #include <linux/security.h>
31 #include <linux/ctype.h>
32 #include <linux/kmemcheck.h>
33 #include <linux/kmemleak.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/kobject.h>
38 #include <linux/net.h>
39 #include <linux/sysrq.h>
40 #include <linux/highuid.h>
41 #include <linux/writeback.h>
42 #include <linux/ratelimit.h>
43 #include <linux/compaction.h>
44 #include <linux/hugetlb.h>
45 #include <linux/initrd.h>
46 #include <linux/key.h>
47 #include <linux/times.h>
48 #include <linux/limits.h>
49 #include <linux/dcache.h>
50 #include <linux/dnotify.h>
51 #include <linux/syscalls.h>
52 #include <linux/vmstat.h>
53 #include <linux/nfs_fs.h>
54 #include <linux/acpi.h>
55 #include <linux/reboot.h>
56 #include <linux/ftrace.h>
57 #include <linux/perf_event.h>
58 #include <linux/kprobes.h>
59 #include <linux/pipe_fs_i.h>
60 #include <linux/oom.h>
61 #include <linux/kmod.h>
62 #include <linux/capability.h>
63 #include <linux/binfmts.h>
64 #include <linux/sched/sysctl.h>
66 #include <asm/uaccess.h>
67 #include <asm/processor.h>
71 #include <asm/stacktrace.h>
75 #include <asm/setup.h>
77 #ifdef CONFIG_BSD_PROCESS_ACCT
78 #include <linux/acct.h>
80 #ifdef CONFIG_RT_MUTEXES
81 #include <linux/rtmutex.h>
83 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
84 #include <linux/lockdep.h>
86 #ifdef CONFIG_CHR_DEV_SG
90 #ifdef CONFIG_LOCKUP_DETECTOR
91 #include <linux/nmi.h>
95 #if defined(CONFIG_SYSCTL)
97 /* External variables not in a header file. */
98 extern int sysctl_overcommit_memory;
99 extern int sysctl_overcommit_ratio;
100 extern int max_threads;
101 extern int suid_dumpable;
102 #ifdef CONFIG_COREDUMP
103 extern int core_uses_pid;
104 extern char core_pattern[];
105 extern unsigned int core_pipe_limit;
108 extern int min_free_kbytes;
109 extern int pid_max_min, pid_max_max;
110 extern int sysctl_drop_caches;
111 extern int percpu_pagelist_fraction;
112 extern int compat_log;
113 extern int latencytop_enabled;
114 extern int sysctl_nr_open_min, sysctl_nr_open_max;
116 extern int sysctl_nr_trim_pages;
119 extern int blk_iopoll_enabled;
122 /* Constants used for minimum and maximum */
123 #ifdef CONFIG_LOCKUP_DETECTOR
124 static int sixty = 60;
125 static int neg_one = -1;
129 static int __maybe_unused one = 1;
130 static int __maybe_unused two = 2;
131 static int __maybe_unused three = 3;
132 static unsigned long one_ul = 1;
133 static int one_hundred = 100;
135 static int ten_thousand = 10000;
138 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
139 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
141 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
142 static int maxolduid = 65535;
143 static int minolduid;
144 static int min_percpu_pagelist_fract = 8;
146 static int ngroups_max = NGROUPS_MAX;
147 static const int cap_last_cap = CAP_LAST_CAP;
149 #ifdef CONFIG_INOTIFY_USER
150 #include <linux/inotify.h>
155 #ifdef CONFIG_SPARC64
156 extern int sysctl_tsb_ratio;
160 extern int pwrsw_enabled;
161 extern int unaligned_enabled;
165 extern int no_unaligned_warning;
166 extern int unaligned_dump_stack;
169 #ifdef CONFIG_PROC_SYSCTL
170 static int proc_do_cad_pid(struct ctl_table *table, int write,
171 void __user *buffer, size_t *lenp, loff_t *ppos);
172 static int proc_taint(struct ctl_table *table, int write,
173 void __user *buffer, size_t *lenp, loff_t *ppos);
177 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
178 void __user *buffer, size_t *lenp, loff_t *ppos);
181 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
182 void __user *buffer, size_t *lenp, loff_t *ppos);
183 #ifdef CONFIG_COREDUMP
184 static int proc_dostring_coredump(struct ctl_table *table, int write,
185 void __user *buffer, size_t *lenp, loff_t *ppos);
188 #ifdef CONFIG_MAGIC_SYSRQ
189 /* Note: sysrq code uses it's own private copy */
190 static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
192 static int sysrq_sysctl_handler(ctl_table *table, int write,
193 void __user *buffer, size_t *lenp,
198 error = proc_dointvec(table, write, buffer, lenp, ppos);
203 sysrq_toggle_support(__sysrq_enabled);
210 static struct ctl_table kern_table[];
211 static struct ctl_table vm_table[];
212 static struct ctl_table fs_table[];
213 static struct ctl_table debug_table[];
214 static struct ctl_table dev_table[];
215 extern struct ctl_table random_table[];
217 extern struct ctl_table epoll_table[];
220 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
221 int sysctl_legacy_va_layout;
224 /* The default sysctl tables: */
226 static struct ctl_table sysctl_base_table[] = {
228 .procname = "kernel",
245 .child = debug_table,
255 #ifdef CONFIG_SCHED_DEBUG
256 static int min_sched_granularity_ns = 100000; /* 100 usecs */
257 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
258 static int min_wakeup_granularity_ns; /* 0 usecs */
259 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
261 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
262 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
263 #endif /* CONFIG_SMP */
264 #endif /* CONFIG_SCHED_DEBUG */
266 #ifdef CONFIG_COMPACTION
267 static int min_extfrag_threshold;
268 static int max_extfrag_threshold = 1000;
271 static struct ctl_table kern_table[] = {
273 .procname = "sched_child_runs_first",
274 .data = &sysctl_sched_child_runs_first,
275 .maxlen = sizeof(unsigned int),
277 .proc_handler = proc_dointvec,
279 #ifdef CONFIG_SCHED_DEBUG
281 .procname = "sched_min_granularity_ns",
282 .data = &sysctl_sched_min_granularity,
283 .maxlen = sizeof(unsigned int),
285 .proc_handler = sched_proc_update_handler,
286 .extra1 = &min_sched_granularity_ns,
287 .extra2 = &max_sched_granularity_ns,
290 .procname = "sched_latency_ns",
291 .data = &sysctl_sched_latency,
292 .maxlen = sizeof(unsigned int),
294 .proc_handler = sched_proc_update_handler,
295 .extra1 = &min_sched_granularity_ns,
296 .extra2 = &max_sched_granularity_ns,
299 .procname = "sched_wakeup_granularity_ns",
300 .data = &sysctl_sched_wakeup_granularity,
301 .maxlen = sizeof(unsigned int),
303 .proc_handler = sched_proc_update_handler,
304 .extra1 = &min_wakeup_granularity_ns,
305 .extra2 = &max_wakeup_granularity_ns,
309 .procname = "sched_tunable_scaling",
310 .data = &sysctl_sched_tunable_scaling,
311 .maxlen = sizeof(enum sched_tunable_scaling),
313 .proc_handler = sched_proc_update_handler,
314 .extra1 = &min_sched_tunable_scaling,
315 .extra2 = &max_sched_tunable_scaling,
318 .procname = "sched_migration_cost_ns",
319 .data = &sysctl_sched_migration_cost,
320 .maxlen = sizeof(unsigned int),
322 .proc_handler = proc_dointvec,
325 .procname = "sched_nr_migrate",
326 .data = &sysctl_sched_nr_migrate,
327 .maxlen = sizeof(unsigned int),
329 .proc_handler = proc_dointvec,
332 .procname = "sched_time_avg_ms",
333 .data = &sysctl_sched_time_avg,
334 .maxlen = sizeof(unsigned int),
336 .proc_handler = proc_dointvec,
339 .procname = "sched_shares_window_ns",
340 .data = &sysctl_sched_shares_window,
341 .maxlen = sizeof(unsigned int),
343 .proc_handler = proc_dointvec,
346 .procname = "timer_migration",
347 .data = &sysctl_timer_migration,
348 .maxlen = sizeof(unsigned int),
350 .proc_handler = proc_dointvec_minmax,
354 #endif /* CONFIG_SMP */
355 #ifdef CONFIG_NUMA_BALANCING
357 .procname = "numa_balancing_scan_delay_ms",
358 .data = &sysctl_numa_balancing_scan_delay,
359 .maxlen = sizeof(unsigned int),
361 .proc_handler = proc_dointvec,
364 .procname = "numa_balancing_scan_period_min_ms",
365 .data = &sysctl_numa_balancing_scan_period_min,
366 .maxlen = sizeof(unsigned int),
368 .proc_handler = proc_dointvec,
371 .procname = "numa_balancing_scan_period_reset",
372 .data = &sysctl_numa_balancing_scan_period_reset,
373 .maxlen = sizeof(unsigned int),
375 .proc_handler = proc_dointvec,
378 .procname = "numa_balancing_scan_period_max_ms",
379 .data = &sysctl_numa_balancing_scan_period_max,
380 .maxlen = sizeof(unsigned int),
382 .proc_handler = proc_dointvec,
385 .procname = "numa_balancing_scan_size_mb",
386 .data = &sysctl_numa_balancing_scan_size,
387 .maxlen = sizeof(unsigned int),
389 .proc_handler = proc_dointvec,
391 #endif /* CONFIG_NUMA_BALANCING */
392 #endif /* CONFIG_SCHED_DEBUG */
394 .procname = "sched_rt_period_us",
395 .data = &sysctl_sched_rt_period,
396 .maxlen = sizeof(unsigned int),
398 .proc_handler = sched_rt_handler,
401 .procname = "sched_rt_runtime_us",
402 .data = &sysctl_sched_rt_runtime,
403 .maxlen = sizeof(int),
405 .proc_handler = sched_rt_handler,
407 #ifdef CONFIG_SCHED_AUTOGROUP
409 .procname = "sched_autogroup_enabled",
410 .data = &sysctl_sched_autogroup_enabled,
411 .maxlen = sizeof(unsigned int),
413 .proc_handler = proc_dointvec_minmax,
418 #ifdef CONFIG_CFS_BANDWIDTH
420 .procname = "sched_cfs_bandwidth_slice_us",
421 .data = &sysctl_sched_cfs_bandwidth_slice,
422 .maxlen = sizeof(unsigned int),
424 .proc_handler = proc_dointvec_minmax,
428 #ifdef CONFIG_PROVE_LOCKING
430 .procname = "prove_locking",
431 .data = &prove_locking,
432 .maxlen = sizeof(int),
434 .proc_handler = proc_dointvec,
437 #ifdef CONFIG_LOCK_STAT
439 .procname = "lock_stat",
441 .maxlen = sizeof(int),
443 .proc_handler = proc_dointvec,
448 .data = &panic_timeout,
449 .maxlen = sizeof(int),
451 .proc_handler = proc_dointvec,
453 #ifdef CONFIG_COREDUMP
455 .procname = "core_uses_pid",
456 .data = &core_uses_pid,
457 .maxlen = sizeof(int),
459 .proc_handler = proc_dointvec,
462 .procname = "core_pattern",
463 .data = core_pattern,
464 .maxlen = CORENAME_MAX_SIZE,
466 .proc_handler = proc_dostring_coredump,
469 .procname = "core_pipe_limit",
470 .data = &core_pipe_limit,
471 .maxlen = sizeof(unsigned int),
473 .proc_handler = proc_dointvec,
476 #ifdef CONFIG_PROC_SYSCTL
478 .procname = "tainted",
479 .maxlen = sizeof(long),
481 .proc_handler = proc_taint,
484 #ifdef CONFIG_LATENCYTOP
486 .procname = "latencytop",
487 .data = &latencytop_enabled,
488 .maxlen = sizeof(int),
490 .proc_handler = proc_dointvec,
493 #ifdef CONFIG_BLK_DEV_INITRD
495 .procname = "real-root-dev",
496 .data = &real_root_dev,
497 .maxlen = sizeof(int),
499 .proc_handler = proc_dointvec,
503 .procname = "print-fatal-signals",
504 .data = &print_fatal_signals,
505 .maxlen = sizeof(int),
507 .proc_handler = proc_dointvec,
511 .procname = "reboot-cmd",
512 .data = reboot_command,
515 .proc_handler = proc_dostring,
518 .procname = "stop-a",
519 .data = &stop_a_enabled,
520 .maxlen = sizeof (int),
522 .proc_handler = proc_dointvec,
525 .procname = "scons-poweroff",
526 .data = &scons_pwroff,
527 .maxlen = sizeof (int),
529 .proc_handler = proc_dointvec,
532 #ifdef CONFIG_SPARC64
534 .procname = "tsb-ratio",
535 .data = &sysctl_tsb_ratio,
536 .maxlen = sizeof (int),
538 .proc_handler = proc_dointvec,
543 .procname = "soft-power",
544 .data = &pwrsw_enabled,
545 .maxlen = sizeof (int),
547 .proc_handler = proc_dointvec,
550 .procname = "unaligned-trap",
551 .data = &unaligned_enabled,
552 .maxlen = sizeof (int),
554 .proc_handler = proc_dointvec,
558 .procname = "ctrl-alt-del",
560 .maxlen = sizeof(int),
562 .proc_handler = proc_dointvec,
564 #ifdef CONFIG_FUNCTION_TRACER
566 .procname = "ftrace_enabled",
567 .data = &ftrace_enabled,
568 .maxlen = sizeof(int),
570 .proc_handler = ftrace_enable_sysctl,
573 #ifdef CONFIG_STACK_TRACER
575 .procname = "stack_tracer_enabled",
576 .data = &stack_tracer_enabled,
577 .maxlen = sizeof(int),
579 .proc_handler = stack_trace_sysctl,
582 #ifdef CONFIG_TRACING
584 .procname = "ftrace_dump_on_oops",
585 .data = &ftrace_dump_on_oops,
586 .maxlen = sizeof(int),
588 .proc_handler = proc_dointvec,
591 #ifdef CONFIG_MODULES
593 .procname = "modprobe",
594 .data = &modprobe_path,
595 .maxlen = KMOD_PATH_LEN,
597 .proc_handler = proc_dostring,
600 .procname = "modules_disabled",
601 .data = &modules_disabled,
602 .maxlen = sizeof(int),
604 /* only handle a transition from default "0" to "1" */
605 .proc_handler = proc_dointvec_minmax,
612 .procname = "hotplug",
613 .data = &uevent_helper,
614 .maxlen = UEVENT_HELPER_PATH_LEN,
616 .proc_handler = proc_dostring,
619 #ifdef CONFIG_CHR_DEV_SG
621 .procname = "sg-big-buff",
622 .data = &sg_big_buff,
623 .maxlen = sizeof (int),
625 .proc_handler = proc_dointvec,
628 #ifdef CONFIG_BSD_PROCESS_ACCT
632 .maxlen = 3*sizeof(int),
634 .proc_handler = proc_dointvec,
637 #ifdef CONFIG_MAGIC_SYSRQ
640 .data = &__sysrq_enabled,
641 .maxlen = sizeof (int),
643 .proc_handler = sysrq_sysctl_handler,
646 #ifdef CONFIG_PROC_SYSCTL
648 .procname = "cad_pid",
650 .maxlen = sizeof (int),
652 .proc_handler = proc_do_cad_pid,
656 .procname = "threads-max",
657 .data = &max_threads,
658 .maxlen = sizeof(int),
660 .proc_handler = proc_dointvec,
663 .procname = "random",
665 .child = random_table,
668 .procname = "usermodehelper",
670 .child = usermodehelper_table,
673 .procname = "overflowuid",
674 .data = &overflowuid,
675 .maxlen = sizeof(int),
677 .proc_handler = proc_dointvec_minmax,
678 .extra1 = &minolduid,
679 .extra2 = &maxolduid,
682 .procname = "overflowgid",
683 .data = &overflowgid,
684 .maxlen = sizeof(int),
686 .proc_handler = proc_dointvec_minmax,
687 .extra1 = &minolduid,
688 .extra2 = &maxolduid,
691 #ifdef CONFIG_MATHEMU
693 .procname = "ieee_emulation_warnings",
694 .data = &sysctl_ieee_emulation_warnings,
695 .maxlen = sizeof(int),
697 .proc_handler = proc_dointvec,
701 .procname = "userprocess_debug",
702 .data = &show_unhandled_signals,
703 .maxlen = sizeof(int),
705 .proc_handler = proc_dointvec,
709 .procname = "pid_max",
711 .maxlen = sizeof (int),
713 .proc_handler = proc_dointvec_minmax,
714 .extra1 = &pid_max_min,
715 .extra2 = &pid_max_max,
718 .procname = "panic_on_oops",
719 .data = &panic_on_oops,
720 .maxlen = sizeof(int),
722 .proc_handler = proc_dointvec,
724 #if defined CONFIG_PRINTK
726 .procname = "printk",
727 .data = &console_loglevel,
728 .maxlen = 4*sizeof(int),
730 .proc_handler = proc_dointvec,
733 .procname = "printk_ratelimit",
734 .data = &printk_ratelimit_state.interval,
735 .maxlen = sizeof(int),
737 .proc_handler = proc_dointvec_jiffies,
740 .procname = "printk_ratelimit_burst",
741 .data = &printk_ratelimit_state.burst,
742 .maxlen = sizeof(int),
744 .proc_handler = proc_dointvec,
747 .procname = "printk_delay",
748 .data = &printk_delay_msec,
749 .maxlen = sizeof(int),
751 .proc_handler = proc_dointvec_minmax,
753 .extra2 = &ten_thousand,
756 .procname = "dmesg_restrict",
757 .data = &dmesg_restrict,
758 .maxlen = sizeof(int),
760 .proc_handler = proc_dointvec_minmax_sysadmin,
765 .procname = "kptr_restrict",
766 .data = &kptr_restrict,
767 .maxlen = sizeof(int),
769 .proc_handler = proc_dointvec_minmax_sysadmin,
775 .procname = "ngroups_max",
776 .data = &ngroups_max,
777 .maxlen = sizeof (int),
779 .proc_handler = proc_dointvec,
782 .procname = "cap_last_cap",
783 .data = (void *)&cap_last_cap,
784 .maxlen = sizeof(int),
786 .proc_handler = proc_dointvec,
788 #if defined(CONFIG_LOCKUP_DETECTOR)
790 .procname = "watchdog",
791 .data = &watchdog_enabled,
792 .maxlen = sizeof (int),
794 .proc_handler = proc_dowatchdog,
799 .procname = "watchdog_thresh",
800 .data = &watchdog_thresh,
801 .maxlen = sizeof(int),
803 .proc_handler = proc_dowatchdog,
808 .procname = "softlockup_panic",
809 .data = &softlockup_panic,
810 .maxlen = sizeof(int),
812 .proc_handler = proc_dointvec_minmax,
817 .procname = "nmi_watchdog",
818 .data = &watchdog_enabled,
819 .maxlen = sizeof (int),
821 .proc_handler = proc_dowatchdog,
826 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
828 .procname = "unknown_nmi_panic",
829 .data = &unknown_nmi_panic,
830 .maxlen = sizeof (int),
832 .proc_handler = proc_dointvec,
835 #if defined(CONFIG_X86)
837 .procname = "panic_on_unrecovered_nmi",
838 .data = &panic_on_unrecovered_nmi,
839 .maxlen = sizeof(int),
841 .proc_handler = proc_dointvec,
844 .procname = "panic_on_io_nmi",
845 .data = &panic_on_io_nmi,
846 .maxlen = sizeof(int),
848 .proc_handler = proc_dointvec,
850 #ifdef CONFIG_DEBUG_STACKOVERFLOW
852 .procname = "panic_on_stackoverflow",
853 .data = &sysctl_panic_on_stackoverflow,
854 .maxlen = sizeof(int),
856 .proc_handler = proc_dointvec,
860 .procname = "bootloader_type",
861 .data = &bootloader_type,
862 .maxlen = sizeof (int),
864 .proc_handler = proc_dointvec,
867 .procname = "bootloader_version",
868 .data = &bootloader_version,
869 .maxlen = sizeof (int),
871 .proc_handler = proc_dointvec,
874 .procname = "kstack_depth_to_print",
875 .data = &kstack_depth_to_print,
876 .maxlen = sizeof(int),
878 .proc_handler = proc_dointvec,
881 .procname = "io_delay_type",
882 .data = &io_delay_type,
883 .maxlen = sizeof(int),
885 .proc_handler = proc_dointvec,
888 #if defined(CONFIG_MMU)
890 .procname = "randomize_va_space",
891 .data = &randomize_va_space,
892 .maxlen = sizeof(int),
894 .proc_handler = proc_dointvec,
897 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
899 .procname = "spin_retry",
901 .maxlen = sizeof (int),
903 .proc_handler = proc_dointvec,
906 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
908 .procname = "acpi_video_flags",
909 .data = &acpi_realmode_flags,
910 .maxlen = sizeof (unsigned long),
912 .proc_handler = proc_doulongvec_minmax,
917 .procname = "ignore-unaligned-usertrap",
918 .data = &no_unaligned_warning,
919 .maxlen = sizeof (int),
921 .proc_handler = proc_dointvec,
924 .procname = "unaligned-dump-stack",
925 .data = &unaligned_dump_stack,
926 .maxlen = sizeof (int),
928 .proc_handler = proc_dointvec,
931 #ifdef CONFIG_DETECT_HUNG_TASK
933 .procname = "hung_task_panic",
934 .data = &sysctl_hung_task_panic,
935 .maxlen = sizeof(int),
937 .proc_handler = proc_dointvec_minmax,
942 .procname = "hung_task_check_count",
943 .data = &sysctl_hung_task_check_count,
944 .maxlen = sizeof(unsigned long),
946 .proc_handler = proc_doulongvec_minmax,
949 .procname = "hung_task_timeout_secs",
950 .data = &sysctl_hung_task_timeout_secs,
951 .maxlen = sizeof(unsigned long),
953 .proc_handler = proc_dohung_task_timeout_secs,
956 .procname = "hung_task_warnings",
957 .data = &sysctl_hung_task_warnings,
958 .maxlen = sizeof(unsigned long),
960 .proc_handler = proc_doulongvec_minmax,
965 .procname = "compat-log",
967 .maxlen = sizeof (int),
969 .proc_handler = proc_dointvec,
972 #ifdef CONFIG_RT_MUTEXES
974 .procname = "max_lock_depth",
975 .data = &max_lock_depth,
976 .maxlen = sizeof(int),
978 .proc_handler = proc_dointvec,
982 .procname = "poweroff_cmd",
983 .data = &poweroff_cmd,
984 .maxlen = POWEROFF_CMD_PATH_LEN,
986 .proc_handler = proc_dostring,
992 .child = key_sysctls,
995 #ifdef CONFIG_RCU_TORTURE_TEST
997 .procname = "rcutorture_runnable",
998 .data = &rcutorture_runnable,
999 .maxlen = sizeof(int),
1001 .proc_handler = proc_dointvec,
1004 #ifdef CONFIG_PERF_EVENTS
1006 * User-space scripts rely on the existence of this file
1007 * as a feature check for perf_events being enabled.
1009 * So it's an ABI, do not remove!
1012 .procname = "perf_event_paranoid",
1013 .data = &sysctl_perf_event_paranoid,
1014 .maxlen = sizeof(sysctl_perf_event_paranoid),
1016 .proc_handler = proc_dointvec,
1019 .procname = "perf_event_mlock_kb",
1020 .data = &sysctl_perf_event_mlock,
1021 .maxlen = sizeof(sysctl_perf_event_mlock),
1023 .proc_handler = proc_dointvec,
1026 .procname = "perf_event_max_sample_rate",
1027 .data = &sysctl_perf_event_sample_rate,
1028 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1030 .proc_handler = perf_proc_update_handler,
1033 #ifdef CONFIG_KMEMCHECK
1035 .procname = "kmemcheck",
1036 .data = &kmemcheck_enabled,
1037 .maxlen = sizeof(int),
1039 .proc_handler = proc_dointvec,
1044 .procname = "blk_iopoll",
1045 .data = &blk_iopoll_enabled,
1046 .maxlen = sizeof(int),
1048 .proc_handler = proc_dointvec,
1054 static struct ctl_table vm_table[] = {
1056 .procname = "overcommit_memory",
1057 .data = &sysctl_overcommit_memory,
1058 .maxlen = sizeof(sysctl_overcommit_memory),
1060 .proc_handler = proc_dointvec_minmax,
1065 .procname = "panic_on_oom",
1066 .data = &sysctl_panic_on_oom,
1067 .maxlen = sizeof(sysctl_panic_on_oom),
1069 .proc_handler = proc_dointvec_minmax,
1074 .procname = "oom_kill_allocating_task",
1075 .data = &sysctl_oom_kill_allocating_task,
1076 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1078 .proc_handler = proc_dointvec,
1081 .procname = "oom_dump_tasks",
1082 .data = &sysctl_oom_dump_tasks,
1083 .maxlen = sizeof(sysctl_oom_dump_tasks),
1085 .proc_handler = proc_dointvec,
1088 .procname = "overcommit_ratio",
1089 .data = &sysctl_overcommit_ratio,
1090 .maxlen = sizeof(sysctl_overcommit_ratio),
1092 .proc_handler = proc_dointvec,
1095 .procname = "page-cluster",
1096 .data = &page_cluster,
1097 .maxlen = sizeof(int),
1099 .proc_handler = proc_dointvec_minmax,
1103 .procname = "dirty_background_ratio",
1104 .data = &dirty_background_ratio,
1105 .maxlen = sizeof(dirty_background_ratio),
1107 .proc_handler = dirty_background_ratio_handler,
1109 .extra2 = &one_hundred,
1112 .procname = "dirty_background_bytes",
1113 .data = &dirty_background_bytes,
1114 .maxlen = sizeof(dirty_background_bytes),
1116 .proc_handler = dirty_background_bytes_handler,
1120 .procname = "dirty_ratio",
1121 .data = &vm_dirty_ratio,
1122 .maxlen = sizeof(vm_dirty_ratio),
1124 .proc_handler = dirty_ratio_handler,
1126 .extra2 = &one_hundred,
1129 .procname = "dirty_bytes",
1130 .data = &vm_dirty_bytes,
1131 .maxlen = sizeof(vm_dirty_bytes),
1133 .proc_handler = dirty_bytes_handler,
1134 .extra1 = &dirty_bytes_min,
1137 .procname = "dirty_writeback_centisecs",
1138 .data = &dirty_writeback_interval,
1139 .maxlen = sizeof(dirty_writeback_interval),
1141 .proc_handler = dirty_writeback_centisecs_handler,
1144 .procname = "dirty_expire_centisecs",
1145 .data = &dirty_expire_interval,
1146 .maxlen = sizeof(dirty_expire_interval),
1148 .proc_handler = proc_dointvec_minmax,
1152 .procname = "nr_pdflush_threads",
1153 .mode = 0444 /* read-only */,
1154 .proc_handler = pdflush_proc_obsolete,
1157 .procname = "swappiness",
1158 .data = &vm_swappiness,
1159 .maxlen = sizeof(vm_swappiness),
1161 .proc_handler = proc_dointvec_minmax,
1163 .extra2 = &one_hundred,
1165 #ifdef CONFIG_HUGETLB_PAGE
1167 .procname = "nr_hugepages",
1169 .maxlen = sizeof(unsigned long),
1171 .proc_handler = hugetlb_sysctl_handler,
1172 .extra1 = (void *)&hugetlb_zero,
1173 .extra2 = (void *)&hugetlb_infinity,
1177 .procname = "nr_hugepages_mempolicy",
1179 .maxlen = sizeof(unsigned long),
1181 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1182 .extra1 = (void *)&hugetlb_zero,
1183 .extra2 = (void *)&hugetlb_infinity,
1187 .procname = "hugetlb_shm_group",
1188 .data = &sysctl_hugetlb_shm_group,
1189 .maxlen = sizeof(gid_t),
1191 .proc_handler = proc_dointvec,
1194 .procname = "hugepages_treat_as_movable",
1195 .data = &hugepages_treat_as_movable,
1196 .maxlen = sizeof(int),
1198 .proc_handler = hugetlb_treat_movable_handler,
1201 .procname = "nr_overcommit_hugepages",
1203 .maxlen = sizeof(unsigned long),
1205 .proc_handler = hugetlb_overcommit_handler,
1206 .extra1 = (void *)&hugetlb_zero,
1207 .extra2 = (void *)&hugetlb_infinity,
1211 .procname = "lowmem_reserve_ratio",
1212 .data = &sysctl_lowmem_reserve_ratio,
1213 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1215 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1218 .procname = "drop_caches",
1219 .data = &sysctl_drop_caches,
1220 .maxlen = sizeof(int),
1222 .proc_handler = drop_caches_sysctl_handler,
1226 #ifdef CONFIG_COMPACTION
1228 .procname = "compact_memory",
1229 .data = &sysctl_compact_memory,
1230 .maxlen = sizeof(int),
1232 .proc_handler = sysctl_compaction_handler,
1235 .procname = "extfrag_threshold",
1236 .data = &sysctl_extfrag_threshold,
1237 .maxlen = sizeof(int),
1239 .proc_handler = sysctl_extfrag_handler,
1240 .extra1 = &min_extfrag_threshold,
1241 .extra2 = &max_extfrag_threshold,
1244 #endif /* CONFIG_COMPACTION */
1246 .procname = "min_free_kbytes",
1247 .data = &min_free_kbytes,
1248 .maxlen = sizeof(min_free_kbytes),
1250 .proc_handler = min_free_kbytes_sysctl_handler,
1254 .procname = "percpu_pagelist_fraction",
1255 .data = &percpu_pagelist_fraction,
1256 .maxlen = sizeof(percpu_pagelist_fraction),
1258 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1259 .extra1 = &min_percpu_pagelist_fract,
1263 .procname = "max_map_count",
1264 .data = &sysctl_max_map_count,
1265 .maxlen = sizeof(sysctl_max_map_count),
1267 .proc_handler = proc_dointvec_minmax,
1272 .procname = "nr_trim_pages",
1273 .data = &sysctl_nr_trim_pages,
1274 .maxlen = sizeof(sysctl_nr_trim_pages),
1276 .proc_handler = proc_dointvec_minmax,
1281 .procname = "laptop_mode",
1282 .data = &laptop_mode,
1283 .maxlen = sizeof(laptop_mode),
1285 .proc_handler = proc_dointvec_jiffies,
1288 .procname = "block_dump",
1289 .data = &block_dump,
1290 .maxlen = sizeof(block_dump),
1292 .proc_handler = proc_dointvec,
1296 .procname = "vfs_cache_pressure",
1297 .data = &sysctl_vfs_cache_pressure,
1298 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1300 .proc_handler = proc_dointvec,
1303 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1305 .procname = "legacy_va_layout",
1306 .data = &sysctl_legacy_va_layout,
1307 .maxlen = sizeof(sysctl_legacy_va_layout),
1309 .proc_handler = proc_dointvec,
1315 .procname = "zone_reclaim_mode",
1316 .data = &zone_reclaim_mode,
1317 .maxlen = sizeof(zone_reclaim_mode),
1319 .proc_handler = proc_dointvec,
1323 .procname = "min_unmapped_ratio",
1324 .data = &sysctl_min_unmapped_ratio,
1325 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1327 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1329 .extra2 = &one_hundred,
1332 .procname = "min_slab_ratio",
1333 .data = &sysctl_min_slab_ratio,
1334 .maxlen = sizeof(sysctl_min_slab_ratio),
1336 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1338 .extra2 = &one_hundred,
1343 .procname = "stat_interval",
1344 .data = &sysctl_stat_interval,
1345 .maxlen = sizeof(sysctl_stat_interval),
1347 .proc_handler = proc_dointvec_jiffies,
1352 .procname = "mmap_min_addr",
1353 .data = &dac_mmap_min_addr,
1354 .maxlen = sizeof(unsigned long),
1356 .proc_handler = mmap_min_addr_handler,
1361 .procname = "numa_zonelist_order",
1362 .data = &numa_zonelist_order,
1363 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1365 .proc_handler = numa_zonelist_order_handler,
1368 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1369 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1371 .procname = "vdso_enabled",
1372 .data = &vdso_enabled,
1373 .maxlen = sizeof(vdso_enabled),
1375 .proc_handler = proc_dointvec,
1379 #ifdef CONFIG_HIGHMEM
1381 .procname = "highmem_is_dirtyable",
1382 .data = &vm_highmem_is_dirtyable,
1383 .maxlen = sizeof(vm_highmem_is_dirtyable),
1385 .proc_handler = proc_dointvec_minmax,
1391 .procname = "scan_unevictable_pages",
1392 .data = &scan_unevictable_pages,
1393 .maxlen = sizeof(scan_unevictable_pages),
1395 .proc_handler = scan_unevictable_handler,
1397 #ifdef CONFIG_MEMORY_FAILURE
1399 .procname = "memory_failure_early_kill",
1400 .data = &sysctl_memory_failure_early_kill,
1401 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1403 .proc_handler = proc_dointvec_minmax,
1408 .procname = "memory_failure_recovery",
1409 .data = &sysctl_memory_failure_recovery,
1410 .maxlen = sizeof(sysctl_memory_failure_recovery),
1412 .proc_handler = proc_dointvec_minmax,
1420 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1421 static struct ctl_table binfmt_misc_table[] = {
1426 static struct ctl_table fs_table[] = {
1428 .procname = "inode-nr",
1429 .data = &inodes_stat,
1430 .maxlen = 2*sizeof(int),
1432 .proc_handler = proc_nr_inodes,
1435 .procname = "inode-state",
1436 .data = &inodes_stat,
1437 .maxlen = 7*sizeof(int),
1439 .proc_handler = proc_nr_inodes,
1442 .procname = "file-nr",
1443 .data = &files_stat,
1444 .maxlen = sizeof(files_stat),
1446 .proc_handler = proc_nr_files,
1449 .procname = "file-max",
1450 .data = &files_stat.max_files,
1451 .maxlen = sizeof(files_stat.max_files),
1453 .proc_handler = proc_doulongvec_minmax,
1456 .procname = "nr_open",
1457 .data = &sysctl_nr_open,
1458 .maxlen = sizeof(int),
1460 .proc_handler = proc_dointvec_minmax,
1461 .extra1 = &sysctl_nr_open_min,
1462 .extra2 = &sysctl_nr_open_max,
1465 .procname = "dentry-state",
1466 .data = &dentry_stat,
1467 .maxlen = 6*sizeof(int),
1469 .proc_handler = proc_nr_dentry,
1472 .procname = "overflowuid",
1473 .data = &fs_overflowuid,
1474 .maxlen = sizeof(int),
1476 .proc_handler = proc_dointvec_minmax,
1477 .extra1 = &minolduid,
1478 .extra2 = &maxolduid,
1481 .procname = "overflowgid",
1482 .data = &fs_overflowgid,
1483 .maxlen = sizeof(int),
1485 .proc_handler = proc_dointvec_minmax,
1486 .extra1 = &minolduid,
1487 .extra2 = &maxolduid,
1489 #ifdef CONFIG_FILE_LOCKING
1491 .procname = "leases-enable",
1492 .data = &leases_enable,
1493 .maxlen = sizeof(int),
1495 .proc_handler = proc_dointvec,
1498 #ifdef CONFIG_DNOTIFY
1500 .procname = "dir-notify-enable",
1501 .data = &dir_notify_enable,
1502 .maxlen = sizeof(int),
1504 .proc_handler = proc_dointvec,
1508 #ifdef CONFIG_FILE_LOCKING
1510 .procname = "lease-break-time",
1511 .data = &lease_break_time,
1512 .maxlen = sizeof(int),
1514 .proc_handler = proc_dointvec,
1519 .procname = "aio-nr",
1521 .maxlen = sizeof(aio_nr),
1523 .proc_handler = proc_doulongvec_minmax,
1526 .procname = "aio-max-nr",
1527 .data = &aio_max_nr,
1528 .maxlen = sizeof(aio_max_nr),
1530 .proc_handler = proc_doulongvec_minmax,
1532 #endif /* CONFIG_AIO */
1533 #ifdef CONFIG_INOTIFY_USER
1535 .procname = "inotify",
1537 .child = inotify_table,
1542 .procname = "epoll",
1544 .child = epoll_table,
1549 .procname = "protected_symlinks",
1550 .data = &sysctl_protected_symlinks,
1551 .maxlen = sizeof(int),
1553 .proc_handler = proc_dointvec_minmax,
1558 .procname = "protected_hardlinks",
1559 .data = &sysctl_protected_hardlinks,
1560 .maxlen = sizeof(int),
1562 .proc_handler = proc_dointvec_minmax,
1567 .procname = "suid_dumpable",
1568 .data = &suid_dumpable,
1569 .maxlen = sizeof(int),
1571 .proc_handler = proc_dointvec_minmax_coredump,
1575 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1577 .procname = "binfmt_misc",
1579 .child = binfmt_misc_table,
1583 .procname = "pipe-max-size",
1584 .data = &pipe_max_size,
1585 .maxlen = sizeof(int),
1587 .proc_handler = &pipe_proc_fn,
1588 .extra1 = &pipe_min_size,
1593 static struct ctl_table debug_table[] = {
1594 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1596 .procname = "exception-trace",
1597 .data = &show_unhandled_signals,
1598 .maxlen = sizeof(int),
1600 .proc_handler = proc_dointvec
1603 #if defined(CONFIG_OPTPROBES)
1605 .procname = "kprobes-optimization",
1606 .data = &sysctl_kprobes_optimization,
1607 .maxlen = sizeof(int),
1609 .proc_handler = proc_kprobes_optimization_handler,
1617 static struct ctl_table dev_table[] = {
1621 int __init sysctl_init(void)
1623 struct ctl_table_header *hdr;
1625 hdr = register_sysctl_table(sysctl_base_table);
1626 kmemleak_not_leak(hdr);
1630 #endif /* CONFIG_SYSCTL */
1636 #ifdef CONFIG_PROC_SYSCTL
1638 static int _proc_do_string(void* data, int maxlen, int write,
1639 void __user *buffer,
1640 size_t *lenp, loff_t *ppos)
1646 if (!data || !maxlen || !*lenp) {
1654 while (len < *lenp) {
1655 if (get_user(c, p++))
1657 if (c == 0 || c == '\n')
1663 if(copy_from_user(data, buffer, len))
1665 ((char *) data)[len] = 0;
1683 if(copy_to_user(buffer, data, len))
1686 if(put_user('\n', ((char __user *) buffer) + len))
1697 * proc_dostring - read a string sysctl
1698 * @table: the sysctl table
1699 * @write: %TRUE if this is a write to the sysctl file
1700 * @buffer: the user buffer
1701 * @lenp: the size of the user buffer
1702 * @ppos: file position
1704 * Reads/writes a string from/to the user buffer. If the kernel
1705 * buffer provided is not large enough to hold the string, the
1706 * string is truncated. The copied string is %NULL-terminated.
1707 * If the string is being read by the user process, it is copied
1708 * and a newline '\n' is added. It is truncated if the buffer is
1711 * Returns 0 on success.
1713 int proc_dostring(struct ctl_table *table, int write,
1714 void __user *buffer, size_t *lenp, loff_t *ppos)
1716 return _proc_do_string(table->data, table->maxlen, write,
1717 buffer, lenp, ppos);
1720 static size_t proc_skip_spaces(char **buf)
1723 char *tmp = skip_spaces(*buf);
1729 static void proc_skip_char(char **buf, size_t *size, const char v)
1739 #define TMPBUFLEN 22
1741 * proc_get_long - reads an ASCII formatted integer from a user buffer
1743 * @buf: a kernel buffer
1744 * @size: size of the kernel buffer
1745 * @val: this is where the number will be stored
1746 * @neg: set to %TRUE if number is negative
1747 * @perm_tr: a vector which contains the allowed trailers
1748 * @perm_tr_len: size of the perm_tr vector
1749 * @tr: pointer to store the trailer character
1751 * In case of success %0 is returned and @buf and @size are updated with
1752 * the amount of bytes read. If @tr is non-NULL and a trailing
1753 * character exists (size is non-zero after returning from this
1754 * function), @tr is updated with the trailing character.
1756 static int proc_get_long(char **buf, size_t *size,
1757 unsigned long *val, bool *neg,
1758 const char *perm_tr, unsigned perm_tr_len, char *tr)
1761 char *p, tmp[TMPBUFLEN];
1767 if (len > TMPBUFLEN - 1)
1768 len = TMPBUFLEN - 1;
1770 memcpy(tmp, *buf, len);
1774 if (*p == '-' && *size > 1) {
1782 *val = simple_strtoul(p, &p, 0);
1786 /* We don't know if the next char is whitespace thus we may accept
1787 * invalid integers (e.g. 1234...a) or two integers instead of one
1788 * (e.g. 123...1). So lets not allow such large numbers. */
1789 if (len == TMPBUFLEN - 1)
1792 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1795 if (tr && (len < *size))
1805 * proc_put_long - converts an integer to a decimal ASCII formatted string
1807 * @buf: the user buffer
1808 * @size: the size of the user buffer
1809 * @val: the integer to be converted
1810 * @neg: sign of the number, %TRUE for negative
1812 * In case of success %0 is returned and @buf and @size are updated with
1813 * the amount of bytes written.
1815 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1819 char tmp[TMPBUFLEN], *p = tmp;
1821 sprintf(p, "%s%lu", neg ? "-" : "", val);
1825 if (copy_to_user(*buf, tmp, len))
1833 static int proc_put_char(void __user **buf, size_t *size, char c)
1836 char __user **buffer = (char __user **)buf;
1837 if (put_user(c, *buffer))
1839 (*size)--, (*buffer)++;
1845 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1847 int write, void *data)
1850 *valp = *negp ? -*lvalp : *lvalp;
1855 *lvalp = (unsigned long)-val;
1858 *lvalp = (unsigned long)val;
1864 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1866 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1867 int write, void __user *buffer,
1868 size_t *lenp, loff_t *ppos,
1869 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1870 int write, void *data),
1873 int *i, vleft, first = 1, err = 0;
1874 unsigned long page = 0;
1878 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1883 i = (int *) tbl_data;
1884 vleft = table->maxlen / sizeof(*i);
1888 conv = do_proc_dointvec_conv;
1891 if (left > PAGE_SIZE - 1)
1892 left = PAGE_SIZE - 1;
1893 page = __get_free_page(GFP_TEMPORARY);
1894 kbuf = (char *) page;
1897 if (copy_from_user(kbuf, buffer, left)) {
1904 for (; left && vleft--; i++, first=0) {
1909 left -= proc_skip_spaces(&kbuf);
1913 err = proc_get_long(&kbuf, &left, &lval, &neg,
1915 sizeof(proc_wspace_sep), NULL);
1918 if (conv(&neg, &lval, i, 1, data)) {
1923 if (conv(&neg, &lval, i, 0, data)) {
1928 err = proc_put_char(&buffer, &left, '\t');
1931 err = proc_put_long(&buffer, &left, lval, neg);
1937 if (!write && !first && left && !err)
1938 err = proc_put_char(&buffer, &left, '\n');
1939 if (write && !err && left)
1940 left -= proc_skip_spaces(&kbuf);
1945 return err ? : -EINVAL;
1952 static int do_proc_dointvec(struct ctl_table *table, int write,
1953 void __user *buffer, size_t *lenp, loff_t *ppos,
1954 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1955 int write, void *data),
1958 return __do_proc_dointvec(table->data, table, write,
1959 buffer, lenp, ppos, conv, data);
1963 * proc_dointvec - read a vector of integers
1964 * @table: the sysctl table
1965 * @write: %TRUE if this is a write to the sysctl file
1966 * @buffer: the user buffer
1967 * @lenp: the size of the user buffer
1968 * @ppos: file position
1970 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1971 * values from/to the user buffer, treated as an ASCII string.
1973 * Returns 0 on success.
1975 int proc_dointvec(struct ctl_table *table, int write,
1976 void __user *buffer, size_t *lenp, loff_t *ppos)
1978 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1983 * Taint values can only be increased
1984 * This means we can safely use a temporary.
1986 static int proc_taint(struct ctl_table *table, int write,
1987 void __user *buffer, size_t *lenp, loff_t *ppos)
1990 unsigned long tmptaint = get_taint();
1993 if (write && !capable(CAP_SYS_ADMIN))
1998 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2004 * Poor man's atomic or. Not worth adding a primitive
2005 * to everyone's atomic.h for this
2008 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2009 if ((tmptaint >> i) & 1)
2017 #ifdef CONFIG_PRINTK
2018 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2019 void __user *buffer, size_t *lenp, loff_t *ppos)
2021 if (write && !capable(CAP_SYS_ADMIN))
2024 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2028 struct do_proc_dointvec_minmax_conv_param {
2033 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2035 int write, void *data)
2037 struct do_proc_dointvec_minmax_conv_param *param = data;
2039 int val = *negp ? -*lvalp : *lvalp;
2040 if ((param->min && *param->min > val) ||
2041 (param->max && *param->max < val))
2048 *lvalp = (unsigned long)-val;
2051 *lvalp = (unsigned long)val;
2058 * proc_dointvec_minmax - read a vector of integers with min/max values
2059 * @table: the sysctl table
2060 * @write: %TRUE if this is a write to the sysctl file
2061 * @buffer: the user buffer
2062 * @lenp: the size of the user buffer
2063 * @ppos: file position
2065 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2066 * values from/to the user buffer, treated as an ASCII string.
2068 * This routine will ensure the values are within the range specified by
2069 * table->extra1 (min) and table->extra2 (max).
2071 * Returns 0 on success.
2073 int proc_dointvec_minmax(struct ctl_table *table, int write,
2074 void __user *buffer, size_t *lenp, loff_t *ppos)
2076 struct do_proc_dointvec_minmax_conv_param param = {
2077 .min = (int *) table->extra1,
2078 .max = (int *) table->extra2,
2080 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2081 do_proc_dointvec_minmax_conv, ¶m);
2084 static void validate_coredump_safety(void)
2086 #ifdef CONFIG_COREDUMP
2087 if (suid_dumpable == SUID_DUMPABLE_SAFE &&
2088 core_pattern[0] != '/' && core_pattern[0] != '|') {
2089 printk(KERN_WARNING "Unsafe core_pattern used with "\
2090 "suid_dumpable=2. Pipe handler or fully qualified "\
2091 "core dump path required.\n");
2096 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2097 void __user *buffer, size_t *lenp, loff_t *ppos)
2099 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2101 validate_coredump_safety();
2105 #ifdef CONFIG_COREDUMP
2106 static int proc_dostring_coredump(struct ctl_table *table, int write,
2107 void __user *buffer, size_t *lenp, loff_t *ppos)
2109 int error = proc_dostring(table, write, buffer, lenp, ppos);
2111 validate_coredump_safety();
2116 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2117 void __user *buffer,
2118 size_t *lenp, loff_t *ppos,
2119 unsigned long convmul,
2120 unsigned long convdiv)
2122 unsigned long *i, *min, *max;
2123 int vleft, first = 1, err = 0;
2124 unsigned long page = 0;
2128 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2133 i = (unsigned long *) data;
2134 min = (unsigned long *) table->extra1;
2135 max = (unsigned long *) table->extra2;
2136 vleft = table->maxlen / sizeof(unsigned long);
2140 if (left > PAGE_SIZE - 1)
2141 left = PAGE_SIZE - 1;
2142 page = __get_free_page(GFP_TEMPORARY);
2143 kbuf = (char *) page;
2146 if (copy_from_user(kbuf, buffer, left)) {
2153 for (; left && vleft--; i++, first = 0) {
2159 left -= proc_skip_spaces(&kbuf);
2161 err = proc_get_long(&kbuf, &left, &val, &neg,
2163 sizeof(proc_wspace_sep), NULL);
2168 if ((min && val < *min) || (max && val > *max))
2172 val = convdiv * (*i) / convmul;
2174 err = proc_put_char(&buffer, &left, '\t');
2175 err = proc_put_long(&buffer, &left, val, false);
2181 if (!write && !first && left && !err)
2182 err = proc_put_char(&buffer, &left, '\n');
2184 left -= proc_skip_spaces(&kbuf);
2189 return err ? : -EINVAL;
2196 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2197 void __user *buffer,
2198 size_t *lenp, loff_t *ppos,
2199 unsigned long convmul,
2200 unsigned long convdiv)
2202 return __do_proc_doulongvec_minmax(table->data, table, write,
2203 buffer, lenp, ppos, convmul, convdiv);
2207 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2208 * @table: the sysctl table
2209 * @write: %TRUE if this is a write to the sysctl file
2210 * @buffer: the user buffer
2211 * @lenp: the size of the user buffer
2212 * @ppos: file position
2214 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2215 * values from/to the user buffer, treated as an ASCII string.
2217 * This routine will ensure the values are within the range specified by
2218 * table->extra1 (min) and table->extra2 (max).
2220 * Returns 0 on success.
2222 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2223 void __user *buffer, size_t *lenp, loff_t *ppos)
2225 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2229 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2230 * @table: the sysctl table
2231 * @write: %TRUE if this is a write to the sysctl file
2232 * @buffer: the user buffer
2233 * @lenp: the size of the user buffer
2234 * @ppos: file position
2236 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2237 * values from/to the user buffer, treated as an ASCII string. The values
2238 * are treated as milliseconds, and converted to jiffies when they are stored.
2240 * This routine will ensure the values are within the range specified by
2241 * table->extra1 (min) and table->extra2 (max).
2243 * Returns 0 on success.
2245 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2246 void __user *buffer,
2247 size_t *lenp, loff_t *ppos)
2249 return do_proc_doulongvec_minmax(table, write, buffer,
2250 lenp, ppos, HZ, 1000l);
2254 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2256 int write, void *data)
2259 if (*lvalp > LONG_MAX / HZ)
2261 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2267 lval = (unsigned long)-val;
2270 lval = (unsigned long)val;
2277 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2279 int write, void *data)
2282 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2284 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2290 lval = (unsigned long)-val;
2293 lval = (unsigned long)val;
2295 *lvalp = jiffies_to_clock_t(lval);
2300 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2302 int write, void *data)
2305 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2311 lval = (unsigned long)-val;
2314 lval = (unsigned long)val;
2316 *lvalp = jiffies_to_msecs(lval);
2322 * proc_dointvec_jiffies - read a vector of integers as seconds
2323 * @table: the sysctl table
2324 * @write: %TRUE if this is a write to the sysctl file
2325 * @buffer: the user buffer
2326 * @lenp: the size of the user buffer
2327 * @ppos: file position
2329 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2330 * values from/to the user buffer, treated as an ASCII string.
2331 * The values read are assumed to be in seconds, and are converted into
2334 * Returns 0 on success.
2336 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2337 void __user *buffer, size_t *lenp, loff_t *ppos)
2339 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2340 do_proc_dointvec_jiffies_conv,NULL);
2344 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2345 * @table: the sysctl table
2346 * @write: %TRUE if this is a write to the sysctl file
2347 * @buffer: the user buffer
2348 * @lenp: the size of the user buffer
2349 * @ppos: pointer to the file position
2351 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2352 * values from/to the user buffer, treated as an ASCII string.
2353 * The values read are assumed to be in 1/USER_HZ seconds, and
2354 * are converted into jiffies.
2356 * Returns 0 on success.
2358 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2359 void __user *buffer, size_t *lenp, loff_t *ppos)
2361 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2362 do_proc_dointvec_userhz_jiffies_conv,NULL);
2366 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2367 * @table: the sysctl table
2368 * @write: %TRUE if this is a write to the sysctl file
2369 * @buffer: the user buffer
2370 * @lenp: the size of the user buffer
2371 * @ppos: file position
2372 * @ppos: the current position in the file
2374 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2375 * values from/to the user buffer, treated as an ASCII string.
2376 * The values read are assumed to be in 1/1000 seconds, and
2377 * are converted into jiffies.
2379 * Returns 0 on success.
2381 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2382 void __user *buffer, size_t *lenp, loff_t *ppos)
2384 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2385 do_proc_dointvec_ms_jiffies_conv, NULL);
2388 static int proc_do_cad_pid(struct ctl_table *table, int write,
2389 void __user *buffer, size_t *lenp, loff_t *ppos)
2391 struct pid *new_pid;
2395 tmp = pid_vnr(cad_pid);
2397 r = __do_proc_dointvec(&tmp, table, write, buffer,
2398 lenp, ppos, NULL, NULL);
2402 new_pid = find_get_pid(tmp);
2406 put_pid(xchg(&cad_pid, new_pid));
2411 * proc_do_large_bitmap - read/write from/to a large bitmap
2412 * @table: the sysctl table
2413 * @write: %TRUE if this is a write to the sysctl file
2414 * @buffer: the user buffer
2415 * @lenp: the size of the user buffer
2416 * @ppos: file position
2418 * The bitmap is stored at table->data and the bitmap length (in bits)
2421 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2422 * large bitmaps may be represented in a compact manner. Writing into
2423 * the file will clear the bitmap then update it with the given input.
2425 * Returns 0 on success.
2427 int proc_do_large_bitmap(struct ctl_table *table, int write,
2428 void __user *buffer, size_t *lenp, loff_t *ppos)
2432 size_t left = *lenp;
2433 unsigned long bitmap_len = table->maxlen;
2434 unsigned long *bitmap = (unsigned long *) table->data;
2435 unsigned long *tmp_bitmap = NULL;
2436 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2438 if (!bitmap_len || !left || (*ppos && !write)) {
2444 unsigned long page = 0;
2447 if (left > PAGE_SIZE - 1)
2448 left = PAGE_SIZE - 1;
2450 page = __get_free_page(GFP_TEMPORARY);
2451 kbuf = (char *) page;
2454 if (copy_from_user(kbuf, buffer, left)) {
2460 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2466 proc_skip_char(&kbuf, &left, '\n');
2467 while (!err && left) {
2468 unsigned long val_a, val_b;
2471 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2475 if (val_a >= bitmap_len || neg) {
2487 err = proc_get_long(&kbuf, &left, &val_b,
2488 &neg, tr_b, sizeof(tr_b),
2492 if (val_b >= bitmap_len || neg ||
2503 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2505 proc_skip_char(&kbuf, &left, '\n');
2509 unsigned long bit_a, bit_b = 0;
2512 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2513 if (bit_a >= bitmap_len)
2515 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2519 err = proc_put_char(&buffer, &left, ',');
2523 err = proc_put_long(&buffer, &left, bit_a, false);
2526 if (bit_a != bit_b) {
2527 err = proc_put_char(&buffer, &left, '-');
2530 err = proc_put_long(&buffer, &left, bit_b, false);
2538 err = proc_put_char(&buffer, &left, '\n');
2544 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2546 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2558 #else /* CONFIG_PROC_SYSCTL */
2560 int proc_dostring(struct ctl_table *table, int write,
2561 void __user *buffer, size_t *lenp, loff_t *ppos)
2566 int proc_dointvec(struct ctl_table *table, int write,
2567 void __user *buffer, size_t *lenp, loff_t *ppos)
2572 int proc_dointvec_minmax(struct ctl_table *table, int write,
2573 void __user *buffer, size_t *lenp, loff_t *ppos)
2578 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2579 void __user *buffer, size_t *lenp, loff_t *ppos)
2584 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2585 void __user *buffer, size_t *lenp, loff_t *ppos)
2590 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2591 void __user *buffer, size_t *lenp, loff_t *ppos)
2596 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2597 void __user *buffer, size_t *lenp, loff_t *ppos)
2602 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2603 void __user *buffer,
2604 size_t *lenp, loff_t *ppos)
2610 #endif /* CONFIG_PROC_SYSCTL */
2613 * No sense putting this after each symbol definition, twice,
2614 * exception granted :-)
2616 EXPORT_SYMBOL(proc_dointvec);
2617 EXPORT_SYMBOL(proc_dointvec_jiffies);
2618 EXPORT_SYMBOL(proc_dointvec_minmax);
2619 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2620 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2621 EXPORT_SYMBOL(proc_dostring);
2622 EXPORT_SYMBOL(proc_doulongvec_minmax);
2623 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);