Skip to contentSkip to conversation

xfs: sanitize da node pad field on write

PATCH In review Yuto Ohnuki 2 participants 2 messages Apr 23 – May 11 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xfs: sanitize da node pad field on write

The DA node block header (xfs_da3_node_hdr) contains a __pad32 field that should always be zero. Prior to commit a45086e27dfa21 ("xfs:
validate metadata LSNs against log on v5 superblocks"), xfs_da3_node_create() did not zero the full header, so __pad32 could contain stale data on older filesystems.

Clear this field in the write verifier to ensure it is corrected whenever the block is next written to disk.

---
Changes in v2:
- Added comments explaining why __pad32 is cleared unconditionally.
- Link to v1: https://lore.kernel.org/all/[email protected]/

---
 fs/xfs/libxfs/xfs_da_btree.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/xfs/libxfs/xfs_da_btree.c +6 -0
index ad801b7bd2dd..4edbf4bb5c7f 100644
@@ -318,6 +318,12 @@ xfs_da3_node_write_verify(
 	if (bip)
 		hdr3->info.lsn = cpu_to_be64(bip->bli_item.li_lsn);
 
+	/*
+	 * Old kernels may not have zeroed the padding field in the header,
+	 * so clear it unconditionally to sanitize stale data on disk.
+	 */
+	hdr3->__pad32 = 0;
+
 	xfs_buf_update_cksum(bp, XFS_DA3_NODE_CRC_OFF);
 }
 
Signature · 8 lines
2.50.1




Amazon Web Services EMEA SARL, 38 avenue John F. Kennedy, L-1855 Luxembourg, R.C.S. Luxembourg B186284

Amazon Web Services EMEA SARL, Irish Branch, One Burlington Plaza, Burlington Road, Dublin 4, Ireland, branch registration number 908705
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 27 lines · Yuto Ohnuki

The DA node block header (xfs_da3_node_hdr) contains a __pad32 field that should always be zero. Prior to commit a45086e27dfa21 ("xfs:
validate metadata LSNs against log on v5 superblocks"), xfs_da3_node_create() did not zero the full header, so __pad32 could contain stale data on older filesystems.

Clear this field in the write verifier to ensure it is corrected whenever the block is next written to disk.

---
Changes in v2:
- Added comments explaining why __pad32 is cleared unconditionally.
- Link to v1: https://lore.kernel.org/all/[email protected]/

---
 fs/xfs/libxfs/xfs_da_btree.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/xfs/libxfs/xfs_da_btree.c +0 -0
index ad801b7bd2dd..4edbf4bb5c7f 100644
@@ -318,6 +318,12 @@ xfs_da3_node_write_verify(
 	if (bip)
 		hdr3->info.lsn = cpu_to_be64(bip->bli_item.li_lsn);

fs/xfs/libxfs/xfs_da_btree.c xfs_da3_node_write_verify( · line 329

Quoted 10 lines
fs/xfs/libxfs/xfs_da_btree.c +6 -0
 
+	/*
+	 * Old kernels may not have zeroed the padding field in the header,
+	 * so clear it unconditionally to sanitize stale data on disk.
+	 */
+	hdr3->__pad32 = 0;
+
 	xfs_buf_update_cksum(bp, XFS_DA3_NODE_CRC_OFF);
 }
 

Looks good.

Quoted 9 lines
Signature · 8 lines
2.50.1




Amazon Web Services EMEA SARL, 38 avenue John F. Kennedy, L-1855 Luxembourg, R.C.S. Luxembourg B186284

Amazon Web Services EMEA SARL, Irish Branch, One Burlington Plaza, Burlington Road, Dublin 4, Ireland, branch registration number 908705