Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1440981 > unrolled thread
| Started by | Chunwei Chen <david.chen@osnexus.com> |
|---|---|
| First post | 2016-07-12 02:30 +0200 |
| Last post | 2016-07-12 07:30 +0200 |
| Articles | 5 — 4 participants |
Back to article view | Back to linux.kernel
[PATCH] vfs: check i_count under lock in evict_inodes Chunwei Chen <david.chen@osnexus.com> - 2016-07-12 02:30 +0200
Re: [PATCH] vfs: check i_count under lock in evict_inodes Al Viro <viro@ZenIV.linux.org.uk> - 2016-07-12 02:50 +0200
Re: [PATCH] vfs: check i_count under lock in evict_inodes David Chen <david.chen@osnexus.com> - 2016-07-12 03:40 +0200
Re: [PATCH] vfs: check i_count under lock in evict_inodes Christoph Hellwig <hch@infradead.org> - 2016-07-12 03:50 +0200
Re: [PATCH] vfs: check i_count under lock in evict_inodes Al Viro <viro@ZenIV.linux.org.uk> - 2016-07-12 07:30 +0200
| From | Chunwei Chen <david.chen@osnexus.com> |
|---|---|
| Date | 2016-07-12 02:30 +0200 |
| Subject | [PATCH] vfs: check i_count under lock in evict_inodes |
| Message-ID | <rTTKh-5SH-5@gated-at.bofh.it> |
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
[toc] | [next] | [standalone]
| From | Al Viro <viro@ZenIV.linux.org.uk> |
|---|---|
| Date | 2016-07-12 02:50 +0200 |
| Message-ID | <rTU3E-607-7@gated-at.bofh.it> |
| In reply to | #1440981 |
On Mon, Jul 11, 2016 at 05:15:04PM -0700, Chunwei Chen wrote: > 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. Details, please. Ideally - with a reproducer. Who is calling that iput() at that point of generic_shutdown_super() (has to be another thread) and just what will happen if the same iput() is delayed until *after* evict_inodes(), all the way into ->put_super(). At which point there's no promise whatsoever that the data structures used by ->evict_inode() hadn't been already freed...
[toc] | [prev] | [next] | [standalone]
| From | David Chen <david.chen@osnexus.com> |
|---|---|
| Date | 2016-07-12 03:40 +0200 |
| Message-ID | <rTUQ2-6xe-13@gated-at.bofh.it> |
| In reply to | #1440990 |
Hi Al, I'm not sure about the in-tree fs, but in zfsonlinux, it would offload iput to a thread, so this would happen there. And it would wait for the thread in put_super(), so that part is not a problem... Thanks 2016-07-11 17:46 GMT-07:00 Al Viro <viro@zeniv.linux.org.uk>: > On Mon, Jul 11, 2016 at 05:15:04PM -0700, Chunwei Chen wrote: >> 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. > > Details, please. Ideally - with a reproducer. Who is calling that iput() > at that point of generic_shutdown_super() (has to be another thread) and > just what will happen if the same iput() is delayed until *after* > evict_inodes(), all the way into ->put_super(). At which point there's > no promise whatsoever that the data structures used by ->evict_inode() > hadn't been already freed... >
[toc] | [prev] | [next] | [standalone]
| From | Christoph Hellwig <hch@infradead.org> |
|---|---|
| Date | 2016-07-12 03:50 +0200 |
| Message-ID | <rTUZH-6B4-5@gated-at.bofh.it> |
| In reply to | #1441010 |
On Mon, Jul 11, 2016 at 06:31:57PM -0700, David Chen wrote: > Hi Al, > > I'm not sure about the in-tree fs, but in zfsonlinux, it would offload > iput to a thread, so this would happen there. And it would wait for > the thread in put_super(), so that part is not a problem... And why exactly is your use of a broken and undistributable out of tree module our problem?
[toc] | [prev] | [next] | [standalone]
| From | Al Viro <viro@ZenIV.linux.org.uk> |
|---|---|
| Date | 2016-07-12 07:30 +0200 |
| Message-ID | <rTYqB-yl-1@gated-at.bofh.it> |
| In reply to | #1441010 |
On Mon, Jul 11, 2016 at 06:31:57PM -0700, David Chen wrote: > Hi Al, > > I'm not sure about the in-tree fs, but in zfsonlinux, it would offload > iput to a thread, so this would happen there. And it would wait for > the thread in put_super(), so that part is not a problem... *shrug* I hadn't looked (and won't look) at zfs glue, but I'd suggest trying something along the line of stopping that thread in the beginning of your ->kill_sb() (having told the sucker to stop offloading, of course) and only then calling generic_shutdown_super()...
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web