diff options
author | Ard Biesheuvel <ard.biesheuvel@linaro.org> | 2016-09-13 15:13:31 +0100 |
---|---|---|
committer | Ard Biesheuvel <ard.biesheuvel@linaro.org> | 2016-09-13 15:35:36 +0100 |
commit | 94a3845be698ddeed9d126363c755bd3bb13dd17 (patch) | |
tree | f139d9214a4819384b29af663bca9a787f7fa79a | |
parent | dd82465a9f0f0beff0e4d74c6e3192b966853332 (diff) | |
download | edk2-94a3845be698ddeed9d126363c755bd3bb13dd17.tar.gz edk2-94a3845be698ddeed9d126363c755bd3bb13dd17.tar.bz2 edk2-94a3845be698ddeed9d126363c755bd3bb13dd17.zip |
ArmVirtPkg/FdtParser: avoid unaligned accesses with the MMU off
When parsing the device tree to find the memory node, we are still running
with the MMU off, which means unaligned memory accesses are not allowed.
Since the FDT only mandates 32-bit alignment, 64-bit quantities are not
guaranteed to appear naturally aligned, and so should be accessed using
32-bit accesses instead.
Reported-by: Julien Grall <julien.grall@arm.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
-rw-r--r-- | ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/FdtParser.c | 14 | ||||
-rw-r--r-- | ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/FdtParser.c | 14 |
2 files changed, 12 insertions, 16 deletions
diff --git a/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/FdtParser.c b/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/FdtParser.c index 46a5fe6409..afdc81a883 100644 --- a/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/FdtParser.c +++ b/ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/FdtParser.c @@ -65,17 +65,15 @@ FindMemnode ( return FALSE;
}
- if (AddressCells == 1) {
- *SystemMemoryBase = fdt32_to_cpu (*Prop);
- } else {
- *SystemMemoryBase = fdt64_to_cpu (*(UINT64 *)Prop);
+ *SystemMemoryBase = fdt32_to_cpu (Prop[0]);
+ if (AddressCells > 1) {
+ *SystemMemoryBase = (*SystemMemoryBase << 32) | fdt32_to_cpu (Prop[1]);
}
Prop += AddressCells;
- if (SizeCells == 1) {
- *SystemMemorySize = fdt32_to_cpu (*Prop);
- } else {
- *SystemMemorySize = fdt64_to_cpu (*(UINT64 *)Prop);
+ *SystemMemorySize = fdt32_to_cpu (Prop[0]);
+ if (SizeCells > 1) {
+ *SystemMemorySize = (*SystemMemorySize << 32) | fdt32_to_cpu (Prop[1]);
}
return TRUE;
diff --git a/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/FdtParser.c b/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/FdtParser.c index 992932ee97..38fd5d3ed0 100644 --- a/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/FdtParser.c +++ b/ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/FdtParser.c @@ -65,17 +65,15 @@ FindMemnode ( return FALSE;
}
- if (AddressCells == 1) {
- *SystemMemoryBase = fdt32_to_cpu (*Prop);
- } else {
- *SystemMemoryBase = fdt64_to_cpu (*(UINT64 *)Prop);
+ *SystemMemoryBase = fdt32_to_cpu (Prop[0]);
+ if (AddressCells > 1) {
+ *SystemMemoryBase = (*SystemMemoryBase << 32) | fdt32_to_cpu (Prop[1]);
}
Prop += AddressCells;
- if (SizeCells == 1) {
- *SystemMemorySize = fdt32_to_cpu (*Prop);
- } else {
- *SystemMemorySize = fdt64_to_cpu (*(UINT64 *)Prop);
+ *SystemMemorySize = fdt32_to_cpu (Prop[0]);
+ if (SizeCells > 1) {
+ *SystemMemorySize = (*SystemMemorySize << 32) | fdt32_to_cpu (Prop[1]);
}
return TRUE;
|