ocfs2: validate i_refcount_loc when refcount flag is set
PATCH v3 1/1 ocfs2: validate i_refcount_loc when refcount flag is set
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.
---
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(+)
fs/ocfs2/inode.c +7 -0
@@ -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:
Signature · 1 line
2.43.0
Quoted 9 lines · Deepanshu Kartikey
Add validation in
ocfs2_validate_inode_block()to check that if an inode hasOCFS2_HAS_REFCOUNT_FLset, it must also have a validi_refcount_loc. A corrupted filesystem image can have this inconsistent state, which later triggers aBUG_ONinocfs2_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.
Quoted 6 lines
Reported-by [email protected]Tested-by [email protected]Signed-off-by Deepanshu Kartikey <[email protected]>
Quoted 25 lines
---
v3: Usele16_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(+)fs/ocfs2/inode.c +7
-0@@ -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: