[03/12] gdbserver: Add assert in x86_linux_read_description.

Message ID 20241220200501.324191-4-christina.schimpe@intel.com
State New
Headers
Series Add CET shadow stack support |

Commit Message

Schimpe, Christina Dec. 20, 2024, 8:04 p.m. UTC
  On x86 the PTRACE_GETREGSET request is currently only used for the xstate regset.
The size of the xstate regset is initialized to 0 such that it can be reset to
the appropriate size once we know it is supported for the current target
in x86_linux_read_description.

However, this configuration would not just affect the xstate regset but any regset
with PTRACE_GETREGSET request that is added in the future.  The new regset  would be
misconfigured with the xstate regset size.  To avoid this we add an assert for
unsupported regsets and check explicitly for the note type of the register set.
---
 gdbserver/linux-x86-low.cc | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
  

Comments

Thiago Jung Bauermann Feb. 6, 2025, 3 a.m. UTC | #1
"Schimpe, Christina" <christina.schimpe@intel.com> writes:

> On x86 the PTRACE_GETREGSET request is currently only used for the xstate regset.
> The size of the xstate regset is initialized to 0 such that it can be reset to
> the appropriate size once we know it is supported for the current target
> in x86_linux_read_description.
>
> However, this configuration would not just affect the xstate regset but any regset
> with PTRACE_GETREGSET request that is added in the future.  The new regset  would be
> misconfigured with the xstate regset size.  To avoid this we add an assert for
> unsupported regsets and check explicitly for the note type of the register set.
> ---
>  gdbserver/linux-x86-low.cc | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>

--
Thiago
  

Patch

diff --git a/gdbserver/linux-x86-low.cc b/gdbserver/linux-x86-low.cc
index 6c2688d3678..b023b34a0a4 100644
--- a/gdbserver/linux-x86-low.cc
+++ b/gdbserver/linux-x86-low.cc
@@ -894,7 +894,12 @@  x86_linux_read_description ()
 	   regset++)
 	{
 	  if (regset->get_request == PTRACE_GETREGSET)
-	    regset->size = xsave_len;
+	    {
+	      if (regset->nt_type == NT_X86_XSTATE)
+		regset->size = xsave_len;
+	      else
+		gdb_assert_not_reached ("invalid regset type.");
+	    }
 	  else if (regset->type != GENERAL_REGS)
 	    regset->size = 0;
 	}