7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Darrick J. Wong commit 017dd7a84ff4cd2275eb62f4ee6d63c705bac107 upstream. LOLLM noticed a buffer overrun if the xattr scrubber encounters a file with a shortform attr fork with sf->count > 0 but if_bytes == sizeof(struct xfs_attr_sf_hdr). Basically, we have enough data to have a header with a nonzero count, but no space for any of those shortform entries. In this case, the xfs_attr_sf_nextentry() call will run off the end of if_data and blow up. Cc: stable@vger.kernel.org # v6.4 Fixes: ae0506eba78fd1 ("xfs: check used space of shortform xattr structures") Signed-off-by: Darrick J. Wong Assisted-by: LOLLM # finding obvious bugs Reviewed-by: Christoph Hellwig Signed-off-by: Carlos Maiolino Signed-off-by: Greg Kroah-Hartman --- fs/xfs/scrub/attr.c | 11 +++++++++-- fs/xfs/scrub/attr_repair.c | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) --- a/fs/xfs/scrub/attr.c +++ b/fs/xfs/scrub/attr.c @@ -590,12 +590,17 @@ xchk_xattr_check_sf( } for (i = 0; i < sf->count; i++) { - unsigned char *name = sfe->nameval; - unsigned char *value = &sfe->nameval[sfe->namelen]; + unsigned char *name; + unsigned char *value; if (xchk_should_terminate(sc, &error)) return error; + if ((unsigned char *)(sfe + 1) >= end) { + xchk_fblock_set_corrupt(sc, XFS_ATTR_FORK, 0); + break; + } + next = xfs_attr_sf_nextentry(sfe); if ((unsigned char *)next > end) { xchk_fblock_set_corrupt(sc, XFS_ATTR_FORK, 0); @@ -618,6 +623,7 @@ xchk_xattr_check_sf( break; } + name = sfe->nameval; if (!xchk_xattr_set_map(sc, ab->usedmap, (char *)name - (char *)sf, sfe->namelen)) { @@ -625,6 +631,7 @@ xchk_xattr_check_sf( break; } + value = &sfe->nameval[sfe->namelen]; if (!xchk_xattr_set_map(sc, ab->usedmap, (char *)value - (char *)sf, sfe->valuelen)) { --- a/fs/xfs/scrub/attr_repair.c +++ b/fs/xfs/scrub/attr_repair.c @@ -477,6 +477,9 @@ xrep_xattr_recover_sf( if (xchk_should_terminate(sc, &error)) return error; + if ((unsigned char *)(sfe + 1) >= end) + break; + next = xfs_attr_sf_nextentry(sfe); if ((unsigned char *)next > end) break;