Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp826538rwi; Wed, 19 Oct 2022 03:32:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM62eiZurgiaBvoHVzVqAh9D/ExFVqr9cBsSM3gAy5/bYVMMtcoinYaXI3k+OZv4N+X/gNdL X-Received: by 2002:a17:907:7e90:b0:78d:50f7:8abd with SMTP id qb16-20020a1709077e9000b0078d50f78abdmr5942265ejc.523.1666175451092; Wed, 19 Oct 2022 03:30:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666175451; cv=none; d=google.com; s=arc-20160816; b=GsbAFzt4sOhtKpbUuXizi89Y5FBgA0ieIUsfXB/RT99ClLCyHNix5wWv6clWBYrt6R EG2v8syyJDF7lGPcUYmlxrmE9hi4k1kdAduwmAocdxMMzLCwZNlII+gmoCuDG/SlgkgG gvQG09NrdEfHmrUl2mm838Tu2FqLtq5cQGpC67OxeiTyw3DPuaZ4oYZ0m/5Z269C4UqH owgXK8HNHkP8Sgcv3filFL2FFlk8aYL4a2uBxOz8IJuSqBYoI2pR976kUOtEnCeD4elW hEjMCLf6Pkw5oUr61N1CH9gZLHgSqmE35OKgn0PzBU8uZHWDddY92dLr6YqQeLiL1EGl C1qw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+2rjujWWhfgfG5tiQA0YDLR0d/ewQAf1OGHqtKrMnW4=; b=YxRUyYu/I3XEaryaINsnLGwVY2NTG35sUYo2U3StcV1mUm560kkk//5CXbhXEhH0N5 HZCtutFE/bFbOwE2OGLqW/mGclbvinILz/FN9WqFLXbxSvkiDoixprUICq/weg4wekj+ I1oofliJY2/7WNgh9+AFKB/xtm3LDdEEvr3de4hghdxeTejSQwvz+Gbomj40y0IbRzuH jLPSfLAUl7W0/pxDzfK7mdQSZMJWfY37kYxSgRvNQM2UWeuH42CtDqKrfjY/UAwTtyFd BqhRP/N/+c51dSihsLvNeMWnzVR/N7VbL6Vy0ARsuI/qIbbSFhJVtBM7Oh90Acn6v8PQ zD0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aOhI13vO; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eb10-20020a0564020d0a00b004537a3c4982si15974882edb.601.2022.10.19.03.30.22; Wed, 19 Oct 2022 03:30:51 -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=@linuxfoundation.org header.s=korg header.b=aOhI13vO; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234254AbiJSJm7 (ORCPT + 99 others); Wed, 19 Oct 2022 05:42:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234377AbiJSJkS (ORCPT ); Wed, 19 Oct 2022 05:40:18 -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 84748E8C49; Wed, 19 Oct 2022 02:16:26 -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 1C5D7617F4; Wed, 19 Oct 2022 09:15:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 298F7C433C1; Wed, 19 Oct 2022 09:15:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170900; bh=dwDcdLbwsITSd0znTm2jm+ojffy7JRp4bA5tasq8cI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aOhI13vOZ4rtf3CTUG8ErM3fBuZSFIcxLAIwWag2rAmIPMw89BE3ujxF2aHbE0GjF 5OGMGhf1pvBCgS/PS5fAYmKYLZaL8H0I83T7wjkAXX4Q/ry2Cu/2FgIeSXOqs4nQ5e uL0dMc4hXw0pAV1V8t02j5RXUygh0ctPSXCc5vIc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Varun Prakash , Sagi Grimberg , Christoph Hellwig , Sasha Levin Subject: [PATCH 6.0 830/862] nvmet-tcp: add bounds check on Transfer Tag Date: Wed, 19 Oct 2022 10:35:17 +0200 Message-Id: <20221019083326.575072658@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 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