summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorDave Chinner <dchinner@redhat.com>2018-11-20 00:31:10 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-12-13 10:51:31 +0300
commitb61fdcdbdad97639dfb9c605ab89e2d33d5d6aa0 (patch)
treec66ce0bc8c9e80e4089af5766480296c8da39379 /fs
parentac3ec5a40ec9b63208d661319536451f0f93f16c (diff)
downloadlinux-b61fdcdbdad97639dfb9c605ab89e2d33d5d6aa0.tar.xz
iomap: sub-block dio needs to zeroout beyond EOF
[ Upstream commit b450672fb66b4a991a5b55ee24209ac7ae7690ce ] If we are doing sub-block dio that extends EOF, we need to zero the unused tail of the block to initialise the data in it it. If we do not zero the tail of the block, then an immediate mmap read of the EOF block will expose stale data beyond EOF to userspace. Found with fsx running sub-block DIO sizes vs MAPREAD/MAPWRITE operations. Fix this by detecting if the end of the DIO write is beyond EOF and zeroing the tail if necessary. Signed-off-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/iomap.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/fs/iomap.c b/fs/iomap.c
index 914c07c9e0d6..d3d227682f7d 100644
--- a/fs/iomap.c
+++ b/fs/iomap.c
@@ -1700,7 +1700,14 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
dio->submit.cookie = submit_bio(bio);
} while (nr_pages);
- if (need_zeroout) {
+ /*
+ * We need to zeroout the tail of a sub-block write if the extent type
+ * requires zeroing or the write extends beyond EOF. If we don't zero
+ * the block tail in the latter case, we can expose stale data via mmap
+ * reads of the EOF block.
+ */
+ if (need_zeroout ||
+ ((dio->flags & IOMAP_DIO_WRITE) && pos >= i_size_read(inode))) {
/* zero out from the end of the write to the end of the block */
pad = pos & (fs_block_size - 1);
if (pad)