From: Shardul Bankar <shardul.b@mpiricsoftware.com>
To: slava@dubeyko.com, zippel@linux-m68k.org,
linux-fsdevel@vger.kernel.org, glaubitz@physik.fu-berlin.de,
frank.li@vivo.com
Cc: akpm@osdl.org, linux-kernel@vger.kernel.org,
janak@mpiricsoftware.com, shardulsb08@gmail.com,
stable@vger.kernel.org,
syzbot+1c8ff72d0cd8a50dfeaa@syzkaller.appspotmail.com,
Shardul Bankar <shardul.b@mpiricsoftware.com>
Subject: [PATCH v2 1/2] hfsplus: skip node 0 in hfs_bmap_alloc
Date: Wed, 24 Dec 2025 20:43:46 +0530 [thread overview]
Message-ID: <20251224151347.1861896-2-shardul.b@mpiricsoftware.com> (raw)
In-Reply-To: <20251224151347.1861896-1-shardul.b@mpiricsoftware.com>
Node 0 is the header node in HFS+ B-trees and should always be allocated.
However, if a filesystem image has node 0's bitmap bit unset (e.g., due to
corruption or a buggy image generator), hfs_bmap_alloc() will find node 0
as free and attempt to allocate it. This causes a conflict because node 0
already exists as the header node, leading to a WARN_ON(1) in
hfs_bnode_create() when the node is found already hashed.
This issue can occur with syzkaller-generated HFS+ images or corrupted
real-world filesystems. Add a guard in hfs_bmap_alloc() to skip node 0
during allocation, providing defense-in-depth against such corruption.
Reported-by: syzbot+1c8ff72d0cd8a50dfeaa@syzkaller.appspotmail.com
Link: https://syzkaller.appspot.com/bug?extid=1c8ff72d0cd8a50dfeaa
Signed-off-by: Shardul Bankar <shardul.b@mpiricsoftware.com>
---
v2:
- Keep the node-0 allocation guard as targeted hardening for corrupted images.
fs/hfsplus/btree.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/hfsplus/btree.c b/fs/hfsplus/btree.c
index 229f25dc7c49..60985f449450 100644
--- a/fs/hfsplus/btree.c
+++ b/fs/hfsplus/btree.c
@@ -411,6 +411,9 @@ struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree)
if (byte != 0xff) {
for (m = 0x80, i = 0; i < 8; m >>= 1, i++) {
if (!(byte & m)) {
+ /* Skip node 0 (header node, always allocated) */
+ if (idx == 0 && i == 0)
+ continue;
idx += i;
data[off] |= m;
set_page_dirty(*pagep);
--
2.34.1
next prev parent reply other threads:[~2025-12-24 15:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-24 15:13 [PATCH v2 0/2] hfsplus: avoid re-allocating header node 0 and stop on already-hashed nodes Shardul Bankar
2025-12-24 15:13 ` Shardul Bankar [this message]
2025-12-25 4:02 ` [PATCH v2 1/2] hfsplus: skip node 0 in hfs_bmap_alloc Viacheslav Dubeyko
2025-12-25 6:32 ` Shardul Bankar
2025-12-29 20:12 ` Viacheslav Dubeyko
2025-12-24 15:13 ` [PATCH v2 2/2] hfsplus: return error when node already exists in hfs_bnode_create Shardul Bankar
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=20251224151347.1861896-2-shardul.b@mpiricsoftware.com \
--to=shardul.b@mpiricsoftware.com \
--cc=akpm@osdl.org \
--cc=frank.li@vivo.com \
--cc=glaubitz@physik.fu-berlin.de \
--cc=janak@mpiricsoftware.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=shardulsb08@gmail.com \
--cc=slava@dubeyko.com \
--cc=stable@vger.kernel.org \
--cc=syzbot+1c8ff72d0cd8a50dfeaa@syzkaller.appspotmail.com \
--cc=zippel@linux-m68k.org \
/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