]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: check leaf attribute block freemap in verifier
authorDarrick J. Wong <darrick.wong@oracle.com>
Fri, 5 Oct 2018 02:36:09 +0000 (21:36 -0500)
committerEric Sandeen <sandeen@redhat.com>
Fri, 5 Oct 2018 02:36:09 +0000 (21:36 -0500)
Source kernel commit: 65cfcc3897d7715a878b9f59736e7527ca27514f

Check the leaf attribute freemap when we're verifying the block.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/xfs_attr_leaf.c

index 30b6990b80d5f0ccd0fd81c2b4d466a5c98e402d..70a48e3a9dc2fe0914d015a32889b7408712b320 100644 (file)
@@ -239,6 +239,8 @@ xfs_attr3_leaf_verify(
        struct xfs_attr_leafblock       *leaf = bp->b_addr;
        struct xfs_perag                *pag = bp->b_pag;
        struct xfs_attr_leaf_entry      *entries;
+       uint16_t                        end;
+       int                             i;
 
        xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &ichdr, leaf);
 
@@ -284,6 +286,26 @@ xfs_attr3_leaf_verify(
        /* XXX: need to range check rest of attr header values */
        /* XXX: hash order check? */
 
+       /*
+        * Quickly check the freemap information.  Attribute data has to be
+        * aligned to 4-byte boundaries, and likewise for the free space.
+        */
+       for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; i++) {
+               if (ichdr.freemap[i].base > mp->m_attr_geo->blksize)
+                       return __this_address;
+               if (ichdr.freemap[i].base & 0x3)
+                       return __this_address;
+               if (ichdr.freemap[i].size > mp->m_attr_geo->blksize)
+                       return __this_address;
+               if (ichdr.freemap[i].size & 0x3)
+                       return __this_address;
+               end = ichdr.freemap[i].base + ichdr.freemap[i].size;
+               if (end < ichdr.freemap[i].base)
+                       return __this_address;
+               if (end > mp->m_attr_geo->blksize)
+                       return __this_address;
+       }
+
        return NULL;
 }