All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xen: vm_event: do not do vm_event_op for an invalid domain
@ 2025-03-17 23:08 Volodymyr Babchuk
  2025-03-17 23:40 ` Andrew Cooper
  2025-03-17 23:51 ` Tamas K Lengyel
  0 siblings, 2 replies; 4+ messages in thread
From: Volodymyr Babchuk @ 2025-03-17 23:08 UTC (permalink / raw)
  To: xen-devel@lists.xenproject.org
  Cc: Stefano Stabellini, Roger Pau Monné, Volodymyr Babchuk,
	Tamas K Lengyel, Alexandru Isaila, Petre Pircalabu

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.

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/
---
 xen/common/vm_event.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/xen/common/vm_event.c b/xen/common/vm_event.c
index fbf1aa0848..a4c233de52 100644
--- a/xen/common/vm_event.c
+++ b/xen/common/vm_event.c
@@ -600,6 +600,13 @@ int vm_event_domctl(struct domain *d, struct xen_domctl_vm_event_op *vec)
         return 0;
     }
 
+    if ( unlikely(!d) )
+    {
+        gdprintk(XENLOG_INFO,
+                 "Tried to do a memory event op on invalid domain\n");
+        return -EINVAL;
+    }
+
     rc = xsm_vm_event_control(XSM_PRIV, d, vec->mode, vec->op);
     if ( rc )
         return rc;
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] xen: vm_event: do not do vm_event_op for an invalid domain
  2025-03-17 23:08 [PATCH] xen: vm_event: do not do vm_event_op for an invalid domain Volodymyr Babchuk
@ 2025-03-17 23:40 ` Andrew Cooper
  2025-03-17 23:51 ` Tamas K Lengyel
  1 sibling, 0 replies; 4+ messages in thread
From: Andrew Cooper @ 2025-03-17 23:40 UTC (permalink / raw)
  To: Volodymyr Babchuk, xen-devel@lists.xenproject.org
  Cc: Stefano Stabellini, Roger Pau Monné, Tamas K Lengyel,
	Alexandru Isaila, Petre Pircalabu

On 17/03/2025 11:08 pm, Volodymyr Babchuk wrote:
> 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.
>
> 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/
> ---
>  xen/common/vm_event.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/xen/common/vm_event.c b/xen/common/vm_event.c
> index fbf1aa0848..a4c233de52 100644
> --- a/xen/common/vm_event.c
> +++ b/xen/common/vm_event.c
> @@ -600,6 +600,13 @@ int vm_event_domctl(struct domain *d, struct xen_domctl_vm_event_op *vec)
>          return 0;
>      }
>  
> +    if ( unlikely(!d) )
> +    {
> +        gdprintk(XENLOG_INFO,
> +                 "Tried to do a memory event op on invalid domain\n");
> +        return -EINVAL;
> +    }
> +
>      rc = xsm_vm_event_control(XSM_PRIV, d, vec->mode, vec->op);
>      if ( rc )
>          return rc;

Oops.  Git blame says this is my fault.

This behaviour is intentional.  See XEN_DOMCTL_vm_event_op (along with
test_assign_device and get_domain_state) early in do_domctl().

It was introduced in commit d48e1836074c ("vm_event: Add a new opcode to
get VM_EVENT_INTERFACE_VERSION") so that XEN_VM_EVENT_GET_VERSION could
succeed.

Apparently I deleted it in commit 48b84249459f ("xen/vm-event: Drop
unused u_domctl parameter from vm_event_domctl()"), and that wasn't
intentional.

That will want putting in with an extra comment.

/* All other subops need to target a real domain. */
if ( unlikely(d == NULL) )
    return -ESRCH;

Don't both with a printk().  It's just noise, and -ESRCH is correct code
to use.

~Andrew


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] xen: vm_event: do not do vm_event_op for an invalid domain
  2025-03-17 23:08 [PATCH] xen: vm_event: do not do vm_event_op for an invalid domain Volodymyr Babchuk
  2025-03-17 23:40 ` Andrew Cooper
@ 2025-03-17 23:51 ` Tamas K Lengyel
  2025-03-18  0:01   ` Volodymyr Babchuk
  1 sibling, 1 reply; 4+ messages in thread
From: Tamas K Lengyel @ 2025-03-17 23:51 UTC (permalink / raw)
  To: Volodymyr Babchuk
  Cc: xen-devel@lists.xenproject.org, Stefano Stabellini,
	Roger Pau Monné, Alexandru Isaila, Petre Pircalabu

On Mon, Mar 17, 2025 at 7:08 PM Volodymyr Babchuk
<Volodymyr_Babchuk@epam.com> wrote:
>
> 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.
>
> 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/
> ---
>  xen/common/vm_event.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/xen/common/vm_event.c b/xen/common/vm_event.c
> index fbf1aa0848..a4c233de52 100644
> --- a/xen/common/vm_event.c
> +++ b/xen/common/vm_event.c
> @@ -600,6 +600,13 @@ int vm_event_domctl(struct domain *d, struct xen_domctl_vm_event_op *vec)
>          return 0;
>      }
>
> +    if ( unlikely(!d) )
> +    {
> +        gdprintk(XENLOG_INFO,
> +                 "Tried to do a memory event op on invalid domain\n");

This is not a memory event op?

Tamas


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] xen: vm_event: do not do vm_event_op for an invalid domain
  2025-03-17 23:51 ` Tamas K Lengyel
@ 2025-03-18  0:01   ` Volodymyr Babchuk
  0 siblings, 0 replies; 4+ messages in thread
From: Volodymyr Babchuk @ 2025-03-18  0:01 UTC (permalink / raw)
  To: Tamas K Lengyel
  Cc: xen-devel@lists.xenproject.org, Stefano Stabellini,
	Roger Pau Monné, Alexandru Isaila, Petre Pircalabu

Hi Tamas,


Tamas K Lengyel <tamas@tklengyel.com> writes:

> On Mon, Mar 17, 2025 at 7:08 PM Volodymyr Babchuk
> <Volodymyr_Babchuk@epam.com> wrote:
>>
>> 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.
>>
>> 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/
>> ---
>>  xen/common/vm_event.c | 7 +++++++
>>  1 file changed, 7 insertions(+)
>>
>> diff --git a/xen/common/vm_event.c b/xen/common/vm_event.c
>> index fbf1aa0848..a4c233de52 100644
>> --- a/xen/common/vm_event.c
>> +++ b/xen/common/vm_event.c
>> @@ -600,6 +600,13 @@ int vm_event_domctl(struct domain *d, struct xen_domctl_vm_event_op *vec)
>>          return 0;
>>      }
>>
>> +    if ( unlikely(!d) )
>> +    {
>> +        gdprintk(XENLOG_INFO,
>> +                 "Tried to do a memory event op on invalid domain\n");
>
> This is not a memory event op?

Oh, this is good catch. I absent mindedly copied an error message from a
couple of lines below. Looks like we need another patch that fixes error
messages.


--
WBR, Volodymyr

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-03-18  0:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-17 23:08 [PATCH] xen: vm_event: do not do vm_event_op for an invalid domain Volodymyr Babchuk
2025-03-17 23:40 ` Andrew Cooper
2025-03-17 23:51 ` Tamas K Lengyel
2025-03-18  0:01   ` Volodymyr Babchuk

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.