diff options
author | Jean Delvare <jdelvare@suse.de> | 2018-11-16 11:18:25 +0100 |
---|---|---|
committer | Jean Delvare <jdelvare@suse.de> | 2018-11-16 11:18:25 +0100 |
commit | 82497fa02d60757c2cfa645cf89a79abb1435273 (patch) | |
tree | 96daaaf9a600e48ce38c94e2ebd85762df59b503 /util.c | |
parent | fde47bb227b8fa817c88d7e10a8eb771c46de1df (diff) | |
download | dmidecode-git-82497fa02d60757c2cfa645cf89a79abb1435273.tar.gz |
dmidecode: Don't use memcpy on /dev/mem on arm64
On arm64, calling memcpy on /dev/mem will cause a bus error if the
start and the end of the buffer are not aligned on a 64-bit boundary.
Using option --no-sysfs triggers this.
Use a slow manual byte-by-byte copy in that case, to prevent the bus
error. This is only a fallback path (at least on Linux) and not
performance-critical anyway, as it is a one-time operation and DMI
tables are usually not too large.
This fixes bug #55026:
https://savannah.nongnu.org/bugs/index.php?55026
Signed-off-by: Jean Delvare <jdelvare@suse.de>
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -155,6 +155,18 @@ out: return p; } +static void safe_memcpy(void *dest, const void *src, size_t n) +{ +#ifdef USE_SLOW_MEMCPY + size_t i; + + for (i = 0; i < n; i++) + *((u8 *)dest + i) = *((const u8 *)src + i); +#else + memcpy(dest, src, n); +#endif +} + /* * Copy a physical memory chunk into a memory buffer. * This function allocates memory. @@ -214,7 +226,7 @@ void *mem_chunk(off_t base, size_t len, const char *devmem) if (mmp == MAP_FAILED) goto try_read; - memcpy(p, (u8 *)mmp + mmoffset, len); + safe_memcpy(p, (u8 *)mmp + mmoffset, len); if (munmap(mmp, mmoffset + len) == -1) { |