From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gmmr-4.centrum.cz (gmmr-4.centrum.cz [46.255.227.205]) by sourceware.org (Postfix) with ESMTPS id 3324A3858C56 for ; Fri, 4 Nov 2022 17:31:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3324A3858C56 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=volny.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=volny.cz Received: from gmmr-4.centrum.cz (localhost [127.0.0.1]) by gmmr-4.centrum.cz (Postfix) with ESMTP id 5CB841CCD8 for ; Fri, 4 Nov 2022 18:31:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=volny.cz; s=mail; t=1667583092; bh=H9evzcQQjAnPSj5kfYG0mwfEDeKSOGrVMkX3E3UHXak=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=FkQYXAZ8w861KoDfhPyINH4KBbXMJdnAHo1JEjahmGR0SBRVdsRbcxvDPNUdVCDN/ FohxNVnHn+qPyC31qsSrNvG9Qyra54nG6zBgKdaePAD9y46Up+XTmBJnN8VcQZHENR DQg911MXQ0pptXv4Ga1TsRv4/31Q0auLTyV0pjTg= Received: from vm1.excello.cz (vm1.excello.cz [IPv6:2001:67c:1591::3]) by gmmr-4.centrum.cz (Postfix) with QMQP id 5A2D22022009 for ; Fri, 4 Nov 2022 18:31:32 +0100 (CET) Received: from vm1.excello.cz by vm1.excello.cz (VF-Scanner: Clear:RC:0(46.255.227.205):SC:0(-3.8/5.0):CC:0:; processed in 0.7 s); 04 Nov 2022 17:31:32 +0000 X-VF-Scanner-ID: 20221104173131.684480.14095.vm1.excello.cz.0 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 Received: from gmmr-4.centrum.cz (46.255.227.205) by out2.virusfree.cz with ESMTPS (TLSv1.3, TLS_AES_256_GCM_SHA384); 4 Nov 2022 18:31:31 +0100 Received: from gm-smtp10.centrum.cz (envoy-stl.cent [10.32.56.18]) by gmmr-4.centrum.cz (Postfix) with ESMTP id 9492120226F2 for ; Fri, 4 Nov 2022 18:31:31 +0100 (CET) Received: from ktus.lan (217-115-245-101.cust.avonet.cz [217.115.245.101]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by gm-smtp10.centrum.cz (Postfix) with ESMTPSA id 805ABB2AC5 for ; Fri, 4 Nov 2022 18:31:31 +0100 (CET) Received: by ktus.lan (Postfix, from userid 209) id 384C230FAED; Fri, 4 Nov 2022 18:31:31 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-Spam-Level: X-VF-Scanner-Moved-X-Spam-Status: No, score=-3.4 required=5.0 tests=ALL_TRUSTED,BAYES_00,FROM_CZ, NICE_REPLY_A autolearn=disabled version=3.4.0 Received: from [192.168.33.9] (217-115-245-101.cust.avonet.cz [217.115.245.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vanekt) by ktus.lan (Postfix) with ESMTPSA id A7BAC30FAE7; Fri, 4 Nov 2022 18:31:24 +0100 (CET) Message-ID: Date: Fri, 4 Nov 2022 18:31:25 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.13.1 Subject: Re: [PATCH 2/3] gdb/arm: Ensure that stack pointers are in sync Content-Language: en-GB To: =?UTF-8?Q?Torbj=c3=b6rn_SVENSSON?= , gdb-patches@sourceware.org Cc: luis.machado@arm.com References: <20221104144438.2786801-1-torbjorn.svensson@foss.st.com> <20221104144438.2786801-3-torbjorn.svensson@foss.st.com> From: Tomas Vanek In-Reply-To: <20221104144438.2786801-3-torbjorn.svensson@foss.st.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: Torbjorn, thanks for addressing the issue so fast! With two fixes commented inline the patch series resolves [Bug tdep/29738] Tomas On 04/11/2022 15:44, Torbjörn SVENSSON wrote: > 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); Should use tdep->m_profile_msp_regnum, tdep->m_profile_msp_s_regnum is not initialized on M-profile without sec ext > + cache->psp_s > + = get_frame_register_unsigned (frame, tdep->m_profile_psp_s_regnum); And here similarly tdep->m_profile_psp_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