* [PATCH v3] ocfs2: validate i_refcount_loc when refcount flag is set
@ 2025-12-12 5:58 Deepanshu Kartikey
2025-12-12 7:13 ` Joseph Qi
0 siblings, 1 reply; 2+ messages in thread
From: Deepanshu Kartikey @ 2025-12-12 5:58 UTC (permalink / raw)
To: mark, jlbec, joseph.qi, heming.zhao
Cc: ocfs2-devel, linux-kernel, Deepanshu Kartikey,
syzbot+6d832e79d3efe1c46743
Add validation in ocfs2_validate_inode_block() to check that if an
inode has OCFS2_HAS_REFCOUNT_FL set, it must also have a valid
i_refcount_loc. A corrupted filesystem image can have this inconsistent
state, which later triggers a BUG_ON in ocfs2_remove_refcount_tree()
when the inode is being wiped during unlink.
Catch this corruption early during inode validation to fail gracefully
instead of crashing the kernel.
Reported-by: syzbot+6d832e79d3efe1c46743@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=6d832e79d3efe1c46743
Tested-by: syzbot+6d832e79d3efe1c46743@syzkaller.appspotmail.com
Link: https://lore.kernel.org/all/20251208084407.3021466-1-kartikey406@gmail.com/T/ [v1]
Link: https://lore.kernel.org/all/20251212045646.9988-1-kartikey406@gmail.com/T/ [v2]
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
---
v3: Use le16_to_cpu() for consistency with other checks (Joseph Qi)
v2: Shortened error message to fix line length (Heming Zhao)
---
fs/ocfs2/inode.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/fs/ocfs2/inode.c b/fs/ocfs2/inode.c
index 78f81950c9ee..1019ca80760c 100644
--- a/fs/ocfs2/inode.c
+++ b/fs/ocfs2/inode.c
@@ -1484,6 +1484,13 @@ int ocfs2_validate_inode_block(struct super_block *sb,
goto bail;
}
+ if ((le16_to_cpu(di->i_dyn_features) & OCFS2_HAS_REFCOUNT_FL) &&
+ !di->i_refcount_loc) {
+ rc = ocfs2_error(sb, "Inode #%llu has refcount flag but no i_refcount_loc\n",
+ (unsigned long long)bh->b_blocknr);
+ goto bail;
+ }
+
rc = 0;
bail:
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v3] ocfs2: validate i_refcount_loc when refcount flag is set
2025-12-12 5:58 [PATCH v3] ocfs2: validate i_refcount_loc when refcount flag is set Deepanshu Kartikey
@ 2025-12-12 7:13 ` Joseph Qi
0 siblings, 0 replies; 2+ messages in thread
From: Joseph Qi @ 2025-12-12 7:13 UTC (permalink / raw)
To: Deepanshu Kartikey, mark, jlbec, heming.zhao, akpm
Cc: ocfs2-devel, linux-kernel, syzbot+6d832e79d3efe1c46743
On 2025/12/12 13:58, Deepanshu Kartikey wrote:
> Add validation in ocfs2_validate_inode_block() to check that if an
> inode has OCFS2_HAS_REFCOUNT_FL set, it must also have a valid
> i_refcount_loc. A corrupted filesystem image can have this inconsistent
> state, which later triggers a BUG_ON in ocfs2_remove_refcount_tree()
> when the inode is being wiped during unlink.
>
> Catch this corruption early during inode validation to fail gracefully
> instead of crashing the kernel.
>
> Reported-by: syzbot+6d832e79d3efe1c46743@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=6d832e79d3efe1c46743
> Tested-by: syzbot+6d832e79d3efe1c46743@syzkaller.appspotmail.com
> Link: https://lore.kernel.org/all/20251208084407.3021466-1-kartikey406@gmail.com/T/ [v1]
> Link: https://lore.kernel.org/all/20251212045646.9988-1-kartikey406@gmail.com/T/ [v2]
> Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
> ---
> v3: Use le16_to_cpu() for consistency with other checks (Joseph Qi)
> v2: Shortened error message to fix line length (Heming Zhao)
> ---
> fs/ocfs2/inode.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/fs/ocfs2/inode.c b/fs/ocfs2/inode.c
> index 78f81950c9ee..1019ca80760c 100644
> --- a/fs/ocfs2/inode.c
> +++ b/fs/ocfs2/inode.c
> @@ -1484,6 +1484,13 @@ int ocfs2_validate_inode_block(struct super_block *sb,
> goto bail;
> }
>
> + if ((le16_to_cpu(di->i_dyn_features) & OCFS2_HAS_REFCOUNT_FL) &&
> + !di->i_refcount_loc) {
> + rc = ocfs2_error(sb, "Inode #%llu has refcount flag but no i_refcount_loc\n",
> + (unsigned long long)bh->b_blocknr);
> + goto bail;
> + }
> +
> rc = 0;
>
> bail:
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-12-12 7:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-12 5:58 [PATCH v3] ocfs2: validate i_refcount_loc when refcount flag is set Deepanshu Kartikey
2025-12-12 7:13 ` Joseph Qi
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®