* [PATCH v4 0/9] Sashiko inspired OCFS2 fixes
@ 2026-12-05 10:14 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
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: Siddh Raman Pant @ 2026-12-05 10:14 UTC (permalink / raw)
To: Mark Fasheh, Joel Becker, Joseph Qi, Heming Zhao
Cc: ocfs2-devel, linux-kernel
Initially had posted the last commit (== v1), but Sashiko review loop
led to a rabbit hole with AI fun.
Thanks,
Siddh
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 invalid short 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 | 182 +++++++++++++++++++++++++++++++++--------------
1 file changed, 130 insertions(+), 52 deletions(-)
--
2.53.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v4 1/9] ocfs2: reject local xattrs with both an empty name and an empty value
2026-12-05 10:14 [PATCH v4 0/9] Sashiko inspired OCFS2 fixes Siddh Raman Pant
@ 2026-12-05 10:14 ` 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
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Siddh Raman Pant @ 2026-12-05 10:14 UTC (permalink / raw)
To: Mark Fasheh, Joel Becker, Joseph Qi, Heming Zhao
Cc: ocfs2-devel, linux-kernel
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] 10+ messages in thread
* [PATCH v4 2/9] ocfs2: reject xattr names that overlap the header or entries
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 ` Siddh Raman Pant
2026-12-05 10:14 ` [PATCH v4 3/9] ocfs2: reject invalid short external xattr values Siddh Raman Pant
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Siddh Raman Pant @ 2026-12-05 10:14 UTC (permalink / raw)
To: Mark Fasheh, Joel Becker, Joseph Qi, Heming Zhao
Cc: ocfs2-devel, linux-kernel
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] 10+ messages in thread
* [PATCH v4 3/9] ocfs2: reject invalid short external xattr values
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 ` Siddh Raman Pant
2026-12-05 10:14 ` [PATCH v4 4/9] ocfs2: check the space used by xattr values and value roots Siddh Raman Pant
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Siddh Raman Pant @ 2026-12-05 10:14 UTC (permalink / raw)
To: Mark Fasheh, Joel Becker, Joseph Qi, Heming Zhao
Cc: ocfs2-devel, linux-kernel
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, after all its clusters have been removed. Allow that entry
and use its local flag to account for the root during compaction and
removal.
Sashiko pointed out that reusing an empty external entry that still
claims clusters can hit BUG_ON(!orig_value_size) if resizing fails.
Once the value root is in bounds, check that an empty external value
has no clusters before allowing readers or writers to use it.
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 | 52 +++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 49 insertions(+), 3 deletions(-)
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index 2d32cba2a36f..769e01e61a45 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -26,6 +26,7 @@
#include <linux/module.h>
#include <linux/string.h>
#include <linux/security.h>
+#include <linux/unaligned.h>
#include <cluster/masklog.h>
@@ -228,13 +229,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,9 +263,36 @@ 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;
}
+static int ocfs2_validate_empty_xattr_root(struct super_block *sb, u64 blkno,
+ struct ocfs2_xattr_entry *xe,
+ const void *value)
+{
+ size_t off;
+ u32 clusters;
+
+ if (ocfs2_xattr_is_local(xe) || xe->xe_value_size)
+ return 0;
+
+ off = offsetof(struct ocfs2_xattr_value_root, xr_clusters);
+ clusters = get_unaligned_le32(value + off);
+ if (clusters)
+ return ocfs2_error(sb,
+ "Empty external xattr in block %llu has %u clusters\n",
+ (unsigned long long)blkno, clusters);
+
+ return 0;
+}
static int ocfs2_xattr_bucket_get_name_value(struct super_block *sb,
struct ocfs2_xattr_header *xh,
@@ -1153,6 +1189,11 @@ static int ocfs2_validate_xattr_entries_flat(struct super_block *sb, u64 blkno,
"Invalid xattr in block %llu: entry %d value root is out of bounds\n",
(unsigned long long)blkno, i);
}
+
+ ret = ocfs2_validate_empty_xattr_root(sb, blkno, xe,
+ (void *)xh + value_offset);
+ if (ret)
+ return ret;
}
return 0;
@@ -1275,6 +1316,7 @@ static int ocfs2_validate_xattr_bucket(struct ocfs2_xattr_bucket *bucket,
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);
if (ret)
@@ -1308,6 +1350,12 @@ static int ocfs2_validate_xattr_bucket(struct ocfs2_xattr_bucket *bucket,
"Invalid xattr bucket %llu: entry %d value root 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,
+ xe, value);
+ if (ret)
+ return ret;
}
return 0;
@@ -1917,8 +1965,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] 10+ messages in thread
* [PATCH v4 4/9] ocfs2: check the space used by xattr values and value roots
2026-12-05 10:14 [PATCH v4 0/9] Sashiko inspired OCFS2 fixes Siddh Raman Pant
` (2 preceding siblings ...)
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
2026-12-05 10:14 ` [PATCH v4 5/9] ocfs2: reject misaligned xattr name offsets Siddh Raman Pant
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Siddh Raman Pant @ 2026-12-05 10:14 UTC (permalink / raw)
To: Mark Fasheh, Joel Becker, Joseph Qi, Heming Zhao
Cc: ocfs2-devel, linux-kernel
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
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v4 5/9] ocfs2: reject misaligned xattr name offsets
2026-12-05 10:14 [PATCH v4 0/9] Sashiko inspired OCFS2 fixes Siddh Raman Pant
` (3 preceding siblings ...)
2026-12-05 10:14 ` [PATCH v4 4/9] ocfs2: check the space used by xattr values and value roots Siddh Raman Pant
@ 2026-12-05 10:14 ` Siddh Raman Pant
2026-12-05 10:14 ` [PATCH v4 6/9] ocfs2: reject overlapping entries in xattr blocks Siddh Raman Pant
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Siddh Raman Pant @ 2026-12-05 10:14 UTC (permalink / raw)
To: Mark Fasheh, Joel Becker, Joseph Qi, Heming Zhao
Cc: ocfs2-devel, linux-kernel
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 abec874b6a27..fe432222694d 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -80,6 +80,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)
@@ -1170,6 +1171,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] 10+ messages in thread
* [PATCH v4 6/9] ocfs2: reject overlapping entries in xattr blocks
2026-12-05 10:14 [PATCH v4 0/9] Sashiko inspired OCFS2 fixes Siddh Raman Pant
` (4 preceding siblings ...)
2026-12-05 10:14 ` [PATCH v4 5/9] ocfs2: reject misaligned xattr name offsets Siddh Raman Pant
@ 2026-12-05 10:14 ` 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
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Siddh Raman Pant @ 2026-12-05 10:14 UTC (permalink / raw)
To: Mark Fasheh, Joel Becker, Joseph Qi, Heming Zhao
Cc: ocfs2-devel, linux-kernel
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 fe432222694d..a390bcd82f76 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>
@@ -1135,15 +1136,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)) /
@@ -1158,7 +1160,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)
@@ -1189,6 +1191,16 @@ static int ocfs2_validate_xattr_entries_flat(struct super_block *sb, u64 blkno,
"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);
+
ret = ocfs2_validate_empty_xattr_root(sb, blkno, xe,
(void *)xh + value_offset);
if (ret)
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v4 7/9] ocfs2: copy all xattr names and values when converting a block
2026-12-05 10:14 [PATCH v4 0/9] Sashiko inspired OCFS2 fixes Siddh Raman Pant
` (5 preceding siblings ...)
2026-12-05 10:14 ` [PATCH v4 6/9] ocfs2: reject overlapping entries in xattr blocks Siddh Raman Pant
@ 2026-12-05 10:14 ` 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
8 siblings, 0 replies; 10+ messages in thread
From: Siddh Raman Pant @ 2026-12-05 10:14 UTC (permalink / raw)
To: Mark Fasheh, Joel Becker, Joseph Qi, Heming Zhao
Cc: ocfs2-devel, linux-kernel
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 a390bcd82f76..63f62a15a68e 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -2015,11 +2015,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);
@@ -2030,6 +2029,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)
{
@@ -4742,7 +4746,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;
@@ -4759,11 +4762,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);
@@ -4774,13 +4774,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] 10+ messages in thread
* [PATCH v4 8/9] ocfs2: exclude holes from the xattr bucket's name/value length
2026-12-05 10:14 [PATCH v4 0/9] Sashiko inspired OCFS2 fixes Siddh Raman Pant
` (6 preceding siblings ...)
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 ` Siddh Raman Pant
2026-12-05 10:14 ` [PATCH v4 9/9] ocfs2: use the bucket accessor when restoring xattr search Siddh Raman Pant
8 siblings, 0 replies; 10+ messages in thread
From: Siddh Raman Pant @ 2026-12-05 10:14 UTC (permalink / raw)
To: Mark Fasheh, Joel Becker, Joseph Qi, Heming Zhao
Cc: ocfs2-devel, linux-kernel
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 63f62a15a68e..d45cea78c7e0 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -4745,7 +4745,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;
@@ -4788,7 +4788,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. */
@@ -4797,11 +4796,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] 10+ messages in thread
* [PATCH v4 9/9] ocfs2: use the bucket accessor when restoring xattr search
2026-12-05 10:14 [PATCH v4 0/9] Sashiko inspired OCFS2 fixes Siddh Raman Pant
` (7 preceding siblings ...)
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 ` Siddh Raman Pant
8 siblings, 0 replies; 10+ messages in thread
From: Siddh Raman Pant @ 2026-12-05 10:14 UTC (permalink / raw)
To: Mark Fasheh, Joel Becker, Joseph Qi, Heming Zhao
Cc: ocfs2-devel, linux-kernel
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.
Let's resolve the offset with ocfs2_xattr_bucket_get_name_value() and
select the corresponding buffer, matching the other lookup paths, so
that we avoid inlined cross-buffer pointer arithmetic past xs->end
(which can also trick less intelligent AI models into a false OOB).
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 d45cea78c7e0..254cfc291892 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -4856,16 +4856,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] 10+ messages in thread
end of thread, other threads:[~2026-12-05 10:15 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH v4 4/9] ocfs2: check the space used by xattr values and value roots Siddh Raman Pant
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
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.