On 03/10/2023 07:41, Chaitanya S Prakash wrote:
Reservations are contiguous ranges of virtual addresses that exactly match the bounds of an owning capability. When an owning capability is passed to a syscall, it's bounds are first verified against the existing reservation. If the bounds of the capability are found to overlap with the bounds of another mapping, the syscall fails with a -ERESERVATION
It looks like there is some confusion between mapping and reservation here, -ERESERVATION is not related to mappings. Overall I'm not sure I understand the second test, which this sentence seems to describe. AFAICT it is essentially the same as the first one in patch 7, and shouldn't fail. I think what you are trying to test here is the case where ptr is *null-derived*, in which case an overlap with an existing reservation will indeed cause -ERESERVATION.
Kevin
error code. A partial unmap within a particular reservation still allows the rest of the region to be accessible. Tests to verify the same have been added.
Signed-off-by: Chaitanya S Prakash chaitanyas.prakash@arm.com
tools/testing/selftests/arm64/morello/mmap.c | 34 ++++++++++++++++++++ 1 file changed, 34 insertions(+)
diff --git a/tools/testing/selftests/arm64/morello/mmap.c b/tools/testing/selftests/arm64/morello/mmap.c index 7b1a247719f4..a2bf0c09dac1 100644 --- a/tools/testing/selftests/arm64/morello/mmap.c +++ b/tools/testing/selftests/arm64/morello/mmap.c @@ -394,6 +394,39 @@ TEST(test_range_check) ASSERT_EQ(retval, 0); } +/* test to verify mmap() behaviour when capability bounds are modified */ +TEST(test_mmap_bounds_check) +{
- void *ptr, *new_ptr;
- size_t size;
- int retval;
- int prot = PROT_READ | PROT_WRITE;
- int flags = MAP_PRIVATE | MAP_ANONYMOUS;
- /* test to verify rest of reservation region is accessible after a partial
* unmap
*/
- ptr = mmap(NULL, MMAP_SIZE, prot, flags, -1, 0);
- ASSERT_FALSE(IS_ERR_VALUE(ptr));
- retval = munmap(ptr, pagesize);
- ASSERT_EQ(retval, 0);
- ptr = ptr + pagesize;
- size = MMAP_SIZE - pagesize;
- EXPECT_EQ(0, probe_mem_range(ptr, size,
PROBE_MODE_TOUCH | PROBE_MODE_VERIFY));
- retval = munmap(ptr, size);
- ASSERT_EQ(retval, 0);
- /* overlapping mappings produce a reservation error */
- ptr = mmap(NULL, MMAP_SIZE, prot, flags, -1, 0);
- ASSERT_FALSE(IS_ERR_VALUE(ptr));
- new_ptr = mmap(ptr + MMAP_SIZE_REDUCED, MMAP_SIZE_REDUCED, prot,
flags | MAP_FIXED, -1, 0);
- VERIFY_ERRNO((unsigned long)new_ptr, (unsigned long)-ERESERVATION);
- retval = munmap(ptr, MMAP_SIZE);
- ASSERT_EQ(retval, 0);
+}
int main(int argc, char **argv, char **envp, struct morello_auxv *auxv) { reg_data.argc = argc; @@ -408,5 +441,6 @@ int main(int argc, char **argv, char **envp, struct morello_auxv *auxv) test_map_growsdown(); test_validity_tag_check(); test_range_check();
- test_mmap_bounds_check(); return 0;
}