From patchwork Mon Oct 24 11:32:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9227 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp460880wru; Mon, 24 Oct 2022 06:42:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7qoOqGtdFtOlKKlGjIXsfm2Bj/LlKLILk3jAs1oS8KPIjr6SRlzfMCdG6HRf6H8e/LjnqC X-Received: by 2002:a50:fd94:0:b0:461:5131:d3c with SMTP id o20-20020a50fd94000000b0046151310d3cmr15215742edt.112.1666618959346; Mon, 24 Oct 2022 06:42:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666618959; cv=none; d=google.com; s=arc-20160816; b=VDHRwZ/VYVMZwExSR2m5woiXLIYi2TYa0tFwbGHGdi4MR46i5Twj/dBSIfjuR2/iaS YpmaJH3ViQr9Ukxu/qyLEvHKBKAtOpJJh7+6YMcwZquTdXPXuJrBxKCD2T/aRCjoCt6F c4/KITIGyRB38Zcjg3yvYgiyqcionN0UW4eOF1f62z3cunXA1fwEXMXZXxIMjG9iDYcG /UHsNcQSB2OWRJC1cr4/abDpcjtj2gP2BHf3rgMfJyo2dZ0zx8kyrBetZ0Dc83L8y7nU DVVbKXONFtki+89cy4uA0/X8hMnvZf0TpQ2noeXVz/TaBYncfCc8BIp8mq41OcECoAlG q6fQ== 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=bq42xQuaRM/uafj7pRTh8fSHm914PHX5xMxZKSqSO7g=; b=jjgwIzEuHMrQyPbCglpRFiK4T5XWU37RLx8oImNuHiprkQulnX7ysaT2UD4MgQG/Ru tbJCZvBj5CLXqE783cvMftVgOQ1lvgh7VklVWDxHJ6OU7eki7+RXUNnJF8KTkY1iUuHs BvVsEr5pAUJ7q1a2TGmdjcBTCSIryfgL74xTsaOjb0XWsoThrB5NZuU+Xc6X36lwZr9t jyXE9ObgYwJ8P3sP7aZ/0Hf8DslGvNnuDdW0k8JJFba9Ih9KUoE1GLwisdlPDpwnYXh+ CE1bqVg48BaSYLPOEArLGS7aoXeJ4QzkG0MXl5Bxv5RTghOfLWHYKmcniZgawmjUU08p Xutg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DwbxD2FD; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f11-20020a0564021e8b00b0045ca1098d05si33173908edf.349.2022.10.24.06.42.06; Mon, 24 Oct 2022 06:42:39 -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=DwbxD2FD; 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 S232834AbiJXNc3 (ORCPT + 99 others); Mon, 24 Oct 2022 09:32:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235993AbiJXN3T (ORCPT ); Mon, 24 Oct 2022 09:29:19 -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 84DB3ABF00; Mon, 24 Oct 2022 05:32:24 -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 D331E612DB; Mon, 24 Oct 2022 12:32:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E999BC433C1; Mon, 24 Oct 2022 12:32:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614733; bh=bp9G17ff+AGvKAiisHdp5V9YGOcAbJR9l6FKgPCOQTE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DwbxD2FDKCxgTzEgm19pFxQ1I9bT66ANHUt4/mURIa/9gcybpXWOC95Yaqz/czU8j vyu5POJVGgLjARDQLW07SYei9OyuDh0PUmeD7VDT0YTyGi5Tz7MdDPwH0laFA8nDzC ns0+3J8sn2vYwwm/wCN7l6Xq6I1azuWw7TWN2Yhg= 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 5.10 373/390] nvmet-tcp: add bounds check on Transfer Tag Date: Mon, 24 Oct 2022 13:32:50 +0200 Message-Id: <20221024113038.902327612@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747576641722750943?= X-GMAIL-MSGID: =?utf-8?q?1747576641722750943?= 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",