From: Andreas Gruenbacher Date: Mon, 21 Jun 2021 20:28:50 +0000 (+0200) Subject: gfs2: Fix underflow in gfs2_page_mkwrite X-Git-Tag: v5.15~860^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d3c51c55cb9274dd43c156f1f26b5eb4d5f2d58c;p=platform%2Fkernel%2Flinux-starfive.git gfs2: Fix underflow in gfs2_page_mkwrite On filesystems with a block size smaller than PAGE_SIZE and non-empty files smaller then PAGE_SIZE, gfs2_page_mkwrite could end up allocating excess blocks beyond the end of the file, similar to fallocate. This doesn't make sense; fix it. Reported-by: Bob Peterson Fixes: 184b4e60853d ("gfs2: Fix end-of-file handling in gfs2_page_mkwrite") Cc: stable@vger.kernel.org # v5.5+ Signed-off-by: Andreas Gruenbacher --- diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index 7b757195fd97..37041873bb95 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c @@ -450,8 +450,8 @@ static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf) file_update_time(vmf->vma->vm_file); /* page is wholly or partially inside EOF */ - if (offset > size - PAGE_SIZE) - length = offset_in_page(size); + if (size - offset < PAGE_SIZE) + length = size - offset; else length = PAGE_SIZE;