All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ranjan Kumar" <ranjan.kumar@broadcom.com>, linux-scsi@vger.kernel.org
Subject: Re: [PATCH v2 16/20] scsi: mpi3mr: Fix sense buffer use after free on BSG command completion
Date: Thu, 19 Nov 2026 07:34:11 +0000	[thread overview]
Message-ID: <sashiko-outbox-222605@kernel.org> (raw)
In-Reply-To: <20261119071133.127282-17-ranjan.kumar@broadcom.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] scsi: mpi3mr: race on bsg_cmds.done and reply in
  mpi3mr_bsg_process_mpt_cmds()
--

commit 8590d021fe282f240b050a47484ba6f1b211d756
Author: Ranjan Kumar <ranjan.kumar@broadcom.com>

scsi: mpi3mr: Fix sense buffer use after free on BSG command completion

This commit adds a spinlock to struct mpi3mr_drv_cmd to serialize access to
command state, sense buffers, and completion callbacks between BSG command
handling, admin reply processing, and controller resets.

> diff --git a/drivers/scsi/mpi3mr/mpi3mr_app.c b/drivers/scsi/mpi3mr/mpi3mr_app.c
> index 30a01b02a9fc6..fb54bd8093da5 100644
> --- a/drivers/scsi/mpi3mr/mpi3mr_app.c
> +++ b/drivers/scsi/mpi3mr/mpi3mr_app.c
[ ... ]
> @@ -2795,11 +2797,13 @@ static long mpi3mr_bsg_process_mpt_cmds(struct bsg_job *job)
>  			block_seq = mpi3mr_tgtdev_block_io_inc(mrioc, tgtdev);
>  	}
>  
> +	spin_lock_irqsave(&mrioc->bsg_cmds.state_lock, flags);
>  	mrioc->bsg_cmds.state = MPI3MR_CMD_PENDING;
>  	mrioc->bsg_cmds.is_waiting = 1;
>  	mrioc->bsg_cmds.callback = NULL;
>  	mrioc->bsg_cmds.is_sense = 0;
>  	mrioc->bsg_cmds.sensebuf = sense_buff_k;
> +	spin_unlock_irqrestore(&mrioc->bsg_cmds.state_lock, flags);
>  	memset(mrioc->bsg_cmds.reply, 0, mrioc->reply_sz);
>  	mpi_header->host_tag = cpu_to_le16(MPI3MR_HOSTTAG_BSG_CMDS);
>  	if (mrioc->logging_level & MPI3_DEBUG_BSG_INFO) {

[Severity: Medium]
Should memset(mrioc->bsg_cmds.reply, ...) and
init_completion(&mrioc->bsg_cmds.done) run before releasing
mrioc->bsg_cmds.state_lock?

Once state is set to MPI3MR_CMD_PENDING with is_waiting = 1 and state_lock
is released, a concurrent reset or a late reply from an earlier timed-out
BSG command can acquire state_lock and complete bsg_cmds before
init_completion(&mrioc->bsg_cmds.done) runs:

CPU0                                  CPU1
mpi3mr_bsg_process_mpt_cmds()
  spin_lock_irqsave(&state_lock)
  bsg_cmds.state = MPI3MR_CMD_PENDING
  bsg_cmds.is_waiting = 1
  spin_unlock_irqrestore(&state_lock)
                                      mpi3mr_soft_reset_handler()
                                        ...
                                        mpi3mr_drv_cmd_comp_reset()
                                          spin_lock_irqsave(&state_lock)
                                          complete(&bsg_cmds.done)
                                            <-- NULL pointer dereference
                                          spin_unlock_irqrestore(&state_lock)
  init_completion(&bsg_cmds.done)

Because mpi3mr_init_drv_cmd() does not initialize cmdptr->done, on the
first BSG command after probe bsg_cmds.done is still all-zeroes and
complete() dereferences NULL in swake_up_locked().  On later BSG commands,
init_completion() outside state_lock races with complete() on
done.wait.lock or resets done.done after the wakeup, and memset() on
bsg_cmds.reply races with memcpy() in mpi3mr_process_admin_reply_desc().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119071133.127282-1-ranjan.kumar@broadcom.com?part=16

  reply	other threads:[~2026-11-19  7:34 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  7:11 [PATCH v2 00/20] scsi: mpi3mr: Fix issues reported by Sashiko Ranjan Kumar
2026-11-19  7:11 ` [PATCH v2 01/20] scsi: mpi3mr: Fix out-of-bounds read of the BSG request Ranjan Kumar
2026-11-19  7:11 ` [PATCH v2 02/20] scsi: mpi3mr: Fix integer wrap in BSG buffer entry lengths Ranjan Kumar
2026-11-19  7:11 ` [PATCH v2 03/20] scsi: mpi3mr: Remove redundant BSG buffer length checks Ranjan Kumar
2026-11-19  7:11 ` [PATCH v2 04/20] scsi: mpi3mr: Fix PRP list leak in BSG passthrough Ranjan Kumar
2026-11-19  7:11 ` [PATCH v2 05/20] scsi: mpi3mr: Fix reposting of invalid reply address on the admin queue Ranjan Kumar
2026-11-19  7:11 ` [PATCH v2 06/20] scsi: mpi3mr: Fix endianness of device handles in BSG requests Ranjan Kumar
2026-11-19  7:11 ` [PATCH v2 07/20] scsi: mpi3mr: Fix integer overflow in the HDB upload bounds check Ranjan Kumar
2026-11-19  7:11 ` [PATCH v2 08/20] scsi: mpi3mr: Fix integer overflow in the log data size calculation Ranjan Kumar
2026-11-19  7:11 ` [PATCH v2 09/20] scsi: mpi3mr: Queue DEVICE_INFO_CHANGED events to the bottom half again Ranjan Kumar
2026-11-19  7:11 ` [PATCH v2 10/20] scsi: mpi3mr: Fix target device reference leaks Ranjan Kumar
2026-11-19  7:11 ` [PATCH v2 11/20] scsi: mpi3mr: Fix the 32 bit shift when building the phy mask Ranjan Kumar
2026-11-19  7:11 ` [PATCH v2 12/20] scsi: mpi3mr: Fix empty device list race in the all targets query Ranjan Kumar
2026-11-19  7:11 ` [PATCH v2 13/20] scsi: mpi3mr: Fix the lowest phy number for phys 32 and above Ranjan Kumar
2026-11-19  7:11 ` [PATCH v2 14/20] scsi: mpi3mr: Fix target private data use after free in BSG passthrough Ranjan Kumar
2026-11-19  7:11 ` [PATCH v2 15/20] scsi: mpi3mr: Fix block_io accounting when a target is re-created during BSG Ranjan Kumar
2026-11-19  7:11 ` [PATCH v2 16/20] scsi: mpi3mr: Fix sense buffer use after free on BSG command completion Ranjan Kumar
2026-11-19  7:34   ` sashiko-bot [this message]
2026-11-20  8:24     ` Ranjan Kumar
2026-11-19  7:11 ` [PATCH v2 17/20] scsi: mpi3mr: Fix partly written and lost entries in the log data buffer Ranjan Kumar
2026-11-19  7:11 ` [PATCH v2 18/20] scsi: mpi3mr: Fix byte order handling in the NVMe passthrough commands Ranjan Kumar
2026-11-19  7:11 ` [PATCH v2 19/20] scsi: mpi3mr: Fix byte order of the BSG status reply Ranjan Kumar
2026-11-19  7:11 ` [PATCH v2 20/20] scsi: mpi3mr: Use the correct conversion for the diag buffer post request 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=sashiko-outbox-222605@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.