util/vfio-helpers: Assert offset is aligned to page size
authorPhilippe Mathieu-Daudé <philmd@redhat.com>
Tue, 3 Nov 2020 02:07:33 +0000 (03:07 +0100)
committerStefan Hajnoczi <stefanha@redhat.com>
Tue, 3 Nov 2020 19:06:23 +0000 (19:06 +0000)
mmap(2) states:

  'offset' must be a multiple of the page size as returned
   by sysconf(_SC_PAGE_SIZE).

Add an assertion to be sure we don't break this contract.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-id: 20201103020733.2303148-8-philmd@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Tested-by: Eric Auger <eric.auger@redhat.com>
util/vfio-helpers.c

index 73f7bfa75405be2bb4f78b79f6167c6affd1f221..804768d5c668dedf706fe6bd73f1f3aad2e74a29 100644 (file)
@@ -162,6 +162,7 @@ void *qemu_vfio_pci_map_bar(QEMUVFIOState *s, int index,
                             Error **errp)
 {
     void *p;
+    assert(QEMU_IS_ALIGNED(offset, qemu_real_host_page_size));
     assert_bar_index_valid(s, index);
     p = mmap(NULL, MIN(size, s->bar_region_info[index].size - offset),
              prot, MAP_SHARED,