From 83ecb4b86a2c811afd7cd19638f929e15d6611d5 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Fri, 22 Mar 2024 17:27:54 -0700 Subject: [PATCH] ctrl thread stepping machine: read initial stack-pointer-check-value *before* single-stepping stuck threads, otherwise we can obtain an incorrect stack check value if the single-step causes a call. --- src/ctrl/ctrl_core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ctrl/ctrl_core.c b/src/ctrl/ctrl_core.c index 390c5a6e..9090a929 100644 --- a/src/ctrl/ctrl_core.c +++ b/src/ctrl/ctrl_core.c @@ -2861,6 +2861,15 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) } } + ////////////////////////////// + //- rjf: read initial stack-pointer-check value + // + // This MUST happen before any threads move, including single-stepping stuck + // threads, because otherwise, their stack pointer may change, if single-stepping + // causes e.g. entrance into a function via a call instruction. + // + U64 sp_check_value = dmn_rsp_from_thread(target_thread); + ////////////////////////////// //- rjf: single step "stuck threads" // @@ -3011,7 +3020,6 @@ ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg) // if(stop_event == 0) { - U64 sp_check_value = dmn_rsp_from_thread(target_thread); B32 spoof_mode = 0; CTRL_Spoof spoof = {0}; for(;;)