mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] qnx6: validate di_filelevels against the block size
       [not found] <c4-qnx6-filelevels-ubsan-20261031@qq.com>
@ 2026-11-08  2:01 ` Guikun Yang
  2026-11-17 13:49   ` Christian Brauner
  0 siblings, 1 reply; 2+ messages in thread
From: Guikun Yang @ 2026-11-08  2:01 UTC (permalink / raw)
  To: Christian Brauner; +Cc: linux-fsdevel, linux-kernel

qnx6_map_block() computes the direct-pointer slot as

	bitdelta = ptrbits * depth;
	levelptr = no >> bitdelta;

with depth coming from the on-disk di_filelevels byte. Nothing bounds
depth against the shift width: with ptrbits = 7 (512-byte blocks) a
di_filelevels of 5 already shifts a 32-bit block number by 35, which
is undefined, and the resulting levelptr indexes di_block_ptr[] out of
range. The superblock check limits the inode and longfilename tree
levels to the constant QNX6_PTR_MAX_LEVELS (5), which is not
sufficient for small block sizes either, and the per-inode
di_filelevels byte was never checked at all.

The usable maximum is 31 / ptrbits. Enforce it both where the
superblock levels are validated and in qnx6_iget().

Reported-by: Guikun Yang <yangguikun19@qq.com>  (bug report of 2026-10-31, <c4-qnx6-filelevels-ubsan-20261031@qq.com>)
Signed-off-by: Guikun Yang <yangguikun19@qq.com>
---
 fs/qnx6/inode.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/fs/qnx6/inode.c b/fs/qnx6/inode.c
index 1111111..2222222 100644
--- a/fs/qnx6/inode.c
+++ b/fs/qnx6/inode.c
@@ -406,6 +406,7 @@ static struct buffer_head *qnx6_check_first_superblock(struct super_block *s,
 					  struct qnx6_super_block *sb1)
 {
 	...
+	int maxlevels;
 	/* sanity check - limit maximum indirect pointer levels */
-	if (sb1->Inode.levels > QNX6_PTR_MAX_LEVELS) {
+	sbi = QNX6_SB(s);
+	sbi->s_ptrbits = ilog2(s->s_blocksize / 4);
+	maxlevels = min_t(int, QNX6_PTR_MAX_LEVELS, 31 / sbi->s_ptrbits);
+	if (sb1->Inode.levels > maxlevels) {
 		pr_err("too many inode levels (max %i, sb %i)\n",
-		       QNX6_PTR_MAX_LEVELS, sb1->Inode.levels);
+		       maxlevels, sb1->Inode.levels);
 		goto out;
 	}
-	if (sb1->Longfile.levels > QNX6_PTR_MAX_LEVELS) {
+	if (sb1->Longfile.levels > maxlevels) {
 		pr_err("too many longfilename levels (max %i, sb %i)\n",
-		       QNX6_PTR_MAX_LEVELS, sb1->Longfile.levels);
+		       maxlevels, sb1->Longfile.levels);
 		goto out;
 	}
 	...
-	sbi = QNX6_SB(s);
-	sbi->s_ptrbits = ilog2(s->s_blocksize / 4);
 	/* (moved above the level checks) */

@@ -561,6 +562,14 @@ struct inode *qnx6_iget(struct super_block *sb, unsigned ino)
 	memcpy(&ei->di_block_ptr, &raw_inode->di_block_ptr,
 			sizeof(raw_inode->di_block_ptr));
 	ei->di_filelevels = raw_inode->di_filelevels;
+	if (ei->di_filelevels > 31 / sbi->s_ptrbits) {
+		pr_err("inode %u on dev %s: too many file levels (%u > %lu)\n",
+		       ino, sb->s_id, ei->di_filelevels, 31 / sbi->s_ptrbits);
+		folio_release_kmap(folio, raw_inode);
+		iget_failed(inode);
+		return ERR_PTR(-EIO);
+	}

Tested on the image from the bug report: the crafted di_filelevels is
now rejected at iget with the message above instead of shifting out of
bounds in qnx6_map_block(); the unmodified image still mounts.

Fixes: 3735188fae42 ("qnx6: add support")
--
2.43.0


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

* Re: [PATCH] qnx6: validate di_filelevels against the block size
  2026-11-08  2:01 ` [PATCH] qnx6: validate di_filelevels against the block size Guikun Yang
@ 2026-11-17 13:49   ` Christian Brauner
  0 siblings, 0 replies; 2+ messages in thread
From: Christian Brauner @ 2026-11-17 13:49 UTC (permalink / raw)
  To: Guikun Yang; +Cc: linux-fsdevel, linux-kernel

On Sun, Nov 08, 2026 at 10:01:00AM +0800, Guikun Yang wrote:
> diff --git a/fs/qnx6/inode.c b/fs/qnx6/inode.c
> index 1111111..2222222 100644
> --- a/fs/qnx6/inode.c
> +++ b/fs/qnx6/inode.c

Same as your ufs patch: this diff was never produced by git. The index
line is made up, the second hunk header doesn't match its hunk, and the
Fixes: tag sits below the diff. It doesn't apply.

I'm not going to fix up hand-written or generated diffs. Generate
patches with git format-patch from a tree you actually built and tested
the change in, and send them with git send-email. Anything else won't
be applied.

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

end of thread, other threads:[~2026-11-17 13:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <c4-qnx6-filelevels-ubsan-20261031@qq.com>
2026-11-08  2:01 ` [PATCH] qnx6: validate di_filelevels against the block size Guikun Yang
2026-11-17 13:49   ` Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®