From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id CGxaE1HWpmfMuCcAWB0awg (envelope-from ) for ; Fri, 07 Feb 2025 22:58:09 -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=BBXJ8HRe; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 4C80E1E105; Fri, 7 Feb 2025 22:58:09 -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 BC2B01E05C for ; Fri, 7 Feb 2025 22:58:08 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 64A8E3857835 for ; Sat, 8 Feb 2025 03:58:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 64A8E3857835 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=BBXJ8HRe Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by sourceware.org (Postfix) with ESMTPS id C10AC3857835 for ; Sat, 8 Feb 2025 03:57:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C10AC3857835 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 C10AC3857835 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::632 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1738987058; cv=none; b=KI8xItexSm6BSi4OWwF1lJWXP/xJPHZAnMmWRK6e7ERAvurxPIk6lgfhoHv9Zr21mB+8Er9rFTsXVWRYvWTX2uAafC7inA0iro0GXyigm3GcMhIa4kR1YYcQsYOD3/ytTaICbomgXddWrRnWwfxvyjX8AQ9J6JDUCE62GRp36OA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1738987058; c=relaxed/simple; bh=W95YNg4qZ7/ASxvUrMHGZ9M5NF4JiR6n5i+zyuBJ1qs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Vdz3xz6acxqhleemNALW0935oiCV9fa1Anv3aURI4T0lkkz/HfIVGN1bKU/gcjrEF6f7Duwa58TarcaOTf+hpaSZBp7nEB3p3elR4Wjn152AnQw6hhWvengwalUUnJ0Xi7hmA40j0dKeDyn7NjLicSf1PQmxFNjyzP44e2ondww= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C10AC3857835 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-21f3e2b4eceso47115475ad.2 for ; Fri, 07 Feb 2025 19:57:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1738987057; x=1739591857; 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=FLC5mABX4uCwdMLUC1GDYLBDHx5GG1cQAjpiXSFafp0=; b=BBXJ8HResFimL0421JPN5R2rGvQL0r+klhFA1WDf7Vz/kgmD82U5h2Dcu3SDjC5RxE XdP5RR1woUgdXdItJqwadL4Oz5fE8MF3gKuIHof2uefMjQrU5lBLjkGqOi28fblDPMx7 jyxaWbIAjqYyAjtop/xQ08OHjWLmyd0HzsqA0RAu9p8XE/zhin1LbsVop0l39SdlA5x1 VepO4xOHmCTZPdnh8hw0sGfGSTscSOp1pTl6QUeIX7Buf0eSw7nEtRfcih3ciMzNAPXp HT/HzF3W9R5fwf0rZiYLnZjrV/wsAScxMuEmgrGVIk5GYW8tdJ6pzJ1tCflWJUkBHr6L n9AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738987057; x=1739591857; 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=FLC5mABX4uCwdMLUC1GDYLBDHx5GG1cQAjpiXSFafp0=; b=gQqESDgKwP5yyKnVz692qibeMM+aiINVXbYtg8WsUXN+FXyarssx22SaTmhH1Y6Tvg YYNQt8svpjcx9jH1/BPP9FDAsvaistH2qeD2QM/m3ZVDaMhRC8dCqZ1X93DKT51Z2U80 /1DGjv0i32rqgSNwdeCmC4oR4ufy4QHuPB3Uny4GvqYvya62SPISyLc7V7WERtpoQpgI CfKnQHTFye4GazUi1aNoFDt2+77g8yH04Bgz+rHNJqjj0iaLwTAtReiIpjXC6PTyBeIZ +yJ9Zbkt0OHI5KBCZdqD99XLCpaehcjDAqE5oS7k1cEXUHETIXEx0kztddFX3ExOtC+q ZRrA== X-Gm-Message-State: AOJu0YwkSg/IsH50M3TMCOcX3mxXKU/IQTFSHm5kWMZmzM4K9iNaZU/Z o8SDNI+W7Q9nPBRUVNPNdbAF+bphY+WPdG34SJk+aIc9VmpCnfHip6EOIDpNbiI= X-Gm-Gg: ASbGncsnARS6d/RR/w4DMgjHH9zGSu7VmoXNJi/4PpwY6IdhgYdb8CM8uPDk2cTkq9Y 4XqbEZDWSLQhbWj/hS5dkQc6AfyciCXbWmvAebigIxQvkP7HibM49EQ5NMSLZoDQPBhYBOGlYQg gX9Sb4Xd9GPDcix0Lvw2vEscbgBsFTQWryei9gTsYcDxW/256hEVr1ibdPbOIyICzbKrt4K4xoo ZyEyDcJnhBSY4aDQOsqt2APoVQGnlV/3GNZphZe6Y8j/QphdAbcp1STW+I3YBxMxzqXbIZXW4qm a6lp3f2+4c47BX/U3rKZyYE= X-Google-Smtp-Source: AGHT+IGJCz4TOWvyf3uzKCG4cwGVDF6phyQcGlGhps9EDiunG5/NALw1wYgj+xHuyJzCO6TZD8QFjQ== X-Received: by 2002:a05:6a20:c88b:b0:1e1:dbfd:1fde with SMTP id adf61e73a8af0-1ee03b425c8mr10130997637.27.1738987056849; Fri, 07 Feb 2025 19:57:36 -0800 (PST) Received: from localhost ([2804:14d:7e39:8470:b53a:98d4:8895:d0]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73048ae7e54sm3796674b3a.76.2025.02.07.19.57.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Feb 2025 19:57:36 -0800 (PST) From: Thiago Jung Bauermann To: "Schimpe, Christina" Cc: "gdb-patches@sourceware.org" Subject: Re: [PATCH 09/12] gdb, gdbarch: Enable inferior calls for shadow stack support. In-Reply-To: (Christina Schimpe's message of "Thu, 6 Feb 2025 15:07:28 +0000") References: <20241220200501.324191-1-christina.schimpe@intel.com> <20241220200501.324191-10-christina.schimpe@intel.com> <87tt97hhpf.fsf@linaro.org> User-Agent: mu4e 1.12.8; emacs 29.4 Date: Sat, 08 Feb 2025 00:57:33 -0300 Message-ID: <871pw9rsuq.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: Thursday, February 6, 2025 4:32 AM >> To: Schimpe, Christina >> Cc: gdb-patches@sourceware.org >> Subject: Re: [PATCH 09/12] gdb, gdbarch: Enable inferior calls for shadow stack >> support. >> >> >> "Schimpe, Christina" writes: >> >> > diff --git a/gdb/infcall.c b/gdb/infcall.c index >> > 6399278c6ae..3a4f1e35a2f 100644 >> > --- a/gdb/infcall.c >> > +++ b/gdb/infcall.c >> > @@ -1453,6 +1453,12 @@ call_function_by_hand_dummy (struct value >> *function, >> > bp_addr, args.size (), args.data (), >> > sp, return_method, struct_addr); >> > >> > + /* Push the return address of the inferior (bp_addr) on the shadow stack >> > + and update the shadow stack pointer. As we don't execute a call >> > + instruction to start the inferior we need to handle this >> > + manually. */ if (gdbarch_shadow_stack_push_p (gdbarch)) >> > + gdbarch_shadow_stack_push (gdbarch, bp_addr); >> > + >> >> For AArch64's Guarded Control Stack, instead of adding a new gdbarch method I >> added this change to aarch64_push_dummy_call: >> >> if (aarch64_gcs_is_enabled (regcache)) >> aarch64_push_gcs_entry (regcache, bp_addr); >> >> To implement aarch64_gcs_is_enabled I did add a new method to >> aarch64_gdbarch_tdep so that OS-independent code in aarch64-tdep.c could call >> Linux-specific logic in aarch64-linux-tdep.c: >> >> static bool >> aarch64_gcs_is_enabled (regcache *regs) >> { >> gdbarch *arch = regs->arch (); >> aarch64_gdbarch_tdep *tdep = gdbarch_tdep (arch); >> >> if (tdep->gcs_is_enabled == nullptr) >> return false; >> >> return tdep->gcs_is_enabled (regs); >> } >> >> Wouldn't a similar approach work for amd64? > > Hi Thiago, > > Thank you for the feedback! > > I think I could also fix it in amd64_push_dummy_call by implementing it in a similar way > than you do. > But isn't it better to keep the code generic ? > > Generic code for handling shadow stacks is also required for the implementation of "bt > shadow", > as I tried to provide an implementation that can be used by other architectures as well. Yes, that is a good point. I'm on the fence on this one. On the one hand, there's value in keeping generic code simpler if something can be handled just as well by arch-specific code, but also it's good to share code between architectures. My suggestion for this gdbarch hook then is that it should also accept a regcache as argument. call_function_by_hand_dummy already obtains it so that it can call gdbarch_push_dummy_call, so it avoids another call to inferior_thread deeper in the stack since the hook implementation will need it. -- Thiago