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 <[email protected]>

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/[email protected]

> 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/[email protected]?part=1

Reply via email to