diff mbox series

[v2] xen: vm_event: do not do vm_event_op for an invalid domain

Message ID 20250318003943.1191439-1-volodymyr_babchuk@epam.com (mailing list archive)
State New
Headers show
Series [v2] xen: vm_event: do not do vm_event_op for an invalid domain | expand

Commit Message

Volodymyr Babchuk March 18, 2025, 12:39 a.m. UTC
A privileged domain can issue XEN_DOMCTL_vm_event_op with
op->domain == DOMID_INVALID. In this case vm_event_domctl()
function will get NULL as the first parameter and this will
cause hypervisor panic, as it tries to derefer this pointer.

Fix the issue by checking if valid domain is passed in.

Fixes: 48b84249459f ("xen/vm-event: Drop unused u_domctl parameter from vm_event_domctl()")
Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>

---

This issue was found by the xen fuzzer ([1])

[1] https://lore.kernel.org/all/20250315003544.1101488-1-volodymyr_babchuk@epam.com/

In v2:
 - Added Fixes: tag
Addressed Andrew's comment:
 - Don't printk anything
 - Return -ESRCH instead of -EINVAL
 - Add comment that describes why do we need this check
---
 xen/common/vm_event.c | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff --git a/xen/common/vm_event.c b/xen/common/vm_event.c
index fbf1aa0848..1666ff615f 100644
--- a/xen/common/vm_event.c
+++ b/xen/common/vm_event.c
@@ -600,6 +600,10 @@  int vm_event_domctl(struct domain *d, struct xen_domctl_vm_event_op *vec)
         return 0;
     }
 
+    /* All other subops need to target a real domain. */
+    if ( unlikely(d == NULL) )
+        return -ESRCH;
+
     rc = xsm_vm_event_control(XSM_PRIV, d, vec->mode, vec->op);
     if ( rc )
         return rc;