[PATCH v3 3/9] ocfs2: reject short nonempty external xattr values

From: Siddh Raman Pant

Date: Sat Dec 05 2026 - 03:09:42 EST


OCFS2 stores values up to OCFS2_XATTR_INLINE_SIZE locally. If a
short value is marked external, removal expects a value root, but
namevalue_size_xe() uses the value length to calculate its storage
size. The mismatch can hit BUG_ON() in ocfs2_xa_fill_value_buf().

Reject a nonzero external value at or below the inline size limit in
ocfs2_validate_xattr_entry(). A zero-length external value can be
journaled by ocfs2_xattr_bucket_value_truncate() during inode
deletion. Allow that entry and use its local flag to account for the
root during compaction and removal.

Fixes: 3fc12afa0cea ("ocfs2: Provide ocfs2_xa_fill_value_buf() for external value processing")
Signed-off-by: Siddh Raman Pant <siddh.raman.pant@xxxxxxxxxx>
---
fs/ocfs2/xattr.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index 2d32cba2a36f..f00ed6389b20 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -228,13 +228,21 @@ static int namevalue_size_xi(struct ocfs2_xattr_info *xi)
return namevalue_size(xi->xi_name_len, xi->xi_value_len);
}

+static int ocfs2_xattr_value_size(struct ocfs2_xattr_entry *xe)
+{
+ if (!ocfs2_xattr_is_local(xe))
+ return OCFS2_XATTR_ROOT_SIZE;
+
+ return OCFS2_XATTR_SIZE(le64_to_cpu(xe->xe_value_size));
+}
+
static int namevalue_size_xe(struct ocfs2_xattr_entry *xe)
{
u64 value_len = le64_to_cpu(xe->xe_value_size);

BUG_ON((value_len > OCFS2_XATTR_INLINE_SIZE) &&
ocfs2_xattr_is_local(xe));
- return namevalue_size(xe->xe_name_len, value_len);
+ return OCFS2_XATTR_SIZE(xe->xe_name_len) + ocfs2_xattr_value_size(xe);
}

static int ocfs2_validate_xattr_entry(struct super_block *sb, u64 blkno,
@@ -254,6 +262,14 @@ static int ocfs2_validate_xattr_entry(struct super_block *sb, u64 blkno,
(unsigned long long)blkno,
(unsigned long long)value_len);

+ /* Inode deletion can leave a truncated external value in a bucket. */
+ if (!ocfs2_xattr_is_local(xe) && value_len &&
+ value_len <= OCFS2_XATTR_INLINE_SIZE)
+ return ocfs2_error(sb,
+ "Invalid external xattr in block %llu: value size %llu\n",
+ (unsigned long long)blkno,
+ (unsigned long long)value_len);
+
return 0;
}

@@ -1917,8 +1933,6 @@ static void ocfs2_xa_fill_value_buf(struct ocfs2_xa_loc *loc,

/* Value bufs are for value trees */
BUG_ON(ocfs2_xattr_is_local(loc->xl_entry));
- BUG_ON(namevalue_size_xe(loc->xl_entry) !=
- (name_size + OCFS2_XATTR_ROOT_SIZE));

loc->xl_ops->xlo_fill_value_buf(loc, vb);
vb->vb_xv =
--
2.53.0