Before expanding the Linux image in "expand_linux_image" function, TBoot moves 
the inintrd image as high in memory as possible. If the kernel image is located 
high in memory, currently, TBoot writes over the kernel image.
The following patch adds additional checks to prevent the kernel image from 
being overwritten.

Signed-off-by: Safayet Ahmed <safayet.ah...@ge.com>

diff --git a/tboot/common/linux.c b/tboot/common/linux.c
index 26d653a..dfc2c54 100644
--- a/tboot/common/linux.c
+++ b/tboot/common/linux.c
@@ -204,6 +204,19 @@ bool expand_linux_image(const void *linux_image, size_t 
linux_size,
         initrd_base = initrd_base & PAGE_MASK;
     }
 
+    /* check for overlap with a kernel image placed high in memory */
+    if( (initrd_base < ((uint32_t)linux_image + linux_size))
+            && ((uint32_t)linux_image < (initrd_base+initrd_size)) ){
+        /* set the starting address just below the image */
+        initrd_base = (uint32_t)linux_image - initrd_size;
+        initrd_base = initrd_base & PAGE_MASK;
+        /* make sure we're still in usable RAM and above tboot end address*/
+        if( initrd_base < max_ram_base ){
+            printk(TBOOT_ERR"no available memory for initrd\n");
+            return false;
+        }
+    }
+

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
tboot-devel mailing list
tboot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tboot-devel

Reply via email to