Linux SCSI subsystem development
 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 v5 01/13] scsi: fnic: Make debug logging protocol independent
Date: Wed, 24 Jun 2026 05:08:57 +0000	[thread overview]
Message-ID: <20260624050858.1FA3D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260624044334.3079-2-kartilak@cisco.com>

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

Pre-existing issues:
- [High] Shared struct member used as the flags argument in spin_lock_irqsave() causing IRQ state corruption.
- [High] Lockless modification of fnic_priv(sc)->flags after dropping wq_copy_lock leads to data races and potential Use-After-Free.
--

commit d6c65edf1de54a8d582352945f8226579f06a57d
Author: Karan Tilak Kumar <kartilak@cisco.com>
Subject: scsi: fnic: Make debug logging protocol independent

Make the fnic debug macros take struct fnic instead of struct Scsi_Host so
FCP and NVMe initiator roles can share the same logging interface. Route FCP
messages through shost_printk() and NVMe messages through printk(). Convert
existing debug call sites to pass the fnic instance directly.

> diff --git a/drivers/scsi/fnic/fnic_fcs.c b/drivers/scsi/fnic/fnic_fcs.c
> index 063eb864a5cd0..ca592bc3f6182 100644
> --- a/drivers/scsi/fnic/fnic_fcs.c
> +++ b/drivers/scsi/fnic/fnic_fcs.c
> @@ -1014,7 +1014,7 @@ void fnic_delete_fcp_tports(struct fnic *fnic)
>  
>  	spin_lock_irqsave(&fnic->fnic_lock, flags);
>  	list_for_each_entry_safe(tport, next, &fnic->iport.tport_list, links) {
> -		FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
> +		FNIC_FCS_DBG(KERN_INFO, fnic,
>  					 "removing fcp rport fcid: 0x%x", tport->fcid);
>  		fdls_set_tport_state(tport, FDLS_TGT_STATE_OFFLINING);
>  		fnic_del_tport_timer_sync(fnic, tport);

[Severity: High]
This is a pre-existing issue, but can the call to fnic_del_tport_timer_sync()
corrupt the CPU's IRQ state here?

In fnic_delete_fcp_tports(), the lock is acquired using a local flags
variable:

	spin_lock_irqsave(&fnic->fnic_lock, flags);

However, inside fnic_del_tport_timer_sync(), the lock is released and
reacquired using the shared fnic->lock_flags struct member:

	spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
	timer_delete_sync(&tport->retry_timer);
	spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags);

Would restoring the IRQ state from the uninitialized or stale fnic->lock_flags
leave interrupts incorrectly enabled or disabled? The same pattern also exists
in fnic_tport_event_handler() where it acquires the lock using a local flags
variable but later calls fdls_delete_tport().

[ ... ]

> diff --git a/drivers/scsi/fnic/fnic_scsi.c b/drivers/scsi/fnic/fnic_scsi.c
> index 6ee3c559e129c..0759540f66753 100644
> --- a/drivers/scsi/fnic/fnic_scsi.c
> +++ b/drivers/scsi/fnic/fnic_scsi.c
> @@ -1255,7 +1254,7 @@ static void fnic_fcpio_itmf_cmpl_handler(struct fnic *fnic, unsigned int cq_inde
>  		atomic64_inc(&fnic_stats->io_stats.ioreq_null);
>  		spin_unlock_irqrestore(&fnic->wq_copy_lock[hwq], flags);
>  		fnic_priv(sc)->flags |= FNIC_IO_ABT_TERM_REQ_NULL;
> -		shost_printk(KERN_ERR, fnic->host,
> +		fnic_printk(KERN_ERR, fnic,
>  			  "itmf_cmpl io_req is null - "

[Severity: High]
This is a pre-existing issue, but could this lockless modification cause a data
race or a use-after-free?

In fnic_fcpio_itmf_cmpl_handler(), fnic_priv(sc)->flags is modified
immediately after dropping the wq_copy_lock. If io_req is NULL, it indicates
the IO request has already been cleaned up. Once cleaned up, the block layer
may have already completed the SCSI command via scsi_done() and freed or
recycled the scsi_cmnd structure.

Is it possible that modifying the command's flags locklessly here will result
in memory corruption of a newly recycled or freed command? This pattern also
appears to exist in fnic_abort_cmd() and fnic_pending_aborts_iter().

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

  reply	other threads:[~2026-06-24  5:08 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-24  4:43 [PATCH v5 00/13] Introduce functionality for NVMe initiator Karan Tilak Kumar
2026-06-24  4:43 ` [PATCH v5 01/13] scsi: fnic: Make debug logging protocol independent Karan Tilak Kumar
2026-06-24  5:08   ` sashiko-bot [this message]
2026-06-24  4:43 ` [PATCH v5 02/13] scsi: fnic: Use fnic_num for non-SCSI identifiers Karan Tilak Kumar
2026-06-24  5:11   ` sashiko-bot
2026-06-24  4:43 ` [PATCH v5 03/13] scsi: fnic: Decode firmware role configuration Karan Tilak Kumar
2026-06-24  4:43 ` [PATCH v5 04/13] scsi: fnic: Advertise NVMe initiator service parameters Karan Tilak Kumar
2026-06-24  4:43 ` [PATCH v5 05/13] scsi: fnic: Add FDLS role handling for NVMe initiators Karan Tilak Kumar
2026-06-24  5:18   ` sashiko-bot
2026-06-24  4:43 ` [PATCH v5 06/13] scsi: fnic: Add the NVMe/FC transport path Karan Tilak Kumar
2026-06-24  5:12   ` sashiko-bot
2026-06-24  4:43 ` [PATCH v5 07/13] scsi: fnic: Route completions and resets by initiator role Karan Tilak Kumar
2026-06-24  5:11   ` sashiko-bot
2026-06-24  4:43 ` [PATCH v5 08/13] scsi: fnic: Handle NVMe LS frames in FDLS Karan Tilak Kumar
2026-06-24  5:13   ` sashiko-bot
2026-06-24  4:43 ` [PATCH v5 09/13] scsi: fnic: Send NVMe LS requests through FDLS Karan Tilak Kumar
2026-06-24  5:11   ` sashiko-bot
2026-06-24  4:43 ` [PATCH v5 10/13] scsi: fnic: Abort timed-out NVMe LS requests Karan Tilak Kumar
2026-06-24  5:13   ` sashiko-bot
2026-06-24  4:43 ` [PATCH v5 11/13] scsi: fnic: Track NVMe transport statistics Karan Tilak Kumar
2026-06-24  5:15   ` sashiko-bot
2026-06-24  4:43 ` [PATCH v5 12/13] scsi: fnic: Expose NVMe transport state in debugfs Karan Tilak Kumar
2026-06-24  5:17   ` sashiko-bot
2026-06-24  4:43 ` [PATCH v5 13/13] scsi: fnic: Bump up version number Karan Tilak 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=20260624050858.1FA3D1F000E9@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox