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=c895c88d05fef0960027611b15a5a94ac98647bb;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 53308a5ccf92..7399bd7de49a 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -801,6 +801,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; @@ -867,7 +868,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: