From 377e12f14a2c3694c3a733782b91ae7beecc44f3 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Wed, 16 Jul 2014 14:00:57 -0700 Subject: [PATCH] Rate limit debugging stack traces There have been issues in the past where excessive debug logging to the console has resulted in significant performance impacts. In the vast majority of these cases only a few stack traces are required to diagnose the issue. Therefore, stack traces dumped to the console will now we limited to 5 every 60s. Signed-off-by: Brian Behlendorf Signed-off-by: Prakash Surya Closes #374 --- module/spl/spl-debug.c | 22 +++++++++++++++------- module/spl/spl-kmem.c | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/module/spl/spl-debug.c b/module/spl/spl-debug.c index 93c3f31b8a..6c4e043f05 100644 --- a/module/spl/spl-debug.c +++ b/module/spl/spl-debug.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -1073,15 +1074,22 @@ spl_debug_get_mb(void) } EXPORT_SYMBOL(spl_debug_get_mb); -void spl_debug_dumpstack(struct task_struct *tsk) +/* + * Limit the number of stack traces dumped to not more than 5 every + * 60 seconds to prevent denial-of-service attacks from debug code. + */ +DEFINE_RATELIMIT_STATE(dumpstack_ratelimit_state, 60 * HZ, 5); + +void +spl_debug_dumpstack(struct task_struct *tsk) { - extern void show_task(struct task_struct *); + if (__ratelimit(&dumpstack_ratelimit_state)) { + if (tsk == NULL) + tsk = current; - if (tsk == NULL) - tsk = current; - - printk("SPL: Showing stack for process %d\n", tsk->pid); - dump_stack(); + printk("SPL: Showing stack for process %d\n", tsk->pid); + dump_stack(); + } } EXPORT_SYMBOL(spl_debug_dumpstack); diff --git a/module/spl/spl-kmem.c b/module/spl/spl-kmem.c index e458c20201..6389dc5aab 100644 --- a/module/spl/spl-kmem.c +++ b/module/spl/spl-kmem.c @@ -725,7 +725,7 @@ kmem_alloc_debug(size_t size, int flags, const char *func, int line, "large kmem_alloc(%llu, 0x%x) at %s:%d (%lld/%llu)\n", (unsigned long long) size, flags, func, line, kmem_alloc_used_read(), kmem_alloc_max); - dump_stack(); + spl_debug_dumpstack(NULL); } /* Use the correct allocator */