diff --git a/sys/gnu/ext2fs/ext2_readwrite.c b/sys/gnu/ext2fs/ext2_readwrite.c index f054a6e897b..30a2f561c2f 100644 --- a/sys/gnu/ext2fs/ext2_readwrite.c +++ b/sys/gnu/ext2fs/ext2_readwrite.c @@ -238,10 +238,19 @@ WRITE(ap) if (uio->uio_offset + xfersize > ip->i_size) vnode_pager_setsize(vp, uio->uio_offset + xfersize); + /* + * Avoid a data-consistency race between write() and mmap() + * by ensuring that newly allocated blocks are zerod. The + * race can occur even in the case where the write covers + * the entire block. + */ + flags |= B_CLRBUF; +#if 0 if (fs->s_frag_size > xfersize) flags |= B_CLRBUF; else flags &= ~B_CLRBUF; +#endif error = ext2_balloc(ip, lbn, blkoffset + xfersize, ap->a_cred, &bp, flags); diff --git a/sys/gnu/fs/ext2fs/ext2_readwrite.c b/sys/gnu/fs/ext2fs/ext2_readwrite.c index f054a6e897b..30a2f561c2f 100644 --- a/sys/gnu/fs/ext2fs/ext2_readwrite.c +++ b/sys/gnu/fs/ext2fs/ext2_readwrite.c @@ -238,10 +238,19 @@ WRITE(ap) if (uio->uio_offset + xfersize > ip->i_size) vnode_pager_setsize(vp, uio->uio_offset + xfersize); + /* + * Avoid a data-consistency race between write() and mmap() + * by ensuring that newly allocated blocks are zerod. The + * race can occur even in the case where the write covers + * the entire block. + */ + flags |= B_CLRBUF; +#if 0 if (fs->s_frag_size > xfersize) flags |= B_CLRBUF; else flags &= ~B_CLRBUF; +#endif error = ext2_balloc(ip, lbn, blkoffset + xfersize, ap->a_cred, &bp, flags); diff --git a/sys/ufs/ufs/ufs_readwrite.c b/sys/ufs/ufs/ufs_readwrite.c index 4830120c621..e1d775c8e97 100644 --- a/sys/ufs/ufs/ufs_readwrite.c +++ b/sys/ufs/ufs/ufs_readwrite.c @@ -468,10 +468,19 @@ WRITE(ap) if (uio->uio_offset + xfersize > ip->i_size) vnode_pager_setsize(vp, uio->uio_offset + xfersize); + /* + * Avoid a data-consistency race between write() and mmap() + * by ensuring that newly allocated blocks are zerod. The + * race can occur even in the case where the write covers + * the entire block. + */ + flags |= B_CLRBUF; +#if 0 if (fs->fs_bsize > xfersize) flags |= B_CLRBUF; else flags &= ~B_CLRBUF; +#endif /* XXX is uio->uio_offset the right thing here? */ error = VOP_BALLOC(vp, uio->uio_offset, xfersize, ap->a_cred, flags, &bp);