From: "Schimpe, Christina" <christina.schimpe@intel.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 09/12] gdb, gdbarch: Enable inferior calls for shadow stack support.
Date: Fri, 20 Dec 2024 20:04:58 +0000 [thread overview]
Message-ID: <20241220200501.324191-10-christina.schimpe@intel.com> (raw)
In-Reply-To: <20241220200501.324191-1-christina.schimpe@intel.com>
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.
---
gdb/gdbarch-gen.c | 32 ++++++++++++++++++++++++++++++++
gdb/gdbarch-gen.h | 14 ++++++++++++++
gdb/gdbarch_components.py | 16 ++++++++++++++++
gdb/infcall.c | 6 ++++++
4 files changed, 68 insertions(+)
diff --git a/gdb/gdbarch-gen.c b/gdb/gdbarch-gen.c
index d05c7a3cbdf..c33c476dfdb 100644
--- a/gdb/gdbarch-gen.c
+++ b/gdb/gdbarch-gen.c
@@ -260,6 +260,7 @@ struct gdbarch
gdbarch_get_pc_address_flags_ftype *get_pc_address_flags = default_get_pc_address_flags;
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_shadow_stack_push_ftype *shadow_stack_push = nullptr;
};
/* Create a new ``struct gdbarch'' based on information provided by
@@ -531,6 +532,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
/* Skip verify of get_pc_address_flags, invalid_p == 0. */
/* 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 shadow_stack_push, has predicate. */
if (!log.empty ())
internal_error (_("verify_gdbarch: the following are invalid ...%s"),
log.c_str ());
@@ -1396,6 +1398,12 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
gdb_printf (file,
"gdbarch_dump: use_target_description_from_corefile_notes = <%s>\n",
host_address_to_string (gdbarch->use_target_description_from_corefile_notes));
+ 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);
}
@@ -5507,3 +5515,27 @@ set_gdbarch_use_target_description_from_corefile_notes (struct gdbarch *gdbarch,
{
gdbarch->use_target_description_from_corefile_notes = use_target_description_from_corefile_notes;
}
+
+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)
+{
+ 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);
+}
+
+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 9fda85f860f..ff14a3666b9 100644
--- a/gdb/gdbarch-gen.h
+++ b/gdb/gdbarch-gen.h
@@ -1778,3 +1778,17 @@ extern void set_gdbarch_read_core_file_mappings (struct gdbarch *gdbarch, gdbarc
typedef bool (gdbarch_use_target_description_from_corefile_notes_ftype) (struct gdbarch *gdbarch, struct bfd *corefile_bfd);
extern bool gdbarch_use_target_description_from_corefile_notes (struct gdbarch *gdbarch, struct bfd *corefile_bfd);
extern void set_gdbarch_use_target_description_from_corefile_notes (struct gdbarch *gdbarch, gdbarch_use_target_description_from_corefile_notes_ftype *use_target_description_from_corefile_notes);
+
+/* 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.
+
+ Push the address NEW_ADDR on 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);
+extern void gdbarch_shadow_stack_push (struct gdbarch *gdbarch, CORE_ADDR new_addr);
+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 cc7c6d8677b..52f265e8e0e 100644
--- a/gdb/gdbarch_components.py
+++ b/gdb/gdbarch_components.py
@@ -2815,3 +2815,19 @@ The corefile's bfd is passed through COREFILE_BFD.
predefault="default_use_target_description_from_corefile_notes",
invalid=False,
)
+
+Method(
+ comment="""
+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.
+
+Push the address NEW_ADDR on the shadow stack and update the shadow stack
+pointer.
+""",
+ type="void",
+ name="shadow_stack_push",
+ params=[("CORE_ADDR", "new_addr")],
+ predicate=True,
+)
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);
+
/* 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
ID so that the breakpoint code can correctly re-identify the
--
2.34.1
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Sean Fennelly, Jeffrey Schneiderman, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
next prev parent reply other threads:[~2024-12-20 20:09 UTC|newest]
Thread overview: 72+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-20 20:04 [PATCH 00/12] Add CET " Schimpe, Christina
2024-12-20 20:04 ` [PATCH 01/12] gdb, testsuite: Rename set_sanitizer_default to append_environment Schimpe, Christina
2025-01-28 13:45 ` Guinevere Larsen
2025-01-30 13:07 ` Schimpe, Christina
2025-01-30 14:27 ` Tom de Vries
2025-01-30 16:39 ` Schimpe, Christina
2024-12-20 20:04 ` [PATCH 02/12] gdbserver: Add optional runtime register set type Schimpe, Christina
2025-01-28 13:35 ` Guinevere Larsen
2025-01-30 10:28 ` Schimpe, Christina
2025-01-30 13:53 ` Guinevere Larsen
2025-01-30 17:43 ` Schimpe, Christina
2025-02-06 2:59 ` Thiago Jung Bauermann
2025-02-06 12:15 ` Schimpe, Christina
2024-12-20 20:04 ` [PATCH 03/12] gdbserver: Add assert in x86_linux_read_description Schimpe, Christina
2025-02-06 3:00 ` Thiago Jung Bauermann
2024-12-20 20:04 ` [PATCH 04/12] gdb: Sync up x86-gcc-cpuid.h with cpuid.h from gcc 14 branch Schimpe, Christina
2025-02-06 3:03 ` Thiago Jung Bauermann
2025-02-06 12:23 ` Schimpe, Christina
2024-12-20 20:04 ` [PATCH 05/12] gdb, gdbserver: Use xstate_bv for target description creation on x86 Schimpe, Christina
2025-01-30 14:51 ` Guinevere Larsen
2025-01-30 16:45 ` Schimpe, Christina
2025-02-06 3:09 ` Thiago Jung Bauermann
2025-02-06 12:33 ` Schimpe, Christina
2024-12-20 20:04 ` [PATCH 06/12] gdb, gdbserver: Add support of Intel shadow stack pointer register Schimpe, Christina
2025-02-06 3:13 ` Thiago Jung Bauermann
2025-02-06 14:33 ` Schimpe, Christina
2025-02-08 3:44 ` Thiago Jung Bauermann
2024-12-20 20:04 ` [PATCH 07/12] gdb, bfd: amd64 linux coredump support with shadow stack Schimpe, Christina
2025-02-06 3:15 ` Thiago Jung Bauermann
2025-02-07 11:54 ` Schimpe, Christina
2024-12-20 20:04 ` [PATCH 08/12] gdb: Handle shadow stack pointer register unwinding for amd64 linux Schimpe, Christina
2025-01-30 14:29 ` Guinevere Larsen
2025-01-30 16:11 ` Schimpe, Christina
2025-01-30 16:13 ` Guinevere Larsen
2025-01-30 16:40 ` Schimpe, Christina
2025-02-06 3:30 ` Thiago Jung Bauermann
2025-02-06 14:40 ` Schimpe, Christina
2024-12-20 20:04 ` Schimpe, Christina [this message]
2025-02-06 3:31 ` [PATCH 09/12] gdb, gdbarch: Enable inferior calls for shadow stack support Thiago Jung Bauermann
2025-02-06 15:07 ` Schimpe, Christina
2025-02-08 3:57 ` Thiago Jung Bauermann
2025-02-10 8:37 ` Schimpe, Christina
2024-12-20 20:04 ` [PATCH 10/12] gdb: Implement amd64 linux shadow stack support for inferior calls Schimpe, Christina
2025-02-06 3:34 ` Thiago Jung Bauermann
2025-02-07 11:55 ` Schimpe, Christina
2024-12-20 20:05 ` [PATCH 11/12] gdb, gdbarch: Introduce gdbarch method to get the shadow stack pointer Schimpe, Christina
2025-01-28 20:27 ` Guinevere Larsen
2025-01-30 10:33 ` Luis Machado
2025-01-30 12:34 ` Schimpe, Christina
2025-01-30 13:42 ` Guinevere Larsen
2025-02-06 3:35 ` Thiago Jung Bauermann
2025-02-07 12:01 ` Schimpe, Christina
2025-02-08 4:03 ` Thiago Jung Bauermann
2025-02-10 8:58 ` Schimpe, Christina
2025-02-11 1:53 ` Thiago Jung Bauermann
2025-02-15 3:45 ` Thiago Jung Bauermann
2025-02-16 10:45 ` Schimpe, Christina
2025-02-20 8:48 ` Schimpe, Christina
2025-02-21 5:10 ` Thiago Jung Bauermann
2025-02-21 9:41 ` Schimpe, Christina
2024-12-20 20:05 ` [PATCH 12/12] gdb: Enable displaced stepping with shadow stack on amd64 linux Schimpe, Christina
2024-12-20 20:14 ` Eli Zaretskii
2025-01-02 9:04 ` Schimpe, Christina
2025-01-02 9:15 ` Eli Zaretskii
2025-02-06 3:37 ` Thiago Jung Bauermann
2025-01-16 14:01 ` [PING][PATCH 00/12] Add CET shadow stack support Schimpe, Christina
2025-01-27 9:44 ` [PING*2][PATCH " Schimpe, Christina
2025-01-30 15:01 ` [PATCH " Guinevere Larsen
2025-01-30 17:46 ` Schimpe, Christina
2025-02-04 3:57 ` Thiago Jung Bauermann
2025-02-04 9:40 ` Schimpe, Christina
2025-02-06 3:44 ` Thiago Jung Bauermann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241220200501.324191-10-christina.schimpe@intel.com \
--to=christina.schimpe@intel.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox