x86/stacktrace: Prevent infinite loop in arch_stack_walk_user()

arch_stack_walk_user() checks `if (fp == frame.next_fp)` to prevent a
infinite loop by self reference but it's not enogh for circular reference.

Once a lack of return address is found, there is no point to continue the
loop, so break out.

Fixes: 02b67518e2 ("tracing: add support for userspace stacktraces in tracing/iter_ctrl")
Signed-off-by: Eiichi Tsukata <devel@etsukata.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lkml.kernel.org/r/20190711023501.963-1-devel@etsukata.com
This commit is contained in:
Eiichi Tsukata 2019-07-11 11:35:01 +09:00 committed by Thomas Gleixner
parent 7652ac9201
commit cbf5b73d16
1 changed files with 3 additions and 5 deletions

View File

@ -129,11 +129,9 @@ void arch_stack_walk_user(stack_trace_consume_fn consume_entry, void *cookie,
break;
if ((unsigned long)fp < regs->sp)
break;
if (frame.ret_addr) {
if (!consume_entry(cookie, frame.ret_addr, false))
return;
}
if (fp == frame.next_fp)
if (!frame.ret_addr)
break;
if (!consume_entry(cookie, frame.ret_addr, false))
break;
fp = frame.next_fp;
}