Skip to contentSkip to conversation

x86: Fix XEN_DOMCTL_gdbsx_guestmemio crash

RFC PATCH Superseded Andrew Cooper 3 participants 4 messages Apr 20, 2022 – Apr 21, 2022

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 x86: Fix XEN_DOMCTL_gdbsx_guestmemio crash

When CONFIG_GDBSX is compiled out, iommu_do_domctl() falls over a NULL pointer. It isn't really correct for processing of XEN_DOMCTL_gdbsx_* to fall into the default case when compiled out.

---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Wei Liu <[email protected]>
CC: Julien Grall <[email protected]>
CC: Juergen Gross <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>

RFC, because this has implications across the codebase. The tl;dr is that case FOO:'s shouldn't be compiled out; we still know what the subops are, even when the functionality is compiled out.

There are several ways to express this. Alternatives would be:

    case XEN_DOMCTL_gdbsx_guestmemio:
        if ( !IS_ENABLED(CONFIG_GDBSX) )
        {
            rc = -EOPNOTSUPP;
            break;
        }
        ...;

but given my debugger series creating gdbsx.c, I was also considering:

    case XEN_DOMCTL_gdbsx_guestmemio:
    case XEN_DOMCTL_gdbsx_pausevcpu:
    case XEN_DOMCTL_gdbsx_unpausevcpu:
    case XEN_DOMCTL_gdbsx_domstatus:
        rc = gdbsx_do_domctl(d, iop);
        break;

when I can rework the callers of domain_pause_for_debugger() slightly, at which point we can conditionally compile the gdbsx variables out struct domain/vcpu, which wouldn't be compatible with the first suggestion.

Thoughts?

---
 xen/arch/x86/domctl.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
xen/arch/x86/domctl.c +8 -1
index a6aae500a30b..1faa5a49ff3c 100644
@@ -890,7 +890,14 @@ long arch_do_domctl(
         copyback = true;
         break;
     }
-#endif
+#else /* CONFIG_GDBSX */
+    case XEN_DOMCTL_gdbsx_guestmemio:
+    case XEN_DOMCTL_gdbsx_pausevcpu:
+    case XEN_DOMCTL_gdbsx_unpausevcpu:
+    case XEN_DOMCTL_gdbsx_domstatus:
+        rc = -EOPNOTSUPP;
+        break;
+#endif /* CONFIG_GDBSX */
 
     case XEN_DOMCTL_setvcpuextstate:
     case XEN_DOMCTL_getvcpuextstate:
Signature · 1 line
2.11.0
#1 lore raw
Quoted 30 lines · Andrew Cooper

When CONFIG_GDBSX is compiled out, iommu_do_domctl() falls over a NULL pointer. It isn't really correct for processing of XEN_DOMCTL_gdbsx_* to fall into the default case when compiled out.

---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Wei Liu <[email protected]>
CC: Julien Grall <[email protected]>
CC: Juergen Gross <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>

RFC, because this has implications across the codebase. The tl;dr is that case FOO:'s shouldn't be compiled out; we still know what the subops are, even when the functionality is compiled out.

There are several ways to express this. Alternatives would be:

     case XEN_DOMCTL_gdbsx_guestmemio:
         if ( !IS_ENABLED(CONFIG_GDBSX) )
         {
             rc = -EOPNOTSUPP;
             break;
         }
         ...;
Quoted 8 lines

but given my debugger series creating gdbsx.c, I was also considering:

     case XEN_DOMCTL_gdbsx_guestmemio:
     case XEN_DOMCTL_gdbsx_pausevcpu:
     case XEN_DOMCTL_gdbsx_unpausevcpu:
     case XEN_DOMCTL_gdbsx_domstatus:
         rc = gdbsx_do_domctl(d, iop);
         break;

I'd go this route.

Juergen

#2 lore raw
Quoted 33 lines · Juergen Gross
Quoted 32 lines · Andrew Cooper

When CONFIG_GDBSX is compiled out, iommu_do_domctl() falls over a NULL pointer. It isn't really correct for processing of XEN_DOMCTL_gdbsx_* to fall into the default case when compiled out.

---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Wei Liu <[email protected]>
CC: Julien Grall <[email protected]>
CC: Juergen Gross <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>

RFC, because this has implications across the codebase. The tl;dr is that case FOO:'s shouldn't be compiled out; we still know what the subops are, even when the functionality is compiled out.

There are several ways to express this. Alternatives would be:

     case XEN_DOMCTL_gdbsx_guestmemio:
         if ( !IS_ENABLED(CONFIG_GDBSX) )
         {
             rc = -EOPNOTSUPP;
             break;
         }
         ...;

but given my debugger series creating gdbsx.c, I was also considering:

Quoted 8 lines
Quoted 6 lines
     case XEN_DOMCTL_gdbsx_guestmemio:
     case XEN_DOMCTL_gdbsx_pausevcpu:
     case XEN_DOMCTL_gdbsx_unpausevcpu:
     case XEN_DOMCTL_gdbsx_domstatus:
         rc = gdbsx_do_domctl(d, iop);
         break;

I'd go this route.

+1 if we already start enumerating sub-system domctl-s (as proposed for the IOMMU ones as well).

Jan

#3 lore raw
Quoted 40 lines · Jan Beulich
Quoted 39 lines · Juergen Gross
Quoted 38 lines · Andrew Cooper

When CONFIG_GDBSX is compiled out, iommu_do_domctl() falls over a NULL pointer. It isn't really correct for processing of XEN_DOMCTL_gdbsx_* to fall into the default case when compiled out.

---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Wei Liu <[email protected]>
CC: Julien Grall <[email protected]>
CC: Juergen Gross <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>

RFC, because this has implications across the codebase. The tl;dr is that case FOO:'s shouldn't be compiled out; we still know what the subops are, even when the functionality is compiled out.

There are several ways to express this. Alternatives would be:

     case XEN_DOMCTL_gdbsx_guestmemio:
         if ( !IS_ENABLED(CONFIG_GDBSX) )
         {
             rc = -EOPNOTSUPP;
             break;
         }
         ...;

but given my debugger series creating gdbsx.c, I was also considering:

     case XEN_DOMCTL_gdbsx_guestmemio:
     case XEN_DOMCTL_gdbsx_pausevcpu:
     case XEN_DOMCTL_gdbsx_unpausevcpu:
     case XEN_DOMCTL_gdbsx_domstatus:
         rc = gdbsx_do_domctl(d, iop);
         break;
Quoted 3 lines
Quoted 1 line

I'd go this route.

+1 if we already start enumerating sub-system domctl-s (as proposed for the IOMMU ones as well).

Ok, so that seems like general agreement for "we shouldn't compile out case statements" which is something we should apply across the codebase going forward.

For gdbsx_do_domctl() specifically, that's going to want to wait until "[PATCH v5 0/6] Clean up common/arch split for debugger.h" has gone in, but I don't anticipate any issues there.

~Andrew