Skip to contentSkip to conversation

qnx6: keep the top-level pointer index unsigned in qnx6_block_map()

PATCH Applied Matthias Goergens 2 participants 2 messages Sep 27 – Oct 21

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qnx6: keep the top-level pointer index unsigned in qnx6_block_map()

qnx6_block_map()'s top-level index is levelptr = no >> bitdelta, computed from the 32-bit block number no. With bitdelta == 0 (a depth-0 tree) that is just no, and assigning a value above INT_MAX to the int levelptr narrows it negative; the levelptr > QNX6_NO_DIRECT_POINTERS - 1 check then passes and di_block_ptr[levelptr] is indexed out of bounds (UBSan array-index reports index -16777216 and -8 on crafted images).

Reachable with a crafted inode whose i_size is large enough that mpage asks for block numbers beyond 2^31.

The only other assignment to levelptr, in the loop, is masked to ptrbits and so is never negative; making levelptr unsigned leaves that path unchanged and makes the bounds check reject the large values.

This is independent of bitdelta itself being too large to shift by (depth * ptrbits >= 32), a separate bug in the same function that a still-pending patch of mine guards against; that guard leaves the result of a valid shift assigned to the same int levelptr, so it does not fix the narrowing this patch does.

Fixes 5d026c724220 ("fs: initial qnx6fs addition")
---
 fs/qnx6/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/qnx6/inode.c +1 -1
index 6de49333acad..7df3eed5142d 100644
@@ -117,7 +117,7 @@ static unsigned qnx6_block_map(struct inode *inode, unsigned no)
 	unsigned block = 0;
 	struct buffer_head *bh;
 	__fs32 ptr;
-	int levelptr;
+	unsigned int levelptr;
 	int ptrbits = sbi->s_ptrbits;
 	int bitdelta;
 	u32 mask = (1 << ptrbits) - 1;
Signature · 1 line
2.55.0
maintainer Applied
#1 lore raw
Quoted 1 line · Matthias Goergens

qnx6: keep the top-level pointer index unsigned in qnx6_block_map()

Applied to the vfs-7.5.misc branch of the vfs/vfs.git tree. Patches in the vfs-7.5.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-7.5.misc

[1/1] qnx6: keep the top-level pointer index unsigned in qnx6_block_map()

      https://git.kernel.org/vfs/vfs/c/345a23b25153