From nobody Fri Feb 21 19:32:00 2025 Received: from mail-il1-f226.google.com (mail-il1-f226.google.com [209.85.166.226]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C945B1D88D1 for ; Fri, 24 Jan 2025 18:03:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.226 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737741833; cv=none; b=D2y/DE92qTn4cy6aNlOKyTVcWy+bd7aiJY6wxDG7kyTzhGk8UMZIPZVuvTtTEjBSGPtKx5c7fJKgo0SHykWUyntHI0Z83mkX3KS2wmPtxkZ7oz13twoQU3NSidzNd4i77YpT/aYT0s5KZm2dgUcshuu+Oh48fnvw0KwW8Bqz+Zk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737741833; c=relaxed/simple; bh=zeGSCKFaaSI9d7yT+UVkqElBXX7PAwnvTLJEjTdRIJA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=uq+MWNOUDslvowEMGTU6rAExKIEEcbUtz+rz5+pyXhLOd+vccFPwHk3n1zHT/HOhC3rncGyAFBJ8I7tELulqaTfyOmiRCcwDJ5PCazLe0dWOcVx2I+DIfwjzbhRKxNEE4l6c1ZyDNqIt6CebY7dK5J1voqTA+aCGkJKo7ejGOXI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com; spf=fail smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=fhD3U3D5; arc=none smtp.client-ip=209.85.166.226 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=purestorage.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b="fhD3U3D5" Received: by mail-il1-f226.google.com with SMTP id e9e14a558f8ab-3a7e499d7b2so605285ab.0 for ; Fri, 24 Jan 2025 10:03:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1737741831; x=1738346631; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=1XpCNPxx2sS27CmMIsN7upmtK0PeD89d72RGUihyz90=; b=fhD3U3D5ps25oL5pXD9NgrnIU22/xDkrKUhYbxX2QLYCzdFKOBGCAzRTH+GHiTimTD Q4GcPsWciSwHTH5QVWmWAZzHOF7ZMlgUhc56EisA8nEiWRQfOVABVOcqQ27O4hvRTlGO Ss+6IKGIzYVLUcZ7mTgVhaMsUntOPFZ08Y/JK1xrnfU6lZGL74aoss+fD4wued6l3XXU AsF5SRVRjAKcy67AgbQeYnMHvhkQTZC0I0ws3592tAVj2B1ZFS0VbuanuwxnLaMjtYWh QfXMI0wVflsqv+eXNGzKaKL4FbvZWE4XdKy/M4PvZ/lwaN+cZjKfhS8BFDiAxZuW5rHz xg3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737741831; x=1738346631; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1XpCNPxx2sS27CmMIsN7upmtK0PeD89d72RGUihyz90=; b=JERYgAW8+4YyOC6onUjAnvpnP8edNjIoGGFWbCjVhx6hl2E77NeDtkHtSTUMbSF5Xu 0LWETFmvvPUFlfLCLoUZhiLLVdj+NM4wJByfOVRPQCN+3/vcfz93nu5R7UccmFWZJoiG sBv7IDc2yV1RQKki260hPqEdutcw6icp8m+WmgsRPyJD5XgXD7tSxF+QluOnnpRQ7HTF YDqwEkTjT75Fi2BKJKPxAZ3AGzSMWVC6x530RJ3pumP0xJ9l59w3SZCIHOUixs11nPJ0 EhSSlRZOquLQR/fX+zdbBKL8//2sanoFLe+nIExoktnTtpROrOjSMt8NBpAIwV7u19+9 iY9g== X-Forwarded-Encrypted: i=1; AJvYcCXa/Gum2OKYkfmto1kf/T++qfHB3/94Am6PFRclfETtRCeNarVR4htO+R16VXICCD1qpRSA+l7KAQFLCB0=@vger.kernel.org X-Gm-Message-State: AOJu0Yy86i+9aXEyjEIu9BzZCwsOJ3Q/gvHrkz2K4tz8w60BPFAV+8ns a0ZEzTzTU4qzS+3mGy6ejDhF2eqqLflZbGdaoGi3A0EHYWDVuBZ+5VekxLi8AHxw5DNzOEE3toj 7sg7pKzVZcuPXtGb2jPSBD5US6mdndQgbxoy3uq9PBASP4BKq X-Gm-Gg: ASbGnctqlDvfzwzJ0+LHJ4B6RoBurQPeD/bh6Galm3YqE9pIsPeEPW6V8i9/2WRYN4L 7pvVWYMNDvubrKNhN8cYC2Yl4C9UTMnDQM7Ldawq8zrgPh35MIsHb0kX8uHWA+lHk+x7W9KuNmI tJVn3M55bIM/57OkMMAblQ2QwLZQfAa6b/uhedtMF+0wLOzd9oRWJkKJ5la5+aj7BVWG+oxr6Wu lLUPM73vnDUGJDFJSJ6bbrwoqGs/uIfgKBjjrg4KLiHdyQgcENiv0Jo9LWb/tkRGPRCh827eHYu usvJK7x/dI8k X-Google-Smtp-Source: AGHT+IHSFUS/grHJrmDBI0zDHi/JOfF6zLSw3MBeGwRKgw8SBBoWa3SsCeYyO+GBghV7AcvPHhgyrIsvAozB X-Received: by 2002:a05:6e02:160a:b0:3ce:7ac0:64c2 with SMTP id e9e14a558f8ab-3cfb15f3254mr26261215ab.1.1737741830346; Fri, 24 Jan 2025 10:03:50 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([2620:125:9017:12:36:3:5:0]) by smtp-relay.gmail.com with ESMTPS id e9e14a558f8ab-3cfc7529e56sm1290165ab.63.2025.01.24.10.03.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 10:03:50 -0800 (PST) X-Relaying-Domain: purestorage.com Received: from dev-csander.dev.purestorage.com (dev-csander.dev.purestorage.com [10.7.70.37]) by c7-smtp-2023.dev.purestorage.com (Postfix) with ESMTP id A5F393401C3; Fri, 24 Jan 2025 11:03:49 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 9C02EE40B44; Fri, 24 Jan 2025 11:03:49 -0700 (MST) From: Caleb Sander Mateos To: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg Cc: Maurizio Lombardi , Caleb Sander Mateos , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] nvme-tcp: fix connect failure on receiving partial ICResp PDU Date: Fri, 24 Jan 2025 11:03:41 -0700 Message-ID: <20250124180342.1628060-1-csander@purestorage.com> X-Mailer: git-send-email 2.45.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" nvme_tcp_init_connection() attempts to receive an ICResp PDU but only checks that the return value from recvmsg() is non-negative. If the sender closes the TCP connection or sends fewer than 128 bytes, this check will pass even though the full PDU wasn't received. Ensure the full ICResp PDU is received by checking that recvmsg() returns the expected 128 bytes. Additionally set the MSG_WAITALL flag for recvmsg(), as a sender could split the ICResp over multiple TCP frames. Without MSG_WAITALL, recvmsg() could return prematurely with only part of the PDU. Signed-off-by: Caleb Sander Mateos Fixes: 3f2304f8c6d6 ("nvme-tcp: add NVMe over TCP host driver") --- v3: fix return value to indicate error v2: add Fixes tag drivers/nvme/host/tcp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index dc5bbca58c6d..8cd1735772c6 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -1447,15 +1447,17 @@ static int nvme_tcp_init_connection(struct nvme_tcp= _queue *queue) iov.iov_len =3D sizeof(*icresp); if (nvme_tcp_queue_tls(queue)) { msg.msg_control =3D cbuf; msg.msg_controllen =3D sizeof(cbuf); } + msg.msg_flags =3D MSG_WAITALL; ret =3D kernel_recvmsg(queue->sock, &msg, &iov, 1, iov.iov_len, msg.msg_flags); - if (ret < 0) { + if (ret < sizeof(*icresp)) { pr_warn("queue %d: failed to receive icresp, error %d\n", nvme_tcp_queue_id(queue), ret); + ret =3D -ECONNRESET; goto free_icresp; } ret =3D -ENOTCONN; if (nvme_tcp_queue_tls(queue)) { ctype =3D tls_get_record_type(queue->sock->sk, --=20 2.45.2