All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Karan Tilak Kumar" <kartilak@cisco.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v6 10/13] scsi: fnic: Abort timed-out NVMe LS requests
Date: Fri, 24 Jul 2026 18:26:47 +0000	[thread overview]
Message-ID: <20260724182648.61F641F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260724174811.5118-11-kartilak@cisco.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Use-after-free of `tport` in `nvfnic_ls_req_abort` due to concurrent target port deletion.
- [High] Immediate reuse of an Exchange ID (OXID) on ABTS timeout risks cross-talk with delayed target responses.
--

--- Patch [10]: [PATCH v6 10/13] scsi: fnic: Abort timed-out NVMe LS requests ---
commit 39245a565a721e78c479fc226cff0b04ea8531d0
Author: Karan Tilak Kumar <kartilak@cisco.com>

scsi: fnic: Abort timed-out NVMe LS requests

Add an FDLS helper that sends ABTS frames for outstanding NVMe LS
requests.

Use the active LS request OXID when building the ABTS frame, send it
through the FCoE transmit path, and call it from LS timeout and abort
handling.

> diff --git a/drivers/scsi/fnic/fnic_nvme.c b/drivers/scsi/fnic/fnic_nvme.c
> index 0b05dc9698be2..aa3c935d08155 100644
> --- a/drivers/scsi/fnic/fnic_nvme.c
> +++ b/drivers/scsi/fnic/fnic_nvme.c
> @@ -1279,6 +1283,23 @@ void nvfnic_ls_rsp_recv(struct fnic_iport_s *iport,
>  	spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags);
>  }
>  
> +static bool nvfnic_ls_req_cleanup(struct fnic_iport_s *iport,
> +				  struct nvmefc_ls_req *lsreq,
> +				  uint16_t oxid)
> +{
> +	struct nvfnic_ls_req *nvfnic_ls_req = lsreq->private;
> +
> +	if (!nvfnic_ls_req)
> +		return false;
> +
> +	lsreq->private = NULL;
> +	list_del(&nvfnic_ls_req->list);
> +	fdls_free_oxid(iport, oxid, &nvfnic_ls_req->oxid);

[Severity: High]
Is it safe to immediately reuse the OXID on an ABTS timeout, or should it
be quarantined for 2 * R_A_TOV?

When an NVMe LS request's ABTS frame times out, nvfnic_ls_req_timeout()
calls nvfnic_ls_req_cleanup(), which unconditionally calls fdls_free_oxid()
and returns the OXID to the active free pool.

According to Fibre Channel specifications, if an abort times out, the OXID
must be quarantined for 2 * R_A_TOV because a slow target might still send
a delayed response to the original aborted exchange.

If the OXID is reused immediately for a new request to the same target,
could the delayed response be incorrectly matched to the new request,
causing logic errors and potential data corruption?

> +	nvfnic_ls_req->state = FNIC_LS_REQ_CMD_COMPLETE;
> +
> +	return true;
> +}
> +

[ ... ]

