From: sashiko-bot@kernel.org
To: "Srinivasan Shanmugam" <srinivasan.shanmugam@amd.com>
Cc: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v5 3/4] drm/xe: Convert xe_user_fence to drm_user_fence
Date: Mon, 31 Aug 2026 05:56:41 +0000 [thread overview]
Message-ID: <20260831055642.4B7EA1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260831054154.107602-4-srinivasan.shanmugam@amd.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Possible Use-After-Free of xe_device when a foreign dma-fence signals after device teardown.
--
commit 3bd2b743d1b606804ebc5081e49badce29c41a21
Author: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
drm/xe: Convert xe_user_fence to drm_user_fence
Replace the open-coded user fence implementation in xe_sync.c with the
new common drm_user_fence helper.
> diff --git a/drivers/gpu/drm/xe/xe_sync.c b/drivers/gpu/drm/xe/xe_sync.c
> index 37866768d64c2..2d1e07792506e 100644
> --- a/drivers/gpu/drm/xe/xe_sync.c
> +++ b/drivers/gpu/drm/xe/xe_sync.c
> @@ -19,36 +18,60 @@
[ ... ]
> +static void xe_ufence_worker(struct drm_user_fence *base, bool mm_ok)
> +{
> + struct xe_user_fence *ufence = container_of(base, struct xe_user_fence, base);
[ ... ]
> + if (mm_ok) {
> + if (copy_to_user(ufence->addr, &ufence->value, sizeof(ufence->value)))
> + drm_dbg(&ufence->xe->drm,
> + "copy_to_user failed, user fence wasn't signaled\n");
> + } else {
> + drm_dbg(&ufence->xe->drm,
> + "mmget_not_zero() failed, ufence wasn't signaled\n");
> + }
> +
> + wake_up_all(&ufence->xe->ufence_wq);
> +}
[ ... ]
> static struct xe_user_fence *user_fence_create(struct xe_device *xe, u64 addr,
> u64 value)
> {
> @@ -63,51 +86,22 @@ static struct xe_user_fence *user_fence_create(struct xe_device *xe, u64 addr,
> if (!ufence)
> return ERR_PTR(-ENOMEM);
>
> - ufence->xe = xe;
> - kref_init(&ufence->refcount);
> - ufence->addr = ptr;
> + ufence->xe = xe;
> + ufence->addr = ptr;
> ufence->value = value;
> - ufence->mm = current->mm;
> - mmgrab(ufence->mm);
> + drm_user_fence_init(&ufence->base, xe->ordered_wq, &xe_ufence_ops);
[Severity: High]
This is a pre-existing issue, but does this code leave the xe_device vulnerable
to a use-after-free when an external dma-fence signals after device teardown?
When a user creates a user fence that depends on an external dma-fence (e.g.,
from amdgpu) by passing a syncobj, xe_sync_entry_parse() creates the user fence
without taking a reference to the xe_device.
If the user then closes the xe file descriptor or the device is hot-unplugged,
the last reference to xe_device can be dropped. xe_sync_entry_cleanup()
drops the sync entry's reference to the user fence but does not cancel
the pending callback.
When the external dma-fence eventually signals, the callback invokes
queue_work(). Because the workqueue points to xe->ordered_wq which was already
destroyed during device teardown, this causes a UAF crash. If the worker
does run, it will also access the freed xe_device pointer in xe_ufence_worker()
to wake up waiters.
Could user_fence_create() take a reference to the xe_device, or could
xe_sync_entry_cleanup() be updated to explicitly cancel the pending callback?
>
> return ufence;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260827062142.4038272-1-srinivasan.shanmugam@amd.com?part=3
next prev parent reply other threads:[~2026-08-31 5:56 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-27 6:21 [PATCH 0/2] drm: Add Common drm_user_fence helper and Convert XE Srinivasan Shanmugam
2026-08-27 6:21 ` [PATCH 1/2] drm: Add common drm_user_fence helper Srinivasan Shanmugam
2026-08-27 6:32 ` sashiko-bot
2026-08-27 6:21 ` [PATCH 2/2] drm/xe: Convert xe_user_fence to drm_user_fence Srinivasan Shanmugam
2026-08-27 6:37 ` sashiko-bot
2026-08-27 6:28 ` ✗ CI.checkpatch: warning for drm: Add Common drm_user_fence helper and Convert XE Patchwork
2026-08-27 6:29 ` ✗ CI.KUnit: failure " Patchwork
2026-08-31 5:41 ` [PATCH v5 0/4] drm: Add common drm_work_fence/drm_user_fence helpers and convert XE Srinivasan Shanmugam
2026-08-31 10:16 ` Thomas Hellström
2026-08-31 11:13 ` SHANMUGAM, SRINIVASAN
2026-08-31 12:22 ` Thomas Hellström
2026-08-31 12:36 ` SHANMUGAM, SRINIVASAN
2026-08-31 12:40 ` Thomas Hellström
2026-08-31 5:41 ` [PATCH v5 1/4] drm: Add drm_work_fence helper Srinivasan Shanmugam
2026-08-31 5:41 ` [PATCH v5 2/4] drm: Add drm_user_fence helper Srinivasan Shanmugam
2026-08-31 5:41 ` [PATCH v5 3/4] drm/xe: Convert xe_user_fence to drm_user_fence Srinivasan Shanmugam
2026-08-31 5:56 ` sashiko-bot [this message]
2026-08-31 5:41 ` [PATCH v5 4/4] drm: Add per-signal compare functionality " Srinivasan Shanmugam
2026-08-31 5:51 ` sashiko-bot
2026-08-31 13:45 ` [PATCH v6 0/4] drm: Add common drm_work_fence/drm_user_fence helpers and convert XE Srinivasan Shanmugam
2026-08-31 13:45 ` [PATCH v6 1/4] drm: Add drm_work_fence helper Srinivasan Shanmugam
2026-08-31 20:21 ` Matthew Brost
2026-09-01 7:39 ` SHANMUGAM, SRINIVASAN
2026-09-01 10:04 ` Matthew Brost
2026-09-02 15:20 ` [PATCH v7 " Srinivasan Shanmugam
2026-09-02 15:20 ` [PATCH v7 2/4] drm: Add drm_user_fence helper Srinivasan Shanmugam
2026-09-08 4:54 ` Matthew Brost
2026-09-02 15:20 ` [PATCH v7 3/4] drm/xe: Convert xe_user_fence to drm_user_fence Srinivasan Shanmugam
2026-09-02 15:34 ` sashiko-bot
2026-09-08 5:11 ` Matthew Brost
2026-09-02 15:20 ` [PATCH v7 4/4] drm: Add per-signal compare functionality " Srinivasan Shanmugam
2026-09-02 15:29 ` sashiko-bot
2026-09-08 4:53 ` [PATCH v7 1/4] drm: Add drm_work_fence helper Matthew Brost
2026-08-31 13:45 ` [PATCH v6 2/4] drm: Add drm_user_fence helper Srinivasan Shanmugam
2026-08-31 20:36 ` Matthew Brost
2026-08-31 13:45 ` [PATCH v6 3/4] drm/xe: Convert xe_user_fence to drm_user_fence Srinivasan Shanmugam
2026-08-31 13:45 ` [PATCH v6 4/4] drm: Add per-signal compare functionality " Srinivasan Shanmugam
2026-08-31 14:25 ` sashiko-bot
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=20260831055642.4B7EA1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=srinivasan.shanmugam@amd.com \
/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.