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,
sashiko-reviews@lists.linux.dev
Subject: [PATCH v3 6/9] ocfs2: reject overlapping entries in xattr blocks
Date: Sat, 5 Dec 2026 13:38:56 +0530 [thread overview]
Message-ID: <40e435b1a6ceb4ef41dc5afccd668f54dc910f4c.1796458015.git.siddh.raman.pant@oracle.com> (raw)
In-Reply-To: <cover.1796458015.git.siddh.raman.pant@oracle.com>
ocfs2_validate_xattr_entries_flat() checks each entry in isolation.
If two name/value pairs overlap, removing one can shift the other's
name past the end of the block. Copying the cached block into a
bucket carries the bad offset into the next name comparison.
Use a bitmap to track the storage occupied by each pair, including
alignment padding and space for an external value root. Reject a pair
that overlaps another before compaction can move it.
A Sashiko review of another patch exposed this missing overlap check.
Fixes: cf1d6c763fbc ("ocfs2: Add extended attribute support")
Reported-by: Sashiko AI <sashiko-bot@kernel.org>
Link: https://sashiko.dev/#/patchset/20261204152650.349289-1-siddh.raman.pant@oracle.com?part=1
Signed-off-by: Siddh Raman Pant <siddh.raman.pant@oracle.com>
---
fs/ocfs2/xattr.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index 3d5abc4516b7..75036d0fd9b6 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -9,6 +9,7 @@
* Copyright (C) 2001-2003 Andreas Gruenbacher, <agruen@suse.de>
*/
+#include <linux/bitmap.h>
#include <linux/capability.h>
#include <linux/fs.h>
#include <linux/types.h>
@@ -1115,15 +1116,16 @@ static int ocfs2_validate_xattr_entries_flat(struct super_block *sb, u64 blkno,
struct ocfs2_xattr_header *xh,
size_t region_size)
{
+ DECLARE_BITMAP(used, OCFS2_MAX_BLOCKSIZE / OCFS2_XATTR_ALIGN) = {};
u16 xattr_count = le16_to_cpu(xh->xh_count);
size_t entries_limit = region_size;
size_t nv_limit = region_size;
size_t max_entries;
int i, ret;
- if (region_size < sizeof(*xh))
+ if (region_size < sizeof(*xh) || region_size > OCFS2_MAX_BLOCKSIZE)
return ocfs2_error(sb,
- "Invalid xattr in block %llu: region size %zu is too small\n",
+ "Invalid xattr in block %llu: invalid region size %zu\n",
(unsigned long long)blkno, region_size);
max_entries = (entries_limit - sizeof(*xh)) /
@@ -1138,7 +1140,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, value_size;
+ size_t value_offset, value_size, first, end;
ret = ocfs2_validate_xattr_entry(sb, blkno, xe);
if (ret)
@@ -1168,6 +1170,16 @@ static int ocfs2_validate_xattr_entries_flat(struct super_block *sb, u64 blkno,
return ocfs2_error(sb,
"Invalid xattr in block %llu: entry %d value is out of bounds\n",
(unsigned long long)blkno, i);
+
+ first = name_offset / OCFS2_XATTR_ALIGN;
+ end = (value_offset + value_size) / OCFS2_XATTR_ALIGN;
+
+ if (find_next_bit(used, end, first) < end)
+ return ocfs2_error(sb,
+ "Invalid xattr in block %llu: entry %d overlaps another entry\n",
+ (unsigned long long)blkno, i);
+
+ bitmap_set(used, first, end - first);
}
return 0;
--
2.53.0
next prev parent reply other threads:[~2026-12-05 8:09 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <sashiko-outbox-249784@kernel.org>
2026-12-04 15:26 ` [PATCH v2 1/2] ocfs2: use the bucket accessor when restoring xattr search Siddh Raman Pant
2026-12-04 15:26 ` [PATCH v2 2/2] ocfs2: reject xattr names at the end of their storage Siddh Raman Pant
2026-12-05 8:08 ` [PATCH v3 0/9] Sashiko inspired OCFS2 fixes Siddh Raman Pant
2026-12-05 8:08 ` [PATCH v3 1/9] ocfs2: reject local xattrs with both an empty name and an empty value Siddh Raman Pant
2026-12-05 8:08 ` [PATCH v3 2/9] ocfs2: reject xattr names that overlap the header or entries Siddh Raman Pant
2026-12-05 8:08 ` [PATCH v3 3/9] ocfs2: reject short nonempty external xattr values Siddh Raman Pant
2026-12-05 8:08 ` [PATCH v3 4/9] ocfs2: check the space used by xattr values and value roots Siddh Raman Pant
2026-12-05 8:08 ` [PATCH v3 5/9] ocfs2: reject misaligned xattr name offsets Siddh Raman Pant
2026-12-05 8:08 ` Siddh Raman Pant [this message]
2026-12-05 8:08 ` [PATCH v3 7/9] ocfs2: copy all xattr names and values when converting a block Siddh Raman Pant
2026-12-05 8:08 ` [PATCH v3 8/9] ocfs2: exclude holes from the xattr bucket's name/value length Siddh Raman Pant
2026-12-05 8:09 ` [PATCH v3 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=40e435b1a6ceb4ef41dc5afccd668f54dc910f4c.1796458015.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 \
--cc=sashiko-reviews@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®