From: Thanh Nguyen <thanhnguyentuan2007@gmail.com>
To: Jens Axboe <axboe@kernel.dk>, Andrew Morton <akpm@linux-foundation.org>
Cc: Ming Lei <ming.lei@redhat.com>,
linux-block@vger.kernel.org, linux-scsi@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
syzbot+4138704b4276d9a57251@syzkaller.appspotmail.com
Subject: [PATCH] sbitmap: reset alloc_hint to NULL after freeing
Date: Tue, 1 Dec 2026 23:15:07 -0500 [thread overview]
Message-ID: <20261202041507.603-1-thanhnguyentuan2007@gmail.com> (raw)
In sbitmap_init_node(), if init_alloc_hint() succeeds and the subsequent
kvzalloc_node() for sb->map fails, the error path calls
free_percpu(sb->alloc_hint) without resetting sb->alloc_hint to NULL.
When a caller tears down the enclosing object on failure (for example,
scsi_alloc_sdev() failing in scsi_realloc_sdev_budget_map() and calling
__scsi_remove_device() -> scsi_device_dev_release() -> sbitmap_free()),
the dangling sb->alloc_hint pointer is passed to free_percpu() a second
time, triggering WARN_ON_ONCE(1) in free_percpu().
Reset sb->alloc_hint to NULL after free_percpu() in both
sbitmap_init_node() and sbitmap_free() (consistent with sb->map = NULL),
and also initialize sb->alloc_hint to NULL in the depth == 0 early return
path of sbitmap_init_node().
Fixes: c548e62bcf6a ("scsi: sbitmap: Move allocation hint into sbitmap")
Reported-by: syzbot+4138704b4276d9a57251@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=4138704b4276d9a57251
Cc: stable@vger.kernel.org
Signed-off-by: Thanh Nguyen <thanhnguyentuan2007@gmail.com>
---
include/linux/sbitmap.h | 1 +
lib/sbitmap.c | 2 ++
2 files changed, 3 insertions(+)
diff --git a/include/linux/sbitmap.h b/include/linux/sbitmap.h
index cc7ad189c..620480e33 100644
--- a/include/linux/sbitmap.h
+++ b/include/linux/sbitmap.h
@@ -185,6 +185,7 @@ static inline unsigned int __map_depth(const struct sbitmap *sb, int index)
static inline void sbitmap_free(struct sbitmap *sb)
{
free_percpu(sb->alloc_hint);
+ sb->alloc_hint = NULL;
kvfree(sb->map);
sb->map = NULL;
}
diff --git a/lib/sbitmap.c b/lib/sbitmap.c
index 4d188d05d..59879e27d 100644
--- a/lib/sbitmap.c
+++ b/lib/sbitmap.c
@@ -119,6 +119,7 @@ int sbitmap_init_node(struct sbitmap *sb, unsigned int depth, int shift,
if (depth == 0) {
sb->map = NULL;
+ sb->alloc_hint = NULL;
return 0;
}
@@ -132,6 +133,7 @@ int sbitmap_init_node(struct sbitmap *sb, unsigned int depth, int shift,
sb->map = kvzalloc_node(sb->map_nr * sizeof(*sb->map), flags, node);
if (!sb->map) {
free_percpu(sb->alloc_hint);
+ sb->alloc_hint = NULL;
return -ENOMEM;
}
--
2.56.1
reply other threads:[~2026-12-02 4:15 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261202041507.603-1-thanhnguyentuan2007@gmail.com \
--to=thanhnguyentuan2007@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=ming.lei@redhat.com \
--cc=stable@vger.kernel.org \
--cc=syzbot+4138704b4276d9a57251@syzkaller.appspotmail.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®