From patchwork Fri Mar 18 07:41:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fu Wei Fu X-Patchwork-Id: 64036 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp900686lbc; Fri, 18 Mar 2016 00:43:34 -0700 (PDT) X-Received: by 10.140.109.33 with SMTP id k30mr20117093qgf.45.1458287014095; Fri, 18 Mar 2016 00:43:34 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id g48si11256715qgd.15.2016.03.18.00.43.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Mar 2016 00:43:34 -0700 (PDT) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1agp2w-0007mL-84; Fri, 18 Mar 2016 07:42:10 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1agp2v-0007mB-EG for xen-devel@lists.xensource.com; Fri, 18 Mar 2016 07:42:09 +0000 Received: from [193.109.254.147] by server-10.bemta-14.messagelabs.com id EB/29-02986-051BBE65; Fri, 18 Mar 2016 07:42:08 +0000 X-Env-Sender: fu.wei@linaro.org X-Msg-Ref: server-12.tower-27.messagelabs.com!1458286926!32092187!1 X-Originating-IP: [209.132.183.28] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMjA5LjEzMi4xODMuMjggPT4gNTQwNjQ=\n X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 24633 invoked from network); 18 Mar 2016 07:42:07 -0000 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by server-12.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 18 Mar 2016 07:42:07 -0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id CFE85C00B8C7; Fri, 18 Mar 2016 07:42:05 +0000 (UTC) Received: from magi-f22.redhat.com (vpn1-7-51.pek2.redhat.com [10.72.7.51]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2I7g2ZW029770; Fri, 18 Mar 2016 03:42:03 -0400 From: fu.wei@linaro.org To: xen-devel@lists.xensource.com, Ian.Campbell@citrix.com, julien.grall@linaro.org Date: Fri, 18 Mar 2016 15:41:48 +0800 Message-Id: <1458286908-27677-1-git-send-email-fu.wei@linaro.org> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 Cc: jcm@redhat.com, Fu Wei , leif.lindholm@linaro.org, linaro-uefi@lists.linaro.org Subject: [Xen-devel] [PATCH] xen/arm64: check XSM Magic and Signature from the second unknown module. X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" From: Fu Wei This patch add a check_xsm_signature static function for detecting XSM from the second unknown module. If xen can't get the kind of module from compatible, we guess the kind of these first two unknown respectively: (1) The first unknown must be kernel; (2) The second unknown is ramdisk, only if we have ramdisk; (3) Start from the 2nd unknown, detect the XSM binary signature; (4) If we got XSM in the 2nd unknown, that means we don't load initrd. Signed-off-by: Fu Wei --- ChangeLog: v1: This patch - the first upstream patch to xen-devel mailing lists. xen/arch/arm/bootfdt.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index 8a14015..1a74ecf 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -163,6 +163,36 @@ static void __init process_memory_node(const void *fdt, int node, } } +static bool __init check_xsm_signature(const void *fdt, int node, + const char *name, + u32 address_cells, u32 size_cells) +{ + uint32_t selinux_magic = 0xf97cff8c; + const struct fdt_property *prop; + paddr_t start, size; + const __be32 *cell; + /* 16 == sizeof(uint32_t) * 2 + sizeof("XenFlask") - 1 */ + char magic[16]; + int len; + + prop = fdt_get_property(fdt, node, "reg", &len); + if ( !prop ) + panic("node %s missing `reg' property\n", name); + + if ( len < dt_cells_to_size(address_cells + size_cells) ) + panic("fdt: node `%s': `reg` property length is too short\n", name); + + cell = (const __be32 *)prop->data; + device_tree_get_reg(&cell, address_cells, size_cells, &start, &size); + + copy_from_paddr(magic, start, 16); + if (strncmp(magic, (char *) &selinux_magic, sizeof(uint32_t)) || + strncmp(magic + sizeof(uint32_t) * 2, "XenFlask", 8)) + return 0; + + return 1; +} + static void __init process_multiboot_node(const void *fdt, int node, const char *name, u32 address_cells, u32 size_cells) @@ -186,7 +216,13 @@ static void __init process_multiboot_node(const void *fdt, int node, else kind = BOOTMOD_UNKNOWN; - /* Guess that first two unknown are kernel and ramdisk respectively. */ + /** + * Guess the kind of these first two unknown respectively: + * (1) The first unknown must be kernel; + * (2) The second unknown is ramdisk, only if we have ramdisk; + * (3) Start from the 2nd unknown, detect the XSM binary signature; + * (4) If we got XSM in the 2nd unknown, that means we have not initrd. + */ if ( kind == BOOTMOD_UNKNOWN ) { switch ( kind_guess++ ) @@ -195,6 +231,9 @@ static void __init process_multiboot_node(const void *fdt, int node, case 1: kind = BOOTMOD_RAMDISK; break; default: break; } + if (kind_guess > 1 && check_xsm_signature(fdt, node, name, + address_cells, size_cells)) + kind = BOOTMOD_XSM; } prop = fdt_get_property(fdt, node, "reg", &len);