Skip to contentSkip to conversation

jfs: fix array-index-out-of-bounds in diAllocBit()

PATCH New Haotian Zhang 1 participant 1 message Dec 31, 2025 JFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 jfs: fix array-index-out-of-bounds in diAllocBit()

syzbot reported an array-index-out-of-bounds access in diAllocBit(), where im_agctl[] is indexed by agno derived from on-disk agstart without validation.

agno is computed via BLKTOAG() and may become negative or exceed MAXAG when the filesystem metadata is corrupted, leading to an out-of-bounds access to imap->im_agctl[].

Validate agno before using it and abort the operation if the value is invalid.

---
 fs/jfs/jfs_imap.c | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/jfs/jfs_imap.c +8 -0
index ecb8e05b8b84..cc72fcaa94e2 100644
@@ -2044,6 +2044,14 @@ static int diAllocBit(struct inomap * imap, struct iag * iagp, int ino)
 	 * the extent.
 	 */
 	agno = BLKTOAG(le64_to_cpu(iagp->agstart), JFS_SBI(imap->im_ipimap->i_sb));
+	if (agno >= MAXAG || agno < 0) {
+		if (amp)
+			release_metapage(amp);
+		if (bmp)
+			release_metapage(bmp);
+		return -EIO;
+	}
+
 	extno = ino >> L2INOSPEREXT;
 	bitno = ino & (INOSPEREXT - 1);
 
Signature · 1 line
2.43.0