From nobody Sun Feb 8 01:33:49 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 77D19C04A6A for ; Thu, 3 Aug 2023 13:05:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236067AbjHCNFM (ORCPT ); Thu, 3 Aug 2023 09:05:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236021AbjHCNE2 (ORCPT ); Thu, 3 Aug 2023 09:04:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0ED7423A; Thu, 3 Aug 2023 06:04:06 -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 3AA1F61D8E; Thu, 3 Aug 2023 13:04:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69961C433C7; Thu, 3 Aug 2023 13:04:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691067845; bh=I490fSd2+TavDVwDW1x+c3cDdrHaMFzqgaAU/N78IJQ=; h=From:To:Cc:Subject:Date:From; b=Ds+Wi/Au4fBA7WA7rXAlutoefTS4YHjDhcxfam+f+z84Ljc/eoxLcy9l9O9tBvK+L ABkegchRZhwC6wU/96ZZhI08PLJ7PTj+cxBKQEcA56CODUAmp5AV30raE+VZl4lpeR q+Q+TbwTgEk2J5sQUhyvw2vjw4uOmiFGQyfHtnXvYDyV1tzMWI/GkUsTjkHa1fj90j D6r3Nv9BXwooAcZ2qtWl2z0m38VF5LS7pBzpFkd0ExY4CXhDPe4MFeRM+ZdhcKbpFS YoIwSuhZETTnhDShrK3WBg442S2bqtpE3RBv8NU7eSCFd7itE/HSiYYL10lVW6Oss5 92nA7lNPsm4Ow== 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.14] scsi: lpfc: Fix a possible data race in lpfc_unregister_fcf_rescan() Date: Thu, 3 Aug 2023 09:04:02 -0400 Message-Id: <20230803130402.641836-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.14.320 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 4a0889dd4c1d0..709b24a812b5d 100644 --- a/drivers/scsi/lpfc/lpfc_hbadisc.c +++ b/drivers/scsi/lpfc/lpfc_hbadisc.c @@ -6429,7 +6429,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