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

From: Tigran Aivazian
Date: Fri Oct 10 2025 - 12:13:12 EST


On Fri, 10 Oct 2025 at 16:44, Tigran Aivazian <aivazian.tigran@xxxxxxxxx> wrote:
> Thank you, but logically this code should simply be inside the "else"
> clause of the previous checks, which already check for BFS_VDIR and
> BFS_VREG, I think.

Actually, I would first of all print the value of vtype, because that
is where the
corruption comes from, and print i_mode as %07o, not %04o. So, I would
suggest a patch like this.

Reviewed-by: Tigran Aivazian <aivazian.tigran@xxxxxxxxx>

diff -urN a/fs/bfs/inode.c b/fs/bfs/inode.c
--- a/fs/bfs/inode.c 2025-10-10 16:52:40.968468556 +0100
+++ b/fs/bfs/inode.c 2025-10-10 16:54:09.904052351 +0100
@@ -71,6 +71,11 @@
inode->i_op = &bfs_file_inops;
inode->i_fop = &bfs_file_operations;
inode->i_mapping->a_ops = &bfs_aops;
+ } else {
+ brelse(bh);
+ printf("Bad file type vtype=%u mode=0%07o %s:%08lx\n",
+ le32_to_cpu(di->i_vtype), inode->i_mode,
inode->i_sb->s_id, ino);
+ goto error;
}

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