Skip to contentSkip to conversation

xfs: reject a hole in a remote xattr value

PATCH In review Kyuwon Cho 2 participants 2 messages Nov 25 XFS filesystem

lore
Share & tools
lore

Kyuwon Cho

author
#0 lore raw

PATCH v2 1/1 xfs: reject a hole in a remote xattr value

xfs_attr_rmtval_get() maps the blocks of a remote xattr value from the on-disk value length and only asserts that a mapping is not a hole. The leaf verifier caps the length at XFS_XATTR_SIZE_MAX but does not check it against the blocks the value owns, so a larger length makes the read reach a hole. Without CONFIG_XFS_DEBUG the hole becomes a disk address past the end of the device:

xfs_buf_map_verify: daddr 0x258000001a7f0 out of range, EOFS 0x96000

  WARNING: fs/xfs/xfs_buf.c:423 at xfs_find_get_buf+0x160f/0x2350
  Call Trace:
   xfs_buf_read_map (fs/xfs/xfs_buf.c:648)
   xfs_attr_rmtval_get (fs/xfs/libxfs/xfs_attr_remote.c:434)
   xfs_attr3_leaf_getvalue (fs/xfs/libxfs/xfs_attr_leaf.c:2718)

Check for a hole or a delalloc extent at run time and return -EFSCORRUPTED, as xfs_attr_rmtval_stale() does.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")

---
v2:
- Read the start block into a local so that the checks fit in 80
columns, and post the patch as its own thread (Christoph).
v1: https://lore.kernel.org/linux-xfs/[email protected]/
Report: https://lore.kernel.org/linux-xfs/[email protected]/

An image with crafted metadata and recomputed CRCs is outside the XFS threat model, so this is a hardening fix for such an image, not a security fix.

The issue was found by an LLM-guided test generator that we are developing as a research prototype. The patch was written with LLM assistance; we reviewed and tested it. It applies to the xfs for-next branch. With it, the reproducer from the report no longer triggers the warning, and XFS reports the corruption instead.

 fs/xfs/libxfs/xfs_attr_remote.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
fs/xfs/libxfs/xfs_attr_remote.c +7 -3
index e6c8dd1a997a..7cd3f2de1a80 100644
@@ -424,12 +424,16 @@ xfs_attr_rmtval_get(
 		ASSERT(nmap >= 1);
 
 		for (i = 0; (i < nmap) && (valuelen > 0); i++) {
+			xfs_fsblock_t	fsbno = map[i].br_startblock;
 			xfs_daddr_t	dblkno;
 			int		dblkcnt;
 
-			ASSERT((map[i].br_startblock != DELAYSTARTBLOCK) &&
-			       (map[i].br_startblock != HOLESTARTBLOCK));
-			dblkno = XFS_FSB_TO_DADDR(mp, map[i].br_startblock);
+			if (XFS_IS_CORRUPT(mp, fsbno == DELAYSTARTBLOCK) ||
+			    XFS_IS_CORRUPT(mp, fsbno == HOLESTARTBLOCK)) {
+				xfs_bmap_mark_sick(args->dp, XFS_ATTR_FORK);
+				return -EFSCORRUPTED;
+			}
+			dblkno = XFS_FSB_TO_DADDR(mp, fsbno);
 			dblkcnt = XFS_FSB_TO_BB(mp, map[i].br_blockcount);
 			error = xfs_buf_read(mp->m_ddev_targp, dblkno, dblkcnt,
 					0, &bp, &xfs_attr3_rmt_buf_ops);
Signature · 1 line
2.43.0