From nobody Mon Feb 13 22:31:43 2023 X-Original-To: dev-commits-src-all@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 4PFzbM36yJz3qVhj; Mon, 13 Feb 2023 22:31:43 +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 4PFzbM264bz3FLW; Mon, 13 Feb 2023 22:31:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676327503; 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=5izOZXZvgupkobSEM0ZQPZSA7fRnuIAPNEUzVDZhF+g=; b=lQUpfWaa2qxU33JF/tsWFl544yUtB4SutYoSuS9YAXhvjU45rGSU/a0AmgBObRMe50Gr8w n48TFbecUaPFzton3B7zFiP4kbh4Hu2uTSi+JWg290MrYdhfOonOHpGaJS7un0u33DfKxz 4t0i1q3u+fZB4z8YAyZz57KIXaCYz+/uBWs27t0lh+ozgLEV1QJ/VtVFlBm+0Gb8nyNPmD QayrO9YPZWmrEW0FuDOTf9d5B4kH1NcWmiz/joGICVUL0P33zQ6kymLt+9iLnTjOSj47A2 aPP9QQoo3AnB9ugliB2nGIhOu+fF0k1i2JoGoy3T1j3B2qsof96ya0QCpaYXTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676327503; 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=5izOZXZvgupkobSEM0ZQPZSA7fRnuIAPNEUzVDZhF+g=; b=UYPx+65Hon5swND94eIUE5/jZge6u7nB0X+T+Iy0Hfzkak3YBlfxv+vExv1jT7lOWlTpra F8qKm4OA142ODAbyKKZ7lBL0SxNA9ZVWWkksxDfdgV/eVrK/9Yb4r/c8JglLd9ROMafCjf CM8ukNFAMUyU73TsCIvGZ9cGnScYokkz98e/6Zp4MI7XgHI+oX+7lXk9Whcw6YG+hPzYCe WI1QjiTlxelDmzlKnf8J5J2uPtpKPf/odG+TOeMmKl0OG7T0UaGiTfSUVjq3T5XNU05ALH SdDnPH45yuNDlm0ZIN1oop8LDYh3wy/e4FjArH/0BgN7UvYqhgwiS2EX/vyGMg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1676327503; a=rsa-sha256; cv=none; b=rMiOy0CP0AM+k9QKHLSKOs+j9nhq6r71e2/3nFkkm8Q2HPW6B+aEew3qS6BVjuM/pKOd8f +IHWcGeGgtyCP0c/PwRvjFXHY4lzSuHkNcy4ya2l4QaKkyP6DsgcnAFsBXd7E1cy00x24V qKG7yLw6l9lgzfO0I315jFAamyv6PQygb+l92v+FEch9wbpv9CYWPlyctpTAidfS37tej9 ZhVK4ESorAFr/FpI0pTVxAwxO2GdWFpAKKLIuwZZHMYaTABnofGNk5oPfJK4ilIMu4eqgd Sl5AdM6DXVBXkVbUhKWnUJ5DIgg4az0QLqbN2ObL4tyBxog7udPno9QjWIJwCw== 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 4PFzbM1D9XzbgT; Mon, 13 Feb 2023 22:31:43 +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 31DMVhjB080776; Mon, 13 Feb 2023 22:31:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31DMVhCv080775; Mon, 13 Feb 2023 22:31:43 GMT (envelope-from git) Date: Mon, 13 Feb 2023 22:31:43 GMT Message-Id: <202302132231.31DMVhCv080775@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 0152d453a08f - main - msdosfs deextend: validate pages of the partial buffer List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/main X-Git-Reftype: branch X-Git-Commit: 0152d453a08fa2bad694dc04a8184fce2b7faa10 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=0152d453a08fa2bad694dc04a8184fce2b7faa10 commit 0152d453a08fa2bad694dc04a8184fce2b7faa10 Author: Konstantin Belousov AuthorDate: 2023-02-11 18:09:30 +0000 Commit: Konstantin Belousov CommitDate: 2023-02-13 22:29:42 +0000 msdosfs deextend: validate pages of the partial buffer Suppose that the cluster size is larger than page size. If the buffer at the old EOF (before extending) was partial and dirty, it cannot be automatically neither written out nor validated by the buffer cache, since extending buffer adds invalid pages at the end. Correct the buffer state by calling vfs_bio_clrbuf() on it, to mark newly added and zeroed pages as valid. Note that UFS is immune to the problem because ffs_truncate() always allocate the block and buffer for the last byte of the file. PR: 269341 Reported by: asomers In collaboration with: pho Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D38549 --- sys/fs/msdosfs/msdosfs_denode.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/sys/fs/msdosfs/msdosfs_denode.c b/sys/fs/msdosfs/msdosfs_denode.c index 0b4135d60784..a82517acbdfe 100644 --- a/sys/fs/msdosfs/msdosfs_denode.c +++ b/sys/fs/msdosfs/msdosfs_denode.c @@ -497,6 +497,7 @@ deextend(struct denode *dep, u_long length, struct ucred *cred) { struct msdosfsmount *pmp = dep->de_pmp; struct vnode *vp = DETOV(dep); + struct buf *bp; u_long count; int error; @@ -523,16 +524,41 @@ 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. + */ + error = bread(vp, de_cluster(pmp, dep->de_FileSize), pmp->pm_bpcluster, + NOCRED, &bp); + if (error != 0) + goto rewind; + vfs_bio_clrbuf(bp); + 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(vp))); + +rewind: + /* truncate the added clusters away again */ + (void)detrunc(dep, dep->de_FileSize, 0, cred); + return (error); } /*