On 4/20/22 3:57 PM, Sidhartha Kumar wrote:
Because mremap does not have a MAP_FIXED_NOREPLACE flag, it can destroy existing mappings. This causes a segfault when regions such as text are remapped and the permissions are changed.
Verify the requested mremap destination address does not overlap any existing mappings by using mmap's MAP_FIXED_NOREPLACE flag. Keep incrementing the destination address until a valid mapping is found or fail the current test once the max address is reached.
Signed-off-by: Sidhartha Kumar sidhartha.kumar@oracle.com
v2: -rename remap_region_valid() to is_remap_region_valid(). -change return value of is_remap_region_valid() to bool. -take out overflow check from is_remap_region_valid() to inside caller. -fail just the current test on overflow rather than existing the program -fix alignment of mmap calls -change "can't" to "couldn't" in error message -increment mremap destination address by dest_alignment rather than src_alignment
Thank you.
Reviewed-by: Shuah Khan skhan@linuxfoundation.org
Andrew, please let me know if you would like me to take this through kselftest tree.