All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] drm/amdgpu/aca: Robustness and safety fixes for ACA driver
@ 2026-08-08 21:08 Sreeraj S Kurup
  2026-08-08 21:08 ` [PATCH 1/5] drm/amdgpu/aca: Fix race condition and UAF in error cache logging Sreeraj S Kurup
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Sreeraj S Kurup @ 2026-08-08 21:08 UTC (permalink / raw)
  To: alexander.deucher, christian.koenig
  Cc: amd-gfx, dri-devel, linux-kernel, airlied, simona,
	Sreeraj S Kurup

This patch series addresses several race conditions, boundary check bugs,
logic inversions, NULL pointer checks, and buffer size parameters across
the AMDGPU ACA (Accelerated Compute Architecture) driver subsystem:

Sreeraj S Kurup (5):
  drm/amdgpu/aca: Fix race condition and UAF in error cache logging
  drm/amdgpu/aca: Add upper bounds check in aca_bank_hwip_is_matched
  drm/amdgpu/aca: Fix inverted validation logic in
    amdgpu_aca_get_error_data
  drm/amdgpu/aca: Add missing NULL check for banks parameter in
    aca_banks_add_bank
  drm/amdgpu/aca: Fix off-by-one buffer size parameter in add_aca_sysfs

 drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c | 31 ++++++++++---------------
 1 file changed, 12 insertions(+), 19 deletions(-)

-- 
2.54.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/5] drm/amdgpu/aca: Fix race condition and UAF in error cache logging
  2026-08-08 21:08 [PATCH 0/5] drm/amdgpu/aca: Robustness and safety fixes for ACA driver Sreeraj S Kurup
@ 2026-08-08 21:08 ` Sreeraj S Kurup
  2026-08-08 21:08 ` [PATCH 2/5] drm/amdgpu/aca: Add upper bounds check in aca_bank_hwip_is_matched Sreeraj S Kurup
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Sreeraj S Kurup @ 2026-08-08 21:08 UTC (permalink / raw)
  To: alexander.deucher, christian.koenig
  Cc: amd-gfx, dri-devel, linux-kernel, airlied, simona,
	Sreeraj S Kurup

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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/5] drm/amdgpu/aca: Add upper bounds check in aca_bank_hwip_is_matched
  2026-08-08 21:08 [PATCH 0/5] drm/amdgpu/aca: Robustness and safety fixes for ACA driver Sreeraj S Kurup
  2026-08-08 21:08 ` [PATCH 1/5] drm/amdgpu/aca: Fix race condition and UAF in error cache logging Sreeraj S Kurup
@ 2026-08-08 21:08 ` Sreeraj S Kurup
  2026-08-08 21:08 ` [PATCH 3/5] drm/amdgpu/aca: Fix inverted validation logic in amdgpu_aca_get_error_data Sreeraj S Kurup
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Sreeraj S Kurup @ 2026-08-08 21:08 UTC (permalink / raw)
  To: alexander.deucher, christian.koenig
  Cc: amd-gfx, dri-devel, linux-kernel, airlied, simona,
	Sreeraj S Kurup

In aca_bank_hwip_is_matched(), the 'type' parameter is used directly
as an array index into aca_hwid_mcatypes[]. The function previously
checked whether 'type' was equal to ACA_HWIP_TYPE_UNKNOW, but did not
validate whether 'type' was less than ACA_HWIP_TYPE_COUNT or negative.

If an invalid or out-of-bounds enum value is passed, an out-of-bounds
memory read occurs on the aca_hwid_mcatypes array.

Fix this by validating that 'type' is strictly greater than
ACA_HWIP_TYPE_UNKNOW and less than ACA_HWIP_TYPE_COUNT before
performing the array lookup.

Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c
index d0d473082431..c76664af9902 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c
@@ -138,7 +138,7 @@ static bool aca_bank_hwip_is_matched(struct aca_bank *bank, enum aca_hwip_type t
 	int hwid, mcatype;
 	u64 ipid;
 
-	if (!bank || type == ACA_HWIP_TYPE_UNKNOW)
+	if (!bank || type <= ACA_HWIP_TYPE_UNKNOW || type >= ACA_HWIP_TYPE_COUNT)
 		return false;
 
 	hwip = &aca_hwid_mcatypes[type];
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/5] drm/amdgpu/aca: Fix inverted validation logic in amdgpu_aca_get_error_data
  2026-08-08 21:08 [PATCH 0/5] drm/amdgpu/aca: Robustness and safety fixes for ACA driver Sreeraj S Kurup
  2026-08-08 21:08 ` [PATCH 1/5] drm/amdgpu/aca: Fix race condition and UAF in error cache logging Sreeraj S Kurup
  2026-08-08 21:08 ` [PATCH 2/5] drm/amdgpu/aca: Add upper bounds check in aca_bank_hwip_is_matched Sreeraj S Kurup
