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 7/9] ocfs2: copy all xattr names and values when converting a block
Date: Sat, 5 Dec 2026 15:44:23 +0530 [thread overview]
Message-ID: <e9ee64159d106aa235fef34aed420bee73cd4ce8.1796465362.git.siddh.raman.pant@oracle.com> (raw)
In-Reply-To: <cover.1796465362.git.siddh.raman.pant@oracle.com>
ocfs2_cp_xattr_block_to_bucket() starts copying names and values at
the offset in the last entry. Resizing an earlier xattr can move its
name and value to a lower offset without changing its position in the
entry array. If the block then fills up, conversion skips those bytes
and the resized attribute can no longer be found.
Find the lowest name offset across all entries, as the block allocator
already does, and copy from there to the end of the block.
Fixes: 012255961c9e ("ocfs2: Enable xattr set in index btree")
Signed-off-by: Siddh Raman Pant <siddh.raman.pant@oracle.com>
---
fs/ocfs2/xattr.c | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index a390bcd82f76..63f62a15a68e 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -2015,11 +2015,10 @@ static int ocfs2_xa_block_can_reuse(struct ocfs2_xa_loc *loc,
namevalue_size_xi(xi);
}
-static int ocfs2_xa_block_get_free_start(struct ocfs2_xa_loc *loc)
+static int ocfs2_xattr_min_offset(struct ocfs2_xattr_header *xh, int free_start)
{
- struct ocfs2_xattr_header *xh = loc->xl_header;
int i, count = le16_to_cpu(xh->xh_count);
- int offset, free_start = loc->xl_size;
+ int offset;
for (i = 0; i < count; i++) {
offset = le16_to_cpu(xh->xh_entries[i].xe_name_offset);
@@ -2030,6 +2029,11 @@ static int ocfs2_xa_block_get_free_start(struct ocfs2_xa_loc *loc)
return free_start;
}
+static int ocfs2_xa_block_get_free_start(struct ocfs2_xa_loc *loc)
+{
+ return ocfs2_xattr_min_offset(loc->xl_header, loc->xl_size);
+}
+
static int ocfs2_xa_block_check_space(struct ocfs2_xa_loc *loc,
struct ocfs2_xattr_info *xi)
{
@@ -4742,7 +4746,6 @@ static void ocfs2_cp_xattr_block_to_bucket(struct inode *inode,
int i, blocksize = inode->i_sb->s_blocksize;
int blks = ocfs2_blocks_per_xattr_bucket(inode->i_sb);
u16 offset, size, off_change;
- struct ocfs2_xattr_entry *xe;
struct ocfs2_xattr_block *xb =
(struct ocfs2_xattr_block *)xb_bh->b_data;
struct ocfs2_xattr_header *xb_xh = &xb->xb_attrs.xb_header;
@@ -4759,11 +4762,8 @@ static void ocfs2_cp_xattr_block_to_bucket(struct inode *inode,
memset(bucket_block(bucket, i), 0, blocksize);
/*
- * An empty block has no names or values to carry over, and the
- * xh_entries[count - 1] below would be xh_entries[-1]. Leave the
- * bucket empty, but carry over the hash ocfs2_xa_remove_entry() left
- * in the block's xh_entries[0] so that the bucket still holds the key
- * it is looked up by.
+ * An empty bucket still needs the hash ocfs2_xa_remove_entry()
+ * left in the block's first entry.
*/
if (!count) {
xh->xh_num_buckets = cpu_to_le16(1);
@@ -4774,13 +4774,12 @@ static void ocfs2_cp_xattr_block_to_bucket(struct inode *inode,
}
/*
- * Since the xe_name_offset is based on ocfs2_xattr_header,
- * there is a offset change corresponding to the change of
- * ocfs2_xattr_header's position.
+ * Resizing an xattr can move its name/value pair below the last
+ * entry's pair. Copy from the lowest name offset in the block.
*/
off_change = offsetof(struct ocfs2_xattr_block, xb_attrs.xb_header);
- xe = &xb_xh->xh_entries[count - 1];
- offset = le16_to_cpu(xe->xe_name_offset) + off_change;
+ offset = ocfs2_xattr_min_offset(xb_xh, blocksize - off_change);
+ offset += off_change;
size = blocksize - offset;
/* copy all the names and values. */
--
2.53.0
next 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 ` Siddh Raman Pant [this message]
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 ` [PATCH v4 9/9] ocfs2: use the bucket accessor when restoring xattr search Siddh Raman Pant
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=e9ee64159d106aa235fef34aed420bee73cd4ce8.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®