Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp204927rwi; Wed, 12 Oct 2022 18:42:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6CPfSgq4LaET6AQVGFQgWV3hnB52YNnjbBbpWoC8PAxoyQqIP4qgfVbhhC9LMpFaEjyAil X-Received: by 2002:aa7:cad5:0:b0:454:88dc:2c22 with SMTP id l21-20020aa7cad5000000b0045488dc2c22mr30243384edt.352.1665625361851; Wed, 12 Oct 2022 18:42:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665625361; cv=none; d=google.com; s=arc-20160816; b=jdYt2e1QvUOlj26tZTEu4Mu1v29SnwOzuc39qL/Oln49ToQrWb5L5Brx9mxCGy14Ir O1gkUfAQS93une030wWrDmjYoyTxBORTNaHok1TV4Eui4RaQ56+7FS6Vi7O4QkUa0rM/ mGA/KKTAyfdy5Vlxy97lg6jScKP55BTRSXRbwy/hjsdiILPe2EgNPU2Dq1jl3nXT6EPG 8VwoxTp86hbobQbWkGrXzeXnf6FSomClKYqzy8iMI2DR5sAsmQoW9xy0bIFO765qBJH3 vYTiZmUbZnS4waA4twPZPLFolbQ/DoyRrirULxrvUYNWxPBcyIIpmDo2i2MTcfHM7IYb MO0Q== 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=BMMIRGmMxLAr2rFGaqrgJiyfdU/BDDW4K7szMeY6Kcc=; b=Yvb6/Cc63maEhAnQEX5Vqsneb3DtZE6afI+R0Y+yjnbVdc47iDrt/OFF1pXKXejXgo a0FlTiWxXbQU3TtqiCev/Dl1erJNWh/kUB2xFmoAAGQoaEgcipkC36KIl52ADq8rwbpm rgDVbY/3Cm3Z1HPZgAk6jjTkc8e0gb5xL5bKFytbIdD8qwoX2gcUAGanrcdXjPV+roOh 3J+FtOd9fPeydR479Jc1Jw4OKb3GNJ25metVGbgbxgf2jtLZYY4VuyCnTWGIjS1PIzj8 OQPalA/XPFhN/dqUlic7nRD7llRua9dJhHfFX92+DMkSRl0iocisz3fQRZBRx3qwWr53 xACw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AkMpCmfh; 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 o2-20020a056402444200b00445f660de5asi1071946edb.141.2022.10.12.18.42.16; Wed, 12 Oct 2022 18:42:41 -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=AkMpCmfh; 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 S232341AbiJMBCb (ORCPT + 99 others); Wed, 12 Oct 2022 21:02:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230307AbiJMBCB (ORCPT ); Wed, 12 Oct 2022 21:02:01 -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 EFA483342B; Wed, 12 Oct 2022 17:59:09 -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 D4AA4616E1; Thu, 13 Oct 2022 00:23:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D298C433D6; Thu, 13 Oct 2022 00:23:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665620597; bh=z6CmzjKVk4PY69fRH9ipg6espvL9nETdxiwJhXO51/A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AkMpCmfh2ZJInJsmU+6FQ+/MBB97yUgfv12hWOIaN2IDSmaIc5V4PECoYwTq589mV nKjyijsnNFC2Kc1XBAV1ebCQNfUDHdfamKxE8y+HbwojNhNYxM6NAOS0qF4Lo655ec WC7m+Mungbk79JgPAkqVC9UrvZYqYqGJNPAO0RNylUukNNi1B3aIFiqjmydTNpYTc2 1548Ct8dIk31EYAtRHEcTv6e++O4UTrGjQQJYHpYDIdUf/yUcSiSCfdWRD2sgoXCz2 QTGwdxnqFr+Q+BB1xi2HcgV0wAmJ5vWo8qkZZk8odYNXELferHmm4zGMZKqHpkqHWZ Th+DBJsQ0r5ZA== 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.15 42/47] nvmet-tcp: add bounds check on Transfer Tag Date: Wed, 12 Oct 2022 20:21:17 -0400 Message-Id: <20221013002124.1894077-42-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221013002124.1894077-1-sashal@kernel.org> References: <20221013002124.1894077-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 fba5a77c58d6..2add26637c87 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -934,10 +934,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