[coreboot-gerrit] New patch to review for coreboot: 977e444 cbfs: Fix overwalk on file scan

Isaac Christensen (isaac.christensen@se-eng.com) gerrit at coreboot.org
Fri Aug 8 23:12:59 CEST 2014


Isaac Christensen (isaac.christensen at se-eng.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/6539

-gerrit

commit 977e4449acb7bb000ae11a736b70423f8100f586
Author: Steven Sherk <steven.sherk at se-eng.com>
Date:   Wed Aug 14 14:55:57 2013 -0600

    cbfs: Fix overwalk on file scan
    
    A bootblock overwalk was occuring when deriving the actual
    length, the bootblock size was not taken into account and bootblock
    size was not aligned.
    
    Resolved merge conflict.
    
    Change-Id: I7eb42f8deaaf223dcf07b37bb7dde4643acd508f
    Signed-off-by: Steven Sherk <steven.sherk at se-eng.com>
    Reviewed-on: https://gerrit.chromium.org/gerrit/65989
    Reviewed-by: Aaron Durbin <adurbin at chromium.org>
    Commit-Queue: Steve Sherk <ssherk70 at gmail.com>
    Tested-by: Steve Sherk <ssherk70 at gmail.com>
    (cherry picked from commit 20b0ba479b01755fbdc7f3dd9214e8af923402ba)
    Signed-off-by: Isaac Christensen <isaac.christensen at se-eng.com>
---
 payloads/libpayload/libcbfs/cbfs_core.c | 15 +++++++++++++--
 src/lib/cbfs_core.c                     | 15 +++++++++++++--
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/payloads/libpayload/libcbfs/cbfs_core.c b/payloads/libpayload/libcbfs/cbfs_core.c
index a3d3e02..fb15744 100644
--- a/payloads/libpayload/libcbfs/cbfs_core.c
+++ b/payloads/libpayload/libcbfs/cbfs_core.c
@@ -119,11 +119,22 @@ struct cbfs_file *cbfs_get_file(struct cbfs_media *media, const char *name)
 	// TODO Add a "size" in CBFS header for a platform independent way to
 	// determine the end of CBFS data.
 #if defined(CONFIG_LP_ARCH_X86) && CONFIG_LP_ARCH_X86
-	romsize -= htonl(header->bootblocksize);
+	// resolve actual length of ROM used for CBFS components
+	// the bootblock size was not taken into account
+	romsize -= ntohl(header->bootblocksize);
+
+	// fine tune the length to handle alignment positioning.
+	// using (bootblock size) % align, to derive the
+	// number of bytes the bootblock is off from the alignment size.
+	if ((ntohl(header->bootblocksize) % align))
+		romsize -= (align - (ntohl(header->bootblocksize) % align));
+	else
+		romsize -= 1;
 #endif
-	DEBUG("CBFS location: 0x%x~0x%x, align: %d\n", offset, romsize, align);
 
+	DEBUG("CBFS location: 0x%x~0x%x, align: %d\n", offset, romsize, align);
 	DEBUG("Looking for '%s' starting from 0x%x.\n", name, offset);
+
 	media->open(media);
 	while (offset < romsize &&
 	       media->read(media, &file, offset, sizeof(file)) == sizeof(file)) {
diff --git a/src/lib/cbfs_core.c b/src/lib/cbfs_core.c
index 7ef103b..264d9a8 100644
--- a/src/lib/cbfs_core.c
+++ b/src/lib/cbfs_core.c
@@ -119,11 +119,22 @@ struct cbfs_file *cbfs_get_file(struct cbfs_media *media, const char *name)
 	// TODO Add a "size" in CBFS header for a platform independent way to
 	// determine the end of CBFS data.
 #if defined(CONFIG_ARCH_X86) && CONFIG_ARCH_X86
-	romsize -= htonl(header->bootblocksize);
+	// resolve actual length of ROM used for CBFS components
+	// the bootblock size was not taken into account
+	romsize -= ntohl(header->bootblocksize);
+
+	// fine tune the length to handle alignment positioning.
+	// using (bootblock size) % align, to derive the
+	// number of bytes the bootblock is off from the alignment size.
+	if ((ntohl(header->bootblocksize) % align))
+		romsize -= (align - (ntohl(header->bootblocksize) % align));
+	else
+		romsize -= 1;
 #endif
-	DEBUG("CBFS location: 0x%x~0x%x, align: %d\n", offset, romsize, align);
 
+	DEBUG("CBFS location: 0x%x~0x%x, align: %d\n", offset, romsize, align);
 	DEBUG("Looking for '%s' starting from 0x%x.\n", name, offset);
+
 	media->open(media);
 	while (offset < romsize &&
 	       media->read(media, &file, offset, sizeof(file)) == sizeof(file)) {



More information about the coreboot-gerrit mailing list