diff --git a/fs/autofs4/root.c b/fs/autofs4/root.c index 47adf270106a656ea98b54cf6875a66cfae70ab5..b4631046867e30a92e2bf5b866d9bc8a05e0c375 100644 --- a/fs/autofs4/root.c +++ b/fs/autofs4/root.c @@ -655,14 +655,29 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s /* * If this dentry is unhashed, then we shouldn't honour this - * lookup even if the dentry is positive. Returning ENOENT here - * doesn't do the right thing for all system calls, but it should - * be OK for the operations we permit from an autofs. + * lookup. Returning ENOENT here doesn't do the right thing + * for all system calls, but it should be OK for the operations + * we permit from an autofs. */ if (dentry->d_inode && d_unhashed(dentry)) { + /* + * A user space application can (and has done in the past) + * remove and re-create this directory during the callback. + * This can leave us with an unhashed dentry, but a + * successful mount! So we need to perform another + * cached lookup in case the dentry now exists. + */ + struct dentry *parent = dentry->d_parent; + struct dentry *new = d_lookup(parent, &dentry->d_name); + if (new != NULL) + dentry = new; + else + dentry = ERR_PTR(-ENOENT); + if (unhashed) dput(unhashed); - return ERR_PTR(-ENOENT); + + return dentry; } if (unhashed)