Skip to contentSkip to conversation

Safer nfsd_cross_mnt()

PATCH In review Al Viro 3 participants 4 messages Apr 21, 2009 – Apr 22, 2009

Subsystems (2)
lore
Share & tools
lore

Al Viro

author
#0 lore raw

PATCH 1/5 Safer nfsd_cross_mnt()

AFAICS, we have a subtle bug there: if we have crossed mountpoint *and* it got mount --move'd away, we'll be holding only one reference to fs containing dentry - exp->ex_path.mnt. IOW, we ought to dput() before exp_put().

---
 fs/nfsd/vfs.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
fs/nfsd/vfs.c +7 -2
index ab93fcf..46e6bd2 100644
@@ -116,10 +116,15 @@ nfsd_cross_mnt(struct svc_rqst *rqstp, struct dentry **dpp,
 	}
 	if ((exp->ex_flags & NFSEXP_CROSSMOUNT) || EX_NOHIDE(exp2)) {
 		/* successfully crossed mount point */
-		exp_put(exp);
-		*expp = exp2;
+		/*
+		 * This is subtle: dentry is *not* under mnt at this point.
+		 * The only reason we are safe is that original mnt is pinned
+		 * down by exp, so we should dput before putting exp.
+		 */
 		dput(dentry);
 		*dpp = mounts;
+		exp_put(exp);
+		*expp = exp2;
 	} else {
 		exp_put(exp2);
 		dput(mounts);
Signature · 1 line
1.5.6.5
#1 lore raw
Quoted 5 lines · Al Viro

AFAICS, we have a subtle bug there: if we have crossed mountpoint *and* it got mount --move'd away, we'll be holding only one reference to fs containing dentry - exp->ex_path.mnt. IOW, we ought to dput() before exp_put().

OK. So a dentry of its own doesn't hold any reference on its filesystem?

--b.

Quoted 36 lines
---
 fs/nfsd/vfs.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
fs/nfsd/vfs.c +7 -2
index ab93fcf..46e6bd2 100644
@@ -116,10 +116,15 @@ nfsd_cross_mnt(struct svc_rqst *rqstp, struct dentry **dpp,
 	}
 	if ((exp->ex_flags & NFSEXP_CROSSMOUNT) || EX_NOHIDE(exp2)) {
 		/* successfully crossed mount point */
-		exp_put(exp);
-		*expp = exp2;
+		/*
+		 * This is subtle: dentry is *not* under mnt at this point.
+		 * The only reason we are safe is that original mnt is pinned
+		 * down by exp, so we should dput before putting exp.
+		 */
 		dput(dentry);
 		*dpp = mounts;
+		exp_put(exp);
+		*expp = exp2;
 	} else {
 		exp_put(exp2);
 		dput(mounts);
Signature · 7 lines
1.5.6.5


--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
Quoted 9 lines · J. Bruce Fields
Quoted 5 lines · Al Viro

AFAICS, we have a subtle bug there: if we have crossed mountpoint *and* it got mount --move'd away, we'll be holding only one reference to fs containing dentry - exp->ex_path.mnt. IOW, we ought to dput() before exp_put().

OK. So a dentry of its own doesn't hold any reference on its filesystem?

Nope. That's why you want vfsmount or superblock reference. And export *does* contain vfsmount reference, so everything's fine, provided that you drop them in the right order.

#3 lore raw
Quoted 8 lines · Al Viro
Quoted 7 lines · J. Bruce Fields
Quoted 5 lines · Al Viro

AFAICS, we have a subtle bug there: if we have crossed mountpoint *and* it got mount --move'd away, we'll be holding only one reference to fs containing dentry - exp->ex_path.mnt. IOW, we ought to dput() before exp_put().

Quoted 6 lines
Quoted 2 lines

OK. So a dentry of its own doesn't hold any reference on its filesystem?

Nope. That's why you want vfsmount or superblock reference. And export *does* contain vfsmount reference, so everything's fine, provided that you drop them in the right order.

Got it, thanks.

--b.