From: Jackie Liu <[email protected]>

nbd_start_device() checks NBD_FLAG_CAN_MULTI_CONN before dropping
config_lock to update the hardware queue count. A concurrent
NBD_SET_SOCK can add a connection during that window, and NBD_SET_FLAGS
can clear the flag without changing the connection count.

The queue-count retry only notices changes to num_connections and does
not repeat the flag check. Startup can therefore create multiple receive
workers even though the server no longer advertises multi-connection
support.

Recheck the current connection count and flags after reacquiring
config_lock, before retrying the queue update or starting the device.
Return -EINVAL if multiple connections are no longer supported.

Fixes: 8b428f42f3ed ("nbd: fix lockdep deadlock warning")
Cc: [email protected] # v6.17+
Signed-off-by: Jackie Liu <[email protected]>
---
 drivers/block/nbd.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index e8e8517fb6c7..9987c56758ec 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1533,6 +1533,9 @@ static int nbd_start_device(struct nbd_device *nbd)
        /* The device may have been started or reconfigured while unlocked. */
        if (nbd->pid)
                return -EBUSY;
+       if (config->num_connections > 1 &&
+           !(config->flags & NBD_FLAG_CAN_MULTI_CONN))
+               return -EINVAL;
 
        /* if another code path updated nr_hw_queues, retry until succeed */
        if (num_connections != config->num_connections) {

Reply via email to