* [PATCH] ext2: reject xattr value overlapping the entry area
@ 2026-09-15 6:44 Guanglei Zhu
2026-09-15 6:52 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Guanglei Zhu @ 2026-09-15 6:44 UTC (permalink / raw)
To: Jan Kara; +Cc: linux-ext4, linux-kernel
ext2_xattr_entry_valid() checks that a value ends within the block but
not that it starts after the entry area, so a corrupted block can place
a value inside the entries. ext2_xattr_set() then underflows the free
space calculation:
free = min_offs - ((char*)last - (char*)header) - sizeof(__u32);
and writes the new value before the start of the block:
val = (char *)header + min_offs - size;
Check that the value area does not overlap the entry area and refuse
such a block instead.
Signed-off-by: Guanglei Zhu <zhugl3@xiaopeng.com>
---
A crafted ext2 image with an xattr entry whose e_value_offs lies inside
the entry area triggers, on a KASAN build, a use-after-free report in
ext2_xattr_set(). With this patch, setxattr() on such an image returns
-EIO instead.
fs/ext2/xattr.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
index 9b68c490a..2b89b758e 100644
--- a/fs/ext2/xattr.c
+++ b/fs/ext2/xattr.c
@@ -485,6 +485,14 @@ ext2_xattr_set(struct inode *inode, int name_index, const char *name,
if (not_found > 0)
here = last;
+ /*
+ * The value area must not overlap the entry area, otherwise
+ * the space calculation below underflows and the new value
+ * would be written before the start of the block.
+ */
+ if (min_offs < (size_t)((char *)last - (char *)header) + sizeof(__u32))
+ goto bad_block;
+
/* Check whether we have enough space left. */
free = min_offs - ((char*)last - (char*)header) - sizeof(__u32);
} else {
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ext2: reject xattr value overlapping the entry area
2026-09-15 6:44 [PATCH] ext2: reject xattr value overlapping the entry area Guanglei Zhu
@ 2026-09-15 6:52 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-09-15 6:52 UTC (permalink / raw)
To: Guanglei Zhu; +Cc: linux-ext4, tytso
> ext2_xattr_entry_valid() checks that a value ends within the block but
> not that it starts after the entry area, so a corrupted block can place
> a value inside the entries. ext2_xattr_set() then underflows the free
> space calculation:
>
> free = min_offs - ((char*)last - (char*)header) - sizeof(__u32);
>
> and writes the new value before the start of the block:
>
> val = (char *)header + min_offs - size;
>
> Check that the value area does not overlap the entry area and refuse
> such a block instead.
>
> Signed-off-by: Guanglei Zhu <zhugl3@xiaopeng.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260915064453.249419-1-zhugl3@xiaopeng.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-15 6:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-15 6:44 [PATCH] ext2: reject xattr value overlapping the entry area Guanglei Zhu
2026-09-15 6:52 ` sashiko-bot
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.