public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Christian Schoenebeck <linux_oss@crudebyte.com>
To: Dominique Martinet <asmadeus@codewreck.org>
Cc: Eric Van Hensbergen <ericvh@kernel.org>,
	Latchesar Ionkov <lucho@ionkov.net>, Greg Kurz <groug@kaod.org>,
	Jianyong Wu <jianyong.wu@arm.com>,
	stable@vger.kernel.org, Eric Van Hensbergen <ericvh@gmail.com>,
	v9fs@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] 9p: add missing locking around taking dentry fid list
Date: Thu, 23 May 2024 10:34:14 +0200	[thread overview]
Message-ID: <3116644.1xDzT5uuKM@silver> (raw)
In-Reply-To: <Zk4qcmtot6WEC1Xx@codewreck.org>

On Wednesday, May 22, 2024 7:25:06 PM CEST Dominique Martinet wrote:
> Christian Schoenebeck wrote on Wed, May 22, 2024 at 04:35:19PM +0200:
[...]
> > > diff --git a/fs/9p/vfs_dentry.c b/fs/9p/vfs_dentry.c
> > > index f16f73581634..01338d4c2d9e 100644
> > > --- a/fs/9p/vfs_dentry.c
> > > +++ b/fs/9p/vfs_dentry.c
> > > @@ -48,12 +48,17 @@ static int v9fs_cached_dentry_delete(const struct dentry *dentry)
> > >  static void v9fs_dentry_release(struct dentry *dentry)
> > >  {
> > >  	struct hlist_node *p, *n;
> > > +	struct hlist_head head;
> > >  
> > >  	p9_debug(P9_DEBUG_VFS, " dentry: %pd (%p)\n",
> > >  		 dentry, dentry);
> > > -	hlist_for_each_safe(p, n, (struct hlist_head *)&dentry->d_fsdata)
> > > +
> > > +	spin_lock(&dentry->d_lock);
> > > +	hlist_move_list((struct hlist_head *)&dentry->d_fsdata, &head);
> > > +	spin_unlock(&dentry->d_lock);
> > > +
> > > +	hlist_for_each_safe(p, n, &head)
> > >  		p9_fid_put(hlist_entry(p, struct p9_fid, dlist));
> > > -	dentry->d_fsdata = NULL;
> > >  }
> > 
> > I'm not sure if that works out. So you are moving the list from dentry to a
> > local variable. But if you look at v9fs_fid_find() [fs/9p/fid.c#123] it reads
> > dentry->d_fsdata (twice) and holds it as local variable before taking a
> > lock. So the lock in v9fs_fid_find() should happen earlier, no?
> 
> The comment still works -- if detry->d_fsdata is NULL then
> hlist_for_each_entry will stop short and not iterate over anything (it
> won't bug out), so that part is fine in my opinion.

I meant the opposite: dentry->d_fsdata not being NULL. In this case
v9fs_fid_find() takes a local copy of the list head pointer as `h` without
taking a lock before.

Then v9fs_fid_find() takes the lock to run hlist_for_each_entry(), but at this
point `h` could already point at garbage.

/Christian



  reply	other threads:[~2024-05-23  8:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-21 12:29 [PATCH] 9p: add missing locking around taking dentry fid list Dominique Martinet
2024-05-22 14:35 ` Christian Schoenebeck
2024-05-22 17:25   ` Dominique Martinet
2024-05-23  8:34     ` Christian Schoenebeck [this message]
2024-05-23  9:27       ` Dominique Martinet
2024-05-23 10:05         ` Christian Schoenebeck
2024-05-23 11:38           ` Dominique Martinet

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=3116644.1xDzT5uuKM@silver \
    --to=linux_oss@crudebyte.com \
    --cc=asmadeus@codewreck.org \
    --cc=ericvh@gmail.com \
    --cc=ericvh@kernel.org \
    --cc=groug@kaod.org \
    --cc=jianyong.wu@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lucho@ionkov.net \
    --cc=stable@vger.kernel.org \
    --cc=v9fs@lists.linux.dev \
    /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