From nobody Sat Jan 15 00:51:37 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 8930F195120C; Sat, 15 Jan 2022 00:51:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JbKP627y9z4k3H; Sat, 15 Jan 2022 00:51:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642207898; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6Gir8DN0KBqUbrRJ5ryAUQJTaVAZd/Cnxx7zdpUvW40=; b=HGsCwFhJovVbxXhNYS1eXQEb5ES+Q6qGtlGTdOuq3GuaXm42/Bq/d6X+UTlewMhcazJmIi DzOj5gGIXuLVD+wwbtk7u1z6q70oHz/ExQQ4FHVWWy2QFpYaCHOPx+tYmVrDp8OcuSchDS LRt1+o7tJR36YQu04Tq/S0QY8WOd6hmadZ1SIuOcOPTbgvUdxKdIP3taqq0rOARQnlo/i3 F8pi1nut863KtAN5bgss3XAgscev8lQ1qTkRVRO+VviU4L1MzkutaeZ2L6FQMi9U3OqGE2 hdlNAi5H+zugMYzWI1XhuHLvm5RkV+EWFce2b7tXUyfnLR70hfAh+VpkAJYbPQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id BF4A11DF89; Sat, 15 Jan 2022 00:51:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20F0pbhQ031127; Sat, 15 Jan 2022 00:51:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20F0pbbY031126; Sat, 15 Jan 2022 00:51:37 GMT (envelope-from git) Date: Sat, 15 Jan 2022 00:51:37 GMT Message-Id: <202201150051.20F0pbbY031126@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 472f57606443 - stable/13 - msdosfs: take inusemap inconsistency as an error, not invariants violation List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 472f5760644320e59abc2b5362e84635dc650daf Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642207898; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6Gir8DN0KBqUbrRJ5ryAUQJTaVAZd/Cnxx7zdpUvW40=; b=VAueT7EnsLZp2sBSAwasrhGN8T3BSyeMp0GFapLPuPyYzqk6IABjvhozpmCkwCr4VicoA4 FqmYiUnAT36ogZLdoYd5B3pK9Dd31m3nuL4rQFN1RAZf+ru29kJXzaB7KkBwN1Cl5dj7t3 WsDyy3mlFqn/gQAz3JW/Yik27GQTjEdwALhSibpYz2pI9snnlyO5+ZFOJ6LEdexlTI76VP p81Vt0q2iVT2MlR6QA+Qdp5xXJn/tSgNQsoyrzf8KqCo2pcpWY1Q4yhDXqSHm26vtTzbe4 FwFxCbKGTpkfQxVMoONaMXQ0rRr17UolH9YtfsT2bAyKLOx6veHjISU/basgBA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642207898; a=rsa-sha256; cv=none; b=LLk4AepAko2/ruOzK4KvxPgQ8KxAGQTe6LBIhaR80p15ibZHuHG4PmFScNkkLB6SAoMv/U R8mk7Nz5ixGsNZnBFMWnS9aMxXUsrpKb+uYOo3UzrVAcYsy4+rWsO76WFD9ipsL3BVWKO8 QPRWczRwJh+7vuZIiS9QZB5zVN+PUBPSL3msEwofKrkO5KgInvGnE41HJTko3JV5zl/LX9 h3S42LExENUOQFzTtYCd3Mij55gWIilW9ImFHxqFHLpB1NUnZKoOY8wlakBTKC4n9pO2gQ fzQK3lfgHdbuYmOPsQ8CBzrFRw/1XStBhyzPGgUHU6tuAI1TrqgVSqzi55wl/A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=472f5760644320e59abc2b5362e84635dc650daf commit 472f5760644320e59abc2b5362e84635dc650daf Author: Konstantin Belousov AuthorDate: 2021-12-25 18:39:15 +0000 Commit: Konstantin Belousov CommitDate: 2022-01-14 18:11:01 +0000 msdosfs: take inusemap inconsistency as an error, not invariants violation (cherry picked from commit 2c9a1c22c323b069d1f4883170349545c94b7b8d) --- sys/fs/msdosfs/msdosfs_fat.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/sys/fs/msdosfs/msdosfs_fat.c b/sys/fs/msdosfs/msdosfs_fat.c index 6d5bfc7fa46e..202feeef0102 100644 --- a/sys/fs/msdosfs/msdosfs_fat.c +++ b/sys/fs/msdosfs/msdosfs_fat.c @@ -80,8 +80,7 @@ static void updatefats(struct msdosfsmount *pmp, struct buf *bp, u_long fatbn); static __inline void usemap_alloc(struct msdosfsmount *pmp, u_long cn); -static __inline void - usemap_free(struct msdosfsmount *pmp, u_long cn); +static int usemap_free(struct msdosfsmount *pmp, u_long cn); static int clusteralloc1(struct msdosfsmount *pmp, u_long start, u_long count, u_long fillwith, u_long *retcluster, u_long *got); @@ -398,7 +397,7 @@ usemap_alloc(struct msdosfsmount *pmp, u_long cn) pmp->pm_flags |= MSDOSFS_FSIMOD; } -static __inline void +static int usemap_free(struct msdosfsmount *pmp, u_long cn) { @@ -408,13 +407,17 @@ usemap_free(struct msdosfsmount *pmp, u_long cn) pmp->pm_maxcluster)); KASSERT((pmp->pm_flags & MSDOSFSMNT_RONLY) == 0, ("usemap_free on ro msdosfs mount")); + if ((pmp->pm_inusemap[cn / N_INUSEBITS] & + (1U << (cn % N_INUSEBITS))) == 0) { + 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]); + return (EINTEGRITY); + } pmp->pm_freeclustercount++; pmp->pm_flags |= MSDOSFS_FSIMOD; - KASSERT((pmp->pm_inusemap[cn / N_INUSEBITS] & - (1U << (cn % N_INUSEBITS))) != 0, - ("Freeing unused sector %ld %ld %x", cn, cn % N_INUSEBITS, - (unsigned)pmp->pm_inusemap[cn / N_INUSEBITS])); pmp->pm_inusemap[cn / N_INUSEBITS] &= ~(1U << (cn % N_INUSEBITS)); + return (0); } int @@ -432,11 +435,11 @@ clusterfree(struct msdosfsmount *pmp, u_long cluster, u_long *oldcnp) * bit in the "in use" cluster bit map. */ MSDOSFS_LOCK_MP(pmp); - usemap_free(pmp, cluster); + error = usemap_free(pmp, cluster); MSDOSFS_UNLOCK_MP(pmp); - if (oldcnp) + if (error == 0 && oldcnp != NULL) *oldcnp = oldcn; - return (0); + return (error); } /* @@ -712,7 +715,7 @@ chainalloc(struct msdosfsmount *pmp, u_long start, u_long count, error = fatchain(pmp, start, count, fillwith); if (error != 0) { for (cl = start, n = count; n-- > 0;) - usemap_free(pmp, cl++); + (void)usemap_free(pmp, cl++); return (error); } #ifdef MSDOSFS_DEBUG @@ -846,7 +849,12 @@ freeclusterchain(struct msdosfsmount *pmp, u_long cluster) } lbn = bn; } - usemap_free(pmp, cluster); + error = usemap_free(pmp, cluster); + if (error != 0) { + updatefats(pmp, bp, lbn); + MSDOSFS_UNLOCK_MP(pmp); + return (error); + } switch (pmp->pm_fatmask) { case FAT12_MASK: readcn = getushort(bp->b_data + bo); @@ -940,8 +948,13 @@ fillinusemap(struct msdosfsmount *pmp) #endif brelse(bp); return (EINVAL); - } else if (readcn == CLUST_FREE) - usemap_free(pmp, cn); + } else if (readcn == CLUST_FREE) { + error = usemap_free(pmp, cn); + if (error != 0) { + brelse(bp); + return (error); + } + } } if (bp != NULL) brelse(bp);