From nobody Thu Jan 30 17:35:18 2025 Received: from mail-pl1-f227.google.com (mail-pl1-f227.google.com [209.85.214.227]) (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 AC170223328 for ; Fri, 24 Jan 2025 18:43:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.227 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737744233; cv=none; b=Hwmxge/peW/ziDo3NA5yiFKtBwo05FRDVu6GcTqgafMzdFlpMCqp6Td/U2KrExY86NydK1tpUU+xfrl8qUmOWdToHWucllT2izpoiy1JKP9gfofD7j/xYCM18VMgt5x7hJBr3Qm7e07bT4fbiW0is+ZVKVaeqeFQysTWfkQjtqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737744233; c=relaxed/simple; bh=VDWyJsC2Nyss+XscbGjEZV2sFKEYPy+Is7O7NSIxQcE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=F3iEmeM6YLgHBv+3xVFESGYYqM2XzcNU1lXfX+kySiwzrurLPF1+FGMGffDx8E2UfrYIl67uQ94TGoc64Ftvc5i6Hh8VgWYkX/PiwkD4Lm3kmUAQ87NEa9qRUpPjOuSD2Xyke2U50YmgJYTd7fQvuNTKmTSOFwI5mbdqimLouyY= 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=T7n3hB+n; arc=none smtp.client-ip=209.85.214.227 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="T7n3hB+n" Received: by mail-pl1-f227.google.com with SMTP id d9443c01a7336-21634417587so5673295ad.3 for ; Fri, 24 Jan 2025 10:43:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1737744231; x=1738349031; 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=YEtlMU2LVA4ZfmH2lP33mJI86LNP9DhvLnmv4lopNA4=; b=T7n3hB+nsMA5YMZEwjzSFY4kTGk8Jjhfy2a4bx8EFiIF2bXfYu5kfoFq+zD8d+gRDo vSpqeFbjPmX0DJY+h0KrCcmx0K3Kzj7qsJX/dU6PNIdWlYR1wScYvRX60XEqurbcHtjK V+JgWnxBJHCg3POfkhZmPAz16wVNQowiAezgZdf6P53FAMNcxIKokEHcRjk6JSZLSDqY WDorkZF+GtKkI8vMWqlyrWizZgdhxFlltcpReCskkpXusnQL2s1wBDpsGZGuS5DJa+IO iyEqarvLrl/nehbUCq/dWCN7LNMCVIAER24NLCI83vMyqRLZKhK680ZTviOK8xWDGmA8 VDRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737744231; x=1738349031; 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=YEtlMU2LVA4ZfmH2lP33mJI86LNP9DhvLnmv4lopNA4=; b=U7MkjlP5KKxNv8friJWRki59RFAwsqJAe5XbsbukgbvMbkdIqcW8ddobQ+AtO8uxu8 8pza15wdVGxsYAssD2K5rzfmzQFlp2m7eDjg99vSHbKAYMlxiad/PKttBP+RMF07IJfn QNcoF1B8Ro9uhqKYIED3+UOh9Vk1wxXBrCmGvKQWJpOsanlwIOEZDvytfZzgrD6SaGUr +JULyR9VexQMK143g/iU8xoH3iZt7vYC1zv+GBvWVkd/youbZLPqsrvwkSvoTf5/G/y/ nPWnWYUQt9KmkadHgu8DJ9Z7FwscqVt00qm8BTyBOqG5lT+IOe9rZBFdv6MFnitxYZjZ eFpg== X-Forwarded-Encrypted: i=1; AJvYcCVrQHAH4NNUfah+IaQhKB0h15Q5YrMw3suNiXtn9DG7N3e3xR1Fxv6Ku0wVP9tMlEQsRiwKl1kKsSjLwzQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyyzX3lmLjouqutquUFAnb8jXyI8oM7Ly670hCwmuvtB7usTRKw XPyrZgQnEKYoEtyCpfnZJwR/QHuW9T0cSlzpgcic5mmqziwNYWE2Q++y68M6fxKf8uD/XcWvJUr UrwA9NHc36cYpxaw85g33UcF5M+RZemS7Lki+Avov00xBnO1r X-Gm-Gg: ASbGnctYd80z3LAi4ysCZwkKefF+k/8EH7wD7ZIlDkaY4Ze0NsGkS84lIVbbtmxv7sH Ca9tiDXglxZE5ilPLDcOnOsdqNfDSUh7mFI4eqkXwszej2vsXrFVbCHSL0xfVxFUVDdv9Aav1/o ueoZzRr4lg/4Z3FD7KAhoRkqzoBjyrbEvdFzpu/3JMXEQYkZ1m8Zt5NbO7V8QPn3XrdBK+NLLI6 RsnkC+1GglhGb7W3jV/JneZ3tiZmwvquEMZM+yvWpAIxFj9kVZMuNc6ekqGcCYKUTfnBbgsHkun mlKJ+nKFWdkI X-Google-Smtp-Source: AGHT+IE1qFlx4fc9QJayOTXsUhZ9jV8XdHUSzKo0DrxG505CrhSSM8S84FMdGkAQnA4S19wF+OQyiQN4dZ4C X-Received: by 2002:a17:902:d4c3:b0:21b:d105:26ca with SMTP id d9443c01a7336-21c35560010mr179634065ad.4.1737744230854; Fri, 24 Jan 2025 10:43: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 d9443c01a7336-21da3ea1e27sm991625ad.34.2025.01.24.10.43.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 10:43: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 2C7633401C3; Fri, 24 Jan 2025 11:43:50 -0700 (MST) Received: by dev-csander.dev.purestorage.com (Postfix, from userid 1557716354) id 33E75E41077; Fri, 24 Jan 2025 11:43:20 -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 v4] nvme-tcp: fix connect failure on receiving partial ICResp PDU Date: Fri, 24 Jan 2025 11:43:10 -0700 Message-ID: <20250124184311.1642797-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") Reviewed-by: Sagi Grimberg --- v4: keep recvmsg() error return value v3: fix return value to indicate error v2: add Fixes tag drivers/nvme/host/tcp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index e9ff6babc540..56679eb8c0d6 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -1446,15 +1446,18 @@ 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); + if (ret >=3D 0) + 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