stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Al Viro <viro@zeniv.linux.org.uk>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH 3.15 02/12] lock_parent: dont step on stale ->d_parent of all-but-freed one
Date: Thu, 12 Jun 2014 16:21:04 -0700	[thread overview]
Message-ID: <20140612232045.011362521@linuxfoundation.org> (raw)
In-Reply-To: <20140612232044.886466924@linuxfoundation.org>

3.15-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Al Viro <viro@zeniv.linux.org.uk>

commit c2338f2dc7c1e9f6202f370c64ffd7f44f3d4b51 upstream.

Dentry that had been through (or into) __dentry_kill() might be seen
by shrink_dentry_list(); that's normal, it'll be taken off the shrink
list and freed if __dentry_kill() has already finished.  The problem
is, its ->d_parent might be pointing to already freed dentry, so
lock_parent() needs to be careful.

We need to check that dentry hasn't already gone into __dentry_kill()
*and* grab rcu_read_lock() before dropping ->d_lock - the latter makes
sure that whatever we see in ->d_parent after dropping ->d_lock it
won't be freed until we drop rcu_read_lock().

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 fs/dcache.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -532,10 +532,12 @@ static inline struct dentry *lock_parent
 	struct dentry *parent = dentry->d_parent;
 	if (IS_ROOT(dentry))
 		return NULL;
+	if (unlikely((int)dentry->d_lockref.count < 0))
+		return NULL;
 	if (likely(spin_trylock(&parent->d_lock)))
 		return parent;
-	spin_unlock(&dentry->d_lock);
 	rcu_read_lock();
+	spin_unlock(&dentry->d_lock);
 again:
 	parent = ACCESS_ONCE(dentry->d_parent);
 	spin_lock(&parent->d_lock);



  parent reply	other threads:[~2014-06-12 23:21 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-12 23:21 [PATCH 3.15 00/12] 3.15.1-stable review Greg Kroah-Hartman
2014-06-12 23:21 ` [PATCH 3.15 01/12] fs,userns: Change inode_capable to capable_wrt_inode_uidgid Greg Kroah-Hartman
2014-06-12 23:21 ` Greg Kroah-Hartman [this message]
2014-06-12 23:21 ` [PATCH 3.15 03/12] auditsc: audit_krule mask accesses need bounds checking Greg Kroah-Hartman
2014-06-12 23:21 ` [PATCH 3.15 04/12] PCI/MSI: Fix memory leak in free_msi_irqs() Greg Kroah-Hartman
2014-06-12 23:21 ` [PATCH 3.15 05/12] mei: me: fix hw ready reset flow Greg Kroah-Hartman
2014-06-12 23:21 ` [PATCH 3.15 06/12] mei: me: drop harmful wait optimization Greg Kroah-Hartman
2014-06-12 23:21 ` [PATCH 3.15 07/12] mei: me: read H_CSR after asserting reset Greg Kroah-Hartman
2014-06-12 23:21 ` [PATCH 3.15 08/12] [media] rtl28xxu: add 1b80:d395 Peak DVB-T USB Greg Kroah-Hartman
2014-06-12 23:21 ` [PATCH 3.15 09/12] [media] rtl28xxu: add [1b80:d39d] Sveon STV20 Greg Kroah-Hartman
2014-06-12 23:21 ` [PATCH 3.15 10/12] [media] rtl28xxu: add [1b80:d3af] Sveon STV27 Greg Kroah-Hartman
2014-06-13 15:16 ` [PATCH 3.15 00/12] 3.15.1-stable review Guenter Roeck
2014-06-13 16:07   ` Greg Kroah-Hartman
2014-06-13 16:18     ` Guenter Roeck
2014-06-14 10:31   ` Satoru Takeuchi
2014-06-14 14:41     ` Greg Kroah-Hartman

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=20140612232045.011362521@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.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).