Skip to content

Commit 78d2d32

Browse files
Carlos Llamasakpm00
authored andcommitted
mm/mremap: fix regression in vrm->new_addr check
Commit 3215eac ("mm/mremap: refactor initial parameter sanity checks") moved the sanity check for vrm->new_addr from mremap_to() to check_mremap_params(). However, this caused a regression as vrm->new_addr is now checked even when MREMAP_FIXED and MREMAP_DONTUNMAP flags are not specified. In this case, vrm->new_addr can be garbage and create unexpected failures. Fix this by moving the new_addr check after the vrm_implies_new_addr() guard. This ensures that the new_addr is only checked when the user has specified one explicitly. Link: https://lkml.kernel.org/r/[email protected] Fixes: 3215eac ("mm/mremap: refactor initial parameter sanity checks") Signed-off-by: Carlos Llamas <[email protected]> Reviewed-by: Liam R. Howlett <[email protected]> Reviewed-by: Vlastimil Babka <[email protected]> Reviewed-by: Lorenzo Stoakes <[email protected]> Cc: Carlos Llamas <[email protected]> Cc: Jann Horn <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 7989fdc commit 78d2d32

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

mm/mremap.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,15 +1774,18 @@ static unsigned long check_mremap_params(struct vma_remap_struct *vrm)
17741774
if (!vrm->new_len)
17751775
return -EINVAL;
17761776

1777-
/* Is the new length or address silly? */
1778-
if (vrm->new_len > TASK_SIZE ||
1779-
vrm->new_addr > TASK_SIZE - vrm->new_len)
1777+
/* Is the new length silly? */
1778+
if (vrm->new_len > TASK_SIZE)
17801779
return -EINVAL;
17811780

17821781
/* Remainder of checks are for cases with specific new_addr. */
17831782
if (!vrm_implies_new_addr(vrm))
17841783
return 0;
17851784

1785+
/* Is the new address silly? */
1786+
if (vrm->new_addr > TASK_SIZE - vrm->new_len)
1787+
return -EINVAL;
1788+
17861789
/* The new address must be page-aligned. */
17871790
if (offset_in_page(vrm->new_addr))
17881791
return -EINVAL;

0 commit comments

Comments
 (0)