From patchwork Sat Oct 22 07:29:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7716 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1109614wrr; Sat, 22 Oct 2022 01:49:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5DR47s8Y86f9Z8WF6UyuZr/cz92zfxcykUZCE1elHdD3Ov6rNBtyC40TSFBfrPdrfAu48n X-Received: by 2002:a17:907:7d8e:b0:78d:ed30:643b with SMTP id oz14-20020a1709077d8e00b0078ded30643bmr18783591ejc.253.1666428553827; Sat, 22 Oct 2022 01:49:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666428553; cv=none; d=google.com; s=arc-20160816; b=wDnhTho+cDmIp3EPeirIdPCMNJ480km2WOXUQ25MMHPPwAiXFglI9Sqkz4GT3+L3xB xKSlUolOsN4Bp6iCdW2dAW7afWhpJ/WH8ijs9iNlLyPeLu7fuhE1I3qzlaZ7y+v5XV79 z4VNMNKxczCDQIWL0UrQdgtlic1QdZqI5StxqIBLv8n583EV0iqoHp/ZljPzlqLnep3K oN9NwpIsziohsE+/vlTtA7kHYMdJJivzt0yIwLi673OIgZRzOs9hzVczCicIPAMBGVQO Lxd4OSQ81BpuF20fACfPbwnyFp7J64qreNTcYkSgt2oYBVT6D/VZf0wRxCgJuHhT2Zx+ JTxg== 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=duQ/Ub4xhfgwaxBICN3qN1Zr5XIXW/XLeJaA0NU7oK6NMulqqozy3uPxq9jAqvKIB1 qTa7r2he+2xUWIqRTwuqCPirxD8VfnjIbKjQ1iH4sZsZ10nzjNfmKha6uNOJe+eJ4S8f M63IJkTbUiF3ReD7SelCcgjU9ee5sIi7kfRUTPdYfAR810/sM+mT8uWvD/Cuqlhl1wZe 35Us+fu482MWT9PzUiEBkAKkOpRkMUBR7rH/Ap+aP6THi6c6ZK0xTiEwdrtyK3krGcbS HVs2i5Ez6DpTOv4ebnNnTJj7wOEfldX2g1IqvzbyNfpIhfMuOMd/7gQDa5LuoBGaPmzb iJvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="LY/XsOsE"; 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 t19-20020a056402525300b00458ebf5aee0si25723081edd.344.2022.10.22.01.48.50; Sat, 22 Oct 2022 01:49:13 -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="LY/XsOsE"; 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 S234811AbiJVIsS (ORCPT + 99 others); Sat, 22 Oct 2022 04:48:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235298AbiJVIpK (ORCPT ); Sat, 22 Oct 2022 04:45:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 252BE2ECF79; Sat, 22 Oct 2022 01:09:14 -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 3083860B40; Sat, 22 Oct 2022 08:08:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1F092C433D6; Sat, 22 Oct 2022 08:08:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666426087; bh=dwDcdLbwsITSd0znTm2jm+ojffy7JRp4bA5tasq8cI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LY/XsOsEx8etMhovH+bGMvR8liGgzvKaxkSeDCYBjDo8ha07p/fwwbxGHwFFoxMvr 0gTGj+31GbgoXqQJxc4OyvpPIP9FmFUMaYd8s8cuh1IlrytcR8Zw1itvIL2teKT216 blgfwCPEBhTnpvevS8yc+wONJ0F1IIEnKrQuNFKY= 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.19 687/717] nvmet-tcp: add bounds check on Transfer Tag Date: Sat, 22 Oct 2022 09:29:26 +0200 Message-Id: <20221022072528.879668076@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 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?1747376987311038096?= X-GMAIL-MSGID: =?utf-8?q?1747376987311038096?= 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",