public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Theodore Ts'o" <tytso@mit.edu>
To: Eric Biggers <ebiggers@kernel.org>
Cc: Jun Nie <jun.nie@linaro.org>,
	adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org,
	linux-kernel@vger.kernel.org, tudor.ambarus@linaro.org
Subject: Re: [PATCH 2/2] ext4: refuse to create ea block when umounted
Date: Fri, 30 Dec 2022 22:27:37 -0500	[thread overview]
Message-ID: <Y6+sKX4bgSZ3RNrk@mit.edu> (raw)
In-Reply-To: <Y69GZdLcWkCvZhq1@sol.localdomain>

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/Y5wGZG05uicAPscI@mit.edu

					- 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

      reply	other threads:[~2022-12-31  3:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-30 11:00 [PATCH 1/2] ext4: optimize ea_inode block expansion Jun Nie
2022-12-30 11:00 ` [PATCH 2/2] ext4: refuse to create ea block when umounted Jun Nie
2022-12-30 20:13   ` Eric Biggers
2022-12-31  3:27     ` Theodore Ts'o [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y6+sKX4bgSZ3RNrk@mit.edu \
    --to=tytso@mit.edu \
    --cc=adilger.kernel@dilger.ca \
    --cc=ebiggers@kernel.org \
    --cc=jun.nie@linaro.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tudor.ambarus@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox