git: a1735a7698a6 - stable/13 - nfsd: Add a sanity check to SecinfoNoname for file type

From: Rick Macklem <rmacklem_at_FreeBSD.org>
Date: Sun, 15 May 2022 19:18:12 UTC
The branch stable/13 has been updated by rmacklem:

URL: https://cgit.FreeBSD.org/src/commit/?id=a1735a7698a60eff1e0682261033e37fc530f85d

commit a1735a7698a60eff1e0682261033e37fc530f85d
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2022-05-01 20:41:31 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2022-05-15 19:17:11 +0000

    nfsd: Add a sanity check to SecinfoNoname for file type
    
    Robert Morris reported that, for the case of SecinfoNoname
    with the Parent option, providing a non-directory could
    cause a crash.
    
    This patch adds a sanity check for v_type == VDIR for
    this case, to avoid the crash.
    
    PR:     260300
    
    (cherry picked from commit 47d75c29f5510ad844f0bc7fbc07d481ebb7fd9e)
---
 sys/fs/nfsserver/nfs_nfsdserv.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/sys/fs/nfsserver/nfs_nfsdserv.c b/sys/fs/nfsserver/nfs_nfsdserv.c
index d72716ce7fd8..2bb113b6441d 100644
--- a/sys/fs/nfsserver/nfs_nfsdserv.c
+++ b/sys/fs/nfsserver/nfs_nfsdserv.c
@@ -3822,6 +3822,11 @@ nfsrvd_secinfononame(struct nfsrv_descript *nd, int isdgram,
 	fhstyle = fxdr_unsigned(int, *tl);
 	switch (fhstyle) {
 	case NFSSECINFONONAME_PARENT:
+		if (dp->v_type != VDIR) {
+			vput(dp);
+			nd->nd_repstat = NFSERR_NOTDIR;
+			goto nfsmout;
+		}
 		NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, LOOKUP,
 		    LOCKLEAF | SAVESTART);
 		nfsvno_setpathbuf(&named, &bufp, &hashp);