Skip to content

Commit

Permalink
libvmm: add more error-checking to guest images setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan-Velickovic committed Oct 3, 2023
1 parent 771e46c commit aecb74c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/arch/aarch64/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,33 @@ uintptr_t linux_setup_images(uintptr_t ram_start,
uintptr_t initrd_dest,
size_t initrd_size)
{
// Before doing any copying, let's sanity check the addresses.
// First we'll check that everything actually lives inside RAM.
// @ivanv: TODO
// Check that the kernel and DTB to do not overlap
uintptr_t dtb_start = dtb_dest;
uintptr_t dtb_end = dtb_start + dtb_size;
uintptr_t kernel_start = kernel;
uintptr_t kernel_end = kernel_start + kernel_size;
if (!(dtb_start >= kernel_end || dtb_end <= kernel_start)) {
LOG_VMM_ERR("Linux kernel image [0x%lx..0x%lx) overlaps with the destination of the DTB [0x%lx)\n",
kernel_start, kernel_end, dtb_start, dtb_end);
return 0;
}
// Check that the kernel and initrd do not overlap
uintptr_t initrd_start = initrd_dest;
uintptr_t initrd_end = initrd_start + initrd_size;
if (!(initrd_start >= kernel_end || initrd_end <= kernel_start)) {
LOG_VMM_ERR("Linux kernel image [0x%lx..0x%lx) overlaps with the destination of the initial RAM disk [0x%lx)\n",
kernel_start, kernel_end, initrd_start, initrd_end);
return 0;
}
// Check that the DTB and initrd do not overlap
if (!(initrd_start >= dtb_end || initrd_end <= dtb_start)) {
LOG_VMM_ERR("DTB [0x%lx..0x%lx) overlaps with the destination of the initial RAM disk [0x%lx)\n",
dtb_start, dtb_end, initrd_start, initrd_end);
return 0;
}
// @ivanv: is there a initrd magic to check?
// First we inspect the kernel image header to confirm it is a valid image
// and to determine where in memory to place the image.
Expand Down

0 comments on commit aecb74c

Please sign in to comment.