From patchwork Tue Apr 2 19:58:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10882265 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C433D1390 for ; Tue, 2 Apr 2019 19:58:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF24828684 for ; Tue, 2 Apr 2019 19:58:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A34CD288D7; Tue, 2 Apr 2019 19:58:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 738DE28684 for ; Tue, 2 Apr 2019 19:58:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726337AbfDBT62 (ORCPT ); Tue, 2 Apr 2019 15:58:28 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:43602 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726157AbfDBT61 (ORCPT ); Tue, 2 Apr 2019 15:58:27 -0400 Received: by mail-pl1-f193.google.com with SMTP id m10so6787406plt.10 for ; Tue, 02 Apr 2019 12:58:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zQEr3FfgZzvWxc5u7cOolA1w7b2W4VieB8Xp8U7mCfE=; b=OVtByl5rz21yTjCpwt+TqKsxVleDqcr2U+5hTc+oULKvlppi5kNVgupuXAyNkfzB5a HzeILibEiKU4+uy3fYxdi/PO5cB8hHyqfueQbLttUfGni7wqmSVOVDXw2Im32iflk5mC KusVM1vU7amDMg2gngvajReURxCicqcnlPS15d8gyXurMdmhaq3B38EVwChD5DVLKh0k wQpwYwXZKCp+8UMqMUNxooYrGnRZbvF/5o1SnQgYH91X9wpLbnPG1XbP0hHq6ntx5dtj HPgDMehtyQkA8XZBXbPaVwrSEQ276+BqEVpBAdZbH10FZ+cwPdwsSGSKGR5JsLgjOaef puHw== X-Gm-Message-State: APjAAAVgOfuUC9LQYZrZ5XVFhwDbxkjOz2Nsgftaj1+X6b/glzLdr4eB 0F3ea5TCy2i0Buks6TsZKwQ= X-Google-Smtp-Source: APXvYqzwAULeiO8iRKYEm5JM+DAUffJQjAvexsbOmFNmMVHapY/ZsOyetDjRtBtw9eO8xTNdxpeyiw== X-Received: by 2002:a17:902:361:: with SMTP id 88mr73128619pld.78.1554235107247; Tue, 02 Apr 2019 12:58:27 -0700 (PDT) Received: from desktop-bart.svl.corp.google.com ([2620:15c:2cd:203:5cdc:422c:7b28:ebb5]) by smtp.gmail.com with ESMTPSA id o5sm49055490pfa.135.2019.04.02.12.58.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Apr 2019 12:58:26 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: Mike Christie , Christoph Hellwig , target-devel@vger.kernel.org, Bart Van Assche , Mike Christie , Hannes Reinecke , Nicholas Bellinger Subject: [PATCH 01/11] target/core: Fix a race condition in the LUN lookup code Date: Tue, 2 Apr 2019 12:58:05 -0700 Message-Id: <20190402195815.254796-2-bvanassche@acm.org> X-Mailer: git-send-email 2.20.GIT In-Reply-To: <20190402195815.254796-1-bvanassche@acm.org> References: <20190402195815.254796-1-bvanassche@acm.org> MIME-Version: 1.0 Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The rcu_dereference(deve->se_lun) expression occurs two times 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 --- 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 1f8482b6473b..7eae1c823c4e 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;