Skip to content

Commit 0add783

Browse files
committed
Add a bounds check for partial MMIO maps
Signed-off-by: Alastair D'Silva <alastair@d-silva.org>
1 parent d9d6ef5 commit 0add783

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/mmio.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,35 @@ ocxl_err ocxl_mmio_map_advanced(ocxl_afu_h afu, ocxl_mmio_type type, size_t size
257257
ocxl_afu *my_afu = (ocxl_afu *) afu;
258258
ocxl_err rc = OCXL_INVALID_ARGS;
259259

260+
if (size == 0) {
261+
switch (type) {
262+
case OCXL_PER_PASID_MMIO:
263+
size = my_afu->per_pasid_mmio.length;
264+
break;
265+
case OCXL_GLOBAL_MMIO:
266+
size = my_afu->global_mmio.length;
267+
break;
268+
}
269+
}
270+
260271
switch (type) {
261272
case OCXL_GLOBAL_MMIO:
273+
if (offset + size > my_afu->global_mmio.length) {
274+
rc = OCXL_NO_MEM;
275+
errmsg(my_afu, rc, "Offset(%x) + size(%x) of global MMIO map request exceeds available size of %x",
276+
offset, size, my_afu->global_mmio.length);
277+
return rc;
278+
}
262279
return global_mmio_map(my_afu, size, prot, flags, offset, region);
263280
break;
264281

265282
case OCXL_PER_PASID_MMIO:
283+
if (offset + size > my_afu->global_mmio.length) {
284+
rc = OCXL_NO_MEM;
285+
errmsg(my_afu, rc, "Offset(%x) + size(%x) of global MMIO map request exceeds available size of %x",
286+
offset, size, my_afu->global_mmio.length);
287+
return rc;
288+
}
266289
return mmio_map(my_afu, size, prot, flags, offset, region);
267290
break;
268291

0 commit comments

Comments
 (0)