Skip to content

Commit

Permalink
mm/mprotect: fix do_mprotect_pkey() return on error
Browse files Browse the repository at this point in the history
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/[email protected]
Fixes: 2286a69 ("mm: change mprotect_fixup to vma iterator")
Signed-off-by: Liam R. Howlett <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
howlett authored and akpm00 committed Apr 16, 2023
1 parent dd47ac4 commit 82f9513
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion mm/mprotect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 82f9513

Please sign in to comment.