Blame SOURCES/0002-dmidecode-Don-t-use-memcpy-on-dev-mem-on-arm64.patch

db7f50
From 82497fa02d60757c2cfa645cf89a79abb1435273 Mon Sep 17 00:00:00 2001
db7f50
From: Jean Delvare <jdelvare@suse.de>
db7f50
Date: Fri, 16 Nov 2018 11:18:25 +0100
db7f50
Subject: [PATCH 1/4] dmidecode: Don't use memcpy on /dev/mem on arm64
db7f50
db7f50
On arm64, calling memcpy on /dev/mem will cause a bus error if the
db7f50
start and the end of the buffer are not aligned on a 64-bit boundary.
db7f50
Using option --no-sysfs triggers this.
db7f50
db7f50
Use a slow manual byte-by-byte copy in that case, to prevent the bus
db7f50
error. This is only a fallback path (at least on Linux) and not
db7f50
performance-critical anyway, as it is a one-time operation and DMI
db7f50
tables are usually not too large.
db7f50
db7f50
This fixes bug #55026:
db7f50
https://savannah.nongnu.org/bugs/index.php?55026
db7f50
db7f50
Signed-off-by: Jean Delvare <jdelvare@suse.de>
db7f50
---
db7f50
 config.h |  5 +++++
db7f50
 util.c   | 14 +++++++++++++-
db7f50
 2 files changed, 18 insertions(+), 1 deletion(-)
db7f50
db7f50
diff --git a/config.h b/config.h
db7f50
index e39091f..4237355 100644
db7f50
--- a/config.h
db7f50
+++ b/config.h
db7f50
@@ -26,4 +26,9 @@
db7f50
 #define ALIGNMENT_WORKAROUND
db7f50
 #endif
db7f50
 
db7f50
+/* Avoid unaligned memcpy on /dev/mem */
db7f50
+#ifdef __aarch64__
db7f50
+#define USE_SLOW_MEMCPY
db7f50
+#endif
db7f50
+
db7f50
 #endif
db7f50
diff --git a/util.c b/util.c
db7f50
index eeffdae..04aaadd 100644
db7f50
--- a/util.c
db7f50
+++ b/util.c
db7f50
@@ -155,6 +155,18 @@ void *read_file(off_t base, size_t *max_len, const char *filename)
db7f50
 	return p;
db7f50
 }
db7f50
 
db7f50
+static void safe_memcpy(void *dest, const void *src, size_t n)
db7f50
+{
db7f50
+#ifdef USE_SLOW_MEMCPY
db7f50
+	size_t i;
db7f50
+
db7f50
+	for (i = 0; i < n; i++)
db7f50
+		*((u8 *)dest + i) = *((const u8 *)src + i);
db7f50
+#else
db7f50
+	memcpy(dest, src, n);
db7f50
+#endif
db7f50
+}
db7f50
+
db7f50
 /*
db7f50
  * Copy a physical memory chunk into a memory buffer.
db7f50
  * This function allocates memory.
db7f50
@@ -214,7 +226,7 @@ void *mem_chunk(off_t base, size_t len, const char *devmem)
db7f50
 	if (mmp == MAP_FAILED)
db7f50
 		goto try_read;
db7f50
 
db7f50
-	memcpy(p, (u8 *)mmp + mmoffset, len);
db7f50
+	safe_memcpy(p, (u8 *)mmp + mmoffset, len);
db7f50
 
db7f50
 	if (munmap(mmp, mmoffset + len) == -1)
db7f50
 	{
db7f50
-- 
db7f50
2.17.1
db7f50