From nobody Mon Sep 11 18:50:27 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 4Rkwl80SQYz4tLLF; Mon, 11 Sep 2023 18:50:28 +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 4Rkwl74VZ8z3Rc5; Mon, 11 Sep 2023 18:50:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694458227; 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=e3bZjszuZxEevcDGZ6oq+oxB+LUQk5JaZZAKxx8F1Hs=; b=vhXBN6tH1iBr1ywseSPIxgoNVKKHbd1BCtvcTHC24wqW4KgxDEBtjZDAGF1qeytbCSYa3L 5Y9eStJQt2kF5/KV8VbuNAWamQKMnx+CLL97t/vpzo0eK9eZ0EXoO5EbYmzWk5SQaBoTfG 1A03D52UjjM10RoSjPmjSBE3G4uz1oqAvondHZ5Hq9aqlLUoaHy5zdjcxcm0sL/WSW+KzM mEOLJOmy3wUu4WUGFCTgzzLzAIGPLAWyDoI6ia+xAdts8+ZbQnZuTS6dCMlM1uIZAuDNbm RLTKwpPmE8OfSjlAFwYdh0qbMGdTxTTr2l9/5sqKGS1qaUYGM+nRl47O76uMgg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1694458227; a=rsa-sha256; cv=none; b=JMVJwnpFhHgAw04hGvd65zIl1zAwEDZT5MP78Au2ySD8i9QuzDhBcZv2KMzNtFMmYqDdZe 2/8FSWnqiQKAxWRu+e+5xQSlvSHOGE/+0/PN+/clsEjaF8aFp5zXWQlTe8kE2VJjg3iwbC eIyLq5Y6tcd47roAeFPR+p4fc2xV8q7Diaw4QpVjBI5NPi88FzaO0IToIOwpHEXOuPVPLb ye4rvAx8iwNQms0RDT6ROuZY7EuXJietjolHxf9jjJDQv5ChQVYg8Akzvbpm0LzJ9tx3n4 qOc+wzRv8fvCNEyFwx0vpdTAOB065HEfGoQiCdP9E8xc/pxfQ08QwPK1JSqgCA== 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=1694458227; 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=e3bZjszuZxEevcDGZ6oq+oxB+LUQk5JaZZAKxx8F1Hs=; b=bjZo+fJnGP9CrflffpuM+BveFO60urrZ2MG6vWhDzvyudgSh85XEl5QttOQp9SH88GI54q u3fv9kpAS6CafTjT9hQyzjJdWvNxYTiKrpgXIUhssk6RZmF3uevEYstJIknZX37gUWgn4+ mmQL+yCUBpGSlbMJYCtGEmBozTZ2f7uiPB/xK4HBPlmV5GqxqyVsNV4SBoGuYSlqJpf2VJ +glPhpYACQNEyw1bxCWl9PHqS9TLI8SBtPCEXcnJ5+QuiwF0tzxP8biuLFl0o4uMnnEBtx 1HisVW3GV7I03U2n2UCD2LWAKL2C4vH2xcFPmz3ya6PB8zTrudS5rQaaS3dL3w== 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 4Rkwl73bcDz10M7; Mon, 11 Sep 2023 18:50:27 +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 38BIoRjN083211; Mon, 11 Sep 2023 18:50:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38BIoR0O083208; Mon, 11 Sep 2023 18:50:27 GMT (envelope-from git) Date: Mon, 11 Sep 2023 18:50:27 GMT Message-Id: <202309111850.38BIoR0O083208@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: b2e3ab898cd2 - stable/12 - 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: emaste X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: b2e3ab898cd2a8517858f32cc7397cf026013548 Auto-Submitted: auto-generated The branch stable/12 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=b2e3ab898cd2a8517858f32cc7397cf026013548 commit b2e3ab898cd2a8517858f32cc7397cf026013548 Author: Konstantin Belousov AuthorDate: 2023-02-11 18:09:30 +0000 Commit: Ed Maste CommitDate: 2023-09-11 18:04:59 +0000 msdosfs deextend: validate pages of the partial buffer PR: 269341 (cherry picked from commit 0152d453a08fa2bad694dc04a8184fce2b7faa10) (cherry picked from commit c2ee668306bbe3edf4a05246ed3a88f52dfc94ae) --- 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 b251c2797467..57d1c96a561b 100644 --- a/sys/fs/msdosfs/msdosfs_denode.c +++ b/sys/fs/msdosfs/msdosfs_denode.c @@ -476,6 +476,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; @@ -502,16 +503,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); } /*