From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id BRehNsy8VGjFSxUAWB0awg (envelope-from ) for ; Thu, 19 Jun 2025 21:43:40 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=ObftGlrE; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id CB7C11E11C; Thu, 19 Jun 2025 21:43:40 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.8 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_SBL_CSS,RCVD_IN_VALIDITY_CERTIFIED, RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id ED2081E0C2 for ; Thu, 19 Jun 2025 21:43:37 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1F3E73850062 for ; Fri, 20 Jun 2025 01:43:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1F3E73850062 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=ObftGlrE Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 00AE738560BE for ; Fri, 20 Jun 2025 01:42:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 00AE738560BE Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 00AE738560BE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::436 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1750383780; cv=none; b=cjbJVumahQjsmH3tXM9axQoisLYBH9WzbofDWeBvr0Mj8+IobDE8oDysw8jBLoE7Ylw2aI4kzCnfeYom++r5/LIshsFQTkFKXRZIFlWYc7gYPzsVGPYLGlnWaPavmrxBsuZeUhn3zLeDlkHUxeA+rPj/J+e1YKU22zk+u8sULrc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1750383780; c=relaxed/simple; bh=YFhLjCQ1SKrUkWBQH3JOs3Cs8iKljrFz3s/msqz40N0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Yc5JqjWOOAF9+EmNbqVWIwWj/M3jx2wLYAafsge/Kp0Ggn/pwqoguIPvILFdP9b5ssSh5plHLoyacZbmlvV4MASfGZ88MmnvcIWkwZ6rUEEhRHeZ7Ftl9uqwYjLBLKFY0k5rIldVk8/d3ePmkEj16UZoxGM//Fxubml/g1dF7l4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 00AE738560BE Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-7390d21bb1cso972714b3a.2 for ; Thu, 19 Jun 2025 18:42:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1750383778; x=1750988578; darn=sourceware.org; h=mime-version:message-id:date:user-agent:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=3Io97Nrfb21+ivkD2NMJD3cA72wqZSq3Z646UObbmwA=; b=ObftGlrEvFwYHVQ2RVm0oWrUrsmT5tvceKULY+GmRBc1BJSUq0qzReTp9izDvRtcDI 4YPYvsvyW5K5MeOoTTv5tV9TOcn9mb5A4Hs+wYMp2AHK4fKTxlxPzJxaQ7Uod/d/A0L7 DNwT8xvsyGpCEhPBjIV9rEKCpKRYcfcPPNLSCoKuEMc5bVvI+Efp9zR0/mul6aGk7gjV v5WXFHYLu+i1HxxaFScS/1PDoGmaqfCXBycek0V+Sn4kgtutjgEx52lufJBsJ/UzWhvJ uL3yWCNzfDb+CUa532UESfztvGtWcgp1UoHEDWjBVnf3qvypsh1wkVai7I/x8tT1Rxyu iy8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750383778; x=1750988578; h=mime-version:message-id:date:user-agent:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=3Io97Nrfb21+ivkD2NMJD3cA72wqZSq3Z646UObbmwA=; b=ERiKkdx5P4fSatCRVPtb8dRoimlbV4oyayhY/peWR5lm+AKaasAO6PA8gSKHE6eJP+ s0Qt98jgSxAqyCgSYxglCrcX/VV72o+4m2E6wJqZ1qVi+8a08LcCjr9S72DWdduJV6e2 7+FtKbfv5eC3GQAHLM/mhsCSW6WFr0Z5JRH8f9M5KSi/gXn30bh9P2mLWLCRvyKlY8ud MXDtmN74J7/ER+suWaex8uqJyEke9CZPmN4Ylr5+n9B5rau1myDxZo+B3xyXsHXs99XJ PA/KlxmkG3p66vzjvFKly1DJPpD05eCzTGsUnfopCg2dZa/nIP4FPTP+Fq9Fz3VtJW57 ZhYg== X-Forwarded-Encrypted: i=1; AJvYcCXHieFSQ6PG9eifzROogG+1R3Ndeeyns1hNp+v2O2S22guE4hP5ABGKemE+iNFc1kJQqjQZAg5LlFHppA==@sourceware.org X-Gm-Message-State: AOJu0YypOBKAEJrNinBnc57HtEsfLaMsLxY/W5ugzqndNdu2AGcHSMuN cy+wSdOCACPdLau+Qvl0ADG1hFcKtPxrUCwjTlZDUWw8866cBV/pN4YDzpdpsJL5WHc= X-Gm-Gg: ASbGncsiHwNgzhhcGWGutmI20s/iMMSiLYTVb1rB6jt1WuRqMK6P6U0kBb8xG9awgSI dSVrE/0RRVRyHSzQOvUQB18//sk8+aPvxUqfWpfS5KMCUh3O0375FP+oK/oywjmZyg00KU5z8tZ uCkH0NYWzB+Jhxo/ZthEpBmHJFInf9wcpZqqKJHTzebZflpnOqG2ll+pvNtuyLyTJz+YQ+NYjF0 6gSwq28BC4RbjCzSpqhSbQuY+RUgb/ysUZ7yC53uG5VtVmWS1l+I3t16Bo8qQLFwhPzTt/U+cAx o/LX9KM2FrrvHu2mnr0xbnD2/8cPdnBHRlDd1iBdxIWriUqCewGrO+2Ip5jY8U5J4RGCHA6l X-Google-Smtp-Source: AGHT+IFU7a65lvsWKAAN+Kmhc6/7A8li/DTmEbo0oKC0vVRMNu8v1TUUnKAC0mvVTQHkwt/tJLnP+g== X-Received: by 2002:a05:6a21:2d8f:b0:21f:543f:f11c with SMTP id adf61e73a8af0-22026ca84e3mr1589104637.2.1750383778200; Thu, 19 Jun 2025 18:42:58 -0700 (PDT) Received: from localhost ([2804:14d:7e39:88d6:5445:e80d:c771:b2da]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b31f126c50asm388209a12.78.2025.06.19.18.42.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jun 2025 18:42:57 -0700 (PDT) From: Thiago Jung Bauermann To: Luis Machado Cc: Christina Schimpe , gdb-patches@sourceware.org, eliz@gnu.org Subject: Re: [PATCH v4 07/11] gdb: Handle shadow stack pointer register unwinding for amd64 linux. In-Reply-To: (Luis Machado's message of "Thu, 19 Jun 2025 10:25:05 +0100") References: <20250617121147.1956686-1-christina.schimpe@intel.com> <20250617121147.1956686-8-christina.schimpe@intel.com> User-Agent: mu4e 1.12.11; emacs 30.1 Date: Thu, 19 Jun 2025 22:42:55 -0300 Message-ID: <871prfp4rk.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Luis Machado writes: > On 6/17/25 13:11, Christina Schimpe wrote: >> + Using /proc/PID/smaps we can only check if the current shadow >> + stack pointer SSP points to shadow stack memory. Only if this is >> + the case a valid previous shadow stack pointer can be >> + calculated. */ >> + std::pair range; >> + if (linux_address_in_shadow_stack_mem_range (ssp, &range)) >> + { >> + /* The shadow stack grows downwards. To compute the previous >> + shadow stack pointer, we need to increment SSP. */ >> + CORE_ADDR new_ssp >> + = ssp + amd64_linux_shadow_stack_element_size_aligned (gdbarch); >> + >> + /* If NEW_SSP points to the end of or before (<=) the current >> + shadow stack memory range we consider NEW_SSP as valid (but >> + empty). */ > > I couldn't quite understand the difference between the empty case and the > unavailable case. But maybe I just don't fully understand the feature. > > Would it be possible to make the comment a bit more clear? I understood it to mean that if new_ssp == range.second, then it points to the top of the stack and there aren't any elements. Whereas if new_ssp points outside of the shadow stack area, then it's garbage and we failed to unwind it, hence the unavailable value. Christina, please correct me if I'm wrong. But now looking at this again, I think there's an off-by-one error: range.second is the first address outside of the memory range, so the comparison needs to be strictly less than. And the shadow stack will be empty if new_ssp == range.second - 1 (there's no need to check for that, though). >> + if (new_ssp <= range.second) >> + return frame_unwind_got_address (this_frame, regnum, new_ssp); >> + } >> + } >> + >> + /* Return a value which is marked as unavailable in case we could not >> + calculate a valid previous shadow stack pointer. */ >> + value *retval >> + = value::allocate_register (get_next_frame_sentinel_okay (this_frame), >> + regnum, register_type (gdbarch, regnum)); >> + retval->mark_bytes_unavailable (0, retval->type ()->length ()); >> + return retval; >> +} -- Thiago