Re: [PATCH 3/4] nvmet-tcp: fix handling of tls alerts
From: Hannes Reinecke <hare@suse.de>
Date: 2025-07-31 17:13:09
Also in:
linux-nfs, linux-nvme
On 7/31/25 17:29, Olga Kornievskaia wrote:
On Thu, Jul 31, 2025 at 2:10 AM Hannes Reinecke [off-list ref] wrote:quoted
On 7/30/25 22:08, Olga Kornievskaia wrote:quoted
Revert kvec msg iterator before trying to process a TLS alert when possible. In nvmet_tcp_try_recv_data(), it's assumed that no msg control message buffer is set prior to sock_recvmsg(). Hannes suggested that upon detecting that TLS control message is received log a message and error out. Left comments in the code for the future improvements. Fixes: a1c5dd8355b1 ("nvmet-tcp: control messages for recvmsg()") Suggested-by: Hannes Reinecke <hare@suse.de> Reviewed-by: Hannes Reinecky <redacted> Signed-off-by: Olga Kornievskaia <okorniev@redhat.com> --- drivers/nvme/target/tcp.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c index 688033b88d38..055e420d3f2e 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c@@ -1161,6 +1161,7 @@ static int nvmet_tcp_try_recv_pdu(struct nvmet_tcp_queue *queue) if (unlikely(len < 0)) return len; if (queue->tls_pskid) { + iov_iter_revert(&msg.msg_iter, len); ret = nvmet_tcp_tls_record_ok(queue, &msg, cbuf); if (ret < 0) return ret;@@ -1217,19 +1218,28 @@ static void nvmet_tcp_prep_recv_ddgst(struct nvmet_tcp_cmd *cmd) static int nvmet_tcp_try_recv_data(struct nvmet_tcp_queue *queue) { struct nvmet_tcp_cmd *cmd = queue->cmd; - int len, ret; + int len; while (msg_data_left(&cmd->recv_msg)) { + /* to detect that we received a TlS alert, we assumed that + * cmg->recv_msg's control buffer is not setup. kTLS will + * return an error when no control buffer is set and + * non-tls-data payload is received. + */ len = sock_recvmsg(cmd->queue->sock, &cmd->recv_msg, cmd->recv_msg.msg_flags); + if (cmd->recv_msg.msg_flags & MSG_CTRUNC) { + if (len == 0 || len == -EIO) { + pr_err("queue %d: unhandled control message\n", + queue->idx); + /* note that unconsumed TLS control message such + * as TLS alert is still on the socket. + */Hmm. Will it get cleared when we close the socket?If the socket is closed then any data on that socket would be freed.quoted
Or shouldn't we rather introduce proper cmsg handling?That would be what I have originally proposed (I know that was on the private list). But yes, we can setup a dedicated kvec to receive the TLS control message once its been detected and then call nvme_tcp_tls_record_ok(). Let me know if proper cmsg handling is what's desired for this patch.quoted
(If we do, we'll need it to do on the host side, too)
No, let's delegate that to a next step. My main concern is that data on the socket is freed upon closing (ie on reconnect). If that's the case we should leave it for now. There is talk to handle TLS new session ticket messages, which probably will require some evaluation of TLS messages and will most certainly require the updated TLS Alert handling. 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