diff options
author | John Levon <john.levon@nutanix.com> | 2021-07-14 12:33:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-14 12:33:20 +0100 |
commit | 2a0a92912d598de871ab47c034432c5fa6546dc4 (patch) | |
tree | 7c33b0f6350fe6e2cce0434dd2bfe9b9631b4dca /lib | |
parent | 561b3092c73b1b45756630fac73b182a3de0fdff (diff) | |
download | libvfio-user-2a0a92912d598de871ab47c034432c5fa6546dc4.zip libvfio-user-2a0a92912d598de871ab47c034432c5fa6546dc4.tar.gz libvfio-user-2a0a92912d598de871ab47c034432c5fa6546dc4.tar.bz2 |
check for valid vfu_setup_region() flags (#579)
Complain about a region that isn't readable *or* writable, or any unknown flags.
Signed-off-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libvfio-user.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/libvfio-user.c b/lib/libvfio-user.c index 1ee4026..c9c78d6 100644 --- a/lib/libvfio-user.c +++ b/lib/libvfio-user.c @@ -1430,6 +1430,17 @@ vfu_setup_region(vfu_ctx_t *vfu_ctx, int region_idx, size_t size, assert(vfu_ctx != NULL); + if ((flags & ~(VFU_REGION_FLAG_MASK)) || + (!(flags & VFU_REGION_FLAG_RW))) { + vfu_log(vfu_ctx, LOG_ERR, "invalid region flags"); + return ERROR_INT(EINVAL); + } + + if ((flags & VFU_REGION_FLAG_ALWAYS_CB) && (cb == NULL)) { + vfu_log(vfu_ctx, LOG_ERR, "VFU_REGION_FLAG_ALWAYS_CB needs callback"); + return ERROR_INT(EINVAL); + } + if ((mmap_areas == NULL) != (nr_mmap_areas == 0) || (mmap_areas != NULL && fd == -1)) { vfu_log(vfu_ctx, LOG_ERR, "invalid mappable region arguments"); @@ -1451,11 +1462,6 @@ vfu_setup_region(vfu_ctx_t *vfu_ctx, int region_idx, size_t size, return ERROR_INT(EINVAL); } - if ((flags & VFU_REGION_FLAG_ALWAYS_CB) && (cb == NULL)) { - vfu_log(vfu_ctx, LOG_ERR, "VFU_REGION_FLAG_ALWAYS_CB needs callback"); - return ERROR_INT(EINVAL); - } - if (region_idx == VFU_PCI_DEV_MIGR_REGION_IDX && size < vfu_get_migr_register_area_size()) { vfu_log(vfu_ctx, LOG_ERR, "invalid migration region size %zu", size); |