From: sashiko-bot@kernel.org
To: "Ranjan Kumar" <ranjan.kumar@broadcom.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v3 06/10] mpi3mr: Fix memory leak on operational queue creation failure
Date: Fri, 24 Jul 2026 10:51:06 +0000 [thread overview]
Message-ID: <20260724105106.D37551F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260724102505.115136-7-ranjan.kumar@broadcom.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Race condition in interrupt pointer clearing causes Use-After-Free and TOCTOU NULL pointer dereferences.
- [High] Permanent DMA memory leak of `q_segment_list` when `kzalloc_objs` fails during queue allocation.
--
--- Patch [6]: [PATCH v3 06/10] mpi3mr: Fix memory leak on operational queue creation failure ---
commit 30cab2ccb258127e2dd2cf1a6d7a0d940a8b72fa
Author: Ranjan Kumar <ranjan.kumar@broadcom.com>
mpi3mr: Fix memory leak on operational queue creation failure
When operational queue creation fails after one or more queues have
been created, the error path frees the queue information arrays but
does not release the DMA memory segments associated with the created
queues, resulting in a memory leak. Fix this by ensuring that partially
allocated segments are freed immediately if a queue fails to create.
Closes: https://sashiko.dev/#/patchset/20260626114109.43685-1-ranjan.kumar@broadcom.com?part=6
Closes: https://sashiko.dev/#/patchset/20260708183305.244485-1-ranjan.kumar@broadcom.com?part=6
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
> index 9f7cee26ebcd3..370ad85681171 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
> @@ -2020,6 +2020,10 @@ static void mpi3mr_free_op_reply_q_segments(struct mpi3mr_ioc *mrioc, u16 q_idx)
> u16 j;
> int size;
> struct segments *segments;
> + u16 midx = REPLY_QUEUE_IDX_TO_MSIX_IDX(q_idx, mrioc->op_reply_q_offset);
> +
> + if (midx < mrioc->intr_info_count)
> + mrioc->intr_info[midx].op_reply_q = NULL;
[Severity: High]
This isn't a bug introduced by this patch, but can this clear the pointer
while an interrupt is actively accessing it?
Since we clear mrioc->intr_info[midx].op_reply_q without disabling the
IRQ or calling synchronize_irq(), a hardware interrupt firing concurrently
could access the queue locklessly.
For example, in drivers/scsi/mpi3mr/mpi3mr_fw.c:mpi3mr_isr_poll():
if (!atomic_read(&intr_info->op_reply_q->pend_ios))
break;
The pointer is evaluated unconditionally and could be set to NULL
concurrently before being read again.
Similarly, in mpi3mr_isr_primary():
if (intr_info->op_reply_q)
num_op_reply = mpi3mr_process_op_reply_q(mrioc,
intr_info->op_reply_q);
There is a race window where op_reply_q can be set to NULL after the
check, resulting in processing a queue whose segments are actively
being freed.
>
> segments = mrioc->op_reply_qinfo[q_idx].q_segments;
> if (!segments)
> return;
[Severity: High]
This is a pre-existing issue, but could this early return bypass the
cleanup for q_segment_list?
In mpi3mr_alloc_op_reply_q_segments(), if the kzalloc_objs() call for
q_segments fails, it returns without cleaning up the successfully allocated
q_segment_list:
op_reply_q->q_segments = kzalloc_objs(struct segments,
op_reply_q->num_segments);
if (!op_reply_q->q_segments)
return -ENOMEM;
Because q_segments is NULL in this failure path, the cleanup function
mpi3mr_free_op_reply_q_segments() returns early here, bypassing the
dma_free_coherent() cleanup for q_segment_list. This could cause a
permanent DMA memory leak of q_segment_list.
Does this same vulnerability exist in mpi3mr_alloc_op_req_q_segments()
and mpi3mr_free_op_req_q_segments() where similar early returns occur?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260724102505.115136-1-ranjan.kumar@broadcom.com?part=6
next prev parent reply other threads:[~2026-07-24 10:51 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-24 10:24 [PATCH v3 00/10] mpi3mr: Few Enhancements and minor fixes Ranjan Kumar
2026-07-24 10:24 ` [PATCH v3 01/10] mpi3mr: Skip device shutdown during unload per controller configuration Ranjan Kumar
2026-07-24 10:59 ` sashiko-bot
2026-07-24 10:24 ` [PATCH v3 02/10] mpi3mr: Update MPI Headers to revision 41 Ranjan Kumar
2026-07-24 10:24 ` [PATCH v3 03/10] mpi3mr: Add early timestamp synchronization after driver load Ranjan Kumar
2026-07-24 10:24 ` [PATCH v3 04/10] mpi3mr: Fix NVMe page size caching for non-operational devices Ranjan Kumar
2026-07-24 10:44 ` sashiko-bot
2026-07-24 10:25 ` [PATCH v3 05/10] mpi3mr: Fix performance regression caused by extended IRQ poll sleep Ranjan Kumar
2026-07-24 10:50 ` sashiko-bot
2026-07-24 10:25 ` [PATCH v3 06/10] mpi3mr: Fix memory leak on operational queue creation failure Ranjan Kumar
2026-07-24 10:51 ` sashiko-bot [this message]
2026-07-24 10:25 ` [PATCH v3 07/10] mpi3mr: Fix firmware event reference leak during cleanup Ranjan Kumar
2026-07-24 11:02 ` sashiko-bot
2026-07-24 10:25 ` [PATCH v3 08/10] mpi3mr: Fix SAS port allocation and registration error handling Ranjan Kumar
2026-07-24 10:58 ` sashiko-bot
2026-07-24 10:25 ` [PATCH v3 09/10] mpi3mr: Fix SAS PHY cleanup in host addition error paths Ranjan Kumar
2026-07-24 10:25 ` [PATCH v3 10/10] mpi3mr: Driver version update to 8.18.0.8.50 Ranjan Kumar
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=20260724105106.D37551F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=ranjan.kumar@broadcom.com \
--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 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.