Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

exfat: zero out post-EOF page cache on file extension

xfstests generic/363 was failing due to unzeroed post-EOF page
cache that allowed mmap writes beyond EOF to become visible
after file extension.

For example, in following xfs_io sequence, 0x22 should not be
written to the file but would become visible after the extension:

xfs_io -f -t -c "pwrite -S 0x11 0 8" \
-c "mmap 0 4096" \
-c "mwrite -S 0x22 32 32" \
-c "munmap" \
-c "pwrite -S 0x33 512 32" \
$testfile

This violates the expected behavior where writes beyond EOF via
mmap should not persist after the file is extended. Instead, the
extended region should contain zeros.

Fix this by using truncate_pagecache() to truncate the page cache
after the current EOF when extending the file.

Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>

authored by

Yuezhang Mo and committed by
Namjae Jeon
4e163c39 9aee8de9

+5
+5
fs/exfat/file.c
··· 25 25 struct exfat_sb_info *sbi = EXFAT_SB(sb); 26 26 struct exfat_chain clu; 27 27 28 + truncate_pagecache(inode, i_size_read(inode)); 29 + 28 30 ret = inode_newsize_ok(inode, size); 29 31 if (ret) 30 32 return ret; ··· 640 638 return -EIO; 641 639 642 640 inode_lock(inode); 641 + 642 + if (pos > i_size_read(inode)) 643 + truncate_pagecache(inode, i_size_read(inode)); 643 644 644 645 valid_size = ei->valid_size; 645 646