From: Changyul Lee <lcy8047@gmail.com>
To: Juergen Gross <jgross@suse.com>,
Stefano Stabellini <sstabellini@kernel.org>
Cc: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>,
xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org,
Changyul Lee <lcy8047@gmail.com>
Subject: [PATCH] xen/virtio: Fix use-after-free of grant DMA data after rebind
Date: Wed, 18 Nov 2026 20:11:49 -0500 [thread overview]
Message-ID: <20261119011149.534095-1-lcy8047@gmail.com> (raw)
When the device is unbound, devres frees its grant DMA data but leaves
the entry in xen_grant_dma_devices. On rebind, the remaining entry
causes xen_grant_setup_dma_ops() to skip setup. Since x86 retains
dev->dma_ops across unbind, subsequent DMA operations access the freed
data.
Register a devres action to erase the entry before freeing the data.
Fixes: 61367688f1fb ("xen/virtio: enable grant based virtio on x86")
Signed-off-by: Changyul Lee <lcy8047@gmail.com>
---
Found with a static analysis tool we are developing.
Tested in QEMU with KVM Xen HVM emulation (xen-version=0x4000a) and
CONFIG_XEN_VIRTIO_FORCE_GRANT=y, using a virtio-keyboard-pci device with
iommu_platform=on. Unbinding and rebinding virtio-pci through sysfs
triggers a KASAN slab-use-after-free in xen_grant_dma_alloc() before
this patch and no report after it.
drivers/xen/grant-dma-ops.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/xen/grant-dma-ops.c b/drivers/xen/grant-dma-ops.c
index 5fcafa4c344f..784413e6d282 100644
--- a/drivers/xen/grant-dma-ops.c
+++ b/drivers/xen/grant-dma-ops.c
@@ -66,6 +66,15 @@ static int store_xen_grant_dma_data(struct device *dev,
return ret;
}
+static void remove_xen_grant_dma_data(void *dev)
+{
+ unsigned long flags;
+
+ xa_lock_irqsave(&xen_grant_dma_devices, flags);
+ __xa_erase(&xen_grant_dma_devices, (unsigned long)dev);
+ xa_unlock_irqrestore(&xen_grant_dma_devices, flags);
+}
+
/*
* DMA ops for Xen frontends (e.g. virtio).
*
@@ -396,6 +405,9 @@ static void xen_grant_setup_dma_ops(struct device *dev, domid_t backend_domid)
goto err;
}
+ if (devm_add_action_or_reset(dev, remove_xen_grant_dma_data, dev))
+ goto err;
+
dev->dma_ops = &xen_grant_dma_ops;
return;
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
--
2.43.0
reply other threads:[~2026-11-19 1:11 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261119011149.534095-1-lcy8047@gmail.com \
--to=lcy8047@gmail.com \
--cc=jgross@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=oleksandr_tyshchenko@epam.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®