libunwind/backport-aarch64-unw_step-validates-address-before-calling-dwarf_get.patch
2023-06-01 11:17:37 +08:00

49 lines
1.3 KiB
Diff

From 8a0e2fa6579085dc8f51b2bdd90d8b00a2e7d6ab Mon Sep 17 00:00:00 2001
From: he7850 <im.bin.hu@gmail.com>
Date: Wed, 3 May 2023 15:18:27 +0800
Subject: [PATCH] aarch64: unw_step() validates address before calling
dwarf_get
Signed-off-by: he7850 <im.bin.hu@gmail.com>
---
src/aarch64/Gstep.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/aarch64/Gstep.c b/src/aarch64/Gstep.c
index f4ef369d3..a2ed9bc35 100644
--- a/src/aarch64/Gstep.c
+++ b/src/aarch64/Gstep.c
@@ -156,18 +156,28 @@ unw_step (unw_cursor_t *cursor)
dwarf_get (&c->dwarf, c->dwarf.loc[UNW_AARCH64_X30], &c->dwarf.ip);
}
- /* Restore default memory validation state */
- c->validate = validate;
-
ret = dwarf_step (&c->dwarf);
Debug(1, "dwarf_step()=%d\n", ret);
+ /* Restore default memory validation state */
+ c->validate = validate;
+
if (unlikely (ret == -UNW_ESTOPUNWIND))
return ret;
if (unlikely (ret < 0))
{
/* DWARF failed. */
+
+ /*
+ * We could get here because of missing/bad unwind information.
+ * Validate all addresses before dereferencing.
+ */
+ if (c->dwarf.as == unw_local_addr_space)
+ {
+ c->validate = 1;
+ }
+
if (is_plt_entry (&c->dwarf))
{
Debug (2, "found plt entry\n");