From: Krystian Kaniewski <krystianmkaniewski@gmail.com>
To: Jens Axboe <axboe@kernel.dk>, linux-block@vger.kernel.org
Cc: Nilay Shroff <nilay@linux.ibm.com>,
Hannes Reinecke <hare@suse.de>, Ming Lei <ming.lei@redhat.com>,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
syzkaller-bugs@googlegroups.com, syzbot@lists.linux.dev,
syzbot+e90526cab23b9efcd03c@syzkaller.appspotmail.com
Subject: Re: [PATCH v2] blk-mq: fix out-of-bounds read in blk_mq_free_rqs
Date: Mon, 2 Nov 2026 12:08:57 +0100 [thread overview]
Message-ID: <a8fb3606-017b-464e-a09f-1f1ddf3bc45e@gmail.com> (raw)
In-Reply-To: <20261014170538.1089448-1-krystianmkaniewski@gmail.com>
On 10/14/26 19:05, Krystian Kaniewski wrote:
> A KASAN slab-out-of-bounds read can occur in blk_mq_free_rqs() when there
> is a mismatch between the number of hardware queues allocated for the IO
> scheduler (et->nr_hw_queues) and the number of hardware queues in the block
> tag set (set->nr_hw_queues).
>
> This mismatch can happen if blk_mq_update_nr_hw_queues() fails halfway
> through (e.g., due to memory pressure during
> blk_mq_prealloc_tag_set_tags()). In this error path, the elevator is
> restored with a larger number of hardware queues than the block tag set
> actually has.
>
> When the elevator is later freed, blk_mq_free_sched_tags() iterates up to
> the new et->nr_hw_queues and calls blk_mq_free_rqs(). In blk_mq_free_rqs(),
> it attempts to access set->tags[hctx_idx] to get the driver tags. Because
> set->nr_hw_queues was not updated due to the earlier failure, set->tags
> still has the old (smaller) size, leading to an out-of-bounds read.
>
> BUG: KASAN: slab-out-of-bounds in blk_mq_free_rqs+0xde/0x680
> Read of size 8 at addr ffff88818d67fc28 by task syz-executor117/5839
> Call Trace:
> blk_mq_free_rqs+0xde/0x680
> blk_mq_free_map_and_rqs+0x40/0xf0
> blk_mq_free_sched_tags
> blk_mq_free_sched_res+0xeb/0x280
> elevator_change_done+0x1d2/0x5c0
> elevator_change+0x34f/0x480
> elv_iosched_store+0x504/0x630
> queue_attr_store+0x207/0x2b0
>
> To fix this, explicitly check if hctx_idx < set->nr_hw_queues before
> accessing set->tags[hctx_idx]. If hctx_idx >= set->nr_hw_queues, the
> hardware queue doesn't exist in the tag set, meaning there are no driver
> tags to clear mappings from. In this case, safely set drv_tags to NULL. The
> subsequent call to blk_mq_clear_rq_mapping() already handles a NULL
> drv_tags pointer and will safely return.
>
> Fixes: 04225d13aef1 ("block: fix potential deadlock while running nr_hw_queue update")
> Assisted-by: Gemini:gemini-3.5-flash Gemini:gemini-3.1-pro-preview syzbot
> Reported-by: syzbot+e90526cab23b9efcd03c@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=e90526cab23b9efcd03c
> Link: https://syzkaller.appspot.com/ai_job?id=827b5760-86a0-4f44-9c69-430b572eac12
> Reviewed-by: Nilay Shorff <nilay@linux.ibm.com>
> Cc: stable@vger.kernel.org # 6.17+
> Signed-off-by: Krystian Kaniewski <krystianmkaniewski@gmail.com>
> ---
> Changes since v1:
> - Drop the additional blk_mq_alloc_rqs() claim, as that path is bounded by
> set->nr_hw_queues.
> - Add Nilay's Reviewed-by tag.
> - Rebase onto current mainline and refresh the recipient list.
>
> v1: https://lore.kernel.org/all/c92b0c7e-17fb-44c8-99d9-59d45004d05a@mail.kernel.org/
>
> block/blk-mq.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index 025a799f35b92..259a5705efb79 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -3484,8 +3484,10 @@ void blk_mq_free_rqs(struct blk_mq_tag_set *set, struct blk_mq_tags *tags,
>
> if (blk_mq_is_shared_tags(set->flags))
> drv_tags = set->shared_tags;
> - else
> + else if (hctx_idx < set->nr_hw_queues)
> drv_tags = set->tags[hctx_idx];
> + else
> + drv_tags = NULL;
>
> if (tags->static_rqs && set->ops->exit_request) {
> int i;
>
> base-commit: 0fcb05b72344f40806cbe810de8872f1698bf053
Hi Jens,
A gentle ping on this fix. The patch has Nilay's Reviewed-by, and
syzbot CI tested v2 without finding any issues.
Please let me know if any changes are needed.
Thanks,
--
Krystian Kaniewski
prev parent reply other threads:[~2026-11-02 11:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-14 17:05 Krystian Kaniewski
2026-11-02 11:08 ` Krystian Kaniewski [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a8fb3606-017b-464e-a09f-1f1ddf3bc45e@gmail.com \
--to=krystianmkaniewski@gmail.com \
--cc=axboe@kernel.dk \
--cc=hare@suse.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ming.lei@redhat.com \
--cc=nilay@linux.ibm.com \
--cc=stable@vger.kernel.org \
--cc=syzbot+e90526cab23b9efcd03c@syzkaller.appspotmail.com \
--cc=syzbot@lists.linux.dev \
--cc=syzkaller-bugs@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®