From: Jan Kara <jack@suse.cz>
To: Xiaoguang Wang <xiaoguang.wang@linux.alibaba.com>
Cc: tj@kernel.org, linux-fsdevel@vger.kernel.org,
joseph qi <joseph.qi@linux.alibaba.com>
Subject: Re: Does have race between __mark_inode_dirty() and evict()
Date: Thu, 23 Apr 2020 17:27:06 +0200 [thread overview]
Message-ID: <20200423152706.GA28707@quack2.suse.cz> (raw)
In-Reply-To: <fdf7f9da-4516-f5c3-c5c9-06a1a3f8e55a@linux.alibaba.com>
Hi!
On Mon 20-04-20 14:23:19, Xiaoguang Wang wrote:
> Recently we run into a NULL pointer dereference panic in our internal 4.9
> kernel it panics because inode->i_wb has become zero in
> wbc_attach_and_unlock_inode(), and by crash tools analysis, inode's
> dirtied_when is zero, but dirtied_time_when is not zero, seems that this
> inode has been used after free. Looking into both 4.9 and upstream codes,
> seems that there maybe a race:
>
> __mark_inode_dirty(...)
> {
> spin_lock(&inode->i_lock);
> ...
> if (inode->i_state & I_FREEING)
> goto out_unlock_inode;
> ...
> if (!was_dirty) {
> struct bdi_writeback *wb;
> struct list_head *dirty_list;
> bool wakeup_bdi = false;
>
> wb = locked_inode_to_wb_and_lock_list(inode);
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> this function will unlock inode->i_ilock firstly and then relock,
> but once the inode->i_ilock is unlocked, evict() may run in, set
> I_FREEING flag, and free the inode, and later
> locked_inode_to_wb_and_lock_list relocks inode->i_ilock again, but
> will not check the I_FREEING flag again, so the use after free for
> this inode would happen.
If someone is calling __mark_inode_dirty(), he should be holding inode
reference (either directly or indirectly through having dentry reference,
file open, ...) which prevents the scenario you suggest.
But I've just recently tracked down a very similarly looking issue reported
to me. I've submitted patches to fix it here [1].
[1] https://lore.kernel.org/linux-ext4/20200421085445.5731-1-jack@suse.cz
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
prev parent reply other threads:[~2020-04-23 15:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-20 6:23 Does have race between __mark_inode_dirty() and evict() Xiaoguang Wang
2020-04-23 15:27 ` Jan Kara [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=20200423152706.GA28707@quack2.suse.cz \
--to=jack@suse.cz \
--cc=joseph.qi@linux.alibaba.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=tj@kernel.org \
--cc=xiaoguang.wang@linux.alibaba.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).