From: sashiko-bot@kernel.org
To: "Lizhi Hou" <lizhi.hou@amd.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH V1] accel/amdxdna: Require carveout when PASID and force_iova are disabled
Date: Thu, 04 Jun 2026 20:10:12 +0000 [thread overview]
Message-ID: <20260604201013.340341F0089A@smtp.kernel.org> (raw)
In-Reply-To: <20260604195459.2423279-1-lizhi.hou@amd.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Dangling pointer in `client->sva` leads to a Use-After-Free and double-free during DRM close if `iommu_sva_get_pasid()` fails.
--
commit a925d70753a15e6bc99a30d4fbc4ec99fe4b925e
Author: Lizhi Hou <lizhi.hou@amd.com>
accel/amdxdna: Require carveout when PASID and force_iova are disabled
When both PASID and force_iova are disabled, this patch ensures carveout
memory is configured, returning an error during DRM open if it is not.
> diff --git a/drivers/accel/amdxdna/amdxdna_pci_drv.c b/drivers/accel/amdxdna/amdxdna_pci_drv.c
> index c677293c1ae7f..1f066ed8d2365 100644
> --- a/drivers/accel/amdxdna/amdxdna_pci_drv.c
> +++ b/drivers/accel/amdxdna/amdxdna_pci_drv.c
> @@ -120,8 +120,14 @@ static int amdxdna_drm_open(struct drm_device *ddev, struct drm_file *filp)
>
> if (!amdxdna_iova_on(xdna)) {
> /* No need to fail open since user may use pa + carveout later. */
> - if (amdxdna_sva_init(client))
> + if (amdxdna_sva_init(client)) {
> XDNA_WARN(xdna, "PASID not available for pid %d", client->pid);
> + if (!amdxdna_use_carveout(xdna)) {
> + XDNA_ERR(xdna, "PASID unavailable and carveout not configured");
> + kfree(client);
> + return -EINVAL;
> + }
> + }
[Severity: High]
This is a pre-existing issue, but since this patch relies on the fallback
behavior when amdxdna_sva_init() fails, does this leave a dangling pointer in
client->sva?
Looking at amdxdna_sva_init(), if iommu_sva_bind_device() succeeds but
iommu_sva_get_pasid() fails, the sva handle is unbound but the pointer isn't
cleared:
amdxdna_sva_init() {
...
client->pasid = iommu_sva_get_pasid(client->sva);
if (client->pasid == IOMMU_PASID_INVALID) {
iommu_sva_unbind_device(client->sva);
XDNA_ERR(xdna, "SVA get pasid failed");
return -ENODEV;
}
...
}
If amdxdna_use_carveout() returns true, amdxdna_drm_open() continues
successfully, keeping the client object alive.
When the DRM file is later closed, amdxdna_sva_fini() is called:
amdxdna_sva_fini() {
if (IS_ERR_OR_NULL(client->sva))
return;
iommu_sva_unbind_device(client->sva);
}
Since client->sva still holds the old pointer instead of NULL or an error
pointer, the IS_ERR_OR_NULL check will pass, and iommu_sva_unbind_device()
will be called a second time. Can this cause a double-free or use-after-free
of the iommu_sva structure during cleanup?
> }
> mmgrab(client->mm);
> init_srcu_struct(&client->hwctx_srcu);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260604195459.2423279-1-lizhi.hou@amd.com?part=1
prev parent reply other threads:[~2026-06-04 20:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-04 19:54 [PATCH V1] accel/amdxdna: Require carveout when PASID and force_iova are disabled Lizhi Hou
2026-06-04 19:56 ` Mario Limonciello
2026-06-05 16:22 ` Lizhi Hou
2026-06-04 20:10 ` sashiko-bot [this message]
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=20260604201013.340341F0089A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=lizhi.hou@amd.com \
--cc=sashiko-reviews@lists.linux.dev \
/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 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.