From: sashiko-bot@kernel.org
To: "Ranjan Kumar" <ranjan.kumar@broadcom.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v2 06/10] mpi3mr: Fix memory leak on operational queue creation failure
Date: Wed, 08 Jul 2026 19:48:09 +0000 [thread overview]
Message-ID: <20260708194810.6D1C71F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260708183305.244485-7-ranjan.kumar@broadcom.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] The patch introduces a newly triggerable NULL pointer dereference if a spurious interrupt fires on an IRQ vector associated with a queue that was downgraded or freed.
Pre-existing issues:
- [High] The `out_failed` error path leaves dangling pointers in `mrioc->intr_info[*].op_reply_q`, leading to a Use-After-Free in the interrupt handler.
--
--- Patch [6]: [PATCH v2 06/10] mpi3mr: Fix memory leak on operational queue creation failure ---
commit 442fad52bcdebc4eb17a6ed94630805034267b41
Author: Ranjan Kumar <ranjan.kumar@broadcom.com>
Subject: mpi3mr: Fix memory leak on operational queue creation failure
This commit fixes a memory leak where partially allocated DMA memory segments
were not freed if operational queue creation failed. It also hardens the
error handling path by checking for NULL pointers before freeing segments
and resetting operational queue counts to prevent deferred panics.
Closes: https://sashiko.dev/#/patchset/20260626114109.43685-1-ranjan.kumar@broadcom.com?part=6
> diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
> --- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
[ ... ]
> @@ -2533,6 +2533,13 @@ static int mpi3mr_create_op_queues(struct mpi3mr_ioc *mrioc)
> }
> }
>
> + if (i < num_queues) {
> + for (j = i; j < num_queues; j++) {
> + mpi3mr_free_op_req_q_segments(mrioc, j);
> + mpi3mr_free_op_reply_q_segments(mrioc, j);
> + }
> + }
> +
[Severity: High]
Does this introduce a NULL pointer dereference if a spurious interrupt fires
on an IRQ vector associated with a downgraded queue?
If operational queue creation partially fails during a controller reset
(e.g., i < num_queues), this loop explicitly sets
op_reply_qinfo[j].q_segments = NULL via mpi3mr_free_op_reply_q_segments().
Since i > 0, the function succeeds and the controller downgrades to fewer
queues.
However, the driver appears to leave mrioc->intr_info[j].op_reply_q pointing
to these unreached queues. If a spurious interrupt triggers on one of the
unreached vectors, the handler would do this:
mpi3mr_isr_primary() {
if (intr_info->op_reply_q)
mpi3mr_process_op_reply_q(mrioc, intr_info->op_reply_q)
}
And inside mpi3mr_process_op_reply_q():
mpi3mr_process_op_reply_q() {
struct segments *segments = op_reply_q->q_segments;
...
reply_desc = (struct mpi3_default_reply_descriptor *)segments[segment_ix].segment + ...
}
Could this unconditionally dereference the newly nullified q_segments array?
> if (i == 0) {
> /* Not even one queue is created successfully*/
> retval = -1;
[ ... ]
> out_failed:
> - kfree(mrioc->req_qinfo);
> - mrioc->req_qinfo = NULL;
> -
> + if (mrioc->req_qinfo) {
> + for (j = 0; j < i; j++) {
> + mpi3mr_free_op_req_q_segments(mrioc, j);
> + mpi3mr_free_op_reply_q_segments(mrioc, j);
> + }
> + kfree(mrioc->req_qinfo);
> + mrioc->req_qinfo = NULL;
> + }
> + mrioc->num_op_req_q = 0;
> kfree(mrioc->op_reply_qinfo);
> mrioc->op_reply_qinfo = NULL;
> + mrioc->num_op_reply_q = 0;
>
> return retval;
> }
[Severity: High]
This is a pre-existing issue, but does this error path leave dangling pointers
that could cause a Use-After-Free?
If mpi3mr_create_op_queues completely fails during a controller reset
(e.g., i == 0), the code jumps here and frees the mrioc->op_reply_qinfo array.
However, it seems to leave pointers to this array intact inside
mrioc->intr_info[*].op_reply_q. Because these pointers were preserved from
the initial driver load, and interrupts are re-enabled earlier in the reset
sequence, any hardware or spurious interrupt could trigger the primary handler:
mpi3mr_isr_primary() {
if (intr_info->op_reply_q)
num_op_reply = mpi3mr_process_op_reply_q(mrioc, intr_info->op_reply_q);
}
Could this dereference the freed op_reply_qinfo memory? Should the references
in intr_info be cleared when this array is freed?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260708183305.244485-1-ranjan.kumar@broadcom.com?part=6
next prev parent reply other threads:[~2026-07-08 19:48 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 18:32 [PATCH v2 00/10] mpi3mr: Few Enhancements and minor fixes Ranjan Kumar
2026-07-08 18:32 ` [PATCH v2 01/10] mpi3mr: Skip device shutdown during unload per controller configuration Ranjan Kumar
2026-07-08 18:53 ` sashiko-bot
2026-07-08 18:32 ` [PATCH v2 02/10] mpi3mr: Update MPI Headers to revision 41 Ranjan Kumar
2026-07-08 18:32 ` [PATCH v2 03/10] mpi3mr: Add early timestamp synchronization after driver load Ranjan Kumar
2026-07-08 18:32 ` [PATCH v2 04/10] mpi3mr: Fix NVMe page size caching for non-operational devices Ranjan Kumar
2026-07-08 19:18 ` sashiko-bot
2026-07-08 18:33 ` [PATCH v2 05/10] mpi3mr: Fix performance regression caused by extended IRQ poll sleep Ranjan Kumar
2026-07-08 19:30 ` sashiko-bot
2026-07-08 18:33 ` [PATCH v2 06/10] mpi3mr: Fix memory leak on operational queue creation failure Ranjan Kumar
2026-07-08 19:48 ` sashiko-bot [this message]
2026-07-08 18:33 ` [PATCH v2 07/10] mpi3mr: Fix firmware event reference leak during cleanup Ranjan Kumar
2026-07-08 19:59 ` sashiko-bot
2026-07-08 18:33 ` [PATCH v2 08/10] mpi3mr: Fix SAS port allocation and registration error handling Ranjan Kumar
2026-07-08 20:12 ` sashiko-bot
2026-07-08 18:33 ` [PATCH v2 09/10] mpi3mr: Fix SAS PHY cleanup in host addition error paths Ranjan Kumar
2026-07-08 18:33 ` [PATCH v2 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=20260708194810.6D1C71F000E9@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox