[PATCH v2 2/2] ocfs2: reject xattr names at the end of their storage
From: Siddh Raman Pant
Date: Fri Dec 04 2026 - 10:27:27 EST
ocfs2_validate_xattr_entries_flat() allows xe_name_offset to equal
region_size when both the name and local value are empty.
When another xattr no longer fits in the block, the empty entry is
copied into a bucket by ocfs2_cp_xattr_block_to_bucket() and the
offset of entry is changed to OCFS2_XATTR_BUCKET_SIZE. On the next
read, ocfs2_validate_xattr_bucket() rejects the entry and makes the
filesystem read-only.
Require name_offset to be less than nv_limit before accepting the
entry. Empty names and values at valid offsets remain allowed.
A Sashiko review of another patch exposed this missing bounds check.
Reported-by: Sashiko AI <sashiko-bot@xxxxxxxxxx>
Link: https://sashiko.dev/#/patchset/20261204120536.161006-1-siddh.raman.pant@xxxxxxxxxx?part=1
Fixes: 8914a3330b72 ("ocfs2: validate inline xattrs during inode block validation")
Signed-off-by: Siddh Raman Pant <siddh.raman.pant@xxxxxxxxxx>
---
fs/ocfs2/xattr.c | 12 ++----------
1 file changed, 2 insertions(+), 10 deletions(-)
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index 1b013ca43efb..277a63542ad6 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -1123,7 +1123,7 @@ static int ocfs2_validate_xattr_entries_flat(struct super_block *sb, u64 blkno,
if (ret)
return ret;
- if (name_offset > nv_limit ||
+ if (name_offset >= nv_limit ||
xe->xe_name_len > nv_limit - name_offset)
return ocfs2_error(sb,
"Invalid xattr in block %llu: entry %d name is out of bounds\n",
@@ -4802,15 +4802,7 @@ static void ocfs2_xattr_update_xattr_search(struct inode *inode,
if (xe->xe_name_len != xi->xi_name_len)
continue;
- /**
- * An empty local name/value pair takes no space, so
- * ocfs2_validate_xattr_entries_flat() allows offsets
- * just past the old storage. ocfs2_cp_xattr_block_to_bucket()
- * moves the data to the end of the bucket and adjusts each
- * offset. The empty pair then points just past the bucket.
- * Its name already matches, so don't look up a nonexistent
- * buffer.
- */
+ /* Empty names already match; no buffer access is needed. */
if (xi->xi_name_len) {
const char *name;
--
2.53.0