From: Liam R. Howlett Date: Tue, 6 Jun 2023 18:29:12 +0000 (-0400) Subject: mm/mprotect: fix do_mprotect_pkey() limit check X-Git-Tag: v6.6.17~4403^2~37 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=77795f900e2a07c1cbedc375789aefb43843b6c2;p=platform%2Fkernel%2Flinux-rpi.git mm/mprotect: fix do_mprotect_pkey() limit check The return of do_mprotect_pkey() can still be incorrectly returned as success if there is a gap that spans to or beyond the end address passed in. Update the check to ensure that the end address has indeed been seen. Link: https://lore.kernel.org/all/CABi2SkXjN+5iFoBhxk71t3cmunTk-s=rB4T7qo0UQRh17s49PQ@mail.gmail.com/ Link: https://lkml.kernel.org/r/20230606182912.586576-1-Liam.Howlett@oracle.com Fixes: 82f951340f25 ("mm/mprotect: fix do_mprotect_pkey() return on error") Signed-off-by: Liam R. Howlett Reported-by: Jeff Xu Reviewed-by: Lorenzo Stoakes Acked-by: David Hildenbrand Acked-by: Vlastimil Babka Cc: Signed-off-by: Andrew Morton --- diff --git a/mm/mprotect.c b/mm/mprotect.c index 92d3d3c..c59e756 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -867,7 +867,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len, } tlb_finish_mmu(&tlb); - if (!error && vma_iter_end(&vmi) < end) + if (!error && tmp < end) error = -ENOMEM; out: