From: "Theodore Ts'o" <tytso@mit.edu>
To: Edward Adam Davis <eadavis@qq.com>
Cc: syzbot+ee72b9a7aad1e5a77c5c@syzkaller.appspotmail.com,
adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
syzkaller-bugs@googlegroups.com
Subject: Re: [PATCH] ext4: fix deadlock in ext4_xattr_inode_iget
Date: Wed, 19 Jun 2024 23:10:44 -0400 [thread overview]
Message-ID: <20240620031044.GB1553731@mit.edu> (raw)
In-Reply-To: <tencent_9E9EB81B474B0E1B23256EBA05BB79332408@qq.com>
On Thu, Apr 04, 2024 at 09:54:02AM +0800, Edward Adam Davis wrote:
> According to mark inode dirty context, it does not need to be protected by lock
> i_data_sem, and if it is protected by i_data_sem, a deadlock will occur.
The i_data_sem lock is not to protect mark_inode_dirty_context, but to
avoid races with the writeback code, which you can see right before
you added the down_write() line.
More detail about why it is necessary can be found in commit
90e775b71ac4 ("ext4: fix lost truncate due to race with writeback"):
The following race can lead to a loss of i_disksize update from truncate
thus resulting in a wrong inode size if the inode size isn't updated
again before inode is reclaimed:
ext4_setattr() mpage_map_and_submit_extent()
EXT4_I(inode)->i_disksize = attr->ia_size;
... ...
disksize = ((loff_t)mpd->first_page) << PAGE_CACHE_SHIFT
/* False because i_size isn't
* updated yet */
if (disksize > i_size_read(inode))
/* True, because i_disksize is
* already truncated */
if (disksize > EXT4_I(inode)->i_disksize)
/* Overwrite i_disksize
* update from truncate */
ext4_update_i_disksize()
i_size_write(inode, attr->ia_size);
For other places updating i_disksize such race cannot happen because
i_mutex prevents these races. Writeback is the only place where we do
not hold i_mutex and we cannot grab it there because of lock ordering.
We fix the race by doing both i_disksize and i_size update in truncate
Atomically under i_data_sem and in mpage_map_and_submit_extent() we move
the check against i_size under i_data_sem as well.
So your proposed fix would introduce a regression by re-enabling the
bug which is fixed by commit 90e775b71ac4.
In any case, as Andreas has pointed out, this is a false positive; the
supposed deadlock involves an ea_inode in stack trace #0, whereas the
stack trace #1 involves a write to a data inode. Andreas has
suggested fixing this by annotating the lock appropriately. This case
is not going to happen in real production systems today, since
triggering it requires using the debugging mount option
debug_want_extra_isize.
So while it would be good to avoid the false positive lockdep warning,
fixing this is a lower priority bug --- it certainly isn't security
issue that syzbot developers like to point at when talking about the
"Linux security disaster". It isn't even a real production level bug!
Cheers,
- Ted
next prev parent reply other threads:[~2024-06-20 3:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-03 7:45 [syzbot] [ext4?] possible deadlock in ext4_xattr_inode_iget (3) syzbot
2024-04-04 1:54 ` [PATCH] ext4: fix deadlock in ext4_xattr_inode_iget Edward Adam Davis
2024-06-20 3:10 ` Theodore Ts'o [this message]
2024-04-08 21:38 ` [syzbot] [ext4?] possible deadlock in ext4_xattr_inode_iget (3) Andreas Dilger
2024-11-02 22:58 ` syzbot
2024-11-07 17:14 ` Jan Kara
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=20240620031044.GB1553731@mit.edu \
--to=tytso@mit.edu \
--cc=adilger.kernel@dilger.ca \
--cc=eadavis@qq.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=syzbot+ee72b9a7aad1e5a77c5c@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
/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;
as well as URLs for NNTP newsgroup(s).