From: sashiko-bot@kernel.org
To: "Chandrakanth Patil" <chandrakanth.patil@broadcom.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH 16/17] mpi3mr: Fix use-after-free of the firmware event workqueue
Date: Tue, 18 Aug 2026 18:23:35 +0000 [thread overview]
Message-ID: <20260818182335.C3EBE1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260818231426.58105-17-chandrakanth.patil@broadcom.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Use-After-Free of firmware event (`fwevt`) in `mpi3mr_cleanup_fwevt_list` during driver teardown.
--
--- Patch [16]: [PATCH 16/17] mpi3mr: Fix use-after-free of the firmware event workqueue ---
commit d1068d82a1a0b06d1a9647481bac5d43ff5f1ebc
Author: Chandrakanth Patil <chandrakanth.patil@broadcom.com>
mpi3mr: Fix use-after-free of the firmware event workqueue
This commit fixes a use-after-free issue regarding the firmware event
workqueue in the mpi3mr driver. It ensures the worker thread pointer is
checked while holding the event lock to prevent a race condition with the
workqueue being destroyed.
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c
> index 510c990d42d1b..4a72b3d89c294 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_os.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c
> @@ -233,10 +233,11 @@ static void mpi3mr_fwevt_add_to_list(struct mpi3mr_ioc *mrioc,
> {
> unsigned long flags;
>
> - if (!mrioc->fwevt_worker_thread)
> - return;
> -
> spin_lock_irqsave(&mrioc->fwevt_lock, flags);
> + if (!mrioc->fwevt_worker_thread) {
> + spin_unlock_irqrestore(&mrioc->fwevt_lock, flags);
> + return;
> + }
> /* get fwevt reference count while adding it to fwevt_list */
> mpi3mr_fwevt_get(fwevt);
> INIT_LIST_HEAD(&fwevt->list);
[Severity: High]
This is a pre-existing issue, but while reviewing the firmware event
lifecycle, I noticed another potential use-after-free during driver teardown.
In mpi3mr_dequeue_fwevt(), the list reference is dropped before returning
the pointer:
drivers/scsi/mpi3mr/mpi3mr_os.c:mpi3mr_dequeue_fwevt() {
...
fwevt = list_first_entry(&mrioc->fwevt_list,
struct mpi3mr_fwevt, list);
list_del_init(&fwevt->list);
/*
* Put fwevt reference count after
* removing it from fwevt_list
*/
mpi3mr_fwevt_put(fwevt);
}
spin_unlock_irqrestore(&mrioc->fwevt_lock, flags);
return fwevt;
}
Then in mpi3mr_cleanup_fwevt_list(), we pass this unreferenced pointer to
cancel_work_sync():
drivers/scsi/mpi3mr/mpi3mr_os.c:mpi3mr_cleanup_fwevt_list() {
...
while ((fwevt = mpi3mr_dequeue_fwevt(mrioc)))
mpi3mr_cancel_work(fwevt);
...
}
Could the background worker thread (mpi3mr_fwevt_worker) concurrently finish
executing and free the fwevt structure, causing cancel_work_sync() inside
mpi3mr_cancel_work() to access freed memory?
Additionally, lockless access to mrioc->current_event in
mpi3mr_cleanup_fwevt_list() could similarly read a concurrently freed event if
the worker thread finishes in the middle of cleanup:
drivers/scsi/mpi3mr/mpi3mr_os.c:mpi3mr_cleanup_fwevt_list() {
...
if (mrioc->current_event) {
fwevt = mrioc->current_event;
...
mpi3mr_cancel_work(fwevt);
}
}
Does this code need to hold a reference to fwevt while calling
mpi3mr_cancel_work() to prevent the worker thread from freeing it?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260818231426.58105-1-chandrakanth.patil@broadcom.com?part=16
next prev parent reply other threads:[~2026-08-18 18:23 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-18 23:14 [PATCH 0/17] mpi3mr: fix out-of-bounds accesses and reference leaks Chandrakanth Patil
2026-08-18 23:14 ` [PATCH 01/17] mpi3mr: Fix buffer overflow in BSG passthrough request copy Chandrakanth Patil
2026-08-18 18:14 ` sashiko-bot
2026-08-18 23:14 ` [PATCH 02/17] mpi3mr: Fix out-of-bounds read when copying BSG MPI requests Chandrakanth Patil
2026-08-18 18:15 ` sashiko-bot
2026-08-18 23:14 ` [PATCH 03/17] mpi3mr: Fix I/O block counter leak on admin request post failure Chandrakanth Patil
2026-08-18 18:11 ` sashiko-bot
2026-08-18 23:14 ` [PATCH 04/17] mpi3mr: Fix target device reference leak in BSG task management Chandrakanth Patil
2026-08-18 18:13 ` sashiko-bot
2026-08-18 23:14 ` [PATCH 05/17] mpi3mr: Fix buffer overflow when caching log data Chandrakanth Patil
2026-08-18 23:14 ` [PATCH 06/17] mpi3mr: Fix out-of-bounds reply frame access Chandrakanth Patil
2026-08-18 18:11 ` sashiko-bot
2026-08-18 23:14 ` [PATCH 07/17] mpi3mr: Fix out-of-bounds sense buffer access Chandrakanth Patil
2026-08-18 18:11 ` sashiko-bot
2026-08-18 23:14 ` [PATCH 08/17] mpi3mr: Fix out-of-bounds bitmap access during device removal Chandrakanth Patil
2026-08-18 18:13 ` sashiko-bot
2026-08-18 23:14 ` [PATCH 09/17] mpi3mr: Fix target device reference leak in device removal handshake Chandrakanth Patil
2026-08-18 18:18 ` sashiko-bot
2026-08-18 23:14 ` [PATCH 10/17] mpi3mr: Fix out-of-bounds read in SAS topology change events Chandrakanth Patil
2026-08-18 18:10 ` sashiko-bot
2026-08-18 23:14 ` [PATCH 11/17] mpi3mr: Fix out-of-bounds read of event data Chandrakanth Patil
2026-08-18 18:16 ` sashiko-bot
2026-08-18 23:14 ` [PATCH 12/17] mpi3mr: Fix out-of-bounds phy array access on link change Chandrakanth Patil
2026-08-18 18:33 ` sashiko-bot
2026-08-18 23:14 ` [PATCH 13/17] mpi3mr: Fix buffer overflow in the BSG target device map Chandrakanth Patil
2026-08-18 23:14 ` [PATCH 14/17] mpi3mr: Fix out-of-bounds read in PCIe topology change events Chandrakanth Patil
2026-08-18 18:23 ` sashiko-bot
2026-08-18 23:14 ` [PATCH 15/17] mpi3mr: zero out diagnostic buffer status memory Chandrakanth Patil
2026-08-18 18:21 ` sashiko-bot
2026-08-18 23:14 ` [PATCH 16/17] mpi3mr: Fix use-after-free of the firmware event workqueue Chandrakanth Patil
2026-08-18 18:23 ` sashiko-bot [this message]
2026-08-18 23:14 ` [PATCH 17/17] mpi3mr: Fix NULL pointer dereference on PCI error recovery Chandrakanth Patil
2026-08-18 18:32 ` 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=20260818182335.C3EBE1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=chandrakanth.patil@broadcom.com \
--cc=linux-scsi@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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