x86/stacktrace: Fix infinite loop in arch_stack_walk_user()
Subsystems (2)
PATCH 1/1 x86/stacktrace: Fix infinite loop in arch_stack_walk_user()
Current arch_stack_walk_user() checks if (fp == frame.next_fp) to prevent infinite loop by self reference but it's not enogh for circular reference.
Once we find a lack of return address, there is no need to continue loop, so let's break out.
--- arch/x86/kernel/stacktrace.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
arch/x86/kernel/stacktrace.c +2 -5
@@ -129,11 +129,8 @@ 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 || + !consume_entry (cookie, frame.ret_addr, false))break ; fp = frame.next_fp; }
Signature · 1 line
2.21.0
Quoted 3 lines · Eiichi Tsukata
Once we find a lack of return address, there is no need to continue loop, so let's break out.
Looks good to me, feel free to add
and I'll assume this comes through the x86 -tip tree..
Linus
tip-bot for Eiichi Tsukata
merge bot[tip:x86/urgent] x86/stacktrace: Prevent infinite loop in arch_stack_walk_user()
In reply to Eiichi Tsukatax86/stacktrace: Prevent infinite loop in arch_stack_walk_user()
Commit-ID: cbf5b73d162b22e044fe0b7d51dcaa33be065253 Gitweb: https://git.kernel.org/tip/cbf5b73d162b22e044fe0b7d51dcaa33be065253 Author: Eiichi Tsukata <[email protected]> AuthorDate: Thu, 11 Jul 2019 11:35:01 +0900 Committer: Thomas Gleixner <[email protected]> CommitDate: Thu, 11 Jul 2019 08:22:03 +0200
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.
--- arch/x86/kernel/stacktrace.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
arch/x86/kernel/stacktrace.c +3 -5
@@ -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; }