mirror of
https://github.com/torvalds/linux.git
synced 2026-11-20 13:03:48 +00:00
nfsd: unlock the locked parent after crossing a mount in CREATE
Since commitf58a48389c("nfsd: correctly handle CREATE of mounted-on files"), nfsd_proc_create() and nfsd3_create_file() call nfsd_cross_mnt() on the dentry returned by start_creating(). When the name refers to a file that has something mounted on it, nfsd_cross_mnt() replaces that dentry with the root of the mounted filesystem and drops its reference to the original one. The replacement is later passed to end_creating(), which unlocks the d_parent of the dentry it is given. That is the parent of the mount source, not the directory start_creating() locked, so the directory being created in is left locked and another directory's i_rwsem is released without being held. Do the crossing on a separate reference that is only used for fh_compose(), so that the dentry returned by start_creating() is the one passed to end_creating(). Only positive regular files are crossed, so the later checks on the child dentry give the same result. This was found by AI-assisted code review (Claude Code). The fix has been build-tested with W=1 only; no reproducer was run. Fixes:f58a48389c("nfsd: correctly handle CREATE of mounted-on files") Signed-off-by: orkunsari <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Chuck Lever <[email protected]>
This commit is contained in:
+11
-3
@@ -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;
|
||||
|
||||
+12
-6
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user