From: fu.wei@linaro.org
To: xen-devel@lists.xensource.com, julien.grall@arm.com,
stefano.stabellini@citrix.com, dgdegra@tycho.nsa.gov,
konrad.wilk@oracle.com
Cc: jcm@redhat.com, Fu Wei <fu.wei@linaro.org>,
leif.lindholm@linaro.org, linaro-uefi@lists.linaro.org
Subject: [PATCH v3] xen/arm64: check XSM Magic and Signature from the second unknown module.
Date: Tue, 29 Mar 2016 11:26:55 +0800 [thread overview]
Message-ID: <1459222015-12036-1-git-send-email-fu.wei@linaro.org> (raw)
From: Fu Wei <fu.wei@linaro.org>
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 <fu.wei@linaro.org>
---
Changelog:
v3: Using memcmp instead of strncmp.
Using "return 0;" instead of panic();
Improve some comments.
v2: http://lists.xen.org/archives/html/xen-devel/2016-03/msg03543.html
Using XEN_MAGIC macro instead of 0xf97cff8c :
uint32_t selinux_magic = 0xf97cff8c; --> uint32_t xen_magic = XEN_MAGIC;
Comment out the code(return 0 directly), if CONFIG_FLASK is not set.
v1: http://lists.xen.org/archives/html/xen-devel/2016-03/msg02430.html
The first upstream patch to xen-devel mailing lists.
xen/arch/arm/bootfdt.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 53 insertions(+), 1 deletion(-)
diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c
index 8a14015..10d3382 100644
--- a/xen/arch/arm/bootfdt.c
+++ b/xen/arch/arm/bootfdt.c
@@ -163,6 +163,49 @@ static void __init process_memory_node(const void *fdt, int node,
}
}
+/**
+ * check_xsm_signature - Check XSM Magic and Signature of the module header
+ * A XSM module has a special header
+ * ------------------------------------------------
+ * uint magic | uint target_len | uchar target[8] |
+ * 0xf97cff8c | 8 | "XenFlask" |
+ * ------------------------------------------------
+ * 0xf97cff8c is policy magic number (XSM_MAGIC).
+ * So we only read the first 16 bytes of the module, then check these three
+ * parts. This checking (memcmp) assumes little-endian byte order.
+ */
+static bool __init check_xsm_signature(const void *fdt, int node,
+ const char *name,
+ u32 address_cells, u32 size_cells)
+{
+#ifdef CONFIG_FLASK
+ u32 xen_magic = XSM_MAGIC, target_len = 8;
+ const struct fdt_property *prop;
+ unsigned char buff[16];
+ paddr_t start, size;
+ const __be32 *cell;
+ int len;
+
+ prop = fdt_get_property(fdt, node, "reg", &len);
+ if ( !prop || len < dt_cells_to_size(address_cells + size_cells))
+ return 0;
+
+ cell = (const __be32 *)prop->data;
+ device_tree_get_reg(&cell, address_cells, size_cells, &start, &size);
+
+ copy_from_paddr(buff, start, sizeof(buff));
+
+ if (memcmp(buff, (void *) &xen_magic, sizeof(u32)) ||
+ memcmp(buff + sizeof(u32), (void *) &target_len, sizeof(u32)) ||
+ memcmp(buff + sizeof(u32) * 2, "XenFlask", target_len))
+ return 0;
+
+ return 1;
+#else
+ return 0;
+#endif
+}
+
static void __init process_multiboot_node(const void *fdt, int node,
const char *name,
u32 address_cells, u32 size_cells)
@@ -186,7 +229,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 +244,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);
--
2.5.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next reply other threads:[~2016-03-29 3:26 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-29 3:26 fu.wei [this message]
2016-03-29 9:56 ` [PATCH v3] xen/arm64: check XSM Magic and Signature from the second unknown module Jan Beulich
2016-03-29 11:10 ` Fu Wei
2016-04-01 18:10 ` Julien Grall
2016-04-05 13:41 ` Fu Wei
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1459222015-12036-1-git-send-email-fu.wei@linaro.org \
--to=fu.wei@linaro.org \
--cc=dgdegra@tycho.nsa.gov \
--cc=jcm@redhat.com \
--cc=julien.grall@arm.com \
--cc=konrad.wilk@oracle.com \
--cc=leif.lindholm@linaro.org \
--cc=linaro-uefi@lists.linaro.org \
--cc=stefano.stabellini@citrix.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).