]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: fix xfs_buf magic number endian checks
authorDarrick J. Wong <darrick.wong@oracle.com>
Mon, 6 May 2019 22:00:29 +0000 (18:00 -0400)
committerEric Sandeen <sandeen@redhat.com>
Mon, 6 May 2019 22:00:29 +0000 (18:00 -0400)
Source kernel commit: 15baadf72cedc2a09ea792c1fc59451502b55da2

Create a separate magic16 check function so that we don't run afoul of
static checkers.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/libxfs_io.h
libxfs/rdwr.c
libxfs/xfs_attr_leaf.c
libxfs/xfs_da_btree.c
libxfs/xfs_dir2_leaf.c
libxfs/xfs_dquot_buf.c
libxfs/xfs_inode_buf.c

index 569516c459a09fb4ac666e7276152b64da2198f4..79ffd4703baf0e8d7132a322832f9e79010bb69d 100644 (file)
@@ -41,7 +41,10 @@ struct xfs_buf_map {
 
 struct xfs_buf_ops {
        char *name;
-       uint32_t magic[2];      /* v4 and v5 on disk magic values */
+       union {
+               __be32 magic[2];        /* v4 and v5 on disk magic values */
+               __be16 magic16[2];      /* v4 and v5 on disk magic values */
+       };
        void (*verify_read)(struct xfs_buf *);
        void (*verify_write)(struct xfs_buf *);
        xfs_failaddr_t (*verify_struct)(struct xfs_buf *);
@@ -75,7 +78,8 @@ typedef struct xfs_buf {
 #endif
 } xfs_buf_t;
 
-bool xfs_verify_magic(struct xfs_buf *bp, uint32_t dmagic);
+bool xfs_verify_magic(struct xfs_buf *bp, __be32 dmagic);
+bool xfs_verify_magic16(struct xfs_buf *bp, __be16 dmagic);
 
 enum xfs_buf_flags_t { /* b_flags bits */
        LIBXFS_B_EXIT           = 0x0001,       /* ==LIBXFS_EXIT_ON_FAILURE */
index 450fed013037e7775e19955b6365ed47f6321526..e3ff58424fc4aa81b5d814bf317ca7a2c70a1e0a 100644 (file)
@@ -1332,7 +1332,7 @@ struct cache_operations libxfs_bcache_operations = {
 bool
 xfs_verify_magic(
        struct xfs_buf          *bp,
-       uint32_t                dmagic)
+       __be32                  dmagic)
 {
        struct xfs_mount        *mp = bp->b_target->bt_mount;
        int                     idx;
@@ -1343,6 +1343,25 @@ xfs_verify_magic(
        return dmagic == bp->b_ops->magic[idx];
 }
 
+/*
+ * Verify an on-disk magic value against the magic value specified in the
+ * verifier structure. The verifier magic is in disk byte order so the caller is
+ * expected to pass the value directly from disk.
+ */
+bool
+xfs_verify_magic16(
+       struct xfs_buf          *bp,
+       __be16                  dmagic)
+{
+       struct xfs_mount        *mp = bp->b_target->bt_mount;
+       int                     idx;
+
+       idx = xfs_sb_version_hascrc(&mp->m_sb);
+       if (unlikely(WARN_ON(!bp->b_ops || !bp->b_ops->magic16[idx])))
+               return false;
+       return dmagic == bp->b_ops->magic16[idx];
+}
+
 /*
  * Inode cache stubs.
  */
index ae6c0042a5f0e3795b31ec6428c1d59dc0bdd35d..679c7d0db800120387fa1068c08b72a1d438d7f6 100644 (file)
@@ -353,8 +353,8 @@ xfs_attr3_leaf_read_verify(
 
 const struct xfs_buf_ops xfs_attr3_leaf_buf_ops = {
        .name = "xfs_attr3_leaf",
-       .magic = { cpu_to_be16(XFS_ATTR_LEAF_MAGIC),
-                  cpu_to_be16(XFS_ATTR3_LEAF_MAGIC) },
+       .magic16 = { cpu_to_be16(XFS_ATTR_LEAF_MAGIC),
+                    cpu_to_be16(XFS_ATTR3_LEAF_MAGIC) },
        .verify_read = xfs_attr3_leaf_read_verify,
        .verify_write = xfs_attr3_leaf_write_verify,
        .verify_struct = xfs_attr3_leaf_verify,
index eb45b774b00cb85a41b0395bfca924e0aa2a2ea5..87b2bc37dfd5dc30660ab6b42cce97ee354acb4a 100644 (file)
@@ -124,7 +124,7 @@ xfs_da3_blkinfo_verify(
        struct xfs_mount        *mp = bp->b_target->bt_mount;
        struct xfs_da_blkinfo   *hdr = &hdr3->hdr;
 
-       if (!xfs_verify_magic(bp, hdr->magic))
+       if (!xfs_verify_magic16(bp, hdr->magic))
                return __this_address;
 
        if (xfs_sb_version_hascrc(&mp->m_sb)) {
@@ -136,7 +136,7 @@ xfs_da3_blkinfo_verify(
                        return __this_address;
        }
 
-       return 0;
+       return NULL;
 }
 
 static xfs_failaddr_t
@@ -269,8 +269,8 @@ xfs_da3_node_verify_struct(
 
 const struct xfs_buf_ops xfs_da3_node_buf_ops = {
        .name = "xfs_da3_node",
-       .magic = { cpu_to_be16(XFS_DA_NODE_MAGIC),
-                  cpu_to_be16(XFS_DA3_NODE_MAGIC) },
+       .magic16 = { cpu_to_be16(XFS_DA_NODE_MAGIC),
+                    cpu_to_be16(XFS_DA3_NODE_MAGIC) },
        .verify_read = xfs_da3_node_read_verify,
        .verify_write = xfs_da3_node_write_verify,
        .verify_struct = xfs_da3_node_verify_struct,
index d7e8ccefe28674f79ccbb2f1e08b68cd248e9294..d5ece2ccc6916f88de8ea13c9799fe5ba8b92160 100644 (file)
@@ -195,8 +195,8 @@ xfs_dir3_leaf_write_verify(
 
 const struct xfs_buf_ops xfs_dir3_leaf1_buf_ops = {
        .name = "xfs_dir3_leaf1",
-       .magic = { cpu_to_be16(XFS_DIR2_LEAF1_MAGIC),
-                  cpu_to_be16(XFS_DIR3_LEAF1_MAGIC) },
+       .magic16 = { cpu_to_be16(XFS_DIR2_LEAF1_MAGIC),
+                    cpu_to_be16(XFS_DIR3_LEAF1_MAGIC) },
        .verify_read = xfs_dir3_leaf_read_verify,
        .verify_write = xfs_dir3_leaf_write_verify,
        .verify_struct = xfs_dir3_leaf_verify,
@@ -204,8 +204,8 @@ const struct xfs_buf_ops xfs_dir3_leaf1_buf_ops = {
 
 const struct xfs_buf_ops xfs_dir3_leafn_buf_ops = {
        .name = "xfs_dir3_leafn",
-       .magic = { cpu_to_be16(XFS_DIR2_LEAFN_MAGIC),
-                  cpu_to_be16(XFS_DIR3_LEAFN_MAGIC) },
+       .magic16 = { cpu_to_be16(XFS_DIR2_LEAFN_MAGIC),
+                    cpu_to_be16(XFS_DIR3_LEAFN_MAGIC) },
        .verify_read = xfs_dir3_leaf_read_verify,
        .verify_write = xfs_dir3_leaf_write_verify,
        .verify_struct = xfs_dir3_leaf_verify,
index 9db73d4b3a363dd8ae022809aa49449cbc1fb108..8bcae16905b046b7448bbd0ecf6f33a384e891f0 100644 (file)
@@ -275,8 +275,8 @@ xfs_dquot_buf_write_verify(
 
 const struct xfs_buf_ops xfs_dquot_buf_ops = {
        .name = "xfs_dquot",
-       .magic = { cpu_to_be16(XFS_DQUOT_MAGIC),
-                  cpu_to_be16(XFS_DQUOT_MAGIC) },
+       .magic16 = { cpu_to_be16(XFS_DQUOT_MAGIC),
+                    cpu_to_be16(XFS_DQUOT_MAGIC) },
        .verify_read = xfs_dquot_buf_read_verify,
        .verify_write = xfs_dquot_buf_write_verify,
        .verify_struct = xfs_dquot_buf_verify_struct,
@@ -284,8 +284,8 @@ const struct xfs_buf_ops xfs_dquot_buf_ops = {
 
 const struct xfs_buf_ops xfs_dquot_buf_ra_ops = {
        .name = "xfs_dquot_ra",
-       .magic = { cpu_to_be16(XFS_DQUOT_MAGIC),
-                  cpu_to_be16(XFS_DQUOT_MAGIC) },
+       .magic16 = { cpu_to_be16(XFS_DQUOT_MAGIC),
+                    cpu_to_be16(XFS_DQUOT_MAGIC) },
        .verify_read = xfs_dquot_buf_readahead_verify,
        .verify_write = xfs_dquot_buf_write_verify,
 };
index 8b88e0e6487ad066f92ecd69a6a577c5d298b35f..108e541c55522fa8ce7dca365a290972f381005b 100644 (file)
@@ -93,7 +93,7 @@ xfs_inode_buf_verify(
 
                dip = xfs_buf_offset(bp, (i << mp->m_sb.sb_inodelog));
                unlinked_ino = be32_to_cpu(dip->di_next_unlinked);
-               di_ok = xfs_verify_magic(bp, dip->di_magic) &&
+               di_ok = xfs_verify_magic16(bp, dip->di_magic) &&
                        xfs_dinode_good_version(mp, dip->di_version) &&
                        xfs_verify_agino_or_null(mp, agno, unlinked_ino);
                if (unlikely(XFS_TEST_ERROR(!di_ok, mp,
@@ -142,16 +142,16 @@ xfs_inode_buf_write_verify(
 
 const struct xfs_buf_ops xfs_inode_buf_ops = {
        .name = "xfs_inode",
-       .magic = { cpu_to_be16(XFS_DINODE_MAGIC),
-                  cpu_to_be16(XFS_DINODE_MAGIC) },
+       .magic16 = { cpu_to_be16(XFS_DINODE_MAGIC),
+                    cpu_to_be16(XFS_DINODE_MAGIC) },
        .verify_read = xfs_inode_buf_read_verify,
        .verify_write = xfs_inode_buf_write_verify,
 };
 
 const struct xfs_buf_ops xfs_inode_buf_ra_ops = {
        .name = "xfs_inode_ra",
-       .magic = { cpu_to_be16(XFS_DINODE_MAGIC),
-                  cpu_to_be16(XFS_DINODE_MAGIC) },
+       .magic16 = { cpu_to_be16(XFS_DINODE_MAGIC),
+                    cpu_to_be16(XFS_DINODE_MAGIC) },
        .verify_read = xfs_inode_buf_readahead_verify,
        .verify_write = xfs_inode_buf_write_verify,
 };