Skip to contentSkip to conversation

xen/arm64: check XSM Magic and Signature from the second unknown module.

PATCH Superseded [email protected] 3 participants 4 messages Mar 18, 2016 – Mar 25, 2016

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/arm64: check XSM Magic and Signature from the second unknown module.

From: Fu Wei <[email protected]>

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.

---
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(-)
xen/arch/arm/bootfdt.c +40 -1
index 8a14015..1a74ecf 100644
@@ -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);
Signature · 7 lines
2.5.0


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#1 lore raw

xen/arch/arm/bootfdt.c static void __init process_memory_node(const void *fdt, int node, · line 170

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 18.03.16 at 08:41, <[email protected]> wrote:
xen/arch/arm/bootfdt.c +5 -0
@@ -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;

So this would be the 3rd instance of this literal number in the source base. I would have wanted to suggest using one of the two constants we already have, but I don't know which one to pick.

Daniel - why do we have both XSM_MAGIC and FLASK_MAGIC?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#2 lore raw

Hi Jan,

Quoted 17 lines · Jan Beulich

xen/arch/arm/bootfdt.c static void __init process_memory_node(const void *fdt, int node, · line 170

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 18.03.16 at 08:41, <[email protected]> wrote:
xen/arch/arm/bootfdt.c +5 -0
@@ -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;

So this would be the 3rd instance of this literal number in the source base. I would have wanted to suggest using one of the two constants we already have, but I don't know which one to pick.

Quoted 1 line

Daniel - why do we have both XSM_MAGIC and FLASK_MAGIC?

Ah, Sorry for that , I didn't know we already have these definition.

OK, I think we should use XSM_MAGIC,
and I think FLASK_MAGIC should be "XenFlask".
Please correct me if I misunderstand something.

So maybe I should do :

    uint32_t xen_magic = XEN_MAGIC;
Quoted 3 lines

Jan

Signature · 15 lines
Best regards,

Fu Wei
Software Engineer
Red Hat Software (Beijing) Co.,Ltd.Shanghai Branch
Ph: +86 21 61221326(direct)
Ph: +86 186 2020 4684 (mobile)
Room 1512, Regus One Corporate Avenue,Level 15,
One Corporate Avenue,222 Hubin Road,Huangpu District,
Shanghai,China 200021

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#3 lore raw
Quoted 21 lines · Fu Wei

Hi Jan,

Quoted 18 lines · Jan Beulich

xen/arch/arm/bootfdt.c static void __init process_memory_node(const void *fdt, int node, · line 170

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 18.03.16 at 08:41, <[email protected]> wrote:
xen/arch/arm/bootfdt.c +5 -0
@@ -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;

So this would be the 3rd instance of this literal number in the source base. I would have wanted to suggest using one of the two constants we already have, but I don't know which one to pick.

Daniel - why do we have both XSM_MAGIC and FLASK_MAGIC?

I think the intent was that FLASK_MAGIC be the primary source of the constant with XSM_MAGIC set to that value when FLASK was the chosen XSM module. With the relative locations of the definitions in Xen, this ended up duplicating the literal which isn't quite as nice. I would be fine with consolidating either way; perhaps move FLASK_MAGIC into xsm.h and conditionally define XSM_MAGIC to reference it?

Quoted 5 lines

Ah, Sorry for that , I didn't know we already have these definition.

OK, I think we should use XSM_MAGIC,
and I think FLASK_MAGIC should be "XenFlask".
Please correct me if I misunderstand something.

These constants are also defined as POLICYDB_MAGIC and POLICYDB_STRING in xen/xsm/flask/ss/policydb.h (that will probably need to be moved if you want to use them elsewhere).

The hypervisor also supports loading policies whose magic type declares them to be SELinux policy, but I think it's fine if ARM requires that the policy be built targeting Xen - the build has done that for a while, and the original reason (older versions of checkpolicy didn't support creating xen-type policy) is no longer an issue.

Signature · 7 lines
Daniel De Graaf
National Security Agency

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel