]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
gdb, gdbserver: Add support of Intel shadow stack pointer register.
authorChristina Schimpe <christina.schimpe@intel.com>
Fri, 29 Mar 2019 15:38:50 +0000 (16:38 +0100)
committerChristina Schimpe <christina.schimpe@intel.com>
Fri, 29 Aug 2025 17:02:09 +0000 (17:02 +0000)
commit63b862be762e1e6e7ce667c6b4a1a3dd79939bf4
treecf8c814f8e03c1bd15fc41843911dc8ebaf2399e
parent6ef3896cfe781078bf5b576c0e5a264874f2381c
gdb, gdbserver: Add support of Intel shadow stack pointer register.

This patch adds the user mode register PL3_SSP which is part of the
Intel(R) Control-Flow Enforcement Technology (CET) feature for support
of shadow stack.
For now, only native and remote debugging support for shadow stack
userspace on amd64 linux are covered by this patch including 64 bit and
x32 support.  32 bit support is not covered due to missing Linux kernel
support.

This patch requires fixing the test gdb.base/inline-frame-cycle-unwind
which is failing in case the shadow stack pointer is unavailable.
Such a state is possible if shadow stack is disabled for the current thread
but supported by HW.

This test uses the Python unwinder inline-frame-cycle-unwind.py which fakes
the cyclic stack cycle by reading the pending frame's registers and adding
them to the unwinder:

~~~
for reg in pending_frame.architecture().registers("general"):
     val = pending_frame.read_register(reg)
     unwinder.add_saved_register(reg, val)
     return unwinder
~~~

However, in case the python unwinder is used we add a register (pl3_ssp) that is
unavailable.  This leads to a NOT_AVAILABLE_ERROR caught in
gdb/frame-unwind.c:frame_unwind_try_unwinder and it is continued with standard
unwinders.  This destroys the faked cyclic behavior and the stack is
further unwinded after frame 5.

In the working scenario an error should be triggered:
~~~
bt
0  inline_func () at /tmp/gdb.base/inline-frame-cycle-unwind.c:49^M
1  normal_func () at /tmp/gdb.base/inline-frame-cycle-unwind.c:32^M
2  0x000055555555516e in inline_func () at /tmp/gdb.base/inline-frame-cycle-unwind.c:45^M
3  normal_func () at /tmp/gdb.base/inline-frame-cycle-unwind.c:32^M
4  0x000055555555516e in inline_func () at /tmp/gdb.base/inline-frame-cycle-unwind.c:45^M
5  normal_func () at /tmp/gdb.base/inline-frame-cycle-unwind.c:32^M
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) PASS: gdb.base/inline-frame-cycle-unwind.exp: cycle at level 5: backtrace when the unwind is broken at frame 5
~~~

To fix the Python unwinder, we simply skip the unavailable registers.

Also it makes the test gdb.dap/scopes.exp fail.  The shadow stack feature is
disabled by default, so the pl3_ssp register which is added with my CET
shadow stack series will be shown as unavailable and we see a TCL error:
~~
>>> {"seq": 12, "type": "request", "command": "variables", "arguments": {"variablesReference": 2, "count": 85}}
Content-Length: 129^M
^M
{"request_seq": 12, "type": "response", "command": "variables", "success": false, "message": "value is not available", "seq": 25}FAIL: gdb.dap/scopes.exp: fetch all registers success
ERROR: tcl error sourcing /tmp/gdb/testsuite/gdb.dap/scopes.exp.
ERROR: tcl error code TCL LOOKUP DICT body
ERROR: key "body" not known in dictionary
    while executing
"dict get $val body variables"
    (file "/tmp/gdb/testsuite/gdb.dap/scopes.exp" line 152)
    invoked from within
"source /tmp/gdb/testsuite/gdb.dap/scopes.exp"
    ("uplevel" body line 1)
    invoked from within
"uplevel #0 source /tmp/gdb/testsuite/gdb.dap/scopes.exp"
    invoked from within
"catch "uplevel #0 source $test_file_name" msg"
UNRESOLVED: gdb.dap/scopes.exp: testcase '/tmp/gdb/testsuite/gdb.dap/scopes.exp' aborted due to Tcl error
~~

I am fixing this by enabling the test for CET shadow stack, in case we
detect that the HW supports it:
~~~
    # If x86 shadow stack is supported we need to configure GLIBC_TUNABLES
    # such that the feature is enabled and the register pl3_ssp is
    # available.  Otherwise the reqeust to fetch all registers will fail
    # with "message": "value is not available".
    if { [allow_ssp_tests] } {
append_environment GLIBC_TUNABLES "glibc.cpu.hwcaps" "SHSTK"
    }
~~~

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Luis Machado <luis.machado@arm.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
30 files changed:
gdb/NEWS
gdb/amd64-linux-nat.c
gdb/amd64-linux-tdep.c
gdb/amd64-tdep.c
gdb/amd64-tdep.h
gdb/arch/amd64.c
gdb/arch/i386.c
gdb/arch/x86-linux-tdesc-features.c
gdb/doc/gdb.texinfo
gdb/features/Makefile
gdb/features/i386/32bit-ssp.c [new file with mode: 0644]
gdb/features/i386/32bit-ssp.xml [new file with mode: 0644]
gdb/features/i386/64bit-ssp.c [new file with mode: 0644]
gdb/features/i386/64bit-ssp.xml [new file with mode: 0644]
gdb/i386-tdep.c
gdb/i386-tdep.h
gdb/nat/x86-linux-tdesc.c
gdb/nat/x86-linux.c
gdb/nat/x86-linux.h
gdb/testsuite/gdb.arch/amd64-shadow-stack.c [new file with mode: 0644]
gdb/testsuite/gdb.arch/amd64-shadow-stack.exp [new file with mode: 0644]
gdb/testsuite/gdb.base/inline-frame-cycle-unwind.py
gdb/testsuite/gdb.dap/scopes.exp
gdb/testsuite/lib/gdb.exp
gdb/x86-linux-nat.c
gdb/x86-linux-nat.h
gdb/x86-tdep.c
gdb/x86-tdep.h
gdbserver/linux-x86-low.cc
gdbsupport/x86-xstate.h