[Devel,vz7,2/3] ext4: fix off-by-in in loop termination in ext4_find_unwritten_pgoff()

Submitted by Maxim Patlasov on July 26, 2017, 4:50 a.m.

Details

Message ID 150104458864.5571.2266911579571462058.stgit@maxim-thinkpad
State New
Series "ext4: backport SEEK_DATA/SEEK_HOLE patches from mainline"
Headers show

Commit Message

Maxim Patlasov July 26, 2017, 4:50 a.m.
Backport 3f1d5bad3fae983da07be01cff2fde13293bb7b9 from ml:

    ext4: fix off-by-in in loop termination in ext4_find_unwritten_pgoff()

    There is an off-by-one error in loop termination conditions in
    ext4_find_unwritten_pgoff() since 'end' may index a page beyond end of
    desired range if 'endoff' is page aligned. It doesn't have any visible
    effects but still it is good to fix it.

    Signed-off-by: Jan Kara <jack@suse.cz>
    Signed-off-by: Theodore Ts'o <tytso@mit.edu>

Signed-off-by: Maxim Patlasov <mpatlasov@virtuozzo.com>

https://jira.sw.ru/browse/PSBM-68292
---
 fs/ext4/file.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index da5851e..be8da78 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -443,7 +443,7 @@  static int ext4_find_unwritten_pgoff(struct inode *inode,
 	endoff = (loff_t)end_blk << blkbits;
 
 	index = startoff >> PAGE_CACHE_SHIFT;
-	end = endoff >> PAGE_CACHE_SHIFT;
+	end = (endoff - 1) >> PAGE_CACHE_SHIFT;
 
 	pagevec_init(&pvec, 0);
 	do {