x86/boot: Improve MBI2 structure check (was: Reduce assembly code)
v10 cover x86/boot: Improve MBI2 structure check (was: Reduce assembly code)
This series came from part of the work of removing duplications between boot code and rewriting part of code from assembly to C.
Changes since v1, more details in specific commits:
- style updates;
- comments and descriptions improvements;
- other improvements.
Changes since v2:
- rebased on master, resolved conflicts;
- add comment on trampoline section.
Changes since v3:
- changed new function name;
- declare efi_multiboot2 in a separate header;
- distinguish entry point from using magic number;
- other minor changes (see commens in commits).
Changes since v4:
- rebase on staging;
- set %fs and %gs as other segment registers;
- style and other changes.
Changes since v5:
- fixed a typo.
Changes since v6:
- remove merged patch;
- comment and style;
- change some pointer checks to avoid overflows;
- rename parse-mbi2.c to mbi2.c.
Changes since v7:
- removed merged parts;
- add required stack alignment.
Changes since v8:
- added "Fixes:" line;
- typo in commit message: Adler -> Alder;
- add ".init" to mbi2.o;
- reduce difference in Makefile.
Changes since v9:
- minor messages updates.
Frediano Ziglio (2):
x86/boot: Align mbi2.c stack to 16 bytes
x86/boot: Improve MBI2 structure check
xen/arch/x86/efi/Makefile | 4 ++-- xen/arch/x86/efi/mbi2.c | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-)
Signature · 1 line
2.34.1
PATCH v10 1/2 x86/boot: Align mbi2.c stack to 16 bytes
Doing previous testing with an Alder Lake Intel machine with the "x86/boot: Improve MBI2 structure check" commit test started to fail. Removing the commit makes the tests succeed however there was not apparent reason (looking at the code) for the failure.
So I instrumented code to output the structure and tested code with this extracted data with and without the mentioned commit and results were the same.
Compiled assembly code from lab was also fine beside not keeping the 16-byte alignment for the stack.
Turning on stack alignment solve the problem on Alder Lake machine.
---
Changes since v8:
- added "Fixes:" line;
- typo in commit message: Adler -> Alder;
- add ".init" to mbi2.o;
- reduce difference.
Changes since v9:
- minor commit message fix;
- added Reviewed-by.
--- xen/arch/x86/efi/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/efi/Makefile +2 -2
@@ -9,11 +9,11 @@ $(obj)/%.o: $(src)/%.ihex FORCE $(obj)/boot.init.o: $(obj)/buildid.o $(call cc-option-add,cflags-stack-boundary,CC,-mpreferred-stack-boundary=4) -$(addprefix $(obj)/,$(EFIOBJ-y)): CFLAGS_stack_boundary := $(cflags-stack-boundary) +$(addprefix $(obj)/,$(EFIOBJ-y) mbi2.init.o): CFLAGS_stack_boundary := $(cflags-stack-boundary) obj-y := common-stub.o stub.o obj-$(XEN_BUILD_EFI) := $(filter-out %.init.o,$(EFIOBJ-y)) obj-bin-$(XEN_BUILD_EFI) := $(filter %.init.o,$(EFIOBJ-y)) -obj-bin-y += mbi2.o +obj-bin-y += mbi2.init.o extra-$(XEN_BUILD_EFI) += buildid.o relocs-dummy.o nocov-$(XEN_BUILD_EFI) += stub.o
Signature · 1 line
2.34.1
PATCH v10 2/2 x86/boot: Improve MBI2 structure check
In reply to Frediano ZiglioTag structure should contain at least the tag header. Entire tag structure must be contained inside MBI2 data.
---
Changes since v6:
- compare against total_size every time to avoid overflows.
Changes since v7:
- check for tag type being MULTIBOOT2_TAG_TYPE_END before checking tag size. This allows caller to not fill full tag (type field is before size field).
Changes since v9:
- fixed tag order.
--- xen/arch/x86/efi/mbi2.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
xen/arch/x86/efi/mbi2.c +5 -2
@@ -13,6 +13,7 @@ efi_multiboot2_prelude(uint32_t magic, const multiboot2_fixed_t *mbi)EFI_HANDLE ImageHandle =NULL ;EFI_SYSTEM_TABLE *SystemTable =NULL ;const char *cmdline =NULL ; +const void *const mbi_raw = (const void *)mbi;bool have_bs = false;if ( magic !=MULTIBOOT2_BOOTLOADER_MAGIC )
@@ -21,8 +22,10 @@ efi_multiboot2_prelude(uint32_t magic, const multiboot2_fixed_t *mbi)/* Skip Multiboot2 information fixed part. */ tag =_p (ROUNDUP ((unsigned long )(mbi +1 ),MULTIBOOT2_TAG_ALIGN )); -for ( ; (const void *)tag - (const void *)mbi < mbi->total_size && - tag->type !=MULTIBOOT2_TAG_TYPE_END ; +for ( ; (const void *)(tag +1 ) - mbi_raw <= mbi->total_size && + tag->type !=MULTIBOOT2_TAG_TYPE_END && + tag->size >=sizeof (*tag) && + (const void *)tag + tag->size - mbi_raw <= mbi->total_size; tag =_p (ROUNDUP ((unsigned long )tag + tag->size,MULTIBOOT2_TAG_ALIGN )) ) {
Signature · 1 line
2.34.1
Quoted 2 lines · Frediano Ziglio
This series came from part of the work of removing duplications between boot code and rewriting part of code from assembly to C.
Quoted 53 lines
Changes since v1, more details in specific commits:
- style updates;
- comments and descriptions improvements;
- other improvements.Changes since v2:
- rebased on master, resolved conflicts;
- add comment on trampoline section.Changes since v3:
- changed new function name;
- declareefi_multiboot2in a separate header;
- distinguish entry point from using magic number;
- other minor changes (see commens in commits).Changes since v4:
- rebase on staging;
- set %fs and %gs as other segment registers;
- style and other changes.Changes since v5:
- fixed a typo.Changes since v6:
- remove merged patch;
- comment and style;
- change some pointer checks to avoid overflows;
- renameparse-mbi2.ctombi2.c.Changes since v7:
- removed merged parts;
- add required stack alignment.Changes since v8:
- added "Fixes:" line;
- typo in commit message: Adler -> Alder;
- add ".init" to mbi2.o;
- reduce difference inMakefile.Changes since v9:
- minor messages updates.Frediano Ziglio (2):
x86/boot: Alignmbi2.cstack to 16 bytes
x86/boot: Improve MBI2 structure checkxen/arch/x86/efi/Makefile | 4 ++-- xen/arch/x86/efi/mbi2.c | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-)Signature · 1 line
2.34.1
Signature · 3 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab
Quoted 4 lines · Marek Marczykowski-Górecki
Quoted 2 lines · Frediano Ziglio
This series came from part of the work of removing duplications between boot code and rewriting part of code from assembly to C.
I've committed this series, but I've rewritten the commit message on patch 1.
As presented, that's a set of debugging notes of how the patch ended up the way it did, not an explanation of the problem and how it is being addressed.
~Andrew