From: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
To: "shardul.b@mpiricsoftware.com" <shardul.b@mpiricsoftware.com>,
"zippel@linux-m68k.org" <zippel@linux-m68k.org>,
"glaubitz@physik.fu-berlin.de" <glaubitz@physik.fu-berlin.de>,
"slava@dubeyko.com" <slava@dubeyko.com>,
"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
"frank.li@vivo.com" <frank.li@vivo.com>
Cc: "akpm@osdl.org" <akpm@osdl.org>,
"janak@mpiricsoftware.com" <janak@mpiricsoftware.com>,
"shardulsb08@gmail.com" <shardulsb08@gmail.com>,
"stable@vger.kernel.org" <stable@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"syzbot+1c8ff72d0cd8a50dfeaa@syzkaller.appspotmail.com"
<syzbot+1c8ff72d0cd8a50dfeaa@syzkaller.appspotmail.com>
Subject: Re: [PATCH v3] hfsplus: return error when node already exists in hfs_bnode_create
Date: Mon, 29 Dec 2025 22:24:35 +0000 [thread overview]
Message-ID: <08e7f7ef7da57448945a8d62160d2d7a67df2883.camel@ibm.com> (raw)
In-Reply-To: <20251229204938.1907089-1-shardul.b@mpiricsoftware.com>
On Tue, 2025-12-30 at 02:19 +0530, Shardul Bankar wrote:
> When hfs_bnode_create() finds that a node is already hashed (which should
> not happen in normal operation), it currently returns the existing node
> without incrementing its reference count. This causes a reference count
> inconsistency that leads to a kernel panic when the node is later freed
> in hfs_bnode_put():
>
> kernel BUG at fs/hfsplus/bnode.c:676!
> BUG_ON(!atomic_read(&node->refcnt))
>
> This scenario can occur when hfs_bmap_alloc() attempts to allocate a node
> that is already in use (e.g., when node 0's bitmap bit is incorrectly
> unset), or due to filesystem corruption.
>
> Returning an existing node from a create path is not normal operation.
>
> Fix this by returning ERR_PTR(-EEXIST) instead of the node when it's
> already hashed. This properly signals the error condition to callers,
> which already check for IS_ERR() return values.
>
> Reported-by: syzbot+1c8ff72d0cd8a50dfeaa@syzkaller.appspotmail.com
> Link: https://syzkaller.appspot.com/bug?extid=1c8ff72d0cd8a50dfeaa
> Link: https://lore.kernel.org/all/784415834694f39902088fa8946850fc1779a318.camel@ibm.com/
> Fixes: 634725a92938 ("[PATCH] hfs: cleanup HFS+ prints")
> Signed-off-by: Shardul Bankar <shardul.b@mpiricsoftware.com>
> ---
> v3 changes:
> - This is posted standalone as discussed in the v2 thread.
> v2 changes:
> - Implement Slava's suggestion: return ERR_PTR(-EEXIST) for already-hashed nodes.
> - Keep the node-0 allocation guard as a minimal, targeted hardening measure.
>
> fs/hfsplus/bnode.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/hfsplus/bnode.c b/fs/hfsplus/bnode.c
> index 191661af9677..250a226336ea 100644
> --- a/fs/hfsplus/bnode.c
> +++ b/fs/hfsplus/bnode.c
> @@ -629,7 +629,7 @@ struct hfs_bnode *hfs_bnode_create(struct hfs_btree *tree, u32 num)
> if (node) {
> pr_crit("new node %u already hashed?\n", num);
> WARN_ON(1);
> - return node;
> + return ERR_PTR(-EEXIST);
> }
> node = __hfs_bnode_create(tree, num);
> if (!node)
Looks good. Thank you for the fix.
Reviewed-by: Viacheslav Dubeyko <slava@dubeyko.com>
Thanks,
Slava.
prev parent reply other threads:[~2025-12-29 22:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-29 20:49 Shardul Bankar
2025-12-29 22:24 ` Viacheslav Dubeyko [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=08e7f7ef7da57448945a8d62160d2d7a67df2883.camel@ibm.com \
--to=slava.dubeyko@ibm.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=shardul.b@mpiricsoftware.com \
--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
all inboxes | Powered by JetHome®