* [PATCH v2 1/2] ocfs2: use the bucket accessor when restoring xattr search
[not found] <sashiko-outbox-249784@kernel.org>
@ 2026-12-04 15:26 ` 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
1 sibling, 1 reply; 12+ messages in thread
From: Siddh Raman Pant @ 2026-12-04 15:26 UTC (permalink / raw)
To: Mark Fasheh, Joel Becker, Joseph Qi, Heming Zhao
Cc: ocfs2-devel, linux-kernel, sashiko-reviews
ocfs2_xattr_update_xattr_search() compares candidate names using a
bucket-relative offset from the first buffer. Cluster alignment keeps
the whole bucket in one page, so valid names are already reached
correctly.
ocfs2_validate_xattr_bucket() already documents that the entry array
is contiguous across the bucket's buffer heads and that cluster
alignment keeps the whole bucket in one page. It rejects an unaligned
bucket block number before accessing the entry array. The conversion
adjusts each xe_name_offset to be relative to the whole bucket.
But less powerful AI models can trip on this code and complain about
an OOB access because the context around the call path was missed.
So let's resolve the offset with ocfs2_xattr_bucket_get_name_value()
and select the corresponding buffer, matching the other bucket lookup
paths which also operate under the same guarantee.
Signed-off-by: Siddh Raman Pant <siddh.raman.pant@oracle.com>
---
fs/ocfs2/xattr.c | 32 ++++++++++++++++++++++++++++----
1 file changed, 28 insertions(+), 4 deletions(-)
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index 71e5986bafaa..1b013ca43efb 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -4794,16 +4794,40 @@ static void ocfs2_xattr_update_xattr_search(struct inode *inode,
count = le16_to_cpu(xs->header->xh_count);
for (i = 0; i < count; i++) {
struct ocfs2_xattr_entry *xe = &xs->header->xh_entries[i];
+ int block_off, name_off;
if (ocfs2_xattr_get_type(xe) != xi->xi_name_index)
continue;
+
if (xe->xe_name_len != xi->xi_name_len)
continue;
- if (!memcmp(xs->base + le16_to_cpu(xe->xe_name_offset),
- xi->xi_name, xi->xi_name_len)) {
- xs->here = xe;
- return;
+
+ /**
+ * 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.
+ */
+ if (xi->xi_name_len) {
+ const char *name;
+
+ if (ocfs2_xattr_bucket_get_name_value(inode->i_sb,
+ xs->header, i,
+ &block_off,
+ &name_off))
+ continue;
+
+ name = bucket_block(xs->bucket, block_off) + name_off;
+
+ if (memcmp(name, xi->xi_name, xi->xi_name_len))
+ continue;
}
+
+ xs->here = xe;
+ return;
}
/*
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 2/2] ocfs2: reject xattr names at the end of their storage
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 ` Siddh Raman Pant
0 siblings, 0 replies; 12+ messages in thread
From: Siddh Raman Pant @ 2026-12-04 15:26 UTC (permalink / raw)
To: Mark Fasheh, Joel Becker, Joseph Qi, Heming Zhao
Cc: ocfs2-devel, linux-kernel, sashiko-reviews
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@kernel.org>
Link: https://sashiko.dev/#/patchset/20261204120536.161006-1-siddh.raman.pant@oracle.com?part=1
Fixes: 8914a3330b72 ("ocfs2: validate inline xattrs during inode block validation")
Signed-off-by: Siddh Raman Pant <siddh.raman.pant@oracle.com>
---
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
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v3 0/9] Sashiko inspired OCFS2 fixes
[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-05 8:08 ` 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
` (8 more replies)
1 sibling, 9 replies; 12+ messages in thread
From: Siddh Raman Pant @ 2026-12-05 8:08 UTC (permalink / raw)
To: Mark Fasheh, Joel Becker, Joseph Qi, Heming Zhao
Cc: ocfs2-devel, linux-kernel, sashiko-reviews
Initially started from last commit, but Sashiko review twice led to a
rabbit hole with AI fun.
Siddh Raman Pant (9):
ocfs2: reject local xattrs with both an empty name and an empty value
ocfs2: reject xattr names that overlap the header or entries
ocfs2: reject short nonempty external xattr values
ocfs2: check the space used by xattr values and value roots
ocfs2: reject misaligned xattr name offsets
ocfs2: reject overlapping entries in xattr blocks
ocfs2: copy all xattr names and values when converting a block
ocfs2: exclude holes from the xattr bucket's name/value length
ocfs2: use the bucket accessor when restoring xattr search
fs/ocfs2/xattr.c | 150 +++++++++++++++++++++++++++++++----------------
1 file changed, 98 insertions(+), 52 deletions(-)
--
2.53.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v3 1/9] ocfs2: reject local xattrs with both an empty name and an empty value
2026-12-05 8:08 ` [PATCH v3 0/9] Sashiko inspired OCFS2 fixes Siddh Raman Pant
@ 2026-12-05 8:08 ` 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
` (7 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Siddh Raman Pant @ 2026-12-05 8:08 UTC (permalink / raw)
To: Mark Fasheh, Joel Becker, Joseph Qi, Heming Zhao
Cc: ocfs2-devel, linux-kernel, sashiko-reviews
ocfs2_validate_xattr_entries_flat() allows xe_name_offset to equal
region_size when both the name and local value are empty. Converting
the block to a bucket moves that offset to OCFS2_XATTR_BUCKET_SIZE.
If the entry survives the update, ocfs2_validate_xattr_bucket()
rejects it on the next read and makes the filesystem read-only.
Even an empty pair that starts inside its block can reach the end.
ocfs2_xa_block_wipe_namevalue() can shift it there when removing
another entry. ocfs2_defrag_xattr_bucket() can also place it there
when packing a bucket, and the next lookup uses a nonexistent buffer.
Reject an empty local pair in ocfs2_validate_xattr_entry(), which
checks both blocks and buckets. An ACL has an empty name and a
value. A named attribute can still have an empty value.
A Sashiko review of another patch exposed this missing bounds check.
Fixes: 012255961c9e ("ocfs2: Enable xattr set in index btree")
Reported-by: Sashiko AI <sashiko-bot@kernel.org>
Link: https://sashiko.dev/#/patchset/20261204120536.161006-1-siddh.raman.pant@oracle.com?part=1
Link: https://sashiko.dev/#/patchset/20261204152650.349289-1-siddh.raman.pant@oracle.com?part=2
Signed-off-by: Siddh Raman Pant <siddh.raman.pant@oracle.com>
---
fs/ocfs2/xattr.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index 71e5986bafaa..5fc71934b069 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -242,6 +242,11 @@ static int ocfs2_validate_xattr_entry(struct super_block *sb, u64 blkno,
{
u64 value_len = le64_to_cpu(xe->xe_value_size);
+ if (ocfs2_xattr_is_local(xe) && !xe->xe_name_len && !value_len)
+ return ocfs2_error(sb,
+ "Xattr in block %llu has neither a name nor a value\n",
+ (unsigned long long)blkno);
+
if (value_len > OCFS2_XATTR_INLINE_SIZE &&
ocfs2_xattr_is_local(xe))
return ocfs2_error(sb,
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v3 2/9] ocfs2: reject xattr names that overlap the header or entries
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 ` Siddh Raman Pant
2026-12-05 8:08 ` [PATCH v3 3/9] ocfs2: reject short nonempty external xattr values Siddh Raman Pant
` (6 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Siddh Raman Pant @ 2026-12-05 8:08 UTC (permalink / raw)
To: Mark Fasheh, Joel Becker, Joseph Qi, Heming Zhao
Cc: ocfs2-devel, linux-kernel, sashiko-reviews
ocfs2_validate_xattr_entries_flat() checks where a name ends, but
allows it to start inside the header or the entry array. A lookup
can then return entry metadata as the xattr value.
Require the name to start after the entry array and before the end
of xattr storage.
Fixes: cf1d6c763fbc ("ocfs2: Add extended attribute support")
Signed-off-by: Siddh Raman Pant <siddh.raman.pant@oracle.com>
---
fs/ocfs2/xattr.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index 5fc71934b069..2d32cba2a36f 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -1128,7 +1128,8 @@ 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 < struct_size(xh, xh_entries, xattr_count) ||
+ 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",
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v3 3/9] ocfs2: reject short nonempty external xattr values
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 ` 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
` (5 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Siddh Raman Pant @ 2026-12-05 8:08 UTC (permalink / raw)
To: Mark Fasheh, Joel Becker, Joseph Qi, Heming Zhao
Cc: ocfs2-devel, linux-kernel, sashiko-reviews
OCFS2 stores values up to OCFS2_XATTR_INLINE_SIZE locally. If a
short value is marked external, removal expects a value root, but
namevalue_size_xe() uses the value length to calculate its storage
size. The mismatch can hit BUG_ON() in ocfs2_xa_fill_value_buf().
Reject a nonzero external value at or below the inline size limit in
ocfs2_validate_xattr_entry(). A zero-length external value can be
journaled by ocfs2_xattr_bucket_value_truncate() during inode
deletion. Allow that entry and use its local flag to account for the
root during compaction and removal.
Fixes: 3fc12afa0cea ("ocfs2: Provide ocfs2_xa_fill_value_buf() for external value processing")
Signed-off-by: Siddh Raman Pant <siddh.raman.pant@oracle.com>
---
fs/ocfs2/xattr.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index 2d32cba2a36f..f00ed6389b20 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -228,13 +228,21 @@ static int namevalue_size_xi(struct ocfs2_xattr_info *xi)
return namevalue_size(xi->xi_name_len, xi->xi_value_len);
}
+static int ocfs2_xattr_value_size(struct ocfs2_xattr_entry *xe)
+{
+ if (!ocfs2_xattr_is_local(xe))
+ return OCFS2_XATTR_ROOT_SIZE;
+
+ return OCFS2_XATTR_SIZE(le64_to_cpu(xe->xe_value_size));
+}
+
static int namevalue_size_xe(struct ocfs2_xattr_entry *xe)
{
u64 value_len = le64_to_cpu(xe->xe_value_size);
BUG_ON((value_len > OCFS2_XATTR_INLINE_SIZE) &&
ocfs2_xattr_is_local(xe));
- return namevalue_size(xe->xe_name_len, value_len);
+ return OCFS2_XATTR_SIZE(xe->xe_name_len) + ocfs2_xattr_value_size(xe);
}
static int ocfs2_validate_xattr_entry(struct super_block *sb, u64 blkno,
@@ -254,6 +262,14 @@ static int ocfs2_validate_xattr_entry(struct super_block *sb, u64 blkno,
(unsigned long long)blkno,
(unsigned long long)value_len);
+ /* Inode deletion can leave a truncated external value in a bucket. */
+ if (!ocfs2_xattr_is_local(xe) && value_len &&
+ value_len <= OCFS2_XATTR_INLINE_SIZE)
+ return ocfs2_error(sb,
+ "Invalid external xattr in block %llu: value size %llu\n",
+ (unsigned long long)blkno,
+ (unsigned long long)value_len);
+
return 0;
}
@@ -1917,8 +1933,6 @@ static void ocfs2_xa_fill_value_buf(struct ocfs2_xa_loc *loc,
/* Value bufs are for value trees */
BUG_ON(ocfs2_xattr_is_local(loc->xl_entry));
- BUG_ON(namevalue_size_xe(loc->xl_entry) !=
- (name_size + OCFS2_XATTR_ROOT_SIZE));
loc->xl_ops->xlo_fill_value_buf(loc, vb);
vb->vb_xv =
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v3 4/9] ocfs2: check the space used by xattr values and value roots
2026-12-05 8:08 ` [PATCH v3 0/9] Sashiko inspired OCFS2 fixes Siddh Raman Pant
` (2 preceding siblings ...)
2026-12-05 8:08 ` [PATCH v3 3/9] ocfs2: reject short nonempty external xattr values Siddh Raman Pant
@ 2026-12-05 8:08 ` Siddh Raman Pant
2026-12-05 8:08 ` [PATCH v3 5/9] ocfs2: reject misaligned xattr name offsets Siddh Raman Pant
` (4 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Siddh Raman Pant @ 2026-12-05 8:08 UTC (permalink / raw)
To: Mark Fasheh, Joel Becker, Joseph Qi, Heming Zhao
Cc: ocfs2-devel, linux-kernel, sashiko-reviews
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 f00ed6389b20..662ccca685b1 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -1137,8 +1137,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)
@@ -1157,18 +1156,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);
- }
}
return 0;
@@ -1290,7 +1283,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);
ret = ocfs2_validate_xattr_entry(sb, blkno, xe);
if (ret)
@@ -1312,18 +1304,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);
- }
}
return 0;
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v3 5/9] ocfs2: reject misaligned xattr name offsets
2026-12-05 8:08 ` [PATCH v3 0/9] Sashiko inspired OCFS2 fixes Siddh Raman Pant
` (3 preceding siblings ...)
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 ` Siddh Raman Pant
2026-12-05 8:08 ` [PATCH v3 6/9] ocfs2: reject overlapping entries in xattr blocks Siddh Raman Pant
` (3 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Siddh Raman Pant @ 2026-12-05 8:08 UTC (permalink / raw)
To: Mark Fasheh, Joel Becker, Joseph Qi, Heming Zhao
Cc: ocfs2-devel, linux-kernel, sashiko-reviews
OCFS2 packs name/value pairs backwards from the end of xattr storage.
ocfs2_xa_block_add_namevalue() subtracts the aligned size of a new
pair from the lowest existing offset. If that offset is misaligned,
each new pair inherits the misalignment.
Check the alignment of xe_name_offset relative to the end of xattr
storage in ocfs2_validate_xattr_entries_flat().
Fixes: cf1d6c763fbc ("ocfs2: Add extended attribute support")
Signed-off-by: Siddh Raman Pant <siddh.raman.pant@oracle.com>
---
fs/ocfs2/xattr.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index 662ccca685b1..3d5abc4516b7 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -79,6 +79,7 @@ struct ocfs2_xattr_set_ctxt {
#define OCFS2_XATTR_ROOT_SIZE (sizeof(struct ocfs2_xattr_def_value_root))
#define OCFS2_XATTR_INLINE_SIZE 80
#define OCFS2_XATTR_HEADER_GAP 4
+#define OCFS2_XATTR_ALIGN (OCFS2_XATTR_ROUND + 1)
#define OCFS2_XATTR_FREE_IN_IBODY (OCFS2_MIN_XATTR_INLINE_SIZE \
- sizeof(struct ocfs2_xattr_header) \
- OCFS2_XATTR_HEADER_GAP)
@@ -1150,6 +1151,11 @@ static int ocfs2_validate_xattr_entries_flat(struct super_block *sb, u64 blkno,
"Invalid xattr in block %llu: entry %d name is out of bounds\n",
(unsigned long long)blkno, i);
+ if (!IS_ALIGNED(nv_limit - name_offset, OCFS2_XATTR_ALIGN))
+ return ocfs2_error(sb,
+ "Invalid xattr in block %llu: entry %d name offset %zu is misaligned\n",
+ (unsigned long long)blkno, i, name_offset);
+
value_offset = name_offset + OCFS2_XATTR_SIZE(xe->xe_name_len);
if (value_offset > nv_limit)
return ocfs2_error(sb,
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v3 6/9] ocfs2: reject overlapping entries in xattr blocks
2026-12-05 8:08 ` [PATCH v3 0/9] Sashiko inspired OCFS2 fixes Siddh Raman Pant
` (4 preceding siblings ...)
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
2026-12-05 8:08 ` [PATCH v3 7/9] ocfs2: copy all xattr names and values when converting a block Siddh Raman Pant
` (2 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Siddh Raman Pant @ 2026-12-05 8:08 UTC (permalink / raw)
To: Mark Fasheh, Joel Becker, Joseph Qi, Heming Zhao
Cc: ocfs2-devel, linux-kernel, sashiko-reviews
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
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v3 7/9] ocfs2: copy all xattr names and values when converting a block
2026-12-05 8:08 ` [PATCH v3 0/9] Sashiko inspired OCFS2 fixes Siddh Raman Pant
` (5 preceding siblings ...)
2026-12-05 8:08 ` [PATCH v3 6/9] ocfs2: reject overlapping entries in xattr blocks Siddh Raman Pant
@ 2026-12-05 8:08 ` 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
8 siblings, 0 replies; 12+ messages in thread
From: Siddh Raman Pant @ 2026-12-05 8:08 UTC (permalink / raw)
To: Mark Fasheh, Joel Becker, Joseph Qi, Heming Zhao
Cc: ocfs2-devel, linux-kernel, sashiko-reviews
ocfs2_cp_xattr_block_to_bucket() starts copying names and values at
the offset in the last entry. Resizing an earlier xattr can move its
name and value to a lower offset without changing its position in the
entry array. If the block then fills up, conversion skips those bytes
and the resized attribute can no longer be found.
Find the lowest name offset across all entries, as the block allocator
already does, and copy from there to the end of the block.
Fixes: 012255961c9e ("ocfs2: Enable xattr set in index btree")
Signed-off-by: Siddh Raman Pant <siddh.raman.pant@oracle.com>
---
fs/ocfs2/xattr.c | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index 75036d0fd9b6..2ea5a3c036bf 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -1983,11 +1983,10 @@ static int ocfs2_xa_block_can_reuse(struct ocfs2_xa_loc *loc,
namevalue_size_xi(xi);
}
-static int ocfs2_xa_block_get_free_start(struct ocfs2_xa_loc *loc)
+static int ocfs2_xattr_min_offset(struct ocfs2_xattr_header *xh, int free_start)
{
- struct ocfs2_xattr_header *xh = loc->xl_header;
int i, count = le16_to_cpu(xh->xh_count);
- int offset, free_start = loc->xl_size;
+ int offset;
for (i = 0; i < count; i++) {
offset = le16_to_cpu(xh->xh_entries[i].xe_name_offset);
@@ -1998,6 +1997,11 @@ static int ocfs2_xa_block_get_free_start(struct ocfs2_xa_loc *loc)
return free_start;
}
+static int ocfs2_xa_block_get_free_start(struct ocfs2_xa_loc *loc)
+{
+ return ocfs2_xattr_min_offset(loc->xl_header, loc->xl_size);
+}
+
static int ocfs2_xa_block_check_space(struct ocfs2_xa_loc *loc,
struct ocfs2_xattr_info *xi)
{
@@ -4710,7 +4714,6 @@ 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;
- struct ocfs2_xattr_entry *xe;
struct ocfs2_xattr_block *xb =
(struct ocfs2_xattr_block *)xb_bh->b_data;
struct ocfs2_xattr_header *xb_xh = &xb->xb_attrs.xb_header;
@@ -4727,11 +4730,8 @@ static void ocfs2_cp_xattr_block_to_bucket(struct inode *inode,
memset(bucket_block(bucket, i), 0, blocksize);
/*
- * An empty block has no names or values to carry over, and the
- * xh_entries[count - 1] below would be xh_entries[-1]. Leave the
- * bucket empty, but carry over the hash ocfs2_xa_remove_entry() left
- * in the block's xh_entries[0] so that the bucket still holds the key
- * it is looked up by.
+ * An empty bucket still needs the hash ocfs2_xa_remove_entry()
+ * left in the block's first entry.
*/
if (!count) {
xh->xh_num_buckets = cpu_to_le16(1);
@@ -4742,13 +4742,12 @@ static void ocfs2_cp_xattr_block_to_bucket(struct inode *inode,
}
/*
- * Since the xe_name_offset is based on ocfs2_xattr_header,
- * there is a offset change corresponding to the change of
- * ocfs2_xattr_header's position.
+ * Resizing an xattr can move its name/value pair below the last
+ * entry's pair. Copy from the lowest name offset in the block.
*/
off_change = offsetof(struct ocfs2_xattr_block, xb_attrs.xb_header);
- xe = &xb_xh->xh_entries[count - 1];
- offset = le16_to_cpu(xe->xe_name_offset) + off_change;
+ offset = ocfs2_xattr_min_offset(xb_xh, blocksize - off_change);
+ offset += off_change;
size = blocksize - offset;
/* copy all the names and values. */
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v3 8/9] ocfs2: exclude holes from the xattr bucket's name/value length
2026-12-05 8:08 ` [PATCH v3 0/9] Sashiko inspired OCFS2 fixes Siddh Raman Pant
` (6 preceding siblings ...)
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 ` Siddh Raman Pant
2026-12-05 8:09 ` [PATCH v3 9/9] ocfs2: use the bucket accessor when restoring xattr search Siddh Raman Pant
8 siblings, 0 replies; 12+ messages in thread
From: Siddh Raman Pant @ 2026-12-05 8:08 UTC (permalink / raw)
To: Mark Fasheh, Joel Becker, Joseph Qi, Heming Zhao
Cc: ocfs2-devel, linux-kernel, sashiko-reviews
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 2ea5a3c036bf..9f21a0d3ebae 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -4713,7 +4713,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;
@@ -4756,7 +4756,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. */
@@ -4765,11 +4764,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
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v3 9/9] ocfs2: use the bucket accessor when restoring xattr search
2026-12-05 8:08 ` [PATCH v3 0/9] Sashiko inspired OCFS2 fixes Siddh Raman Pant
` (7 preceding siblings ...)
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 ` Siddh Raman Pant
8 siblings, 0 replies; 12+ messages in thread
From: Siddh Raman Pant @ 2026-12-05 8:09 UTC (permalink / raw)
To: Mark Fasheh, Joel Becker, Joseph Qi, Heming Zhao
Cc: ocfs2-devel, linux-kernel, sashiko-reviews
ocfs2_xattr_update_xattr_search() compares candidate names using a
bucket-relative offset from the first buffer. Cluster alignment keeps
the whole bucket in one page, so valid names are already reached
correctly.
ocfs2_validate_xattr_bucket() already documents that the entry array
is contiguous across the bucket's buffer heads and that cluster
alignment keeps the whole bucket in one page. It rejects an unaligned
bucket block number before accessing the entry array. Here,
ocfs2_xattr_create_index_block() places the bucket at the start of a
newly allocated cluster. The conversion adjusts each xe_name_offset
to be relative to the whole bucket.
But less powerful AI models can trip on this code and complain about
an OOB access because the context around the call path was missed.
The review treated xs->end as the end of the whole bucket, even
though it marks only the end of the first buffer.
So let's resolve the offset with ocfs2_xattr_bucket_get_name_value()
and select the corresponding buffer, matching the other bucket lookup
paths which also operate under the same guarantee.
When both names are empty and the namespaces match, skip the buffer
lookup. The old memcmp() read zero bytes even when an empty pair
pointed just past the last buffer.
Signed-off-by: Siddh Raman Pant <siddh.raman.pant@oracle.com>
---
fs/ocfs2/xattr.c | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index 9f21a0d3ebae..f786867a666d 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -4824,16 +4824,32 @@ static void ocfs2_xattr_update_xattr_search(struct inode *inode,
count = le16_to_cpu(xs->header->xh_count);
for (i = 0; i < count; i++) {
struct ocfs2_xattr_entry *xe = &xs->header->xh_entries[i];
+ int block_off, name_off;
if (ocfs2_xattr_get_type(xe) != xi->xi_name_index)
continue;
+
if (xe->xe_name_len != xi->xi_name_len)
continue;
- if (!memcmp(xs->base + le16_to_cpu(xe->xe_name_offset),
- xi->xi_name, xi->xi_name_len)) {
- xs->here = xe;
- return;
+
+ /* Empty names already match; no buffer access is needed. */
+ if (xi->xi_name_len) {
+ const char *name;
+
+ if (ocfs2_xattr_bucket_get_name_value(inode->i_sb,
+ xs->header, i,
+ &block_off,
+ &name_off))
+ continue;
+
+ name = bucket_block(xs->bucket, block_off) + name_off;
+
+ if (memcmp(name, xi->xi_name, xi->xi_name_len))
+ continue;
}
+
+ xs->here = xe;
+ return;
}
/*
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-12-05 8:10 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[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 ` [PATCH v3 6/9] ocfs2: reject overlapping entries in xattr blocks Siddh Raman Pant
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
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.