From nobody Thu Jan 30 17:24:45 2025 Received: from mail-oi1-f225.google.com (mail-oi1-f225.google.com [209.85.167.225]) (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 37A2B14A4E1 for ; Thu, 23 Jan 2025 22:50:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.225 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737672609; cv=none; b=aT6hymur56zOeGXUi2sNQv1Wwb0ILSiTvsHyr3lsfK3AXpMsRpfEm2HBNxe1axOw9C4VDs4k/UazpunRPKGmGdDxAo3cjhjiotvQ0Eohhve36PP6vwlfPn+2jx1jExOs1KcslScNY+i+ySrOmiVV+lqW7/kLhMuNDJQE0ugf5dM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737672609; c=relaxed/simple; bh=q05om5R0CXwQIg5+RO3OhDv9AwsoUlRLxl7UGjy0+tQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=RRcolz4FVNOHUf/3XPNhOuxHBwyrgERsd+dMQpCJHAVnLQf50kNZ28a0O7arWx6QPa//dBAifAT7f+sGo4h1y/2YGJHZZlk0L9J3ifoo6rG68dUmTMXsyCu1+XuRrpr0p7p6eZ6+jT/rspNwZwxvCyDgq2ku9fV6dceLEBN5AAA= 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=LcMe34/P; arc=none smtp.client-ip=209.85.167.225 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="LcMe34/P" Received: by mail-oi1-f225.google.com with SMTP id 5614622812f47-3ebc07d3d0cso203754b6e.0 for ; Thu, 23 Jan 2025 14:50:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1737672606; x=1738277406; 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=TYqG72Eb5Ow401LLShh/k1Lu/YVk568nsSQiPQFqa5w=; b=LcMe34/PGTSzF9ggN+2/RJH/UDaa1rx+YBgxLRbdtVY/usLDxnkSf7Zfgc0K2zpe1E 5pEBiaYvnsZdJhuFUl5LS7cbE2+79fZHLrZTI6OQVGgAIE1jzQL0jJQeHWUu2N7wObTY h2DgMg2+0WJnXnGc18NQREcqxNRMzsJNzJvEkQej+eHocpfZzQZ2nEv4PapvHFlE1DLF jiZtNX66NeFUaxjiLGENFHkkhm6dNqSWHKIwMsrTsLbs21T3oq7yYchK6pCDYxXr5W8S c8T3cUhtXwUr52k2mhIXgGiPSpBH7RT/bwRr/3XYnd/wmBuCKEZzd+Xy+B2nkJ3Eqgjp lvlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737672606; x=1738277406; 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=TYqG72Eb5Ow401LLShh/k1Lu/YVk568nsSQiPQFqa5w=; b=oo+LPQ7/FXr23iwO7M3sxAaFgUyT8xEUnhqUvruM94iCeHC5KfyD5dd2KHGQYFvCcv Mw/HY8KhIkjifyg6tKkLZQZCCyMBMsYw1aMyB9UQP1a52jg+L0ZHdakZ1x0tF1ob3pO+ ePZwr8A1Jm3anpAoawhE+GwHGxglgF/P8gP1jdZ400JhlCSo33QxgC89BYHZLdVfoCVS Ioi55Y5NSfuesgHt57Mlj1UpqBntJ3ySZbgmmiBkS0FsJAqAMAXnvugxW8nXHqf3H5bS 4LzWYNWImmQ0PAx6mR7CVrVBA84b9uV6iMwQLuA7i/WTEStCzggrLlsTp3mlN/MQhvMU kbOA== X-Forwarded-Encrypted: i=1; AJvYcCXh3T3759G6yxWcnkxczFGtop11uxVwUfqlT+hWFV6yh/ATIis36PRt9oOVARb/y6NKKukTINwqte3pXmQ=@vger.kernel.org X-Gm-Message-State: AOJu0YynD80fRNQcycbjyiJ1WwSCjCbZ96kJ8SAKsIqFtohbSlPl+VnF 0AQj5SkcRtAl7Onnlp/N2EMg478qIFBOXhzn5sJk3sGina5NkWeciB5b5/diqNePnWqoqvjy/3i DtGZfdSul//fT5Xnrc8JtqBohQ3baB1Dg X-Gm-Gg: ASbGncuKDw/umwN7AEfZNUi2vaEc+zTW5Nk5XMhdT0CZ0W/g16HC9ChqwqUlUDZOG7E eQlwxgdoM5onl45vPe9FqHMyvjECaOW1d6qpX7QDEGTxRXcNCmmfSR9RDBF8q93+cilPApol9dm bpLReeynqiUCaDoepmeQ3FbcDt650ULQ/H1ySRJaFgILp0j4h4ch4Y9JgDz95DBGtAI7WzNCBqs ZljSJDfMm0Bq2XMlLY7LSqOhsA+BRiJAawFFLLYipfG2a9tHX+XCHPFqNg05y8Bll+7Fl+6O+CM IAWzkZhcWaSNjiUDe3J3M2hvEeM= X-Google-Smtp-Source: AGHT+IHpWJkZ+qtt5aMbV6lGk0QNXQn8vS9/dGclooytG0WLIfEst5DC13cDEF1gEAhdsLutrZ06MeYb3UcR X-Received: by 2002:a05:6870:7190:b0:29e:6394:fd47 with SMTP id 586e51a60fabf-2b2518a4b04mr1781964fac.4.1737672606160; Thu, 23 Jan 2025 14:50:06 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.128]) by smtp-relay.gmail.com with ESMTPS id 586e51a60fabf-2b28f187fdasm40892fac.9.2025.01.23.14.50.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 14:50:06 -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 2431F340748; Thu, 23 Jan 2025 15:50:05 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 16F59E4105C; Thu, 23 Jan 2025 15:50:05 -0700 (MST) From: Caleb Sander Mateos To: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg Cc: Caleb Sander Mateos , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] nvme-tcp: fix connect failure on receiving partial ICResp PDU Date: Thu, 23 Jan 2025 15:49:40 -0700 Message-ID: <20250123224941.1359950-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") --- drivers/nvme/host/tcp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index dc5bbca58c6d..d23c6243da5d 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -1447,13 +1447,14 @@ 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); goto free_icresp; } ret =3D -ENOTCONN; --=20 2.45.2