]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
mkfs: fix hardlink detection in directory import code
authorDarrick J. Wong <djwong@kernel.org>
Mon, 8 Jun 2026 17:17:09 +0000 (10:17 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Thu, 2 Jul 2026 19:38:24 +0000 (12:38 -0700)
There's a serious problem in the hardlink detection code in the new mkfs
protofile functionality that copies a directory tree into the new
filesystem.  It's been long established that hardlinks can only be
detected by comparing st_ino *and* st_dev, but the new code doesn't do
that.  Fix the detector.

Cc: <linux-xfs@vger.kernel.org> # v6.17.0
Fixes: 8a4ea72724930c ("proto: add ability to populate a filesystem from a directory")
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
mkfs/proto.c

index e435f2e6d42b4a95852ea65cfd0b24c713fd0fad..dd47e41d833e5a2e60c134ca8c40d75713a1f91a 100644 (file)
@@ -1314,6 +1314,7 @@ writetimestamps(
 }
 
 struct hardlink {
+       dev_t           src_dev;
        ino_t           src_ino;
        xfs_ino_t       dst_ino;
 };
@@ -1368,7 +1369,8 @@ get_hardlink_dst_inode(
        size_t                  i = 0;
 
        for (; i < hardlink_tracker.count; i++, h++) {
-               if (h->src_ino == filestat->st_ino)
+               if (h->src_dev == filestat->st_dev &&
+                   h->src_ino == filestat->st_ino)
                        return h->dst_ino;
        }
        return 0;
@@ -1406,6 +1408,7 @@ track_hardlink_inode(
        }
 
        h = &hardlink_tracker.entries[hardlink_tracker.count];
+       h->src_dev = filestat->st_dev;
        h->src_ino = filestat->st_ino;
        h->dst_ino = dst_ino;
        hardlink_tracker.count++;