libsel4vmmplatsupport: Fix an off-by-one error Previously, the 'end' of an IO port range was not inclusive. This would result in a bug where one IO port whose value is the 'end' of a range would be mistaken as being part of that range when it should not be. This commit fixes it so that the 'end' of an IO port range is now inclusive. Also harden the range overlap check.
diff --git a/libsel4vmmplatsupport/src/ioports.c b/libsel4vmmplatsupport/src/ioports.c index 1eb2e73..9bf80d6 100644 --- a/libsel4vmmplatsupport/src/ioports.c +++ b/libsel4vmmplatsupport/src/ioports.c
@@ -102,7 +102,7 @@ } /* ensure this range does not overlap */ for (int i = 0; i < io_list->num_ioports; i++) { - if (io_list->ioports[i]->range.end > port->range.start && io_list->ioports[i]->range.start < port->range.end) { + if (io_list->ioports[i]->range.end >= port->range.start && io_list->ioports[i]->range.start <= port->range.end) { ZF_LOGE("Requested ioport range 0x%x-0x%x for %s overlaps with existing range 0x%x-0x%x for %s", port->range.start, port->range.end, port->interface.desc ? port->interface.desc : "Unknown IO Port", io_list->ioports[i]->range.start, io_list->ioports[i]->range.end, @@ -130,7 +130,7 @@ } io_list->alloc_addr += io_range->size; io_range->start = free_port_addr; - io_range->end = free_port_addr + io_range->size; + io_range->end = free_port_addr + io_range->size - 1; return 0; }