Skip to content

Commit cf1b232

Browse files
Mike Christieaxboe
Mike Christie
authored andcommitted
nbd: verify socket is supported during setup
nbd requires socket families to support the shutdown method so the nbd recv workqueue can be woken up from its sock_recvmsg call. If the socket does not support the callout we will leave recv works running or get hangs later when the device or module is removed. This adds a check during socket connection/reconnection to make sure the socket being passed in supports the needed callout. Reported-by: [email protected] Fixes: e9e006f ("nbd: fix max number of supported devs") Tested-by: Richard W.M. Jones <[email protected]> Signed-off-by: Mike Christie <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 962399b commit cf1b232

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

drivers/block/nbd.c

+21-2
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,25 @@ static blk_status_t nbd_queue_rq(struct blk_mq_hw_ctx *hctx,
980980
return ret;
981981
}
982982

983+
static struct socket *nbd_get_socket(struct nbd_device *nbd, unsigned long fd,
984+
int *err)
985+
{
986+
struct socket *sock;
987+
988+
*err = 0;
989+
sock = sockfd_lookup(fd, err);
990+
if (!sock)
991+
return NULL;
992+
993+
if (sock->ops->shutdown == sock_no_shutdown) {
994+
dev_err(disk_to_dev(nbd->disk), "Unsupported socket: shutdown callout must be supported.\n");
995+
*err = -EINVAL;
996+
return NULL;
997+
}
998+
999+
return sock;
1000+
}
1001+
9831002
static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
9841003
bool netlink)
9851004
{
@@ -989,7 +1008,7 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
9891008
struct nbd_sock *nsock;
9901009
int err;
9911010

992-
sock = sockfd_lookup(arg, &err);
1011+
sock = nbd_get_socket(nbd, arg, &err);
9931012
if (!sock)
9941013
return err;
9951014

@@ -1041,7 +1060,7 @@ static int nbd_reconnect_socket(struct nbd_device *nbd, unsigned long arg)
10411060
int i;
10421061
int err;
10431062

1044-
sock = sockfd_lookup(arg, &err);
1063+
sock = nbd_get_socket(nbd, arg, &err);
10451064
if (!sock)
10461065
return err;
10471066

0 commit comments

Comments
 (0)