From f804532ac23a78157f32b49255f2f5226018e084 Mon Sep 17 00:00:00 2001 From: "Danylo Kyrylov -X (dkyrylov - SOFTSERVE INC at Cisco)" Date: Fri, 13 Sep 2024 09:09:48 +0000 Subject: [PATCH] Pull request #4430: Unwind arm fix Merge in SNORT/snort3 from ~DKYRYLOV/snort3:unwind_arm_fix to master Squashed commit of the following: commit b1e48c94f8eae4d6b92da78d1c4164830501c272 Author: dkyrylov Date: Wed Aug 28 19:38:14 2024 +0300 process: skip vDSO frame on aarch64 skip vDSO frame on aarch64, continue unwinding past unw_get_proc_info failure --- src/main/process.cc | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/main/process.cc b/src/main/process.cc index 50b8cbbe1..8d4e74bfd 100644 --- a/src/main/process.cc +++ b/src/main/process.cc @@ -232,11 +232,24 @@ static void print_backtrace(SigSafePrinter& ssp) // walk the stack frames unsigned frame_num = 0; + bool signal_frame_found = false; + while ((ret = unw_step(&cursor)) > 0) { - // skip printing any frames until we've found the frame that received the signal - if (frame_num == 0 && !unw_is_signal_frame(&cursor)) - continue; + if (!signal_frame_found) + { + if (unw_is_signal_frame(&cursor)) + { + signal_frame_found = true; +#ifdef __aarch64__ + // skip __kernel_rt_sigreturn in vDSO for arm + continue; +#endif + } + else + // skip printing any frames until we've found the frame that received the signal + continue; + } unw_word_t pc; if ((ret = unw_get_reg(&cursor, UNW_REG_IP, &pc)) < 0) @@ -246,12 +259,6 @@ static void print_backtrace(SigSafePrinter& ssp) return; } - unw_proc_info_t pip; - if ((ret = unw_get_proc_info(&cursor, &pip)) < 0) - { - ssp.printf("unw_get_proc_info failed: %s (%d)\n", unw_strerror(ret), ret); - return; - } ssp.printf(" #%u 0x%x", frame_num, pc); @@ -274,11 +281,19 @@ static void print_backtrace(SigSafePrinter& ssp) break; } - Dl_info dlinfo; - if (dladdr((void *)(uintptr_t)(pip.start_ip + offset), &dlinfo) - && dlinfo.dli_fname && *dlinfo.dli_fname) + unw_proc_info_t pip; + if ((ret = unw_get_proc_info(&cursor, &pip)) < 0) { - ssp.printf(" (%s @0x%x)", dlinfo.dli_fname, dlinfo.dli_fbase); + ssp.printf(" unw_get_proc_info failed: %s (%d)", unw_strerror(ret), ret); + } + else + { + Dl_info dlinfo; + if (dladdr((void*) (uintptr_t) (pip.start_ip + offset), &dlinfo) + && dlinfo.dli_fname && *dlinfo.dli_fname) + { + ssp.printf(" (%s @0x%x)", dlinfo.dli_fname, dlinfo.dli_fbase); + } } ssp.printf("\n"); -- 2.47.3