[PATCH] bfs: Verify inode mode when loading from disk

From: Tetsuo Handa
Date: Fri Oct 10 2025 - 10:24:57 EST


The inode mode loaded from corrupted disk can be invalid.
Since Boot File System supports only root directory and regular files [1],
reject inodes which are neither directory nor regular file.

Link: https://martin.hinner.info/fs/bfs/ [1]
Reported-by: syzbot+895c23f6917da440ed0d@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=895c23f6917da440ed0d
Signed-off-by: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx>
---
Since reproducer for BFS is not yet found, I can't test this patch.
But I assume this is the only location which can store bogus file mode.

fs/bfs/inode.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/fs/bfs/inode.c b/fs/bfs/inode.c
index 1d41ce477df5..6cc552f77d51 100644
--- a/fs/bfs/inode.c
+++ b/fs/bfs/inode.c
@@ -72,6 +72,12 @@ struct inode *bfs_iget(struct super_block *sb, unsigned long ino)
inode->i_fop = &bfs_file_operations;
inode->i_mapping->a_ops = &bfs_aops;
}
+ if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode)) {
+ brelse(bh);
+ printf("Bad file type (0%04o) %s:%08lx.\n",
+ inode->i_mode, inode->i_sb->s_id, ino);
+ goto error;
+ }

BFS_I(inode)->i_sblock = le32_to_cpu(di->i_sblock);
BFS_I(inode)->i_eblock = le32_to_cpu(di->i_eblock);
--
2.47.3