Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tyrel Datwyler" <tyreld@linux.ibm.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v2 02/20] scsi: ibmvfc: fix trace logging for NVMe FCP commands
Date: Sat, 19 Sep 2026 01:47:55 +0000	[thread overview]
Message-ID: <20260919014756.1270B1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260919013306.2948028-3-tyreld@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] scsi: ibmvfc: UAF of nvmefc_fcp_req in ibmvfc_trc_start()
- [Medium] scsi: ibmvfc: trace data dropped for SCSI TMFs
--

commit d84c85cc97fa932f9084a1571f9d4d47d52e914d
Author: Tyrel Datwyler <tyreld@linux.ibm.com>
scsi: ibmvfc: fix trace logging for NVMe FCP commands

This commit fixes trace logging for NVMe FCP commands by gating SCSI-specific
field reads on evt->cmnd. It records the NVMe SQE opcode and payload length
from the v3nvme union member for NVMe FCP events.

> diff --git a/drivers/scsi/ibmvscsi/ibmvfc-core.c b/drivers/scsi/ibmvscsi/ibmvfc-core.c
> index aa7ae81df41b1..6558ed3c67c4b 100644
> --- a/drivers/scsi/ibmvscsi/ibmvfc-core.c
> +++ b/drivers/scsi/ibmvscsi/ibmvfc-core.c
> @@ -257,11 +258,16 @@ static void ibmvfc_trc_start(struct ibmvfc_event *evt)
>  
>  	switch (entry->fmt) {
>  	case IBMVFC_CMD_FORMAT:
> -		entry->op_code = iu->cdb[0];
>  		entry->scsi_id = be64_to_cpu(vfc_cmd->tgt_scsi_id);
> -		entry->lun = scsilun_to_int(&iu->lun);
> -		entry->tmf_flags = iu->tmf_flags;
> -		entry->u.start.xfer_len = be32_to_cpu(iu->xfer_len);
> +		if (evt->cmnd) {
> +			entry->op_code = iu->cdb[0];
> +			entry->lun = scsilun_to_int(&iu->lun);
> +			entry->tmf_flags = iu->tmf_flags;
> +			entry->u.start.xfer_len = be32_to_cpu(iu->xfer_len);

[Severity: Medium]
Will this drop trace data for SCSI Task Management Functions?

When an internally generated SCSI TMF is processed, evt->cmnd is initialized
to NULL. Since the extraction of LUN and TMF flags is now strictly gated on
evt->cmnd, TMFs will be skipped entirely leaving these trace fields zeroed out.

> +		} else if (evt->fcp_req) {
> +			entry->op_code = vfc_cmd->v3nvme.iu.sqe.common.opcode;
> +			entry->u.start.xfer_len = evt->fcp_req->payload_length;

[Severity: High]
Can this result in a use-after-free on the NVMe FCP request?

The command has already been submitted to the hardware at this point. In
ibmvfc_send_event(), the queue lock is dropped before calling
ibmvfc_trc_start():

drivers/scsi/ibmvscsi/ibmvfc-core.c:ibmvfc_send_event() {
	...
	spin_unlock_irqrestore(&evt->queue->l_lock, flags);
	ibmvfc_trc_start(evt);
}

Because the lock is dropped, the hardware completion can race and process
the response, calling evt->done(). This hands the NVMe FCP request back to
the block layer where it is completed and freed. Meanwhile, this thread will
locklessly dereference evt->fcp_req->payload_length here, accessing the freed
memory.

> +		}
>  		break;
>  	case IBMVFC_MAD_FORMAT:

[ ... ]

> @@ -294,15 +301,19 @@ static void ibmvfc_trc_end(struct ibmvfc_event *evt)
>  
>  	switch (entry->fmt) {
>  	case IBMVFC_CMD_FORMAT:
> -		entry->op_code = iu->cdb[0];
>  		entry->scsi_id = be64_to_cpu(vfc_cmd->tgt_scsi_id);
> -		entry->lun = scsilun_to_int(&iu->lun);
> -		entry->tmf_flags = iu->tmf_flags;
>  		entry->u.end.status = be16_to_cpu(vfc_cmd->status);
>  		entry->u.end.error = be16_to_cpu(vfc_cmd->error);
> -		entry->u.end.fcp_rsp_flags = rsp->flags;
> -		entry->u.end.rsp_code = rsp->data.info.rsp_code;
> -		entry->u.end.scsi_status = rsp->scsi_status;
> +		if (evt->cmnd) {
> +			entry->op_code = iu->cdb[0];
> +			entry->lun = scsilun_to_int(&iu->lun);
> +			entry->tmf_flags = iu->tmf_flags;
> +			entry->u.end.fcp_rsp_flags = rsp->flags;
> +			entry->u.end.rsp_code = rsp->data.info.rsp_code;
> +			entry->u.end.scsi_status = rsp->scsi_status;

[Severity: Medium]
Will this also drop trace data in the end trace for SCSI TMFs?

Similarly to the start trace, since evt->cmnd is NULL for SCSI TMFs, the
response code, FCP response flags, and SCSI status will be left unrecorded
for these events.

> +		} else if (evt->fcp_req) {
> +			entry->op_code = vfc_cmd->v3nvme.iu.sqe.common.opcode;
> +		}
>  		break;
>  	case IBMVFC_MAD_FORMAT:

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260919013306.2948028-1-tyreld@linux.ibm.com?part=2

  reply	other threads:[~2026-09-19  1:47 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-19  1:32 [PATCH v2 00/20] scsi: ibmvfc: Fixes and cleanup for NVMe/FC support Tyrel Datwyler
2026-09-19  1:32 ` [PATCH v2 01/20] scsi: ibmvfc: initialize evt->tgt for NVMe FCP commands Tyrel Datwyler
2026-09-19  1:51   ` sashiko-bot
2026-09-19  1:32 ` [PATCH v2 02/20] scsi: ibmvfc: fix trace logging " Tyrel Datwyler
2026-09-19  1:47   ` sashiko-bot [this message]
2026-09-19  1:32 ` [PATCH v2 03/20] scsi: ibmvfc: complete NVMe FCP requests on H_CLOSED send failure Tyrel Datwyler
2026-09-19  1:44   ` sashiko-bot
2026-09-19  1:32 ` [PATCH v2 04/20] scsi: ibmvfc: defer NVMe local port registration out of atomic context Tyrel Datwyler
2026-09-19  1:32 ` [PATCH v2 05/20] scsi: ibmvfc: fix uninitialized _done dereference for TMF events on send failure Tyrel Datwyler
2026-09-19  1:32 ` [PATCH v2 06/20] scsi: ibmvfc: fix uninitialized shwqs in ibmvfc_purge_requests() Tyrel Datwyler
2026-09-19  1:32 ` [PATCH v2 07/20] scsi: ibmvfc: fix uninitialized status logged on LS abort send failure Tyrel Datwyler
2026-09-19  1:32 ` [PATCH v2 08/20] scsi: ibmvfc: fix inverted suppress-ABTS capability check in NVMe TMF path Tyrel Datwyler
2026-09-19  1:32 ` [PATCH v2 09/20] scsi: ibmvfc: fix infinite reset loop on NULL evt in implicit logout path Tyrel Datwyler
2026-09-19  1:32 ` [PATCH v2 10/20] scsi: ibmvfc: fix u16 overflow of max_cmds in ibmvfc_set_login_info() Tyrel Datwyler
2026-09-19  1:32 ` [PATCH v2 11/20] scsi: ibmvfc: fix UAF and hang in ibmvfc_cancel_all_mq() on send failure Tyrel Datwyler
2026-09-19  1:32 ` [PATCH v2 12/20] scsi: ibmvfc: fix data race on tgt->nvme_remote_port Tyrel Datwyler
2026-09-19  1:32 ` [PATCH v2 13/20] scsi: ibmvfc: make NVMe FCP abort callback asynchronous Tyrel Datwyler
2026-09-19  1:33 ` [PATCH v2 14/20] scsi: ibmvfc: fix UAF and stall in NVMe LS abort callback Tyrel Datwyler
2026-09-19  1:53   ` sashiko-bot
2026-09-19  1:33 ` [PATCH v2 15/20] scsi: ibmvfc: unregister NVMe local port on adapter removal Tyrel Datwyler
2026-09-19  1:58   ` sashiko-bot
2026-09-19  1:33 ` [PATCH v2 16/20] scsi: ibmvfc: fix NVMe local port leak on fabric link bounce Tyrel Datwyler
2026-09-19  1:33 ` [PATCH v2 17/20] scsi: ibmvfc: fix TOCTOU race in ibmvfc_nvme_create_queue() on adapter removal Tyrel Datwyler
2026-09-19  1:33 ` [PATCH v2 18/20] scsi: ibmvfc: fix NVMe sub-queue registration failure disabling SCSI multiqueue Tyrel Datwyler
2026-09-19  1:33 ` [PATCH v2 19/20] scsi: ibmvfc: fix nr_nvme_hw_queues module parameter ignored for NVMe queue sizing Tyrel Datwyler
2026-09-19  1:33 ` [PATCH v2 20/20] scsi: ibmvfc: fix concurrent SCSI and NVMe discover-targets race dropping targets Tyrel Datwyler

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=20260919014756.1270B1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tyreld@linux.ibm.com \
    /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