Skip to contentSkip to conversation

x86: Declare the BIOS image as arrays of unknown size

PATCH New Mika Tammi 1 participant 1 message Oct 30 KVM

lore
Share & tools
lore

Mika Tammi

author
#0 lore raw

PATCH 1/1 x86: Declare the BIOS image as arrays of unknown size

bios-export.h declares bios_rom and bios_rom_end, the start and the end of the BIOS image in bios-rom.S, as zero-length arrays. To the compiler, bios_rom is then an object of size 0. fortify-headers, a _FORTIFY_SOURCE implementation for musl, checks the size of memcpy()'s source as well as its destination [1], so the memcpy() in setup_bios() that copies the image out of bios_rom traps, and lkvm on x86 built with musl and _FORTIFY_SOURCE, as nixpkgs builds it by default, dies at start:

Program received signal SIGILL, Illegal instruction. 0x00000000004010ac in setup_bios[cold] ()

Declare both as arrays of unknown size, like the kernel's section symbols such as _text[] and _etext[], so that the compiler assumes nothing about their size.

[1] fortify-headers 3.0.1, include/string.h, memcpy():

	if (__n > __bd || __n > __bs)
		__builtin_trap();
Assisted-by Claude:claude-opus-5-5

---
I used Claude Opus 5.5 to track down the cause, write this patch and its description, and run the tests below; I have reviewed the result.

Tested with nixpkgs' kvmtool package and its default hardening, which includes _FORTIFY_SOURCE: x86_64 lkvm with musl, dynamic and static, cross-compiled on x86_64 with "Makefile: Use correct nm binary when cross-compiling for x86_64", died with SIGILL as above and now boots an x86_64 guest under KVM. A native x86_64 lkvm with glibc, and builds for arm64, riscv32 and riscv64, are byte-identical with and without this patch; the glibc one still boots the guest.

 x86/include/kvm/bios-export.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
x86/include/kvm/bios-export.h +2 -2
index 23825aa..42fa4d2 100644
@@ -3,8 +3,8 @@
 
 struct kvm;
 
-extern char bios_rom[0];
-extern char bios_rom_end[0];
+extern char bios_rom[];
+extern char bios_rom_end[];
 
 #define bios_rom_size		(bios_rom_end - bios_rom)
 
Signature · 1 line
2.54.0 (Apple Git-157)