Safer nfsd_cross_mnt()
Subsystems (2)
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
@@ -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
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 todput()beforeexp_put().
OK. So a dentry of its own doesn't hold any reference on its filesystem?
--b.
Quoted 36 lines
Signed-off-by Al Viro <[email protected]>--- fs/nfsd/vfs.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)fs/nfsd/vfs.c +7
-2@@ -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
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 todput()beforeexp_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.
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 todput()beforeexp_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.