Skip to content

Commit eeece46

Browse files
jankaratytso
authored andcommitted
ext4: fix zeroing of page during writeback
Tail of a page straddling inode size must be zeroed when being written out due to POSIX requirement that modifications of mmaped page beyond inode size must not be written to the file. ext4_bio_write_page() did this only for blocks fully beyond inode size but didn't properly zero blocks partially beyond inode size. Fix this. The problem has been uncovered by mmap_11-4 test in openposix test suite (part of LTP). Reported-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com> Fixes: 5a0dc73 Fixes: bd2d021 CC: stable@vger.kernel.org Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent aa13d5f commit eeece46

1 file changed

Lines changed: 11 additions & 13 deletions

File tree

‎fs/ext4/page-io.c‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,17 @@ int ext4_bio_write_page(struct ext4_io_submit *io,
421421
set_page_writeback(page);
422422
ClearPageError(page);
423423

424+
/*
425+
* Comments copied from block_write_full_page_endio:
426+
*
427+
* The page straddles i_size. It must be zeroed out on each and every
428+
* writepage invocation because it may be mmapped. "A file is mapped
429+
* in multiples of the page size. For a file that is not a multiple of
430+
* the page size, the remaining memory is zeroed when mapped, and
431+
* writes to that region are not written out to the file."
432+
*/
433+
if (len < PAGE_CACHE_SIZE)
434+
zero_user_segment(page, len, PAGE_CACHE_SIZE);
424435
/*
425436
* In the first loop we prepare and mark buffers to submit. We have to
426437
* mark all buffers in the page before submitting so that
@@ -432,19 +443,6 @@ int ext4_bio_write_page(struct ext4_io_submit *io,
432443
do {
433444
block_start = bh_offset(bh);
434445
if (block_start >= len) {
435-
/*
436-
* Comments copied from block_write_full_page_endio:
437-
*
438-
* The page straddles i_size. It must be zeroed out on
439-
* each and every writepage invocation because it may
440-
* be mmapped. "A file is mapped in multiples of the
441-
* page size. For a file that is not a multiple of
442-
* the page size, the remaining memory is zeroed when
443-
* mapped, and writes to that region are not written
444-
* out to the file."
445-
*/
446-
zero_user_segment(page, block_start,
447-
block_start + blocksize);
448446
clear_buffer_dirty(bh);
449447
set_buffer_uptodate(bh);
450448
continue;

0 commit comments

Comments
 (0)