summaryrefslogtreecommitdiffstats
path: root/sys/ufs
diff options
context:
space:
mode:
authormckusick <mckusick@FreeBSD.org>2012-02-09 22:34:16 +0000
committermckusick <mckusick@FreeBSD.org>2012-02-09 22:34:16 +0000
commitae0070400298fe2b9c55eac51b6233e66ff8eb71 (patch)
tree83b06f36bf3e064584b9d0207d6d37a974689a9d /sys/ufs
parent4fc3bdaf2c31a67f9ade71bdaf263600f8ffe3fd (diff)
downloadFreeBSD-src-ae0070400298fe2b9c55eac51b6233e66ff8eb71.zip
FreeBSD-src-ae0070400298fe2b9c55eac51b6233e66ff8eb71.tar.gz
Historically when an application wrote an entire block of a file,
the kernel allocated a buffer but did not zero it as it was about to be completely filled by a uiomove() from the user's buffer. However, if the uiomove() failed, the old contents of the buffer could be exposed especially if the file was being mmap'ed. The fix was to always zero the buffer when it was allocated. This change first attempts the uiomove() to the newly allocated (and dirty) buffer and only zeros it if the uiomove() fails. The effect is to eliminate the gratuitous zeroing of the buffer in the usual case where the uiomove() successfully fills it. Reviewed by: kib Tested by: scottl MFC after: 2 weeks (to 9 only)
Diffstat (limited to 'sys/ufs')
-rw-r--r--sys/ufs/ffs/ffs_vnops.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/sys/ufs/ffs/ffs_vnops.c b/sys/ufs/ffs/ffs_vnops.c
index 81c7af4..333f447 100644
--- a/sys/ufs/ffs/ffs_vnops.c
+++ b/sys/ufs/ffs/ffs_vnops.c
@@ -718,15 +718,6 @@ ffs_write(ap)
vnode_pager_setsize(vp, ip->i_size);
break;
}
- /*
- * If the buffer is not valid we have to clear out any
- * garbage data from the pages instantiated for the buffer.
- * If we do not, a failed uiomove() during a write can leave
- * the prior contents of the pages exposed to a userland
- * mmap(). XXX deal with uiomove() errors a better way.
- */
- if ((bp->b_flags & B_CACHE) == 0 && fs->fs_bsize <= xfersize)
- vfs_bio_clrbuf(bp);
if (ioflag & IO_DIRECT)
bp->b_flags |= B_DIRECT;
if ((ioflag & (IO_SYNC|IO_INVAL)) == (IO_SYNC|IO_INVAL))
@@ -743,6 +734,26 @@ ffs_write(ap)
error =
uiomove((char *)bp->b_data + blkoffset, (int)xfersize, uio);
+ /*
+ * If the buffer is not already filled and we encounter an
+ * error while trying to fill it, we have to clear out any
+ * garbage data from the pages instantiated for the buffer.
+ * If we do not, a failed uiomove() during a write can leave
+ * the prior contents of the pages exposed to a userland mmap.
+ *
+ * Note that we need only clear buffers with a transfer size
+ * equal to the block size because buffers with a shorter
+ * transfer size were cleared above by the call to UFS_BALLOC()
+ * with the BA_CLRBUF flag set.
+ *
+ * If the source region for uiomove identically mmaps the
+ * buffer, uiomove() performed the NOP copy, and the buffer
+ * content remains valid because the page fault handler
+ * validated the pages.
+ */
+ if (error != 0 && (bp->b_flags & B_CACHE) == 0 &&
+ fs->fs_bsize == xfersize)
+ vfs_bio_clrbuf(bp);
if ((ioflag & (IO_VMIO|IO_DIRECT)) &&
(LIST_EMPTY(&bp->b_dep))) {
bp->b_flags |= B_RELBUF;
OpenPOWER on IntegriCloud