summaryrefslogtreecommitdiffstats
path: root/util/cbfstool/rmodule.c
diff options
context:
space:
mode:
authorPatrick Rudolph <patrick.rudolph@9elements.com>2021-06-11 21:24:10 +0200
committerPatrick Georgi <pgeorgi@google.com>2021-06-15 07:47:35 +0000
commitd023909b0112889941c1470cd125b1903572ba3b (patch)
tree4c92322f65ca5e672e3af98f9804d4f9d65d6c91 /util/cbfstool/rmodule.c
parent6ccb252918c8a076dcf0a122e3aac028b4e80d4e (diff)
downloadcoreboot-d023909b0112889941c1470cd125b1903572ba3b.tar.gz
coreboot-d023909b0112889941c1470cd125b1903572ba3b.tar.bz2
coreboot-d023909b0112889941c1470cd125b1903572ba3b.zip
treewide: Disable R_AMD64_32S relocation support
This fixes a hard to debug hang that could occur in any stage, but in the end it follows simple rules and is easy to fix. In long mode the 32bit displacement addressing used on 'mov' and 'lea' instructions is sign-extended. Those instructions can be found using readelf on the stage and searching for relocation type R_X86_64_32S. The sign extension is no issue when either running in protected mode or the code module and thus the address is below 2GiB. If the address is greater than 2GiB, as usually the case for code in TSEG, the higher address bits [64:32] are all set to 1 and the effective address is pointing to memory not paged. Accessing this memory will cause a page fault, which isn't handled either. To prevent such problems - disable R_AMD64_32S relocations in rmodtool - add comment explaining why it's not allowed - use the pseudo op movabs, which doesn't use 32bit displacement addressing - Print a useful error message if such a reloc is present in the code Fixes a crash in TSEG and when in long mode seen on Intel Sandybridge. Change-Id: Ia5f5a9cde7c325f67b12e3a8e9a76283cc3870a3 Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/55448 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
Diffstat (limited to 'util/cbfstool/rmodule.c')
-rw-r--r--util/cbfstool/rmodule.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/util/cbfstool/rmodule.c b/util/cbfstool/rmodule.c
index 4ac2951f72ca..ce005108edb8 100644
--- a/util/cbfstool/rmodule.c
+++ b/util/cbfstool/rmodule.c
@@ -38,10 +38,16 @@ static int valid_reloc_amd64(Elf64_Rela *rel)
type = ELF64_R_TYPE(rel->r_info);
- /* Only these 6 relocations are expected to be found. */
+ /*
+ * Relocation R_AMD64_32S is not allowed. It can only be safely used in protected mode,
+ * and when the address pointed to is below 2 GiB in long mode.
+ * Using it in assembly operations will break compilation with error:
+ * E: Invalid reloc type: 11
+ */
+
+ /* Only these 5 relocations are expected to be found. */
return (type == R_AMD64_64 ||
type == R_AMD64_PC64 ||
- type == R_AMD64_32S ||
type == R_AMD64_32 ||
type == R_AMD64_PC32 ||
/*
@@ -60,7 +66,6 @@ static int should_emit_amd64(Elf64_Rela *rel)
/* Only emit absolute relocations */
return (type == R_AMD64_64 ||
- type == R_AMD64_32S ||
type == R_AMD64_32);
}
@@ -182,6 +187,10 @@ static int for_each_reloc(struct rmod_context *ctx, struct reloc_filter *f,
if (!ctx->ops->valid_type(r)) {
ERROR("Invalid reloc type: %u\n",
(unsigned int)ELF64_R_TYPE(r->r_info));
+ if ((ctx->ops->arch == EM_X86_64) &&
+ (ELF64_R_TYPE(r->r_info) == R_AMD64_32S))
+ ERROR("Illegal use of 32bit sign extended addressing at offset 0x%x\n",
+ (unsigned int)r->r_offset);
return -1;
}