From: Joseph Qi <joseph.qi@linux.alibaba.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Heming Zhao <heming.zhao@suse.com>
Cc: Mark Fasheh <mark@fasheh.com>, Joel Becker <jlbec@evilplan.org>,
ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/2] ocfs2: reject inconsistent xattr bucket during defrag
Date: Thu, 3 Sep 2026 21:13:13 +0800 [thread overview]
Message-ID: <20260903131313.2396208-3-joseph.qi@linux.alibaba.com> (raw)
In-Reply-To: <20260903131313.2396208-1-joseph.qi@linux.alibaba.com>
ocfs2_defrag_xattr_bucket() has two mlog_bug_on_msg() checks that
assume the name/value pairs in a bucket are disjoint and that
xh_free_start is not below the compacted region.
ocfs2_validate_xattr_bucket() only checks each entry in isolation,
so a corrupt bucket holding overlapping entries, or one with an
inflated xh_free_start, passes validation and then hits BUG() in
defrag when a setxattr triggers it.
Defrag works on a linear copy of the bucket and does not touch the
real blocks before the copy back, so the checks can return an error
instead of calling BUG().
Fixes: 012255961c9e ("ocfs2: Enable xattr set in index btree")
Signed-off-by: Joseph Qi <joseph.qi@linux.alibaba.com>
---
fs/ocfs2/xattr.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index c71fa7983b73..e6c49adaac8a 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -4804,16 +4804,22 @@ static int ocfs2_defrag_xattr_bucket(struct inode *inode,
memmove(bucket_buf + end - len,
bucket_buf + offset, len);
xe->xe_name_offset = cpu_to_le16(end - len);
+ } else if (end < offset + len) {
+ ret = ocfs2_error(inode->i_sb,
+ "Defrag check failed for bucket %llu\n",
+ (unsigned long long)blkno);
+ goto out;
}
- mlog_bug_on_msg(end < offset + len, "Defrag check failed for "
- "bucket %llu\n", (unsigned long long)blkno);
-
end -= len;
}
- mlog_bug_on_msg(xh_free_start > end, "Defrag check failed for "
- "bucket %llu\n", (unsigned long long)blkno);
+ if (xh_free_start > end) {
+ ret = ocfs2_error(inode->i_sb,
+ "Defrag check failed for bucket %llu\n",
+ (unsigned long long)blkno);
+ goto out;
+ }
if (xh_free_start == end)
goto out;
--
2.39.3
prev parent reply other threads:[~2026-09-03 13:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 12:41 [PATCH] ocfs2: allow xattr bucket entries to span multiple blocks Joseph Qi
2026-09-03 13:13 ` [PATCH v2 0/2] ocfs2: xattr bucket validation fixes Joseph Qi
2026-09-03 13:13 ` [PATCH v2 1/2] ocfs2: allow xattr bucket entries to span multiple blocks Joseph Qi
2026-09-03 13:13 ` Joseph Qi [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=20260903131313.2396208-3-joseph.qi@linux.alibaba.com \
--to=joseph.qi@linux.alibaba.com \
--cc=akpm@linux-foundation.org \
--cc=heming.zhao@suse.com \
--cc=jlbec@evilplan.org \
--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®