From: Liam R. Howlett Date: Wed, 5 Apr 2023 15:57:56 +0000 (-0400) Subject: mm/mprotect: Fix do_mprotect_pkey() return on error X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=c996a0d5dba9cfcbcfd052aaed939339ccc32d2a;p=users%2Fjedix%2Flinux-maple.git mm/mprotect: Fix do_mprotect_pkey() return on error When the loop over the VMA is terminated early due to an error, the return code could be overwritten with ENOMEM. Fix this by only setting the error code when it is not set already. Fixes: 2286a6914c77 ("mm: change mprotect_fixup to vma iterator") Cc: Signed-off-by: Liam R. Howlett --- diff --git a/mm/mprotect.c b/mm/mprotect.c index b9da9a5f87fe..6d0b55607b9e 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -803,6 +803,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len, tlb_gather_mmu(&tlb, current->mm); nstart = start; tmp = vma->vm_start; + error = 0; for_each_vma_range(vmi, vma, end) { unsigned long mask_off_old_flags; unsigned long newflags; @@ -869,7 +870,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len, } tlb_finish_mmu(&tlb); - if (vma_iter_end(&vmi) < end) + if (!error && vma_iter_end(&vmi) < end) error = -ENOMEM; out: