Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp173965rwi; Wed, 12 Oct 2022 18:06:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6tneSz+d3YxRWWDySHDav3uwUk1gf1e4m0CbQCZ/0PHSSti3DIBQYG0fy+brT2gY7F+/8N X-Received: by 2002:aa7:de9a:0:b0:44d:8191:44c5 with SMTP id j26-20020aa7de9a000000b0044d819144c5mr29793250edv.232.1665623170435; Wed, 12 Oct 2022 18:06:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665623170; cv=none; d=google.com; s=arc-20160816; b=pMTwVd3ThYImVwv30qqbG06MctNfoGPbAcGkF/UY34rXr49YD7Q+IaV56c/4sw3SXh KrV1m3ry1b+wPXFx5ojmHHHHL6zScZFqMONv7VOOhhQx03PdzY1idHTxfFseGu3i3ftG eSM7Kypt5LDkgRtydXxP4E7KU6pbKo40olgSoGHDNpnxMPka6qEtlStHLGxfhwOlgh8+ xikObLexDHWrUiXlP4+u7WBIGDmtIFA+pz3k4vOUN6MVrly8itbkWgAA9qixWM6guHpB CjFNBs1ySr3f0KyWBFKx0nAB9zn213ZjKtayMl22DKTG70CzsErXuimWCLIRRAztdRUI VsRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+2rjujWWhfgfG5tiQA0YDLR0d/ewQAf1OGHqtKrMnW4=; b=TQYXBmk1e4ScWXSyim7bD2yR+zt8YN+cu5HD62TKGnUBHyS9nRjY0AHXzpyjXKvUNm /lim88FnSNObqU7rV5D2jb26tnLPfKhCJcMSSjmekBGsfCxfH1+aamT2t23pgrqoGzmU cSDucYhVGEtBj9K14u69YN9uXRyHpwyrK1pbrxDkAjhzXsv/ICzfupW7QQHd/CC/ihcR /cj6bQc7jss4LDunPZkuGgjUa8ouF9onDpIqF7Fh61VybVJ+aDreQ3WtOm8h+8H+jmNk qyfFzJlM7juxtStBAh2bzeSi8t9d4TcET/EqGU7rTOpPvBm08WLZq9sX2o3juuRH5sf9 iyWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Qt1xltwI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dr22-20020a170907721600b0078db8fe2834si8999043ejc.245.2022.10.12.18.05.44; Wed, 12 Oct 2022 18:06:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Qt1xltwI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230212AbiJMAV1 (ORCPT + 99 others); Wed, 12 Oct 2022 20:21:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230136AbiJMAUi (ORCPT ); Wed, 12 Oct 2022 20:20:38 -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 12D9B15E0E3; Wed, 12 Oct 2022 17:18:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9E1FE616B6; Thu, 13 Oct 2022 00:18:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32F61C43142; Thu, 13 Oct 2022 00:18:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665620286; bh=dwDcdLbwsITSd0znTm2jm+ojffy7JRp4bA5tasq8cI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qt1xltwIPH+NrxZy16OvHb0z+arvl73HuTj0joaQsnuKIt0WfVBIpgC78ssj18OKS v4mOyVvyI9OgUs5yfKK4Z5712RkjjZZgmSLf3a+6DO8DEBN1U7gtJ34FGGZoclTn8a DilvVNQoueAw8xvFTKjAh2kjVF5IlpBtsjesJsfXRNXV+5yz45ExSTGVpQvHcTBORb OoLdanxM78oy9yoY5prOzpEl8V9zdguadFaM2n8ivTOPY8P6UxVgE10ZFWxN+nBIAq Y+U6MiLG0AutwoZiTzfvaI82more/T2UjowMxe3cLJCZXANHkK8YTzJUfsmCzHhlc4 P/BLguT2qTtMQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Varun Prakash , Sagi Grimberg , Christoph Hellwig , Sasha Levin , kch@nvidia.com, linux-nvme@lists.infradead.org Subject: [PATCH AUTOSEL 6.0 54/67] nvmet-tcp: add bounds check on Transfer Tag Date: Wed, 12 Oct 2022 20:15:35 -0400 Message-Id: <20221013001554.1892206-54-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221013001554.1892206-1-sashal@kernel.org> References: <20221013001554.1892206-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Varun Prakash [ Upstream commit b6a545ffa2c192b1e6da4a7924edac5ba9f4ea2b ] ttag is used as an index to get cmd in nvmet_tcp_handle_h2c_data_pdu(), add a bounds check to avoid out-of-bounds access. Signed-off-by: Varun Prakash Reviewed-by: Sagi Grimberg Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/nvme/target/tcp.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c index a3694a32f6d5..7dcf88cde189 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -935,10 +935,17 @@ static int nvmet_tcp_handle_h2c_data_pdu(struct nvmet_tcp_queue *queue) struct nvme_tcp_data_pdu *data = &queue->pdu.data; struct nvmet_tcp_cmd *cmd; - if (likely(queue->nr_cmds)) + if (likely(queue->nr_cmds)) { + if (unlikely(data->ttag >= queue->nr_cmds)) { + pr_err("queue %d: received out of bound ttag %u, nr_cmds %u\n", + queue->idx, data->ttag, queue->nr_cmds); + nvmet_tcp_fatal_error(queue); + return -EPROTO; + } cmd = &queue->cmds[data->ttag]; - else + } else { cmd = &queue->connect; + } if (le32_to_cpu(data->data_offset) != cmd->rbytes_done) { pr_err("ttag %u unexpected data offset %u (expected %u)\n", -- 2.35.1