All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sreeraj S Kurup" <sreekuttan2156239@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v4 6/6] drm/amdgpu/ras: Fix delayed work cancellation order during teardown
Date: Sun, 09 Aug 2026 09:23:51 +0000	[thread overview]
Message-ID: <20260809092352.388231F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260809084735.9743-7-sreekuttan2156239@gmail.com>

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

Pre-existing issues:
- [Critical] Widened race condition allowing delayed work to be re-queued, leading to a Use-After-Free.
--

--- Patch [6]: [PATCH v4 6/6] drm/amdgpu/ras: Fix delayed work cancellation order during teardown ---
commit 0a6b2c827639f23d781a308f6731a9c602763c4a
Author: Sreeraj S Kurup <sreekuttan2156239@gmail.com>

drm/amdgpu/ras: Fix delayed work cancellation order during teardown

This commit reorders the cancellation of delayed work in amdgpu_ras_fini()
and amdgpu_ras_recovery_fini(). It moves cancel_delayed_work_sync() and
cancel_work_sync() before mutex destruction and subsystem teardown to
prevent work handlers from attempting to acquire destroyed locks.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
> index 764cd49504083..23b9844d9f1ca 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
[ ... ]
> @@ -4751,6 +4750,8 @@ int amdgpu_ras_fini(struct amdgpu_device *adev)
>  	if (!adev->ras_enabled || !con)
>  		return 0;
>  
> +	cancel_delayed_work_sync(&con->ras_counte_delay_work);
> +

[Severity: Critical]
This isn't a bug introduced by this patch, but by moving this
cancel_delayed_work_sync() earlier in amdgpu_ras_fini(), does this widen a race
condition that could lead to a Use-After-Free?

If a userspace process calls the AMDGPU_CTX_OP_QUERY_STATE2 ioctl concurrently
with device teardown, amdgpu_ctx_query2() can asynchronously re-queue the work:

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c:amdgpu_ctx_query2() {
    ...
    schedule_delayed_work(&con->ras_counte_delay_work,
                          msecs_to_jiffies(AMDGPU_RAS_COUNTE_DELAY_MS));
    ...
}

Because the ioctl lacks drm_dev_enter() synchronization, it can re-arm the work
after this cancellation but before the end of amdgpu_ras_fini().

When kfree(con) is called later in amdgpu_ras_fini(), will the re-armed
ras_counte_delay_work access the freed con structure?

>  	amdgpu_ras_critical_region_fini(adev);
>  	mutex_destroy(&con->critical_region_lock);
>  
[ ... ]
> @@ -4785,8 +4786,6 @@ int amdgpu_ras_fini(struct amdgpu_device *adev)
>  	if (AMDGPU_RAS_GET_FEATURES(con->features))
>  		amdgpu_ras_disable_all_features(adev, 0);
>  
> -	cancel_delayed_work_sync(&con->ras_counte_delay_work);
> -
>  	amdgpu_ras_set_context(adev, NULL);
>  	kfree(con);
>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260809084735.9743-1-sreekuttan2156239@gmail.com?part=6

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

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-09  8:47 [PATCH v4 0/6] drm/amdgpu: Robustness and safety fixes for ACA and RAS drivers Sreeraj S Kurup
2026-08-09  8:47 ` [PATCH v4 1/6] drm/amdgpu/aca: Fix race condition and UAF in error cache logging Sreeraj S Kurup
2026-08-09  8:47 ` [PATCH v4 2/6] drm/amdgpu/aca: Add upper bounds check in aca_bank_hwip_is_matched Sreeraj S Kurup
2026-08-09  8:47 ` [PATCH v4 3/6] drm/amdgpu/aca: Fix inverted validation logic and list cleanup Sreeraj S Kurup
2026-08-09  9:11   ` sashiko-bot
2026-08-09  8:47 ` [PATCH v4 4/6] drm/amdgpu/aca: Add missing NULL check for banks parameter in aca_banks_add_bank Sreeraj S Kurup
2026-08-09  9:19   ` sashiko-bot
2026-08-09  8:47 ` [PATCH v4 5/6] drm/amdgpu/aca: Fix off-by-one buffer size parameter in add_aca_sysfs Sreeraj S Kurup
2026-08-09  9:13   ` sashiko-bot
2026-08-09  8:47 ` [PATCH v4 6/6] drm/amdgpu/ras: Fix delayed work cancellation order during teardown Sreeraj S Kurup
2026-08-09  9:23   ` 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=20260809092352.388231F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sreekuttan2156239@gmail.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.