jfs: fix array-index-out-of-bounds in diAllocBit()
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.
Reported-by [email protected]
Signed-off-by Haotian Zhang <[email protected]>
--- fs/jfs/jfs_imap.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/jfs/jfs_imap.c +8 -0
@@ -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