[PATCH v3 4/9] ocfs2: check the space used by xattr values and value roots

From: Siddh Raman Pant

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


ocfs2_validate_xattr_entries_flat() and ocfs2_validate_xattr_bucket()
check the length of a local value, but compaction also moves its
alignment padding. For an external value, both checks cover only the
root header. The extent record that follows it can lie past the end
of the block.

Use ocfs2_xattr_value_size() in both checks so the entire local
value or external value root fits.

Fixes: cf1d6c763fbc ("ocfs2: Add extended attribute support")
Signed-off-by: Siddh Raman Pant <siddh.raman.pant@xxxxxxxxxx>
---
fs/ocfs2/xattr.c | 30 +++++++-----------------------
1 file changed, 7 insertions(+), 23 deletions(-)

diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index f00ed6389b20..662ccca685b1 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -1137,8 +1137,7 @@ static int ocfs2_validate_xattr_entries_flat(struct super_block *sb, u64 blkno,
for (i = 0; i < xattr_count; i++) {
struct ocfs2_xattr_entry *xe = &xh->xh_entries[i];
size_t name_offset = le16_to_cpu(xe->xe_name_offset);
- size_t value_offset;
- u64 value_len = le64_to_cpu(xe->xe_value_size);
+ size_t value_offset, value_size;

ret = ocfs2_validate_xattr_entry(sb, blkno, xe);
if (ret)
@@ -1157,18 +1156,12 @@ static int ocfs2_validate_xattr_entries_flat(struct super_block *sb, u64 blkno,
"Invalid xattr in block %llu: entry %d value starts out of bounds\n",
(unsigned long long)blkno, i);

- if (ocfs2_xattr_is_local(xe)) {
- if (value_len > nv_limit - value_offset)
- return ocfs2_error(sb,
- "Invalid xattr in block %llu: entry %d value is out of bounds\n",
- (unsigned long long)blkno,
- i);
- } else if (sizeof(struct ocfs2_xattr_value_root) >
- nv_limit - value_offset) {
+ /* Cover value padding and the full extent root. */
+ value_size = ocfs2_xattr_value_size(xe);
+ if (value_size > nv_limit - value_offset)
return ocfs2_error(sb,
- "Invalid xattr in block %llu: entry %d value root is out of bounds\n",
+ "Invalid xattr in block %llu: entry %d value is out of bounds\n",
(unsigned long long)blkno, i);
- }
}

return 0;
@@ -1290,7 +1283,6 @@ static int ocfs2_validate_xattr_bucket(struct ocfs2_xattr_bucket *bucket,
size_t block_off = name_offset >> sb->s_blocksize_bits;
size_t block_offset = name_offset % nv_limit;
size_t value_offset;
- u64 value_len = le64_to_cpu(xe->xe_value_size);

ret = ocfs2_validate_xattr_entry(sb, blkno, xe);
if (ret)
@@ -1312,18 +1304,10 @@ static int ocfs2_validate_xattr_bucket(struct ocfs2_xattr_bucket *bucket,
"Invalid xattr bucket %llu: entry %d value starts out of bounds\n",
(unsigned long long)blkno, i);

- if (ocfs2_xattr_is_local(xe)) {
- if (value_len > nv_limit - value_offset)
- return ocfs2_error(sb,
- "Invalid xattr bucket %llu: entry %d value is out of bounds\n",
- (unsigned long long)blkno,
- i);
- } else if (sizeof(struct ocfs2_xattr_value_root) >
- nv_limit - value_offset) {
+ if (ocfs2_xattr_value_size(xe) > nv_limit - value_offset)
return ocfs2_error(sb,
- "Invalid xattr bucket %llu: entry %d value root is out of bounds\n",
+ "Invalid xattr bucket %llu: entry %d value is out of bounds\n",
(unsigned long long)blkno, i);
- }
}

return 0;
--
2.53.0