xen/arm64: check XSM Magic and Signature from the second unknown module.
PATCH v2 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.---
v2: 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 | 57 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-)
xen/arch/arm/bootfdt.c +56 -1
@@ -163,6 +163,52 @@ 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. +* So we only read the first 16 Bytes of the module, then check these three +* parts. +*/ +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; +paddr_t start, size; +const __be32 *cell; +char buff[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 (buff, start,sizeof (buff)); + +if (strncmp (buff, (char *) &xen_magic,sizeof (u32)) || +strncmp (buff +sizeof (u32), (char *) &target_len,sizeof (u32)) || +strncmp (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 +232,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 +247,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
Quoted 5 lines · On Tue, Mar 29, 2016 at 01:55:07AM +0800, [email protected] wrote:
From: Fu Wei <[email protected]>
This patch add a
check_xsm_signaturestatic function for detecting XSM from the second unknown module.
Quoted 7 lines
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.
Pls make the 'xen' be 'Xen'.
Quoted 1 line
Signed-off-by Fu Wei <[email protected]>
Cc-ing also Daniel (XSM maintainer).
And Julien (linaro.org != arm.com) and Stefano.
Quoted 18 lines
---
v2: UsingXEN_MAGICmacro instead of0xf97cff8c:
uint32_tselinux_magic=0xf97cff8c; -->uint32_txen_magic=XEN_MAGIC; Comment out the code(return 0 directly), ifCONFIG_FLASKis 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 | 57 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-)xen/arch/arm/bootfdt.c +0
-0@@ -163,6 +163,52 @@ static void __init process_memory_node(const void *fdt, int node, } }
xen/arch/arm/bootfdt.c static void __init process_memory_node(const void *fdt, int node, · line 174
Quoted 10 lines
xen/arch/arm/bootfdt.c +9
-0+/** +* 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. +* So we only read the first 16 Bytes of the module, then check these three
s/Bytes/bytes/
xen/arch/arm/bootfdt.c static void __init process_memory_node(const void *fdt, int node, · line 175
Quoted 1 line
xen/arch/arm/bootfdt.c +1
-0+* parts.
Is it possible for the hypervisor to chnage the policy magic number? Perhaps you should have :
BUILD_BUG_ON(0xf97cff8c != XSM_MAGIC);
to guard against changes?
Quoted 6 lines
xen/arch/arm/bootfdt.c +6
-0+*/ +static bool __init check_xsm_signature (const void *fdt,int node, +const char *name, +u32 address_cells,u32 size_cells) +{ +#ifdef CONFIG_FLASK
xen/arch/arm/bootfdt.c static void __init process_memory_node(const void *fdt, int node, · line 191
Quoted 10 lines
xen/arch/arm/bootfdt.c +10
-0+u32 xen_magic =XSM_MAGIC , target_len =8 ; +const struct fdt_property *prop; +paddr_t start, size; +const __be32 *cell; +char buff[16 ]; +int len; + + prop =fdt_get_property (fdt, node,"reg" , &len); +if ( !prop ) +panic ("node %s missing `reg' property\n" , name);
Why panic? Can't you just return?
xen/arch/arm/bootfdt.c static void __init process_memory_node(const void *fdt, int node, · line 194
Quoted 3 lines
xen/arch/arm/bootfdt.c +3
-0+ +if ( len <dt_cells_to_size (address_cells + size_cells) ) +panic ("fdt: node `%s': `reg` property length is too short\n" , name);
Ditto?
Quoted 53 lines
xen/arch/arm/bootfdt.c +27
-1+ + cell = (const __be32 *)prop->data; +device_tree_get_reg (&cell, address_cells, size_cells, &start, &size); + +copy_from_paddr (buff, start,sizeof (buff)); + +if (strncmp (buff, (char *) &xen_magic,sizeof (u32)) || +strncmp (buff +sizeof (u32), (char *) &target_len,sizeof (u32)) || +strncmp (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 +232,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 +247,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
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 51 lines · Konrad Rzeszutek Wilk
Quoted 5 lines · On Tue, Mar 29, 2016 at 01:55:07AM +0800, [email protected] wrote:
From: Fu Wei <[email protected]>
This patch add a
check_xsm_signaturestatic function for detecting XSM from the second unknown module.Quoted 7 lines
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.Pls make the 'xen' be 'Xen'.
Quoted 1 line
Signed-off-by Fu Wei <[email protected]>Cc-ing also Daniel (XSM maintainer).
And Julien (linaro.org != arm.com) and Stefano.
Quoted 18 lines
---
v2: UsingXEN_MAGICmacro instead of0xf97cff8c:
uint32_tselinux_magic=0xf97cff8c; -->uint32_txen_magic=XEN_MAGIC; Comment out the code(return 0 directly), ifCONFIG_FLASKis 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 | 57 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-)xen/arch/arm/bootfdt.c +0
-0@@ -163,6 +163,52 @@ static void __init process_memory_node(const void *fdt, int node, } }xen/arch/arm/bootfdt.c static void __init process_memory_node(const void *fdt, int node, · line 174
Quoted 10 lines
xen/arch/arm/bootfdt.c +9
-0+/** +* 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. +* So we only read the first 16 Bytes of the module, then check these three s/Bytes/bytes/
Quoted 8 lines
xen/arch/arm/bootfdt.c static void __init process_memory_node(const void *fdt, int node, · line 175
Quoted 1 line
xen/arch/arm/bootfdt.c +1
-0+* parts. Is it possible for the hypervisor to chnage the policy magic number? Perhaps you should have :
BUILD_BUG_ON(0xf97cff8c != XSM_MAGIC);to guard against changes?
The value of XSM_MAGIC will always be that constant if FLASK is the enabled security module; the value was different when the (now-removed) ACM module was selected.
[...]
Quoted 5 lines
xen/arch/arm/bootfdt.c static void __init process_memory_node(const void *fdt, int node, · line 205
Quoted 5 lines
xen/arch/arm/bootfdt.c +5
-0+if (strncmp (buff, (char *) &xen_magic,sizeof (u32)) || +strncmp (buff +sizeof (u32), (char *) &target_len,sizeof (u32)) || +strncmp (buff +sizeof (u32) *2 ,"XenFlask" , target_len)) +return 0 ; +
memcmp() is more correct than strncmp() here, especially since target_len will have embedded NULLs. It also assumes little endian byte order; is that worth commenting on?
Signature · 7 lines
Daniel De Graaf National Security Agency _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Hi Daniel,
Quoted 71 lines · Daniel De Graaf
Quoted 70 lines · Konrad Rzeszutek Wilk
Quoted 6 lines · On Tue, Mar 29, 2016 at 01:55:07AM +0800, [email protected] wrote:
From: Fu Wei <[email protected]>
This patch add a
check_xsm_signaturestatic function for detecting XSM from the second unknown module.Quoted 8 lines
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 loadinitrd.
Pls make the 'xen' be 'Xen'.
Quoted 1 line
Signed-off-by Fu Wei <[email protected]>Cc-ing also Daniel (XSM maintainer).
And Julien (linaro.org != arm.com) and Stefano.
Quoted 28 lines
---
v2: UsingXEN_MAGICmacro instead of0xf97cff8c:uint32_t selinux_magic = 0xf97cff8c; --> uint32_t xen_magic =
XEN_MAGIC;
Comment out the code(return 0 directly), ifCONFIG_FLASKis 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 | 57 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-)xen/arch/arm/bootfdt.c +2
-0@@ -163,6 +163,52 @@ 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
+ * ------------------------------------------------Quoted 6 lines
+ * uint magic | uint target_len | uchar target[8] | + * 0xf97cff8c | 8 | "XenFlask" |+ * ------------------------------------------------
+ *0xf97cff8cis policy magic number.
+ * So we only read the first 16 Bytes of the module, then check these threes/Bytes/bytes/
Quoted 2 lines
+ * parts.
Is it possible for the hypervisor to chnage the policy magic number? Perhaps
you should have :
Quoted 8 lines
Quoted 3 lines
BUILD_BUG_ON(0xf97cff8c != XSM_MAGIC);to guard against changes?
The value of
XSM_MAGICwill always be that constant if FLASK is the enabled security module; the value was different when the (now-removed) ACM module was selected.
OK, it seems we can just use this :-)
Quoted 11 lines
[...]
Quoted 7 lines
xen/arch/arm/bootfdt.c static void __init process_memory_node(const void *fdt, int node, · line 205
Quoted 7 lines
xen/arch/arm/bootfdt.c +2
-0+if (strncmp (buff, (char *) &xen_magic,sizeof (u32)) || + strncmp(buff + sizeof(u32), (char *) &target_len, sizeof(u32))||
xen/arch/arm/bootfdt.c +3
-0+ strncmp(buff + sizeof(u32) * 2, "XenFlask", target_len)) +return 0 ; +
Quoted 5 lines
memcmp()is more correct thanstrncmp()here, especially sincetarget_lenwill
have embedded NULLs. It also assumes little endian byte order; is that worth
commenting on?
yes, thanks. I think memcmp() is correct too! :-) I have added a comment in the next version :-)
Please check my v3 patch :-)
http://lists.xen.org/archives/html/xen-devel/2016-03/msg03564.html
Quoted 4 lines
--
Daniel De Graaf
National Security Agency
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
Hi Konrad,
Quoted 14 lines · Konrad Rzeszutek Wilk
Quoted 5 lines · On Tue, Mar 29, 2016 at 01:55:07AM +0800, [email protected] wrote:
From: Fu Wei <[email protected]>
This patch add a
check_xsm_signaturestatic function for detecting XSM from the second unknown module.Quoted 7 lines
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.
Quoted 1 line
Pls make the 'xen' be 'Xen'.
Thanks, :-)
Quoted 4 lines
Quoted 2 lines
Signed-off-by Fu Wei <[email protected]>Cc-ing also Daniel (XSM maintainer).
Thanks, I will add him into to-list next time:-)
Quoted 21 lines
And Julien (linaro.org != arm.com) and Stefano.
Quoted 19 lines
---
v2: UsingXEN_MAGICmacro instead of0xf97cff8c:
uint32_tselinux_magic=0xf97cff8c; -->uint32_txen_magic=XEN_MAGIC; Comment out the code(return 0 directly), ifCONFIG_FLASKis 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 | 57 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-)xen/arch/arm/bootfdt.c +0
-0@@ -163,6 +163,52 @@ static void __init process_memory_node(const void *fdt, int node, } }
Quoted 11 lines
xen/arch/arm/bootfdt.c static void __init process_memory_node(const void *fdt, int node, · line 174
Quoted 9 lines
xen/arch/arm/bootfdt.c +9
-0+/** +* 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. +* So we only read the first 16 Bytes of the module, then check these three s/Bytes/bytes/
thanks , will do
Quoted 28 lines
xen/arch/arm/bootfdt.c static void __init process_memory_node(const void *fdt, int node, · line 175
Quoted 1 line
xen/arch/arm/bootfdt.c +1
-0+* parts. Is it possible for the hypervisor to chnage the policy magic number? Perhaps you should have :
BUILD_BUG_ON(0xf97cff8c != XSM_MAGIC);to guard against changes?
Quoted 6 lines
xen/arch/arm/bootfdt.c +6
-0+*/ +static bool __init check_xsm_signature (const void *fdt,int node, +const char *name, +u32 address_cells,u32 size_cells) +{ +#ifdef CONFIG_FLASK xen/arch/arm/bootfdt.c static void __init process_memory_node(const void *fdt, int node, · line 191
Quoted 10 lines
xen/arch/arm/bootfdt.c +10
-0+u32 xen_magic =XSM_MAGIC , target_len =8 ; +const struct fdt_property *prop; +paddr_t start, size; +const __be32 *cell; +char buff[16 ]; +int len; + + prop =fdt_get_property (fdt, node,"reg" , &len); +if ( !prop ) +panic ("node %s missing `reg' property\n" , name);Why panic? Can't you just return?
Quoted 5 lines
xen/arch/arm/bootfdt.c static void __init process_memory_node(const void *fdt, int node, · line 194
Quoted 3 lines
xen/arch/arm/bootfdt.c +3
-0+ +if ( len <dt_cells_to_size (address_cells + size_cells) ) +panic ("fdt: node `%s': `reg` property length is too short\n" , name);Ditto?
Good point, will do
Thanks for your review :-)
Quoted 54 lines
Quoted 54 lines
xen/arch/arm/bootfdt.c +27
-2+ + cell = (const __be32 *)prop->data; +device_tree_get_reg (&cell, address_cells, size_cells, &start, &size); + +copy_from_paddr (buff, start,sizeof (buff)); + +if (strncmp (buff, (char *) &xen_magic,sizeof (u32)) || +strncmp (buff +sizeof (u32), (char *) &target_len,sizeof (u32)) || +strncmp (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 +232,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 +247,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
[email protected]
http://lists.xen.org/xen-devel
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