Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sasha Levin" <sashal@kernel.org>
Cc: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org
Subject: Re: [PATCH AUTOSEL 6.18] drm/xe: Fix null pointer dereference in devcoredump cleanup
Date: Mon, 31 Aug 2026 14:54:26 +0000	[thread overview]
Message-ID: <20260831145426.8B0EB1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260831133314.4125787-170-sashal@kernel.org>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Pre-existing issues:
- [Critical] Missing cancellation of deferred snapshot work during driver unload leads to a use-after-free.
- [High] Calling cancel_work_sync() from within the work item itself causes a self-deadlock on the dev_coredumpm_timeout() error path.
- [High] dev_coredumpm_timeout() synchronous error path clears the snapshot memory, causing a NULL pointer dereference in the worker thread.
--

commit 9607c0ac0490954ce494b7fd2f2026e574352b10
Author: Zhanjun Dong <zhanjun.dong@intel.com>
Subject: drm/xe: Fix null pointer dereference in devcoredump cleanup

In xe_devcoredump_snapshot_free(), ss->gt may be NULL when the snapshot
was never fully populated. Guard the xe_guc_capture_put_matched_nodes()
call with IS_ERR_OR_NULL() to prevent a null dereference.

Link: https://patch.msgid.link/20260326181017.2060209-1-zhanjun.dong@intel.com

> diff --git a/drivers/gpu/drm/xe/xe_devcoredump.c b/drivers/gpu/drm/xe/xe_devcoredump.c
> index 203e3038cc817..26a294f79e79f 100644
> --- a/drivers/gpu/drm/xe/xe_devcoredump.c
> +++ b/drivers/gpu/drm/xe/xe_devcoredump.c
[ ... ]
> @@ -255,7 +256,8 @@ static void xe_devcoredump_free(void *data)
>  	if (!data || !coredump_to_xe(coredump))
>  		return;
>  
> -	cancel_work_sync(&coredump->snapshot.work);
> +	if (coredump->captured)
> +		cancel_work_sync(&coredump->snapshot.work);

[Severity: High]
This is a pre-existing issue, but does calling cancel_work_sync() from within
the work item itself cause a self-deadlock?

In xe_devcoredump_deferred_snap_work(), which executes on the workqueue, there
is a call to dev_coredumpm_timeout(). If dev_coredumpm_timeout() fails (for
example, if devcoredump is disabled via sysfs or memory allocation fails), it
synchronously invokes the free callback, xe_devcoredump_free().

Because coredump->captured is true while this work is executing,
xe_devcoredump_free() calls cancel_work_sync() on the same work item. Since
this executes in the context of the work item itself, it blocks forever
waiting for the work to complete, deadlocking the system_unbound_wq worker.

[Severity: High]
This isn't a bug introduced by this patch, but can the synchronous error path
described above also result in a null pointer dereference within the worker
thread?

Assuming the deadlock in cancel_work_sync() is bypassed, xe_devcoredump_free()
will clear the snapshot memory:

	/* To prevent stale data on next snapshot, clear everything */
	memset(&coredump->snapshot, 0, sizeof(coredump->snapshot));

Once dev_coredumpm_timeout() returns control to
xe_devcoredump_deferred_snap_work(), the worker thread immediately attempts
to evaluate gt_to_fw(ss->gt). Since ss->gt was just zeroed out, this results
in an invalid pointer offset, which is then dereferenced by
xe_force_wake_get(), crashing the kernel.

[Severity: Critical]
This is another pre-existing issue in the devcoredump lifecycle, but is there
a risk of a use-after-free here due to missing cancellation of deferred
snapshot work during driver unload?

When the driver is unloaded or unbound, xe_driver_devcoredump_fini() executes:

static void xe_driver_devcoredump_fini(void *arg)
{
	struct drm_device *drm = arg;

	dev_coredump_put(drm->dev);
}

If a GPU hang recently queued xe_devcoredump_deferred_snap_work() on the
system workqueue, and the driver is unloaded before this work executes,
dev_coredumpm_timeout() hasn't been called yet. This means the devcd device
does not exist, so dev_coredump_put() does nothing.

The driver teardown completes and frees the xe_device memory. The workqueue
subsequently executes the pending work, dereferencing the freed coredump
structure.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260831133314.4125787-170-sashal@kernel.org?part=1

  reply	other threads:[~2026-08-31 14:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260831133314.4125787-1-sashal@kernel.org>
2026-08-31 13:23 ` [PATCH AUTOSEL 6.18] drm/xe: Fix null pointer dereference in devcoredump cleanup Sasha Levin
2026-08-31 14:54   ` sashiko-bot [this message]
2026-08-31 13:30 ` [PATCH AUTOSEL 6.18] drm/xe/guc: Add support for NO_RESPONSE_BUSY in CTB Sasha Levin

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=20260831145426.8B0EB1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=sashal@kernel.org \
    --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