From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) by sourceware.org (Postfix) with ESMTPS id A46C3385841C for ; Fri, 18 Nov 2022 15:53:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A46C3385841C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=foss.st.com Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2AICElqF025082; Fri, 18 Nov 2022 16:53:45 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=selector1; bh=//pA12FaD48pFNBO3sdvFu1z7viZ4lOReT41xjwTrUs=; b=6xHgWEZTMaGkUoXOnS2hjAJMtJ0cQZQWglixYcu5HWT0Hl1VGAOqhjoByVjqZ0ez2dKP 6IMagCf91E+Qd24Sf2UnzFzXvHOTOT3xDGdF20ODtVZOGnzDmBykdN40Et4DvixbEa8K j0lil4En+E/faD1pZmHscDg73GSeP2/X45ETva0OILEA9HMObGgydXICL5qJkj5kmIeK trAQ2i8MoO+/WzF/SCi1Cisb5VyEUKDZDYOVJDeIvsD1qnMOrOkOnQjfwEzfIiR8L53G 9hibLSmvtFacR5+aG8tUCIzkC3yUp4nL4kkeAKtE75vSLXezJGbuR74P44rGTwMe5boq mw== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3kx0my4shn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 18 Nov 2022 16:53:45 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 73A4D100039; Fri, 18 Nov 2022 16:53:40 +0100 (CET) Received: from Webmail-eu.st.com (shfdag1node3.st.com [10.75.129.71]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 6D23223C691; Fri, 18 Nov 2022 16:53:40 +0100 (CET) Received: from jkgcxl0002.jkg.st.com (10.210.54.218) by SHFDAG1NODE3.st.com (10.75.129.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.6; Fri, 18 Nov 2022 16:53:40 +0100 From: =?UTF-8?q?Torbj=C3=B6rn=20SVENSSON?= To: CC: , , =?UTF-8?q?Torbj=C3=B6rn=20SVENSSON?= Subject: [PATCH v2 2/4] gdb/arm: Ensure that stack pointers are in sync Date: Fri, 18 Nov 2022 16:52:51 +0100 Message-ID: <20221118155252.113476-3-torbjorn.svensson@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221118155252.113476-1-torbjorn.svensson@foss.st.com> References: <20221118155252.113476-1-torbjorn.svensson@foss.st.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.210.54.218] X-ClientProxiedBy: EQNCAS1NODE3.st.com (10.75.129.80) To SHFDAG1NODE3.st.com (10.75.129.71) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-18_04,2022-11-18_01,2022-06-22_01 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Without this patch, sp might be secure, but msp or psp is non-secure (this state can not happen in the hardware). Signed-off-by: Torbjörn SVENSSON --- gdb/arm-tdep.c | 86 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 28 deletions(-) diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 124a94dc87d..c011b2aa973 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -324,20 +324,6 @@ reconstruct_t_bit(struct gdbarch *gdbarch, CORE_ADDR lr, ULONGEST psr) return psr; } -/* Initialize stack pointers, and flag the active one. */ - -static inline void -arm_cache_init_sp (int regnum, CORE_ADDR* member, - struct arm_prologue_cache *cache, - frame_info_ptr frame) -{ - CORE_ADDR val = get_frame_register_unsigned (frame, regnum); - if (val == cache->sp) - cache->active_sp_regnum = regnum; - - *member = val; -} - /* Initialize CACHE fields for which zero is not adequate (CACHE is expected to have been ZALLOC'ed before calling this function). */ @@ -362,34 +348,78 @@ arm_cache_init (struct arm_prologue_cache *cache, frame_info_ptr frame) if (tdep->have_sec_ext) { - CORE_ADDR msp_val = get_frame_register_unsigned (frame, tdep->m_profile_msp_regnum); - CORE_ADDR psp_val = get_frame_register_unsigned (frame, tdep->m_profile_psp_regnum); - - arm_cache_init_sp (tdep->m_profile_msp_s_regnum, &cache->msp_s, cache, frame); - arm_cache_init_sp (tdep->m_profile_psp_s_regnum, &cache->psp_s, cache, frame); - arm_cache_init_sp (tdep->m_profile_msp_ns_regnum, &cache->msp_ns, cache, frame); - arm_cache_init_sp (tdep->m_profile_psp_ns_regnum, &cache->psp_ns, cache, frame); - + const CORE_ADDR msp_val + = get_frame_register_unsigned (frame, tdep->m_profile_msp_regnum); + const CORE_ADDR psp_val + = get_frame_register_unsigned (frame, tdep->m_profile_psp_regnum); + + cache->msp_s + = get_frame_register_unsigned (frame, tdep->m_profile_msp_s_regnum); + cache->msp_ns + = get_frame_register_unsigned (frame, tdep->m_profile_msp_ns_regnum); + cache->psp_s + = get_frame_register_unsigned (frame, tdep->m_profile_psp_s_regnum); + cache->psp_ns + = get_frame_register_unsigned (frame, tdep->m_profile_psp_ns_regnum); + + /* Identify what msp is alias for (msp_s or msp_ns). */ if (msp_val == cache->msp_s) cache->active_msp_regnum = tdep->m_profile_msp_s_regnum; else if (msp_val == cache->msp_ns) cache->active_msp_regnum = tdep->m_profile_msp_ns_regnum; + else + { + warning (_("Invalid state, unable to determine msp alias.")); + cache->active_msp_regnum = tdep->m_profile_msp_s_regnum; + } + + /* Identify what psp is alias for (psp_s or psp_ns). */ if (psp_val == cache->psp_s) cache->active_psp_regnum = tdep->m_profile_psp_s_regnum; else if (psp_val == cache->psp_ns) cache->active_psp_regnum = tdep->m_profile_psp_ns_regnum; + else + { + warning (_("Invalid state, unable to determine psp alias.")); + cache->active_psp_regnum = tdep->m_profile_psp_s_regnum; + } - /* Use MSP_S as default stack pointer. */ - if (cache->active_sp_regnum == ARM_SP_REGNUM) - cache->active_sp_regnum = tdep->m_profile_msp_s_regnum; + /* Identify what sp is alias for (msp_s, msp_ns, psp_s or psp_ns). */ + if (msp_val == cache->sp) + cache->active_sp_regnum = cache->active_msp_regnum; + else if (psp_val == cache->sp) + cache->active_sp_regnum = cache->active_psp_regnum; + else + { + warning (_("Invalid state, unable to determine sp alias.")); + cache->active_sp_regnum = cache->active_msp_regnum; + } } else if (tdep->is_m) { - arm_cache_init_sp (tdep->m_profile_msp_regnum, &cache->msp_s, cache, frame); - arm_cache_init_sp (tdep->m_profile_psp_regnum, &cache->psp_s, cache, frame); + cache->msp_s + = get_frame_register_unsigned (frame, tdep->m_profile_msp_s_regnum); + cache->psp_s + = get_frame_register_unsigned (frame, tdep->m_profile_psp_s_regnum); + + /* Identify what sp is alias for (msp or psp). */ + if (cache->msp_s == cache->sp) + cache->active_sp_regnum = tdep->m_profile_msp_regnum; + else if (cache->psp_s == cache->sp) + cache->active_sp_regnum = tdep->m_profile_psp_regnum; + else + { + warning (_("Invalid state, unable to determine sp alias.")); + cache->active_sp_regnum = tdep->m_profile_msp_regnum; + } } else - arm_cache_init_sp (ARM_SP_REGNUM, &cache->msp_s, cache, frame); + { + cache->msp_s + = get_frame_register_unsigned (frame, ARM_SP_REGNUM); + + cache->active_sp_regnum = ARM_SP_REGNUM; + } } /* Return the requested stack pointer value (in REGNUM), taking into -- 2.25.1