From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7AA8F5237AD for ; Wed, 9 Sep 2026 10:50:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788951002; cv=none; b=igZKU1km/kIUUb5loiLb8+bP0Bv/nfXuVPVc9Bz0r54A5bL1zTUN6tg3qMBkh6hfx9vGsjTXAlNOQvB7avn1Ve0Prhb3I8+3uE7mO2OVHRclocGmiB0chxs9VRb5F6uLJWOc6Z6XmMziVsXAxqGvDRM0o3WrlHxgjEmP0u997LE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788951002; c=relaxed/simple; bh=Z7B7rLdfi6TUVSQ7G5k/3RcPsmxG8GSbto6C4bqLXSk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I/am+n8pYc07tgS63DqcWItgEm4Ji+OPImFZeJYVGVAI3BcHjgm8LVFEN9MsevjdwzK+XUVJjbtFevO6j6KUiI7PHVg17h5DAEDkKLzRdb/NowGUcOnb0SWBbQ27FuHA964njIYXW5Pydbrh2RJtyTitfq2Y6pMXPBmzg3O4wf8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Eq762dMP; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Eq762dMP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9273E1F00AC4; Wed, 9 Sep 2026 10:49:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788951000; bh=GJTihwOzaLuDO/baQDUhsUzwsUoQqkHRRs+yWuXpmps=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Eq762dMPyyLLxy99cTrf/QXMIpugODNpAwL06tXFTGYoA1AYM3qoYZnb8J9iCg7ya R2ZVJsU+2foRUgvarJGrEPs9N8t97w5AJ3ZQ+Cu9hbigYOvHaUfNx1kaNpGTwu3m4x oIXQmeJ0Nc2Q4CZ0bHCIrYWCpKq2wYOynebgN5T8lcP3OkLDpqywVd2ii3HUSpS0C8 j6MkVXURV4bWUoUGv4xFIHWdbcpPtGshQOugXGik9TeJfiIfdiRoD21VbFKXZeGlFi 9Zi8vrFwS+i9LuR8eCH16s9G5UcRb+OuehHMiGqrqkypMiBOoe51tpbjTEHsj0wfF3 I/BHO8Ahebngw== From: Sasha Levin To: stable@vger.kernel.org Cc: Yehyeong Lee , Keith Busch , Sasha Levin Subject: [PATCH 5.10.y 2/2] nvme-tcp: reject a read that transferred too few bytes Date: Wed, 9 Sep 2026 06:49:57 -0400 Message-ID: <20260909104957.1579361-2-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260909104957.1579361-1-sashal@kernel.org> References: <2026090316-lying-divisive-d066@gregkh> <20260909104957.1579361-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Yehyeong Lee [ Upstream commit 7fa3f73f6c8ddc5f0425b50fb2a626a782ef7d12 ] nvme_tcp_recv_data() completes a request once the current C2HData PDU has been consumed. Nothing compares the total bytes received against the length the command asked for: struct nvme_tcp_request has no receive-side counter, queue->data_remaining is per queue, and blk_mq_end_request() completes for blk_rq_bytes(rq) unconditionally with no residual concept anywhere above. A controller can therefore answer a 4096-byte read with 512 bytes and have it reported as a complete read; user space then gets 4096 bytes of which 3584 are whatever was already in the page. I reproduced that with a test target. Count the bytes received and refuse to complete a successful read whose count does not match, at the two NVME_TCP_F_DATA_SUCCESS paths and in nvme_tcp_process_nvme_cqe(). The success test shifts req->status right by one, because the driver keeps the wire value there and shifts it on completion, so the check must see what the completion path will see. Only REQ_OP_READ is checked, because there the length comes from the sectors the request covers; a passthrough command is built by its submitter, which picks both command and buffer, so the kernel has nothing to compare against. Fixes: 3f2304f8c6d6 ("nvme-tcp: add NVMe over TCP host driver") Cc: stable@vger.kernel.org Signed-off-by: Yehyeong Lee Signed-off-by: Keith Busch Signed-off-by: Sasha Levin --- drivers/nvme/host/tcp.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index 7e25bfa001c59..225ebcceab958 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -90,6 +90,7 @@ struct nvme_tcp_request { struct bio *curr_bio; struct iov_iter iter; + u32 data_recvd; /* send state */ size_t offset; @@ -522,6 +523,29 @@ static void nvme_tcp_error_recovery(struct nvme_ctrl *ctrl) queue_work(nvme_reset_wq, &to_tcp_ctrl(ctrl)->err_work); } +/* + * NVMe has no short read: a read that completes successfully must + * have transferred everything it asked for. + */ +static bool nvme_tcp_data_in_short(struct nvme_tcp_queue *queue, + struct request *rq) +{ + struct nvme_tcp_request *req = blk_mq_rq_to_pdu(rq); + + if (le16_to_cpu(req->status) >> 1) + return false; + if (req_op(rq) != REQ_OP_READ || !req->data_len) + return false; + if (likely(req->data_recvd == req->data_len)) + return false; + + dev_err(queue->ctrl->ctrl.device, + "queue %d tag %#x short data-in: got %u of %u\n", + nvme_tcp_queue_id(queue), rq->tag, + req->data_recvd, req->data_len); + return true; +} + static int nvme_tcp_process_nvme_cqe(struct nvme_tcp_queue *queue, struct nvme_completion *cqe) { @@ -541,6 +565,9 @@ static int nvme_tcp_process_nvme_cqe(struct nvme_tcp_queue *queue, if (req->status == cpu_to_le16(NVME_SC_SUCCESS)) req->status = cqe->status; + if (unlikely(nvme_tcp_data_in_short(queue, rq))) + return -EPROTO; + if (!nvme_try_complete_req(rq, req->status, cqe->result)) nvme_complete_rq(rq); queue->nr_cqe++; @@ -795,6 +822,7 @@ static int nvme_tcp_recv_data(struct nvme_tcp_queue *queue, struct sk_buff *skb, *len -= recv_len; *offset += recv_len; queue->data_remaining -= recv_len; + req->data_recvd += recv_len; } if (!queue->data_remaining) { @@ -803,6 +831,8 @@ static int nvme_tcp_recv_data(struct nvme_tcp_queue *queue, struct sk_buff *skb, queue->ddgst_remaining = NVME_TCP_DIGEST_LENGTH; } else { if (pdu->hdr.flags & NVME_TCP_F_DATA_SUCCESS) { + if (unlikely(nvme_tcp_data_in_short(queue, rq))) + return -EPROTO; nvme_tcp_end_request(rq, le16_to_cpu(req->status)); queue->nr_cqe++; @@ -851,6 +881,9 @@ static int nvme_tcp_recv_ddgst(struct nvme_tcp_queue *queue, pdu->command_id); struct nvme_tcp_request *req = blk_mq_rq_to_pdu(rq); + if (unlikely(nvme_tcp_data_in_short(queue, rq))) + return -EPROTO; + nvme_tcp_end_request(rq, le16_to_cpu(req->status)); queue->nr_cqe++; } @@ -2386,6 +2419,7 @@ static blk_status_t nvme_tcp_setup_cmd_pdu(struct nvme_ns *ns, req->status = cpu_to_le16(NVME_SC_SUCCESS); req->offset = 0; req->data_sent = 0; + req->data_recvd = 0; req->pdu_len = 0; req->pdu_sent = 0; req->data_len = blk_rq_nr_phys_segments(rq) ? -- 2.53.0