Re: [PATCH] blk-mq: fix null-ptr-deref in blk_mq_run_hw_queues
From: Bart Van Assche
Date: Wed Dec 02 2026 - 12:41:51 EST
On 12/2/26 7:13 AM, Peiyang He wrote:
A concurrent caller such as blk_mq_unquiesce_queue() can then get aPlease make it clear that this is a block layer bug and that the NBD
NULL hctx from queue_hctx() and dereference hctx->state in blk_mq_hctx_stopped(), causing a NULL pointer dereference.
driver is only one way to trigger it.
> Fixes: d0c98769ee7d ("blk-mq: use array manage hctx map instead of xarray")
This race is much older than commit d0c98769ee7d. I think this is the
proper Fixes tag:
Fixes: 868f2f0b7206 ("blk-mq: dynamic h/w context count")
> + /*
> + * __blk_mq_update_nr_hw_queues() updates nr_hw_queues and queue_hw_ctx
> + * while the queue is frozen. So we can use q_usage_counter to avoid
> + * racing with it.
> + */
> + if (!percpu_ref_tryget(&q->q_usage_counter))
> + return;
The approach looks good to me but please make the comment more explicit,
e.g. as follows:
/*
* Holding a q_usage_counter reference prevents queue freezing from
* completion and hence serializes the loop below against
* __blk_mq_update_nr_hw_queues().
*/
Thanks,
Bart.