From 05e0daa411a00b5b261045063d364e5d1623bddc Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Thu, 4 Aug 2022 13:58:58 +0000 Subject: [PATCH] arch: fix end of table entry in smbios Previously the code used the SmbiosSysInfo structure for that purpose. Handle 0x0003, DMI type 127, 27 bytes Wrong DMI structures length: 130 bytes announced, structures occupy 131 bytes. Fix this by using the correct structure and padding. Signed-off-by: Wei Liu --- arch/src/x86_64/smbios.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/arch/src/x86_64/smbios.rs b/arch/src/x86_64/smbios.rs index 0924e4522..3104658ec 100644 --- a/arch/src/x86_64/smbios.rs +++ b/arch/src/x86_64/smbios.rs @@ -125,10 +125,20 @@ pub struct SmbiosSysInfo { pub family: u8, } +#[repr(C)] +#[repr(packed)] +#[derive(Default, Copy, Clone)] +pub struct SmbiosEndOfTable { + pub typ: u8, + pub length: u8, + pub handle: u16, +} + // SAFETY: These data structures only contain a series of integers unsafe impl ByteValued for Smbios30Entrypoint {} unsafe impl ByteValued for SmbiosBiosInfo {} unsafe impl ByteValued for SmbiosSysInfo {} +unsafe impl ByteValued for SmbiosEndOfTable {} fn write_and_incr( mem: &GuestMemoryMmap, @@ -212,13 +222,13 @@ pub fn setup_smbios( { handle += 1; - let smbios_sysinfo = SmbiosSysInfo { + let smbios_end = SmbiosEndOfTable { typ: END_OF_TABLE, - length: mem::size_of::() as u8, + length: mem::size_of::() as u8, handle, - ..Default::default() }; - curptr = write_and_incr(mem, smbios_sysinfo, curptr)?; + curptr = write_and_incr(mem, smbios_end, curptr)?; + curptr = write_and_incr(mem, 0u8, curptr)?; curptr = write_and_incr(mem, 0u8, curptr)?; }