* [PATCH] ext4: validate xattr entries in ext4_xattr_move_to_block
@ 2025-09-23 9:25 Deepanshu Kartikey
2025-09-23 12:09 ` Theodore Ts'o
0 siblings, 1 reply; 2+ messages in thread
From: Deepanshu Kartikey @ 2025-09-23 9:25 UTC (permalink / raw)
To: tytso
Cc: adilger.kernel, linux-ext4, linux-kernel, Deepanshu Kartikey,
syzbot+4c9d23743a2409b80293
During inode expansion, ext4_xattr_move_to_block() processes xattr entries
from on-disk structures without validating their integrity. Corrupted
filesystems may contain xattr entries where e_value_size is zero but
e_value_inum is non-zero, indicating the entry claims to store its value
in a separate inode but has no actual value.
This corruption pattern leads to a WARNING in ext4_xattr_block_set() when
it encounters i->value_len of zero while i->in_inode is set, violating
the function's invariant that in-inode xattrs must have non-zero length.
Add validation in ext4_xattr_move_to_block() to detect this specific
corruption pattern and return -EFSCORRUPTED, preventing the invalid
data from propagating to downstream functions and causing warnings.
Reported-by: syzbot+4c9d23743a2409b80293@syzkaller.appspotmail.com
Link: https://syzkaller.appspot.com/bug?extid=4c9d23743a2409b80293
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
---
fs/ext4/xattr.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index 5a6fe1513fd2..60e224c622b4 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -2607,7 +2607,10 @@ static int ext4_xattr_move_to_block(handle_t *handle, struct inode *inode,
struct ext4_xattr_ibody_header *header = IHDR(inode, raw_inode);
int needs_kvfree = 0;
int error;
-
+ if (value_size == 0 && entry->e_value_inum != 0) {
+ error = -EFSCORRUPTED;
+ goto out;
+ }
is = kzalloc(sizeof(struct ext4_xattr_ibody_find), GFP_NOFS);
bs = kzalloc(sizeof(struct ext4_xattr_block_find), GFP_NOFS);
b_entry_name = kmalloc(entry->e_name_len + 1, GFP_NOFS);
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] ext4: validate xattr entries in ext4_xattr_move_to_block
2025-09-23 9:25 [PATCH] ext4: validate xattr entries in ext4_xattr_move_to_block Deepanshu Kartikey
@ 2025-09-23 12:09 ` Theodore Ts'o
0 siblings, 0 replies; 2+ messages in thread
From: Theodore Ts'o @ 2025-09-23 12:09 UTC (permalink / raw)
To: Deepanshu Kartikey
Cc: adilger.kernel, linux-ext4, linux-kernel,
syzbot+4c9d23743a2409b80293
On Tue, Sep 23, 2025 at 02:55:12PM +0530, Deepanshu Kartikey wrote:
> During inode expansion, ext4_xattr_move_to_block() processes xattr entries
> from on-disk structures without validating their integrity. Corrupted
> filesystems may contain xattr entries where e_value_size is zero but
> e_value_inum is non-zero, indicating the entry claims to store its value
> in a separate inode but has no actual value.
>
> This corruption pattern leads to a WARNING in ext4_xattr_block_set() when
> it encounters i->value_len of zero while i->in_inode is set, violating
> the function's invariant that in-inode xattrs must have non-zero length.
>
> Add validation in ext4_xattr_move_to_block() to detect this specific
> corruption pattern and return -EFSCORRUPTED, preventing the invalid
> data from propagating to downstream functions and causing warnings.
>
> Reported-by: syzbot+4c9d23743a2409b80293@syzkaller.appspotmail.com
> Link: https://syzkaller.appspot.com/bug?extid=4c9d23743a2409b80293
> Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
Thanks for the patch! Could you try moving the validation test to the
check_xattrs() function? This should hopefully catch other
maliciously fuzzed file systems so it might address other syzbot
complaints.
Something like:
if (ea_ino && !size) {
err_str = "invalid size in ea xattr";
goto errout;
}
In retrospect, we probably should have had the code interpret
e_value_size==0 as meaning that the xattr entry is always unused, so
that tests such as:
if (!last->e_value_inum && last->e_value_size) {
could become
if (last->e_value_size) {
But there are also places where the code assumes that if e_value_inum
is non-zero, it doesn't need to test e_value_size.
It should be the case where whenever we clear e_value_inum, we also
set i_value_size to zero. So having e_value_num!=0 && e_value_size==0
should only be the case when someone is trying to maliciously play
games with us.
Cheers,
- Ted
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-09-23 12:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-23 9:25 [PATCH] ext4: validate xattr entries in ext4_xattr_move_to_block Deepanshu Kartikey
2025-09-23 12:09 ` Theodore Ts'o
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).