From nobody Tue Oct 03 22:13:57 2023 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 4S0XCp0sG2z4w4Ks; Tue, 3 Oct 2023 22:13:58 +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 4S0XCp054jz4rF5; Tue, 3 Oct 2023 22:13:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696371238; 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=DjbxGuMErZSJSiCmQ+JaBhzTJDSzA+RwCwqnWW8HrW8=; b=A/i0e4CLBwfFUZOIpvvOI+OZVXAPV4BREoci0kBoYbYBwgWc8nXDkpeWPlg+RxInY+WsPp YUzdII1SUyivM4AKWcHeo2iuEaRk055LYVy0ZiEilV2di74cQDvFRAhrE9jfINHV4jUoRp rY8xOrRisPNFJr71jKXN0+RRk+z6TfccJGvBcBgJYbjkvf8pNmRDzIrbmzPbasjiDEUCNo 3lV2aK58fjHA9mAYkBVg5FyTO+o3uairasZ0CUsna9SVVqVFMANigEU4d68CRsLOXIk3/b /FRV82XinDtJIjWg06gm9P8QCL1HLFXwNaIUkFF1xa2tEtwpzSjYx/3g/3Q8zQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1696371238; a=rsa-sha256; cv=none; b=I1XF2AyD0NxyaFCkk51ZUoyKQ3LJJYCLPPIQHbjre5muHkt7Debs8xovsIczWGqSSqaK7W zkOaHrmA4TSeZmVLOcJlVu0buOHPVoGQV9hj3jq5jVeZO3D7KJU4/xUcPeoT3Z8z6jhLIX YDIqh+xvMzBJ3VPZCCBNxxZ6ubK6ptT1G3rlFOjID5vw4dr8MRkVLi7PDeHElCHqex4DSv VLmUHxrbqYrdkI7UJnbLgD9exvaeGrq6V/+YvjVjegs2kZNE43iC7vDKwxxDJaFgDVpulB 9/zhu3gwNYdVaOSVFORS6cgt+IuCFh6AkZPUBW94s1Og9wrs8QFxTgKTOStg0w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696371238; 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=DjbxGuMErZSJSiCmQ+JaBhzTJDSzA+RwCwqnWW8HrW8=; b=gJfRcCi4uWRVtjylSlA7D6O0E+64KQRdYIKxs+uwLKZ6oGRnYHmmTXMRzW/TxTKzs9IhEI aR9U47YtO2PpS8oWM+yXGhxvDJTPgAjoslWrak9VP87Z8Rd239Klbl2Cn+P/tI7v7YNUVr o5Q9+KqKf+3D2afS4wjdPw0h5HB6i5s00uiqOtMxWIc9Bzp9l8Qbr+5gP9vAM6eupeBtYb Ty5Ddc2rgovrYCKDLU2R2+wyG/Hv7ilPn1A+sPztH5al8oTuo12fxszpELPqxzD+Ep6MU5 ce37+9OR2+lwJv/WD6LKFWouzecKeCuTxD8i8pnkxdvIys/DZkBrD78RV9GV4Q== 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 4S0XCn6Frzz1BXJ; Tue, 3 Oct 2023 22:13:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 393MDvDe070981; Tue, 3 Oct 2023 22:13:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 393MDvgD070978; Tue, 3 Oct 2023 22:13:57 GMT (envelope-from git) Date: Tue, 3 Oct 2023 22:13:57 GMT Message-Id: <202310032213.393MDvgD070978@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Gordon Tetlow Subject: git: 7d08a7e6908b - releng/13.2 - msdosfs: zero partially valid extended cluster 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: gordon X-Git-Repository: src X-Git-Refname: refs/heads/releng/13.2 X-Git-Reftype: branch X-Git-Commit: 7d08a7e6908b3ffb72061b7517ed29814d62355b Auto-Submitted: auto-generated The branch releng/13.2 has been updated by gordon: URL: https://cgit.FreeBSD.org/src/commit/?id=7d08a7e6908b3ffb72061b7517ed29814d62355b commit 7d08a7e6908b3ffb72061b7517ed29814d62355b Author: Gordon Tetlow AuthorDate: 2023-10-03 21:23:40 +0000 Commit: Gordon Tetlow CommitDate: 2023-10-03 21:23:40 +0000 msdosfs: zero partially valid extended cluster Approved by: so Security: FreeBSD-SA-23:12.msdosfs Security: CVE-2023-5368 --- sys/fs/msdosfs/msdosfs_denode.c | 53 +++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/sys/fs/msdosfs/msdosfs_denode.c b/sys/fs/msdosfs/msdosfs_denode.c index 030c96d6d354..37d23f2ce60b 100644 --- a/sys/fs/msdosfs/msdosfs_denode.c +++ b/sys/fs/msdosfs/msdosfs_denode.c @@ -384,10 +384,8 @@ detrunc(struct denode *dep, u_long length, int flags, struct ucred *cred) return (EINVAL); } - if (dep->de_FileSize < length) { - vnode_pager_setsize(DETOV(dep), length); + if (dep->de_FileSize < length) return (deextend(dep, length, cred)); - } /* * If the desired length is 0 then remember the starting cluster of @@ -496,13 +494,16 @@ int deextend(struct denode *dep, u_long length, struct ucred *cred) { struct msdosfsmount *pmp = dep->de_pmp; + struct vnode *vp = DETOV(dep); + struct buf *bp; + off_t eof_clusteroff; u_long count; int error; /* * The root of a DOS filesystem cannot be extended. */ - if ((DETOV(dep)->v_vflag & VV_ROOT) && !FAT32(pmp)) + if ((vp->v_vflag & VV_ROOT) != 0 && !FAT32(pmp)) return (EINVAL); /* @@ -522,15 +523,47 @@ deextend(struct denode *dep, u_long length, struct ucred *cred) if (count > pmp->pm_freeclustercount) return (ENOSPC); error = extendfile(dep, count, NULL, NULL, DE_CLEAR); - if (error) { - /* truncate the added clusters away again */ - (void) detrunc(dep, dep->de_FileSize, 0, cred); - return (error); - } + if (error != 0) + goto rewind; } + + /* + * For the case of cluster size larger than the page size, we + * need to ensure that the possibly dirty partial buffer at + * the old end of file is not filled with invalid pages by + * extension. Otherwise it has a contradictory state of + * B_CACHE | B_DELWRI but with invalid pages, and cannot be + * neither written out nor validated. + * + * Fix it by proactively clearing extended pages. Need to do + * both vfs_bio_clrbuf() to mark pages valid, and to zero + * actual buffer content which might exist in the tail of the + * already valid cluster. + */ + error = bread(vp, de_cluster(pmp, dep->de_FileSize), pmp->pm_bpcluster, + NOCRED, &bp); + if (error != 0) + goto rewind; + vfs_bio_clrbuf(bp); + eof_clusteroff = de_cn2off(pmp, de_cluster(pmp, dep->de_FileSize)); + vfs_bio_bzero_buf(bp, dep->de_FileSize - eof_clusteroff, + pmp->pm_bpcluster - dep->de_FileSize + eof_clusteroff); + if (!DOINGASYNC(vp)) + (void)bwrite(bp); + else if (vm_page_count_severe() || buf_dirty_count_severe()) + bawrite(bp); + else + bdwrite(bp); + + vnode_pager_setsize(vp, length); dep->de_FileSize = length; dep->de_flag |= DE_UPDATE | DE_MODIFIED; - return (deupdat(dep, !DOINGASYNC(DETOV(dep)))); + return (deupdat(dep, !DOINGASYNC(vp))); + +rewind: + /* truncate the added clusters away again */ + (void)detrunc(dep, dep->de_FileSize, 0, cred); + return (error); } /*