From patchwork Wed Jun 22 08:59:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dirk Behme X-Patchwork-Id: 9192199 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8DE83601C0 for ; Wed, 22 Jun 2016 09:02:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7BB3F2522B for ; Wed, 22 Jun 2016 09:02:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7071C26223; Wed, 22 Jun 2016 09:02:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0D63E2522B for ; Wed, 22 Jun 2016 09:02:27 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bFe14-00077w-Vg; Wed, 22 Jun 2016 09:00: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 1bFe13-00077q-VJ for xen-devel@lists.xenproject.org; Wed, 22 Jun 2016 09:00:10 +0000 Received: from [193.109.254.147] by server-5.bemta-14.messagelabs.com id D9/A3-08132-9935A675; Wed, 22 Jun 2016 09:00:09 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrFIsWRWlGSWpSXmKPExsXSzf+WW3dGcFa 4wdvdShbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bJlZfZCnplK2ZuvM/UwLhNrIuRi0NI4Cyj xObPp1hAHBaBt0wSpz5NZoXIPGeUuD3xGBuEs4ZR4vud+VCZlYwSP28tAOrh5GAT0JLYOaGDH cQWESiXWLXvEVARBwezgIbEhm1gYWEBc4mPsw+xgtgsAqoSx2acZwaxeQXcJQ78XssGYksIyE msm/ydHSIuKHFy5hOw8cwCEhIHX7xghqgRkZj49z1UvaVE+8qTTCD3SAjcYJZ4O30d8wRGwVl I+mch6V/AyLSKUaM4tagstUjX0EgvqSgzPaMkNzEzR9fQ0EQvN7W4ODE9NScxqVgvOT93EyMw TBmAYAfj2WnOhxglOZiURHnllbPChfiS8lMqMxKLM+KLSnNSiw8xynBwKEnwdgYC5QSLUtNTK 9Iyc4ARA5OW4OBREuEVCwJK8xYXJOYWZ6ZDpE4xKkqJ884E6RMASWSU5sG1waL0EqOslDAvI9 AhQjwFqUW5mSWo8q8YxTkYlYR5n4JM4cnMK4Gb/gpoMRPQ4mX96SCLSxIRUlINjCkt1f7vLbQ frJ/RGKjeeCMg5WTehLj3ud6vVoWsWX2v1Hj2idlFFZ72XcHxd7L4DLWPOVmbnD7Kwx75721D o/rnuiNVO42uPLq62yH1U5dO6I91W26sdNf+fvB7qKHIheOlORFfrcVuqe30dn+3quOXyf87D xp49p2JMY459Spk0e4fGjqGB5RYijMSDbWYi4oTAQwKaULNAgAA X-Env-Sender: Dirk.Behme@de.bosch.com X-Msg-Ref: server-3.tower-27.messagelabs.com!1466586008!48877854!1 X-Originating-IP: [139.15.237.11] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM5LjE1LjIzNy4xMSA9PiAxNTMwMzA=\n X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 41729 invoked from network); 22 Jun 2016 09:00:08 -0000 Received: from smtp6-v.fe.bosch.de (HELO smtp6-v.fe.bosch.de) (139.15.237.11) by server-3.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 22 Jun 2016 09:00:08 -0000 Received: from vsmta12.fe.internet.bosch.com (unknown [10.4.98.52]) by imta23.fe.bosch.de (Postfix) with ESMTP id F13F415800BA for ; Wed, 22 Jun 2016 11:00:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=de.bosch.com; s=2015-01-21; t=1466586007; bh=Fkztw+w29n/RtCYHbEXsFbnY3M0zIvbb7k+ZGSlsatU=; l=10; h=From:From:Reply-To:Sender; b=dnx+WIr/u/QqD2JYTQvX/SQ2+V3S8JLMjBi2gRUPUtSj4kUAzIYrd/KB0hUU33BsL JZ1QWsAgkRxBzthxRuKu2UAXU61m2wqMgklhjxeZagZpylyi4vmeKIx7gbORArjQJl 72SSa5rn90/J4gUDEiKIq7peARNdzJmMN2wb+IeI= Received: from SI-HUB1001.de.bosch.com (vsgw24.fe.internet.bosch.com [10.4.98.24]) by vsmta12.fe.internet.bosch.com (Postfix) with ESMTP id 97FDA1B8063C for ; Wed, 22 Jun 2016 11:00:07 +0200 (CEST) Received: from hi-z08if.hi.de.bosch.com (10.34.209.31) by SI-HUB1001.de.bosch.com (10.4.103.108) with Microsoft SMTP Server id 14.3.195.1; Wed, 22 Jun 2016 11:00:06 +0200 Received: from hi-z08if.hi.de.bosch.com (localhost [127.0.0.1]) by hi-z08if.hi.de.bosch.com (Postfix) with ESMTP id 69D46625F16; Wed, 22 Jun 2016 10:59:21 +0200 (CEST) From: Dirk Behme To: , Julien Grall , Stefano Stabellini Date: Wed, 22 Jun 2016 10:59:19 +0200 Message-ID: <1466585959-12362-1-git-send-email-dirk.behme@de.bosch.com> X-Mailer: git-send-email 2.8.0 MIME-Version: 1.0 X-TM-AS-MML: disable X-TM-AS-Product-Ver: IMSS-7.1.0.1679-8.0.0.1202-22404.006 X-TMASE-MatchedRID: rlV/fSAreo4ryFHbNnBLG7U+IyHhkXf1FuNF4lJG6xsL/50zj0KL7BHx rRblSw8b9Pkiah4SuH4MfgmZ55C/YfF4Lj+zpFjfVnhTcytb5dIwl5uLW9ec01pbYq2f4jz+sCL 2uKJULhPKwJG6rXlLlAMCC5iRZIS0pljg/F9ExYTaGKmW8Fvr+wrefVId6fzVXCmcAC8DBrNvt4 SwM/2FHdOyPb4doLQzVRedb8S231mQqMvYg6LYsOEbUg4xvs+wyeUl7aCTy8hBDVeC8J7uwbEQi kyj8N/gHF0ehhIxzAsREHWgVzxk3WFpiGkolyFoLi5PDX0qWHqCxYB2hPS4vZsoi2XrUn/JQYMO RuDWAmSJSt7i5EtARyAHAopEd76vGrHZr0w9xsuoRfj6Tp/kYf8uVrwgfvlYGISA/t/ZBzptH1k BtWAEqg== Cc: Dirk Behme Subject: [Xen-devel] [PATCH v2] xen: arm: Update arm64 image header 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: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP With the Linux kernel commits https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/Documentation/arm64/booting.txt?id=4370eec05a887b0cd4392cd5dc5b2713174745c0 https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/Documentation/arm64/booting.txt?id=a2c1d73b94ed49f5fac12e95052d7b140783f800 the arm64 image header changed. While the size of the header isn't changed, some members have changed their usage. Update Xen to this updated image header. The main changes are that the first magic is gone and that there is an image size, now. In case we read a size != 0, let's use this image size, now. This does allow us to check if the kernel Image is larger than the size given in the device tree, too. Additionally, add an error message if the magic is not found. This might be the case with kernel's < 3.12 prior to https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=4370eec05a887b0cd4392cd5dc5b2713174745c0 Signed-off-by: Dirk Behme --- xen/arch/arm/kernel.c | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/xen/arch/arm/kernel.c b/xen/arch/arm/kernel.c index 9871bd9..9b9a793 100644 --- a/xen/arch/arm/kernel.c +++ b/xen/arch/arm/kernel.c @@ -28,8 +28,7 @@ #define ZIMAGE32_MAGIC 0x016f2818 -#define ZIMAGE64_MAGIC_V0 0x14000008 -#define ZIMAGE64_MAGIC_V1 0x644d5241 /* "ARM\x64" */ +#define ZIMAGE64_MAGIC 0x644d5241 /* "ARM\x64" */ struct minimal_dtb_header { uint32_t magic; @@ -335,17 +334,17 @@ static int kernel_zimage64_probe(struct kernel_info *info, { /* linux/Documentation/arm64/booting.txt */ struct { - uint32_t magic0; - uint32_t res0; - uint64_t text_offset; /* Image load offset */ - uint64_t res1; - uint64_t res2; + uint32_t code0; + uint32_t code1; + uint64_t text_offset; /* Image load offset, little endian */ + uint64_t image_size; /* Effective Image size, little endian */ + uint64_t flags; /* zImage V1 only from here */ + uint64_t res2; uint64_t res3; uint64_t res4; - uint64_t res5; - uint32_t magic1; - uint32_t res6; + uint32_t magic; /* Magic number, little endian, "ARM\x64" */ + uint32_t res5; } zimage; uint64_t start, end; @@ -354,20 +353,30 @@ static int kernel_zimage64_probe(struct kernel_info *info, copy_from_paddr(&zimage, addr, sizeof(zimage)); - if ( zimage.magic0 != ZIMAGE64_MAGIC_V0 && - zimage.magic1 != ZIMAGE64_MAGIC_V1 ) + if ( zimage.magic != ZIMAGE64_MAGIC ) { + printk(XENLOG_ERR "No valid magic found in header! Kernel too old?\n"); return -EINVAL; + } - /* Currently there is no length in the header, so just use the size */ start = 0; - end = size; /* - * Given the above this check is a bit pointless, but leave it - * here in case someone adds a length field in the future. + * Where image_size is non-zero image_size is little-endian + * and must be respected. */ - if ( (end - start) > size ) + if ( zimage.image_size ) + end = zimage.image_size; + else + end = size; + + if ( (end - start) > size ) { + if ( zimage.image_size ) { + printk(XENLOG_ERR "Error: Kernel Image size: %lu bytes > bootmodule size: %lu bytes\n", + zimage.image_size, (uint64_t)size); + printk(XENLOG_ERR "The field 'size' does not match the size of blob!\n"); + } return -EINVAL; + } info->zimage.kernel_addr = addr; info->zimage.len = end - start;