From patchwork Mon Oct 24 11:32:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9083 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp445616wru; Mon, 24 Oct 2022 06:12:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5tD6R1ldoz5oStDO41QEZJtjoWZG7F0IUniWiRPAgkEzQAeIOZrPkg6cvMVdzvoJaPN2zz X-Received: by 2002:a17:903:283:b0:186:897e:71ea with SMTP id j3-20020a170903028300b00186897e71eamr12357451plr.123.1666617172878; Mon, 24 Oct 2022 06:12:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666617172; cv=none; d=google.com; s=arc-20160816; b=vATVfCjxJuME4EyFwwE85r0uCfR/1YFpyoB9FdkdhzU0V95lYSIQLaVYMXZQNkjuwq i6cey7D04y91pm/BnykJXcFLD/0MVQIu8o4+2N0VZHURjtt5hsTdry4DvvmGMzb9/rxR qFS/mjNfVrNOZTbYByGpS9Tk6ysy+VqLj2vK3R6+RKhXM8h7PNQQvgrMCVyBJloOqT9w gmlRi7+pMHok4jCJ5Bj7pQu0QMXYUUsnACIj10LbDCgbdLaCNDIMWxYum0W4A36YV6xv MensAq9h4TxPEu53wWQEx5bkmCEQSry/5W26luegbbhssSmtgCRR6y5gatF1XuwqfG8+ g6Og== 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=7DxRvWtqyC9FvWnrNSveKfbAvdAYOxjGUjBJR53R608=; b=ScMMs5f5KWtj1gEKQ5GLGg7QTG6mdetW8rzKN8ERTDdKLCrVgWIogMVr8+XuVEgJRG OhW8iyXtAEOnUFKvkaGBmG6yECEbzkTFKY2U8nUHzPZ3nTzhAFDp3YtDS4qyuUYKwlah g338XcmPDWiRiPSIVsPPEqP9znU68al6wD3yIi1nTnAz3Ib6hgmusjn4daWbkyZ2vekl 78+jHtCVtQHbz+s+oKtxAwDbz1DtBy1AvDdMeZvu9YNfKvMexIkoRkh0IMkyAPnA6Id2 9yKOQ75HYSJoRdaJNRSLu27IwrSNRE7mNSTLzEYcupsfTOZz1YTsR/6Wdd+OFKyzHCmA Vviw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=t3NEMBF5; 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 t8-20020a170902e84800b0017f863024acsi38949856plg.235.2022.10.24.06.12.37; Mon, 24 Oct 2022 06:12:52 -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=t3NEMBF5; 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 S235689AbiJXNMS (ORCPT + 99 others); Mon, 24 Oct 2022 09:12:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235919AbiJXNKL (ORCPT ); Mon, 24 Oct 2022 09:10:11 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BB02A47B; Mon, 24 Oct 2022 05:23:31 -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 ams.source.kernel.org (Postfix) with ESMTPS id 09187B8161F; Mon, 24 Oct 2022 12:15:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63EEBC433D6; Mon, 24 Oct 2022 12:15:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613718; bh=j+67didnIPF+xzyve6MvUXmjz4nmKeBUiydpiwCnhUs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t3NEMBF57gAnl8lTkIIuLnagX7B+NrVvvzb6f/Jtn50jpCVRsu6KsYCxSFCcBSlZE TOEJPRMR6X458sRJwr2az39/r/YLePwraEdizw51kUoQQHRgh1hti1VryqsSdTSBMc 1/qUVRYcmK6/BCXkLKa1q7392Wyg0++/Urt25BnM= 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.4 243/255] nvmet-tcp: add bounds check on Transfer Tag Date: Mon, 24 Oct 2022 13:32:33 +0200 Message-Id: <20221024113011.330767504@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@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?1747574768462731520?= X-GMAIL-MSGID: =?utf-8?q?1747574768462731520?= 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 eb5b39c2bba8..df7a911d303f 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -858,10 +858,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",