From c174ca8539a47ea3b87b1d4015a0b9f21c738dad Mon Sep 17 00:00:00 2001 From: Swapnil Ingle Date: Fri, 14 May 2021 12:05:55 +0200 Subject: dma: Use correct len type (#479) * dma: Use correct len type vfio_iommu_type1_dirty_bitmap_get.size is of type __u64 dma_controller_dirty_page_get() receives it as int, instead it should be u64 Also added UT to test overflow of length passed to dma_controller_dirty_page_get Fixes: #477 Signed-off-by: Swapnil Ingle Reviewed-by: John Levon --- test/unit-tests.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit-tests.c b/test/unit-tests.c index 7fbb055..df51b08 100644 --- a/test/unit-tests.c +++ b/test/unit-tests.c @@ -486,7 +486,7 @@ test_dma_map_sg(void **state UNUSED) sg.length = 0xcafebabe; assert_int_equal(0, dma_map_sg(vfu_ctx.dma, &sg, &iovec, 1)); assert_int_equal(0xdeadbeef, iovec.iov_base); - assert_int_equal((int)0x00000000cafebabe, iovec.iov_len); + assert_int_equal(0x00000000cafebabe, iovec.iov_len); } static void @@ -1816,6 +1816,24 @@ test_process_request_free_passed_fds(void **state UNUSED) assert_int_equal(0, process_request(&vfu_ctx)); } +static void +test_dma_controller_dirty_page_get(void **state UNUSED) +{ + dma_memory_region_t *r; + uint64_t len = UINT32_MAX + (uint64_t)10; + char bp[131073]; + + vfu_ctx.dma->nregions = 1; + r = &vfu_ctx.dma->regions[0]; + r->info.iova.iov_base = (void *)0; + r->info.iova.iov_len = len; + r->info.vaddr = (void *)0xdeadbeef; + vfu_ctx.dma->dirty_pgsize = 4096; + + assert_int_equal(0, dma_controller_dirty_page_get(vfu_ctx.dma, (void *)0, + len, 4096, 131073, (char **)&bp)); +} + int main(void) { @@ -1869,6 +1887,7 @@ main(void) cmocka_unit_test_setup(test_cmd_allowed_when_stopped_and_copying, setup), cmocka_unit_test_setup(test_should_exec_command, setup), cmocka_unit_test_setup(test_process_request_free_passed_fds, setup), + cmocka_unit_test_setup(test_dma_controller_dirty_page_get, setup), }; return cmocka_run_group_tests(tests, NULL, NULL); -- cgit v1.1