From: Artem Dinaburg <artem@trailofbits.com>
To: Justin Tee <justin.tee@broadcom.com>, Paul Ely <paul.ely@broadcom.com>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
James Smart <James.Smart@Emulex.Com>,
James Bottomley <James.Bottomley@SteelEye.com>,
"Martin K . Petersen" <mkp@kernel.org>,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
Artem Dinaburg <artem@trailofbits.com>,
stable@vger.kernel.org
Subject: [RFC PATCH 1/3] scsi: lpfc: Do not touch the SFP mailbox after a wait timeout
Date: Sat, 3 Oct 2026 23:41:25 -0400 [thread overview]
Message-ID: <b65e363ff0c63b745de9dba1c1b9e0c988b2dda2.1790968549.git.artem@trailofbits.com> (raw)
In-Reply-To: <cover.1790968549.git.artem@trailofbits.com>
Commit ede596b1434b ("scsi: lpfc: Handle mailbox timeouts in
lpfc_get_sfp_info") made the mailbox cleanup in lpfc_get_sfp_info_wait()
conditional on LPFC_MBX_WAKE, so that a timed-out mailbox is left for
its late completion.
Once lpfc_sli_issue_mbox_wait() returns MBX_TIMEOUT, the mailbox belongs
to the late completion, whose default handler frees it together with its
DMA buffer. Reading mbox_flag at the error label after a timeout is
therefore a use-after-free if the completion has already run.
The LPFC_MBX_WAKE test is also wrong when issuing fails immediately.
lpfc_sli_issue_mbox_wait() clears the flag before issuing, so the caller
still owns the mailbox but skips the cleanup, leaking the mailbox and its
DMA buffer. The A2 page dump does not check for an issue failure at all,
so it can report success with a zeroed page.
Never touch the mailbox after MBX_TIMEOUT, and treat every other
non-success return from either dump as a failure that the caller cleans
up.
Fixes: ede596b1434b ("scsi: lpfc: Handle mailbox timeouts in lpfc_get_sfp_info")
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Artem Dinaburg <artem@trailofbits.com>
---
drivers/scsi/lpfc/lpfc_els.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index 52fc50589..ea8835515 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -7410,12 +7410,12 @@ int lpfc_get_sfp_info_wait(struct lpfc_hba *phba,
}
mbox->vport = phba->pport;
rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_SLI4_CONFIG_TMO);
- if (rc == MBX_NOT_FINISHED) {
+ if (rc == MBX_TIMEOUT)
+ goto error;
+ if (rc != MBX_SUCCESS) {
rc = 1;
goto error;
}
- if (rc == MBX_TIMEOUT)
- goto error;
if (phba->sli_rev == LPFC_SLI_REV4)
mp = mbox->ctx_buf;
else
@@ -7472,6 +7472,10 @@ int lpfc_get_sfp_info_wait(struct lpfc_hba *phba,
if (rc == MBX_TIMEOUT)
goto error;
+ if (rc != MBX_SUCCESS) {
+ rc = 1;
+ goto error;
+ }
if (bf_get(lpfc_mqe_status, &mbox->u.mqe)) {
rc = 1;
goto error;
@@ -7482,7 +7486,7 @@ int lpfc_get_sfp_info_wait(struct lpfc_hba *phba,
DMP_SFF_PAGE_A2_SIZE);
error:
- if (mbox->mbox_flag & LPFC_MBX_WAKE) {
+ if (rc != MBX_TIMEOUT) {
mbox->ctx_buf = mpsave;
lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
}
--
2.43.0
next prev parent reply other threads:[~2026-10-04 3:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-04 3:41 [RFC PATCH 0/3] scsi: lpfc: Fix mailbox timeout ownership races Artem Dinaburg
2026-10-04 3:41 ` Artem Dinaburg [this message]
2026-10-04 3:41 ` [RFC PATCH 2/3] scsi: lpfc: Resolve synchronous mailbox wait ownership under hbalock Artem Dinaburg
2026-10-04 3:41 ` [RFC PATCH 3/3] scsi: lpfc: Add KUnit tests for mailbox wait ownership Artem Dinaburg
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=b65e363ff0c63b745de9dba1c1b9e0c988b2dda2.1790968549.git.artem@trailofbits.com \
--to=artem@trailofbits.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=James.Bottomley@SteelEye.com \
--cc=James.Smart@Emulex.Com \
--cc=justin.tee@broadcom.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=mkp@kernel.org \
--cc=paul.ely@broadcom.com \
--cc=stable@vger.kernel.org \
/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
all inboxes | Powered by JetHome®