Skip to content

Commit 2b6f17d

Browse files
josefbacikksacilotto
authored andcommitted
nbd: freeze the queue while we're adding connections
BugLink: https://bugs.launchpad.net/bugs/1916056 commit b98e762 upstream. 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Kamal Mostafa <[email protected]> Signed-off-by: Stefan Bader <[email protected]>
1 parent 19471c5 commit 2b6f17d

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
@@ -1014,6 +1014,12 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
10141014
if (!sock)
10151015
return err;
10161016

1017+
/*
1018+
* We need to make sure we don't get any errant requests while we're
1019+
* reallocating the ->socks array.
1020+
*/
1021+
blk_mq_freeze_queue(nbd->disk->queue);
1022+
10171023
if (!netlink && !nbd->task_setup &&
10181024
!test_bit(NBD_RT_BOUND, &config->runtime_flags))
10191025
nbd->task_setup = current;
@@ -1052,10 +1058,12 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
10521058
nsock->cookie = 0;
10531059
socks[config->num_connections++] = nsock;
10541060
atomic_inc(&config->live_connections);
1061+
blk_mq_unfreeze_queue(nbd->disk->queue);
10551062

10561063
return 0;
10571064

10581065
put_socket:
1066+
blk_mq_unfreeze_queue(nbd->disk->queue);
10591067
sockfd_put(sock);
10601068
return err;
10611069
}

0 commit comments

Comments
 (0)