Re: [PATCH] configfs: fix a race in configfs_lookup()

From: Al Viro
Date: Wed Aug 25 2021 - 01:19:13 EST


On Mon, Aug 23, 2021 at 07:08:47PM +0200, Christoph Hellwig wrote:

> We can't hold a spinlock over inode allocation. So it would have to be
> something like this:

Check for -ENAMETOOLONG first; easier for analysis that way.

> + dentry->d_fsdata = configfs_get(sd);
> + sd->s_dentry = dentry;
> + spin_unlock(&configfs_dirent_lock);
>
> - found = 1;
> - err = configfs_attach_attr(sd, dentry);
> - break;
> + inode = configfs_create(dentry, mode);
> + if (IS_ERR(inode)) {
> + configfs_put(sd);
> + return ERR_CAST(inode);

Er... Won't that leave dentry with dangling ->d_fsdata?