This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new ff70b2a9d71 arch/xtensa: fix backtrace buffer overflow when size is
zero
ff70b2a9d71 is described below
commit ff70b2a9d71cacd7e8065ba160703c89dc59d5b4
Author: Bowen Wang <[email protected]>
AuthorDate: Fri Nov 20 17:09:43 2026 +0800
arch/xtensa: fix backtrace buffer overflow when size is zero
backtrace_stack() stores the return address it is given before checking
that the buffer has room for it. up_backtrace() rejects size <= 0 on
entry, but in interrupt context it walks the interrupt stack first and
then calls backtrace_stack() again with the interrupted A0 and whatever
room the first walk left:
ret += backtrace_stack(..., running_regs()[REG_A0],
&buffer[ret], size - ret, &skip);
When the first walk fills the buffer, size - ret is 0 and the A0 entry is
written one past its end. Check the room together with ra and skip.
Signed-off-by: Bowen Wang <[email protected]>
---
arch/xtensa/src/common/xtensa_backtrace.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/arch/xtensa/src/common/xtensa_backtrace.c
b/arch/xtensa/src/common/xtensa_backtrace.c
index 0ab11d8c7e5..f2b71953ce3 100644
--- a/arch/xtensa/src/common/xtensa_backtrace.c
+++ b/arch/xtensa/src/common/xtensa_backtrace.c
@@ -181,12 +181,9 @@ static int backtrace_stack(uintptr_t *base, uintptr_t
*limit,
{
int i = 0;
- if (ra)
+ if (ra && i < size && (*skip)-- <= 0)
{
- if ((*skip)-- <= 0)
- {
- buffer[i++] = MAKE_PC_FROM_RA((uintptr_t)ra);
- }
+ buffer[i++] = MAKE_PC_FROM_RA((uintptr_t)ra);
}
while (i < size)