[coreboot-gerrit] Patch set updated for coreboot: cbfs: don't load x86 programs over the top of read-only media

Aaron Durbin (adurbin@chromium.org) gerrit at coreboot.org
Fri Oct 9 21:57:26 CET 2015


Aaron Durbin (adurbin at chromium.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/11823

-gerrit

commit 99f71a6258567641832071a1288b6a727a14da6d
Author: Aaron Durbin <adurbin at chromium.org>
Date:   Wed Oct 7 17:22:42 2015 -0500

    cbfs: don't load x86 programs over the top of read-only media
    
    On x86 the early stages are currently execute-in-place which
    means they live in the memory-mapped spi flash. However, when
    loading romstage from verstage the romstage is
    execute-in-place so it's unnecessary to write over a read-only
    meida -- not to mention writing to read-only memory is wrong
    to begin with.
    
    BUG=chrome-os-partner:44827
    BRANCH=None
    TEST=Built and booted glados. Noted reduction of 20ms when
         loading romstage.
    
    Change-Id: I7cd399302a3925a05fbce82600b4c50ea66a0fcb
    Signed-off-by: Aaron Durbin <adurbin at chromium.org>
---
 src/lib/cbfs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c
index 05b939c..9cdc365 100644
--- a/src/lib/cbfs.c
+++ b/src/lib/cbfs.c
@@ -220,6 +220,16 @@ int cbfs_prog_stage_load(struct prog *pstage)
 	load = (void *)(uintptr_t)stage.load;
 	entry = (void *)(uintptr_t)stage.entry;
 
+	/* Hacky way to not load programs over read only media. The stages
+	 * that would hit this path initialize themselves. */
+	if (ENV_VERSTAGE && IS_ENABLED(CONFIG_ARCH_X86) &&
+	    IS_ENABLED(CONFIG_SPI_FLASH_MEMORY_MAPPED)) {
+		void *mapping = rdev_mmap(fh, foffset, fsize);
+		rdev_munmap(fh, mapping);
+		if (mapping == load)
+			goto out;
+	}
+
 	if (stage.compression == CBFS_COMPRESS_NONE) {
 		if (rdev_readat(fh, load, foffset, fsize) != fsize)
 			return -1;
@@ -242,6 +252,8 @@ int cbfs_prog_stage_load(struct prog *pstage)
 	memset(&load[fsize], 0, stage.memlen - fsize);
 
 	arch_segment_loaded((uintptr_t)load, stage.memlen, SEG_FINAL);
+
+out:
 	prog_set_area(pstage, load, stage.memlen);
 	prog_set_entry(pstage, entry, NULL);
 



More information about the coreboot-gerrit mailing list