summaryrefslogtreecommitdiff
path: root/Makefile.inc
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2016-03-07 17:55:43 -0800
committerMartin Roth <martinroth@google.com>2016-03-09 17:07:14 +0100
commitfffee873c86f88a8a4b92fd9d2e16dc3f6dc7133 (patch)
treebf53b2c51c68659965822a039246adb25f7c9baa /Makefile.inc
parent0819a47d14e8c933dab7089a41625f043778a4c7 (diff)
Makefile: Add build-time overlap check for programs loaded after coreboot
On non-x86 platforms, coreboot uses the memlayout.ld mechanism to statically allocate the different memory regions it needs and guarantees at build time that there are no dangerous overlaps between them. At the end of its (ramstage) execution, however, it usually loads a payload (and possibly other platform-specific components) that is not integrated into the coreboot build system and therefore cannot provide the same overlap guarantees through memlayout.ld. This creates a dangerous memory hazard where a new component could be loaded over memory areas that are still in use by the code-loading ramstage and lead to arbitrary memory corruption bugs. This patch fills this gap in our build-time correctness guarantees by adding the necessary checks as a new intermediate Makefile target on route to assembling the final image. It will parse the memory footprint information of the payload (and other platform-specific post-ramstage components) from CBFS and compare it to a list of memory areas known to be still in use during late ramstage, generating a build failure in case of a possible hazard. BUG=chrome-os-partner:48008 TEST=Built Oak while moving critical regions in the way of BL31 or the payload, observing the desired build-time errors. Built Nyan, Jerry and Falco without issues for good measure. Change-Id: I3ebd2c1caa4df959421265e26f9cab2c54909b68 Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://review.coreboot.org/13949 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Diffstat (limited to 'Makefile.inc')
-rw-r--r--Makefile.inc46
1 files changed, 46 insertions, 0 deletions
diff --git a/Makefile.inc b/Makefile.inc
index 5f4725d5e6..a07f92a800 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -846,6 +846,52 @@ board_id-type := raw
$(obj)/board_id:
printf $(CONFIG_BOARD_ID_STRING) > $@
+# Ensure that no payload segment overlaps with memory regions used by ramstage
+# (not for x86 since it can relocate itself in that case)
+ifneq ($(CONFIG_ARCH_X86),y)
+check-ramstage-overlap-regions := ramstage
+check-ramstage-overlap-files :=
+ifneq ($(CONFIG_PAYLOAD_NONE),y)
+check-ramstage-overlap-files += $(CONFIG_CBFS_PREFIX)/payload
+endif
+
+# will output one or more lines of "<load address in hex> <memlen in decimal>"
+cbfs-get-segments-cmd = $(CBFSTOOL) $(obj)/coreboot.pre print -v | sed -n \
+ '\%$(1)%,\%^[^ ]\{4\}%s% .*load: \(0x[0-9a-fA-F]*\),.*length: [0-9]*/\([0-9]*\).*%\1 \2%p'
+
+ramstage-symbol-addr-cmd = $(OBJDUMP_ramstage) -t $(objcbfs)/ramstage.elf | \
+ sed -n '/ $(1)$$/s/^\([0-9a-fA-F]*\) .*/0x\1/p'
+
+check-ramstage-overlaps: $(obj)/coreboot.pre
+ programs=$$($(foreach file,$(check-ramstage-overlap-files), \
+ $(call cbfs-get-segments-cmd,$(file)) ; )) ; \
+ regions=$$($(foreach region,$(check-ramstage-overlap-regions), \
+ echo $(region) ; \
+ $(call ramstage-symbol-addr-cmd,_$(region)) ; \
+ $(call ramstage-symbol-addr-cmd,_e$(region)) ; )) ; \
+ pstart= ; pend= ; \
+ for x in $$programs; do \
+ if [ -z $$pstart ]; then pstart=$$(($$x)) ; continue ; fi ; \
+ pend=$$(($$pstart + $$x)) ; \
+ rname= ; rstart= ; rend= ; \
+ for y in $$regions ; do \
+ if [ -z $$rname ]; then rname=$$y ; continue ; fi ; \
+ if [ -z $$rstart ]; then rstart=$$(($$y)) ; continue ; fi ; \
+ rend=$$(($$y)) ; \
+ if [ $$pstart -lt $$rend -a $$rstart -lt $$pend ]; then \
+ echo "ERROR: Ramstage region _$$rname overlapped by:" \
+ $(check-ramstage-overlap-files) ; \
+ exit 1 ; \
+ fi ; \
+ rname= ; rstart= ; rend= ; \
+ done ; \
+ pstart= ; pend= ; \
+ done
+
+INTERMEDIATE+=check-ramstage-overlaps
+PHONY+=check-ramstage-overlaps
+endif
+
junit.xml:
echo "Building $(UTIL)"
echo '<?xml version="1.0" encoding="utf-8"?><testsuite>' > $@.tmp