From nobody Sun Feb 8 01:34:06 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73CA8C04A6A for ; Thu, 3 Aug 2023 13:05:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236063AbjHCNFJ (ORCPT ); Thu, 3 Aug 2023 09:05:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235325AbjHCNEU (ORCPT ); Thu, 3 Aug 2023 09:04:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D98F422C; Thu, 3 Aug 2023 06:04:03 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8B07F61D69; Thu, 3 Aug 2023 13:04:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC6C7C433C9; Thu, 3 Aug 2023 13:04:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691067842; bh=rhxbzDHV5pGo6MyspRX0hzKEWdbB8yOXOhFpkX5FGKY=; h=From:To:Cc:Subject:Date:From; b=kPkaB2wLcU/KPBhtgnCZa0+zvIdplTXIebSsx79F37DmxJF2iDnywiELv8Y7TJZbu AbkNgf1v5J9psPLgKkST+fVj66eaKW4cJVfxs1GqYe6KbOQrtzYoD0P8C2Gepuf3bC nkSLHO4E3NPN+dsQ+biyWSn50829E5/j3y5SPDa5hUPKzLTFb2LBKvHx8qrLYXSLYT 9Ulnb/OzjARt2B+Z+ZE7dJBCFXzFUa666iEs7wD9QqT1nIQrm5U5RQEo6WtrgFOfFq 5wHi3j2BBt9xOrW+WSpIi+PMp0ZW8XZnA/qDY8JQxzUBMIyHuyOLUrLELIdXF0J62Q bg8Kzf79ylTwQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Tuo Li , BassCheck , Justin Tee , Laurence Oberman , "Martin K . Petersen" , Sasha Levin , james.smart@broadcom.com, dick.kennedy@broadcom.com, jejb@linux.ibm.com, linux-scsi@vger.kernel.org Subject: [PATCH AUTOSEL 4.19] scsi: lpfc: Fix a possible data race in lpfc_unregister_fcf_rescan() Date: Thu, 3 Aug 2023 09:03:58 -0400 Message-Id: <20230803130358.641808-1-sashal@kernel.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 4.19.289 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Tuo Li [ Upstream commit 0e881c0a4b6146b7e856735226208f48251facd8 ] The variable phba->fcf.fcf_flag is often protected by the lock phba->hbalock() when is accessed. Here is an example in lpfc_unregister_fcf_rescan(): spin_lock_irq(&phba->hbalock); phba->fcf.fcf_flag |=3D FCF_INIT_DISC; spin_unlock_irq(&phba->hbalock); However, in the same function, phba->fcf.fcf_flag is assigned with 0 without holding the lock, and thus can cause a data race: phba->fcf.fcf_flag =3D 0; To fix this possible data race, a lock and unlock pair is added when accessing the variable phba->fcf.fcf_flag. Reported-by: BassCheck Signed-off-by: Tuo Li Link: https://lore.kernel.org/r/20230630024748.1035993-1-islituo@gmail.com Reviewed-by: Justin Tee Reviewed-by: Laurence Oberman Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/lpfc/lpfc_hbadisc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/scsi/lpfc/lpfc_hbadisc.c b/drivers/scsi/lpfc/lpfc_hbad= isc.c index 5d657178c2b98..8be1c0b4e2a86 100644 --- a/drivers/scsi/lpfc/lpfc_hbadisc.c +++ b/drivers/scsi/lpfc/lpfc_hbadisc.c @@ -6443,7 +6443,9 @@ lpfc_unregister_fcf_rescan(struct lpfc_hba *phba) if (rc) return; /* Reset HBA FCF states after successful unregister FCF */ + spin_lock_irq(&phba->hbalock); phba->fcf.fcf_flag =3D 0; + spin_unlock_irq(&phba->hbalock); phba->fcf.current_rec.flag =3D 0; =20 /* --=20 2.40.1