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

Maxim Patlasov mpatlasov at virtuozzo.com
Wed Jul 26 07:50:00 MSK 2017


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 at suse.cz>
    Signed-off-by: Theodore Ts'o <tytso at mit.edu>

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

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

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 {



More information about the Devel mailing list