From: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
To: alexander.deucher@amd.com, christian.koenig@amd.com
Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org, airlied@gmail.com, simona@ffwll.ch,
Sreeraj S Kurup <sreekuttan2156239@gmail.com>
Subject: [PATCH v4 1/6] drm/amdgpu/aca: Fix race condition and UAF in error cache logging
Date: Sun, 9 Aug 2026 08:47:30 +0000 [thread overview]
Message-ID: <20260809084735.9743-2-sreekuttan2156239@gmail.com> (raw)
In-Reply-To: <20260809084735.9743-1-sreekuttan2156239@gmail.com>
In aca_error_cache_log_bank_error(), find_bank_error() released
aerr->lock prior to returning bank_error. This created a time-of-check
to time-of-use (TOCTOU) race window where a concurrent caller of
aca_log_aca_error() could acquire aerr->lock and free the bank_error
node via aca_bank_error_remove().
When execution returned to aca_error_cache_log_bank_error(),
incrementing bank_error->count resulted in a Use-After-Free and
potential kernel memory corruption. Additionally, bank_error->count
was updated outside mutex lock protection.
Fix this by acquiring aerr->lock at the start of
aca_error_cache_log_bank_error() and holding it continuously across
lookup, creation, and counter updates, while removing redundant
internal lock acquisitions in helper functions.
Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c
index db7858fe0c3d..d0d473082431 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c
@@ -237,10 +237,8 @@ static struct aca_bank_error *new_bank_error(struct aca_error *aerr, struct aca_
INIT_LIST_HEAD(&bank_error->node);
memcpy(&bank_error->info, info, sizeof(*info));
- mutex_lock(&aerr->lock);
list_add_tail(&bank_error->node, &aerr->list);
aerr->nr_errors++;
- mutex_unlock(&aerr->lock);
return bank_error;
}
@@ -249,22 +247,16 @@ static struct aca_bank_error *find_bank_error(struct aca_error *aerr, struct aca
{
struct aca_bank_error *bank_error = NULL;
struct aca_bank_info *tmp_info;
- bool found = false;
- mutex_lock(&aerr->lock);
list_for_each_entry(bank_error, &aerr->list, node) {
tmp_info = &bank_error->info;
if (tmp_info->socket_id == info->socket_id &&
tmp_info->die_id == info->die_id) {
- found = true;
- goto out_unlock;
+ return bank_error;
}
}
-out_unlock:
- mutex_unlock(&aerr->lock);
-
- return found ? bank_error : NULL;
+ return NULL;
}
static void aca_bank_error_remove(struct aca_error *aerr, struct aca_bank_error *bank_error)
@@ -306,11 +298,15 @@ int aca_error_cache_log_bank_error(struct aca_handle *handle, struct aca_bank_in
return 0;
aerr = &error_cache->errors[type];
+ mutex_lock(&aerr->lock);
bank_error = get_bank_error(aerr, info);
- if (!bank_error)
+ if (!bank_error) {
+ mutex_unlock(&aerr->lock);
return -ENOMEM;
+ }
bank_error->count += count;
+ mutex_unlock(&aerr->lock);
return 0;
}
--
2.54.0
next prev parent reply other threads:[~2026-08-09 8:49 UTC|newest]
Thread overview: 7+ 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 ` Sreeraj S Kurup [this message]
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 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 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 8:47 ` [PATCH v4 6/6] drm/amdgpu/ras: Fix delayed work cancellation order during teardown Sreeraj S Kurup
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=20260809084735.9743-2-sreekuttan2156239@gmail.com \
--to=sreekuttan2156239@gmail.com \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=simona@ffwll.ch \
/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
all inboxes | Powered by JetHome®