From ae096be00c3ada5acc6dfd601a1ad2bb36e234db Mon Sep 17 00:00:00 2001 From: Julius Werner Date: Fri, 21 Aug 2020 15:20:02 -0700 Subject: [PATCH] libpayload: memmove: Don't make expectations of architecture memcpy default_memmove() calls memcpy() when (src > dst). This is safe for the default_memcpy() implementation, but just calling memcpy() may invoke an architecture-specific implementation. Architectures are free to implement memcpy() however they want and may assume that buffers don't overlap in either direction. So while this happens to work for all current architecture implementations of memcpy(), it's safer not to rely on that and only rely on the known implementation of default_memcpy() for the forwards-overlapping case. Signed-off-by: Julius Werner Change-Id: I7ece4ce9e6622a36612bfade3deb62f351877789 Reviewed-on: https://review.coreboot.org/c/coreboot/+/44691 Reviewed-by: Aaron Durbin Tested-by: build bot (Jenkins) --- payloads/libpayload/libc/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/payloads/libpayload/libc/memory.c b/payloads/libpayload/libc/memory.c index daa53f1bcb..cc33eab686 100644 --- a/payloads/libpayload/libc/memory.c +++ b/payloads/libpayload/libc/memory.c @@ -90,7 +90,7 @@ static void *default_memmove(void *dst, const void *src, size_t n) ssize_t i; if (src > dst) - return memcpy(dst, src, n); + return default_memcpy(dst, src, n); if (!IS_ALIGNED((uintptr_t)dst, sizeof(unsigned long)) || !IS_ALIGNED((uintptr_t)src, sizeof(unsigned long))) {