From: Siddh Raman Pant <siddh.raman.pant@oracle.com>
To: Mark Fasheh <mark@fasheh.com>, Joel Becker <jlbec@evilplan.org>,
Joseph Qi <joseph.qi@linux.alibaba.com>,
Heming Zhao <heming.zhao@suse.com>
Cc: ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH v4 9/9] ocfs2: use the bucket accessor when restoring xattr search
Date: Sat, 5 Dec 2026 15:44:25 +0530 [thread overview]
Message-ID: <f032a1963a792e9b1e5d0cf49448ff1f7e0f3e52.1796465362.git.siddh.raman.pant@oracle.com> (raw)
In-Reply-To: <cover.1796465362.git.siddh.raman.pant@oracle.com>
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. Here,
ocfs2_xattr_create_index_block() places the bucket at the start of a
newly allocated cluster. The conversion adjusts each xe_name_offset
to be relative to the whole bucket.
Let's resolve the offset with ocfs2_xattr_bucket_get_name_value() and
select the corresponding buffer, matching the other lookup paths, so
that we avoid inlined cross-buffer pointer arithmetic past xs->end
(which can also trick less intelligent AI models into a false OOB).
When both names are empty and the namespaces match, skip the buffer
lookup. The old memcmp() read zero bytes even when an empty pair
pointed just past the last buffer.
Signed-off-by: Siddh Raman Pant <siddh.raman.pant@oracle.com>
---
fs/ocfs2/xattr.c | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index d45cea78c7e0..254cfc291892 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -4856,16 +4856,32 @@ 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;
+
+ /* Empty names already match; no buffer access is needed. */
+ 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
prev parent reply other threads:[~2026-12-05 10:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 10:14 [PATCH v4 0/9] Sashiko inspired OCFS2 fixes Siddh Raman Pant
2026-12-05 10:14 ` [PATCH v4 1/9] ocfs2: reject local xattrs with both an empty name and an empty value Siddh Raman Pant
2026-12-05 10:14 ` [PATCH v4 2/9] ocfs2: reject xattr names that overlap the header or entries Siddh Raman Pant
2026-12-05 10:14 ` [PATCH v4 3/9] ocfs2: reject invalid short external xattr values Siddh Raman Pant
2026-12-05 10:14 ` [PATCH v4 4/9] ocfs2: check the space used by xattr values and value roots Siddh Raman Pant
2026-12-05 10:14 ` [PATCH v4 5/9] ocfs2: reject misaligned xattr name offsets Siddh Raman Pant
2026-12-05 10:14 ` [PATCH v4 6/9] ocfs2: reject overlapping entries in xattr blocks Siddh Raman Pant
2026-12-05 10:14 ` [PATCH v4 7/9] ocfs2: copy all xattr names and values when converting a block Siddh Raman Pant
2026-12-05 10:14 ` [PATCH v4 8/9] ocfs2: exclude holes from the xattr bucket's name/value length Siddh Raman Pant
2026-12-05 10:14 ` Siddh Raman Pant [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f032a1963a792e9b1e5d0cf49448ff1f7e0f3e52.1796465362.git.siddh.raman.pant@oracle.com \
--to=siddh.raman.pant@oracle.com \
--cc=heming.zhao@suse.com \
--cc=jlbec@evilplan.org \
--cc=joseph.qi@linux.alibaba.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark@fasheh.com \
--cc=ocfs2-devel@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®