git: 1bcbcd68f590 - stable/13 - msdosfs: handle a case when non-dot lookup returned dvp

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Sat, 15 Jan 2022 00:51:38 UTC
The branch stable/13 has been updated by kib:

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

commit 1bcbcd68f59099f8813f9767e0781a150b1b7918
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2021-12-28 13:41:30 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-01-14 18:11:02 +0000

    msdosfs: handle a case when non-dot lookup returned dvp
    
    (cherry picked from commit 1319c433f4e5d67f8ea6fd2369c604069f733c94)
---
 sys/fs/msdosfs/msdosfs_lookup.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/sys/fs/msdosfs/msdosfs_lookup.c b/sys/fs/msdosfs/msdosfs_lookup.c
index 9940800a72c2..2478cab84a0a 100644
--- a/sys/fs/msdosfs/msdosfs_lookup.c
+++ b/sys/fs/msdosfs/msdosfs_lookup.c
@@ -573,6 +573,10 @@ foundroot:
 			goto restart;
 		}
 	} else if (dp->de_StartCluster == scn && isadir) {
+		if (cnp->cn_namelen != 1 || cnp->cn_nameptr[0] != '.') {
+			/* fs is corrupted, non-dot lookup returned dvp */
+			return (EBADF);
+		}
 		VREF(vdp);	/* we want ourself, ie "." */
 		*vpp = vdp;
 	} else {