diff --git a/fs/nfsd/nfs3proc.c b/fs/nfsd/nfs3proc.c index 60cd01b6a37d..0711e93c9963 100644 --- a/fs/nfsd/nfs3proc.c +++ b/fs/nfsd/nfs3proc.c @@ -334,7 +334,7 @@ nfsd3_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, struct svc_fh *resfhp, struct nfsd3_createargs *argp) { struct iattr *iap = &argp->attrs; - struct dentry *parent, *child; + struct dentry *parent, *child, *mnt_child; struct nfsd_attrs attrs = { .na_iattr = iap, }; @@ -378,21 +378,29 @@ nfsd3_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, } exp = exp_get(fhp->fh_export); + /* + * Cross on a separate reference: child must remain the dentry + * start_creating() returned so that end_creating() unlocks the + * right directory. + */ + mnt_child = dget(child); if (argp->createmode == NFS3_CREATE_UNCHECKED) { /* * If name is already in dcache we need to check for mountpoints */ if (d_is_reg(child) && unlikely(nfsd_mountpoint(child, exp))) { - status = nfsd_cross_mnt(rqstp, &child, &exp); + status = nfsd_cross_mnt(rqstp, &mnt_child, &exp); if (status != nfs_ok) { + dput(mnt_child); exp_put(exp); goto out; } } } - status = fh_compose(resfhp, exp, child, fhp); + status = fh_compose(resfhp, exp, mnt_child, fhp); + dput(mnt_child); exp_put(exp); if (status != nfs_ok) goto out; diff --git a/fs/nfsd/nfsproc.c b/fs/nfsd/nfsproc.c index 1f74008bc06a..2cecae4e0cdf 100644 --- a/fs/nfsd/nfsproc.c +++ b/fs/nfsd/nfsproc.c @@ -682,7 +682,7 @@ nfsd_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, .na_iattr = attr, }; struct svc_export *exp; - struct dentry *dchild; + struct dentry *dchild, *dmnt; struct inode *inode; int type, mode; __be32 status; @@ -705,20 +705,26 @@ nfsd_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, status = nfserrno(PTR_ERR(dchild)); goto out_drop_write; } - /* - * If name exists we need to check for mountpoints - */ exp = exp_get(fhp->fh_export); + /* + * If name exists we need to check for mountpoints. Cross on a + * separate reference: end_creating() unlocks the parent of the + * dentry it is given, and only dchild has the locked directory + * as its parent. + */ + dmnt = dget(dchild); if (d_is_reg(dchild) && unlikely(nfsd_mountpoint(dchild, exp))) { - status = nfsd_cross_mnt(rqstp, &dchild, &exp); + status = nfsd_cross_mnt(rqstp, &dmnt, &exp); if (status != nfs_ok) { + dput(dmnt); exp_put(exp); goto out; } } - status = fh_compose(resfhp, exp, dchild, fhp); + status = fh_compose(resfhp, exp, dmnt, fhp); + dput(dmnt); exp_put(exp); if (!status && d_really_is_negative(dchild)) status = nfserr_noent;