git: 6bccb677d06e - stable/13 - ufs: do not leave around empty buffers shadowing disk content

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Thu, 21 Dec 2023 15:21:11 UTC
The branch stable/13 has been updated by kib:

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

commit 6bccb677d06ea15fb34d00b482c77c8f8bf35e19
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2023-12-11 22:57:28 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2023-12-21 15:20:39 +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 abc1c3524396..21e6e22c6f88 100644
--- a/sys/ufs/ffs/ffs_vnops.c
+++ b/sys/ufs/ffs/ffs_vnops.c
@@ -969,8 +969,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);