XSM labels support in dom0less
cover XSM labels support in dom0less
Currently FLASK can't really be enforced for domains being brought up in dom0less mode, as security contexts are not assigned for domains in this configuration. Thus domains are left with default SECINITSID_UNLABELED SID which policy forbids to create:
(XEN) [ 0.637379] avc: denied { create } for current=d[IDLE] scontext=system_u:system_r:xenboot_t tcontext=system_u:system_r:unlabeled_t tclass=domain
This series extends dom0less bindings with ability to provide human-readable security context in domain's DTS configuration, replicating a toolstack approach and naming.
-Sergiy
Sergiy Kibrik (2):
flask: add const qualifier to security_context_to_sid()
common: dom0less-bindings: introduce XSM labels
docs/misc/arm/device-tree/booting.txt | 8 ++++++++ xen/common/device-tree/Makefile | 2 ++ xen/common/device-tree/dom0less-bindings.c | 11 +++++++++++ xen/xsm/flask/include/security.h | 2 +- xen/xsm/flask/ss/services.c | 2 +- 5 files changed, 23 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/2 flask: add const qualifier to security_context_to_sid()
The function does not modify context argument.
Also it gives more flexibility to this API usage, because some context strings in Xen are also const char*.
--- xen/xsm/flask/include/security.h | 2 +- xen/xsm/flask/ss/services.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
xen/xsm/flask/include/security.h +1 -1
@@ -76,7 +76,7 @@ int security_change_sid(u32 ssid, u32 tsid, u16 tclass, u32 *out_sid);int security_sid_to_context (u32 sid,char **scontext,u32 *scontext_len); -int security_context_to_sid (char *scontext,u32 scontext_len,u32 *out_sid); +int security_context_to_sid (const char *scontext,u32 scontext_len,u32 *out_sid);int security_get_allow_unknown (void );
xen/xsm/flask/ss/services.c +1 -1
@@ -813,7 +813,7 @@ out:* Returns -%EINVAL if the context is invalid, -%ENOMEM if insufficient * memory is available, or 0 on success. */ -int security_context_to_sid (char *scontext,u32 scontext_len,u32 *sid) +int security_context_to_sid (const char *scontext,u32 scontext_len,u32 *sid) {char *scontext2;struct context context;
Signature · 1 line
2.43.0
Re: [PATCH v1 1/2] flask: add const qualifier to security_context_to_sid()
Quoted 28 lines · Sergiy Kibrik
The function does not modify context argument.
Also it gives more flexibility to this API usage, because some context strings in Xen are also const char*.Signed-off-by Sergiy Kibrik <[email protected]>--- xen/xsm/flask/include/security.h | 2 +- xen/xsm/flask/ss/services.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)xen/xsm/flask/include/security.h +1
-1@@ -76,7 +76,7 @@ int security_change_sid(u32 ssid, u32 tsid, u16 tclass, u32 *out_sid);int security_sid_to_context (u32 sid,char **scontext,u32 *scontext_len); -int security_context_to_sid (char *scontext,u32 scontext_len,u32 *out_sid); +int security_context_to_sid (const char *scontext,u32 scontext_len,u32 *out_sid);int security_get_allow_unknown (void );xen/xsm/flask/ss/services.c +0
-0
xen/xsm/flask/ss/services.c out: · line 819
Quoted 8 lines
xen/xsm/flask/ss/services.c +1
-1@@ -813,7 +813,7 @@ out:* Returns -%EINVAL if the context is invalid, -%ENOMEM if insufficient * memory is available, or 0 on success. */ -int security_context_to_sid (char *scontext,u32 scontext_len,u32 *sid) +int security_context_to_sid (const char *scontext,u32 scontext_len,u32 *sid) {char *scontext2;struct context context;
Re: [PATCH v1 1/2] flask: add const qualifier to security_context_to_sid()
In reply to Sergiy Kibrikxen/xsm/flask/include/security.h int security_change_sid(u32 ssid, u32 tsid, u16 tclass, u32 *out_sid); · line 79
Quoted 8 lines · Sergiy Kibrik
xen/xsm/flask/include/security.h +1
-1@@ -76,7 +76,7 @@ int security_change_sid(u32 ssid, u32 tsid, u16 tclass, u32 *out_sid);int security_sid_to_context (u32 sid,char **scontext,u32 *scontext_len); -int security_context_to_sid (char *scontext,u32 scontext_len,u32 *out_sid); +int security_context_to_sid (const char *scontext,u32 scontext_len,u32 *out_sid);
I see Daniel has ack-ed this, but:
- The line is too long now.
- The last parameter name here doesn't match that of the definition.
- While touching code anyway, it would be nice if u<N> was converted to uint<N>_t (or else we'll never complete that conversion).
I think I'll take the liberty of addressing all of these while committing.
Jan
Re: [PATCH v1 1/2] flask: add const qualifier to security_context_to_sid()
Quoted 3 lines · Jan Beulich
- While touching code anyway, it would be nice if u<N> was converted to uint<N>_t (or else we'll never complete that conversion).
I think I'll take the liberty of addressing all of these while committing.
thank you, Jan. BTW, what's up with u<N>? Are they expected to be dropped/converted in Xen?
-Sergiy
Re: [PATCH v1 1/2] flask: add const qualifier to security_context_to_sid()
Quoted 7 lines · Sergiy Kibrik
Quoted 3 lines · Jan Beulich
- While touching code anyway, it would be nice if u<N> was converted to uint<N>_t (or else we'll never complete that conversion).
I think I'll take the liberty of addressing all of these while committing.thank you, Jan. BTW, what's up with u<N>? Are they expected to be dropped/converted in Xen?
Yes. If you go look, s<N> were already dropped, as were __[su]<N>. The use of u<N> sadly is far more widespread.
Jan
PATCH 2/2 common: dom0less-bindings: introduce XSM labels
In reply to Sergiy KibrikAdd "seclabel" property to be able to specify security label for a domain when XSM Flask is enabled, similar to xl configuration files.
Currently guest domain can't be created by Xen in dom0less configuration when Flask is enabled, as domain is assigned "system_u:system_r:unlabeled_t" label by default, which Flask denies to create according to current policy.
--- docs/misc/arm/device-tree/booting.txt | 8 ++++++++ xen/common/device-tree/Makefile | 2 ++ xen/common/device-tree/dom0less-bindings.c | 11 +++++++++++ 3 files changed, 21 insertions(+)
docs/misc/arm/device-tree/booting.txt +8 -0
@@ -345,6 +345,12 @@ with the following properties: not passed. This configuration requires static allocation (xen,static-mem) and direct mapping (direct-map). +- seclabel + + A string property specifying an XSM security label to this domain. Effective + only when FLASK is enabled. Domains will be classified “unlabeled” if + this property not specified. + Under the "xen,domain" compatible node, one or more sub-nodes are present for the DomU kernel and ramdisk.
@@ -422,6 +428,7 @@ chosen { memory = <0 131072>; cpus = <2>; vpl011; + seclabel = "system_u:system_r:domU_t"; vcpu0 { compatible = "xen,vcpu";
@@ -453,6 +460,7 @@ chosen { #size-cells = <0x1>; memory = <0 65536>; cpus = <1>; + seclabel = "system_u:system_r:domU_t"; module@0x4c000000 { compatible = "multiboot,kernel", "multiboot,module";
xen/common/device-tree/Makefile +2 -0
@@ -11,3 +11,5 @@ obj-$(CONFIG_DOMAIN_BUILD_HELPERS) += kernel.o obj-$(CONFIG_STATIC_EVTCHN) += static-evtchn.init.o obj-$(CONFIG_STATIC_MEMORY) += static-memory.init.o obj-$(CONFIG_STATIC_SHM) += static-shmem.init.o + +CFLAGS-y += -I$(srctree)/xsm/flask/include
xen/common/device-tree/dom0less-bindings.c +11 -0
@@ -11,6 +11,8 @@#include <public/bootfdt.h> #include <public/domctl.h> +#include <security.h> +int __init parse_dom0less_node (struct dt_device_node *node,struct boot_domain *bd) {
@@ -21,6 +23,7 @@ int __init parse_dom0less_node(struct dt_device_node *node,bool has_dtb = false;bool iommu = false;const char *dom0less_iommu =NULL ; +const char *xsm_seclabel =NULL ;if ( !dt_device_is_compatible (node,"xen,domain" ) )return -ENOENT ;
@@ -141,5 +144,13 @@ int __init parse_dom0less_node(struct dt_device_node *node,panic ("'llc-colors' found, but LLC coloring is disabled\n" );#endif +if (IS_ENABLED (CONFIG_XSM_FLASK ) && + !dt_property_read_string (node,"seclabel" , &xsm_seclabel) ) + { +if (security_context_to_sid (xsm_seclabel,strlen (xsm_seclabel), + &d_cfg->ssidref) ) +panic ("Invalid security context for domain: %s\n" , xsm_seclabel); + } +return arch_parse_dom0less_node (node, bd); }
Signature · 1 line
2.43.0
Re: [PATCH v1 2/2] common: dom0less-bindings: introduce XSM labels
Quoted 82 lines · Sergiy Kibrik
Add "seclabel" property to be able to specify security label for a domain when XSM Flask is enabled, similar to xl configuration files.
Currently guest domain can't be created by Xen in dom0less configuration when Flask is enabled, as domain is assigned "system_u:system_r:unlabeled_t" label by default, which Flask denies to create according to current policy.
Signed-off-by Sergiy Kibrik <[email protected]>--- docs/misc/arm/device-tree/booting.txt | 8 ++++++++ xen/common/device-tree/Makefile | 2 ++ xen/common/device-tree/dom0less-bindings.c | 11 +++++++++++ 3 files changed, 21 insertions(+)docs/misc/arm/device-tree/booting.txt +8
-0@@ -345,6 +345,12 @@ with the following properties: not passed. This configuration requires static allocation (xen,static-mem) and direct mapping (direct-map). +- seclabel + + A string property specifying an XSM security label to this domain. Effective + only when FLASK is enabled. Domains will be classified “unlabeled” if + this property not specified. + Under the "xen,domain" compatible node, one or more sub-nodes are present for the DomU kernel and ramdisk.@@ -422,6 +428,7 @@ chosen { memory = <0 131072>; cpus = <2>; vpl011; + seclabel = "system_u:system_r:domU_t"; vcpu0 { compatible = "xen,vcpu";@@ -453,6 +460,7 @@ chosen { #size-cells = <0x1>; memory = <0 65536>; cpus = <1>; + seclabel = "system_u:system_r:domU_t"; module@0x4c000000 { compatible = "multiboot,kernel", "multiboot,module";xen/common/device-tree/Makefile +2
-0@@ -11,3 +11,5 @@ obj-$(CONFIG_DOMAIN_BUILD_HELPERS) += kernel.o obj-$(CONFIG_STATIC_EVTCHN) += static-evtchn.init.o obj-$(CONFIG_STATIC_MEMORY) += static-memory.init.o obj-$(CONFIG_STATIC_SHM) += static-shmem.init.o + +CFLAGS-y += -I$(srctree)/xsm/flask/includexen/common/device-tree/dom0less-bindings.c +3
-0@@ -11,6 +11,8 @@#include <public/bootfdt.h> #include <public/domctl.h> +#include <security.h> +int __init parse_dom0less_node (struct dt_device_node *node,struct boot_domain *bd) {@@ -21,6 +23,7 @@ int __init parse_dom0less_node(struct dt_device_node *node,bool has_dtb = false;bool iommu = false;const char *dom0less_iommu =NULL ; +const char *xsm_seclabel =NULL ;if ( !dt_device_is_compatible (node,"xen,domain" ) )return -ENOENT ;@@ -141,5 +144,13 @@ int __init parse_dom0less_node(struct dt_device_node *node,panic ("'llc-colors' found, but LLC coloring is disabled\n" );#endif
xen/common/device-tree/dom0less-bindings.c int __init parse_dom0less_node(struct dt_device_node *node, · line 156
Quoted 10 lines
xen/common/device-tree/dom0less-bindings.c +8
-0+if (IS_ENABLED (CONFIG_XSM_FLASK ) && + !dt_property_read_string (node,"seclabel" , &xsm_seclabel) ) + { +if (security_context_to_sid (xsm_seclabel,strlen (xsm_seclabel), + &d_cfg->ssidref) ) +panic ("Invalid security context for domain: %s\n" , xsm_seclabel); + } +return arch_parse_dom0less_node (node, bd); }
Re: [PATCH v1 2/2] common: dom0less-bindings: introduce XSM labels
In reply to Sergiy KibrikQuoted 15 lines · Sergiy Kibrik
xen/common/device-tree/Makefile +2
-0@@ -11,3 +11,5 @@ obj-$(CONFIG_DOMAIN_BUILD_HELPERS) += kernel.o obj-$(CONFIG_STATIC_EVTCHN) += static-evtchn.init.o obj-$(CONFIG_STATIC_MEMORY) += static-memory.init.o obj-$(CONFIG_STATIC_SHM) += static-shmem.init.o + +CFLAGS-y += -I$(srctree)/xsm/flask/includexen/common/device-tree/dom0less-bindings.c +0
-0
xen/common/device-tree/dom0less-bindings.c line 15
Quoted 5 lines
xen/common/device-tree/dom0less-bindings.c +2
-0@@ -11,6 +11,8 @@#include <public/bootfdt.h> #include <public/domctl.h> +#include <security.h> +
security.h is a private header for internals of flask. Requiring the CFLAGS += -I should have been a hint.
If a suitable public function doesn't exist, then make one rather than inserting a layering violation.
To this specifically, I'm not sure security_context_to_sid() handing out SECINITSID_XEN if you happen to call it too early is the wisest behaviour. It's current call-chain has an earlier check which I think excludes this from occurring.
~Andrew
Re: [PATCH v1 2/2] common: dom0less-bindings: introduce XSM labels
Quoted 4 lines · Andrew Cooper
To this specifically, I'm not sure
security_context_to_sid()handing outSECINITSID_XENif you happen to call it too early is the wisest behaviour. It's current call-chain has an earlier check which I think excludes this from occurring.
It's only call-chain is in FLASK_CONTEXT_TO_SID xsm_op handling, and it does return SECINITSID_XEN to toolstack if called before policy is loaded (I've tried booting with flask=late).
But what's the point of falling back to SECINITSID_XEN anyway?
-Sergiy