mdrestore: fix restore_v2() superblock length check
v2 cover mdrestore: fix restore_v2() superblock length check
Hi all,
On s390x (big-endian), running xfstests -g metadump currently fails 6 out of 9 tests. The failure is triggered by the superblock extent-length validation in restore_v2(). The code rejects xme_len == 1, but a length of 1 is the correct and expected value, since the superblock fits within a single 512-byte sector.
On big-endian systems, this length decodes to 1 and the check aborts the restore. On little-endian systems, the same on-disk bytes are interpreted as 16777216, so the faulty logic never triggers there.
The patch removes the incorrect rejection of a valid extent length of 1 and applies proper logic so that the superblock extent length is validated consistently across all architectures.
The outline of the fix was discussed with Chandan (thanks).
v2:
- xme.xme_len is an ondisk value so use be32_to_cpu() instead of cpu_to_be32()
Pavel Reichl (1):
mdrestore: fix restore_v2() superblock length check
mdrestore/xfs_mdrestore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Signature · 1 line
2.52.0
PATCH v2 1/1 mdrestore: fix restore_v2() superblock length check
On big-endian architectures (e.g. s390x), restoring a filesystem from a v2 metadump fails with "Invalid superblock disk address/length". This is caused by restore_v2() treating a superblock extent length of 1 as an error, even though a length of 1 is expected because the superblock fits within a 512-byte sector.
On little-endian systems, the same raw extent length bytes that represent a value of 1 on big-endian are misinterpreted as 16777216 due to byte ordering, so the faulty check never triggers there and the bug is hidden.
Fix the issue by using an endian-correct comparison of xme_len so that the superblock extent length is validated properly and consistently on all architectures.
--- mdrestore/xfs_mdrestore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mdrestore/xfs_mdrestore.c +1 -1
@@ -437,7 +437,7 @@ restore_v2(if (fread (&xme,sizeof (xme),1 , md_fp) !=1 )fatal ("error reading from metadump file\n" ); -if (xme.xme_addr !=0 || xme.xme_len ==1 || +if (xme.xme_addr !=0 ||be32_to_cpu (xme.xme_len) !=1 || (be64_to_cpu (xme.xme_addr) &XME_ADDR_DEVICE_MASK ) !=XME_ADDR_DATA_DEVICE )fatal ("Invalid superblock disk address/length\n" );
Signature · 1 line
2.52.0
Quoted 10 lines · Pavel Reichl
On big-endian architectures (e.g. s390x), restoring a filesystem from a v2 metadump fails with "Invalid superblock disk address/length". This is caused by
restore_v2()treating a superblock extent length of 1 as an error, even though a length of 1 is expected because the superblock fits within a 512-byte sector.On little-endian systems, the same raw extent length bytes that represent a value of 1 on big-endian are misinterpreted as 16777216 due to byte ordering, so the faulty check never triggers there and the bug is hidden.
Quoted 5 lines
Fix the issue by using an endian-correct comparison of
xme_lenso that the superblock extent length is validated properly and consistently on all architectures.Signed-off-by Pavel Reichl <[email protected]>
Looks good!
--D
Quoted 20 lines
--- mdrestore/xfs_mdrestore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mdrestore/xfs_mdrestore.c +1
-1@@ -437,7 +437,7 @@ restore_v2(if (fread (&xme,sizeof (xme),1 , md_fp) !=1 )fatal ("error reading from metadump file\n" ); -if (xme.xme_addr !=0 || xme.xme_len ==1 || +if (xme.xme_addr !=0 ||be32_to_cpu (xme.xme_len) !=1 || (be64_to_cpu (xme.xme_addr) &XME_ADDR_DEVICE_MASK ) !=XME_ADDR_DATA_DEVICE )fatal ("Invalid superblock disk address/length\n" );Signature · 1 line
2.52.0
Looks good:
Quoted 24 lines · Pavel Reichl
On big-endian architectures (e.g. s390x), restoring a filesystem from a v2 metadump fails with "Invalid superblock disk address/length". This is caused by
restore_v2()treating a superblock extent length of 1 as an error, even though a length of 1 is expected because the superblock fits within a 512-byte sector.On little-endian systems, the same raw extent length bytes that represent a value of 1 on big-endian are misinterpreted as 16777216 due to byte ordering, so the faulty check never triggers there and the bug is hidden.
Fix the issue by using an endian-correct comparison of
xme_lenso that the superblock extent length is validated properly and consistently on all architectures.Signed-off-by Pavel Reichl <[email protected]>--- mdrestore/xfs_mdrestore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mdrestore/xfs_mdrestore.c +0
-0
mdrestore/xfs_mdrestore.c restore_v2( · line 443
Quoted 8 lines
mdrestore/xfs_mdrestore.c +1
-1@@ -437,7 +437,7 @@ restore_v2(if (fread (&xme,sizeof (xme),1 , md_fp) !=1 )fatal ("error reading from metadump file\n" ); -if (xme.xme_addr !=0 || xme.xme_len ==1 || +if (xme.xme_addr !=0 ||be32_to_cpu (xme.xme_len) !=1 || (be64_to_cpu (xme.xme_addr) &XME_ADDR_DEVICE_MASK ) !=XME_ADDR_DATA_DEVICE )fatal ("Invalid superblock disk address/length\n" );
Thanks for fixing this,
Signature · 1 line
Chandan