`mmap` which calls this function can be called with non-canonical
addresses. In this case, it should indicate an ENOMEM error. mozjs
uses this to detect the amount of address bits.
Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1638
UK_ASSERT(PAGE_Lx_ALIGNED(va, algn_lvl));
UK_ASSERT(va <= __VADDR_MAX - len);
- UK_ASSERT(ukarch_vaddr_range_isvalid(va, len));
+
+ /* Applications can request invalid memory ranges in mmap. In case the
+ * address is not valid, then ENOMEM is the specfied error code.
+ * This should only happen rarely in practice, for example when JS
+ * engines (mozjs) do weird stuff to figure out the available address
+ * bits.
+ */
+ if (unlikely(!ukarch_vaddr_range_isvalid(va, len)))
+ return -ENOMEM;
/* Create a new VMA for the requested range. */
if (ops->new) {