diff options
author | John Levon <john.levon@nutanix.com> | 2021-06-01 15:14:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-01 15:14:46 +0100 |
commit | 9c37a1813b65899ad3b0288a51b0cf1c372ee775 (patch) | |
tree | 3cdf95f941ec40788ff64957542cd74c72c988f1 /lib/dma.c | |
parent | 96ec963075e721c939441eaf0b92ea2a24b65668 (diff) | |
download | libvfio-user-9c37a1813b65899ad3b0288a51b0cf1c372ee775.zip libvfio-user-9c37a1813b65899ad3b0288a51b0cf1c372ee775.tar.gz libvfio-user-9c37a1813b65899ad3b0288a51b0cf1c372ee775.tar.bz2 |
limit max DMA region size (#545)
Since the dirty bitmap in message replies is allocated based upon the maximum
size of an individual region, add a limit (somewhat arbitrarily 8TiB, which is a
bitmap size of 256MiB). Add a couple of basic tests on the two DMA limits.
Signed-off-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'lib/dma.c')
-rw-r--r-- | lib/dma.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -71,7 +71,7 @@ fds_are_same_file(int fd1, int fd2) } dma_controller_t * -dma_controller_create(vfu_ctx_t *vfu_ctx, int max_regions) +dma_controller_create(vfu_ctx_t *vfu_ctx, size_t max_regions, size_t max_size) { dma_controller_t *dma; @@ -83,7 +83,8 @@ dma_controller_create(vfu_ctx_t *vfu_ctx, int max_regions) } dma->vfu_ctx = vfu_ctx; - dma->max_regions = max_regions; + dma->max_regions = (int)max_regions; + dma->max_size = max_size; dma->nregions = 0; memset(dma->regions, 0, max_regions * sizeof(dma->regions[0])); dma->dirty_pgsize = 0; @@ -298,6 +299,12 @@ MOCK_DEFINE(dma_controller_add_region)(dma_controller_t *dma, snprintf(rstr, sizeof(rstr), "[%p, %p) fd=%d offset=%#lx prot=%#x", dma_addr, (char *)dma_addr + size, fd, offset, prot); + if (size > dma->max_size) { + vfu_log(dma->vfu_ctx, LOG_ERR, "DMA region size %zu > max %zu", + size, dma->max_size); + return ERROR_INT(ENOSPC); + } + for (idx = 0; idx < dma->nregions; idx++) { region = &dma->regions[idx]; |