From: Chunwei Chen <david.chen@osnexus.com>
To: linux-kernel@vger.kernel.org
Cc: Chunwei Chen <david.chen@osnexus.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
linux-fsdevel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH] vfs: check i_count under lock in evict_inodes
Date: Mon, 11 Jul 2016 17:15:04 -0700 [thread overview]
Message-ID: <1468282504-2272-1-git-send-email-david.chen@osnexus.com> (raw)
We need to check i_count again with i_lock held, because iput might re-add
i_count when lazytime is on. Without this check, we could end up with
double-free or use-after-free.
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Signed-off-by: Chunwei Chen <david.chen@osnexus.com>
---
fs/inode.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/fs/inode.c b/fs/inode.c
index 4ccbc21..10bb020 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -607,7 +607,12 @@ again:
continue;
spin_lock(&inode->i_lock);
- if (inode->i_state & (I_NEW | I_FREEING | I_WILL_FREE)) {
+ /*
+ * check i_count again with lock, because iput might re-add
+ * it when lazytime is on.
+ */
+ if (atomic_read(&inode->i_count) ||
+ (inode->i_state & (I_NEW | I_FREEING | I_WILL_FREE))) {
spin_unlock(&inode->i_lock);
continue;
}
--
2.7.4
next reply other threads:[~2016-07-12 0:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-12 0:15 Chunwei Chen [this message]
2016-07-12 0:46 ` [PATCH] vfs: check i_count under lock in evict_inodes Al Viro
2016-07-12 1:31 ` David Chen
2016-07-12 1:40 ` Christoph Hellwig
2016-07-12 5:26 ` Al Viro
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=1468282504-2272-1-git-send-email-david.chen@osnexus.com \
--to=david.chen@osnexus.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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).