Skip to contentSkip to conversation

hfs: return -EIO instead of BUG() in hfs_write_inode()

PATCH Superseded David Maximiliano Hermitte 2 participants 2 messages Jun 6

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hfs: return -EIO instead of BUG() in hfs_write_inode()

hfs: return -EIO instead of BUG() in hfs_write_inode()

A corrupted or otherwise malformed HFS filesystem image can reach the default case in hfs_write_inode(). The current code calls BUG() there, which turns an on-disk filesystem condition into a kernel crash.

Return -EIO instead. The function already has an error-return path at that location, so this preserves the existing failure semantics while avoiding a reachable kernel BUG.

The issue is reproducible with the public syzbot C reproducer linked below. Before this change, the reproducer triggers a kernel BUG at fs/hfs/inode.c with RIP in hfs_write_inode(). After this change, the same reproducer no longer triggers kernel BUG, hfs_write_inode, KASAN, Oops, Call Trace, or RIP evidence in the validation window.

---
 fs/hfs/inode.c | 1 -
 1 file changed, 1 deletion(-)
fs/hfs/inode.c +0 -1
index 89b33a9d46d5..4192f660b64f 100644
@@ -471,7 +471,6 @@ int hfs_write_inode(struct inode *inode, struct writeback_control *wbc)
 			hfs_btree_write(HFS_SB(inode->i_sb)->cat_tree);
 			return 0;
 		default:
-			BUG();
 			return -EIO;
 		}
 	}
#1 lore raw
Quoted 29 lines · David Maximiliano Hermitte

hfs: return -EIO instead of BUG() in hfs_write_inode()

A corrupted or otherwise malformed HFS filesystem image can reach the default case in hfs_write_inode(). The current code calls BUG() there, which turns an on-disk filesystem condition into a kernel crash.

Return -EIO instead. The function already has an error-return path at that location, so this preserves the existing failure semantics while avoiding a reachable kernel BUG.

The issue is reproducible with the public syzbot C reproducer linked below. Before this change, the reproducer triggers a kernel BUG at fs/hfs/inode.c with RIP in hfs_write_inode(). After this change, the same reproducer no longer triggers kernel BUG, hfs_write_inode, KASAN, Oops, Call Trace, or RIP evidence in the validation window.

---
 fs/hfs/inode.c | 1 -
 1 file changed, 1 deletion(-)
fs/hfs/inode.c +0 -0
index 89b33a9d46d5..4192f660b64f 100644

fs/hfs/inode.c int hfs_write_inode(struct inode *inode, struct writeback_control *wbc) · line 474

Quoted 5 lines
fs/hfs/inode.c +0 -1
@@ -471,7 +471,6 @@ int hfs_write_inode(struct inode *inode, struct writeback_control *wbc)
 			hfs_btree_write(HFS_SB(inode->i_sb)->cat_tree);
 			return 0;
 		default:
-			BUG();
 			return -EIO;

If it's a metadata corruption, shouldn't you return EFSCORRUPTED like the other major filesystems?

--D

Quoted 3 lines
fs/hfs/inode.c +0 -0
 		}
 	}