[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] xen/efi: Avoid EFI stub using absolute symbols



The EFI image should be relocatable. At the moment, all the stub is
relocatable but one place.

On both Arm64 and x86-64 (from a quick glance) , the compiler will generate
absolute pointer in the ErrCodeToStr array. Those values are based on Xen
view of the virtual memory and may not be the same as EFI.

For instance, at least on Arm64, EFI will do a 1:1 mappings of the Stub.

Arguably this is either a compiler bug or a problem with the flags
passed. I narrow down the problem to the following snippet:

const char * const ErrCodeToStr[] = {
    "Not found",
    "The device has no media",
};

const char * foo(unsigned int i)
{
    return ErrCodeToStr[i];
}

To prevent the compiler using absolute pointer, specify the maximum size
of the string.

Signed-off-by: Julien Grall <julien.grall@xxxxxxxxxx>

---

I am not entirely convinced this is the right way. But I though I would
start a conversation to get feedback.
---
 xen/common/efi/boot.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
index 469bf980cc..87d46f2a56 100644
--- a/xen/common/efi/boot.c
+++ b/xen/common/efi/boot.c
@@ -342,7 +342,7 @@ static void __init noreturn blexit(const CHAR16 *str)
 /* generic routine for printing error messages */
 static void __init PrintErrMesg(const CHAR16 *mesg, EFI_STATUS ErrCode)
 {
-    static const CHAR16* const ErrCodeToStr[] __initconstrel = {
+    static const CHAR16 ErrCodeToStr[][25] __initconst  = {
         [~EFI_ERROR_MASK & EFI_NOT_FOUND]           = L"Not found",
         [~EFI_ERROR_MASK & EFI_NO_MEDIA]            = L"The device has no 
media",
         [~EFI_ERROR_MASK & EFI_MEDIA_CHANGED]       = L"Media changed",
-- 
2.11.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.