Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2837672pxb; Mon, 1 Nov 2021 02:55:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhKoicL3gOe5sa7PO0Pyi0JTTwc/h0VAXv3IPvx3xQ71XcmskjQanVY873qpjGG1vtyU/x X-Received: by 2002:a17:906:6a03:: with SMTP id qw3mr36174928ejc.43.1635760517266; Mon, 01 Nov 2021 02:55:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635760517; cv=none; d=google.com; s=arc-20160816; b=wGpfhc5FPxWjwMCwaU1ttCHLPdoUKz4+wuH5XfnYGB39Hpg4MDen4ZD7gvsq0z1dcr 5L+Hrk0DZgZQXTw14AFBoa53TEsLw5fHWgq5dqvoWvvncRri4cZTtG0JF6uM01Hpwk3I QI/ct4G+LNl0y1qxgENEa8SJQitBpbnxRALGVO4Y6+avA5oZGoc3H7KuYx0zcqFWwYLV bjGigPU0jRHBpCvCscT9KilKAlnCWcKCWu/VCGb//vX+vtPAxgPnppBvOJka9MSYG2GM jnQUG3ezWhNtl/9B4xJNk4Taag+VMmW82TyVebuwRH26/4+YgM4m4kET+57X4Sv1O94X DKzg== 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=u/0Crqm0M1rS1DQynRVfYxv8pWILok5MzlQRID2OxFi79GyBI92TdaUQ+x59mvgyfs uGbw8iX5l9MyLdW+XG1k9i/RjZ9Fpm2xVASVJP+L9lzVy1DVK7H+AUVdaaRqUajVxawg RTDgQXDPkrlbDb/2EMYWXb+Yd1hBHSe8FLiLfH9HHadZrT9kt7I+FVlO6iodH6sAjFC5 DjQx0jPR0GBYBwTM35LIkFdQv/AdjiZfD7FAc56kFxvjjt0X5pRJteRjQ5jNtbYZY1Uv jcH5vm9nVsLAI1FYQ4KW3TN7/YbeCO0jCVyH/YjSgGmYegE0jc2/XH2pa+ptsvaorud+ 9Ezg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qoN7BupU; 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 z13si33934016edd.383.2021.11.01.02.54.54; Mon, 01 Nov 2021 02:55:17 -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=qoN7BupU; 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 S234894AbhKAJxS (ORCPT + 99 others); Mon, 1 Nov 2021 05:53:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:51098 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234738AbhKAJss (ORCPT ); Mon, 1 Nov 2021 05:48:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1C37E611CC; Mon, 1 Nov 2021 09:31:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1635759087; bh=oP70mvvBFpm42lYoA/4Wu789MTu/AJSU+1ote24pc8g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qoN7BupUPKKbqvobFGbVjVDjVVXwdF66sfYTemxzy5H1h8yM9wiLpbXfk71zUsgQU bZKqXpHPfQPhpcQWrWGAppFh1tAM9WOBYKvz89wiJHLXVOfk4to3BNfVy6DjLOiLzm apuAMYhT0VbY19jz0myInfLSm1VNi1Bps+80/Sdc= 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.14 067/125] nvme-tcp: fix possible req->offset corruption Date: Mon, 1 Nov 2021 10:17:20 +0100 Message-Id: <20211101082545.833634434@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211101082533.618411490@linuxfoundation.org> References: <20211101082533.618411490@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; }