Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Nilesh Javali" <njavali@marvell.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v4 37/56] scsi: qla2xxx: Add size check for extended VP report ID entry
Date: Tue, 14 Jul 2026 15:40:05 +0000	[thread overview]
Message-ID: <20260714154005.BAFBC1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260714095353.289460-38-njavali@marvell.com>

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

New issues:
- [High] The hardware-defined structure `vp_rpt_id_entry_24xx_ext` uses C bitfields (`vp_idx : 9` and `vp_status : 7`) to map to Little-Endian firmware IOCB data, causing endianness and ABI layout corruption on Big-Endian architectures.

Pre-existing issues:
- [Critical] The virtual port (`vp`) pointer is accessed and modified after releasing `ha->vport_slock` without acquiring a reference.
- [Critical] The `fcport` pointer is dereferenced and modified after the `sess_lock` is released, without acquiring a reference.
- [Critical] In the format 2 branch of `qla24xx_report_id_acquisition`, the driver iterates over the `vha->vp_fcports` list to modify `fcport->scan_state` without acquiring `vha->hw->tgt.sess_lock`.
- [High] Missing endianness conversion when reading the little-endian `bbcr` hardware field.
--

--- Patch [37]: [PATCH v4 37/56] scsi: qla2xxx: Add size check for extended VP report ID entry ---
commit 0a18f95655fa2d187c369d0dd1d03c6b0b2a0d73
Author: Nilesh Javali <njavali@marvell.com>
Subject: scsi: qla2xxx: Add size check for extended VP report ID entry

This commit adds padding to the extended VP report ID entry to match
the hardware IOCB stride. It also updates qla24xx_report_id_acquisition()
to accept a void pointer and extract the virtual port index and status
from the extended structure on 29xx series adapters.

> diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
> index 3ebda35dd584f..cec308811d9eb 100644
> --- a/drivers/scsi/qla2xxx/qla_mbx.c
> +++ b/drivers/scsi/qla2xxx/qla_mbx.c
> @@ -4102,6 +4105,14 @@ qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
>  	if (rptid_entry->entry_status != 0)
>  		return;
>  
> +	if (IS_QLA29XX(ha)) {
> +		vp_idx = rptid_entry_ext->vp_idx;
> +		vp_status = rptid_entry_ext->vp_status;

[Severity: High]
Do C bitfields map correctly on Big-Endian architectures here?

The hardware-defined structure vp_rpt_id_entry_24xx_ext maps to
Little-Endian firmware IOCB data. If vp_idx and vp_status are defined
as bitfields, this can cause endianness and ABI layout corruption on
Big-Endian hosts, leading to mapping to the wrong virtual ports.

[ ... ]

> @@ -4223,8 +4233,8 @@ qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
>  		/* buffer to buffer credit flag */
>  		vha->flags.bbcr_enable = (rptid_entry->u.f1.bbcr & 0xf) != 0;

[Severity: High]
This is a pre-existing issue, but is an endianness conversion missing when
reading the bbcr field here?

The hardware bbcr field is little-endian (defined as __le16), but it is
read natively without byte-swapping. On a big-endian system, the bitwise
AND will mask the wrong byte, resulting in invalid credit behavior.

[ ... ]

> @@ -4241,18 +4251,18 @@ qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
>  			set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
>  			set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
>  		} else {
> -			if (rptid_entry->vp_status != VP_STAT_COMPL &&
> -				rptid_entry->vp_status != VP_STAT_ID_CHG) {
> +			if (vp_status != VP_STAT_COMPL &&
> +				vp_status != VP_STAT_ID_CHG) {
>  				ql_dbg(ql_dbg_mbx, vha, 0x10ba,
>  				    "Could not acquire ID for VP[%d].\n",
> -				    rptid_entry->vp_idx);
> +				    vp_idx);
>  				return;
>  			}
>  
>  			found = 0;
>  			spin_lock_irqsave(&ha->vport_slock, flags);
>  			list_for_each_entry(vp, &ha->vp_list, list) {
> -				if (rptid_entry->vp_idx == vp->vp_idx) {
> +				if (vp_idx == vp->vp_idx) {
>  					found = 1;
>  					break;
>  				}

[Severity: Critical]
This is a pre-existing issue, but is the vp pointer safe to access here?

The vp pointer is extracted from ha->vp_list, but the vport_slock is
dropped before qla_update_host_map(vp, id) is called, and no reference is
taken on the port:

qla24xx_report_id_acquisition() {
    spin_lock_irqsave(&ha->vport_slock, flags);
    list_for_each_entry(vp, &ha->vp_list, list) {
        if (vp_idx == vp->vp_idx) {
            found = 1;
            break;
        }
    }
    spin_unlock_irqrestore(&ha->vport_slock, flags);

    if (!found)
        return;

    qla_update_host_map(vp, id);
}

If another thread concurrently deletes the virtual port via
qla24xx_vport_delete(), the memory could be freed while it's still being
accessed, causing a use-after-free.

[Severity: Critical]
This is a pre-existing issue, but is the fcport pointer safe from a
use-after-free in the format 1 branch of qla24xx_report_id_acquisition()?

The fcport pointer is acquired under a spinlock, but the lock is released
before the pointer is safely used or reference counted:

qla24xx_report_id_acquisition() {
    ...
    fcport = qla2x00_find_fcport_by_wwpn(vha, rptid_entry->u.f1.port_name, 1);
    spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);

    if (fcport) {
        fcport->plogi_nack_done_deadline = jiffies + HZ;
        fcport->dm_login_expire = jiffies + QLA_N2N_WAIT_TIME * HZ;
        fcport->scan_state = QLA_FCPORT_FOUND;
    ...
}

A concurrent session teardown can free the fcport before these updates
complete.

[Severity: Critical]
This is a pre-existing issue, but does iterating over vha->vp_fcports
in the format 2 branch require the sess_lock?

In the format 2 branch (RIDA format 2 / N2N direct connect) of
qla24xx_report_id_acquisition(), the code calls list_for_each_entry
without acquiring the sess_lock that protects vp_fcports:

qla24xx_report_id_acquisition() {
    ...
    list_for_each_entry(fcport, &vha->vp_fcports, list) {
        fcport->scan_state = QLA_FCPORT_SCAN;
        fcport->n2n_flag = 0;
    }
    ...
}

Other threads (e.g., session deletion) might concurrently add or remove
nodes from this list. Iterating a mutating linked list concurrently without
locks could lead to structural corruption or infinite loops.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260714095353.289460-1-njavali@marvell.com?part=37

  reply	other threads:[~2026-07-14 15:40 UTC|newest]

Thread overview: 94+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-14  9:52 [PATCH v4 00/56] scsi: qla2xxx: Add QLA29xx series adapter support Nilesh Javali
2026-07-14  9:52 ` [PATCH v4 01/56] scsi: qla2xxx: Add 29xx series PCI device ID support Nilesh Javali
2026-07-14 10:19   ` sashiko-bot
2026-07-14  9:52 ` [PATCH v4 02/56] scsi: qla2xxx: Add flash read/write interface for 29xx Nilesh Javali
2026-07-14 12:26   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 03/56] scsi: qla2xxx: Add NVRAM config support for 29xx adapters Nilesh Javali
2026-07-14 10:11   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 04/56] scsi: qla2xxx: Add 29xx support in queue initialisation path Nilesh Javali
2026-07-14 10:28   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 05/56] scsi: qla2xxx: Add FC operational firmware load for 29xx Nilesh Javali
2026-07-14 10:43   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 06/56] scsi: qla2xxx: Remove redundant VPD flash read in sysfs read path Nilesh Javali
2026-07-14 10:42   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 07/56] scsi: qla2xxx: Add flash block read/write BSG support for 29xx Nilesh Javali
2026-07-14  9:53 ` [PATCH v4 08/56] scsi: qla2xxx: Add BSG MPI firmware load/dump " Nilesh Javali
2026-07-14 10:59   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 09/56] scsi: qla2xxx: Add 128-byte IOCB definitions " Nilesh Javali
2026-07-14 11:09   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 10/56] scsi: qla2xxx: Add extended status continuation and marker IOCBs Nilesh Javali
2026-07-14 11:06   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 11/56] scsi: qla2xxx: Update IO path to use 128-byte IOCBs for 29xx Nilesh Javali
2026-07-14 11:54   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 12/56] scsi: qla2xxx: Skip image-set-valid attribute " Nilesh Javali
2026-07-14  9:53 ` [PATCH v4 13/56] scsi: qla2xxx: Skip unsupported sysfs attributes " Nilesh Javali
2026-07-14  9:53 ` [PATCH v4 14/56] scsi: qla2xxx: Enable get_fw_version mailbox " Nilesh Javali
2026-07-14 12:10   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 15/56] scsi: qla2xxx: Extend execute_fw mailbox to include 29xx Nilesh Javali
2026-07-14  9:53 ` [PATCH v4 16/56] scsi: qla2xxx: Enable get_adapter_id mailbox for 29xx Nilesh Javali
2026-07-14 12:19   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 17/56] scsi: qla2xxx: Enable init_firmware " Nilesh Javali
2026-07-14 12:48   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 18/56] scsi: qla2xxx: Enable get_firmware_state " Nilesh Javali
2026-07-14 13:13   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 19/56] scsi: qla2xxx: Enable serdes, resource count and FCE trace " Nilesh Javali
2026-07-14 13:10   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 20/56] scsi: qla2xxx: Enable set_els_cmds and echo_test " Nilesh Javali
2026-07-14  9:53 ` [PATCH v4 21/56] scsi: qla2xxx: Add support for QLA29XX in data rate functions Nilesh Javali
2026-07-14  9:53 ` [PATCH v4 22/56] scsi: qla2xxx: Enable qla2x00_shutdown for 29xx Nilesh Javali
2026-07-14 13:30   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 23/56] scsi: qla2xxx: Use ring-slot helpers in __qla2x00_alloc_iocbs Nilesh Javali
2026-07-14  9:53 ` [PATCH v4 24/56] scsi: qla2xxx: Add support for QLA29XX in memory allocation Nilesh Javali
2026-07-14  9:53 ` [PATCH v4 25/56] scsi: qla2xxx: Handle sts_cont_entry_ext_t for 29xx adapters Nilesh Javali
2026-07-14 13:45   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 26/56] scsi: qla2xxx: Update handling of status entries for 29xx series Nilesh Javali
2026-07-14 14:21   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 27/56] scsi: qla2xxx: Enhance ct_entry_24xx_ext iocb handling " Nilesh Javali
2026-07-14  9:53 ` [PATCH v4 28/56] scsi: qla2xxx: Enhance purex_entry " Nilesh Javali
2026-07-14 14:45   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 29/56] scsi: qla2xxx: Update handling of ELS IOCBs " Nilesh Javali
2026-07-14 15:00   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 30/56] scsi: qla2xxx: Add size check for ELS status entry layout on 29xx Nilesh Javali
2026-07-14 14:31   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 31/56] scsi: qla2xxx: Add 29xx extended logio IOCB support Nilesh Javali
2026-07-14 14:49   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 32/56] scsi: qla2xxx: Enhance task management IOCB handling for 29xx series Nilesh Javali
2026-07-14  9:53 ` [PATCH v4 33/56] scsi: qla2xxx: Add abort command " Nilesh Javali
2026-07-14 15:18   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 34/56] scsi: qla2xxx: Enhance ABTS processing " Nilesh Javali
2026-07-14  9:53 ` [PATCH v4 35/56] scsi: qla2xxx: Update VP control IOCB handling " Nilesh Javali
2026-07-14 17:45   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 36/56] scsi: qla2xxx: Add build-time size check for VP config IOCB layout Nilesh Javali
2026-07-14  9:53 ` [PATCH v4 37/56] scsi: qla2xxx: Add size check for extended VP report ID entry Nilesh Javali
2026-07-14 15:40   ` sashiko-bot [this message]
2026-07-14  9:53 ` [PATCH v4 38/56] scsi: qla2xxx: Add LS4 pass-through IOCB handling for 29xx series Nilesh Javali
2026-07-14 15:40   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 39/56] scsi: qla2xxx: Adjust feature gating in BSG paths for 29xx support Nilesh Javali
2026-07-14 15:52   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 40/56] scsi: qla2xxx: Fix queue teardown NULL dma_free and bitmap locking Nilesh Javali
2026-07-14 16:02   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 41/56] scsi: qla2xxx: Replace __le16 bitfields with scalar and accessors Nilesh Javali
2026-07-14 16:24   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 42/56] scsi: qla2xxx: Fix endianness annotations in vp_rpt_id_entry structures Nilesh Javali
2026-07-14  9:53 ` [PATCH v4 43/56] scsi: qla2xxx: Use 64-bit FPM word counters for 29xx host stats Nilesh Javali
2026-07-14 16:25   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 44/56] scsi: qla2xxx: Add 64G/128G port speed setting support Nilesh Javali
2026-07-14 16:54   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 45/56] scsi: qla2xxx: Fix 64G link speed reporting in get_data_rate Nilesh Javali
2026-07-14  9:53 ` [PATCH v4 46/56] scsi: qla2xxx: edif: Fix NULL pointer deref in RX SA delete check Nilesh Javali
2026-07-14 17:24   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 47/56] scsi: qla2xxx: Fix Name Server logout detection on FWI2 adapters Nilesh Javali
2026-07-14  9:53 ` [PATCH v4 48/56] scsi: qla2xxx: Bound VP index against VP_CTRL IOCB bitmap size Nilesh Javali
2026-07-14 17:31   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 49/56] scsi: qla2xxx: Check entry_status in qla24xx_modify_vp_config() Nilesh Javali
2026-07-14 17:54   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 50/56] scsi: qla2xxx: Hold vport reference in qla24xx_report_id_acquisition() Nilesh Javali
2026-07-14 17:54   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 51/56] scsi: qla2xxx: Initialize NVMe abort_work once at submission Nilesh Javali
2026-07-14 17:59   ` sashiko-bot
2026-07-14  9:53 ` [PATCH v4 52/56] scsi: qla2xxx: Hold qpair lock when sending NVMe LS reject Nilesh Javali
2026-07-14  9:53 ` [PATCH v4 53/56] scsi: qla2xxx: Zero dport diagnostics buffer to avoid info leak Nilesh Javali
2026-07-14  9:53 ` [PATCH v4 54/56] scsi: qla2xxx: Fix BSG job leak on validate flash image error path Nilesh Javali
2026-07-14  9:53 ` [PATCH v4 55/56] scsi: qla2xxx: Bound image count in qla2x00_update_fru_versions() Nilesh Javali
2026-07-14  9:53 ` [PATCH v4 56/56] scsi: qla2xxx: Update version to 12.00.00.2607b1 Nilesh Javali
2026-07-14 10:41   ` Hannes Reinecke

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=20260714154005.BAFBC1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=njavali@marvell.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