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 X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70970C2D0DB for ; Fri, 24 Jan 2020 09:54:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 459B920718 for ; Fri, 24 Jan 2020 09:54:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579859653; bh=aNqxugbB0rJlPQfQeeq/dILE5IVWRmXY0hUhEQAI5kA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=z3qRtAl5Ol6tC/fjfUZ6HlS7cdK0zy/SZy1BNan5clppCeXBNs5+Kx4IZl3AeXJM+ RXGU2BkXGPkP0INAfkyjmNgnZYWJTxEjFz5jPC0VsJMTNWkgrKRfFeyeskMmElXGsj q1xqByaDmIHWfWIlMzpLIORK69ah+iLKn95akKQ4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732461AbgAXJyM (ORCPT ); Fri, 24 Jan 2020 04:54:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:57122 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731584AbgAXJyM (ORCPT ); Fri, 24 Jan 2020 04:54:12 -0500 Received: from localhost (unknown [145.15.244.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7C150206D5; Fri, 24 Jan 2020 09:54:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579859651; bh=aNqxugbB0rJlPQfQeeq/dILE5IVWRmXY0hUhEQAI5kA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HVRNapxw8OAyT3RlIbnb1VCgNsaVtc6+jEwDvi0fgsvtB8/1lltT/ttjNCP9qtCjg fwzdd6V68r/nL9JzBF8ssYa4DMl0FdsQN4v4j3GC6lxd4wXH1y4ZfcljWK2l+QKC/r ATm3jzPlvAL2evmYHL6dH44L5aDwgoLV1uWyZfrY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mike Christie , Christoph Hellwig , Hannes Reinecke , Nicholas Bellinger , Bart Van Assche , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.14 165/343] scsi: target/core: Fix a race condition in the LUN lookup code Date: Fri, 24 Jan 2020 10:29:43 +0100 Message-Id: <20200124092941.680908280@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200124092919.490687572@linuxfoundation.org> References: <20200124092919.490687572@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Bart Van Assche [ Upstream commit 63f7479439c95bcd49b7dd4af809862c316c71a3 ] The rcu_dereference(deve->se_lun) expression occurs twice in the LUN lookup functions. Since these expressions are not serialized against deve->se_lun assignments each of these expressions may yield a different result. Avoid that the wrong LUN pointer is stored in se_cmd by reading deve->se_lun only once. Cc: Mike Christie Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: Nicholas Bellinger Fixes: 29a05deebf6c ("target: Convert se_node_acl->device_list[] to RCU hlist") # v4.10 Signed-off-by: Bart Van Assche Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/target/target_core_device.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c index 92b52d2314b53..cebef8e5a43d1 100644 --- a/drivers/target/target_core_device.c +++ b/drivers/target/target_core_device.c @@ -85,7 +85,7 @@ transport_lookup_cmd_lun(struct se_cmd *se_cmd, u64 unpacked_lun) goto out_unlock; } - se_cmd->se_lun = rcu_dereference(deve->se_lun); + se_cmd->se_lun = se_lun; se_cmd->pr_res_key = deve->pr_res_key; se_cmd->orig_fe_lun = unpacked_lun; se_cmd->se_cmd_flags |= SCF_SE_LUN_CMD; @@ -176,7 +176,7 @@ int transport_lookup_tmr_lun(struct se_cmd *se_cmd, u64 unpacked_lun) goto out_unlock; } - se_cmd->se_lun = rcu_dereference(deve->se_lun); + se_cmd->se_lun = se_lun; se_cmd->pr_res_key = deve->pr_res_key; se_cmd->orig_fe_lun = unpacked_lun; se_cmd->se_cmd_flags |= SCF_SE_LUN_CMD; -- 2.20.1