[PATCH v4 5/9] ocfs2: reject misaligned xattr name offsets
From: Siddh Raman Pant
Date: Sat Dec 05 2026 - 05:15:22 EST
OCFS2 packs name/value pairs backwards from the end of xattr storage.
ocfs2_xa_block_add_namevalue() subtracts the aligned size of a new
pair from the lowest existing offset. If that offset is misaligned,
each new pair inherits the misalignment.
Check the alignment of xe_name_offset relative to the end of xattr
storage in ocfs2_validate_xattr_entries_flat().
Fixes: cf1d6c763fbc ("ocfs2: Add extended attribute support")
Signed-off-by: Siddh Raman Pant <siddh.raman.pant@xxxxxxxxxx>
---
fs/ocfs2/xattr.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index abec874b6a27..fe432222694d 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -80,6 +80,7 @@ struct ocfs2_xattr_set_ctxt {
#define OCFS2_XATTR_ROOT_SIZE (sizeof(struct ocfs2_xattr_def_value_root))
#define OCFS2_XATTR_INLINE_SIZE 80
#define OCFS2_XATTR_HEADER_GAP 4
+#define OCFS2_XATTR_ALIGN (OCFS2_XATTR_ROUND + 1)
#define OCFS2_XATTR_FREE_IN_IBODY (OCFS2_MIN_XATTR_INLINE_SIZE \
- sizeof(struct ocfs2_xattr_header) \
- OCFS2_XATTR_HEADER_GAP)
@@ -1170,6 +1171,11 @@ static int ocfs2_validate_xattr_entries_flat(struct super_block *sb, u64 blkno,
"Invalid xattr in block %llu: entry %d name is out of bounds\n",
(unsigned long long)blkno, i);
+ if (!IS_ALIGNED(nv_limit - name_offset, OCFS2_XATTR_ALIGN))
+ return ocfs2_error(sb,
+ "Invalid xattr in block %llu: entry %d name offset %zu is misaligned\n",
+ (unsigned long long)blkno, i, name_offset);
+
value_offset = name_offset + OCFS2_XATTR_SIZE(xe->xe_name_len);
if (value_offset > nv_limit)
return ocfs2_error(sb,
--
2.53.0