From: sashiko-bot@kernel.org
To: "Lizhi Hou" <lizhi.hou@amd.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH V2] accel/amdxdna: Fix VMA access race
Date: Mon, 08 Jun 2026 20:35:25 +0000 [thread overview]
Message-ID: <20260608203525.956141F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260608202828.2771524-1-lizhi.hou@amd.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] Using `list_last_entry()` for error-path cleanup in `amdxdna_hmm_unregister()` introduces severe race conditions and out-of-bounds memory accesses.
--
commit c58a67e26be2ca21d6b5952f0fd92febb2fa73f8
Author: Lizhi Hou <lizhi.hou@amd.com>
accel/amdxdna: Fix VMA access race
This commit removes VMA accesses from aie2_populate_range() and
amdxdna_umap_release() to fix a potential use-after-free where a saved VMA
pointer may have already been freed. It also updates amdxdna_hmm_unregister()
to unregister mappings based on a boolean flag instead of a VMA pointer.
> diff --git a/drivers/accel/amdxdna/amdxdna_gem.c b/drivers/accel/amdxdna/amdxdna_gem.c
> --- a/drivers/accel/amdxdna/amdxdna_gem.c
> +++ b/drivers/accel/amdxdna/amdxdna_gem.c
[ ... ]
> @@ -284,21 +284,26 @@ static const struct mmu_interval_notifier_ops amdxdna_hmm_ops = {
> .invalidate = amdxdna_hmm_invalidate,
> };
>
> -static void amdxdna_hmm_unregister(struct amdxdna_gem_obj *abo,
> - struct vm_area_struct *vma)
> +static void amdxdna_hmm_unregister(struct amdxdna_gem_obj *abo, bool unreg_all)
> {
> struct amdxdna_dev *xdna = to_xdna_dev(to_gobj(abo)->dev);
> struct amdxdna_umap *mapp;
>
> + if (!unreg_all) {
> + down_read(&xdna->notifier_lock);
> + mapp = list_last_entry(&abo->mem.umap_list, struct amdxdna_umap, node);
[Severity: Critical]
Can this cause an out-of-bounds access if the list is empty?
Looking at amdxdna_hmm_register(), it can return 0 without adding an entry
to umap_list:
amdxdna_hmm_register() {
if (!amdxdna_pasid_on(abo->client)) {
abo->mem.uva = addr;
return 0;
}
...
}
If amdxdna_insert_pages() subsequently fails in amdxdna_gem_obj_mmap(), the
error path calls amdxdna_hmm_unregister(abo, false). Since the list is empty,
would list_last_entry() evaluate to an invalid pointer offset, leading to
memory corruption when setting mapp->unmapped = true below?
Additionally, is there a race condition here with concurrent mappings?
If multiple processes mmap the same GEM object concurrently, and one
thread's amdxdna_insert_pages() fails, could it incorrectly retrieve and
unregister the other thread's mapping from the end of the list?
> + queue_work(xdna->notifier_wq, &mapp->hmm_unreg_work);
> + mapp->unmapped = true;
> + up_read(&xdna->notifier_lock);
> +
> + return;
> + }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260608202828.2771524-1-lizhi.hou@amd.com?part=1
prev parent reply other threads:[~2026-06-08 20:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-08 20:28 [PATCH V2] accel/amdxdna: Fix VMA access race Lizhi Hou
2026-06-08 20:35 ` 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=20260608203525.956141F00893@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).