From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id QJVKIYn3iWhT9j8AWB0awg (envelope-from ) for ; Wed, 30 Jul 2025 06:44:25 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=JUJvIDmh; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 841521E102; Wed, 30 Jul 2025 06:44:25 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-10.1 required=5.0 tests=ARC_SIGNED,ARC_VALID, BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,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 C96831E091 for ; Wed, 30 Jul 2025 06:44:24 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4E5083858D33 for ; Wed, 30 Jul 2025 10:44:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E5083858D33 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=JUJvIDmh Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 5E8DF3858408 for ; Wed, 30 Jul 2025 10:42:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5E8DF3858408 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5E8DF3858408 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1753872165; cv=none; b=TsmB2y1Ahxjd2NSsLtinbG2NOgWApCI3HtGJmtokRKi1WAReCqyvzeKhKtY1mpX+Ni2asXLYgMPxtIp9R4MhlRhiRN+9lzsTKj2bgaQSSyL+tfprqHPjF3TTP7hl0U/2ZO9X3dKNmHDezmHA3sBn4fLYUBUG8HJe1TI+RbXYOOk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1753872165; c=relaxed/simple; bh=FmVx3jmnF/ac2ZKOOQvCWjr90bGUpTa183Q5D9ZX/hc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=t9vH6JSYdXYHAWVHaIo3z6fWMHCbVSIT5KfVwSgwj74gYQqaV43n4sSbJTca6qbuSrdH1a22AOMdLc2z6MVOZWh1mHn+j7lHTbx0QPDJZmLBMH3bYF41S6X90YNRKyWvlyRa99ytGkUD4NWyfB1K6s0P24c5IU3rvVhFibAb0c4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5E8DF3858408 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1753872165; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=b7dzbucjDokvazxTWZ2QTmDXo0vLZ29CekzvajVa90M=; b=JUJvIDmhMEmcEpnHigUxyMZJSR7i4CtmZsBozNv4643541xSRn2QZASj7QgBfleNnSKMNg TUPaaKmYteq2TOJ+s/n39gKC2LozCCT8l1p67PxsAiYvaTHf7MAJzDVUVJ9CUQf5n9sjYX h96gw/+axm+JLwLN/SuSbwQDQuOwtW4= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-452-so7b9cQ6MsiZtvkoUd11sQ-1; Wed, 30 Jul 2025 06:42:43 -0400 X-MC-Unique: so7b9cQ6MsiZtvkoUd11sQ-1 X-Mimecast-MFC-AGG-ID: so7b9cQ6MsiZtvkoUd11sQ_1753872162 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-45600d19a2aso51140115e9.1 for ; Wed, 30 Jul 2025 03:42:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753872162; x=1754476962; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=b7dzbucjDokvazxTWZ2QTmDXo0vLZ29CekzvajVa90M=; b=iHgdlk/hYuseWIlGtMUqCq+IyNuNlHpDzQBoU30YDDShU1y63BiQgDoKTbpEQ6kq9K TGAZpj/r4q5eOtyvZJ04hMQLF9wnlcNzZ8zRUvwxFBO8uFNIZln/8KCJlBzNQ6WTtyBh VOoGt9NPb+tRLHkxiNmt3oqE+9b799CSow579ZvhfkPNkhvDrft5dx/xPboqEoQLBaxL NrsRsYZKIfmalGqkrLTVbkB7T22iax+ImOZ2Qj2TeRr8t41slnH9+hFNGIiyCGR4xMYC yAMaKSTvMTyVvpS/zZGnzJJtJQsPb4T4ArmLCHfSNBqejdICzEypUzmdO4nGEff6Ur08 SaqA== X-Forwarded-Encrypted: i=1; AJvYcCVZFWlsBqd9vEPp3XUzF2gdWZesaoRzYDY78cQauGyg9h+xxfVRRxD88d82yjEB3lK/t1Ah8DgdU8Nt8A==@sourceware.org X-Gm-Message-State: AOJu0Yy55JD4nl2z4GBwBJ1/mqN4sre1pd4orLVhi5vk7Upmw0FWdIjJ DbuR3P77KEwFec4iHDQDd/HfaV57JbbPNXQENrWhESe7TFaRWAbBlWCtArK8wVlkuO9METzyn2P kzVIZv0o9cCpMUPTOtDWTrb3edL6u+71Rms1UR/QMQk/G3SzINwbtqkBUF7xYAZA= X-Gm-Gg: ASbGncsnvtFZxshwLVWRSR1bM4p4cQ2+NU2Cf8V+prFFmLM8vOH4gAyoWWzHNtmOjd5 72PxTYbAd6sMs4fcpXl72yozh4WpM0f4g7aCyfMfXVZCsML5LSAZvzh1+gWwb+Ga7y6oGsy87PZ omSqtT5svVzDvBJRPeJ1S1ALDr3WsLVE9cUtx/8Nr/3IzYj4Fb9Y4nJH/UUAt3x7Bw93hpfALht M07QvD0dMN/ENXfNJZrE244ObLYGvzIQ9lw0sAJJaYHfX7A16uUuqlkt/1310pLn51lmySW9ulo wwA1DwJPTKbwO4kML2Q7DbMoGtFkgGCkN2YlBjOxjgK6xzbnoYUx2rZP7GmAjA== X-Received: by 2002:a05:600c:3ba1:b0:456:1fd9:c8f0 with SMTP id 5b1f17b1804b1-45892b947c9mr29592225e9.2.1753872162204; Wed, 30 Jul 2025 03:42:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEmY8ROVgAGNvKl0ZQTyzkd8rp3evDCU2MpTftl/4JaNjyc2ZqwgL4SgJwfikvC7Y5+k65CoA== X-Received: by 2002:a05:600c:3ba1:b0:456:1fd9:c8f0 with SMTP id 5b1f17b1804b1-45892b947c9mr29591845e9.2.1753872161666; Wed, 30 Jul 2025 03:42:41 -0700 (PDT) Received: from localhost (120.81.93.209.dyn.plus.net. [209.93.81.120]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45899fb191fsm17342675e9.21.2025.07.30.03.42.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jul 2025 03:42:41 -0700 (PDT) From: Andrew Burgess To: Christina Schimpe , gdb-patches@sourceware.org Cc: thiago.bauermann@linaro.org, luis.machado@arm.com Subject: Re: [PATCH v5 09/12] gdb, gdbarch: Enable inferior calls for shadow stack support. In-Reply-To: <20250628082810.332526-10-christina.schimpe@intel.com> References: <20250628082810.332526-1-christina.schimpe@intel.com> <20250628082810.332526-10-christina.schimpe@intel.com> Date: Wed, 30 Jul 2025 11:42:40 +0100 Message-ID: <87ikjac63j.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: IN2M_f43GTocKZyf533YBMkD4X3e-iwzuBhADNyBKLY_1753872162 X-Mimecast-Originator: redhat.com 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: > Inferior calls in GDB reset the current PC to the beginning of the function > that is called. As no call instruction is executed the new return address > needs to be pushed to the shadow stack and the shadow stack pointer needs > to be updated. > > This commit adds a new gdbarch method to push an address on the shadow > stack. The method is used to adapt the function 'call_function_by_hand_dummy' > for inferior call shadow stack support. > > Reviewed-by: Thiago Jung Bauermann > Reviewed-By: Luis Machado LGTM. Approved-By: Andrew Burgess Thanks, Andrew > --- > gdb/gdbarch-gen.c | 32 ++++++++++++++++++++++++++++++++ > gdb/gdbarch-gen.h | 14 ++++++++++++++ > gdb/gdbarch_components.py | 16 ++++++++++++++++ > gdb/infcall.c | 14 ++++++++++---- > 4 files changed, 72 insertions(+), 4 deletions(-) > > diff --git a/gdb/gdbarch-gen.c b/gdb/gdbarch-gen.c > index fc570d37a8d..a4b72793fd8 100644 > --- a/gdb/gdbarch-gen.c > +++ b/gdb/gdbarch-gen.c > @@ -262,6 +262,7 @@ struct gdbarch > gdbarch_read_core_file_mappings_ftype *read_core_file_mappings = default_read_core_file_mappings; > gdbarch_use_target_description_from_corefile_notes_ftype *use_target_description_from_corefile_notes = default_use_target_description_from_corefile_notes; > gdbarch_core_parse_exec_context_ftype *core_parse_exec_context = default_core_parse_exec_context; > + gdbarch_shadow_stack_push_ftype *shadow_stack_push = nullptr; > }; > > /* Create a new ``struct gdbarch'' based on information provided by > @@ -535,6 +536,7 @@ verify_gdbarch (struct gdbarch *gdbarch) > /* Skip verify of read_core_file_mappings, invalid_p == 0. */ > /* Skip verify of use_target_description_from_corefile_notes, invalid_p == 0. */ > /* Skip verify of core_parse_exec_context, invalid_p == 0. */ > + /* Skip verify of shadow_stack_push, has predicate. */ > if (!log.empty ()) > internal_error (_("verify_gdbarch: the following are invalid ...%s"), > log.c_str ()); > @@ -1406,6 +1408,12 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file) > gdb_printf (file, > "gdbarch_dump: core_parse_exec_context = <%s>\n", > host_address_to_string (gdbarch->core_parse_exec_context)); > + gdb_printf (file, > + "gdbarch_dump: gdbarch_shadow_stack_push_p() = %d\n", > + gdbarch_shadow_stack_push_p (gdbarch)); > + gdb_printf (file, > + "gdbarch_dump: shadow_stack_push = <%s>\n", > + host_address_to_string (gdbarch->shadow_stack_push)); > if (gdbarch->dump_tdep != NULL) > gdbarch->dump_tdep (gdbarch, file); > } > @@ -5551,3 +5559,27 @@ set_gdbarch_core_parse_exec_context (struct gdbarch *gdbarch, > { > gdbarch->core_parse_exec_context = core_parse_exec_context; > } > + > +bool > +gdbarch_shadow_stack_push_p (struct gdbarch *gdbarch) > +{ > + gdb_assert (gdbarch != NULL); > + return gdbarch->shadow_stack_push != NULL; > +} > + > +void > +gdbarch_shadow_stack_push (struct gdbarch *gdbarch, CORE_ADDR new_addr, regcache *regcache) > +{ > + gdb_assert (gdbarch != NULL); > + gdb_assert (gdbarch->shadow_stack_push != NULL); > + if (gdbarch_debug >= 2) > + gdb_printf (gdb_stdlog, "gdbarch_shadow_stack_push called\n"); > + gdbarch->shadow_stack_push (gdbarch, new_addr, regcache); > +} > + > +void > +set_gdbarch_shadow_stack_push (struct gdbarch *gdbarch, > + gdbarch_shadow_stack_push_ftype shadow_stack_push) > +{ > + gdbarch->shadow_stack_push = shadow_stack_push; > +} > diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h > index 281b97b7aa8..71142332540 100644 > --- a/gdb/gdbarch-gen.h > +++ b/gdb/gdbarch-gen.h > @@ -1802,3 +1802,17 @@ extern void set_gdbarch_use_target_description_from_corefile_notes (struct gdbar > typedef core_file_exec_context (gdbarch_core_parse_exec_context_ftype) (struct gdbarch *gdbarch, bfd *cbfd); > extern core_file_exec_context gdbarch_core_parse_exec_context (struct gdbarch *gdbarch, bfd *cbfd); > extern void set_gdbarch_core_parse_exec_context (struct gdbarch *gdbarch, gdbarch_core_parse_exec_context_ftype *core_parse_exec_context); > + > +/* Some targets support special hardware-assisted control-flow protection > + technologies. For example, the Intel Control-Flow Enforcement Technology > + (Intel CET) on x86 provides a shadow stack and indirect branch tracking. > + To enable shadow stack support for inferior calls the shadow_stack_push > + gdbarch hook has to be provided. > + > + Push NEW_ADDR to the shadow stack and update the shadow stack pointer. */ > + > +extern bool gdbarch_shadow_stack_push_p (struct gdbarch *gdbarch); > + > +typedef void (gdbarch_shadow_stack_push_ftype) (struct gdbarch *gdbarch, CORE_ADDR new_addr, regcache *regcache); > +extern void gdbarch_shadow_stack_push (struct gdbarch *gdbarch, CORE_ADDR new_addr, regcache *regcache); > +extern void set_gdbarch_shadow_stack_push (struct gdbarch *gdbarch, gdbarch_shadow_stack_push_ftype *shadow_stack_push); > diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py > index 91c867e69bf..abc79588473 100644 > --- a/gdb/gdbarch_components.py > +++ b/gdb/gdbarch_components.py > @@ -2848,3 +2848,19 @@ which all assume current_inferior() is the one to read from. > predefault="default_core_parse_exec_context", > invalid=False, > ) > + > +Method( > + comment=""" > +Some targets support special hardware-assisted control-flow protection > +technologies. For example, the Intel Control-Flow Enforcement Technology > +(Intel CET) on x86 provides a shadow stack and indirect branch tracking. > +To enable shadow stack support for inferior calls the shadow_stack_push > +gdbarch hook has to be provided. > + > +Push NEW_ADDR to the shadow stack and update the shadow stack pointer. > +""", > + type="void", > + name="shadow_stack_push", > + params=[("CORE_ADDR", "new_addr"), ("regcache *", "regcache")], > + predicate=True, > +) > diff --git a/gdb/infcall.c b/gdb/infcall.c > index 2b5936d1621..db6d6774367 100644 > --- a/gdb/infcall.c > +++ b/gdb/infcall.c > @@ -1448,10 +1448,16 @@ call_function_by_hand_dummy (struct value *function, > /* Create the dummy stack frame. Pass in the call dummy address as, > presumably, the ABI code knows where, in the call dummy, the > return address should be pointed. */ > - sp = gdbarch_push_dummy_call (gdbarch, function, > - get_thread_regcache (inferior_thread ()), > - bp_addr, args.size (), args.data (), > - sp, return_method, struct_addr); > + regcache *regcache = get_thread_regcache (inferior_thread ()); > + sp = gdbarch_push_dummy_call (gdbarch, function, regcache, bp_addr, > + args.size (), args.data (), sp, > + return_method, struct_addr); > + > + /* Push the return address of the inferior (bp_addr) to the shadow stack > + and update the shadow stack pointer. As we don't execute a call > + instruction to call the function we need to handle this manually. */ > + if (gdbarch_shadow_stack_push_p (gdbarch)) > + gdbarch_shadow_stack_push (gdbarch, bp_addr, regcache); > > /* Set up a frame ID for the dummy frame so we can pass it to > set_momentary_breakpoint. We need to give the breakpoint a frame > -- > 2.43.0