Skip to content

Commit b98e762

Browse files
josefbacikaxboe
authored andcommitted
nbd: freeze the queue while we're adding connections
When setting up a device, we can krealloc the config->socks array to add new sockets to the configuration. However if we happen to get a IO request in at this point even though we aren't setup we could hit a UAF, as we deref config->socks without any locking, assuming that the configuration was setup already and that ->socks is safe to access it as we have a reference on the configuration. But there's nothing really preventing IO from occurring at this point of the device setup, we don't want to incur the overhead of a lock to access ->socks when it will never change while the device is running. To fix this UAF scenario simply freeze the queue if we are adding sockets. This will protect us from this particular case without adding any additional overhead for the normal running case. Cc: [email protected] Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent ac55ad2 commit b98e762

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

drivers/block/nbd.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,12 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
10221022
if (!sock)
10231023
return err;
10241024

1025+
/*
1026+
* We need to make sure we don't get any errant requests while we're
1027+
* reallocating the ->socks array.
1028+
*/
1029+
blk_mq_freeze_queue(nbd->disk->queue);
1030+
10251031
if (!netlink && !nbd->task_setup &&
10261032
!test_bit(NBD_RT_BOUND, &config->runtime_flags))
10271033
nbd->task_setup = current;
@@ -1060,10 +1066,12 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
10601066
nsock->cookie = 0;
10611067
socks[config->num_connections++] = nsock;
10621068
atomic_inc(&config->live_connections);
1069+
blk_mq_unfreeze_queue(nbd->disk->queue);
10631070

10641071
return 0;
10651072

10661073
put_socket:
1074+
blk_mq_unfreeze_queue(nbd->disk->queue);
10671075
sockfd_put(sock);
10681076
return err;
10691077
}

0 commit comments

Comments
 (0)