Skip to contentSkip to conversation

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

PATCH In review David Maximiliano Hermitte 3 participants 4 messages Jun 7 – Jun 9

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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

hfs: return -EFSCORRUPTED 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 -EFSCORRUPTED instead. This reports filesystem metadata corruption consistently with other major filesystems 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.

---
Changes in v2:
- Return -EFSCORRUPTED for metadata corruption, as suggested by Darrick.

 fs/hfs/inode.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/hfs/inode.c +1 -2
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;
+			return -EFSCORRUPTED;
 		}
 	}
#1 lore raw
Quoted 9 lines · David Maximiliano Hermitte

hfs: return -EFSCORRUPTED 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 -EFSCORRUPTED instead. This reports filesystem metadata corruption consistently with other major filesystems while avoiding a reachable kernel BUG.

How is -EFSCORRUPTED handled now? The BUG() marks a situation that is pretty bad, so maybe you don't want to continue to do everything as usual (although a BUG() is very harsh). At the very least, there should be a warning.

Quoted 31 lines

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.

---
Changes in v2:
- Return -EFSCORRUPTED for metadata corruption, as suggested by Darrick.

 fs/hfs/inode.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/hfs/inode.c +1 -2
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;
+			return -EFSCORRUPTED;
 		}
 	}
#2 lore raw
In reply to David Maximiliano Hermitte

Thank you for the review.

That makes sense. I agree that replacing the BUG() with a silent return is probably not enough if this state indicates serious filesystem corruption.

At this point I would prefer not to slow down the fix by guessing the best HFS/VFS error-handling policy. My main goal was to report and narrow down the reachable BUG() site and provide a minimal tested patch showing that the crash can be avoided.

If someone with more HFS/VFS experience wants to take over the final form of the fix, I would be happy with that. I can also help retest a proposed v3 against the public syzbot reproducer.

Thanks again for taking a look.

#3 lore raw
Quoted 11 lines · David Maximiliano Hermitte

Thank you for the review.

That makes sense. I agree that replacing the BUG() with a silent return is probably not enough if this state indicates serious filesystem corruption.

At this point I would prefer not to slow down the fix by guessing the best HFS/VFS error-handling policy. My main goal was to report and narrow down the reachable BUG() site and provide a minimal tested patch showing that the crash can be avoided.

Quoted 5 lines

If someone with more HFS/VFS experience wants to take over the final form of the fix, I would be happy with that. I can also help retest a proposed v3 against the public syzbot reproducer.

Thanks again for taking a look.

If you have corrupted HFS volume, then the issue should be resolved in mount logic. I suspect that we discussed this issue multiple times. But I still don't see that anybody can finish this work.

Thanks,
Slava.