git: ddb82f214f0c - stable/14 - ufs: do not leave around empty buffers shadowing disk content

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Wed, 20 Dec 2023 08:30:22 UTC
The branch stable/14 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=ddb82f214f0cd5171f9830a6d28b75e8ded98613

commit ddb82f214f0cd5171f9830a6d28b75e8ded98613
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2023-12-11 22:57:28 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2023-12-20 08:29:55 +0000

    ufs: do not leave around empty buffers shadowing disk content
    
    (cherry picked from commit ca39f23347e1416a28dde13279bfe5841ad9a746)
---
 sys/ufs/ffs/ffs_vnops.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/sys/ufs/ffs/ffs_vnops.c b/sys/ufs/ffs/ffs_vnops.c
index 2b11a15c46c9..c14cb5e1ee66 100644
--- a/sys/ufs/ffs/ffs_vnops.c
+++ b/sys/ufs/ffs/ffs_vnops.c
@@ -981,8 +981,15 @@ ffs_write(
 		 * validated the pages.
 		 */
 		if (error != 0 && (bp->b_flags & B_CACHE) == 0 &&
-		    fs->fs_bsize == xfersize)
-			vfs_bio_clrbuf(bp);
+		    fs->fs_bsize == xfersize) {
+			if (error == EFAULT && LIST_EMPTY(&bp->b_dep)) {
+				bp->b_flags |= B_INVAL | B_RELBUF | B_NOCACHE;
+				brelse(bp);
+				break;
+			} else {
+				vfs_bio_clrbuf(bp);
+			}
+		}
 
 		vfs_bio_set_flags(bp, ioflag);