Skip to contentSkip to conversation

x86/setup: disallow any src/dst overlaps when relocating Xen image

PATCH Superseded Daniel Kiper 2 participants 3 messages Apr 3, 2018 – Apr 16, 2018 1 message not in the archive

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 x86/setup: disallow any src/dst overlaps when relocating Xen image

Commit 0d31d16 (x86/setup: do not relocate Xen over current Xen image placement) disallowed src/dst images overlaps when relocating Xen image. Though it deliberately allowed destination region between __image_base__ and (__image_base__ + XEN_IMG_OFFSET) overlaps with the end of source image. And here is the problem. If anything between __page_tables_start and __page_tables_end in source image lands in the overlap then some or even all page table entries may not be updated. This usually means boom in early boot which will be difficult to the investigate. So, I think that we have three choices to fix the issue:
- drop XEN_IMG_OFFSET from

    if ( (end > s) && (end - reloc_size + XEN_IMG_OFFSET >= __pa(_end)) )

- add XEN_IMG_OFFSET to xen_phys_start in PFN_DOWN(xen_phys_start) used in loops as one of conditions,
- change PFN_DOWN(xen_phys_start) to PFN_DOWN(xen_remap_end_pfn) proposed in earlier version of this patch.

This patch implements the first option. This way we will avoid all kinds of overlaps which are always full can of worms.

---
 xen/arch/x86/setup.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/setup.c +1 -1
index c0b97a7..b3a66f4 100644
@@ -1003,7 +1003,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
          * Is the region size greater than zero and does it begin
          * at or above the end of current Xen image placement?
          */
-        if ( (end > s) && (end - reloc_size + XEN_IMG_OFFSET >= __pa(_end)) )
+        if ( (end > s) && (end - reloc_size >= __pa(_end)) )
         {
             l4_pgentry_t *pl4e;
             l3_pgentry_t *pl3e;
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 11.04.18 at 10:54, <[email protected]> wrote:
Quoted 16 lines · Daniel Kiper

Commit 0d31d16 (x86/setup: do not relocate Xen over current Xen image placement) disallowed src/dst images overlaps when relocating Xen image. Though it deliberately allowed destination region between __image_base__ and (__image_base__ + XEN_IMG_OFFSET) overlaps with the end of source image. And here is the problem. If anything between __page_tables_start and __page_tables_end in source image lands in the overlap then some or even all page table entries may not be updated. This usually means boom in early boot which will be difficult to the investigate. So, I think that we have three choices to fix the issue:
- drop XEN_IMG_OFFSET from

    if ( (end > s) && (end - reloc_size + XEN_IMG_OFFSET >= __pa(_end)) )

- add XEN_IMG_OFFSET to xen_phys_start in PFN_DOWN(xen_phys_start) used in loops as one of conditions,
- change PFN_DOWN(xen_phys_start) to PFN_DOWN(xen_remap_end_pfn) proposed in earlier version of this patch.

Quoted 6 lines
Quoted 4 lines

This patch implements the first option. This way we will avoid all kinds of overlaps which are always full can of worms.

Ping?

I'll get to it, but it has missed 4.11 anyway, so I don't think there's an urgency here.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
In reply to Daniel Kiper
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 03.04.18 at 17:54, <[email protected]> wrote:

Commit 0d31d16 (x86/setup: do not relocate Xen over current Xen image placement) disallowed src/dst images overlaps when relocating Xen image. Though it deliberately allowed destination region between __image_base__ and (__image_base__ + XEN_IMG_OFFSET) overlaps with the end of source image. And here is the problem. If anything between __page_tables_start and __page_tables_end in source image lands in the overlap then some or even all page table entries may not be updated. This usually means boom in early boot which will be difficult to the investigate. So, I think that we have three choices to fix the issue:
- drop XEN_IMG_OFFSET from

Quoted 8 lines
    if ( (end > s) && (end - reloc_size + XEN_IMG_OFFSET >= __pa(_end)) )

- add XEN_IMG_OFFSET to xen_phys_start in PFN_DOWN(xen_phys_start) used in loops as one of conditions,
- change PFN_DOWN(xen_phys_start) to PFN_DOWN(xen_remap_end_pfn) proposed in earlier version of this patch.

This patch implements the first option. This way we will avoid all kinds of overlaps which are always full can of worms.

Personally I'd like option 2 better, as there's nothing of interest in the [0,XEN_IMG_OFFSET) range. Instead of modifying every PFN_DOWN(xen_phys_start), perhaps simply introduce a local variable, accompanied by a suitable comment.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel