From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-x229.google.com (mail-wm0-x229.google.com [IPv6:2a00:1450:400c:c09::229]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D9C2B1A1E26 for ; Tue, 13 Sep 2016 07:18:04 -0700 (PDT) Received: by mail-wm0-x229.google.com with SMTP id 1so204025360wmz.1 for ; Tue, 13 Sep 2016 07:18:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=Nvnv077NFl4gGEQL1rIBljf6PWLMSzmwacygcFlU6Wk=; b=S9Z15fVW3g8AvxZUnjja6armLlJ3wepg0QZtSCQWXwF8NcCHv7fIJqe+tULrEyx9p+ 1dO0FnoBfdwYsv7WofAiUFFjLno6Pp3+10a5cL0GwtaUED/uLOwNWomGY0y8cxELVhc/ FeNaN7ZOVY+yIMjH27ZKdcUh5iAsCNRgYLAZ8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Nvnv077NFl4gGEQL1rIBljf6PWLMSzmwacygcFlU6Wk=; b=c15y41ee4nKqzUJeCRm/dgFEQknRGK9N0a1l953Foeef+GvuoGCsHC2uKZ0Tw0H8QC GxNyiqINj/js2Bon8b2/9oxmr5Wc2whQyNSXFxDob0btgmBDsx6DotrblTywciOMYOik MzRMDsLvcb55NO5YCoNqXGXowdCtqNfJQcDGTKgGdA0Wq4yGxyva1VCuXFktjJbNr+Qg YDzY03QXLpeAIq/r0UzMkwTPmcN4MRw3R0ET5pQJlReJPOhNl9SuA+OZdfptoct3DaL0 Jsc1k+9hARp0vc1u7xS0SfipI7jeNB3vsa4q+65TtVj4+oS6fmiTG4RhwiHMawXA2bCo T5XA== X-Gm-Message-State: AE9vXwMSq1JKdfdg09FbP0dNoU72TuiC8cWuEN1zEUT9FTPS+dIO8UflJgqUCUWR50EPphRJ X-Received: by 10.28.156.144 with SMTP id f138mr5818218wme.86.1473776282868; Tue, 13 Sep 2016 07:18:02 -0700 (PDT) Received: from localhost.localdomain ([197.128.106.42]) by smtp.gmail.com with ESMTPSA id s6sm23192965wjm.25.2016.09.13.07.18.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Sep 2016 07:18:02 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, lersek@redhat.com Cc: julien.grall@arm.com, Ard Biesheuvel Date: Tue, 13 Sep 2016 15:17:48 +0100 Message-Id: <1473776268-18207-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [PATCH] ArmVirtPkg/FdtParser: avoid unaligned accesses with the MMU off X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Sep 2016 14:18:05 -0000 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 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/FdtParser.c | 14 ++++++-------- 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 46a5fe6409f6..afdc81a8839d 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 992932ee9754..38fd5d3ed00c 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; -- 2.7.4