]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: validate explicit directory block buffer owners
authorDarrick J. Wong <djwong@kernel.org>
Mon, 29 Jul 2024 23:22:38 +0000 (16:22 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 30 Jul 2024 00:01:00 +0000 (17:01 -0700)
Source kernel commit: 29b41ce919b7f0b0c2220e088e450d9b132bec36

Port the existing directory block header checking function to accept an
owner number instead of an xfs_inode, then update the callsites to use
xfs_da_args.owner when possible.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
db/namei.c
libxfs/xfs_dir2.h
libxfs/xfs_dir2_block.c
libxfs/xfs_dir2_priv.h
libxfs/xfs_exchmaps.c

index d2541b78ae33735dcab799a098b1e5f3e261fdf3..303ca3448f60f487afbc9dcbcb2925f88f4ca924 100644 (file)
@@ -337,7 +337,7 @@ list_blockdir(
        unsigned int            end;
        int                     error;
 
-       error = xfs_dir3_block_read(NULL, dp, &bp);
+       error = xfs_dir3_block_read(NULL, dp, args->owner, &bp);
        if (error)
                return error;
 
index d623bfdcd421850600e38c1dfc7e68a82670e8d8..eb3a5c35025b56039cad7d47816737ffc73ff611 100644 (file)
@@ -103,6 +103,7 @@ extern int xfs_dir_ino_validate(struct xfs_mount *mp, xfs_ino_t ino);
 
 xfs_failaddr_t xfs_dir3_leaf_header_check(struct xfs_buf *bp, xfs_ino_t owner);
 xfs_failaddr_t xfs_dir3_data_header_check(struct xfs_buf *bp, xfs_ino_t owner);
+xfs_failaddr_t xfs_dir3_block_header_check(struct xfs_buf *bp, xfs_ino_t owner);
 
 extern const struct xfs_buf_ops xfs_dir3_block_buf_ops;
 extern const struct xfs_buf_ops xfs_dir3_leafn_buf_ops;
index 6107e01cafc7fb943bc33b0981409c80e781cfe1..82da0d3275e36632a21bd3e119eceedab44f7857 100644 (file)
@@ -112,17 +112,20 @@ const struct xfs_buf_ops xfs_dir3_block_buf_ops = {
        .verify_struct = xfs_dir3_block_verify,
 };
 
-static xfs_failaddr_t
+xfs_failaddr_t
 xfs_dir3_block_header_check(
-       struct xfs_inode        *dp,
-       struct xfs_buf          *bp)
+       struct xfs_buf          *bp,
+       xfs_ino_t               owner)
 {
-       struct xfs_mount        *mp = dp->i_mount;
+       struct xfs_mount        *mp = bp->b_mount;
 
        if (xfs_has_crc(mp)) {
                struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr;
 
-               if (be64_to_cpu(hdr3->owner) != dp->i_ino)
+               if (hdr3->magic != cpu_to_be32(XFS_DIR3_BLOCK_MAGIC))
+                       return __this_address;
+
+               if (be64_to_cpu(hdr3->owner) != owner)
                        return __this_address;
        }
 
@@ -133,6 +136,7 @@ int
 xfs_dir3_block_read(
        struct xfs_trans        *tp,
        struct xfs_inode        *dp,
+       xfs_ino_t               owner,
        struct xfs_buf          **bpp)
 {
        struct xfs_mount        *mp = dp->i_mount;
@@ -145,7 +149,7 @@ xfs_dir3_block_read(
                return err;
 
        /* Check things that we can't do in the verifier. */
-       fa = xfs_dir3_block_header_check(dp, *bpp);
+       fa = xfs_dir3_block_header_check(*bpp, owner);
        if (fa) {
                __xfs_buf_mark_corrupt(*bpp, fa);
                xfs_trans_brelse(tp, *bpp);
@@ -380,7 +384,7 @@ xfs_dir2_block_addname(
        tp = args->trans;
 
        /* Read the (one and only) directory block into bp. */
-       error = xfs_dir3_block_read(tp, dp, &bp);
+       error = xfs_dir3_block_read(tp, dp, args->owner, &bp);
        if (error)
                return error;
 
@@ -695,7 +699,7 @@ xfs_dir2_block_lookup_int(
        dp = args->dp;
        tp = args->trans;
 
-       error = xfs_dir3_block_read(tp, dp, &bp);
+       error = xfs_dir3_block_read(tp, dp, args->owner, &bp);
        if (error)
                return error;
 
index 879aa2e9fd73041e13f7c41e513529fa882e4c83..adbc544c9befab3167b9ed7933edf21ac4b861a7 100644 (file)
@@ -50,8 +50,8 @@ extern int xfs_dir_cilookup_result(struct xfs_da_args *args,
 
 
 /* xfs_dir2_block.c */
-extern int xfs_dir3_block_read(struct xfs_trans *tp, struct xfs_inode *dp,
-                              struct xfs_buf **bpp);
+int xfs_dir3_block_read(struct xfs_trans *tp, struct xfs_inode *dp,
+               xfs_ino_t owner, struct xfs_buf **bpp);
 extern int xfs_dir2_block_addname(struct xfs_da_args *args);
 extern int xfs_dir2_block_lookup(struct xfs_da_args *args);
 extern int xfs_dir2_block_removename(struct xfs_da_args *args);
index 21c501aab3e8b25bb9c6a4d60a197bf175a8ae08..71408d7132fa1705682f369a6e8513b83f20bd9a 100644 (file)
@@ -473,7 +473,7 @@ xfs_exchmaps_dir_to_sf(
        if (!isblock)
                return 0;
 
-       error = xfs_dir3_block_read(tp, xmi->xmi_ip2, &bp);
+       error = xfs_dir3_block_read(tp, xmi->xmi_ip2, xmi->xmi_ip2->i_ino, &bp);
        if (error)
                return error;