mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 8/9] ocfs2: exclude holes from the xattr bucket's name/value length
Date: Sat,  5 Dec 2026 15:44:24 +0530	[thread overview]
Message-ID: <e99dd24e224df1fde3e2b9766bd99fdfcccc44c2.1796465362.git.siddh.raman.pant@oracle.com> (raw)
In-Reply-To: <cover.1796465362.git.siddh.raman.pant@oracle.com>

A reflink made without preserving security attributes copies the flat
xattr block and drops the entries for ACLs and security xattrs. Their
payloads can leave holes between a surviving name/value pair and the
end of the block.

On conversion to an indexed bucket, the span copied from the lowest
name offset includes those holes. Using that span for xh_name_value_len
causes fsck.ocfs2 to report XATTR_VALUE_LEN_INVALID on an otherwise
readable bucket. On a 512-byte block filesystem, dropping a five-entry
ACL and converting the clone produced a length of 536 instead of 496.

Keep the span for the copy and xh_free_start. Sum each entry's occupied
space while rebasing its offset and store that sum in xh_name_value_len.

Fixes: 0fe9b66c65f3 ("ocfs2: Add preserve to reflink.")
Signed-off-by: Siddh Raman Pant <siddh.raman.pant@oracle.com>
---
 fs/ocfs2/xattr.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index 63f62a15a68e..d45cea78c7e0 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -4745,7 +4745,7 @@ 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;
+	u16 offset, size, off_change, name_value_len = 0;
 	struct ocfs2_xattr_block *xb =
 				(struct ocfs2_xattr_block *)xb_bh->b_data;
 	struct ocfs2_xattr_header *xb_xh = &xb->xb_attrs.xb_header;
@@ -4788,7 +4788,6 @@ static void ocfs2_cp_xattr_block_to_bucket(struct inode *inode,
 	/* Init new header now. */
 	xh->xh_count = xb_xh->xh_count;
 	xh->xh_num_buckets = cpu_to_le16(1);
-	xh->xh_name_value_len = cpu_to_le16(size);
 	xh->xh_free_start = cpu_to_le16(OCFS2_XATTR_BUCKET_SIZE - size);
 
 	/* copy all the entries. */
@@ -4797,11 +4796,21 @@ static void ocfs2_cp_xattr_block_to_bucket(struct inode *inode,
 	size = count * sizeof(struct ocfs2_xattr_entry);
 	memcpy(target + offset, (char *)xb_xh + offset, size);
 
-	/* Change the xe offset for all the xe because of the move. */
+	/**
+	 * Rebase the offsets and count each pair. Dropping ACLs or security
+	 * xattrs during a reflink can leave holes in the copied region.
+	 */
 	off_change = OCFS2_XATTR_BUCKET_SIZE - blocksize +
 		 offsetof(struct ocfs2_xattr_block, xb_attrs.xb_header);
-	for (i = 0; i < count; i++)
-		le16_add_cpu(&xh->xh_entries[i].xe_name_offset, off_change);
+
+	for (i = 0; i < count; i++) {
+		struct ocfs2_xattr_entry *xe = &xh->xh_entries[i];
+
+		le16_add_cpu(&xe->xe_name_offset, off_change);
+		name_value_len += namevalue_size_xe(xe);
+	}
+
+	xh->xh_name_value_len = cpu_to_le16(name_value_len);
 
 	trace_ocfs2_cp_xattr_block_to_bucket_end(offset, size, off_change);
 
-- 
2.53.0


  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 ` Siddh Raman Pant [this message]
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=e99dd24e224df1fde3e2b9766bd99fdfcccc44c2.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®