diff options
author | Liam R. Howlett <Liam.Howlett@oracle.com> | 2023-04-06 21:30:50 +0200 |
---|---|---|
committer | Andrew Morton <akpm@linux-foundation.org> | 2023-04-16 19:41:24 +0200 |
commit | 82f951340f25bba262766f82caec54e7fd6a73c7 (patch) | |
tree | 5d60ebbb9d88235c27cc1f0e73107d2228adda55 /mm | |
parent | mm/khugepaged: check again on anon uffd-wp during isolation (diff) | |
download | linux-82f951340f25bba262766f82caec54e7fd6a73c7.tar.xz linux-82f951340f25bba262766f82caec54e7fd6a73c7.zip |
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 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>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/mprotect.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/mm/mprotect.c b/mm/mprotect.c index 13e84d8c0797..36351a00c0e8 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -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: |