git: c2ee668306bb - stable/13 - msdosfs deextend: validate pages of the partial buffer
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 19 Feb 2023 05:47:18 UTC
The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=c2ee668306bbe3edf4a05246ed3a88f52dfc94ae commit c2ee668306bbe3edf4a05246ed3a88f52dfc94ae Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2023-02-11 18:09:30 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2023-02-19 05:16:25 +0000 msdosfs deextend: validate pages of the partial buffer PR: 269341 (cherry picked from commit 0152d453a08fa2bad694dc04a8184fce2b7faa10) --- 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 003c710801ee..51c2e3beaf39 100644 --- a/sys/fs/msdosfs/msdosfs_denode.c +++ b/sys/fs/msdosfs/msdosfs_denode.c @@ -495,6 +495,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; @@ -521,16 +522,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); } /*