]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
mm/mprotect: fix do_mprotect_pkey() return on error
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Thu, 6 Apr 2023 19:30:50 +0000 (15:30 -0400)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 16 Apr 2023 17:41:24 +0000 (10:41 -0700)
When the loop over the VMA is terminated early due to an error, the return
code could be overwritten with ENOMEM.  Fix the return code by only
setting the error on early loop termination when the error is not set.

User-visible effects include: attempts to run mprotect() against a
special mapping or with a poorly-aligned hugetlb address should return
-EINVAL, but they presently return -ENOMEM.  In other cases an -EACCESS
should be returned.

Link: https://lkml.kernel.org/r/20230406193050.1363476-1-Liam.Howlett@oracle.com
Fixes: 2286a6914c77 ("mm: change mprotect_fixup to vma iterator")
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/mprotect.c

index 13e84d8c0797a9394caf65d0a0bba52f42338753..36351a00c0e82de1508575f152b816c4d40cf66c 100644 (file)
@@ -838,7 +838,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: