From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 93DD2136988 for ; Mon, 27 Jan 2025 08:09:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737965388; cv=none; b=ZpitoYp7Zok+F4OqVO1uzH801inUHiwciR8djh2E9pyTx5+Bw1Y5+ZfjrqVhMxfCIZpuhJ/VHgcDQfof7/wyS0vlJSH0TWuoVonI0QZ78fM2UTekXyB5Qc+6khgESbMp3eS36TBN2/Jn/dhhxlqJ7sYk2/CmWQd1YAgizMHV4KI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737965388; c=relaxed/simple; bh=t8ILD0Bex861i9gFilRa7oM2zaeZVfACPORglFJaRGk=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=Ky/7Qc5pm1DXdOzbHNd5+/X7Wh0VM8b+RMALHjCtuVsYZwW57g9P5keZ5IX+3wmxFs2+FVKRfGoDAM+AqNhyiCGOFfOushP2PeuBh7RURb7c+deFGRsj+te8wesVv97F5ad7ZTw1uXvaSee0j/o0Qmc56D3ZdclnEiqx328d4CQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=kOGV0enl; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=fXIZMlqP; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=kOGV0enl; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=fXIZMlqP; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="kOGV0enl"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="fXIZMlqP"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="kOGV0enl"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="fXIZMlqP" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id A714921114; Mon, 27 Jan 2025 08:09:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1737965384; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pcJWvty6IsJLPlgXPzoyMqK/3ezLNnrgcU5Soq1Ovy8=; b=kOGV0enlKVmVUCgIHqCx54N6eCEo0IdIK3X5U+we8bySrz1c8/AEt3zscMvlVE32YicB2S cBf52Y6ZizEmCsVZZRdbj7W6liD1cythfJY8CAxgRVP9KMI429hdZ445zBVhgvEDppqgTf SOxLnITO/Y1j+IXA590K+tokygcnfdM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1737965384; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pcJWvty6IsJLPlgXPzoyMqK/3ezLNnrgcU5Soq1Ovy8=; b=fXIZMlqPRDCElrqNnZHmEL0iqUY+Aumm2py+vpKPVxMPbPV75i9Fp8vfuVixlx7504V3/+ ciqZyxABjoXt/KAw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1737965384; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pcJWvty6IsJLPlgXPzoyMqK/3ezLNnrgcU5Soq1Ovy8=; b=kOGV0enlKVmVUCgIHqCx54N6eCEo0IdIK3X5U+we8bySrz1c8/AEt3zscMvlVE32YicB2S cBf52Y6ZizEmCsVZZRdbj7W6liD1cythfJY8CAxgRVP9KMI429hdZ445zBVhgvEDppqgTf SOxLnITO/Y1j+IXA590K+tokygcnfdM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1737965384; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pcJWvty6IsJLPlgXPzoyMqK/3ezLNnrgcU5Soq1Ovy8=; b=fXIZMlqPRDCElrqNnZHmEL0iqUY+Aumm2py+vpKPVxMPbPV75i9Fp8vfuVixlx7504V3/+ ciqZyxABjoXt/KAw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 5E9C613715; Mon, 27 Jan 2025 08:09:44 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id NXhKFUg/l2etewAAD6G6ig (envelope-from ); Mon, 27 Jan 2025 08:09:44 +0000 Message-ID: <80138543-2b15-47bf-9b0a-d959ce79001f@suse.de> Date: Mon, 27 Jan 2025 09:09:43 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4] nvme-tcp: fix connect failure on receiving partial ICResp PDU From: Hannes Reinecke To: Caleb Sander Mateos , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg Cc: Maurizio Lombardi , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org References: <20250124184311.1642797-1-csander@purestorage.com> <9ea74200-7cbc-4a30-9503-864dcec9b45d@suse.de> Content-Language: en-US In-Reply-To: <9ea74200-7cbc-4a30-9503-864dcec9b45d@suse.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Level: X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_SEVEN(0.00)[8]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:mid,purestorage.com:email] X-Spam-Score: -4.30 X-Spam-Flag: NO On 1/27/25 08:37, Hannes Reinecke wrote: > On 1/24/25 19:43, Caleb Sander Mateos wrote: >> 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") >> --- >> 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 = 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); > > But won't we have to wait for a TCP timeout now if the sender sends less > than 128 bytes? With this patch we always wait for 128 bytes, and > possibly wait for TCP timeout if not. > Testcase for this would be nice ... > > And I need to check if secure concatenation is affected here; with > secure concatenation we need to peek at the first packet to check > if it's an ICRESP or a TLS negotiation. > And wouldn't this patch be sufficient here? diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index 841238f38fdd..85b1328a8757 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -1451,12 +1451,13 @@ static int nvme_tcp_init_connection(struct nvme_tcp_queue *queue) } ret = kernel_recvmsg(queue->sock, &msg, &iov, 1, iov.iov_len, msg.msg_flags); + if (ret == 0) + ret = -ENOTCONN; if (ret < 0) { pr_warn("queue %d: failed to receive icresp, error %d\n", nvme_tcp_queue_id(queue), ret); goto free_icresp; } - ret = -ENOTCONN; if (nvme_tcp_queue_tls(queue)) { ctype = tls_get_record_type(queue->sock->sk, (struct cmsghdr *)cbuf); icresp validity is checked later in the code, so if we haven't received a full icresp we _should_ fail those tests. And then we don't really have to check how many bytes we've received. Cheers, Hannes -- Dr. Hannes Reinecke Kernel Storage Architect hare@suse.de +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich