linux-unionfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@zeniv.linux.org.uk>
To: Joseph Qi <joseph.qi@linux.alibaba.com>
Cc: Liangyan <liangyan.peng@linux.alibaba.com>,
	Miklos Szeredi <miklos@szeredi.hu>,
	linux-unionfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] ovl: fix dentry leak in ovl_get_redirect
Date: Mon, 21 Dec 2020 12:11:48 +0000	[thread overview]
Message-ID: <20201221121148.GP3579531@ZenIV.linux.org.uk> (raw)
In-Reply-To: <52a76e73-d46b-d0fd-a75a-76b4a86149b3@linux.alibaba.com>

On Mon, Dec 21, 2020 at 07:14:44PM +0800, Joseph Qi wrote:
> Hi Viro,
> 
> On 12/21/20 2:26 PM, Al Viro wrote:
> > On Sun, Dec 20, 2020 at 08:09:27PM +0800, Liangyan wrote:
> > 
> >> +++ b/fs/overlayfs/dir.c
> >> @@ -973,6 +973,7 @@ static char *ovl_get_redirect(struct dentry *dentry, bool abs_redirect)
> >>  	for (d = dget(dentry); !IS_ROOT(d);) {
> >>  		const char *name;
> >>  		int thislen;
> >> +		struct dentry *parent = NULL;
> >>  
> >>  		spin_lock(&d->d_lock);
> >>  		name = ovl_dentry_get_redirect(d);
> >> @@ -992,7 +993,22 @@ static char *ovl_get_redirect(struct dentry *dentry, bool abs_redirect)
> >>  
> >>  		buflen -= thislen;
> >>  		memcpy(&buf[buflen], name, thislen);
> >> -		tmp = dget_dlock(d->d_parent);
> >> +		parent = d->d_parent;
> >> +		if (unlikely(!spin_trylock(&parent->d_lock))) {
> >> +			rcu_read_lock();
> >> +			spin_unlock(&d->d_lock);
> >> +again:
> >> +			parent = READ_ONCE(d->d_parent);
> >> +			spin_lock(&parent->d_lock);
> >> +			if (unlikely(parent != d->d_parent)) {
> >> +				spin_unlock(&parent->d_lock);
> >> +				goto again;
> >> +			}
> >> +			rcu_read_unlock();
> >> +			spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
> >> +		}
> >> +		tmp = dget_dlock(parent);
> >> +		spin_unlock(&parent->d_lock);
> >>  		spin_unlock(&d->d_lock);
> > 
> > Yecchhhh....  What's wrong with just doing
> > 		spin_unlock(&d->d_lock);
> > 		parent = dget_parent(d);
> > 		dput(d);
> > 		d = parent;
> > instead of that?
> > 
> 
> Now race happens on non-RCU path in lookup_fast(), I'm afraid d_seq can
> not close the race window.

Explain, please.  What exactly are you observing?

  reply	other threads:[~2020-12-21 12:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-20 12:09 [PATCH v2] ovl: fix dentry leak in ovl_get_redirect Liangyan
2020-12-21  6:14 ` Liangyan
2020-12-21  6:26 ` Al Viro
2020-12-21 11:14   ` Joseph Qi
2020-12-21 12:11     ` Al Viro [this message]
2020-12-21 16:51       ` Liangyan
2020-12-21 17:35         ` Al Viro
2020-12-21 18:15           ` Liangyan

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=20201221121148.GP3579531@ZenIV.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=joseph.qi@linux.alibaba.com \
    --cc=liangyan.peng@linux.alibaba.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    /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).