nfsclient: add checks for a server returning the current directory

Commit 3fe2c68ba2 dealt with a panic in cache_enter_time() where
the vnode referred to the directory argument.
It would also be possible to get these panics if a broken
NFS server were to return the directory as an new object being
created within the directory or in a Lookup reply.

This patch adds checks to avoid the panics and logs
messages to indicate that the server is broken for the
file object creation cases.

Reviewd by:	kib
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D28987
This commit is contained in:
Rick Macklem 2021-02-28 14:15:32 -08:00
parent b12a960e42
commit 3e04ab36ba

View File

@ -1423,7 +1423,7 @@ nfs_lookup(struct vop_lookup_args *ap)
}
if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))
cnp->cn_flags |= SAVENAME;
if ((cnp->cn_flags & MAKEENTRY) &&
if ((cnp->cn_flags & MAKEENTRY) && dvp != newvp &&
(cnp->cn_nameiop != DELETE || !(flags & ISLASTCN)) &&
attrflag != 0 && (newvp->v_type != VDIR || dattrflag != 0))
cache_enter_time(dvp, newvp, cnp, &nfsva.na_ctime,
@ -1752,9 +1752,14 @@ nfs_create(struct vop_create_args *ap)
}
}
if (!error) {
if ((cnp->cn_flags & MAKEENTRY) && attrflag)
cache_enter_time(dvp, newvp, cnp, &nfsva.na_ctime,
NULL);
if ((cnp->cn_flags & MAKEENTRY) && attrflag) {
if (dvp != newvp)
cache_enter_time(dvp, newvp, cnp,
&nfsva.na_ctime, NULL);
else
printf("nfs_create: bogus NFS server returned "
"the directory as the new file object\n");
}
*ap->a_vpp = newvp;
} else if (NFS_ISV4(dvp)) {
error = nfscl_maperr(cnp->cn_thread, error, vap->va_uid,
@ -2126,7 +2131,11 @@ nfs_link(struct vop_link_args *ap)
*/
if (VFSTONFS(vp->v_mount)->nm_negnametimeo != 0 &&
(cnp->cn_flags & MAKEENTRY) && attrflag != 0 && error == 0) {
cache_enter_time(tdvp, vp, cnp, &nfsva.na_ctime, NULL);
if (tdvp != vp)
cache_enter_time(tdvp, vp, cnp, &nfsva.na_ctime, NULL);
else
printf("nfs_link: bogus NFS server returned "
"the directory as the new link\n");
}
if (error && NFS_ISV4(vp))
error = nfscl_maperr(cnp->cn_thread, error, (uid_t)0,
@ -2205,7 +2214,12 @@ nfs_symlink(struct vop_symlink_args *ap)
*/
if (VFSTONFS(dvp->v_mount)->nm_negnametimeo != 0 &&
(cnp->cn_flags & MAKEENTRY) && attrflag != 0 && error == 0) {
cache_enter_time(dvp, newvp, cnp, &nfsva.na_ctime, NULL);
if (dvp != newvp)
cache_enter_time(dvp, newvp, cnp, &nfsva.na_ctime,
NULL);
else
printf("nfs_symlink: bogus NFS server returned "
"the directory as the new file object\n");
}
return (error);
}
@ -2278,9 +2292,15 @@ nfs_mkdir(struct vop_mkdir_args *ap)
*/
if (VFSTONFS(dvp->v_mount)->nm_negnametimeo != 0 &&
(cnp->cn_flags & MAKEENTRY) &&
attrflag != 0 && dattrflag != 0)
cache_enter_time(dvp, newvp, cnp, &nfsva.na_ctime,
&dnfsva.na_ctime);
attrflag != 0 && dattrflag != 0) {
if (dvp != newvp)
cache_enter_time(dvp, newvp, cnp,
&nfsva.na_ctime, &dnfsva.na_ctime);
else
printf("nfs_mkdir: bogus NFS server returned "
"the directory that the directory was "
"created in as the new file object\n");
}
*ap->a_vpp = newvp;
}
return (error);