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 pid_max_min, pid_max_max;
109 extern int percpu_pagelist_fraction;
110 extern int compat_log;
111 extern int latencytop_enabled;
112 extern int sysctl_nr_open_min, sysctl_nr_open_max;
114 extern int sysctl_nr_trim_pages;
117 extern int blk_iopoll_enabled;
120 /* Constants used for minimum and maximum */
121 #ifdef CONFIG_LOCKUP_DETECTOR
122 static int sixty = 60;
126 static int __maybe_unused one = 1;
127 static int __maybe_unused two = 2;
128 static int __maybe_unused three = 3;
129 static unsigned long one_ul = 1;
130 static int one_hundred = 100;
132 static int ten_thousand = 10000;
135 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
136 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
138 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
139 static int maxolduid = 65535;
140 static int minolduid;
141 static int min_percpu_pagelist_fract = 8;
143 static int ngroups_max = NGROUPS_MAX;
144 static const int cap_last_cap = CAP_LAST_CAP;
146 #ifdef CONFIG_INOTIFY_USER
147 #include <linux/inotify.h>
152 #ifdef CONFIG_SPARC64
153 extern int sysctl_tsb_ratio;
157 extern int pwrsw_enabled;
160 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
161 extern int unaligned_enabled;
165 extern int unaligned_dump_stack;
168 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
169 extern int no_unaligned_warning;
172 #ifdef CONFIG_PROC_SYSCTL
173 static int proc_do_cad_pid(struct ctl_table *table, int write,
174 void __user *buffer, size_t *lenp, loff_t *ppos);
175 static int proc_taint(struct ctl_table *table, int write,
176 void __user *buffer, size_t *lenp, loff_t *ppos);
180 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
181 void __user *buffer, size_t *lenp, loff_t *ppos);
184 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
185 void __user *buffer, size_t *lenp, loff_t *ppos);
186 #ifdef CONFIG_COREDUMP
187 static int proc_dostring_coredump(struct ctl_table *table, int write,
188 void __user *buffer, size_t *lenp, loff_t *ppos);
191 #ifdef CONFIG_MAGIC_SYSRQ
192 /* Note: sysrq code uses it's own private copy */
193 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
195 static int sysrq_sysctl_handler(ctl_table *table, int write,
196 void __user *buffer, size_t *lenp,
201 error = proc_dointvec(table, write, buffer, lenp, ppos);
206 sysrq_toggle_support(__sysrq_enabled);
213 static struct ctl_table kern_table[];
214 static struct ctl_table vm_table[];
215 static struct ctl_table fs_table[];
216 static struct ctl_table debug_table[];
217 static struct ctl_table dev_table[];
218 extern struct ctl_table random_table[];
220 extern struct ctl_table epoll_table[];
223 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
224 int sysctl_legacy_va_layout;
227 /* The default sysctl tables: */
229 static struct ctl_table sysctl_base_table[] = {
231 .procname = "kernel",
248 .child = debug_table,
258 #ifdef CONFIG_SCHED_DEBUG
259 static int min_sched_granularity_ns = 100000; /* 100 usecs */
260 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
261 static int min_wakeup_granularity_ns; /* 0 usecs */
262 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
264 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
265 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
266 #endif /* CONFIG_SMP */
267 #endif /* CONFIG_SCHED_DEBUG */
269 #ifdef CONFIG_COMPACTION
270 static int min_extfrag_threshold;
271 static int max_extfrag_threshold = 1000;
274 static struct ctl_table kern_table[] = {
276 .procname = "sched_child_runs_first",
277 .data = &sysctl_sched_child_runs_first,
278 .maxlen = sizeof(unsigned int),
280 .proc_handler = proc_dointvec,
282 #ifdef CONFIG_SCHED_DEBUG
284 .procname = "sched_min_granularity_ns",
285 .data = &sysctl_sched_min_granularity,
286 .maxlen = sizeof(unsigned int),
288 .proc_handler = sched_proc_update_handler,
289 .extra1 = &min_sched_granularity_ns,
290 .extra2 = &max_sched_granularity_ns,
293 .procname = "sched_latency_ns",
294 .data = &sysctl_sched_latency,
295 .maxlen = sizeof(unsigned int),
297 .proc_handler = sched_proc_update_handler,
298 .extra1 = &min_sched_granularity_ns,
299 .extra2 = &max_sched_granularity_ns,
302 .procname = "sched_wakeup_granularity_ns",
303 .data = &sysctl_sched_wakeup_granularity,
304 .maxlen = sizeof(unsigned int),
306 .proc_handler = sched_proc_update_handler,
307 .extra1 = &min_wakeup_granularity_ns,
308 .extra2 = &max_wakeup_granularity_ns,
312 .procname = "sched_tunable_scaling",
313 .data = &sysctl_sched_tunable_scaling,
314 .maxlen = sizeof(enum sched_tunable_scaling),
316 .proc_handler = sched_proc_update_handler,
317 .extra1 = &min_sched_tunable_scaling,
318 .extra2 = &max_sched_tunable_scaling,
321 .procname = "sched_migration_cost_ns",
322 .data = &sysctl_sched_migration_cost,
323 .maxlen = sizeof(unsigned int),
325 .proc_handler = proc_dointvec,
328 .procname = "sched_nr_migrate",
329 .data = &sysctl_sched_nr_migrate,
330 .maxlen = sizeof(unsigned int),
332 .proc_handler = proc_dointvec,
335 .procname = "sched_time_avg_ms",
336 .data = &sysctl_sched_time_avg,
337 .maxlen = sizeof(unsigned int),
339 .proc_handler = proc_dointvec,
342 .procname = "sched_shares_window_ns",
343 .data = &sysctl_sched_shares_window,
344 .maxlen = sizeof(unsigned int),
346 .proc_handler = proc_dointvec,
349 .procname = "timer_migration",
350 .data = &sysctl_timer_migration,
351 .maxlen = sizeof(unsigned int),
353 .proc_handler = proc_dointvec_minmax,
357 #endif /* CONFIG_SMP */
358 #ifdef CONFIG_NUMA_BALANCING
360 .procname = "numa_balancing_scan_delay_ms",
361 .data = &sysctl_numa_balancing_scan_delay,
362 .maxlen = sizeof(unsigned int),
364 .proc_handler = proc_dointvec,
367 .procname = "numa_balancing_scan_period_min_ms",
368 .data = &sysctl_numa_balancing_scan_period_min,
369 .maxlen = sizeof(unsigned int),
371 .proc_handler = proc_dointvec,
374 .procname = "numa_balancing_scan_period_max_ms",
375 .data = &sysctl_numa_balancing_scan_period_max,
376 .maxlen = sizeof(unsigned int),
378 .proc_handler = proc_dointvec,
381 .procname = "numa_balancing_scan_size_mb",
382 .data = &sysctl_numa_balancing_scan_size,
383 .maxlen = sizeof(unsigned int),
385 .proc_handler = proc_dointvec,
388 .procname = "numa_balancing_settle_count",
389 .data = &sysctl_numa_balancing_settle_count,
390 .maxlen = sizeof(unsigned int),
392 .proc_handler = proc_dointvec,
395 .procname = "numa_balancing_migrate_deferred",
396 .data = &sysctl_numa_balancing_migrate_deferred,
397 .maxlen = sizeof(unsigned int),
399 .proc_handler = proc_dointvec,
401 #endif /* CONFIG_NUMA_BALANCING */
402 #endif /* CONFIG_SCHED_DEBUG */
404 .procname = "sched_rt_period_us",
405 .data = &sysctl_sched_rt_period,
406 .maxlen = sizeof(unsigned int),
408 .proc_handler = sched_rt_handler,
411 .procname = "sched_rt_runtime_us",
412 .data = &sysctl_sched_rt_runtime,
413 .maxlen = sizeof(int),
415 .proc_handler = sched_rt_handler,
418 .procname = "sched_rr_timeslice_ms",
419 .data = &sched_rr_timeslice,
420 .maxlen = sizeof(int),
422 .proc_handler = sched_rr_handler,
424 #ifdef CONFIG_SCHED_AUTOGROUP
426 .procname = "sched_autogroup_enabled",
427 .data = &sysctl_sched_autogroup_enabled,
428 .maxlen = sizeof(unsigned int),
430 .proc_handler = proc_dointvec_minmax,
435 #ifdef CONFIG_CFS_BANDWIDTH
437 .procname = "sched_cfs_bandwidth_slice_us",
438 .data = &sysctl_sched_cfs_bandwidth_slice,
439 .maxlen = sizeof(unsigned int),
441 .proc_handler = proc_dointvec_minmax,
445 #ifdef CONFIG_PROVE_LOCKING
447 .procname = "prove_locking",
448 .data = &prove_locking,
449 .maxlen = sizeof(int),
451 .proc_handler = proc_dointvec,
454 #ifdef CONFIG_LOCK_STAT
456 .procname = "lock_stat",
458 .maxlen = sizeof(int),
460 .proc_handler = proc_dointvec,
465 .data = &panic_timeout,
466 .maxlen = sizeof(int),
468 .proc_handler = proc_dointvec,
470 #ifdef CONFIG_COREDUMP
472 .procname = "core_uses_pid",
473 .data = &core_uses_pid,
474 .maxlen = sizeof(int),
476 .proc_handler = proc_dointvec,
479 .procname = "core_pattern",
480 .data = core_pattern,
481 .maxlen = CORENAME_MAX_SIZE,
483 .proc_handler = proc_dostring_coredump,
486 .procname = "core_pipe_limit",
487 .data = &core_pipe_limit,
488 .maxlen = sizeof(unsigned int),
490 .proc_handler = proc_dointvec,
493 #ifdef CONFIG_PROC_SYSCTL
495 .procname = "tainted",
496 .maxlen = sizeof(long),
498 .proc_handler = proc_taint,
501 #ifdef CONFIG_LATENCYTOP
503 .procname = "latencytop",
504 .data = &latencytop_enabled,
505 .maxlen = sizeof(int),
507 .proc_handler = proc_dointvec,
510 #ifdef CONFIG_BLK_DEV_INITRD
512 .procname = "real-root-dev",
513 .data = &real_root_dev,
514 .maxlen = sizeof(int),
516 .proc_handler = proc_dointvec,
520 .procname = "print-fatal-signals",
521 .data = &print_fatal_signals,
522 .maxlen = sizeof(int),
524 .proc_handler = proc_dointvec,
528 .procname = "reboot-cmd",
529 .data = reboot_command,
532 .proc_handler = proc_dostring,
535 .procname = "stop-a",
536 .data = &stop_a_enabled,
537 .maxlen = sizeof (int),
539 .proc_handler = proc_dointvec,
542 .procname = "scons-poweroff",
543 .data = &scons_pwroff,
544 .maxlen = sizeof (int),
546 .proc_handler = proc_dointvec,
549 #ifdef CONFIG_SPARC64
551 .procname = "tsb-ratio",
552 .data = &sysctl_tsb_ratio,
553 .maxlen = sizeof (int),
555 .proc_handler = proc_dointvec,
560 .procname = "soft-power",
561 .data = &pwrsw_enabled,
562 .maxlen = sizeof (int),
564 .proc_handler = proc_dointvec,
567 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
569 .procname = "unaligned-trap",
570 .data = &unaligned_enabled,
571 .maxlen = sizeof (int),
573 .proc_handler = proc_dointvec,
577 .procname = "ctrl-alt-del",
579 .maxlen = sizeof(int),
581 .proc_handler = proc_dointvec,
583 #ifdef CONFIG_FUNCTION_TRACER
585 .procname = "ftrace_enabled",
586 .data = &ftrace_enabled,
587 .maxlen = sizeof(int),
589 .proc_handler = ftrace_enable_sysctl,
592 #ifdef CONFIG_STACK_TRACER
594 .procname = "stack_tracer_enabled",
595 .data = &stack_tracer_enabled,
596 .maxlen = sizeof(int),
598 .proc_handler = stack_trace_sysctl,
601 #ifdef CONFIG_TRACING
603 .procname = "ftrace_dump_on_oops",
604 .data = &ftrace_dump_on_oops,
605 .maxlen = sizeof(int),
607 .proc_handler = proc_dointvec,
610 .procname = "traceoff_on_warning",
611 .data = &__disable_trace_on_warning,
612 .maxlen = sizeof(__disable_trace_on_warning),
614 .proc_handler = proc_dointvec,
617 #ifdef CONFIG_MODULES
619 .procname = "modprobe",
620 .data = &modprobe_path,
621 .maxlen = KMOD_PATH_LEN,
623 .proc_handler = proc_dostring,
626 .procname = "modules_disabled",
627 .data = &modules_disabled,
628 .maxlen = sizeof(int),
630 /* only handle a transition from default "0" to "1" */
631 .proc_handler = proc_dointvec_minmax,
638 .procname = "hotplug",
639 .data = &uevent_helper,
640 .maxlen = UEVENT_HELPER_PATH_LEN,
642 .proc_handler = proc_dostring,
645 #ifdef CONFIG_CHR_DEV_SG
647 .procname = "sg-big-buff",
648 .data = &sg_big_buff,
649 .maxlen = sizeof (int),
651 .proc_handler = proc_dointvec,
654 #ifdef CONFIG_BSD_PROCESS_ACCT
658 .maxlen = 3*sizeof(int),
660 .proc_handler = proc_dointvec,
663 #ifdef CONFIG_MAGIC_SYSRQ
666 .data = &__sysrq_enabled,
667 .maxlen = sizeof (int),
669 .proc_handler = sysrq_sysctl_handler,
672 #ifdef CONFIG_PROC_SYSCTL
674 .procname = "cad_pid",
676 .maxlen = sizeof (int),
678 .proc_handler = proc_do_cad_pid,
682 .procname = "threads-max",
683 .data = &max_threads,
684 .maxlen = sizeof(int),
686 .proc_handler = proc_dointvec,
689 .procname = "random",
691 .child = random_table,
694 .procname = "usermodehelper",
696 .child = usermodehelper_table,
699 .procname = "overflowuid",
700 .data = &overflowuid,
701 .maxlen = sizeof(int),
703 .proc_handler = proc_dointvec_minmax,
704 .extra1 = &minolduid,
705 .extra2 = &maxolduid,
708 .procname = "overflowgid",
709 .data = &overflowgid,
710 .maxlen = sizeof(int),
712 .proc_handler = proc_dointvec_minmax,
713 .extra1 = &minolduid,
714 .extra2 = &maxolduid,
717 #ifdef CONFIG_MATHEMU
719 .procname = "ieee_emulation_warnings",
720 .data = &sysctl_ieee_emulation_warnings,
721 .maxlen = sizeof(int),
723 .proc_handler = proc_dointvec,
727 .procname = "userprocess_debug",
728 .data = &show_unhandled_signals,
729 .maxlen = sizeof(int),
731 .proc_handler = proc_dointvec,
735 .procname = "pid_max",
737 .maxlen = sizeof (int),
739 .proc_handler = proc_dointvec_minmax,
740 .extra1 = &pid_max_min,
741 .extra2 = &pid_max_max,
744 .procname = "panic_on_oops",
745 .data = &panic_on_oops,
746 .maxlen = sizeof(int),
748 .proc_handler = proc_dointvec,
750 #if defined CONFIG_PRINTK
752 .procname = "printk",
753 .data = &console_loglevel,
754 .maxlen = 4*sizeof(int),
756 .proc_handler = proc_dointvec,
759 .procname = "printk_ratelimit",
760 .data = &printk_ratelimit_state.interval,
761 .maxlen = sizeof(int),
763 .proc_handler = proc_dointvec_jiffies,
766 .procname = "printk_ratelimit_burst",
767 .data = &printk_ratelimit_state.burst,
768 .maxlen = sizeof(int),
770 .proc_handler = proc_dointvec,
773 .procname = "printk_delay",
774 .data = &printk_delay_msec,
775 .maxlen = sizeof(int),
777 .proc_handler = proc_dointvec_minmax,
779 .extra2 = &ten_thousand,
782 .procname = "dmesg_restrict",
783 .data = &dmesg_restrict,
784 .maxlen = sizeof(int),
786 .proc_handler = proc_dointvec_minmax_sysadmin,
791 .procname = "kptr_restrict",
792 .data = &kptr_restrict,
793 .maxlen = sizeof(int),
795 .proc_handler = proc_dointvec_minmax_sysadmin,
801 .procname = "ngroups_max",
802 .data = &ngroups_max,
803 .maxlen = sizeof (int),
805 .proc_handler = proc_dointvec,
808 .procname = "cap_last_cap",
809 .data = (void *)&cap_last_cap,
810 .maxlen = sizeof(int),
812 .proc_handler = proc_dointvec,
814 #if defined(CONFIG_LOCKUP_DETECTOR)
816 .procname = "watchdog",
817 .data = &watchdog_user_enabled,
818 .maxlen = sizeof (int),
820 .proc_handler = proc_dowatchdog,
825 .procname = "watchdog_thresh",
826 .data = &watchdog_thresh,
827 .maxlen = sizeof(int),
829 .proc_handler = proc_dowatchdog,
834 .procname = "softlockup_panic",
835 .data = &softlockup_panic,
836 .maxlen = sizeof(int),
838 .proc_handler = proc_dointvec_minmax,
843 .procname = "nmi_watchdog",
844 .data = &watchdog_user_enabled,
845 .maxlen = sizeof (int),
847 .proc_handler = proc_dowatchdog,
852 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
854 .procname = "unknown_nmi_panic",
855 .data = &unknown_nmi_panic,
856 .maxlen = sizeof (int),
858 .proc_handler = proc_dointvec,
861 #if defined(CONFIG_X86)
863 .procname = "panic_on_unrecovered_nmi",
864 .data = &panic_on_unrecovered_nmi,
865 .maxlen = sizeof(int),
867 .proc_handler = proc_dointvec,
870 .procname = "panic_on_io_nmi",
871 .data = &panic_on_io_nmi,
872 .maxlen = sizeof(int),
874 .proc_handler = proc_dointvec,
876 #ifdef CONFIG_DEBUG_STACKOVERFLOW
878 .procname = "panic_on_stackoverflow",
879 .data = &sysctl_panic_on_stackoverflow,
880 .maxlen = sizeof(int),
882 .proc_handler = proc_dointvec,
886 .procname = "bootloader_type",
887 .data = &bootloader_type,
888 .maxlen = sizeof (int),
890 .proc_handler = proc_dointvec,
893 .procname = "bootloader_version",
894 .data = &bootloader_version,
895 .maxlen = sizeof (int),
897 .proc_handler = proc_dointvec,
900 .procname = "kstack_depth_to_print",
901 .data = &kstack_depth_to_print,
902 .maxlen = sizeof(int),
904 .proc_handler = proc_dointvec,
907 .procname = "io_delay_type",
908 .data = &io_delay_type,
909 .maxlen = sizeof(int),
911 .proc_handler = proc_dointvec,
914 #if defined(CONFIG_MMU)
916 .procname = "randomize_va_space",
917 .data = &randomize_va_space,
918 .maxlen = sizeof(int),
920 .proc_handler = proc_dointvec,
923 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
925 .procname = "spin_retry",
927 .maxlen = sizeof (int),
929 .proc_handler = proc_dointvec,
932 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
934 .procname = "acpi_video_flags",
935 .data = &acpi_realmode_flags,
936 .maxlen = sizeof (unsigned long),
938 .proc_handler = proc_doulongvec_minmax,
941 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
943 .procname = "ignore-unaligned-usertrap",
944 .data = &no_unaligned_warning,
945 .maxlen = sizeof (int),
947 .proc_handler = proc_dointvec,
952 .procname = "unaligned-dump-stack",
953 .data = &unaligned_dump_stack,
954 .maxlen = sizeof (int),
956 .proc_handler = proc_dointvec,
959 #ifdef CONFIG_DETECT_HUNG_TASK
961 .procname = "hung_task_panic",
962 .data = &sysctl_hung_task_panic,
963 .maxlen = sizeof(int),
965 .proc_handler = proc_dointvec_minmax,
970 .procname = "hung_task_check_count",
971 .data = &sysctl_hung_task_check_count,
972 .maxlen = sizeof(int),
974 .proc_handler = proc_dointvec_minmax,
978 .procname = "hung_task_timeout_secs",
979 .data = &sysctl_hung_task_timeout_secs,
980 .maxlen = sizeof(unsigned long),
982 .proc_handler = proc_dohung_task_timeout_secs,
985 .procname = "hung_task_warnings",
986 .data = &sysctl_hung_task_warnings,
987 .maxlen = sizeof(unsigned long),
989 .proc_handler = proc_doulongvec_minmax,
994 .procname = "compat-log",
996 .maxlen = sizeof (int),
998 .proc_handler = proc_dointvec,
1001 #ifdef CONFIG_RT_MUTEXES
1003 .procname = "max_lock_depth",
1004 .data = &max_lock_depth,
1005 .maxlen = sizeof(int),
1007 .proc_handler = proc_dointvec,
1011 .procname = "poweroff_cmd",
1012 .data = &poweroff_cmd,
1013 .maxlen = POWEROFF_CMD_PATH_LEN,
1015 .proc_handler = proc_dostring,
1021 .child = key_sysctls,
1024 #ifdef CONFIG_RCU_TORTURE_TEST
1026 .procname = "rcutorture_runnable",
1027 .data = &rcutorture_runnable,
1028 .maxlen = sizeof(int),
1030 .proc_handler = proc_dointvec,
1033 #ifdef CONFIG_PERF_EVENTS
1035 * User-space scripts rely on the existence of this file
1036 * as a feature check for perf_events being enabled.
1038 * So it's an ABI, do not remove!
1041 .procname = "perf_event_paranoid",
1042 .data = &sysctl_perf_event_paranoid,
1043 .maxlen = sizeof(sysctl_perf_event_paranoid),
1045 .proc_handler = proc_dointvec,
1048 .procname = "perf_event_mlock_kb",
1049 .data = &sysctl_perf_event_mlock,
1050 .maxlen = sizeof(sysctl_perf_event_mlock),
1052 .proc_handler = proc_dointvec,
1055 .procname = "perf_event_max_sample_rate",
1056 .data = &sysctl_perf_event_sample_rate,
1057 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1059 .proc_handler = perf_proc_update_handler,
1063 .procname = "perf_cpu_time_max_percent",
1064 .data = &sysctl_perf_cpu_time_max_percent,
1065 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1067 .proc_handler = perf_cpu_time_max_percent_handler,
1069 .extra2 = &one_hundred,
1072 #ifdef CONFIG_KMEMCHECK
1074 .procname = "kmemcheck",
1075 .data = &kmemcheck_enabled,
1076 .maxlen = sizeof(int),
1078 .proc_handler = proc_dointvec,
1083 .procname = "blk_iopoll",
1084 .data = &blk_iopoll_enabled,
1085 .maxlen = sizeof(int),
1087 .proc_handler = proc_dointvec,
1093 static struct ctl_table vm_table[] = {
1095 .procname = "overcommit_memory",
1096 .data = &sysctl_overcommit_memory,
1097 .maxlen = sizeof(sysctl_overcommit_memory),
1099 .proc_handler = proc_dointvec_minmax,
1104 .procname = "panic_on_oom",
1105 .data = &sysctl_panic_on_oom,
1106 .maxlen = sizeof(sysctl_panic_on_oom),
1108 .proc_handler = proc_dointvec_minmax,
1113 .procname = "oom_kill_allocating_task",
1114 .data = &sysctl_oom_kill_allocating_task,
1115 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1117 .proc_handler = proc_dointvec,
1120 .procname = "oom_dump_tasks",
1121 .data = &sysctl_oom_dump_tasks,
1122 .maxlen = sizeof(sysctl_oom_dump_tasks),
1124 .proc_handler = proc_dointvec,
1127 .procname = "overcommit_ratio",
1128 .data = &sysctl_overcommit_ratio,
1129 .maxlen = sizeof(sysctl_overcommit_ratio),
1131 .proc_handler = proc_dointvec,
1134 .procname = "page-cluster",
1135 .data = &page_cluster,
1136 .maxlen = sizeof(int),
1138 .proc_handler = proc_dointvec_minmax,
1142 .procname = "dirty_background_ratio",
1143 .data = &dirty_background_ratio,
1144 .maxlen = sizeof(dirty_background_ratio),
1146 .proc_handler = dirty_background_ratio_handler,
1148 .extra2 = &one_hundred,
1151 .procname = "dirty_background_bytes",
1152 .data = &dirty_background_bytes,
1153 .maxlen = sizeof(dirty_background_bytes),
1155 .proc_handler = dirty_background_bytes_handler,
1159 .procname = "dirty_ratio",
1160 .data = &vm_dirty_ratio,
1161 .maxlen = sizeof(vm_dirty_ratio),
1163 .proc_handler = dirty_ratio_handler,
1165 .extra2 = &one_hundred,
1168 .procname = "dirty_bytes",
1169 .data = &vm_dirty_bytes,
1170 .maxlen = sizeof(vm_dirty_bytes),
1172 .proc_handler = dirty_bytes_handler,
1173 .extra1 = &dirty_bytes_min,
1176 .procname = "dirty_writeback_centisecs",
1177 .data = &dirty_writeback_interval,
1178 .maxlen = sizeof(dirty_writeback_interval),
1180 .proc_handler = dirty_writeback_centisecs_handler,
1183 .procname = "dirty_expire_centisecs",
1184 .data = &dirty_expire_interval,
1185 .maxlen = sizeof(dirty_expire_interval),
1187 .proc_handler = proc_dointvec_minmax,
1191 .procname = "nr_pdflush_threads",
1192 .mode = 0444 /* read-only */,
1193 .proc_handler = pdflush_proc_obsolete,
1196 .procname = "swappiness",
1197 .data = &vm_swappiness,
1198 .maxlen = sizeof(vm_swappiness),
1200 .proc_handler = proc_dointvec_minmax,
1202 .extra2 = &one_hundred,
1204 #ifdef CONFIG_HUGETLB_PAGE
1206 .procname = "nr_hugepages",
1208 .maxlen = sizeof(unsigned long),
1210 .proc_handler = hugetlb_sysctl_handler,
1211 .extra1 = (void *)&hugetlb_zero,
1212 .extra2 = (void *)&hugetlb_infinity,
1216 .procname = "nr_hugepages_mempolicy",
1218 .maxlen = sizeof(unsigned long),
1220 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1221 .extra1 = (void *)&hugetlb_zero,
1222 .extra2 = (void *)&hugetlb_infinity,
1226 .procname = "hugetlb_shm_group",
1227 .data = &sysctl_hugetlb_shm_group,
1228 .maxlen = sizeof(gid_t),
1230 .proc_handler = proc_dointvec,
1233 .procname = "hugepages_treat_as_movable",
1234 .data = &hugepages_treat_as_movable,
1235 .maxlen = sizeof(int),
1237 .proc_handler = proc_dointvec,
1240 .procname = "nr_overcommit_hugepages",
1242 .maxlen = sizeof(unsigned long),
1244 .proc_handler = hugetlb_overcommit_handler,
1245 .extra1 = (void *)&hugetlb_zero,
1246 .extra2 = (void *)&hugetlb_infinity,
1250 .procname = "lowmem_reserve_ratio",
1251 .data = &sysctl_lowmem_reserve_ratio,
1252 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1254 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1257 .procname = "drop_caches",
1258 .data = &sysctl_drop_caches,
1259 .maxlen = sizeof(int),
1261 .proc_handler = drop_caches_sysctl_handler,
1265 #ifdef CONFIG_COMPACTION
1267 .procname = "compact_memory",
1268 .data = &sysctl_compact_memory,
1269 .maxlen = sizeof(int),
1271 .proc_handler = sysctl_compaction_handler,
1274 .procname = "extfrag_threshold",
1275 .data = &sysctl_extfrag_threshold,
1276 .maxlen = sizeof(int),
1278 .proc_handler = sysctl_extfrag_handler,
1279 .extra1 = &min_extfrag_threshold,
1280 .extra2 = &max_extfrag_threshold,
1283 #endif /* CONFIG_COMPACTION */
1285 .procname = "min_free_kbytes",
1286 .data = &min_free_kbytes,
1287 .maxlen = sizeof(min_free_kbytes),
1289 .proc_handler = min_free_kbytes_sysctl_handler,
1293 .procname = "percpu_pagelist_fraction",
1294 .data = &percpu_pagelist_fraction,
1295 .maxlen = sizeof(percpu_pagelist_fraction),
1297 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1298 .extra1 = &min_percpu_pagelist_fract,
1302 .procname = "max_map_count",
1303 .data = &sysctl_max_map_count,
1304 .maxlen = sizeof(sysctl_max_map_count),
1306 .proc_handler = proc_dointvec_minmax,
1311 .procname = "nr_trim_pages",
1312 .data = &sysctl_nr_trim_pages,
1313 .maxlen = sizeof(sysctl_nr_trim_pages),
1315 .proc_handler = proc_dointvec_minmax,
1320 .procname = "laptop_mode",
1321 .data = &laptop_mode,
1322 .maxlen = sizeof(laptop_mode),
1324 .proc_handler = proc_dointvec_jiffies,
1327 .procname = "block_dump",
1328 .data = &block_dump,
1329 .maxlen = sizeof(block_dump),
1331 .proc_handler = proc_dointvec,
1335 .procname = "vfs_cache_pressure",
1336 .data = &sysctl_vfs_cache_pressure,
1337 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1339 .proc_handler = proc_dointvec,
1342 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1344 .procname = "legacy_va_layout",
1345 .data = &sysctl_legacy_va_layout,
1346 .maxlen = sizeof(sysctl_legacy_va_layout),
1348 .proc_handler = proc_dointvec,
1354 .procname = "zone_reclaim_mode",
1355 .data = &zone_reclaim_mode,
1356 .maxlen = sizeof(zone_reclaim_mode),
1358 .proc_handler = proc_dointvec,
1362 .procname = "min_unmapped_ratio",
1363 .data = &sysctl_min_unmapped_ratio,
1364 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1366 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1368 .extra2 = &one_hundred,
1371 .procname = "min_slab_ratio",
1372 .data = &sysctl_min_slab_ratio,
1373 .maxlen = sizeof(sysctl_min_slab_ratio),
1375 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1377 .extra2 = &one_hundred,
1382 .procname = "stat_interval",
1383 .data = &sysctl_stat_interval,
1384 .maxlen = sizeof(sysctl_stat_interval),
1386 .proc_handler = proc_dointvec_jiffies,
1391 .procname = "mmap_min_addr",
1392 .data = &dac_mmap_min_addr,
1393 .maxlen = sizeof(unsigned long),
1395 .proc_handler = mmap_min_addr_handler,
1400 .procname = "numa_zonelist_order",
1401 .data = &numa_zonelist_order,
1402 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1404 .proc_handler = numa_zonelist_order_handler,
1407 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1408 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1410 .procname = "vdso_enabled",
1411 .data = &vdso_enabled,
1412 .maxlen = sizeof(vdso_enabled),
1414 .proc_handler = proc_dointvec,
1418 #ifdef CONFIG_HIGHMEM
1420 .procname = "highmem_is_dirtyable",
1421 .data = &vm_highmem_is_dirtyable,
1422 .maxlen = sizeof(vm_highmem_is_dirtyable),
1424 .proc_handler = proc_dointvec_minmax,
1430 .procname = "scan_unevictable_pages",
1431 .data = &scan_unevictable_pages,
1432 .maxlen = sizeof(scan_unevictable_pages),
1434 .proc_handler = scan_unevictable_handler,
1436 #ifdef CONFIG_MEMORY_FAILURE
1438 .procname = "memory_failure_early_kill",
1439 .data = &sysctl_memory_failure_early_kill,
1440 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1442 .proc_handler = proc_dointvec_minmax,
1447 .procname = "memory_failure_recovery",
1448 .data = &sysctl_memory_failure_recovery,
1449 .maxlen = sizeof(sysctl_memory_failure_recovery),
1451 .proc_handler = proc_dointvec_minmax,
1457 .procname = "user_reserve_kbytes",
1458 .data = &sysctl_user_reserve_kbytes,
1459 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1461 .proc_handler = proc_doulongvec_minmax,
1464 .procname = "admin_reserve_kbytes",
1465 .data = &sysctl_admin_reserve_kbytes,
1466 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1468 .proc_handler = proc_doulongvec_minmax,
1473 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1474 static struct ctl_table binfmt_misc_table[] = {
1479 static struct ctl_table fs_table[] = {
1481 .procname = "inode-nr",
1482 .data = &inodes_stat,
1483 .maxlen = 2*sizeof(long),
1485 .proc_handler = proc_nr_inodes,
1488 .procname = "inode-state",
1489 .data = &inodes_stat,
1490 .maxlen = 7*sizeof(long),
1492 .proc_handler = proc_nr_inodes,
1495 .procname = "file-nr",
1496 .data = &files_stat,
1497 .maxlen = sizeof(files_stat),
1499 .proc_handler = proc_nr_files,
1502 .procname = "file-max",
1503 .data = &files_stat.max_files,
1504 .maxlen = sizeof(files_stat.max_files),
1506 .proc_handler = proc_doulongvec_minmax,
1509 .procname = "nr_open",
1510 .data = &sysctl_nr_open,
1511 .maxlen = sizeof(int),
1513 .proc_handler = proc_dointvec_minmax,
1514 .extra1 = &sysctl_nr_open_min,
1515 .extra2 = &sysctl_nr_open_max,
1518 .procname = "dentry-state",
1519 .data = &dentry_stat,
1520 .maxlen = 6*sizeof(long),
1522 .proc_handler = proc_nr_dentry,
1525 .procname = "overflowuid",
1526 .data = &fs_overflowuid,
1527 .maxlen = sizeof(int),
1529 .proc_handler = proc_dointvec_minmax,
1530 .extra1 = &minolduid,
1531 .extra2 = &maxolduid,
1534 .procname = "overflowgid",
1535 .data = &fs_overflowgid,
1536 .maxlen = sizeof(int),
1538 .proc_handler = proc_dointvec_minmax,
1539 .extra1 = &minolduid,
1540 .extra2 = &maxolduid,
1542 #ifdef CONFIG_FILE_LOCKING
1544 .procname = "leases-enable",
1545 .data = &leases_enable,
1546 .maxlen = sizeof(int),
1548 .proc_handler = proc_dointvec,
1551 #ifdef CONFIG_DNOTIFY
1553 .procname = "dir-notify-enable",
1554 .data = &dir_notify_enable,
1555 .maxlen = sizeof(int),
1557 .proc_handler = proc_dointvec,
1561 #ifdef CONFIG_FILE_LOCKING
1563 .procname = "lease-break-time",
1564 .data = &lease_break_time,
1565 .maxlen = sizeof(int),
1567 .proc_handler = proc_dointvec,
1572 .procname = "aio-nr",
1574 .maxlen = sizeof(aio_nr),
1576 .proc_handler = proc_doulongvec_minmax,
1579 .procname = "aio-max-nr",
1580 .data = &aio_max_nr,
1581 .maxlen = sizeof(aio_max_nr),
1583 .proc_handler = proc_doulongvec_minmax,
1585 #endif /* CONFIG_AIO */
1586 #ifdef CONFIG_INOTIFY_USER
1588 .procname = "inotify",
1590 .child = inotify_table,
1595 .procname = "epoll",
1597 .child = epoll_table,
1602 .procname = "protected_symlinks",
1603 .data = &sysctl_protected_symlinks,
1604 .maxlen = sizeof(int),
1606 .proc_handler = proc_dointvec_minmax,
1611 .procname = "protected_hardlinks",
1612 .data = &sysctl_protected_hardlinks,
1613 .maxlen = sizeof(int),
1615 .proc_handler = proc_dointvec_minmax,
1620 .procname = "suid_dumpable",
1621 .data = &suid_dumpable,
1622 .maxlen = sizeof(int),
1624 .proc_handler = proc_dointvec_minmax_coredump,
1628 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1630 .procname = "binfmt_misc",
1632 .child = binfmt_misc_table,
1636 .procname = "pipe-max-size",
1637 .data = &pipe_max_size,
1638 .maxlen = sizeof(int),
1640 .proc_handler = &pipe_proc_fn,
1641 .extra1 = &pipe_min_size,
1646 static struct ctl_table debug_table[] = {
1647 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1649 .procname = "exception-trace",
1650 .data = &show_unhandled_signals,
1651 .maxlen = sizeof(int),
1653 .proc_handler = proc_dointvec
1656 #if defined(CONFIG_OPTPROBES)
1658 .procname = "kprobes-optimization",
1659 .data = &sysctl_kprobes_optimization,
1660 .maxlen = sizeof(int),
1662 .proc_handler = proc_kprobes_optimization_handler,
1670 static struct ctl_table dev_table[] = {
1674 int __init sysctl_init(void)
1676 struct ctl_table_header *hdr;
1678 hdr = register_sysctl_table(sysctl_base_table);
1679 kmemleak_not_leak(hdr);
1683 #endif /* CONFIG_SYSCTL */
1689 #ifdef CONFIG_PROC_SYSCTL
1691 static int _proc_do_string(void* data, int maxlen, int write,
1692 void __user *buffer,
1693 size_t *lenp, loff_t *ppos)
1699 if (!data || !maxlen || !*lenp) {
1707 while (len < *lenp) {
1708 if (get_user(c, p++))
1710 if (c == 0 || c == '\n')
1716 if(copy_from_user(data, buffer, len))
1718 ((char *) data)[len] = 0;
1736 if(copy_to_user(buffer, data, len))
1739 if(put_user('\n', ((char __user *) buffer) + len))
1750 * proc_dostring - read a string sysctl
1751 * @table: the sysctl table
1752 * @write: %TRUE if this is a write to the sysctl file
1753 * @buffer: the user buffer
1754 * @lenp: the size of the user buffer
1755 * @ppos: file position
1757 * Reads/writes a string from/to the user buffer. If the kernel
1758 * buffer provided is not large enough to hold the string, the
1759 * string is truncated. The copied string is %NULL-terminated.
1760 * If the string is being read by the user process, it is copied
1761 * and a newline '\n' is added. It is truncated if the buffer is
1764 * Returns 0 on success.
1766 int proc_dostring(struct ctl_table *table, int write,
1767 void __user *buffer, size_t *lenp, loff_t *ppos)
1769 return _proc_do_string(table->data, table->maxlen, write,
1770 buffer, lenp, ppos);
1773 static size_t proc_skip_spaces(char **buf)
1776 char *tmp = skip_spaces(*buf);
1782 static void proc_skip_char(char **buf, size_t *size, const char v)
1792 #define TMPBUFLEN 22
1794 * proc_get_long - reads an ASCII formatted integer from a user buffer
1796 * @buf: a kernel buffer
1797 * @size: size of the kernel buffer
1798 * @val: this is where the number will be stored
1799 * @neg: set to %TRUE if number is negative
1800 * @perm_tr: a vector which contains the allowed trailers
1801 * @perm_tr_len: size of the perm_tr vector
1802 * @tr: pointer to store the trailer character
1804 * In case of success %0 is returned and @buf and @size are updated with
1805 * the amount of bytes read. If @tr is non-NULL and a trailing
1806 * character exists (size is non-zero after returning from this
1807 * function), @tr is updated with the trailing character.
1809 static int proc_get_long(char **buf, size_t *size,
1810 unsigned long *val, bool *neg,
1811 const char *perm_tr, unsigned perm_tr_len, char *tr)
1814 char *p, tmp[TMPBUFLEN];
1820 if (len > TMPBUFLEN - 1)
1821 len = TMPBUFLEN - 1;
1823 memcpy(tmp, *buf, len);
1827 if (*p == '-' && *size > 1) {
1835 *val = simple_strtoul(p, &p, 0);
1839 /* We don't know if the next char is whitespace thus we may accept
1840 * invalid integers (e.g. 1234...a) or two integers instead of one
1841 * (e.g. 123...1). So lets not allow such large numbers. */
1842 if (len == TMPBUFLEN - 1)
1845 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1848 if (tr && (len < *size))
1858 * proc_put_long - converts an integer to a decimal ASCII formatted string
1860 * @buf: the user buffer
1861 * @size: the size of the user buffer
1862 * @val: the integer to be converted
1863 * @neg: sign of the number, %TRUE for negative
1865 * In case of success %0 is returned and @buf and @size are updated with
1866 * the amount of bytes written.
1868 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1872 char tmp[TMPBUFLEN], *p = tmp;
1874 sprintf(p, "%s%lu", neg ? "-" : "", val);
1878 if (copy_to_user(*buf, tmp, len))
1886 static int proc_put_char(void __user **buf, size_t *size, char c)
1889 char __user **buffer = (char __user **)buf;
1890 if (put_user(c, *buffer))
1892 (*size)--, (*buffer)++;
1898 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1900 int write, void *data)
1903 *valp = *negp ? -*lvalp : *lvalp;
1908 *lvalp = (unsigned long)-val;
1911 *lvalp = (unsigned long)val;
1917 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1919 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1920 int write, void __user *buffer,
1921 size_t *lenp, loff_t *ppos,
1922 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1923 int write, void *data),
1926 int *i, vleft, first = 1, err = 0;
1927 unsigned long page = 0;
1931 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1936 i = (int *) tbl_data;
1937 vleft = table->maxlen / sizeof(*i);
1941 conv = do_proc_dointvec_conv;
1944 if (left > PAGE_SIZE - 1)
1945 left = PAGE_SIZE - 1;
1946 page = __get_free_page(GFP_TEMPORARY);
1947 kbuf = (char *) page;
1950 if (copy_from_user(kbuf, buffer, left)) {
1957 for (; left && vleft--; i++, first=0) {
1962 left -= proc_skip_spaces(&kbuf);
1966 err = proc_get_long(&kbuf, &left, &lval, &neg,
1968 sizeof(proc_wspace_sep), NULL);
1971 if (conv(&neg, &lval, i, 1, data)) {
1976 if (conv(&neg, &lval, i, 0, data)) {
1981 err = proc_put_char(&buffer, &left, '\t');
1984 err = proc_put_long(&buffer, &left, lval, neg);
1990 if (!write && !first && left && !err)
1991 err = proc_put_char(&buffer, &left, '\n');
1992 if (write && !err && left)
1993 left -= proc_skip_spaces(&kbuf);
1998 return err ? : -EINVAL;
2005 static int do_proc_dointvec(struct ctl_table *table, int write,
2006 void __user *buffer, size_t *lenp, loff_t *ppos,
2007 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2008 int write, void *data),
2011 return __do_proc_dointvec(table->data, table, write,
2012 buffer, lenp, ppos, conv, data);
2016 * proc_dointvec - read a vector of integers
2017 * @table: the sysctl table
2018 * @write: %TRUE if this is a write to the sysctl file
2019 * @buffer: the user buffer
2020 * @lenp: the size of the user buffer
2021 * @ppos: file position
2023 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2024 * values from/to the user buffer, treated as an ASCII string.
2026 * Returns 0 on success.
2028 int proc_dointvec(struct ctl_table *table, int write,
2029 void __user *buffer, size_t *lenp, loff_t *ppos)
2031 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2036 * Taint values can only be increased
2037 * This means we can safely use a temporary.
2039 static int proc_taint(struct ctl_table *table, int write,
2040 void __user *buffer, size_t *lenp, loff_t *ppos)
2043 unsigned long tmptaint = get_taint();
2046 if (write && !capable(CAP_SYS_ADMIN))
2051 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2057 * Poor man's atomic or. Not worth adding a primitive
2058 * to everyone's atomic.h for this
2061 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2062 if ((tmptaint >> i) & 1)
2063 add_taint(i, LOCKDEP_STILL_OK);
2070 #ifdef CONFIG_PRINTK
2071 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2072 void __user *buffer, size_t *lenp, loff_t *ppos)
2074 if (write && !capable(CAP_SYS_ADMIN))
2077 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2081 struct do_proc_dointvec_minmax_conv_param {
2086 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2088 int write, void *data)
2090 struct do_proc_dointvec_minmax_conv_param *param = data;
2092 int val = *negp ? -*lvalp : *lvalp;
2093 if ((param->min && *param->min > val) ||
2094 (param->max && *param->max < val))
2101 *lvalp = (unsigned long)-val;
2104 *lvalp = (unsigned long)val;
2111 * proc_dointvec_minmax - read a vector of integers with min/max values
2112 * @table: the sysctl table
2113 * @write: %TRUE if this is a write to the sysctl file
2114 * @buffer: the user buffer
2115 * @lenp: the size of the user buffer
2116 * @ppos: file position
2118 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2119 * values from/to the user buffer, treated as an ASCII string.
2121 * This routine will ensure the values are within the range specified by
2122 * table->extra1 (min) and table->extra2 (max).
2124 * Returns 0 on success.
2126 int proc_dointvec_minmax(struct ctl_table *table, int write,
2127 void __user *buffer, size_t *lenp, loff_t *ppos)
2129 struct do_proc_dointvec_minmax_conv_param param = {
2130 .min = (int *) table->extra1,
2131 .max = (int *) table->extra2,
2133 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2134 do_proc_dointvec_minmax_conv, ¶m);
2137 static void validate_coredump_safety(void)
2139 #ifdef CONFIG_COREDUMP
2140 if (suid_dumpable == SUID_DUMP_ROOT &&
2141 core_pattern[0] != '/' && core_pattern[0] != '|') {
2142 printk(KERN_WARNING "Unsafe core_pattern used with "\
2143 "suid_dumpable=2. Pipe handler or fully qualified "\
2144 "core dump path required.\n");
2149 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2150 void __user *buffer, size_t *lenp, loff_t *ppos)
2152 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2154 validate_coredump_safety();
2158 #ifdef CONFIG_COREDUMP
2159 static int proc_dostring_coredump(struct ctl_table *table, int write,
2160 void __user *buffer, size_t *lenp, loff_t *ppos)
2162 int error = proc_dostring(table, write, buffer, lenp, ppos);
2164 validate_coredump_safety();
2169 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2170 void __user *buffer,
2171 size_t *lenp, loff_t *ppos,
2172 unsigned long convmul,
2173 unsigned long convdiv)
2175 unsigned long *i, *min, *max;
2176 int vleft, first = 1, err = 0;
2177 unsigned long page = 0;
2181 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2186 i = (unsigned long *) data;
2187 min = (unsigned long *) table->extra1;
2188 max = (unsigned long *) table->extra2;
2189 vleft = table->maxlen / sizeof(unsigned long);
2193 if (left > PAGE_SIZE - 1)
2194 left = PAGE_SIZE - 1;
2195 page = __get_free_page(GFP_TEMPORARY);
2196 kbuf = (char *) page;
2199 if (copy_from_user(kbuf, buffer, left)) {
2206 for (; left && vleft--; i++, first = 0) {
2212 left -= proc_skip_spaces(&kbuf);
2214 err = proc_get_long(&kbuf, &left, &val, &neg,
2216 sizeof(proc_wspace_sep), NULL);
2221 if ((min && val < *min) || (max && val > *max))
2225 val = convdiv * (*i) / convmul;
2227 err = proc_put_char(&buffer, &left, '\t');
2231 err = proc_put_long(&buffer, &left, val, false);
2237 if (!write && !first && left && !err)
2238 err = proc_put_char(&buffer, &left, '\n');
2240 left -= proc_skip_spaces(&kbuf);
2245 return err ? : -EINVAL;
2252 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2253 void __user *buffer,
2254 size_t *lenp, loff_t *ppos,
2255 unsigned long convmul,
2256 unsigned long convdiv)
2258 return __do_proc_doulongvec_minmax(table->data, table, write,
2259 buffer, lenp, ppos, convmul, convdiv);
2263 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2264 * @table: the sysctl table
2265 * @write: %TRUE if this is a write to the sysctl file
2266 * @buffer: the user buffer
2267 * @lenp: the size of the user buffer
2268 * @ppos: file position
2270 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2271 * values from/to the user buffer, treated as an ASCII string.
2273 * This routine will ensure the values are within the range specified by
2274 * table->extra1 (min) and table->extra2 (max).
2276 * Returns 0 on success.
2278 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2279 void __user *buffer, size_t *lenp, loff_t *ppos)
2281 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2285 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2286 * @table: the sysctl table
2287 * @write: %TRUE if this is a write to the sysctl file
2288 * @buffer: the user buffer
2289 * @lenp: the size of the user buffer
2290 * @ppos: file position
2292 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2293 * values from/to the user buffer, treated as an ASCII string. The values
2294 * are treated as milliseconds, and converted to jiffies when they are stored.
2296 * This routine will ensure the values are within the range specified by
2297 * table->extra1 (min) and table->extra2 (max).
2299 * Returns 0 on success.
2301 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2302 void __user *buffer,
2303 size_t *lenp, loff_t *ppos)
2305 return do_proc_doulongvec_minmax(table, write, buffer,
2306 lenp, ppos, HZ, 1000l);
2310 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2312 int write, void *data)
2315 if (*lvalp > LONG_MAX / HZ)
2317 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2323 lval = (unsigned long)-val;
2326 lval = (unsigned long)val;
2333 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2335 int write, void *data)
2338 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2340 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2346 lval = (unsigned long)-val;
2349 lval = (unsigned long)val;
2351 *lvalp = jiffies_to_clock_t(lval);
2356 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2358 int write, void *data)
2361 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2371 lval = (unsigned long)-val;
2374 lval = (unsigned long)val;
2376 *lvalp = jiffies_to_msecs(lval);
2382 * proc_dointvec_jiffies - read a vector of integers as seconds
2383 * @table: the sysctl table
2384 * @write: %TRUE if this is a write to the sysctl file
2385 * @buffer: the user buffer
2386 * @lenp: the size of the user buffer
2387 * @ppos: file position
2389 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2390 * values from/to the user buffer, treated as an ASCII string.
2391 * The values read are assumed to be in seconds, and are converted into
2394 * Returns 0 on success.
2396 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2397 void __user *buffer, size_t *lenp, loff_t *ppos)
2399 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2400 do_proc_dointvec_jiffies_conv,NULL);
2404 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2405 * @table: the sysctl table
2406 * @write: %TRUE if this is a write to the sysctl file
2407 * @buffer: the user buffer
2408 * @lenp: the size of the user buffer
2409 * @ppos: pointer to the file position
2411 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2412 * values from/to the user buffer, treated as an ASCII string.
2413 * The values read are assumed to be in 1/USER_HZ seconds, and
2414 * are converted into jiffies.
2416 * Returns 0 on success.
2418 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2419 void __user *buffer, size_t *lenp, loff_t *ppos)
2421 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2422 do_proc_dointvec_userhz_jiffies_conv,NULL);
2426 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2427 * @table: the sysctl table
2428 * @write: %TRUE if this is a write to the sysctl file
2429 * @buffer: the user buffer
2430 * @lenp: the size of the user buffer
2431 * @ppos: file position
2432 * @ppos: the current position in the file
2434 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2435 * values from/to the user buffer, treated as an ASCII string.
2436 * The values read are assumed to be in 1/1000 seconds, and
2437 * are converted into jiffies.
2439 * Returns 0 on success.
2441 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2442 void __user *buffer, size_t *lenp, loff_t *ppos)
2444 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2445 do_proc_dointvec_ms_jiffies_conv, NULL);
2448 static int proc_do_cad_pid(struct ctl_table *table, int write,
2449 void __user *buffer, size_t *lenp, loff_t *ppos)
2451 struct pid *new_pid;
2455 tmp = pid_vnr(cad_pid);
2457 r = __do_proc_dointvec(&tmp, table, write, buffer,
2458 lenp, ppos, NULL, NULL);
2462 new_pid = find_get_pid(tmp);
2466 put_pid(xchg(&cad_pid, new_pid));
2471 * proc_do_large_bitmap - read/write from/to a large bitmap
2472 * @table: the sysctl table
2473 * @write: %TRUE if this is a write to the sysctl file
2474 * @buffer: the user buffer
2475 * @lenp: the size of the user buffer
2476 * @ppos: file position
2478 * The bitmap is stored at table->data and the bitmap length (in bits)
2481 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2482 * large bitmaps may be represented in a compact manner. Writing into
2483 * the file will clear the bitmap then update it with the given input.
2485 * Returns 0 on success.
2487 int proc_do_large_bitmap(struct ctl_table *table, int write,
2488 void __user *buffer, size_t *lenp, loff_t *ppos)
2492 size_t left = *lenp;
2493 unsigned long bitmap_len = table->maxlen;
2494 unsigned long *bitmap = (unsigned long *) table->data;
2495 unsigned long *tmp_bitmap = NULL;
2496 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2498 if (!bitmap_len || !left || (*ppos && !write)) {
2504 unsigned long page = 0;
2507 if (left > PAGE_SIZE - 1)
2508 left = PAGE_SIZE - 1;
2510 page = __get_free_page(GFP_TEMPORARY);
2511 kbuf = (char *) page;
2514 if (copy_from_user(kbuf, buffer, left)) {
2520 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2526 proc_skip_char(&kbuf, &left, '\n');
2527 while (!err && left) {
2528 unsigned long val_a, val_b;
2531 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2535 if (val_a >= bitmap_len || neg) {
2547 err = proc_get_long(&kbuf, &left, &val_b,
2548 &neg, tr_b, sizeof(tr_b),
2552 if (val_b >= bitmap_len || neg ||
2563 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2565 proc_skip_char(&kbuf, &left, '\n');
2569 unsigned long bit_a, bit_b = 0;
2572 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2573 if (bit_a >= bitmap_len)
2575 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2579 err = proc_put_char(&buffer, &left, ',');
2583 err = proc_put_long(&buffer, &left, bit_a, false);
2586 if (bit_a != bit_b) {
2587 err = proc_put_char(&buffer, &left, '-');
2590 err = proc_put_long(&buffer, &left, bit_b, false);
2598 err = proc_put_char(&buffer, &left, '\n');
2604 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2606 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2618 #else /* CONFIG_PROC_SYSCTL */
2620 int proc_dostring(struct ctl_table *table, int write,
2621 void __user *buffer, size_t *lenp, loff_t *ppos)
2626 int proc_dointvec(struct ctl_table *table, int write,
2627 void __user *buffer, size_t *lenp, loff_t *ppos)
2632 int proc_dointvec_minmax(struct ctl_table *table, int write,
2633 void __user *buffer, size_t *lenp, loff_t *ppos)
2638 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2639 void __user *buffer, size_t *lenp, loff_t *ppos)
2644 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2645 void __user *buffer, size_t *lenp, loff_t *ppos)
2650 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2651 void __user *buffer, size_t *lenp, loff_t *ppos)
2656 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2657 void __user *buffer, size_t *lenp, loff_t *ppos)
2662 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2663 void __user *buffer,
2664 size_t *lenp, loff_t *ppos)
2670 #endif /* CONFIG_PROC_SYSCTL */
2673 * No sense putting this after each symbol definition, twice,
2674 * exception granted :-)
2676 EXPORT_SYMBOL(proc_dointvec);
2677 EXPORT_SYMBOL(proc_dointvec_jiffies);
2678 EXPORT_SYMBOL(proc_dointvec_minmax);
2679 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2680 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2681 EXPORT_SYMBOL(proc_dostring);
2682 EXPORT_SYMBOL(proc_doulongvec_minmax);
2683 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);