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