From: Hannes Reinecke <hare@suse.de>
To: weidongw@illinois.edu, "Martin K. Petersen" <mkp@kernel.org>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] scsi: libfc: Fix rport kref leak in fc_rport_enter_ready()
Date: Tue, 10 Nov 2026 08:08:38 +0100 [thread overview]
Message-ID: <41aae956-1ece-4af3-99e0-1e9ee1f840d3@suse.de> (raw)
In-Reply-To: <20261108-h123-send-v1-1-b7672ff849f0@illinois.edu>
On 11/8/26 10:01 AM, Weidong Wang via B4 Relay wrote:
> From: Weidong Wang <weidongw@illinois.edu>
>
> fc_rport_enter_ready() takes a reference on the rport unconditionally,
> but only queues event_work, whose handler drops that reference, when no
> event is pending. If rdata->event is already set, the && short-circuits
> past both queue_work() and the compensating kref_put(), so the reference
> is leaked and the fc_rport_priv is never freed.
>
> This is reachable from the wire: a PLOGI from a well-known address goes
> straight to fc_rport_enter_ready(), and a second PLOGI for the same
> S_ID while RPORT_EV_READY is still pending enters it again. After the
> rport is logged out, kmemleak reports:
>
> unreferenced object 0xffff888... (size 512):
> backtrace:
> __kmalloc_noprof
> fc_rport_create
> fc_rport_recv_req
> fc_lport_recv_els_req
> fc_lport_recv
> fcoe_receive_work
>
> Commit 823a65409c89 ("scsi: libfc: Skip additional kref updating work
> event") fixed the same pattern in fc_rport_enter_delete(). Do the same
> here: only take the reference when no event is pending, i.e. when the
> work is actually going to be queued.
>
> The issue was found with an LLM-based bug-finding tool; the reproducer,
> fix and changelog were drafted with AI assistance (Claude), then
> reviewed and tested by the submitter.
>
> Fixes: 4d2095cc42a2 ("scsi: libfc: Revisit kref handling")
> Cc: stable@vger.kernel.org
> Signed-off-by: Weidong Wang <weidongw@illinois.edu>
> ---
> Tested on v7.4-rc1 (05441d697f7f), x86_64, KASAN + kmemleak, QEMU/KVM.
> Reproducer: software FCoE instance on lo; raw FCoE ELS frames injected
> with AF_PACKET (PLOGI from well-known S_IDs 0xfffc01.., a second PLOGI
> for the same S_ID while RPORT_EV_READY is pending, then LOGO), 120 rports.
>
> 2nd enter_ready with kmemleak unreferenced
> event pending fc_rport_priv (512 B)
> unpatched 116 99
> patched 104 0
>
> READY/delete work events are processed the same with and without the
> patch; no KASAN/UBSAN/WARN splats. checkpatch clean, no new W=1 warnings.
> The reproducer can be shared on request.
> ---
> drivers/scsi/libfc/fc_rport.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/scsi/libfc/fc_rport.c b/drivers/scsi/libfc/fc_rport.c
> index c25979d96..7b0938544 100644
> --- a/drivers/scsi/libfc/fc_rport.c
> +++ b/drivers/scsi/libfc/fc_rport.c
> @@ -550,10 +550,11 @@ static void fc_rport_enter_ready(struct fc_rport_priv *rdata)
>
> FC_RPORT_DBG(rdata, "Port is Ready\n");
>
> - kref_get(&rdata->kref);
> - if (rdata->event == RPORT_EV_NONE &&
> - !queue_work(rport_event_queue, &rdata->event_work))
> - kref_put(&rdata->kref, fc_rport_destroy);
> + if (rdata->event == RPORT_EV_NONE) {
> + kref_get(&rdata->kref);
> + if (!queue_work(rport_event_queue, &rdata->event_work))
> + kref_put(&rdata->kref, fc_rport_destroy);
> + }
>
> rdata->event = RPORT_EV_READY;
> }
>
> ---
> base-commit: 05441d697f7f9a927264f4058cbbc6a03dfcac9d
> change-id: 20261108-h123-send-723aeb555069
>
> Best regards,
> --
> Weidong Wang <weidongw@illinois.edu>
>
>
Reviewed-by: Hannes Reinecke <hare@kernel.org>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
prev parent reply other threads:[~2026-11-10 7:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-08 9:01 Weidong Wang via B4 Relay
2026-11-10 7:08 ` Hannes Reinecke [this message]
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=41aae956-1ece-4af3-99e0-1e9ee1f840d3@suse.de \
--to=hare@suse.de \
--cc=James.Bottomley@HansenPartnership.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=mkp@kernel.org \
--cc=stable@vger.kernel.org \
--cc=weidongw@illinois.edu \
/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
all inboxes | Powered by JetHome®