git: 1e74922c68d2 - stable/13 - msdosfs: on integrity error, fire a task to remount filesystem to ro

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

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

commit 1e74922c68d22840581d83d45a9c88cc0c8d4676
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2021-12-25 19:45:47 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-01-14 18:11:02 +0000

    msdosfs: on integrity error, fire a task to remount filesystem to ro
    
    (cherry picked from commit 41e85eeab90dec540c7aa3973ba601bae1f16c10)
---
 sys/fs/msdosfs/msdosfs_denode.c | 1 +
 sys/fs/msdosfs/msdosfs_fat.c    | 1 +
 sys/fs/msdosfs/msdosfs_lookup.c | 6 +++++-
 3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/sys/fs/msdosfs/msdosfs_denode.c b/sys/fs/msdosfs/msdosfs_denode.c
index bdc7436079ea..6fba51708462 100644
--- a/sys/fs/msdosfs/msdosfs_denode.c
+++ b/sys/fs/msdosfs/msdosfs_denode.c
@@ -158,6 +158,7 @@ deget(struct msdosfsmount *pmp, u_long dirclust, u_long diroffset,
 badoff:
 		vgone(nvp);
 		vput(nvp);
+		msdosfs_integrity_error(pmp);
 		return (EBADF);
 	}
 	ldep = malloc(sizeof(struct denode), M_MSDOSFSNODE, M_WAITOK | M_ZERO);
diff --git a/sys/fs/msdosfs/msdosfs_fat.c b/sys/fs/msdosfs/msdosfs_fat.c
index fc1db705989b..e6d9b671e7d7 100644
--- a/sys/fs/msdosfs/msdosfs_fat.c
+++ b/sys/fs/msdosfs/msdosfs_fat.c
@@ -412,6 +412,7 @@ usemap_free(struct msdosfsmount *pmp, u_long cn)
 		printf("%s: Freeing unused sector %ld %ld %x\n",
 		    pmp->pm_mountp->mnt_stat.f_mntonname, cn, cn % N_INUSEBITS,
 		    (unsigned)pmp->pm_inusemap[cn / N_INUSEBITS]);
+		msdosfs_integrity_error(pmp);
 		return (EINTEGRITY);
 	}
 	pmp->pm_freeclustercount++;
diff --git a/sys/fs/msdosfs/msdosfs_lookup.c b/sys/fs/msdosfs/msdosfs_lookup.c
index e30866b5bedd..291f923d79fe 100644
--- a/sys/fs/msdosfs/msdosfs_lookup.c
+++ b/sys/fs/msdosfs/msdosfs_lookup.c
@@ -77,6 +77,7 @@ msdosfs_lookup_checker(struct msdosfsmount *pmp, struct vnode *dvp,
 	 */
 	if (vp == dvp) {
 		vput(vp);
+		msdosfs_integrity_error(pmp);
 		*vpp = NULL;
 		return (EBADF);
 	}
@@ -595,10 +596,13 @@ foundroot:
 			vput(*vpp);
 			goto restart;
 		}
-		return (msdosfs_lookup_checker(pmp, vdp, VTODE(*vpp), vpp));
+		error = msdosfs_lookup_checker(pmp, vdp, VTODE(*vpp), vpp);
+		if (error != 0)
+			return (error);
 	} else if (dp->de_StartCluster == scn && isadir) {
 		if (cnp->cn_namelen != 1 || cnp->cn_nameptr[0] != '.') {
 			/* fs is corrupted, non-dot lookup returned dvp */
+			msdosfs_integrity_error(pmp);
 			return (EBADF);
 		}
 		VREF(vdp);	/* we want ourself, ie "." */