From mboxrd@z Thu Jan 1 00:00:00 1970 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 3725CC04E69 for ; Thu, 3 Aug 2023 13:04:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235947AbjHCNEt (ORCPT ); Thu, 3 Aug 2023 09:04:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235889AbjHCND5 (ORCPT ); Thu, 3 Aug 2023 09:03:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 475D0E6F; Thu, 3 Aug 2023 06:03:53 -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 BC46161D9A; Thu, 3 Aug 2023 13:03:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D326FC433C7; Thu, 3 Aug 2023 13:03:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691067832; bh=AXYOKNxITGomWgcx6d+tCIb6stNbMJblEeusTDMqoNI=; h=From:To:Cc:Subject:Date:From; b=BvWBDnmId2mj5tSRhvdJqz5JdGa+ApmZzOu4xtMZnDsKcVkoTH+p4lRplQZvMlt0o LIt/6wudSWB/8Uj5qFi0b/YVzlkjJNsA253xDuFMMxuvVhc5dVmWDJF7r7yipIx0WX 7fdOo9vldMHZjlwjBhN6as9VkVGrPTKu331Jz8VfF3PIi4PbqgzNFRQpzNAn0vR6Cf /1XeyfZjsk88ZD987atXC7AV6z98Frl5GicuXUIzPQ9D8NfCoUJfejgqX4btIAS5Tz YQ+fCG1lce+y/+gwh691Skk9RbCTRHfzLMgN5Vvi5Q0d7eq/WC/OSk3x4lMcG6QG25 v4KubVAX+8RRA== 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 5.10 1/2] scsi: lpfc: Fix a possible data race in lpfc_unregister_fcf_rescan() Date: Thu, 3 Aug 2023 09:03:47 -0400 Message-Id: <20230803130349.641732-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 5.10.188 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 |= 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 = 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_hbadisc.c index 68ff233f936e5..3ff76ca147a5a 100644 --- a/drivers/scsi/lpfc/lpfc_hbadisc.c +++ b/drivers/scsi/lpfc/lpfc_hbadisc.c @@ -6790,7 +6790,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 = 0; + spin_unlock_irq(&phba->hbalock); phba->fcf.current_rec.flag = 0; /* -- 2.40.1