Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1440981

[PATCH] vfs: check i_count under lock in evict_inodes

From Chunwei Chen <david.chen@osnexus.com>
Newsgroups linux.kernel
Subject [PATCH] vfs: check i_count under lock in evict_inodes
Date 2016-07-12 02:30 +0200
Message-ID <rTTKh-5SH-5@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View 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

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[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

csiph-web