#include <linux/proc_compat.h>
#include <linux/file_compat.h>
#include <linux/swap.h>
+#include <linux/ratelimit.h>
#include <sys/sysmacros.h>
#include <sys/thread.h>
#include <spl-debug.h>
}
EXPORT_SYMBOL(spl_debug_get_mb);
-void spl_debug_dumpstack(struct task_struct *tsk)
-{
- extern void show_task(struct task_struct *);
+/*
+ * 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);
- if (tsk == NULL)
- tsk = current;
+void
+spl_debug_dumpstack(struct task_struct *tsk)
+{
+ if (__ratelimit(&dumpstack_ratelimit_state)) {
+ 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);
"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 */