From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id sYQNEtKtqmeYqyoAWB0awg (envelope-from ) for ; Mon, 10 Feb 2025 20:54:26 -0500 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=c395hKFL; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 39D7A1E105; Mon, 10 Feb 2025 20:54:26 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.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 autolearn=ham autolearn_force=no version=4.0.0 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 C7FF01E08E for ; Mon, 10 Feb 2025 20:54:24 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3611A3858D21 for ; Tue, 11 Feb 2025 01:54:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3611A3858D21 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=c395hKFL Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id 7B8D83858D21 for ; Tue, 11 Feb 2025 01:53:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7B8D83858D21 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 7B8D83858D21 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::330 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1739238815; cv=none; b=rvYG0eED71d1Yo9160vmcBWs8bilAL2QKcEDEp4iesuiA8d40bpKgo6NszWwrLKC1vzyu79FBRoUHwn6mlaF652AV5O9zJtioHHZSe4asdcofCtNo++90R4lK0g7n+1T8wjXVgC+wuCHsmqjqqa7TmeRRpiN1Drc8vak08SzeAc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1739238815; c=relaxed/simple; bh=DGd+N7n1wn24jCXTN2SarpREsL8X1Df1x7PhCcUX2JY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=sGGn3BYtwmDXZNWVa4JdVy4tUT5iYtB5sOcBiaCxpbXx/IkYvckMBH0HLWuE8Cc53giFHZODJ3a3Asj146aPJfQBsdgBZ2G2CAV350gMeHg4V7scAzmSQfUwMNq5Qze1qjVys1vo1IozMSyixSmQ58bzHjzZh2gVAJ14ECKtows= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7B8D83858D21 Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-71e10e6a1ceso1425926a34.0 for ; Mon, 10 Feb 2025 17:53:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739238815; x=1739843615; 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=ithAvFI13Qw/YPzaIXYxN5D6P1D16FOZ4GE1P3L/Q/w=; b=c395hKFL/XNP2vzXg96Lirs5DvbQYhuUKrDr98zpRL/HqdKYIJsQdnL8g8c5GBPVhx 89IpDr4IaWftmWbmXQrOZP2PrQ6um6VX2Fqvl6/O1WqBrrLV8YLY40WxBDkusQGCs9D6 sd5rOD5rh35vNskrLym19YvDsvMRb/vsweBBjSBws/pM4H6Vj/vwk+lyGhpRTtkKCaKP 10VGVS9XKcJ/otAlBVdTx9YZ30QngUCcia9MEpf/6sCnehViIZ1uKyS94zU03Oz6daV+ Jdz6U5orlguqJIWFvVDLc0pUrYfQGBRb+6xgLlIydEQ12ybzuX/dg1NRH437ocg9SeHu Q1/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739238815; x=1739843615; 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=ithAvFI13Qw/YPzaIXYxN5D6P1D16FOZ4GE1P3L/Q/w=; b=qLheA5oqot4i+51JY345zMYcNbq3M8onE6n76KTKsSih5accpJ3ffSNCoknse/QX7P Z14vvw/S/BqnklnEN5oALC+NN9Wt64rdxsnkNA8pNeOGOft0s2vrIVo12lCWIRn9zoLY e55yh76DYwFGE6+otMed9BTydTrwq5urn+ztslYnY6N8H/GU+nZLXbBhKUbdUoy89Ot2 Te3Knb1JF6JufxrJgKNKCIyJWbvHp3TLMyvmpjOgh9JG7T6j+V1riXqiz5DyA5qVBKJL lAWbYFZ24Fjdz8whOH248vqVtR/vJyA6ba2NMx8WSJ+VcYYpgRhHZd3Rz1X9Zq8WPoIB 4f7Q== X-Gm-Message-State: AOJu0YytrJ4x3p3uBxWbsQEjudHxYSbd3J92ca6tU0OWCMziKbvqY403 s8A4I4H076fGjnpTtPWJ8l2g1k4+UJpQORpgaSJz42s4UqCE1NbpkS/5wTAsIe7shJwlW4TvsxN O X-Gm-Gg: ASbGncucCQVxS+LIFJCoZzA6Z3MwPUuI2855ZOMOE/bDu+FL0FovG24QxV1fzUYCLFD ykIkhaBTyk0YvENdJM+xKM1rhAYQ0xjQJNXLRsU8sWC+uK3Z9LmMdZwXNoKCaJmvdA9ktL/a3YU rvi2fNz+njAFdxCi73IhjjJ93KBpLWrB5a3ldZYWU40eWi9amkGLG8Mxr3iOhEap8QLCgMeXq3l tEgB67M+ig+XRVbQhjR8UJ0T9gNOC5g9/TIzJyYopcjLjNmCG3PjE3vWHA36jh5jE0Qrg3eNzxH feDCC438KVr5ak0OzlXH0chH X-Google-Smtp-Source: AGHT+IFn8dkZDYwA51EUzUVu/hwUqpDIlFi5TD6gLZIZAetHm5qetaWyzxdD5X94g3rNCMOxp5LGig== X-Received: by 2002:a05:6830:6d19:b0:718:1163:ef8f with SMTP id 46e09a7af769-726b87a6833mr10155191a34.2.1739238814703; Mon, 10 Feb 2025 17:53:34 -0800 (PST) Received: from localhost ([2804:14d:7e39:8470:920:75be:7a6c:1b7a]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-726d33194b9sm1452058a34.63.2025.02.10.17.53.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 17:53:33 -0800 (PST) From: Thiago Jung Bauermann To: "Schimpe, Christina" Cc: "gdb-patches@sourceware.org" Subject: Re: [PATCH 11/12] gdb, gdbarch: Introduce gdbarch method to get the shadow stack pointer. In-Reply-To: (Christina Schimpe's message of "Mon, 10 Feb 2025 08:58:36 +0000") References: <20241220200501.324191-1-christina.schimpe@intel.com> <20241220200501.324191-12-christina.schimpe@intel.com> <87ldujhhjh.fsf@linaro.org> <87v7tlqdzw.fsf@linaro.org> User-Agent: mu4e 1.12.8; emacs 29.4 Date: Mon, 10 Feb 2025 22:53:31 -0300 Message-ID: <87v7ths0v8.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 "Schimpe, Christina" writes: >> -----Original Message----- >> From: Thiago Jung Bauermann >> Sent: Saturday, February 8, 2025 5:04 AM >> To: Schimpe, Christina >> Cc: gdb-patches@sourceware.org >> Subject: Re: [PATCH 11/12] gdb, gdbarch: Introduce gdbarch method to get the >> shadow stack pointer. >> >> >> "Schimpe, Christina" writes: >> >> >> -----Original Message----- >> >> From: Thiago Jung Bauermann >> >> Sent: Thursday, February 6, 2025 4:35 AM >> >> To: Schimpe, Christina >> >> Cc: gdb-patches@sourceware.org >> >> Subject: Re: [PATCH 11/12] gdb, gdbarch: Introduce gdbarch method to >> >> get the shadow stack pointer. >> >> >> >> >> >> "Schimpe, Christina" writes: >> >> >> >> > diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py >> >> > index 52f265e8e0e..df70cb082a4 100644 >> >> > --- a/gdb/gdbarch_components.py >> >> > +++ b/gdb/gdbarch_components.py >> >> > @@ -2822,6 +2822,8 @@ Some targets support special >> >> > hardware-assisted control-flow protection technologies. For >> >> > example, Intel's Control-flow Enforcement Technology (CET) >> >> > provides a shadow stack and >> >> indirect branch tracking. >> >> > To enable inferior calls the function shadow_stack_push has to be provided. >> >> > +The method get_shadow_stack_pointer has to be provided to enable >> >> > +displaced stepping. >> >> > >> >> > Push the address NEW_ADDR on the shadow stack and update the >> >> > shadow stack pointer. >> >> > @@ -2831,3 +2833,11 @@ pointer. >> >> > params=[("CORE_ADDR", "new_addr")], >> >> > predicate=True, >> >> > ) >> >> > + >> >> > +Method( >> >> > + type="std::optional", >> >> > + name="get_shadow_stack_pointer", >> >> > + params=[], >> >> > + predefault="default_get_shadow_stack_pointer", >> >> > + invalid=False, >> >> > +) >> >> >> >> Ideally, there should be a comment on this method entry. >> >> >> >> This method is only used in amd64-tdep.c and i386-tdep.c. IMHO it >> >> would be better to put it in i386_gdbarch_tdep instead. >> > >> > Hi Thiago, >> > >> > Thank you for the review. >> > >> > As also discussed here: >> > https://sourceware.org/pipermail/gdb-patches/2025-February/215266.html >> > , I wonder if it's better to keep the code generic. >> >> Indeed, that's a good point. In the case of this method, I have an additional >> concern though: its callers assume that if gdbarch_get_shadow_stack_pointer >> returns a value, then it means that shadow stacks are enabled in the inferior. But >> this is an x86 particularity. On AArch64, if the processor supports shadow stacks >> then the shadow stack register is always available, even if shadow stacks are >> turned off. > > Ah ok, I did not know. > >> So I think that there should be an additional method to indicate whether shadow >> stacks are enabled in the inferior. > > Yes, that makes sense. But I want to avoid that we call ptrace twice on x86, once in the method > to check the enablement state and once to get the shadow stack pointer. Ok, makes sense. > Would something like that be acceptable as well? > > Method( > comment=""" > If possible, return the shadow stack pointer. On some architectures, the shadow stack > pointer is available even if the feature is disabled. To return the shadow stack > enablement state configure SHADOW_STACK_ENABLED. > """, > type="std::optional", > name="get_shadow_stack_pointer", > params=[("bool &", "shadow_stack_enabled")], > predefault="default_get_shadow_stack_pointer", > invalid=False, > ) Yes, this looks good. -- Thiago