linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bfs: Verify inode mode when loading from disk
@ 2025-10-10 14:24 Tetsuo Handa
  2025-10-10 15:44 ` Tigran Aivazian
  0 siblings, 1 reply; 8+ messages in thread
From: Tetsuo Handa @ 2025-10-10 14:24 UTC (permalink / raw)
  To: Tigran A. Aivazian, LKML, linux-fsdevel

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@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=895c23f6917da440ed0d
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
---
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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-10-13  6:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-10 14:24 [PATCH] bfs: Verify inode mode when loading from disk Tetsuo Handa
2025-10-10 15:44 ` Tigran Aivazian
2025-10-10 16:06   ` Tigran Aivazian
2025-10-10 23:19     ` Tetsuo Handa
2025-10-11 16:29       ` Tigran Aivazian
2025-10-12  7:34         ` Tetsuo Handa
2025-10-12 17:02           ` Tigran Aivazian
2025-10-13  5:44             ` [PATCH v2] bfs: Reconstruct file type " Tetsuo Handa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).