[PATCH] ocfs2: use the bucket accessor when restoring xattr search
From: Siddh Raman Pant
Date: Fri Dec 04 2026 - 07:06:22 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 "stupider" AI models can trip on this code and complain about an
OOB access because it forgot to see the context around the call path.
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.
The original comparison adds xe_name_offset to the start of the first
bucket buffer. The accessor divides that offset by the fs block size
to select a buffer, then uses the remainder as the offset within it.
With 1 KiB blocks, offset 3172 selects the fourth buffer (block
index 3) and offset 100 within it, since 3 * 1024 + 100 = 3172.
The bucket's buffers occupy consecutive regions of one page, so
both calculations produce the same address.
Signed-off-by: Siddh Raman Pant <siddh.raman.pant@xxxxxxxxxx>
---
fs/ocfs2/xattr.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index 71e5986bafaa..ae3743e448ea 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -4794,12 +4794,20 @@ 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),
+
+ if (ocfs2_xattr_bucket_get_name_value(inode->i_sb, xs->header,
+ i, &block_off,
+ &name_off))
+ continue;
+
+ if (!memcmp(bucket_block(xs->bucket, block_off) + name_off,
xi->xi_name, xi->xi_name_len)) {
xs->here = xe;
return;
--
2.53.0