From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-io1-f99.google.com (mail-io1-f99.google.com [209.85.166.99]) (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 B40C915625A for ; Thu, 23 Jan 2025 17:50:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.99 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737654614; cv=none; b=on6k0942ZS8tQ8nRAqBiKsGTPtreTthxhDFUYtwPQTW3EZRmOeBdzUrrRGyH8TPSie/aL7kxvgV5uGpCl+k4lXGH/RUfeoiiiG8YDnRl4dmB+lx8Oqzvg2SMTl0gikl2sQGmV0VpIEjOpA9cZgDao8HtRwkne9e+ZJgqW/RC3Jo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737654614; c=relaxed/simple; bh=dvQY/8wn9lW66Nx+9PQ+c02avmyoH/MF62DagfGXgqE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Av4UNVRSXD1ebNHIbf8bERF79PItLhDudRo0HTrG11jL+XDIPCzTG7ab4dsRoF+58/n8kFmQSVModiQBU/hMonrSY7J34n4s6SzE8DZUWE459TERgaGYKDPwwPhkLxv5dvluAa3Sf8uwT6qQsA1eoJHqFCnDTG6rITW6RKQLF5s= 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=K8xLGbbV; arc=none smtp.client-ip=209.85.166.99 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="K8xLGbbV" Received: by mail-io1-f99.google.com with SMTP id ca18e2360f4ac-844dabda638so4549339f.2 for ; Thu, 23 Jan 2025 09:50:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1737654612; x=1738259412; 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=vkqhkym4WZhQHcqhRX5xEhxIT/Tytg4NVdG2sTTxj3A=; b=K8xLGbbVlRaRhPy02CmVGBESpZCy0FQUJ8xC1Sk8UiaoZdZpmaRMzsyWymW/p3XNl/ t3YgAaYHiTILkLAQoNirHUB6pv5aLRfHrRUsRm2DIeKxDEfOgJKHIpZG1voXv2oWV9e1 hy6W527eo9Yy+EeR2vDzqpPSHh4YfvwlwuuDeRyCE6rGEJQeXBOKlHv8iwqYdWsiDYIA P3TnjBm8+XbJH5a8evFe4ZQDYQfDh88JZNJSbTwxEI4jC92m9YV+3KREKxcOcl/dKOPT TpVE66JN12gtpb+Tc8PyMhUqAidsVstFOOaj+AOaFShZ0CmNl7FP56uCHX6Hy67zx5do xXyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737654612; x=1738259412; 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=vkqhkym4WZhQHcqhRX5xEhxIT/Tytg4NVdG2sTTxj3A=; b=pFrwgISk1R8GZvNynnBnvEg0dwhsFIM5/DUO/ypnwSrdWTX/wHY5KOrC4nqgyXJqO2 L2ItUpXTLl+7LARO5yM32idf4kOErFS3Zln7Ga0I8ffmrDPo4YH+U5lLMkVvjxPiRX8m L2/A+xsKJIqjnkKGFuhRDlGGAW04UHNOQw8BJhtQx6p27Ek5ZspR9Cc8RkgbcPQjPkBs A+NmHdZrD/8h0e2liKp8Zj0kgycFfmDgNqytSnrz+8ZvNOpVVuJYZ/KQrDkVVDX0MBKE X7527v87ewJjkAi99Q/9Wz2O+dae6Ni/PFvugaP+iLwkTizWwZpFb2fS+cxPfvIgdsg6 ZBIA== X-Forwarded-Encrypted: i=1; AJvYcCW4f2naTUVXYd/CXJib7216FFRB2BlfBYx8AK/NNZwPBdcPZU5f1PjfAQ3TNe/fCRk0gX3mSpBcxAjkhIA=@vger.kernel.org X-Gm-Message-State: AOJu0YyVWBnvDeAwRkAm6e+LtW+31T8kCHbwx9HoRsQIVEOUM2y/iXJQ dqEfEGQSSctKyfhBE8uBvzBIXJiPlXhJsjV+Enjxv9LvA/gqqJa5OFPIcgA+hdLpUPp/Eg91vOs Zh6bCORv8JNQ8rZ4p7tGDKQIl37bMWhd4 X-Gm-Gg: ASbGncs/ejsaOHU+EQvWpxPxLYnQy8SVXYEMYnF/FL1CZux8V0qqKW5lKGTCDQBSDx7 52cPyliNrMBxkA/CxEfW6Iy7sIwynwtxC5K2/yJvBI66uJAcbZkVULukgky/TugHcv/+n6D+xWO bgwxajUCUDK2iIoVqNJLhvJJhpO+DhQCEshYiIpriQDpJdBWGQQXvJ86jqkD8yXAc5zV/XRpdJT +nkGqBs4YeLuXYZDOpoVeA+qM510dQJTNwrW785+TGRIZxFwHH2jHbvl0nZniRGqPEG9NKvtXmU MNqPEov+dUhnT0FH3iOUMLIgrKA= X-Google-Smtp-Source: AGHT+IH0w/taoWhrutymqxi/03488RjZxNI4WngpXFVkXtL3ahX1RvTVkPlQ2ayCNX+aeIkYfIEOFqsl+X4m X-Received: by 2002:a05:6e02:3dc8:b0:3ce:6c17:ec5e with SMTP id e9e14a558f8ab-3cfb193faf8mr24874645ab.7.1737654610309; Thu, 23 Jan 2025 09:50:10 -0800 (PST) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.129]) by smtp-relay.gmail.com with ESMTPS id e9e14a558f8ab-3cfc7509e98sm108245ab.56.2025.01.23.09.50.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 09:50:10 -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 A08E334039C; Thu, 23 Jan 2025 10:50:09 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 912EBE41418; Thu, 23 Jan 2025 10:49:39 -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] nvme-tcp: check that full ICResp is received Date: Thu, 23 Jan 2025 10:48:58 -0700 Message-ID: <20250123174905.1252949-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: 8bit 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 --- 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 = sizeof(*icresp); if (nvme_tcp_queue_tls(queue)) { msg.msg_control = cbuf; msg.msg_controllen = sizeof(cbuf); } + msg.msg_flags = MSG_WAITALL; ret = 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 = -ENOTCONN; -- 2.45.2