Skip to content

Commit 584ce1b

Browse files
q2venkawasaki
authored andcommitted
nbd: Reject unconnected sockets in nbd_get_socket().
NBD requires a handshake, so passing unconnected or half-closed sockets to NBD does not make sense. Let's accept TCP_ESTABLISHED sockets only. Note that AF_UNIX sockets remain in TCP_ESTABLISHED once connect()ed regardless of shutdown(), but this is a prep patch for TCP, allowing a subsequent patch to call tcp_sendmsg_locked() directly without extra setup (e.g. inet_send_prepare()). Signed-off-by: Kuniyuki Iwashima <[email protected]>
1 parent 8dd2218 commit 584ce1b

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

drivers/block/nbd.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,13 @@ static struct socket *nbd_get_socket(struct nbd_device *nbd, unsigned long fd,
12281228
return NULL;
12291229
}
12301230

1231+
if (READ_ONCE(sock->sk->sk_state) != TCP_ESTABLISHED) {
1232+
dev_err(disk_to_dev(nbd->disk), "Socket does not have bi-directional stream.\n");
1233+
*err = -EPIPE;
1234+
sockfd_put(sock);
1235+
return NULL;
1236+
}
1237+
12311238
return sock;
12321239
}
12331240

0 commit comments

Comments
 (0)