]> git-server-git.apps.pok.os.sepia.ceph.com Git - xfsprogs-dev.git/commitdiff
xfs: zero entire directory data block header region at init
authorYuto Ohnuki <ytohnuki@amazon.com>
Thu, 2 Jul 2026 20:00:05 +0000 (13:00 -0700)
committerAndrey Albershteyn <aalbersh@kernel.org>
Wed, 8 Jul 2026 08:40:42 +0000 (10:40 +0200)
Source kernel commit: 00dd8d7ec5253c6273023a0fd6dc08683e0bdfef

xfs_dir3_data_init currently zeroes only the xfs_dir3_blk_hdr portion of
the directory data block header, then manually initializes the bestfree
entries in a loop. This leaves the pad field in xfs_dir3_data_hdr
uninitialized and requires explicit zeroing of each bestfree slot.

Zero the entire header region (geo->data_entry_offset bytes)
unconditionally before setting individual fields. This covers all
current and future header fields, all padding (implicit and explicit),
and the bestfree array, so the manual zeroing loop for bestfree can be
removed.

Suggested-by: Dave Chinner <dgc@kernel.org>
Signed-off-by: Yuto Ohnuki <ytohnuki@amazon.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
libxfs/xfs_dir2_data.c

index 1fb43cdfdd6d04b4635fb94a7d688d5fc5df67df..fb5e4b021217a50f6c8689669c84222bd78f6056 100644 (file)
@@ -725,7 +725,6 @@ xfs_dir3_data_init(
        struct xfs_dir2_data_unused     *dup;
        struct xfs_dir2_data_free       *bf;
        int                             error;
-       int                             i;
 
        /*
         * Get the buffer set up for the block.
@@ -738,13 +737,16 @@ xfs_dir3_data_init(
        xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DIR_DATA_BUF);
 
        /*
-        * Initialize the header.
+        * Initialize the whole directory header region to zero
+        * so that all padding, bestfree entries, and any
+        * future header fields are clean.
         */
        hdr = bp->b_addr;
+       memset(hdr, 0, geo->data_entry_offset);
+
        if (xfs_has_crc(mp)) {
                struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr;
 
-               memset(hdr3, 0, sizeof(*hdr3));
                hdr3->magic = cpu_to_be32(XFS_DIR3_DATA_MAGIC);
                hdr3->blkno = cpu_to_be64(xfs_buf_daddr(bp));
                hdr3->owner = cpu_to_be64(args->owner);
@@ -756,10 +758,6 @@ xfs_dir3_data_init(
        bf = xfs_dir2_data_bestfree_p(mp, hdr);
        bf[0].offset = cpu_to_be16(geo->data_entry_offset);
        bf[0].length = cpu_to_be16(geo->blksize - geo->data_entry_offset);
-       for (i = 1; i < XFS_DIR2_DATA_FD_COUNT; i++) {
-               bf[i].length = 0;
-               bf[i].offset = 0;
-       }
 
        /*
         * Set up an unused entry for the block's body.