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 4/6] drm/amdgpu/aca: Add missing NULL check for banks parameter in aca_banks_add_bank
Date: Sun, 09 Aug 2026 09:19:47 +0000	[thread overview]
Message-ID: <20260809091948.4F2971F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260809084735.9743-5-sreekuttan2156239@gmail.com>

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

New issues:
- [Low] The added NULL check for the `banks` parameter is dead code and introduces unnecessary branching because the parameter is structurally guaranteed to never be NULL.
- [Low] The `lock` member referenced in `remove_aca_handle()` does not exist in `struct aca_handle_manager`, resulting in a compilation failure.

Pre-existing issues:
- [High] Concurrent traversal and modification of `mgr->list` without holding `mgr->lock` on the reader side causes a severe data race.
--

--- Patch [4]: [PATCH v4 4/6] drm/amdgpu/aca: Add missing NULL check for banks parameter in aca_banks_add_bank ---
commit 613bad660f79f7955828e89d88180e64def84678
Author: Sreeraj S Kurup <sreekuttan2156239@gmail.com>

drm/amdgpu/aca: Add missing NULL check for banks parameter in aca_banks_add_bank
    
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.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c
> index c35f6be2ef774..dcddeb3816285 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)

[Severity: Low]
Is this NULL check for banks necessary?

The parameter banks in aca_banks_add_bank() is always the address of a local
stack variable (&banks or &de_banks) in all of its calling paths (e.g., from
aca_banks_update() and aca_banks_generate_cper()), which means it can never
be NULL. Does this introduce unnecessary dead code and branching?

>  		return -EINVAL;
>  
>  	node = kvzalloc_obj(*node);

[ ... ]


There are also a couple of other issues in this area related to the aca
handle list:

[Severity: Low]
Can this code compile successfully?

The lock member referenced in remove_aca_handle() does not exist in
struct aca_handle_manager:

drivers/gpu/drm/amd/amdgpu/amdgpu_aca.h:
struct aca_handle_manager {
	struct list_head list;
	int nr_handles;
};

Attempting to reference mgr->lock here:

drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c:remove_aca_handle() {
    ...
	mutex_lock(&mgr->lock);
	list_del_init(&handle->node);
	mgr->nr_handles--;
	mutex_unlock(&mgr->lock);
    ...
}

appears to result in a compilation failure since lock is not defined in the
struct.


[Severity: High]
This isn't a bug introduced by this patch, but there is an explicit attempt
to fix it here. Could this concurrent traversal cause a data race?

While the writer side in remove_aca_handle() attempts to use mgr->lock:

drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c:remove_aca_handle() {
    ...
	mutex_lock(&mgr->lock);
	list_del_init(&handle->node);
	mgr->nr_handles--;
	mutex_unlock(&mgr->lock);
    ...
}

The reader side traverses mgr->list without holding any lock or using RCU
primitives:

drivers/gpu/drm/amd/amdgpu/amdgpu_aca.c:aca_dispatch_bank() {
    ...
	if (list_empty(&mgr->list))
		return 0;

	list_for_each_entry(handle, &mgr->list, node) {
		if (!aca_bank_is_valid(handle, bank, type))
			continue;
    ...
}

If a background RAS query or sysfs read (which calls aca_dispatch_bank())
traverses mgr->list while remove_aca_handle() concurrently unlinks and frees
a node during teardown, could this lead to a use-after-free or list
corruption and a kernel panic? The fix appears incomplete because it only
syntactically locks the writer side without adding synchronization to the
reader side.

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

  reply	other threads:[~2026-08-09  9:19 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 [this message]
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

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=20260809091948.4F2971F00A3A@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.