From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380028; b=UF14nkQfoB1nkO6SpRe86iLUItMI56SxBgbwErXboCbFlxiTvY4lA3+r7xkNlZCZaMGV 2rutMTA1+L1vgrhOJsAJ3lI8lBGizuCQEX17lORXtqwCTpEP19s6kut/KYVukzGKe6Oo0 ic6BPw2zTQiTSen/Whwfw1a3R374i8i6SG2mMgpY/0Q8goDZQ6vr0xHrgqtXpl01JLgya VnALDUgQhoZ1hveUpxvw07WuKv3uclkFjD24W70+JRke0xMddK7j3W8lc0uMKQ4moZjFV nZQY+eRcQFDHBl+R8vAhKpmBhPXrq+sGfia0oxGe+3/yeysF8nmyx2TuZdg7Y8IlzFQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380028; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=EI0VYGnazj+Nfz+uL9bRnNphoIAUJEL7jGlHdVVbu7g=; b=ZQOya+KhmOGe1hLc8MtFJ3qj3MNlfe10PMWvMGrdvx5PvJmK3PC1rgbO9yfkhebVzCq9 ZaF0+l6GiEr2lIvXBQ772u3E17rP3P1sxZs7zAAjSx4+NXRKiX382iRk27Pfwwoekcvei Rps8tlTtR15ZnQw+jQhlRg9ivAAcIlbRyJFi1jbcmdczgwzx37OEwyJnW717FN8VvJAlY wXyQ4Veacl8uFLXXfoQE8Hs4b12XPUsQaoYK9vi4uTBzun4szvN6+74l63Sx9Gw5EtcyU d2vfBxUeyg1G6IR3zYHP1UDaLwMcGkokXIHPU5BOTqX5CejmyTyR/oLZbFzKtcqyreA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b="n3X/gFul"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 008FB606A32C; Fri, 4 Dec 2026 10:27:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=n3X/gFul Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B1A61F000CE; Fri, 4 Dec 2026 10:27:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380027; bh=EI0VYGnazj+Nfz+uL9bRnNphoIAUJEL7jGlHdVVbu7g=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=n3X/gFulUJrLeiMQ16Xr36DPq3Rk+GZdYObd9y/GORkFwOU88iiv/UpTfRHUNgiN9 LGfqHnIpkjLihAv1BTBLH5QkuJV4qqaohK9A+zTp3KUKfE43SUXVVSh/Ef6cRzZ1/i Rp+6oZS8Rx8udTSEVO07IpWztc5YY1/XRElGn6RI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kyle Mahlkuch , Hannes Reinecke , Paul Ely , "Martin K. Petersen (Oracle)" , Sasha Levin Subject: [PATCH 7.3 089/742] scsi: lpfc: Fix race conditions in ELS retry handling Date: Fri, 4 Dec 2026 18:59:13 +0900 Message-ID: <20261204100637.475119243@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kyle Mahlkuch [ Upstream commit 7470a1f2a84d68d177560b78388e640771b6b94a ] This patch addresses a race condition in the lpfc driver's ELS retry event handling that can lead to a use-after-free in the lpfc_cancel_retry_delay_tmo(), where the NLP_DELAY_TMO flag is cleared before acquiring the lock to check if the retry event is queued. This creates a window where the timer can be rescheduled and fire, causing both the cancel path and the worker thread to release the same reference, resulting in a double-put and use-after-free. Moved capture ndlp and clear evt_arg1 under hbalock while dequeuing LPFC_EVT_ELS_RETRY in lpfc_work_list_done(). Signed-off-by: Kyle Mahlkuch Fixes: e47c9093531d ("[SCSI] lpfc 8.2.5 : Correct ndlp referencing issues") Reviewed-by: Hannes Reinecke Reviewed-by: Paul Ely Link: https://patch.msgid.link/dcea48dd-f76c-4bb0-9275-c12ef9bd78a2@linux.ibm.com Signed-off-by: Martin K. Petersen (Oracle) Signed-off-by: Sasha Levin --- drivers/scsi/lpfc/lpfc_els.c | 29 +++++++++++++++++++++++------ drivers/scsi/lpfc/lpfc_hbadisc.c | 11 ++++++++++- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c index 52fc5058976d9..176dccd4b6347 100644 --- a/drivers/scsi/lpfc/lpfc_els.c +++ b/drivers/scsi/lpfc/lpfc_els.c @@ -4477,18 +4477,35 @@ lpfc_issue_els_edc(struct lpfc_vport *vport, uint8_t retry) void lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp) { - struct lpfc_work_evt *evtp; + struct lpfc_hba *phba = vport->phba; + struct lpfc_work_evt *evtp = &nlp->els_retry_evt; + struct lpfc_nodelist *arg_ndlp = NULL; + unsigned long flags; if (!test_and_clear_bit(NLP_DELAY_TMO, &nlp->nlp_flag)) return; timer_delete_sync(&nlp->nlp_delayfunc); nlp->nlp_last_elscmd = 0; - if (!list_empty(&nlp->els_retry_evt.evt_listp)) { - list_del_init(&nlp->els_retry_evt.evt_listp); - /* Decrement nlp reference count held for the delayed retry */ - evtp = &nlp->els_retry_evt; - lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1); + + /* + * If retry event is queued, remove it under lock and consume + * its payload to prevent double-put. The event holds a reference + * to the nodelist that must be released exactly once. + */ + spin_lock_irqsave(&phba->hbalock, flags); + if (!list_empty(&evtp->evt_listp)) { + list_del_init(&evtp->evt_listp); + /* Take local copy and clear to prevent reuse */ + arg_ndlp = (struct lpfc_nodelist *)evtp->evt_arg1; + evtp->evt_arg1 = NULL; + smp_wmb(); /* Ensure NULL visible before unlock */ } + spin_unlock_irqrestore(&phba->hbalock, flags); + + /* Drop the event-held reference outside the lock */ + if (arg_ndlp) + lpfc_nlp_put(arg_ndlp); + if (test_and_clear_bit(NLP_NPR_2B_DISC, &nlp->nlp_flag)) { if (vport->num_disc_nodes) { if (vport->port_state < LPFC_VPORT_READY) { diff --git a/drivers/scsi/lpfc/lpfc_hbadisc.c b/drivers/scsi/lpfc/lpfc_hbadisc.c index c9b02d2c63054..d105b8eb53faa 100644 --- a/drivers/scsi/lpfc/lpfc_hbadisc.c +++ b/drivers/scsi/lpfc/lpfc_hbadisc.c @@ -840,12 +840,21 @@ lpfc_work_list_done(struct lpfc_hba *phba) while (!list_empty(&phba->work_list)) { list_remove_head((&phba->work_list), evtp, typeof(*evtp), evt_listp); + /* + * The ELS retry event can be requeued by lpfc_els_retry_delay() + * as soon as hbalock is dropped. Consume the payload within the + * hbalock to prevent reuse or double-put. + */ + if (evtp->evt == LPFC_EVT_ELS_RETRY) { + ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1); + evtp->evt_arg1 = NULL; + } spin_unlock_irq(&phba->hbalock); hba_pci_err = test_bit(HBA_PCI_ERR, &phba->bit_flags); free_evt = 1; switch (evtp->evt) { case LPFC_EVT_ELS_RETRY: - ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1); + /* ndlp was already captured under hbalock */ if (!hba_pci_err) { lpfc_els_retry_delay_handler(ndlp); free_evt = 0; /* evt is part of ndlp */ -- 2.53.0