arch/x86: Fix undefined behavior
Fixes report found by undefined behavior sanitizer. Dereferencing a pointer that is not aligned to the size of access is undefined behavior. Switch to memcpy() for unaligned write to EBDA_LOWMEM. Change other write16()s in setup_ebda() to memcpy() for consistency. Change-Id: I79814bd47a14ec59d84068b11d094dc2531995d9 Signed-off-by: Ryan Salsamendi <rsalsamendi@hotmail.com> Reviewed-on: https://review.coreboot.org/20132 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org> Reviewed-by: Philippe Mathieu-Daudé <philippe.mathieu.daude@gmail.com>
This commit is contained in:
parent
cde2bdf496
commit
f0b0712023
|
@ -22,6 +22,10 @@
|
||||||
|
|
||||||
void setup_ebda(u32 low_memory_size, u16 ebda_segment, u16 ebda_size)
|
void setup_ebda(u32 low_memory_size, u16 ebda_segment, u16 ebda_size)
|
||||||
{
|
{
|
||||||
|
u16 low_memory_kb;
|
||||||
|
u16 ebda_kb;
|
||||||
|
void *ebda;
|
||||||
|
|
||||||
/* Skip in S3 resume path */
|
/* Skip in S3 resume path */
|
||||||
if (acpi_is_wakeup_s3())
|
if (acpi_is_wakeup_s3())
|
||||||
return;
|
return;
|
||||||
|
@ -29,15 +33,20 @@ void setup_ebda(u32 low_memory_size, u16 ebda_segment, u16 ebda_size)
|
||||||
if (!low_memory_size || !ebda_segment || !ebda_size)
|
if (!low_memory_size || !ebda_segment || !ebda_size)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* clear BIOS DATA AREA */
|
low_memory_kb = low_memory_size >> 10;
|
||||||
memset((void *)X86_BDA_BASE, 0, X86_BDA_SIZE);
|
ebda_kb = ebda_size >> 10;
|
||||||
|
ebda = (void *)((uintptr_t)ebda_segment << 4);
|
||||||
|
|
||||||
write16(X86_EBDA_LOWMEM, (low_memory_size >> 10));
|
/* clear BIOS DATA AREA */
|
||||||
write16(X86_EBDA_SEGMENT, ebda_segment);
|
memset(X86_BDA_BASE, 0, X86_BDA_SIZE);
|
||||||
|
|
||||||
|
/* Avoid unaligned write16() since it's undefined behavior */
|
||||||
|
memcpy(X86_EBDA_LOWMEM, &low_memory_kb, sizeof(low_memory_kb));
|
||||||
|
memcpy(X86_EBDA_SEGMENT, &ebda_segment, sizeof(ebda_segment));
|
||||||
|
|
||||||
/* Set up EBDA */
|
/* Set up EBDA */
|
||||||
memset((void *)((uintptr_t)ebda_segment << 4), 0, ebda_size);
|
memset(ebda, 0, ebda_size);
|
||||||
write16((void *)((uintptr_t)ebda_segment << 4), (ebda_size >> 10));
|
memcpy(ebda, &ebda_kb, sizeof(ebda_kb));
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup_default_ebda(void)
|
void setup_default_ebda(void)
|
||||||
|
|
Loading…
Reference in New Issue