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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7E814C433FE for ; Thu, 13 Oct 2022 00:39:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=bq42xQuaRM/uafj7pRTh8fSHm914PHX5xMxZKSqSO7g=; b=xT2cOlQIhzDPaQb2Qo1fjAVI1S 9v86QXvp1D0k+gVyBgURPpshS2XROjGb+V4pJyby3K/IzLxZ5GdT5+kQAZaVyPcOfvLpsH61aw7mm Gix1Xaollc8oqXXjcjXy60Eymo+roOxtXodjcaoHk7PLEPVig8/qbK6cv5nxOgv/friGanqKYN+1K t3nSAPtH2JY02vwkMoiXIJReOb6rTAVQqrduo69CGaEMn5tnvwj9NBo0hey+99Z3KPC8J7axtCjEC aioVscOiZjQzoxfV4IH7r4yFiGVoDU9YxN3lqI4GFdxmKzlKhP2/tmrHoxdO276H5x4CA1YuP1uZg p5UZ+z0w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oimFX-009wrT-3K; Thu, 13 Oct 2022 00:38:59 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oim1r-009qGI-Pl for linux-nvme@lists.infradead.org; Thu, 13 Oct 2022 00:24:53 +0000 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 ams.source.kernel.org (Postfix) with ESMTPS id 5DB7BB81CD3; Thu, 13 Oct 2022 00:24:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38E12C433B5; Thu, 13 Oct 2022 00:24:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665620689; bh=bp9G17ff+AGvKAiisHdp5V9YGOcAbJR9l6FKgPCOQTE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=miOl147YI91PFpgMRCopUrA/Q/1GrzCW9dJ+ig2CBnGeuuVdAXPaMXyAjsR7g+84h z+GvY511gfb+y3wimC3FaWVwEH74F4f6h3hxctHkuuK7lzBLiIoALFHOg6gkRXay79 wEymveSoyiwUE+cCUOKujCtKlmy/ZpBCzUClPAKRdf/y2Rfy5ZPXGLE08GynNRBoeg 1jp8fD82A0XcW5ZY+e942knnj/yjwrZPyQn3p+Qx4Gne4cRME4+pwioiSRkuQRubJu TJ7KuExy0xpIWF3QBk3Mg4UKTVXCLDsMv8uZauwlv9j3gPVj+7b2dOTxYbEy1/snQd Rb1JepQpdJdWQ== 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 5.10 29/33] nvmet-tcp: add bounds check on Transfer Tag Date: Wed, 12 Oct 2022 20:23:28 -0400 Message-Id: <20221013002334.1894749-29-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221013002334.1894749-1-sashal@kernel.org> References: <20221013002334.1894749-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221012_172452_056368_B960AE09 X-CRM114-Status: GOOD ( 13.32 ) X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-nvme" Errors-To: linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.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 e3e35b9bd684..2ddbd4f4f628 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -922,10 +922,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