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 2BD94C54EE9 for ; Tue, 20 Sep 2022 18:09:57 +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: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:In-Reply-To:References:List-Owner; bh=g8vQX0TOmlWz8KQOEUN5HNKluOhcRAaDnUCpUlNFrMs=; b=kcllcmowBbSIWzdhSXRZnYg1kn ve+UPfTQs3KeKTtPAPJw9Pyb3JiXvV4PrdsCxeiJr7dt8n45yQ9gRc4UC/u89Je06XXQgKK9ok9QB IqNiotfUL0Iwx74ghBO1wcQ+kMSrQU1nH/8oFwZ0tHvuZFTDrpbdY4hmtxgO0ifT5eT+PpIe50tIG XvFNM3ooefy/KrRx99TK+gvxYHFKkFmWzrvRzXuVa979uqqWsfW9MP4sQVccGiKDGWwZYPJNIyf1N /JxcZPp87VidF7IEeNqixZpft3mcVN3e7cQRxeSbCZFeP2Qn+ePLN2nelAyYt4Xl58R5m8ZhuJP8X 8orxDPqQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oahgv-005e4d-D5; Tue, 20 Sep 2022 18:09:53 +0000 Received: from stargate.chelsio.com ([12.32.117.8]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oahgs-005e3E-M1 for linux-nvme@lists.infradead.org; Tue, 20 Sep 2022 18:09:52 +0000 Received: from fcoe-test11.blr.asicdesigners.com (fcoe-test11.blr.asicdesigners.com [10.193.185.180]) by stargate.chelsio.com (8.14.7/8.14.7) with ESMTP id 28KI9dOe032403; Tue, 20 Sep 2022 11:09:40 -0700 From: Varun Prakash To: sagi@grimberg.me, hch@lst.de Cc: linux-nvme@lists.infradead.org, varun@chelsio.com Subject: [PATCH RESEND] nvmet-tcp: add bound check on Transfer Tag Date: Wed, 21 Sep 2022 00:06:49 +0530 Message-Id: <20220920183649.5177-1-varun@chelsio.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220920_110950_776121_22074E85 X-CRM114-Status: GOOD ( 10.57 ) 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 ttag is used as an index to get cmd in nvmet_tcp_handle_h2c_data_pdu(), add a bound check to avoid out-of-bounds access. Signed-off-by: Varun Prakash --- 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 02df2fc7dfe7..6729c384f2bb 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.31.1