Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2827534pxb; Mon, 1 Nov 2021 02:39:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJaBCvuBdksCUQ0G3GohothqY3/I6ZQ7JyoCR3z3VLgMcm1wH4pKJE6zaF8MUBhP0eHP+f X-Received: by 2002:a05:6402:5190:: with SMTP id q16mr1028205edd.12.1635759568156; Mon, 01 Nov 2021 02:39:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635759568; cv=none; d=google.com; s=arc-20160816; b=nPcuSXSdnfIDHtRAUbyET5UYcT8jY1PbdiF/T6q35G8IXMDilW2A6dj7xtzhHRvqQv MiCqkxUZedPru3TPUdWDYKKt6kcfJUrOG3VMp4ZRAAFBbL+yx+jRPVW6PQn4VZff/ion RuJrhGJ095WzfKNpTSsjWNOOoRdP6t28s3iyLK50UWsIp+DCKpsCR+3VTjDzCw8YkarI I6juk798AoyULjTZJ9JTBf9mjeQ/qrH67tXdo1oWaA6dKGIqNY8PvHaggQ9R14OLp3WX q6DYPfuXAgUi2oh9ygsGPTddPv7TJ0xk7aTHtNjAj6gt8URo1kD2vzY78E4bgj+0XktZ FaMg== 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=jyIDHRyK62tr+kre/7jXYsgQ7hN8FCsU8h9fMalh6fs=; b=XkCZjOz85QW0dKQ8YOYTSiLdYy73UBtbxcg5SNug/wfcnTe+S2OyuHOLfrDah6Hbfm 5+R7L8ye1bnVylYRDTwGazwXwYkf88os0VWW7mHoszWgZn0lqSNMsTMeYiYPyTqN+zDw R5IjnKieb9GUSqMZ7DA9ji25SUyqCWK+sU7VM3KWLRFh/IiEysxlEC55XuTkWZ1nvV3U if1YrJMfonNfmHtibzz53+V8WaNNPc1PA+SpMOQ5Vj5YYxVjLo3oOzB5qyOkCkEbC+wX qFV22gIdrgfnqhNtB5XwuJdEmmhhdqFh2qWsoWwualM64up9MXlh/GmOsQVIv8lyon0s UsGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1Tp55feM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hq4si26090695ejc.66.2021.11.01.02.39.04; Mon, 01 Nov 2021 02:39:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1Tp55feM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S233291AbhKAJiD (ORCPT + 99 others); Mon, 1 Nov 2021 05:38:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:43566 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232958AbhKAJfp (ORCPT ); Mon, 1 Nov 2021 05:35:45 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B93E161165; Mon, 1 Nov 2021 09:25:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1635758749; bh=oP70mvvBFpm42lYoA/4Wu789MTu/AJSU+1ote24pc8g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1Tp55feM08uiZBjyuwyasQuaYAXw3eyhScY87Jm4+8v+tcfwghpvD6cX+tzP6B7b7 qbBiLFGzxPgK25mP53XHDRr4maDj9PnrmNJ7tsrKha//By9toYo95En9uwY3ukoIiS D5pQWfzkPAWE8Ud1RNMtekQhqddsWr+GplVuPfcg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Varun Prakash , Keith Busch , Sagi Grimberg , Christoph Hellwig Subject: [PATCH 5.10 43/77] nvme-tcp: fix possible req->offset corruption Date: Mon, 1 Nov 2021 10:17:31 +0100 Message-Id: <20211101082520.940326703@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211101082511.254155853@linuxfoundation.org> References: <20211101082511.254155853@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Varun Prakash commit ce7723e9cdae4eb3030da082876580f4b2dc0861 upstream. With commit db5ad6b7f8cd ("nvme-tcp: try to send request in queue_rq context") r2t and response PDU can get processed while send function is executing. Current data digest send code uses req->offset after kernel_sendmsg(), this creates a race condition where req->offset gets reset before it is used in send function. This can happen in two cases - 1. Target sends r2t PDU which resets req->offset. 2. Target send response PDU which completes the req and then req is used for a new command, nvme_tcp_setup_cmd_pdu() resets req->offset. Fix this by storing req->offset in a local variable and using this local variable after kernel_sendmsg(). Fixes: db5ad6b7f8cd ("nvme-tcp: try to send request in queue_rq context") Signed-off-by: Varun Prakash Reviewed-by: Keith Busch Reviewed-by: Sagi Grimberg Signed-off-by: Christoph Hellwig Signed-off-by: Greg Kroah-Hartman --- drivers/nvme/host/tcp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -1037,6 +1037,7 @@ static int nvme_tcp_try_send_data_pdu(st static int nvme_tcp_try_send_ddgst(struct nvme_tcp_request *req) { struct nvme_tcp_queue *queue = req->queue; + size_t offset = req->offset; int ret; struct msghdr msg = { .msg_flags = MSG_DONTWAIT }; struct kvec iov = { @@ -1053,7 +1054,7 @@ static int nvme_tcp_try_send_ddgst(struc if (unlikely(ret <= 0)) return ret; - if (req->offset + ret == NVME_TCP_DIGEST_LENGTH) { + if (offset + ret == NVME_TCP_DIGEST_LENGTH) { nvme_tcp_done_send_req(queue); return 1; }