Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 3 Apr 2019 17:02:18 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r345847 - head/sys/fs/msdosfs
Message-ID:  <201904031702.x33H2IC9056774@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Wed Apr  3 17:02:18 2019
New Revision: 345847
URL: https://svnweb.freebsd.org/changeset/base/345847

Log:
  msdosfs: zero tail of the last block on truncation for VREG vnodes as well.
  
  Despite the call to vtruncbuf() from detrunc(), which results in
  zeroing part of the partial page after EOF, there still is a
  possibility to retain the stale data which is revived on file
  enlargement.  If the filesystem block size is greater than the page
  size, partial block might keep other after-EOF pages wired and they
  get reused then.  Fix it by zeroing whole part of the partial buffer
  after EOF, not relying on vnode_pager_setsize().
  
  PR:	236977
  Reported by:	asomers
  Tested by:	pho
  Sponsored by:	The FreeBSD Foundation
  MFC after:	1 week

Modified:
  head/sys/fs/msdosfs/msdosfs_denode.c

Modified: head/sys/fs/msdosfs/msdosfs_denode.c
==============================================================================
--- head/sys/fs/msdosfs/msdosfs_denode.c	Wed Apr  3 13:59:35 2019	(r345846)
+++ head/sys/fs/msdosfs/msdosfs_denode.c	Wed Apr  3 17:02:18 2019	(r345847)
@@ -405,19 +405,21 @@ detrunc(struct denode *dep, u_long length, int flags, 
 			bn = cntobn(pmp, eofentry);
 			error = bread(pmp->pm_devvp, bn, pmp->pm_bpcluster,
 			    NOCRED, &bp);
-			if (error) {
-				brelse(bp);
+		} else {
+			error = bread(DETOV(dep), de_cluster(pmp, length),
+			    pmp->pm_bpcluster, cred, &bp);
+		}
+		if (error) {
 #ifdef MSDOSFS_DEBUG
-				printf("detrunc(): bread fails %d\n", error);
+			printf("detrunc(): bread fails %d\n", error);
 #endif
-				return (error);
-			}
-			memset(bp->b_data + boff, 0, pmp->pm_bpcluster - boff);
-			if (flags & IO_SYNC)
-				bwrite(bp);
-			else
-				bdwrite(bp);
+			return (error);
 		}
+		memset(bp->b_data + boff, 0, pmp->pm_bpcluster - boff);
+		if ((flags & IO_SYNC) != 0)
+			bwrite(bp);
+		else
+			bdwrite(bp);
 	}
 
 	/*



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201904031702.x33H2IC9056774>