From patchwork Fri Feb 21 20:08:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Anastasio X-Patchwork-Id: 13986232 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2BA4AC021B3 for ; Fri, 21 Feb 2025 20:09:06 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.894564.1303279 (Exim 4.92) (envelope-from ) id 1tlZKI-00049r-4U; Fri, 21 Feb 2025 20:08:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 894564.1303279; Fri, 21 Feb 2025 20:08:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tlZKI-00049k-15; Fri, 21 Feb 2025 20:08:46 +0000 Received: by outflank-mailman (input) for mailman id 894564; Fri, 21 Feb 2025 20:08:44 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tlZKG-00049Y-OU for xen-devel@lists.xenproject.org; Fri, 21 Feb 2025 20:08:44 +0000 Received: from raptorengineering.com (mail.raptorengineering.com [23.155.224.40]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a5d78a40-f08f-11ef-9aa9-95dc52dad729; Fri, 21 Feb 2025 21:08:43 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail.rptsys.com (Postfix) with ESMTP id A4B258287311; Fri, 21 Feb 2025 14:08:42 -0600 (CST) Received: from mail.rptsys.com ([127.0.0.1]) by localhost (vali.starlink.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id IoAusBhSdU3V; Fri, 21 Feb 2025 14:08:42 -0600 (CST) Received: from localhost (localhost [127.0.0.1]) by mail.rptsys.com (Postfix) with ESMTP id 06C2E8286E9D; Fri, 21 Feb 2025 14:08:42 -0600 (CST) Received: from mail.rptsys.com ([127.0.0.1]) by localhost (vali.starlink.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 1xvBLXcQI7-X; Fri, 21 Feb 2025 14:08:41 -0600 (CST) Received: from raptor-ewks-026.2lan (5.edge.rptsys.com [23.155.224.38]) by mail.rptsys.com (Postfix) with ESMTPSA id 14A2D8287FBD; Fri, 21 Feb 2025 14:08:40 -0600 (CST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a5d78a40-f08f-11ef-9aa9-95dc52dad729 DKIM-Filter: OpenDKIM Filter v2.10.3 mail.rptsys.com 06C2E8286E9D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raptorengineering.com; s=B8E824E6-0BE2-11E6-931D-288C65937AAD; t=1740168522; bh=wn8lAIb9qnZLpvYqwlQ9gH9RYtSwITlSk1VLzVXXQWE=; h=From:To:Date:Message-Id:MIME-Version; b=E4u8YjjEFSWsgg/qa7TT05uHV5Xtiyuq54A/qovGAWQfr/hDl4tlPKVyD8cwpFhRv aD8faB4NTfq9JOH5kNkjgy60FFiL3SRxM6wQR8gRvwnNNdGp9eW4rjCYBNC2E4d6UC JG6VdPkjKGjaVKTccD+A0MnaH/ti+vqrc4Hh8t5I= X-Virus-Scanned: amavisd-new at rptsys.com From: Shawn Anastasio To: xen-devel@lists.xenproject.org Cc: tpearson@raptorengineering.com, Andrew Cooper , Shawn Anastasio Subject: [PATCH 1/2] xen/ppc: Fix opal.c's misaligned DT reads to avoid tripping UBSAN Date: Fri, 21 Feb 2025 14:08:36 -0600 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Fix two misaligned reads from the FDT in the opal setup code to avoid tripping UBSAN failures. Without this change, UBSAN-enabled builds on PPC will fail on boot before the serial console is even initialized. Reported-by: Andrew Cooper Signed-off-by: Shawn Anastasio --- xen/arch/ppc/opal.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/xen/arch/ppc/opal.c b/xen/arch/ppc/opal.c index 1183b7d5ef..3d0e4daf27 100644 --- a/xen/arch/ppc/opal.c +++ b/xen/arch/ppc/opal.c @@ -34,8 +34,9 @@ static void opal_putchar(char c) void __init boot_opal_init(const void *fdt) { int opal_node; - const __be64 *opal_base; - const __be64 *opal_entry; + const __be64 *opal_base_p; + const __be64 *opal_entry_p; + __be64 opal_base, opal_entry; if ( fdt_check_header(fdt) < 0 ) { @@ -54,17 +55,20 @@ void __init boot_opal_init(const void *fdt) die(); } - opal_base = fdt_getprop(fdt, opal_node, "opal-base-address", NULL); - opal_entry = fdt_getprop(fdt, opal_node, "opal-entry-address", NULL); - if ( !opal_base || !opal_entry ) + opal_base_p = fdt_getprop(fdt, opal_node, "opal-base-address", NULL); + opal_entry_p = fdt_getprop(fdt, opal_node, "opal-entry-address", NULL); + if ( !opal_base_p || !opal_entry_p ) { early_printk("Failed to get opal-base-address/opal-entry-address " "property from DT!\n"); die(); } - opal.base = be64_to_cpu(*opal_base); - opal.entry = be64_to_cpu(*opal_entry); + memcpy(&opal_base, opal_base_p, sizeof(opal_base)); + memcpy(&opal_entry, opal_entry_p, sizeof(opal_entry)); + + opal.base = be64_to_cpu(opal_base); + opal.entry = be64_to_cpu(opal_entry); early_printk_init(opal_putchar);