* [PATCH] hfsplus: fix duplicate bnode creation in hfs_bnode_create
@ 2026-06-21 9:04 Sainath Manda
2026-06-23 5:56 ` Viacheslav Dubeyko
0 siblings, 1 reply; 2+ messages in thread
From: Sainath Manda @ 2026-06-21 9:04 UTC (permalink / raw)
To: slava, glaubitz, frank.li
Cc: linux-fsdevel, linux-kernel, Sainath Manda, syzbot+f83fa2cf571bd7650422
Syzbot reported a WARNING in hfsplus_bnode_create. A maliciously crafted
HFS+ image can request the creation of a duplicate bnode (e.g., bnode 0)
that is mathematically within the tree->node_count bounds, but has
already been hashed in memory. This bypasses initial boundary checks and
triggers a WARN_ON(1) upon a duplicate hash collision.
This patch adds a clean state check in hfs_bnode_create. If a requested
node is already hashed, the driver now safely rejects the operation
with -EEXIST instead of tripping the kernel warning.
Reported-by: syzbot+f83fa2cf571bd7650422@syzkaller.appspotmail.com
Signed-off-by: Sainath Manda sainathmanda777@gmail.com
---
fs/hfsplus/bnode.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/fs/hfsplus/bnode.c b/fs/hfsplus/bnode.c
index f8b5a8ae5..5946baad2 100644
--- a/fs/hfsplus/bnode.c
+++ b/fs/hfsplus/bnode.c
@@ -626,12 +626,18 @@ struct hfs_bnode *hfs_bnode_create(struct hfs_btree *tree, u32 num)
struct page **pagep;
int i;
+ if (num >= tree->node_count) {
+ pr_err("hfsplus: attempted to create invalid bnode %u (max %u)\n",
+ num, tree->node_count);
+ return ERR_PTR(-EINVAL);
+ }
+
spin_lock(&tree->hash_lock);
node = hfs_bnode_findhash(tree, num);
spin_unlock(&tree->hash_lock);
if (node) {
- pr_crit("new node %u already hashed?\n", num);
- WARN_ON(1);
+ pr_err("hfsplus: attempted to create already hashed bnode %u\n",
+ num);
return ERR_PTR(-EEXIST);
}
node = __hfs_bnode_create(tree, num);
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] hfsplus: fix duplicate bnode creation in hfs_bnode_create
2026-06-21 9:04 [PATCH] hfsplus: fix duplicate bnode creation in hfs_bnode_create Sainath Manda
@ 2026-06-23 5:56 ` Viacheslav Dubeyko
0 siblings, 0 replies; 2+ messages in thread
From: Viacheslav Dubeyko @ 2026-06-23 5:56 UTC (permalink / raw)
To: Sainath Manda, glaubitz, frank.li
Cc: linux-fsdevel, linux-kernel, syzbot+f83fa2cf571bd7650422
On Sun, 2026-06-21 at 14:34 +0530, Sainath Manda wrote:
> Syzbot reported a WARNING in hfsplus_bnode_create. A maliciously
> crafted
> HFS+ image can request the creation of a duplicate bnode (e.g., bnode
> 0)
> that is mathematically within the tree->node_count bounds, but has
> already been hashed in memory. This bypasses initial boundary checks
> and
> triggers a WARN_ON(1) upon a duplicate hash collision.
>
> This patch adds a clean state check in hfs_bnode_create. If a
> requested
> node is already hashed, the driver now safely rejects the operation
> with -EEXIST instead of tripping the kernel warning.
>
> Reported-by: syzbot+f83fa2cf571bd7650422@syzkaller.appspotmail.com
> Signed-off-by: Sainath Manda sainathmanda777@gmail.com
> ---
> fs/hfsplus/bnode.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/fs/hfsplus/bnode.c b/fs/hfsplus/bnode.c
> index f8b5a8ae5..5946baad2 100644
> --- a/fs/hfsplus/bnode.c
> +++ b/fs/hfsplus/bnode.c
> @@ -626,12 +626,18 @@ struct hfs_bnode *hfs_bnode_create(struct
> hfs_btree *tree, u32 num)
> struct page **pagep;
> int i;
>
> + if (num >= tree->node_count) {
> + pr_err("hfsplus: attempted to create invalid bnode
> %u (max %u)\n",
> + num, tree->node_count);
> + return ERR_PTR(-EINVAL);
> + }
> +
> spin_lock(&tree->hash_lock);
> node = hfs_bnode_findhash(tree, num);
> spin_unlock(&tree->hash_lock);
> if (node) {
> - pr_crit("new node %u already hashed?\n", num);
> - WARN_ON(1);
> + pr_err("hfsplus: attempted to create already hashed
> bnode %u\n",
> + num);
> return ERR_PTR(-EEXIST);
> }
> node = __hfs_bnode_create(tree, num);
If we have corrupted HFS+ image, then we should not mount it. If I
remember correctly, we already have patch that fixes this issue by
checking b-tree's map during mount operation. Are you sure that you are
running the latest state of the Linux kernel?
Thanks,
Slava.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-23 5:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-21 9:04 [PATCH] hfsplus: fix duplicate bnode creation in hfs_bnode_create Sainath Manda
2026-06-23 5:56 ` Viacheslav Dubeyko
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®