From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id EL8zKYWlAmpuMjIAWB0awg (envelope-from ) for ; Mon, 11 May 2026 23:59:01 -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=C9npfoOG; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 960C21E093; Mon, 11 May 2026 23:59:01 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 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_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (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 C55C51E093 for ; Mon, 11 May 2026 23:59:00 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B20E34BBC0A1 for ; Tue, 12 May 2026 03:58:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B20E34BBC0A1 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=C9npfoOG Received: from mail-dy1-x132d.google.com (mail-dy1-x132d.google.com [IPv6:2607:f8b0:4864:20::132d]) by sourceware.org (Postfix) with ESMTPS id 4587E4BB8F7E for ; Tue, 12 May 2026 03:58:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4587E4BB8F7E 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 4587E4BB8F7E Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::132d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778558303; cv=none; b=GLiwMgso7Wu67xc3ufU3FN5FpD3cJNaE4kiKfmYNz6TyjjTI73z4vviVkJt+g5bjH7UBkxB9vMuiztlc9TrgZhCfIByOhiZ0TdD6zP5Oix1bqtinMxWjw7O39arPIqWbUoXFCGXHsWCF/cO1D7RoxE2a80RJ961HcTP8IbiaOSU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778558303; c=relaxed/simple; bh=pNgPvS4CXVOyHcJZ1dXj5TGCki5gknTRbW6Zcv2HkIc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=WvWk85CZUNOUugD/edF0fG8bKJL+HTbALkxxS+jsrRKdHwD9Ybc7kTCzvOIcJa08cNMuBb52z30OHDm1LY061T9RM+TwzHgFGWBK96WKFrYzhoDMOcUoN0y9d97Q4p7riYMq6VntKMmUvuX9reGPusAjhLpxeDilcloS1fFfgpM= ARC-Authentication-Results: i=1; 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=C9npfoOG DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4587E4BB8F7E Received: by mail-dy1-x132d.google.com with SMTP id 5a478bee46e88-2c156c4a9efso6767893eec.1 for ; Mon, 11 May 2026 20:58:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1778558302; x=1779163102; 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=q5UkhiRyjZ9b6y10Os73jlK1/0qucKfqBs6QIQw0IqE=; b=C9npfoOGae5QiN8jafsKsybdGn2e+wC5AdAG4NaRJx12B8ILZP3VH1N1lMziQ9uQJg JtA8UR0nVcPqzodgxgQ6Vol67kgGkjEKha0plazngnfax65VBmjh4YRvIClgbtoCbXtE ui2O2XRxACJ4hbFhYVisOsFRv2d+CSuBeso/ch5Lz+FC9z0YQt5pYsX3V2VFzSkAqFyk FRbQenwQD8rVeBT2XR14f6RW5YH1Gzdz9xNnP3/drJAmultmunvzegi7G2MtwC2caGve OuZdX29OE5P+tgIwjY3f37QMuOBHDM5bQROHihXQGY7wVB0puzFDGnn8Gouq/9mReH49 /2jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778558302; x=1779163102; h=mime-version:message-id:date:user-agent:references:in-reply-to :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=q5UkhiRyjZ9b6y10Os73jlK1/0qucKfqBs6QIQw0IqE=; b=AsRiHk/I4SLhD3xpwAnymWEKyekSak0kjp+mnXcz98ZTiWYVsZVvYAF5KT9JUYzKjd UiukWYelwH61BhODrWDNtOjXQxLkFpOMx9tk+QlGqwHB0W7NRhgHxk9aLCwIHiJ8b3MX 6Om4BEurpFng0nyL8lvK5rTs3uxqtsYl83uk3x5HP5qsc5vFekB9jjS7a4eXr+vrDB8n LM6lNcHIzPSbwKYk8Qm8/z5AtGLsLRxI7iRps7D+Ip+QL0aBdRXNFY2D95KqJLdWzpem 3TG8YXThYuEkCIMKUoH9UfZptC+fSXdRgsg9gzmLj5bfVtcILiqqWEvb8B4rNGCAmPw2 NkYQ== X-Gm-Message-State: AOJu0YyyzHC0QyleD+PnX9QFcklsBIqd7AaniaVCYeccO0wzlqQvQz3P mkvZqTVrIw/Q4GPhuTjZDAjD2DdJY8ZYRcEmYsqmhdIP6vRpx/ItcpjhoCGeOHoRhOWVSSfzXA1 X8e31 X-Gm-Gg: Acq92OFeSWrOyqqMJye2+HFKJS7uleGqt/+xQwfBB8WcfqE7l9NFENfb8BsIyYw3CUw Y1sWVMiMdhIQoxbXqFlBsExsTtDENH1tovN1kP4bwGT6z9Zt7lW4wNdwkFz46ddqDvgS0TlBC1x HinS6bcYmiJkZ/sbWKRyZPe+ZNZ4H105Vnoi8fQxsWUacWtZQ97SqbR6j+PWdaGE7liKqHFvBvw 8R+bqtmsSCX80ApwPMf09UbW1K1/5kf6jXFRcguucQjEcA/1KPobx6tvkStw2kOSx4gWydbjr88 Mrh+lV3y+sG2AcvQI3qhF8Rzc2IpVr0J23cd03tok7FkHAP7xQ8d2VgeQpf4tvaLQyxzTKz2B5W mQ63j/ee6wVD0I0pDGIgYM/SAZn7IWzAt09QG/9EBg0Qga818rwFUQsY7ajRILEbmAkVs9bc8Co 8P+iD9rlK0K4ygd/qxznGnQJmH3koTqNpObi483FTemeie X-Received: by 2002:a05:7301:1018:b0:2e2:27bb:a48c with SMTP id 5a478bee46e88-2f54df9f289mr13244471eec.14.1778558302050; Mon, 11 May 2026 20:58:22 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8083:c4f1:ef88:5168:2d26]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2f88885b87dsm19660089eec.21.2026.05.11.20.58.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 20:58:21 -0700 (PDT) From: Thiago Jung Bauermann To: Christina Schimpe Cc: gdb-patches@sourceware.org Subject: Re: [PATCH v2 8/9] gdb: Implement the hook 'is_no_return_shadow_stack_address' for amd64 linux. In-Reply-To: <20260123080532.878738-9-christina.schimpe@intel.com> (Christina Schimpe's message of "Fri, 23 Jan 2026 08:05:30 +0000") References: <20260123080532.878738-1-christina.schimpe@intel.com> <20260123080532.878738-9-christina.schimpe@intel.com> User-Agent: mu4e 1.14.1; emacs 30.2 Date: Tue, 12 May 2026 00:58:19 -0300 Message-ID: <87pl31z3c4.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 Christina Schimpe writes: > There can be elements on the shadow stack which are not return addresses. > This can happen, for instance, in case of signals on amd64 linux. > The old shadow stack pointer is pushed in a special format with bit 63 set. > > |1...old SSP| - Pointer to old pre-signal ssp in sigframe token format > (bit 63 set to 1) > > Linux kernel documentation: https://docs.kernel.org/arch/x86/shstk.html > > Implement the gdbarch hook is_no_return_shadow_stack_address to detect > this scenario to print the shadow stack backtrace correctly. > --- > gdb/amd64-linux-tdep.c | 55 ++++++++++++++++++- > .../amd64-shadow-stack-backtrace-signal.exp | 49 +++++++++++++++++ > .../gdb.arch/amd64-shadow-stack-signal.c | 31 +++++++++++ > 3 files changed, 134 insertions(+), 1 deletion(-) > create mode 100644 gdb/testsuite/gdb.arch/amd64-shadow-stack-backtrace-signal.exp > create mode 100644 gdb/testsuite/gdb.arch/amd64-shadow-stack-signal.c Just one nit below. In any case: Reviewed-by: Thiago Jung Bauermann I don't know much about MI, so I won't review patch 9. > diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c > index a4eabccf667..b517f9772f5 100644 > --- a/gdb/amd64-linux-tdep.c > +++ b/gdb/amd64-linux-tdep.c > @@ -1986,6 +1986,56 @@ amd64_linux_get_shadow_stack_size > return shadow_stack_bytes / 8; > } > > +/* Return true, if FRAME is a valid shadow stack frame while FRAME.VALUE > + does not refer to a return address. This can happen, for instance, in > + case of signals. The old shadow stack pointer is pushed in a special > + format with bit 63 set. In case this is true, configure the string > + which describes the frame and is displayed instead of the address in > + the shadow stack backtrace. */ > + > +static bool > +amd64_linux_is_no_return_shadow_stack_address > + (gdbarch *gdbarch, > + const shadow_stack_frame_info &frame, > + std::string &frame_type) > +{ > + /* FRAME must be a valid shadow stack frame. */ > + std::pair range; > + gdb_assert (gdbarch_address_in_shadow_stack_memory_range (gdbarch, > + frame.ssp, > + &range)); > + > + /* In case bit 63 is not configured, the address on the shadow stack > + should be a return address. */ > + constexpr CORE_ADDR mask = (CORE_ADDR) 1 << 63; > + if ((frame.value & mask) == 0) > + return false; > + > + /* To compare the shadow stack pointer of the previous frame with the > + value of FRAME, we must clear bit 63. */ > + CORE_ADDR shadow_stack_val_cleared = (frame.value & (~mask)); > + > + /* Compute the previous/old SSP. The shadow stack grows downwards. To > + compute the previous shadow stack pointer, we need to increment > + FRAME.SSP. */ > + CORE_ADDR prev_ssp > + = frame.ssp + gdbarch_shadow_stack_element_size_aligned (gdbarch); > + > + /* We incremented FRAME.SSP by one element to compute PREV_SSP before. > + In case FRAME.SSP points to the first element of the shadow stack, > + PREV_SSP must point to the bottom of the shadow stack (RANGE.SECOND), > + but not beyond that address. */ > + gdb_assert (prev_ssp > range.first && prev_ssp <= range.second); It's better to use one gdb_assert per condition, so that if it triggers, it's clear which condition was violated. > + > + if (shadow_stack_val_cleared == prev_ssp) > + { > + frame_type = _(""); > + return true; > + } > + > + return false; > +} -- Thiago