[PATCH v4 1/6] qnx6: validate di_filelevels in qnx6_iget() before accessing level pointers
From: Hui Peng
Date: Tue Sep 29 2026 - 23:16:48 EST
In qnx6_iget(), raw_inode->di_filelevels is read from disk without upper
bounds checking. If raw_inode->di_filelevels exceeds QNX6_PTR_MAX_LEVELS
(defined as 5 in include/linux/qnx6_fs.h), qnx6_block_map() performs
out-of-bounds reads past di_block_ptr when dereferencing indirect tree
levels.
Validate raw_inode->di_filelevels against QNX6_PTR_MAX_LEVELS in
qnx6_iget() and return -EIO if it exceeds 5.
Tested in QEMU against tip of mainline commit 62f4c998b297 ("Merge tag 'parisc-for-7.3-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux")
using a loop-device reproducer mounting a crafted QNX6 image with
di_filelevels = 20: on the unfixed kernel, mounting triggered a
buffer_head refcount underflow warning ("VFS: brelse: Trying to free
free buffer"); whereas with this fix applied, qnx6_iget() cleanly rejects
the corrupted inode with -EIO and logs "qnx6: bad filelevels 20 (max 5) on
dev loop0, inode 1".
Fixes: 5d026c724220 ("fs: initial qnx6fs addition")
Cc: stable@xxxxxxxxxxxxxxx
Assisted-by: LLM
Signed-off-by: Hui Peng <benquike@xxxxxxxxx>
---
Changes in v4:
- Rebased cleanly onto upstream mainline commit 62f4c998b297.
- Added QEMU test procedure and verification details in commit message body.
- Updated commit description to state QNX6_PTR_MAX_LEVELS is 5 as noted
by Matthias Goergens.
fs/qnx6/inode.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/fs/qnx6/inode.c b/fs/qnx6/inode.c
index a15bb03f0ec3..e61c33f2e146 100644
--- a/fs/qnx6/inode.c
+++ b/fs/qnx6/inode.c
@@ -561,6 +561,14 @@ struct inode *qnx6_iget(struct super_block *sb, unsigned ino)
sizeof(raw_inode->di_block_ptr));
ei->di_filelevels = raw_inode->di_filelevels;
+ if (ei->di_filelevels > QNX6_PTR_MAX_LEVELS) {
+ pr_err("bad filelevels %u (max %u) on dev %s, inode %u\n",
+ ei->di_filelevels, QNX6_PTR_MAX_LEVELS, sb->s_id, ino);
+ folio_release_kmap(folio, raw_inode);
+ iget_failed(inode);
+ return ERR_PTR(-EIO);
+ }
+
if (S_ISREG(inode->i_mode)) {
inode->i_fop = &generic_ro_fops;
inode->i_mapping->a_ops = &qnx6_aops;
--
2.55.0.1082.g2b9226bbc0-goog