xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xen/efi: Avoid EFI stub using absolute symbols
@ 2017-12-21 14:55 Julien Grall
  2018-01-02 16:35 ` Jan Beulich
  0 siblings, 1 reply; 6+ messages in thread
From: Julien Grall @ 2017-12-21 14:55 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, wei.liu2, George.Dunlap, andrew.cooper3,
	Julien Grall, ian.jackson, andre.przywara, tim, jbeulich

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@linaro.org>

---

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@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-01-17  8:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-21 14:55 [PATCH] xen/efi: Avoid EFI stub using absolute symbols Julien Grall
2018-01-02 16:35 ` Jan Beulich
2018-01-09 19:43   ` Julien Grall
2018-01-12 13:13     ` Jan Beulich
2018-01-16 17:43       ` Julien Grall
2018-01-17  8:30         ` Jan Beulich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).