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 4/9] ocfs2: check the space used by xattr values and value roots
Date: Sat,  5 Dec 2026 15:44:20 +0530	[thread overview]
Message-ID: <2a371083ebd7b60eedb21dbc2bb05671955c4ecc.1796465362.git.siddh.raman.pant@oracle.com> (raw)
In-Reply-To: <cover.1796465362.git.siddh.raman.pant@oracle.com>

ocfs2_validate_xattr_entries_flat() and ocfs2_validate_xattr_bucket()
check the length of a local value, but compaction also moves its
alignment padding. For an external value, both checks cover only the
root header. The extent record that follows it can lie past the end
of the block.

Use ocfs2_xattr_value_size() in both checks so the entire local
value or external value root fits.

Fixes: cf1d6c763fbc ("ocfs2: Add extended attribute support")
Signed-off-by: Siddh Raman Pant <siddh.raman.pant@oracle.com>
---
 fs/ocfs2/xattr.c | 30 +++++++-----------------------
 1 file changed, 7 insertions(+), 23 deletions(-)

diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index 769e01e61a45..abec874b6a27 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -1157,8 +1157,7 @@ static int ocfs2_validate_xattr_entries_flat(struct super_block *sb, u64 blkno,
 	for (i = 0; i < xattr_count; i++) {
 		struct ocfs2_xattr_entry *xe = &xh->xh_entries[i];
 		size_t name_offset = le16_to_cpu(xe->xe_name_offset);
-		size_t value_offset;
-		u64 value_len = le64_to_cpu(xe->xe_value_size);
+		size_t value_offset, value_size;
 
 		ret = ocfs2_validate_xattr_entry(sb, blkno, xe);
 		if (ret)
@@ -1177,18 +1176,12 @@ static int ocfs2_validate_xattr_entries_flat(struct super_block *sb, u64 blkno,
 					   "Invalid xattr in block %llu: entry %d value starts out of bounds\n",
 					   (unsigned long long)blkno, i);
 
-		if (ocfs2_xattr_is_local(xe)) {
-			if (value_len > nv_limit - value_offset)
-				return ocfs2_error(sb,
-						   "Invalid xattr in block %llu: entry %d value is out of bounds\n",
-						   (unsigned long long)blkno,
-						   i);
-		} else if (sizeof(struct ocfs2_xattr_value_root) >
-			   nv_limit - value_offset) {
+		/* Cover value padding and the full extent root. */
+		value_size = ocfs2_xattr_value_size(xe);
+		if (value_size > nv_limit - value_offset)
 			return ocfs2_error(sb,
-					   "Invalid xattr in block %llu: entry %d value root is out of bounds\n",
+					   "Invalid xattr in block %llu: entry %d value is out of bounds\n",
 					   (unsigned long long)blkno, i);
-		}
 
 		ret = ocfs2_validate_empty_xattr_root(sb, blkno, xe,
 						      (void *)xh + value_offset);
@@ -1315,7 +1308,6 @@ static int ocfs2_validate_xattr_bucket(struct ocfs2_xattr_bucket *bucket,
 		size_t block_off = name_offset >> sb->s_blocksize_bits;
 		size_t block_offset = name_offset % nv_limit;
 		size_t value_offset;
-		u64 value_len = le64_to_cpu(xe->xe_value_size);
 		const void *value;
 
 		ret = ocfs2_validate_xattr_entry(sb, blkno, xe);
@@ -1338,18 +1330,10 @@ static int ocfs2_validate_xattr_bucket(struct ocfs2_xattr_bucket *bucket,
 					   "Invalid xattr bucket %llu: entry %d value starts out of bounds\n",
 					   (unsigned long long)blkno, i);
 
-		if (ocfs2_xattr_is_local(xe)) {
-			if (value_len > nv_limit - value_offset)
-				return ocfs2_error(sb,
-						   "Invalid xattr bucket %llu: entry %d value is out of bounds\n",
-						   (unsigned long long)blkno,
-						   i);
-		} else if (sizeof(struct ocfs2_xattr_value_root) >
-			   nv_limit - value_offset) {
+		if (ocfs2_xattr_value_size(xe) > nv_limit - value_offset)
 			return ocfs2_error(sb,
-					   "Invalid xattr bucket %llu: entry %d value root is out of bounds\n",
+					   "Invalid xattr bucket %llu: entry %d value is out of bounds\n",
 					   (unsigned long long)blkno, i);
-		}
 
 		value = bucket_block(bucket, block_off) + value_offset;
 		ret = ocfs2_validate_empty_xattr_root(sb, blkno + block_off,
-- 
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 ` Siddh Raman Pant [this message]
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 ` [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=2a371083ebd7b60eedb21dbc2bb05671955c4ecc.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®