[PATCH v2 1/2] ocfs2: use the bucket accessor when restoring xattr search
From: Siddh Raman Pant
Date: Fri Dec 04 2026 - 10:27:21 EST
ocfs2_xattr_update_xattr_search() compares candidate names using a
bucket-relative offset from the first buffer. Cluster alignment keeps
the whole bucket in one page, so valid names are already reached
correctly.
ocfs2_validate_xattr_bucket() already documents that the entry array
is contiguous across the bucket's buffer heads and that cluster
alignment keeps the whole bucket in one page. It rejects an unaligned
bucket block number before accessing the entry array. The conversion
adjusts each xe_name_offset to be relative to the whole bucket.
But less powerful AI models can trip on this code and complain about
an OOB access because the context around the call path was missed.
So let's resolve the offset with ocfs2_xattr_bucket_get_name_value()
and select the corresponding buffer, matching the other bucket lookup
paths which also operate under the same guarantee.
Signed-off-by: Siddh Raman Pant <siddh.raman.pant@xxxxxxxxxx>
---
fs/ocfs2/xattr.c | 32 ++++++++++++++++++++++++++++----
1 file changed, 28 insertions(+), 4 deletions(-)
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index 71e5986bafaa..1b013ca43efb 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -4794,16 +4794,40 @@ static void ocfs2_xattr_update_xattr_search(struct inode *inode,
count = le16_to_cpu(xs->header->xh_count);
for (i = 0; i < count; i++) {
struct ocfs2_xattr_entry *xe = &xs->header->xh_entries[i];
+ int block_off, name_off;
if (ocfs2_xattr_get_type(xe) != xi->xi_name_index)
continue;
+
if (xe->xe_name_len != xi->xi_name_len)
continue;
- if (!memcmp(xs->base + le16_to_cpu(xe->xe_name_offset),
- xi->xi_name, xi->xi_name_len)) {
- xs->here = xe;
- return;
+
+ /**
+ * An empty local name/value pair takes no space, so
+ * ocfs2_validate_xattr_entries_flat() allows offsets
+ * just past the old storage. ocfs2_cp_xattr_block_to_bucket()
+ * moves the data to the end of the bucket and adjusts each
+ * offset. The empty pair then points just past the bucket.
+ * Its name already matches, so don't look up a nonexistent
+ * buffer.
+ */
+ if (xi->xi_name_len) {
+ const char *name;
+
+ if (ocfs2_xattr_bucket_get_name_value(inode->i_sb,
+ xs->header, i,
+ &block_off,
+ &name_off))
+ continue;
+
+ name = bucket_block(xs->bucket, block_off) + name_off;
+
+ if (memcmp(name, xi->xi_name, xi->xi_name_len))
+ continue;
}
+
+ xs->here = xe;
+ return;
}
/*
--
2.53.0