All of lore.kernel.org
 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 v5 53/56] scsi: qla2xxx: Zero dport diagnostics buffer to avoid info leak
Date: Fri, 17 Jul 2026 17:10:13 +0000	[thread overview]
Message-ID: <20260717171014.3D8601F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260717152904.3155730-54-njavali@marvell.com>

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

Pre-existing issues:
- [Critical] Missing bounds checks on user-provided lengths cause severe stack and heap buffer overflows, as well as out-of-bounds DMA transfers.
- [High] DMA API violation: modifying a buffer via memset() immediately after mapping it for DMA.
- [High] Uninitialized stack buffer leaks kernel stack memory to user space via BSG replies.
- [High] Unlocked read-modify-write of `vha->dport_status` across process and hardirq contexts leads to a data race.
- [Medium] A struct field at an unaligned offset is mapped for DMA, resulting in unsafe cache-line sharing with adjacent struct fields.
--

--- Patch [53]: [PATCH v5 53/56] scsi: qla2xxx: Zero dport diagnostics buffer to avoid info leak ---
commit d9e6712c9051d0111bc1221f583961121d35d896
Author: Nilesh Javali <njavali@marvell.com>
Subject: scsi: qla2xxx: Zero dport diagnostics buffer to avoid info leak

This commit changes kmalloc_obj to kzalloc_obj in
qla2x00_do_dport_diagnostics. This ensures the qla_dport_diag response
buffer is fully zeroed, preventing uninitialized fields from being
leaked to user space.

> diff --git a/drivers/scsi/qla2xxx/qla_bsg.c b/drivers/scsi/qla2xxx/qla_bsg.c
> index 9ee56ccd52b01..3bf3a7b96eb50 100644
> --- a/drivers/scsi/qla2xxx/qla_bsg.c
> +++ b/drivers/scsi/qla2xxx/qla_bsg.c
> @@ -2858,7 +2858,7 @@ qla2x00_do_dport_diagnostics(struct bsg_job *bsg_job)
>  	    !IS_QLA28XX(vha->hw) && !IS_QLA29XX(vha->hw))
>  		return -EPERM;
>  
> -	dd = kmalloc_obj(*dd);
> +	dd = kzalloc_obj(*dd);

[Severity: Medium]
This isn't a bug introduced by this patch, but does mapping the buf field
of this struct for DMA cause unsafe cache-line sharing?

Looking at struct qla_dport_diag in qla_bsg.h, the __packed attribute
places the buf array at an unaligned 2-byte offset:

struct qla_dport_diag {
        uint16_t options;
        uint32_t buf[16];
        uint8_t  unused[62];
} __packed;

This same unaligned buffer is then mapped for DMA:

qla_mbx.c:qla26xx_dport_diagnostics() {
    dd_dma = dma_map_single(&vha->hw->pdev->dev,
        dd_buf, size, DMA_FROM_DEVICE);
}

Because the struct is packed, the mapped buf array shares a cache line
with the preceding options field, which violates DMA mapping hardware
cache alignment rules. Can this lead to data corruption on architectures
with non-coherent DMA caches?

>  	if (!dd) {
>  		ql_log(ql_log_warn, vha, 0x70db,
>  		    "Failed to allocate memory for dport.\n");

[Severity: High]
This is a pre-existing issue, but is it safe to modify a buffer with
memset while it is actively mapped for DMA?

In the underlying diagnostic functions called after this allocation, the
CPU modifies the buffer via memset after mapping it:

qla_mbx.c:qla26xx_dport_diagnostics() {
    dd_dma = dma_map_single(&vha->hw->pdev->dev,
        dd_buf, size, DMA_FROM_DEVICE);
    if (dma_mapping_error(&vha->hw->pdev->dev, dd_dma)) {
        ql_log(ql_log_warn, vha, 0x1194, "Failed to map dma buffer.\n");
        return QLA_MEMORY_ALLOC_FAILED;
    }

    memset(dd_buf, 0, size);
}

A similar pattern exists in qla26xx_dport_diagnostics_v2(). Since the
DMA API strictly prohibits the CPU from accessing or modifying a buffer
while it is mapped for device access, could the CPU cache lines dirtied
by memset be evicted during the DMA operation and overwrite the
diagnostic test data written by the device?

[Severity: Critical]
This is a pre-existing issue, but does this code lack bounds checks on
user-provided lengths, leading to buffer overflows?

In several BSG handler paths, user-controlled lengths dictate memory
operations without bounds checking:

qla_bsg.c:qla2x00_read_i2c() {
    rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
        i2c->device, i2c->offset, i2c->length, i2c->option);
    
    if (rval) {
        ...
    }

    memcpy(i2c->buffer, sfp, i2c->length);
}

Here, the user-controlled i2c->length is passed directly to the firmware
for DMA, potentially overflowing the 256-byte sfp allocation. It is then
used in a memcpy to overflow the 256-byte bsg array on the stack.

Similarly, in qla2x00_write_i2c():

qla_bsg.c:qla2x00_write_i2c() {
    memcpy(sfp, i2c->buffer, i2c->length);
    rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
        i2c->device, i2c->offset, i2c->length, i2c->option);
}

This causes an out-of-bounds memcpy from the stack into the 256-byte
sfp heap chunk.

Finally, in qla2x00_update_fru_versions():

qla_bsg.c:qla2x00_update_fru_versions() {
    count = list->count;
    while (count--) {
        memcpy(sfp, &image->field_info, sizeof(image->field_info));
        ...
        image++;
    }
}

An unbounded count dictates unbounded traversal of the image pointer
beyond the stack buffer. Could these lead to out-of-bounds DMA transfers
and severe memory corruption?

[Severity: High]
This isn't a bug introduced by this patch, but does this code leak
uninitialized stack memory to user space?

There are uninitialized stack buffers populated by BSG requests that
are fully copied back to user space:

qla_bsg.c:qla2x00_read_fru_status() {
    uint8_t bsg[DMA_POOL_SIZE];
    struct qla_status_reg *sr = (void *)bsg;
    ...
    sg_copy_to_buffer(bsg_job->request_payload.sg_list,
        bsg_job->request_payload.sg_cnt, sr, sizeof(*sr));
    ...
    sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
        bsg_job->reply_payload.sg_cnt, sr, sizeof(*sr));
}

A similar pattern exists in qla2x00_read_i2c(). If a user issues a BSG
request with a small or zero payload size, the rest of the array remains
uninitialized. Will the entire structure size then be copied back via
sg_copy_from_buffer(), leaking kernel stack frames to user space?

[Severity: High]
This is a pre-existing issue, but does this code have an unlocked data
race on vha->dport_status?

In process context:

qla_bsg.c:qla2x00_do_dport_diagnostics_v2() {
    if (options == QLA_START_DPORT_TEST_V2 ||
        options == QLA_RESTART_DPORT_TEST_V2) {
        dd->mbx1 = mcp->mb[0];
        dd->mbx2 = mcp->mb[1];
        vha->dport_status |=  DPORT_DIAG_IN_PROGRESS;
    }
}

In hardirq context:

qla_isr.c:qla2x00_async_event() {
    ...
    case MBA_DPORT_DIAGNOSTICS:
        vha->dport_status &= ~DPORT_DIAG_IN_PROGRESS;
}

Both contexts modify the status field asynchronously without locks.
If the async completion interrupt fires before or during the process
context's bitwise OR operation, could the clear operation performed
by the interrupt be overwritten, permanently sticking the flag in
DPORT_DIAG_IN_PROGRESS?

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

  reply	other threads:[~2026-07-17 17:10 UTC|newest]

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