Skip to contentSkip to conversation

nvmet-tcp: check return value of nvmet_tcp_set_queue_sock

PATCH Applied Geliang Tang 3 participants 3 messages May 26 – May 27

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 nvmet-tcp: check return value of nvmet_tcp_set_queue_sock

From: Geliang Tang <[email protected]>

The return value of nvmet_tcp_set_queue_sock() is currently ignored in nvmet_tcp_tls_handshake_done(). If it fails (e.g., due to the socket not being in TCP_ESTABLISHED state), the socket callbacks will not be properly set, leading to queue and socket leakage.

Fix this by capturing the return value and calling nvmet_tcp_schedule_release_queue() on failure to ensure proper cleanup.

Fixes 675b453e0241 ("nvmet-tcp: enable TLS handshake upcall")

---
v2:
- add Hannes's reviewed tag.
- drop patch 2 in v1 as Maurizio suggested.
v1:
- https://patchwork.kernel.org/project/linux-nvme/cover/[email protected]/

---
 drivers/nvme/target/tcp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/nvme/target/tcp.c +3 -2
index 20f150d17a96..88291d45e162 100644
@@ -1844,10 +1844,11 @@ static void nvmet_tcp_tls_handshake_done(void *data, int status,
 	if (!status)
 		status = nvmet_tcp_tls_key_lookup(queue, peerid);
 
+	if (!status)
+		status = nvmet_tcp_set_queue_sock(queue);
+
 	if (status)
 		nvmet_tcp_schedule_release_queue(queue);
-	else
-		nvmet_tcp_set_queue_sock(queue);
 	kref_put(&queue->kref, nvmet_tcp_release_queue);
 }
 
Signature · 1 line
2.53.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Geliang Tang

From: Geliang Tang<[email protected]>

The return value of nvmet_tcp_set_queue_sock() is currently ignored in nvmet_tcp_tls_handshake_done(). If it fails (e.g., due to the socket not being in TCP_ESTABLISHED state), the socket callbacks will not be properly set, leading to queue and socket leakage.

Quoted 6 lines

Fix this by capturing the return value and calling nvmet_tcp_schedule_release_queue() on failure to ensure proper cleanup.

Fixes 675b453e0241 ("nvmet-tcp: enable TLS handshake upcall")

Looks good.

-ck

maintainer Applied
#2 lore raw
In reply to Geliang Tang
Quoted 9 lines · Geliang Tang

From: Geliang Tang <[email protected]>

The return value of nvmet_tcp_set_queue_sock() is currently ignored in nvmet_tcp_tls_handshake_done(). If it fails (e.g., due to the socket not being in TCP_ESTABLISHED state), the socket callbacks will not be properly set, leading to queue and socket leakage.

Fix this by capturing the return value and calling nvmet_tcp_schedule_release_queue() on failure to ensure proper cleanup.

Thanks, applied to nvme-7.2.