The ea block expansion need to access s_root while it is
already set as NULL when umount is triggered. Refuse this
request to avoid panic.
Reported-by: [email protected]
Link: https://syzkaller.appspot.com/bug?id=3613786cb88c93aa1c6a279b1df6a7b201347d08
Signed-off-by: Jun Nie <[email protected]>
---
fs/ext4/xattr.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index 235a517d9c17..ac58494e49b6 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -1422,6 +1422,12 @@ static struct inode *ext4_xattr_inode_create(handle_t *handle,
uid_t owner[2] = { i_uid_read(inode), i_gid_read(inode) };
int err;
+ if (inode->i_sb->s_root == NULL) {
+ ext4_error(inode->i_sb,
+ "refuse to create EA inode when umounting");
+ return ERR_PTR(-EINVAL);
+ }
+
/*
* Let the next inode be the goal, so we try and allocate the EA inode
* in the same group, or nearby one.
--
2.34.1
On Fri, Dec 30, 2022 at 07:00:16PM +0800, Jun Nie wrote:
> The ea block expansion need to access s_root while it is
> already set as NULL when umount is triggered. Refuse this
> request to avoid panic.
>
> Reported-by: [email protected]
> Link: https://syzkaller.appspot.com/bug?id=3613786cb88c93aa1c6a279b1df6a7b201347d08
> Signed-off-by: Jun Nie <[email protected]>
> ---
> fs/ext4/xattr.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
> index 235a517d9c17..ac58494e49b6 100644
> --- a/fs/ext4/xattr.c
> +++ b/fs/ext4/xattr.c
> @@ -1422,6 +1422,12 @@ static struct inode *ext4_xattr_inode_create(handle_t *handle,
> uid_t owner[2] = { i_uid_read(inode), i_gid_read(inode) };
> int err;
>
> + if (inode->i_sb->s_root == NULL) {
> + ext4_error(inode->i_sb,
> + "refuse to create EA inode when umounting");
> + return ERR_PTR(-EINVAL);
> + }
> +
Why is an xattr being set during unmount?
- Eric
On Fri, Dec 30, 2022 at 12:13:25PM -0800, Eric Biggers wrote:
> > diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
> > index 235a517d9c17..ac58494e49b6 100644
> > --- a/fs/ext4/xattr.c
> > +++ b/fs/ext4/xattr.c
> > @@ -1422,6 +1422,12 @@ static struct inode *ext4_xattr_inode_create(handle_t *handle,
> > uid_t owner[2] = { i_uid_read(inode), i_gid_read(inode) };
> > int err;
> >
> > + if (inode->i_sb->s_root == NULL) {
> > + ext4_error(inode->i_sb,
> > + "refuse to create EA inode when umounting");
> > + return ERR_PTR(-EINVAL);
> > + }
This should not be an ext4_error() since this is not a file system
corruption issue, but rather a kernel bug. (With the one known
example being corrected by the first patch in this patch series.
Thanks Jun for working on a patch to things!)
This should be replaced by an ext4_warning() followed by a WARN_ON(1),
so we can get the stack trace.
> Why is an xattr being set during unmount?
The scenario was discovered by syzbot; the reproducer did the moral
equivalent of this (attached) shell script. It required the
combination of lazytime and the debug_want_extra_isize mount options,
with a file system with (non-default) ea_inode feature enabled; so it
was highly unlikely to happen in real life.
For the detailed analysis, see [1]
[1] https://lore.kernel.org/all/[email protected]
- Ted
P.S. Converting this into an xfstests test script to test for a
regression of this bug (or a failure to backport this into various
stable kernels) is also left as an exercise to the reader. :-)
#!/bin/bash -vx
#
# This reproduces an ext4 bug caused by an unfortunate interaction
# between lazytime updates happening when a file system is being
# unmounted and expand_extra_isize
#
# Initially discovered via syzkaller:
# https://syzkaller.appspot.com/bug?id=3613786cb88c93aa1c6a279b1df6a7b201347d08
#
img=/tmp/foo.img
dir=/mnt
file=$dir/file0
rm -f $img
mke2fs -Fq -t ext4 -I 256 -O ea_inode -b 1024 $img 200k
mount $img $dir
v=$(dd if=/dev/zero bs=2000 count=1 2>/dev/null | tr '\0' =)
touch $file
attr -q -s test -V $v $file
umount $dir
mount -o debug_want_extra_isize=128,lazytime /tmp/foo.img $dir
cat $file
umount $dir