lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <3116644.1xDzT5uuKM@silver>
Date: Thu, 23 May 2024 10:34:14 +0200
From: Christian Schoenebeck <linux_oss@...debyte.com>
To: Dominique Martinet <asmadeus@...ewreck.org>
Cc: Eric Van Hensbergen <ericvh@...nel.org>,
 Latchesar Ionkov <lucho@...kov.net>, Greg Kurz <groug@...d.org>,
 Jianyong Wu <jianyong.wu@....com>, stable@...r.kernel.org,
 Eric Van Hensbergen <ericvh@...il.com>, v9fs@...ts.linux.dev,
 linux-kernel@...r.kernel.org
Subject: Re: [PATCH] 9p: add missing locking around taking dentry fid list

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



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