nbd_total_devices is incremented in nbd_dev_add() but never decremented, so it ends up larger than the number of devices left in nbd_index_idr. nbd_genl_status() sizes the reply from it, so status allocates for devices that no longer exist. Decrement it in nbd_dev_remove() under nbd_index_mutex. Fixes: 47d902b90a32 ("nbd: add a status netlink command") Assisted-by: LLM Signed-off-by: Yang Erkun --- drivers/block/nbd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index fbade6ae4481..1448ee63fab5 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -275,6 +275,7 @@ static void nbd_dev_remove(struct nbd_device *nbd) */ mutex_lock(&nbd_index_mutex); idr_remove(&nbd_index_idr, nbd->index); + nbd_total_devices--; mutex_unlock(&nbd_index_mutex); destroy_workqueue(nbd->recv_workq); put_disk(disk); -- 2.52.0