[PATCH v4 6/9] ocfs2: reject overlapping entries in xattr blocks

From: Siddh Raman Pant

Date: Sat Dec 05 2026 - 05:15:48 EST


ocfs2_validate_xattr_entries_flat() checks each entry in isolation.
If two name/value pairs overlap, removing one can shift the other's
name past the end of the block. Copying the cached block into a
bucket carries the bad offset into the next name comparison.

Use a bitmap to track the storage occupied by each pair, including
alignment padding and space for an external value root. Reject a pair
that overlaps another before compaction can move it.

A Sashiko review of another patch exposed this missing overlap check.

Fixes: cf1d6c763fbc ("ocfs2: Add extended attribute support")
Reported-by: Sashiko AI <sashiko-bot@xxxxxxxxxx>
Link: https://sashiko.dev/#/patchset/20261204152650.349289-1-siddh.raman.pant@xxxxxxxxxx?part=1
Signed-off-by: Siddh Raman Pant <siddh.raman.pant@xxxxxxxxxx>
---
fs/ocfs2/xattr.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index fe432222694d..a390bcd82f76 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -9,6 +9,7 @@
* Copyright (C) 2001-2003 Andreas Gruenbacher, <agruen@xxxxxxx>
*/

+#include <linux/bitmap.h>
#include <linux/capability.h>
#include <linux/fs.h>
#include <linux/types.h>
@@ -1135,15 +1136,16 @@ static int ocfs2_validate_xattr_entries_flat(struct super_block *sb, u64 blkno,
struct ocfs2_xattr_header *xh,
size_t region_size)
{
+ DECLARE_BITMAP(used, OCFS2_MAX_BLOCKSIZE / OCFS2_XATTR_ALIGN) = {};
u16 xattr_count = le16_to_cpu(xh->xh_count);
size_t entries_limit = region_size;
size_t nv_limit = region_size;
size_t max_entries;
int i, ret;

- if (region_size < sizeof(*xh))
+ if (region_size < sizeof(*xh) || region_size > OCFS2_MAX_BLOCKSIZE)
return ocfs2_error(sb,
- "Invalid xattr in block %llu: region size %zu is too small\n",
+ "Invalid xattr in block %llu: invalid region size %zu\n",
(unsigned long long)blkno, region_size);

max_entries = (entries_limit - sizeof(*xh)) /
@@ -1158,7 +1160,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, value_size;
+ size_t value_offset, value_size, first, end;

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

+ first = name_offset / OCFS2_XATTR_ALIGN;
+ end = (value_offset + value_size) / OCFS2_XATTR_ALIGN;
+
+ if (find_next_bit(used, end, first) < end)
+ return ocfs2_error(sb,
+ "Invalid xattr in block %llu: entry %d overlaps another entry\n",
+ (unsigned long long)blkno, i);
+
+ bitmap_set(used, first, end - first);
+
ret = ocfs2_validate_empty_xattr_root(sb, blkno, xe,
(void *)xh + value_offset);
if (ret)
--
2.53.0