@ 2026-08-08 21:08 ` Sreeraj S Kurup
  2026-08-08 21:29   ` sashiko-bot
  2026-08-08 21:08 ` [PATCH 4/5] drm/amdgpu/aca: Add missing NULL check for banks parameter in aca_banks_add_bank Sreeraj S Kurup
  2026-08-08 21:08 ` [PATCH 5/5] drm/amdgpu/aca: Fix off-by-one buffer size parameter in add_aca_sysfs Sreeraj S Kurup
  4 siblings, 1 reply; 7+ messages in thread
From: Sreeraj S Kurup @ 2026-08-08 21:08 UTC (permalink / raw)
  To: alexander.deucher, christian.koenig
  Cc: amd-gfx, dri-devel, linux-kernel, airlied, simona,
	Sreeraj S Kurup

aca_handle_is_valid() returned false if !list_empty(&handle->node)
evaluated to true. Because active registered handles have non-empty
nodes in the handle list, valid handles evaluated as invalid.
Consequently, amdgpu_aca_get_error_data() returned -EOPNOTSUPP
whenever aca_handle_is_valid() evaluated to true.

Fix the logic in aca_handle_is_valid() to verify that the handle is
non-NULL, contains a valid mask, and is currently registered in the
list. Negate the check in amdgpu_aca_get_error_data() so valid
handles are processed properly.

Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c
index c76664af9902..1cddacb7c554 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c
@@ -586,10 +586,7 @@ static int __aca_get_error_data(struct amdgpu_device *adev, struct aca_handle *h
 
 static bool aca_handle_is_valid(struct aca_handle *handle)
 {
-	if (!handle->mask || !list_empty(&handle->node))
-		return false;
-
-	return true;
+	return handle && handle->mask && !list_empty(&handle->node);
 }
 
 int amdgpu_aca_get_error_data(struct amdgpu_device *adev, struct aca_handle *handle,
@@ -599,7 +596,7 @@ int amdgpu_aca_get_error_data(struct amdgpu_device *adev, struct aca_handle *han
 	if (!handle || !err_data)
 		return -EINVAL;
 
-	if (aca_handle_is_valid(handle))
+	if (!aca_handle_is_valid(handle))
 		return -EOPNOTSUPP;
 
 	if ((type < 0) || (!(BIT(type) & handle->mask)))
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/5] drm/amdgpu/aca: Add missing NULL check for banks parameter in aca_banks_add_bank
  2026-08-08 21:08 [PATCH 0/5] drm/amdgpu/aca: Robustness and safety fixes for ACA driver Sreeraj S Kurup
                   ` (2 preceding siblings ...)
  2026-08-08 21:08 ` [PATCH 3/5] drm/amdgpu/aca: Fix inverted validation logic in amdgpu_aca_get_error_data Sreeraj S Kurup
@ 2026-08-08 21:08 ` Sreeraj S Kurup
  2026-08-08 21:08 ` [PATCH 5/5] drm/amdgpu/aca: Fix off-by-one buffer size parameter in add_aca_sysfs Sreeraj S Kurup
  4 siblings, 0 replies; 7+ messages in thread
From: Sreeraj S Kurup @ 2026-08-08 21:08 UTC (permalink / raw)
  To: alexander.deucher, christian.koenig
  Cc: amd-gfx, dri-devel, linux-kernel, airlied, simona,
	Sreeraj S Kurup

aca_banks_add_bank() verified that the 'bank' parameter was non-NULL,
but passed 'banks' directly into list_add_tail(&node->node, &banks->list)
and incremented 'banks->nr_banks' without validating whether 'banks' was
NULL.

Add a NULL check for 'banks' to prevent a kernel NULL pointer
dereference if an invalid pointer is passed by a caller.

Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c
index 1cddacb7c554..47f3bcd5de0b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c
@@ -49,7 +49,7 @@ static int aca_banks_add_bank(struct aca_banks *banks, struct aca_bank *bank)
 {
 	struct aca_bank_node *node;
 
-	if (!bank)
+	if (!banks || !bank)
 		return -EINVAL;
 
 	node = kvzalloc_obj(*node);
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 5/5] drm/amdgpu/aca: Fix off-by-one buffer size parameter in add_aca_sysfs
  2026-08-08 21:08 [PATCH 0/5] drm/amdgpu/aca: Robustness and safety fixes for ACA driver Sreeraj S Kurup
                   ` (3 preceding siblings ...)
  2026-08-08 21:08 ` [PATCH 4/5] drm/amdgpu/aca: Add missing NULL check for banks parameter in aca_banks_add_bank Sreeraj S Kurup
@ 2026-08-08 21:08 ` Sreeraj S Kurup
  4 siblings, 0 replies; 7+ messages in thread
From: Sreeraj S Kurup @ 2026-08-08 21:08 UTC (permalink / raw)
  To: alexander.deucher, christian.koenig
  Cc: amd-gfx, dri-devel, linux-kernel, airlied, simona,
	Sreeraj S Kurup

snprintf() guarantees NUL-termination within the size limit specified by
its second argument. Passing 'sizeof(handle->attr_name) - 1'
unnecessarily reduces the usable buffer capacity by one byte, causing
sysfs attribute names to be truncated early.

Pass 'sizeof(handle->attr_name)' directly to snprintf() in add_aca_sysfs()
to allow full use of the allocated buffer space.

Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c
index 47f3bcd5de0b..99c315283f06 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c
@@ -682,7 +682,7 @@ static int add_aca_sysfs(struct amdgpu_device *adev, struct aca_handle *handle)
 {
 	struct device_attribute *aca_attr = &handle->aca_attr;
 
-	snprintf(handle->attr_name, sizeof(handle->attr_name) - 1, "aca_%s", handle->name);
+	snprintf(handle->attr_name, sizeof(handle->attr_name), "aca_%s", handle->name);
 	aca_attr->show = aca_sysfs_read;
 	aca_attr->attr.name = handle->attr_name;
 	aca_attr->attr.mode = S_IRUGO;
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/5] drm/amdgpu/aca: Fix inverted validation logic in amdgpu_aca_get_error_data
  2026-08-08 21:08 ` [PATCH 3/5] drm/amdgpu/aca: Fix inverted validation logic in amdgpu_aca_get_error_data Sreeraj S Kurup
@ 2026-08-08 21:29   ` sashiko-bot
  0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-08-08 21:29 UTC (permalink / raw)
  To: Sreeraj S Kurup; +Cc: dri-devel

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] `aca_handle_is_valid()` incorrectly evaluates removed handles as valid, leading to a Use-After-Free and `mutex_lock` on a destroyed mutex during device teardown.
--

--- Patch [3]: [PATCH 3/5] drm/amdgpu/aca: Fix inverted validation logic in amdgpu_aca_get_error_data ---
commit c1268f69334da0d7e73d9ad9988d74c06033118e
Author: Sreeraj S Kurup <sreekuttan2156239@gmail.com>

drm/amdgpu/aca: Fix inverted validation logic in amdgpu_aca_get_error_data

This commit updates aca_handle_is_valid() to verify handles have non-empty
list nodes, and negates the check in amdgpu_aca_get_error_data() to process
valid handles properly.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c
> index c76664af9902e..1cddacb7c554c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c
> @@ -586,10 +586,7 @@ static int __aca_get_error_data(struct amdgpu_device *adev, struct aca_handle *h
>  
>  static bool aca_handle_is_valid(struct aca_handle *handle)
>  {
> -	if (!handle->mask || !list_empty(&handle->node))
> -		return false;
> -
> -	return true;
> +	return handle && handle->mask && !list_empty(&handle->node);

[Severity: High]
Does this change cause removed handles to be evaluated as valid?

When amdgpu_aca_fini() removes handles, it uses list_del() rather than
list_del_init():

drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c:remove_aca_handle() {
    ...
    list_del(&handle->node);
    ...
}

Because list_del() poisons the list node, list_empty(&handle->node) will
evaluate to false. With this patch, !list_empty(&handle->node) now evaluates
to true, causing aca_handle_is_valid() to return true for a removed handle.
The original code correctly returned false for poisoned nodes.

During device teardown or module unload, if the delayed work
amdgpu_ras_counte_dw() executes concurrently, it calls
amdgpu_aca_get_error_data(). Since the removed handle is now incorrectly
deemed valid, the code would proceed into __aca_get_error_data() and attempt
to call mutex_lock(&aerr->lock) on an already destroyed mutex, potentially
causing a use-after-free or kernel panic.

Should remove_aca_handle() use list_del_init() so that list_empty() can
safely identify removed handles?

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-08-08 21:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-08 21:08 [PATCH 0/5] drm/amdgpu/aca: Robustness and safety fixes for ACA driver Sreeraj S Kurup
2026-08-08 21:08 ` [PATCH 1/5] drm/amdgpu/aca: Fix race condition and UAF in error cache logging Sreeraj S Kurup
2026-08-08 21:08 ` [PATCH 2/5] drm/amdgpu/aca: Add upper bounds check in aca_bank_hwip_is_matched Sreeraj S Kurup
2026-08-08 21:08 ` [PATCH 3/5] drm/amdgpu/aca: Fix inverted validation logic in amdgpu_aca_get_error_data Sreeraj S Kurup
2026-08-08 21:29   ` sashiko-bot
2026-08-08 21:08 ` [PATCH 4/5] drm/amdgpu/aca: Add missing NULL check for banks parameter in aca_banks_add_bank Sreeraj S Kurup
2026-08-08 21:08 ` [PATCH 5/5] drm/amdgpu/aca: Fix off-by-one buffer size parameter in add_aca_sysfs Sreeraj S Kurup

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.