From e7f0fc73cdab811948adf5227c04f722a7c3105b Mon Sep 17 00:00:00 2001 From: John Levon Date: Tue, 28 Sep 2021 17:34:12 +0100 Subject: disable VFIO_USER_DEVICE_GET_REGION_IO_FDS on invalid region (#607) If a region is not set up, asking for its iofds should fail with EINVAL. Co-authored-by: John Levon Signed-off-by: John Levon Reviewed-by: Thanos Makatos --- lib/libvfio-user.c | 5 +++++ test/py/test_device_get_region_io_fds.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/libvfio-user.c b/lib/libvfio-user.c index 69aeb36..25b58e0 100644 --- a/lib/libvfio-user.c +++ b/lib/libvfio-user.c @@ -576,6 +576,11 @@ handle_device_get_region_io_fds(vfu_ctx_t *vfu_ctx, vfu_msg_t *msg) vfu_reg = &vfu_ctx->reg_info[req->index]; + // At least one flag must be set for a valid region. + if (!(vfu_reg->flags & VFU_REGION_FLAG_MASK)) { + return ERROR_INT(EINVAL); + } + LIST_FOREACH(sub_reg, &vfu_reg->subregions, entry) { nr_sub_reg++; } diff --git a/test/py/test_device_get_region_io_fds.py b/test/py/test_device_get_region_io_fds.py index 63e3236..2179cf7 100644 --- a/test/py/test_device_get_region_io_fds.py +++ b/test/py/test_device_get_region_io_fds.py @@ -140,7 +140,7 @@ def test_device_get_region_io_fds_no_regions_setup(): index = VFU_PCI_DEV_BAR3_REGION_IDX, count = 0) ret = msg(ctx, sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, payload, - expect = 0) + expect = errno.EINVAL) def test_device_get_region_io_fds_region_no_mmap(): -- cgit v1.1