Skip to content

Commit b013b81

Browse files
q2venChristoph Hellwig
authored andcommitted
nvme-tcp: fix use-after-free of netns by kernel TCP socket.
Commit 1be5216 ("nvme-tcp: fix selinux denied when calling sock_sendmsg") converted sock_create() in nvme_tcp_alloc_queue() to sock_create_kern(). sock_create_kern() creates a kernel socket, which does not hold a reference to netns. If the code does not manage the netns lifetime properly, use-after-free could happen. Also, TCP kernel socket with sk_net_refcnt 0 has a socket leak problem: it remains FIN_WAIT_1 if it misses FIN after close() because tcp_close() stops all timers. To fix such problems, let's hold netns ref by sk_net_refcnt_upgrade(). We had the same issue in CIFS, SMC, etc, and applied the same solution, see commit ef7134c ("smb: client: Fix use-after-free of network namespace.") and commit 9744d2b ("smc: Fix use-after-free in tcp_write_timer_handler()."). Fixes: 1be5216 ("nvme-tcp: fix selinux denied when calling sock_sendmsg") Signed-off-by: Kuniyuki Iwashima <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent e3105f5 commit b013b81

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/nvme/host/tcp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,8 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid,
18031803
ret = PTR_ERR(sock_file);
18041804
goto err_destroy_mutex;
18051805
}
1806+
1807+
sk_net_refcnt_upgrade(queue->sock->sk);
18061808
nvme_tcp_reclassify_socket(queue->sock);
18071809

18081810
/* Single syn retry */

0 commit comments

Comments
 (0)