dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Andi Shyti" <andi.shyti@linux.intel.com>
Cc: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2] drm/i915/gt: Fix request use-after-free in heartbeat()
Date: Sun, 30 Aug 2026 23:08:08 +0000	[thread overview]
Message-ID: <20260830230808.D88131F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260830225708.3959691-1-andi.shyti@linux.intel.com>

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

Pre-existing issues:
- [High] heartbeat() dereferences the local pointer `rq` without holding a strong reference, making it vulnerable to a Use-After-Free if intel_engine_park_heartbeat() concurrently clears the shared pointer.
--

commit aa7ae2412e3834bb064c9442f0f96ffd0058a8ae
Author: Shuangpeng Bai <shuangpeng.kernel@gmail.com>

drm/i915/gt: Fix request use-after-free in heartbeat()

This commit addresses a request use-after-free in heartbeat() by using cmpxchg 
to manage the detached systole reference and replacing direct struct accesses 
with a local pointer.

Link: https://patch.msgid.link/20260808184302.1509585-1-shuangpeng.kernel@gmail.com

> diff --git a/drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c b/drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c
> index 6424ecce8bcbe..fc6c53c93cf57 100644
> --- a/drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c
> +++ b/drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c
[ ... ]
> @@ -152,9 +160,11 @@ static void heartbeat(struct work_struct *wrk)
>  	if (rq) {
>  		if (i915_request_completed(rq))
>  			i915_request_put(rq);
> -		else
> -			engine->heartbeat.systole = rq;
> +		/* Keep a newer pulse that raced with the detached systole. */
> +		else if (cmpxchg(&engine->heartbeat.systole, NULL, rq))
> +			i915_request_put(rq);
>  	}
> +	rq = READ_ONCE(engine->heartbeat.systole);

[Severity: High]
This is a pre-existing issue, but does heartbeat() safely dereference rq
without holding a strong reference?

If userspace toggles sysfs heartbeat intervals, intel_engine_park_heartbeat()
can execute concurrently, clearing the shared pointer and dropping the
reference:

intel_engine_park_heartbeat() {
    ...
    rq = xchg(&engine->heartbeat.systole, NULL);
    if (rq)
        i915_request_put(rq);
    ...
}

Since rq is loaded locklessly here without a reference bump, could this
result in a Use-After-Free later in heartbeat() when accessing
rq->emitted_jiffies?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260830225708.3959691-1-andi.shyti@linux.intel.com?part=1

      reply	other threads:[~2026-08-30 23:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-30 22:57 [PATCH v2] drm/i915/gt: Fix request use-after-free in heartbeat() Andi Shyti
2026-08-30 23:08 ` 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=20260830230808.D88131F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=andi.shyti@linux.intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.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