> @@ -1648,10 +1675,24 @@ void nvfnic_ls_req_abort(struct nvme_fc_local_port *lport,
>  
>  	/* Mark the state and flags */
>  	nvfnic_ls_req->state = FNIC_LS_REQ_CMD_ABTS_PENDING;
> -	timeout = FNIC_LS_REQ_TMO_MSECS(lsreq->timeout);
> -	mod_timer(&nvfnic_ls_req->ls_req_timer,
> -		  round_jiffies(jiffies + msecs_to_jiffies(timeout)));
> +	oxid = nvfnic_ls_req->oxid;
> +
> +	ret = fdls_send_ls_req_abts(iport, tport, oxid);

[Severity: High]
Can this result in a use-after-free of tport if nvfnic_delete_tport() is
invoked concurrently?

If nvfnic_delete_tport() is invoked twice for the same target port (e.g.
concurrently from the port event handler and the unload/cleanup path), the
second call to nvme_fc_unregister_remoteport() will return -EINVAL since
it is already marked for deletion.

The error path in nvfnic_delete_tport() then calls
nvfnic_terminate_tport_ls_reqs(), which explicitly skips requests in the
FNIC_LS_REQ_CMD_ABTS_STARTED state, and immediately calls kfree(tport).

Concurrently, nvfnic_ls_req_abort() may be in timer_delete_sync() with the
lock dropped and the request in the ABTS_STARTED state. When
nvfnic_ls_req_abort() wakes up and reacquires the lock, it checks
lsreq->private (which was left intact by the cleanup path) and calls
fdls_send_ls_req_abts(iport, tport, oxid). This dereferences the tport that
was just freed.

> +	if (!ret) {
> +		timeout = FNIC_LS_REQ_TMO_MSECS(lsreq->timeout);
> +		mod_timer(&nvfnic_ls_req->ls_req_timer,
> +			  round_jiffies(jiffies + msecs_to_jiffies(timeout)));
> +		spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
> +		return;
> +	}
> +
> +	if (!nvfnic_ls_req_cleanup(iport, lsreq, oxid)) {
> +		spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
> +		return;
> +	}
> +
>  	spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
> +	lsreq->done(lsreq, -EAGAIN);
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260724174811.5118-1-kartilak@cisco.com?part=10

  reply	other threads:[~2026-07-24 18:26 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-24 17:47 [PATCH v6 00/13] Introduce functionality for NVMe initiator Karan Tilak Kumar
2026-07-24 17:47 ` [PATCH v6 01/13] scsi: fnic: Make debug logging protocol independent Karan Tilak Kumar
2026-07-24 18:16   ` sashiko-bot
2026-07-24 17:48 ` [PATCH v6 02/13] scsi: fnic: Use fnic_num for non-SCSI identifiers Karan Tilak Kumar
2026-07-24 18:09   ` sashiko-bot
2026-07-24 17:48 ` [PATCH v6 03/13] scsi: fnic: Decode firmware role configuration Karan Tilak Kumar
2026-07-24 18:07   ` sashiko-bot
2026-07-24 17:48 ` [PATCH v6 04/13] scsi: fnic: Advertise NVMe initiator service parameters Karan Tilak Kumar
2026-07-24 18:05   ` sashiko-bot
2026-07-24 17:48 ` [PATCH v6 05/13] scsi: fnic: Add FDLS role handling for NVMe initiators Karan Tilak Kumar
2026-07-24 18:54   ` sashiko-bot
2026-07-24 17:48 ` [PATCH v6 06/13] scsi: fnic: Add the NVMe/FC transport path Karan Tilak Kumar
2026-07-24 18:20   ` sashiko-bot
2026-07-24 17:48 ` [PATCH v6 07/13] scsi: fnic: Route completions and resets by initiator role Karan Tilak Kumar
2026-07-24 18:26   ` sashiko-bot
2026-07-24 17:48 ` [PATCH v6 08/13] scsi: fnic: Handle NVMe LS frames in FDLS Karan Tilak Kumar
2026-07-24 18:17   ` sashiko-bot
2026-07-24 17:48 ` [PATCH v6 09/13] scsi: fnic: Send NVMe LS requests through FDLS Karan Tilak Kumar
2026-07-24 18:16   ` sashiko-bot
2026-07-24 17:48 ` [PATCH v6 10/13] scsi: fnic: Abort timed-out NVMe LS requests Karan Tilak Kumar
2026-07-24 18:26   ` sashiko-bot [this message]
2026-07-24 17:48 ` [PATCH v6 11/13] scsi: fnic: Track NVMe transport statistics Karan Tilak Kumar
2026-07-24 18:31   ` sashiko-bot
2026-07-24 17:48 ` [PATCH v6 12/13] scsi: fnic: Expose NVMe transport state in debugfs Karan Tilak Kumar
2026-07-24 18:25   ` sashiko-bot
2026-07-24 17:48 ` [PATCH v6 13/13] scsi: fnic: Bump up version number Karan Tilak Kumar
2026-07-24 18:18   ` 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=20260724182648.61F641F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kartilak@cisco.com \
    --cc=linux-scsi@vger.kernel.org \
    --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.