Skip to contentSkip to conversation

Add build-id to XENVER hypercall.

PATCH Superseded Konrad Rzeszutek Wilk 4 participants 20 messages Nov 6, 2015 – Jan 12, 2016

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Add build-id to XENVER hypercall.

Since v1 (http://lists.xen.org/archives/html/xen-devel/2015-10/msg01090.html)
- Made it work on EFI
- Compiles on ARM
- Redid it per comments.

Attached are the three patches that will add XENVER_build_id and add the proper bits in libxl/libxc.

However they also change the behavior of the existing hypercall for XENVER_[compile_info|changeset|commandline|extraversion] - that is they return the string '<denied>'.

This is with XSM enabled or disabled.

The new sub-ops - XENVER_build_id on the other hand will return -EPERM (XSM or not) for !priv guests.

Please take a look and provide your feedback at your leisure.

 tools/flask/policy/policy/modules/xen/xen.te |  9 +++++
 tools/libxc/xc_private.c                     |  7 ++++
 tools/libxc/xc_private.h                     | 10 ++++++
 tools/libxl/libxl.c                          | 24 +++++++++++++
 tools/libxl/libxl.h                          |  5 +++
 tools/libxl/libxl_types.idl                  |  1 +
 tools/libxl/xl_cmdimpl.c                     |  1 +
 xen/arch/x86/Makefile                        | 14 +++++---
 xen/arch/x86/xen.lds.S                       |  6 ++++
 xen/common/kernel.c                          | 54 +++++++++++++++++++++++-----
 xen/common/version.c                         | 41 +++++++++++++++++++++
 xen/include/public/version.h                 | 15 +++++++-
 xen/include/xen/version.h                    |  2 ++
 xen/include/xsm/dummy.h                      | 18 ++++++++++
 xen/include/xsm/xsm.h                        |  6 ++++
 xen/xsm/dummy.c                              |  1 +
 xen/xsm/flask/hooks.c                        | 22 ++++++++++++
 xen/xsm/flask/policy/access_vectors          |  4 +++
 18 files changed, 226 insertions(+), 14 deletions(-)

Konrad Rzeszutek Wilk (2):
xsm/xen_version: Add XSM for the xen_version hypercall.
libxl: info: Display build_id of the hypervisor.

Martin Pohlack (1):
XENVER_build_id: Provide ld-embedded build-ids

#1 lore raw

PATCH v2 1/3 xsm/xen_version: Add XSM for the xen_version hypercall.

All of XENVER_* have now an XSM check.

The subops for XENVER_[compile_info|changeset|commandline| extraversion] are now priviliged operations. To not break guests we still return an string - but it is just '<denied>'.

The rest: XENVER_[version|capabilities| parameters|get_features|page_size|guest_handle] behave as before - allowed by default for all guests.

This is with the XSM default policy and with the dummy ones.

---
v2: Do XSM check for all the XENVER_ ops.
v3: Add empty data conditions.
v4: Return <denied> for priv subops.

---
 tools/flask/policy/policy/modules/xen/xen.te |  9 +++++++++
 xen/common/kernel.c                          | 25 +++++++++++++++++--------
 xen/common/version.c                         |  5 +++++
 xen/include/xen/version.h                    |  1 +
 xen/include/xsm/dummy.h                      | 18 ++++++++++++++++++
 xen/include/xsm/xsm.h                        |  6 ++++++
 xen/xsm/dummy.c                              |  1 +
 xen/xsm/flask/hooks.c                        | 22 ++++++++++++++++++++++
 xen/xsm/flask/policy/access_vectors          |  4 ++++
 9 files changed, 83 insertions(+), 8 deletions(-)
tools/flask/policy/policy/modules/xen/xen.te +9 -0
index d35ae22..1ca0e65 100644
@@ -73,6 +73,12 @@ allow dom0_t xen_t:xen2 {
     pmu_ctrl
     get_symbol
 };
+
+# Allow dom0 to use XENVER_compile_info|changeset|commandline]extraversion
+allow dom0_t xen_t:xen2 {
+    version_priv
+};
+
 allow dom0_t xen_t:mmu memorymap;
 
 # Allow dom0 to use these domctls on itself. For domctls acting on other
@@ -137,6 +143,9 @@ if (guest_writeconsole) {
 # pmu_ctrl is for)
 allow domain_type xen_t:xen2 pmu_use;
 
+# All all domains to use (unprivileged parts of) the XENVER_* hypercall
+allow domain_type xen_t:domain2 version_use;
+
 ###############################################################################
 #
 # Domain creation
xen/common/kernel.c +17 -8
index 6a3196a..d51a3ed 100644
@@ -13,6 +13,7 @@
 #include <xen/nmi.h>
 #include <xen/guest_access.h>
 #include <xen/hypercall.h>
+#include <xsm/xsm.h>
 #include <asm/current.h>
 #include <public/nmi.h>
 #include <public/version.h>
@@ -226,9 +227,10 @@ void __init do_initcalls(void)
 /*
  * Simple hypercalls.
  */
-
 DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
+    bool_t deny = !!xsm_version_op(XSM_HOOK, cmd);
+
     switch ( cmd )
     {
     case XENVER_version:
@@ -239,7 +241,7 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         xen_extraversion_t extraversion;
 
         memset(extraversion, 0, sizeof(extraversion));
-        safe_strcpy(extraversion, xen_extra_version());
+        safe_strcpy(extraversion, deny ? xen_deny() : xen_extra_version());
         if ( copy_to_guest(arg, extraversion, ARRAY_SIZE(extraversion)) )
             return -EFAULT;
         return 0;
@@ -250,10 +252,10 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         xen_compile_info_t info;
 
         memset(&info, 0, sizeof(info));
-        safe_strcpy(info.compiler,       xen_compiler());
-        safe_strcpy(info.compile_by,     xen_compile_by());
-        safe_strcpy(info.compile_domain, xen_compile_domain());
-        safe_strcpy(info.compile_date,   xen_compile_date());
+        safe_strcpy(info.compiler,       deny ? xen_deny() : xen_compiler());
+        safe_strcpy(info.compile_by,     deny ? xen_deny() : xen_compile_by());
+        safe_strcpy(info.compile_domain, deny ? xen_deny() : xen_compile_domain());
+        safe_strcpy(info.compile_date,   deny ? xen_deny() : xen_compile_date());
         if ( copy_to_guest(arg, &info, 1) )
             return -EFAULT;
         return 0;
@@ -288,7 +290,7 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         xen_changeset_info_t chgset;
 
         memset(chgset, 0, sizeof(chgset));
-        safe_strcpy(chgset, xen_changeset());
+        safe_strcpy(chgset, deny ? xen_deny() : xen_changeset());
         if ( copy_to_guest(arg, chgset, ARRAY_SIZE(chgset)) )
             return -EFAULT;
         return 0;
@@ -354,10 +356,17 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         return 0;
 
     case XENVER_commandline:
-        if ( copy_to_guest(arg, saved_cmdline, ARRAY_SIZE(saved_cmdline)) )
+    {
+        size_t len = ARRAY_SIZE(saved_cmdline);
+
+        if ( deny )
+            len = strlen(xen_deny());
+
+        if ( copy_to_guest(arg, deny ? xen_deny() : saved_cmdline, len) )
             return -EFAULT;
         return 0;
     }
+    }
 
     return -ENOSYS;
 }
xen/common/version.c +5 -0
index b152e27..786be4e 100644
@@ -55,3 +55,8 @@ const char *xen_banner(void)
 {
     return XEN_BANNER;
 }
+
+const char *xen_deny(void)
+{
+    return "<denied>";
+}
xen/include/xen/version.h +1 -0
index 81a3c7d..2015c0b 100644
@@ -12,5 +12,6 @@ unsigned int xen_minor_version(void);
 const char *xen_extra_version(void);
 const char *xen_changeset(void);
 const char *xen_banner(void);
+const char *xen_deny(void);
 
 #endif /* __XEN_VERSION_H__ */
xen/include/xsm/dummy.h +18 -0
index 9fe372c..5088462 100644
@@ -721,3 +721,21 @@ static XSM_INLINE int xsm_pmu_op (XSM_DEFAULT_ARG struct domain *d, unsigned int
 }
 
 #endif /* CONFIG_X86 */
+
+#include <public/version.h>
+static XSM_INLINE int xsm_version_op (XSM_DEFAULT_ARG uint32_t op)
+{
+    XSM_ASSERT_ACTION(XSM_HOOK);
+    switch ( op )
+    {
+    case XENVER_version:
+    case XENVER_capabilities:
+    case XENVER_platform_parameters:
+    case XENVER_get_features:
+    case XENVER_pagesize:
+    case XENVER_guest_handle:
+        return xsm_default_action(XSM_HOOK, current->domain, NULL);
+    default:
+        return xsm_default_action(XSM_PRIV, current->domain, NULL);
+    }
+}
xen/include/xsm/xsm.h +6 -0
index ba3caed..e038cbd 100644
@@ -191,6 +191,7 @@ struct xsm_operations {
     int (*ioport_mapping) (struct domain *d, uint32_t s, uint32_t e, uint8_t allow);
     int (*pmu_op) (struct domain *d, unsigned int op);
 #endif
+    int (*version_op) (uint32_t cmd);
 };
 
 #ifdef XSM_ENABLE
@@ -729,6 +730,11 @@ static inline int xsm_pmu_op (xsm_default_t def, struct domain *d, unsigned int
 
 #endif /* CONFIG_X86 */
 
+static inline int xsm_version_op (xsm_default_t def, uint32_t op)
+{
+    return xsm_ops->version_op(op);
+}
+
 #endif /* XSM_NO_WRAPPERS */
 
 #ifdef CONFIG_MULTIBOOT
xen/xsm/dummy.c +1 -0
index 72eba40..6105c07 100644
@@ -162,4 +162,5 @@ void xsm_fixup_ops (struct xsm_operations *ops)
     set_to_dummy_if_null(ops, ioport_mapping);
     set_to_dummy_if_null(ops, pmu_op);
 #endif
+    set_to_dummy_if_null(ops, version_op);
 }
xen/xsm/flask/hooks.c +22 -0
index 4180f3b..d2b915e 100644
@@ -26,6 +26,7 @@
 #include <public/xen.h>
 #include <public/physdev.h>
 #include <public/platform.h>
+#include <public/version.h>
 
 #include <public/xsm/flask_op.h>
 
@@ -1621,6 +1622,26 @@ static int flask_pmu_op (struct domain *d, unsigned int op)
 }
 #endif /* CONFIG_X86 */
 
+static int flask_version_op (uint32_t op)
+{
+    u32 dsid = domain_sid(current->domain);
+
+    switch ( op )
+    {
+    case XENVER_version:
+    case XENVER_capabilities:
+    case XENVER_platform_parameters:
+    case XENVER_get_features:
+    case XENVER_pagesize:
+    case XENVER_guest_handle:
+        return avc_has_perm(dsid, SECINITSID_XEN, SECCLASS_DOMAIN2,
+                            DOMAIN2__VERSION_USE, NULL);
+    default:
+        return avc_has_perm(dsid, SECINITSID_XEN, SECCLASS_XEN2,
+                            XEN2__VERSION_PRIV, NULL);
+    }
+}
+
 long do_flask_op(XEN_GUEST_HANDLE_PARAM(xsm_op_t) u_flask_op);
 int compat_flask_op(XEN_GUEST_HANDLE_PARAM(xsm_op_t) u_flask_op);
 
@@ -1759,6 +1780,7 @@ static struct xsm_operations flask_ops = {
     .ioport_mapping = flask_ioport_mapping,
     .pmu_op = flask_pmu_op,
 #endif
+    .version_op = flask_version_op,
 };
 
 static __init void flask_init(void)
xen/xsm/flask/policy/access_vectors +4 -0
index effb59f..273459f 100644
@@ -93,6 +93,8 @@ class xen2
     pmu_ctrl
 # PMU use (domains, including unprivileged ones, will be using this operation)
     pmu_use
+# XENVER_[compile_info|changeset|commandline|extraversion] usage.
+   version_priv
 }
 
 # Classes domain and domain2 consist of operations that a domain performs on
@@ -242,6 +244,8 @@ class domain2
     mem_sharing
 # XEN_DOMCTL_psr_cat_op
     psr_cat_op
+# XENVER_[version|capabilities|parameters|get_features|page_size|guest_handle].
+    version_use
 }
 
 # Similar to class domain, but primarily contains domctls related to HVM domains
Signature · 1 line
2.1.0
#2 lore raw

Re: [PATCH v2 1/3] xsm/xen_version: Add XSM for the xen_version hypercall.

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 06.11.15 at 20:36, <[email protected]> wrote:

All of XENVER_* have now an XSM check.

The subops for XENVER_[compile_info|changeset|commandline| extraversion] are now priviliged operations. To not break guests we still return an string - but it is just '<denied>'.

And I continue to question at least the extraversion part.

Quoted 5 lines

The rest: XENVER_[version|capabilities| parameters|get_features|page_size|guest_handle] behave as before - allowed by default for all guests.

This is with the XSM default policy and with the dummy ones.

And with a non-default policy you now ignore one of the latter ops to also get denied.

xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 363

Quoted 10 lines
xen/common/kernel.c +5 -1
@@ -354,10 +356,17 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         return 0;
 
     case XENVER_commandline:
-        if ( copy_to_guest(arg, saved_cmdline, ARRAY_SIZE(saved_cmdline)) )
+    {
+        size_t len = ARRAY_SIZE(saved_cmdline);
+
+        if ( deny )
+            len = strlen(xen_deny());

+1 (or else you fail to nul-terminate the output).

Jan

#3 lore raw

Re: [PATCH v2 1/3] xsm/xen_version: Add XSM for the xen_version hypercall.

Quoted 8 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 06.11.15 at 20:36, <[email protected]> wrote:

All of XENVER_* have now an XSM check.

The subops for XENVER_[compile_info|changeset|commandline| extraversion] are now priviliged operations. To not break guests we still return an string - but it is just '<denied>'.

And I continue to question at least the extraversion part.

How about I remove the extraversion part from this patch and we can discuss putting 'extraversion' in the blacklist around another patch.

Quoted 9 lines
Quoted 6 lines

The rest: XENVER_[version|capabilities| parameters|get_features|page_size|guest_handle] behave as before - allowed by default for all guests.

This is with the XSM default policy and with the dummy ones.

And with a non-default policy you now ignore one of the latter ops to also get denied.

No, but that is due to the 'deny' being only checked for certain subops.

I think what you are saying is that for XENVER_[version|capabilities| parameters|get_features|page_size|guest_handle] we should not have any XSM checks as they serve no purpose (which is what I had in the earlier versions of this patch). However Andrew mentioned that he would like _ALL_ of the sub-ops to be checked for.

It feels like I am back to square one :-)

My feeling is that those subops I mentioned should have no XSM checks at all so nobody can mess that up (thought it was fun messing that up).

However Andrew did not like that, but you seem to imply you like that.

Could you two hash out which way you would like this?

Quoted 4 lines
Quoted 4 lines
(quoted diff) +0 -0
@@ -354,10 +356,17 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         return 0;
 
Quoted 9 lines

xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 363

Quoted 7 lines
xen/common/kernel.c +5 -1
     case XENVER_commandline:
-        if ( copy_to_guest(arg, saved_cmdline, ARRAY_SIZE(saved_cmdline)) )
+    {
+        size_t len = ARRAY_SIZE(saved_cmdline);
+
+        if ( deny )
+            len = strlen(xen_deny());

+1 (or else you fail to nul-terminate the output).

Nice spotting!
Perhaps modifying xen_deny() to be:

const char *xen_deny(void)

{
    return "<denied>\0";
}

Would be better?

As this 'len' +1 would lead me to copy one byte extra from the .rodata section where "<denied>" resides leaking to some information leak.

Quoted 2 lines

Jan

#4 lore raw

Re: [PATCH v2 1/3] xsm/xen_version: Add XSM for the xen_version hypercall.

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 06.01.16 at 18:41, <[email protected]> wrote:
Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 06.11.15 at 20:36, <[email protected]> wrote:

All of XENVER_* have now an XSM check.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

The subops for XENVER_[compile_info|changeset|commandline| extraversion] are now priviliged operations. To not break guests we still return an string - but it is just '<denied>'.

And I continue to question at least the extraversion part.

How about I remove the extraversion part from this patch and we can discuss putting 'extraversion' in the blacklist around another patch.

Yes, that'd be a step towards me agreeing with the change. I'm not necessarily saying that's going to be enough, since I said "at least", i.e. I continue to wonder how relevant it really is to hide changeset and compile info (fwiw I agree with hiding the command line).

Quoted 10 lines
Quoted 8 lines
Quoted 5 lines

The rest: XENVER_[version|capabilities| parameters|get_features|page_size|guest_handle] behave as before - allowed by default for all guests.

This is with the XSM default policy and with the dummy ones.

And with a non-default policy you now ignore one of the latter ops to also get denied.

No, but that is due to the 'deny' being only checked for certain subops.

To me this reply seems contradictory in itself: The "no" doesn't seem to match up with the rest.

Quoted 5 lines

I think what you are saying is that for XENVER_[version|capabilities| parameters|get_features|page_size|guest_handle] we should not have any XSM checks as they serve no purpose (which is what I had in the earlier versions of this patch). However Andrew mentioned that he would like _ALL_ of the sub-ops to be checked for.

And I agree with Andrew, hence my earlier comment above (with the reply I can't really make sense of).

Quoted 16 lines
Quoted 12 lines

xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 363

Quoted 10 lines
xen/common/kernel.c +5 -1
@@ -354,10 +356,17 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         return 0;
 
     case XENVER_commandline:
-        if ( copy_to_guest(arg, saved_cmdline, ARRAY_SIZE(saved_cmdline)) )
+    {
+        size_t len = ARRAY_SIZE(saved_cmdline);
+
+        if ( deny )
+            len = strlen(xen_deny());

+1 (or else you fail to nul-terminate the output).

Nice spotting!
Perhaps modifying xen_deny() to be:

Quoted 6 lines

const char *xen_deny(void)

{
    return "<denied>\0";
}

Would be better?

This would just add a second NUL at the end, without altering what strlen() returns on that string.

Jan

#5 lore raw

Re: [PATCH v2 1/3] xsm/xen_version: Add XSM for the xen_version hypercall.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

The subops for XENVER_[compile_info|changeset|commandline| extraversion] are now priviliged operations. To not break guests we still return an string - but it is just '<denied>'.

And I continue to question at least the extraversion part.

Quoted 8 lines
Quoted 2 lines

How about I remove the extraversion part from this patch and we can discuss putting 'extraversion' in the blacklist around another patch.

Yes, that'd be a step towards me agreeing with the change. I'm not necessarily saying that's going to be enough, since I said "at least", i.e. I continue to wonder how relevant it really is to hide changeset and compile info (fwiw I agree with hiding the command line).

I made it now only return '<denied>' for the XENVER_commandline.

Quoted 15 lines
Quoted 11 lines
Quoted 9 lines
Quoted 6 lines

The rest: XENVER_[version|capabilities| parameters|get_features|page_size|guest_handle] behave as before - allowed by default for all guests.

This is with the XSM default policy and with the dummy ones.

And with a non-default policy you now ignore one of the latter ops to also get denied.

No, but that is due to the 'deny' being only checked for certain subops.

To me this reply seems contradictory in itself: The "no" doesn't seem to match up with the rest.

Quoted 8 lines
Quoted 5 lines

I think what you are saying is that for XENVER_[version|capabilities| parameters|get_features|page_size|guest_handle] we should not have any XSM checks as they serve no purpose (which is what I had in the earlier versions of this patch). However Andrew mentioned that he would like _ALL_ of the sub-ops to be checked for.

And I agree with Andrew, hence my earlier comment above (with the reply I can't really make sense of).

I am all confused now.

There are two parts here:
a) The XSM checks - which allow the XENVER_version..XENVER_guest_handle without any hinderance. For XENVER_commandline and XENVER_buildid they are evaluated.

b) Acting on the XSM check. For most of them we cannot actually return -EFAULT and MUST return either an valid value or some form of a string.

The ones for which we could return '<denied>' were changeset, compile_info, commandline, extraversion. To make it simpler we only do it for commandline.

In essence we have an XSM check which is ignored by all XENVER_ subops except commandline (and build_id in later patch).

I think both of you are OK with that?

Quoted 17 lines
Quoted 17 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0 -0
@@ -354,10 +356,17 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         return 0;
 
Quoted 9 lines

xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 363

Quoted 7 lines
xen/common/kernel.c +5 -1
     case XENVER_commandline:
-        if ( copy_to_guest(arg, saved_cmdline, ARRAY_SIZE(saved_cmdline)) )
+    {
+        size_t len = ARRAY_SIZE(saved_cmdline);
+
+        if ( deny )
+            len = strlen(xen_deny());

+1 (or else you fail to nul-terminate the output).

Nice spotting!
Perhaps modifying xen_deny() to be:

Quoted 8 lines
Quoted 6 lines

const char *xen_deny(void)

{
    return "<denied>\0";
}

Would be better?

This would just add a second NUL at the end, without altering what

Right. Sorry about that - the patch I had sent still includes the \0.

Quoted 4 lines

strlen() returns on that string

Jan

#6 lore raw

Re: [PATCH v2 1/3] xsm/xen_version: Add XSM for the xen_version hypercall.

Quoted 34 lines
Quoted 15 lines
Quoted 11 lines · On 08.01.16 at 18:31, <[email protected]> wrote:
Quoted 8 lines
Quoted 5 lines

The rest: XENVER_[version|capabilities| parameters|get_features|page_size|guest_handle] behave as before - allowed by default for all guests.

This is with the XSM default policy and with the dummy ones.

And with a non-default policy you now ignore one of the latter ops to also get denied.

No, but that is due to the 'deny' being only checked for certain subops.

To me this reply seems contradictory in itself: The "no" doesn't seem to match up with the rest.

Quoted 8 lines
Quoted 5 lines

I think what you are saying is that for XENVER_[version|capabilities| parameters|get_features|page_size|guest_handle] we should not have any XSM checks as they serve no purpose (which is what I had in the earlier versions of this patch). However Andrew mentioned that he would like _ALL_ of the sub-ops to be checked for.

And I agree with Andrew, hence my earlier comment above (with the reply I can't really make sense of).

I am all confused now.

There are two parts here:
a) The XSM checks - which allow the XENVER_version..XENVER_guest_handle without any hinderance. For XENVER_commandline and XENVER_buildid they are evaluated.

b) Acting on the XSM check. For most of them we cannot actually return -EFAULT and MUST return either an valid value or some form of a string.

Quoted 8 lines

The ones for which we could return '<denied>' were changeset, compile_info, commandline, extraversion. To make it simpler we only do it for commandline.

In essence we have an XSM check which is ignored by all XENVER_ subops except commandline (and build_id in later patch).

I think both of you are OK with that?

Iirc Andrew's request was to honor XSM denies on any sub-op when a non-default policy is in place. Whereas in default mode only command line and build id are the ones clearly needing restricting. Which won't be possible if you ignore the return value of the XSM check in some of the cases.

Jan

#7 lore raw

Re: [PATCH v2 1/3] xsm/xen_version: Add XSM for the xen_version hypercall.

Quoted 41 lines · Jan Beulich
Quoted 41 lines
Quoted 15 lines
Quoted 11 lines · On 08.01.16 at 18:31, <[email protected]> wrote:
Quoted 8 lines
Quoted 5 lines

The rest: XENVER_[version|capabilities| parameters|get_features|page_size|guest_handle] behave as before - allowed by default for all guests.

This is with the XSM default policy and with the dummy ones.

And with a non-default policy you now ignore one of the latter ops to also get denied.

No, but that is due to the 'deny' being only checked for certain subops.

To me this reply seems contradictory in itself: The "no" doesn't seem to match up with the rest.

Quoted 8 lines
Quoted 5 lines

I think what you are saying is that for XENVER_[version|capabilities| parameters|get_features|page_size|guest_handle] we should not have any XSM checks as they serve no purpose (which is what I had in the earlier versions of this patch). However Andrew mentioned that he would like _ALL_ of the sub-ops to be checked for.

And I agree with Andrew, hence my earlier comment above (with the reply I can't really make sense of).

I am all confused now.

There are two parts here:
a) The XSM checks - which allow the XENVER_version..XENVER_guest_handle without any hinderance. For XENVER_commandline and XENVER_buildid they are evaluated.

b) Acting on the XSM check. For most of them we cannot actually return -EFAULT and MUST return either an valid value or some form of a string.

The ones for which we could return '<denied>' were changeset, compile_info, commandline, extraversion. To make it simpler we only do it for commandline.

In essence we have an XSM check which is ignored by all XENVER_ subops except commandline (and build_id in later patch).

Quoted 7 lines
Quoted 1 line

I think both of you are OK with that?

Iirc Andrew's request was to honor XSM denies on any sub-op when a non-default policy is in place. Whereas in default mode only command line and build id are the ones clearly needing restricting. Which won't be possible if you ignore the return value of the XSM check in some of the cases.

That means we need two (as earlier patches had it) version labels. One for the command_line and build_id (version_priv) and one for the rest (version_use). By default version_use would be available to every guest. If a non-default policy wants to mess with it - that is OK.

Now comes the big question - for the XENVER_[version|capabilities| parameters|get_features|page_size|guest_handle] - if it is denied (so non-default version_use policy) - what should we return?

I can return '<denied>' for the strings, but what should we do for the page_size, capabilities and guest_handle ? -EPERM?

Or leave those out of the version_use check? (so do not act on XSM check on those?)

Quoted 3 lines

Jan

#8 lore raw

Re: [PATCH v2 1/3] xsm/xen_version: Add XSM for the xen_version hypercall.

Quoted 51 lines
Quoted 1 line
Quoted 1 line · On 11.01.16 at 17:01, <[email protected]> wrote:
Quoted 41 lines · Jan Beulich
Quoted 41 lines
Quoted 15 lines
Quoted 11 lines · On 08.01.16 at 18:31, <[email protected]> wrote:
Quoted 8 lines
Quoted 5 lines

The rest: XENVER_[version|capabilities| parameters|get_features|page_size|guest_handle] behave as before - allowed by default for all guests.

This is with the XSM default policy and with the dummy ones.

And with a non-default policy you now ignore one of the latter ops to also get denied.

No, but that is due to the 'deny' being only checked for certain subops.

To me this reply seems contradictory in itself: The "no" doesn't seem to match up with the rest.

Quoted 8 lines
Quoted 5 lines

I think what you are saying is that for XENVER_[version|capabilities| parameters|get_features|page_size|guest_handle] we should not have any XSM checks as they serve no purpose (which is what I had in the earlier versions of this patch). However Andrew mentioned that he would like _ALL_ of the sub-ops to be checked for.

And I agree with Andrew, hence my earlier comment above (with the reply I can't really make sense of).

I am all confused now.

There are two parts here:
a) The XSM checks - which allow the XENVER_version..XENVER_guest_handle without any hinderance. For XENVER_commandline and XENVER_buildid they are evaluated.

b) Acting on the XSM check. For most of them we cannot actually return -EFAULT and MUST return either an valid value or some form of a string.

The ones for which we could return '<denied>' were changeset, compile_info, commandline, extraversion. To make it simpler we only do it for commandline.

In essence we have an XSM check which is ignored by all XENVER_ subops except commandline (and build_id in later patch).

Quoted 7 lines
Quoted 1 line

I think both of you are OK with that?

Iirc Andrew's request was to honor XSM denies on any sub-op when a non-default policy is in place. Whereas in default mode only command line and build id are the ones clearly needing restricting. Which won't be possible if you ignore the return value of the XSM check in some of the cases.

Quoted 4 lines

That means we need two (as earlier patches had it) version labels. One for the command_line and build_id (version_priv) and one for the rest (version_use). By default version_use would be available to every guest. If a non-default policy wants to mess with it - that is OK.

That would seem a little too coarse grained. Why can't we keep it at the sub-op level, just that the default is "OK" for everything except the two?

Quoted 3 lines

Now comes the big question - for the XENVER_[version|capabilities| parameters|get_features|page_size|guest_handle] - if it is denied (so non-default version_use policy) - what should we return?

"<denied>" just like for the others that return strings; page_size and other numeric ones may need to return zero.

Quoted 2 lines

I can return '<denied>' for the strings, but what should we do for the page_size, capabilities and guest_handle ? -EPERM?

guest_handle is particularly interesting: It seems to make very little sense to deny a guest access to its own handle.

Jan

#9 lore raw

Re: [PATCH v2 1/3] xsm/xen_version: Add XSM for the xen_version hypercall.

Quoted 51 lines · Jan Beulich
Quoted 51 lines
Quoted 1 line
Quoted 1 line · On 11.01.16 at 17:01, <[email protected]> wrote:
Quoted 48 lines · Jan Beulich
Quoted 34 lines
Quoted 15 lines
Quoted 11 lines · On 08.01.16 at 18:31, <[email protected]> wrote:
Quoted 8 lines
Quoted 5 lines

The rest: XENVER_[version|capabilities| parameters|get_features|page_size|guest_handle] behave as before - allowed by default for all guests.

This is with the XSM default policy and with the dummy ones.

And with a non-default policy you now ignore one of the latter ops to also get denied.

No, but that is due to the 'deny' being only checked for certain subops.

To me this reply seems contradictory in itself: The "no" doesn't seem to match up with the rest.

Quoted 8 lines
Quoted 5 lines

I think what you are saying is that for XENVER_[version|capabilities| parameters|get_features|page_size|guest_handle] we should not have any XSM checks as they serve no purpose (which is what I had in the earlier versions of this patch). However Andrew mentioned that he would like _ALL_ of the sub-ops to be checked for.

And I agree with Andrew, hence my earlier comment above (with the reply I can't really make sense of).

I am all confused now.

There are two parts here:
a) The XSM checks - which allow the XENVER_version..XENVER_guest_handle without any hinderance. For XENVER_commandline and XENVER_buildid they are evaluated.

b) Acting on the XSM check. For most of them we cannot actually return -EFAULT and MUST return either an valid value or some form of a string.

Quoted 8 lines

The ones for which we could return '<denied>' were changeset, compile_info, commandline, extraversion. To make it simpler we only do it for commandline.

In essence we have an XSM check which is ignored by all XENVER_ subops except commandline (and build_id in later patch).

I think both of you are OK with that?

Iirc Andrew's request was to honor XSM denies on any sub-op when a non-default policy is in place. Whereas in default mode only command line and build id are the ones clearly needing restricting. Which won't be possible if you ignore the return value of the XSM check in some of the cases.

Quoted 8 lines
Quoted 4 lines

That means we need two (as earlier patches had it) version labels. One for the command_line and build_id (version_priv) and one for the rest (version_use). By default version_use would be available to every guest. If a non-default policy wants to mess with it - that is OK.

That would seem a little too coarse grained. Why can't we keep it at the sub-op level, just that the default is "OK" for everything except the two?

So you thinking have a whole new XSM 'class' for this hypercall?

As in (not compile tested of course):

tools/flask/policy/policy/modules/xen/xen.te +7 -0
index 17f304e..fca5809 100644
@@ -141,6 +141,13 @@ if (guest_writeconsole) {
 # pmu_ctrl is for)
 allow domain_type xen_t:xen2 pmu_use;
 
+allow dom0_t version:domain {
+    version parameters ... commandline build_id
+};
+allow domain_type version:domain {
+    version parameters ...
+}
+
 ###############################################################################
 #
 # Domain creation
xen/xsm/flask/policy/access_vectors +12 -0
index c123256..4b20d08 100644
@@ -246,6 +246,18 @@ class domain2
     psr_cat_op
 }
 
+# defined by XENVER_hypercall
+class xenver
+{
+# XENVER_version
+    version
+# XENVER_parameters
+    parameters
+# ... snip..
+    commandline
+    build_id
+}
+
 # Similar to class domain, but primarily contains domctls related to HVM domains
 class hvm
 {
Quoted 16 lines
Quoted 4 lines

Now comes the big question - for the XENVER_[version|capabilities| parameters|get_features|page_size|guest_handle] - if it is denied (so non-default version_use policy) - what should we return?

"<denied>" just like for the others that return strings; page_size and other numeric ones may need to return zero.

Quoted 2 lines

I can return '<denied>' for the strings, but what should we do for the page_size, capabilities and guest_handle ? -EPERM?

guest_handle is particularly interesting: It seems to make very little sense to deny a guest access to its own handle.

Jan

#10 lore raw

Re: [PATCH v2 1/3] xsm/xen_version: Add XSM for the xen_version hypercall.

Quoted 59 lines
Quoted 1 line
Quoted 1 line · On 12.01.16 at 17:37, <[email protected]> wrote:
Quoted 33 lines · Jan Beulich
Quoted 33 lines
Quoted 1 line
Quoted 1 line · On 11.01.16 at 17:01, <[email protected]> wrote:
Quoted 31 lines · Jan Beulich
Quoted 31 lines
Quoted 15 lines
Quoted 11 lines · On 08.01.16 at 18:31, <[email protected]> wrote:
Quoted 8 lines
Quoted 5 lines

The rest: XENVER_[version|capabilities| parameters|get_features|page_size|guest_handle] behave as before - allowed by default for all guests.

This is with the XSM default policy and with the dummy ones.

And with a non-default policy you now ignore one of the latter ops to also get denied.

No, but that is due to the 'deny' being only checked for certain subops.

To me this reply seems contradictory in itself: The "no" doesn't seem to match up with the rest.

Quoted 8 lines
Quoted 5 lines

I think what you are saying is that for XENVER_[version|capabilities| parameters|get_features|page_size|guest_handle] we should not have any XSM checks as they serve no purpose (which is what I had in the earlier versions of this patch). However Andrew mentioned that he would like _ALL_ of the sub-ops to be checked for.

And I agree with Andrew, hence my earlier comment above (with the reply I can't really make sense of).

I am all confused now.

There are two parts here:
a) The XSM checks - which allow the XENVER_version..XENVER_guest_handle without any hinderance. For XENVER_commandline and XENVER_buildid they are evaluated.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

b) Acting on the XSM check. For most of them we cannot actually return -EFAULT and MUST return either an valid value or some form of a string.

The ones for which we could return '<denied>' were changeset,

compile_info,

Quoted 19 lines
Quoted 18 lines
Quoted 6 lines
Quoted 6 lines

commandline, extraversion. To make it simpler we only do it for commandline.

In essence we have an XSM check which is ignored by all XENVER_ subops except commandline (and build_id in later patch).

Quoted 7 lines
Quoted 1 line

I think both of you are OK with that?

Iirc Andrew's request was to honor XSM denies on any sub-op when a non-default policy is in place. Whereas in default mode only command line and build id are the ones clearly needing restricting. Which won't be possible if you ignore the return value of the XSM check in some of the cases.

That means we need two (as earlier patches had it) version labels. One for the command_line and build_id (version_priv) and one for the rest (version_use). By default version_use would be available to every guest. If a non-default policy wants to mess with it - that is OK.

Quoted 5 lines
Quoted 3 lines

That would seem a little too coarse grained. Why can't we keep it at the sub-op level, just that the default is "OK" for everything except the two?

So you thinking have a whole new XSM 'class' for this hypercall?

Yes, subject to Daniel's input it seems to me that's the only way providing the necessary granularity.

Jan

#11 lore raw

Re: [PATCH v2 1/3] xsm/xen_version: Add XSM for the xen_version hypercall.

In reply to Konrad Rzeszutek Wilk
Quoted 6 lines · Konrad Rzeszutek Wilk

All of XENVER_* have now an XSM check.

The subops for XENVER_[compile_info|changeset|commandline| extraversion] are now priviliged operations. To not break guests we still return an string - but it is just '<denied>'.

Quoted 7 lines

The rest: XENVER_[version|capabilities| parameters|get_features|page_size|guest_handle] behave as before - allowed by default for all guests.

This is with the XSM default policy and with the dummy ones.

Comments below, inline.

[...]

Quoted 7 lines
tools/flask/policy/policy/modules/xen/xen.te +0 -0
index d35ae22..1ca0e65 100644
@@ -73,6 +73,12 @@ allow dom0_t xen_t:xen2 {
      pmu_ctrl
      get_symbol

tools/flask/policy/policy/modules/xen/xen.te allow dom0_t xen_t:xen2 { · line 84

Quoted 10 lines
tools/flask/policy/policy/modules/xen/xen.te +6 -0
  };
+
+# Allow dom0 to use XENVER_compile_info|changeset|commandline]extraversion
+allow dom0_t xen_t:xen2 {
+    version_priv
+};
+
  allow dom0_t xen_t:mmu memorymap;
 
  # Allow dom0 to use these domctls on itself. For domctls acting on other

Minor tweak: if you don't want to add the new to the block a few lines above, the one-line permission syntax without braces (as seen below) looks better.

[...]

tools/flask/policy/policy/modules/xen/xen.te

Quoted 4 lines
  DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
  {
tools/flask/policy/policy/modules/xen/xen.te +2 -0
+    bool_t deny = !!xsm_version_op(XSM_HOOK, cmd);
+

Since this call produces denials in the default policy, it should be marked as XSM_OTHER.

Quoted 15 lines
xen/xsm/flask/policy/access_vectors +2 -0
index effb59f..273459f 100644
@@ -93,6 +93,8 @@ class xen2
      pmu_ctrl
  # PMU use (domains, including unprivileged ones, will be using this operation)
      pmu_use
+# XENVER_[compile_info|changeset|commandline|extraversion] usage.
+   version_priv
  }
 
  # Classes domain and domain2 consist of operations that a domain performs on

xen/xsm/flask/policy/access_vectors class domain2 · line 251

Quoted 8 lines
xen/xsm/flask/policy/access_vectors +2 -0
@@ -242,6 +244,8 @@ class domain2
      mem_sharing
  # XEN_DOMCTL_psr_cat_op
      psr_cat_op
+# XENVER_[version|capabilities|parameters|get_features|page_size|guest_handle].
+    version_use
  }
 
  # Similar to class domain, but primarily contains domctls related to HVM domains

I think that both version_priv and version_use belong in the same access vector (xen2) rather than placing version_use in domain2.

Signature · 2 lines
Daniel De Graaf
National Security Agency
#12 lore raw

Re: [PATCH v2 1/3] xsm/xen_version: Add XSM for the xen_version hypercall.

Quoted 34 lines · Daniel De Graaf
Quoted 6 lines · Konrad Rzeszutek Wilk

All of XENVER_* have now an XSM check.

The subops for XENVER_[compile_info|changeset|commandline| extraversion] are now priviliged operations. To not break guests we still return an string - but it is just '<denied>'.

Quoted 7 lines

The rest: XENVER_[version|capabilities| parameters|get_features|page_size|guest_handle] behave as before - allowed by default for all guests.

This is with the XSM default policy and with the dummy ones.

Comments below, inline.

[...]

Quoted 16 lines
tools/flask/policy/policy/modules/xen/xen.te +6 -0
index d35ae22..1ca0e65 100644
@@ -73,6 +73,12 @@ allow dom0_t xen_t:xen2 {
     pmu_ctrl
     get_symbol
 };
+
+# Allow dom0 to use XENVER_compile_info|changeset|commandline]extraversion
+allow dom0_t xen_t:xen2 {
+    version_priv
+};
+
 allow dom0_t xen_t:mmu memorymap;
 
Quoted 4 lines

tools/flask/policy/policy/modules/xen/xen.te allow dom0_t xen_t:xen2 { · line 84

Quoted 1 line
tools/flask/policy/policy/modules/xen/xen.te +0 -0
 # Allow dom0 to use these domctls on itself. For domctls acting on other

Minor tweak: if you don't want to add the new to the block a few lines above, the one-line permission syntax without braces (as seen below) looks better.

OK.

Quoted 9 lines

[...]

tools/flask/policy/policy/modules/xen/xen.te

Quoted 4 lines

DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) {

tools/flask/policy/policy/modules/xen/xen.te +2 -0
+    bool_t deny = !!xsm_version_op(XSM_HOOK, cmd);
+

Since this call produces denials in the default policy, it should be marked as XSM_OTHER.

<nods>

Quoted 22 lines
Quoted 22 lines
xen/xsm/flask/policy/access_vectors +4 -0
index effb59f..273459f 100644
@@ -93,6 +93,8 @@ class xen2
     pmu_ctrl
 # PMU use (domains, including unprivileged ones, will be using this operation)
     pmu_use
+# XENVER_[compile_info|changeset|commandline|extraversion] usage.
+   version_priv
 }
 
 # Classes domain and domain2 consist of operations that a domain performs on
@@ -242,6 +244,8 @@ class domain2
     mem_sharing
 # XEN_DOMCTL_psr_cat_op
     psr_cat_op
+# XENVER_[version|capabilities|parameters|get_features|page_size|guest_handle].
+    version_use
 }
 
Quoted 5 lines

xen/xsm/flask/policy/access_vectors class domain2 · line 251

Quoted 2 lines
xen/xsm/flask/policy/access_vectors +0 -0
 # Similar to class domain, but primarily contains domctls related to HVM domains

I think that both version_priv and version_use belong in the same access vector (xen2) rather than placing version_use in domain2.

OK, it just that the 'xen2' says: "Class xen and xen2 consists of dom0-only operations dealing with the hypervisor itself." (from access_vectors) - hence the split in using domain2 and xen2.

Quoted 4 lines
Signature · 3 lines
-- 
Daniel De Graaf
National Security Agency
#13 lore raw

Re: [PATCH v2 1/3] xsm/xen_version: Add XSM for the xen_version hypercall.

In reply to Daniel De Graaf
Quoted 34 lines · Daniel De Graaf
Quoted 6 lines · Konrad Rzeszutek Wilk

All of XENVER_* have now an XSM check.

The subops for XENVER_[compile_info|changeset|commandline| extraversion] are now priviliged operations. To not break guests we still return an string - but it is just '<denied>'.

Quoted 7 lines

The rest: XENVER_[version|capabilities| parameters|get_features|page_size|guest_handle] behave as before - allowed by default for all guests.

This is with the XSM default policy and with the dummy ones.

Comments below, inline.

[...]

Quoted 16 lines
tools/flask/policy/policy/modules/xen/xen.te +6 -0
index d35ae22..1ca0e65 100644
@@ -73,6 +73,12 @@ allow dom0_t xen_t:xen2 {
     pmu_ctrl
     get_symbol
 };
+
+# Allow dom0 to use XENVER_compile_info|changeset|commandline]extraversion
+allow dom0_t xen_t:xen2 {
+    version_priv
+};
+
 allow dom0_t xen_t:mmu memorymap;
 
Quoted 4 lines

tools/flask/policy/policy/modules/xen/xen.te allow dom0_t xen_t:xen2 { · line 84

Quoted 1 line
tools/flask/policy/policy/modules/xen/xen.te +0 -0
 # Allow dom0 to use these domctls on itself. For domctls acting on other

Minor tweak: if you don't want to add the new to the block a few lines above, the one-line permission syntax without braces (as seen below) looks better.

<nods>

Quoted 9 lines

[...]

tools/flask/policy/policy/modules/xen/xen.te

Quoted 4 lines

DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) {

tools/flask/policy/policy/modules/xen/xen.te +2 -0
+    bool_t deny = !!xsm_version_op(XSM_HOOK, cmd);
+

Since this call produces denials in the default policy, it should be marked as XSM_OTHER.

<nods>

Quoted 22 lines
Quoted 22 lines
xen/xsm/flask/policy/access_vectors +4 -0
index effb59f..273459f 100644
@@ -93,6 +93,8 @@ class xen2
     pmu_ctrl
 # PMU use (domains, including unprivileged ones, will be using this operation)
     pmu_use
+# XENVER_[compile_info|changeset|commandline|extraversion] usage.
+   version_priv
 }
 
 # Classes domain and domain2 consist of operations that a domain performs on
@@ -242,6 +244,8 @@ class domain2
     mem_sharing
 # XEN_DOMCTL_psr_cat_op
     psr_cat_op
+# XENVER_[version|capabilities|parameters|get_features|page_size|guest_handle].
+    version_use
 }
 
Quoted 5 lines

xen/xsm/flask/policy/access_vectors class domain2 · line 251

Quoted 2 lines
xen/xsm/flask/policy/access_vectors +0 -0
 # Similar to class domain, but primarily contains domctls related to HVM domains

I think that both version_priv and version_use belong in the same access vector (xen2) rather than placing version_use in domain2.

Ok, modified.

Quoted 4 lines
Signature · 3 lines
-- 
Daniel De Graaf
National Security Agency
#14 lore raw

PATCH v2 2/3 XENVER_build_id: Provide ld-embedded build-ids

In reply to Konrad Rzeszutek Wilk

From: Martin Pohlack <[email protected]>

The mechanism to get this is via the XENVER_build_id and we add a new subsequent sub-command to retrieve the binary build-id. The hypercall allows an arbitrary size (the buffer and len is provided to the hypervisor).

Note that one can also retrieve the value by 'readelf -h xen-syms'.

For EFI builds we re-use the same build-id that the xen-syms was built with.

Note that there are no changes to the XSM files (dummy.c and hooks.c) as the priviliged subops fall in the default case.

Since the new sub-ops provides the len parameter in the arguments to the hypercall we have to modify libxc to allow copying the arguments before the hypercall. We provide a new macro that modifies the bounce structure to change the direction.

---
v1: Rebase it on Martin's initial patch
v2: Move it to XENVER hypercall
v3: Fix EFI building (Ross's fix)
v4: Don't use the third argument for length.
v5: Use new structure for XENVER_build_id with variable buf.

---
 tools/libxc/xc_private.c            |  7 +++++++
 tools/libxc/xc_private.h            | 10 ++++++++++
 xen/arch/x86/Makefile               | 14 +++++++++-----
 xen/arch/x86/xen.lds.S              |  6 ++++++
 xen/common/kernel.c                 | 29 +++++++++++++++++++++++++++++
 xen/common/version.c                | 36 ++++++++++++++++++++++++++++++++++++
 xen/include/public/version.h        | 15 ++++++++++++++-
 xen/include/xen/version.h           |  1 +
 xen/xsm/flask/policy/access_vectors |  2 +-
 9 files changed, 113 insertions(+), 7 deletions(-)
tools/libxc/xc_private.c +7 -0
index 7c39897..9cd676e 100644
@@ -712,6 +712,13 @@ int xc_version(xc_interface *xch, int cmd, void *arg)
     case XENVER_commandline:
         sz = sizeof(xen_commandline_t);
         break;
+    case XENVER_build_id:
+        {
+            xen_build_id_t *build_id = (xen_build_id_t *)arg;
+            sz = sizeof(*build_id) + build_id->len;
+            HYPERCALL_BOUNCE_SET_DIR(arg, XC_HYPERCALL_BUFFER_BOUNCE_BOTH);
+            break;
+        }
     default:
         ERROR("xc_version: unknown command %d\n", cmd);
         return -EINVAL;
tools/libxc/xc_private.h +10 -0
index 2df1d59..aa0cad7 100644
@@ -202,6 +202,16 @@ enum {
 #define DECLARE_HYPERCALL_BOUNCE(_ubuf, _sz, _dir) DECLARE_NAMED_HYPERCALL_BOUNCE(_ubuf, _ubuf, _sz, _dir)
 
 /*
+ * Change the direction.
+ *
+ * Can only be used if the bounce_pre/bounce_post commands have
+ * not been used.
+ */
+#define HYPERCALL_BOUNCE_SET_DIR(_buf, _dir) do { if ((HYPERCALL_BUFFER(_buf))->hbuf)         \
+                                                        assert(1);                            \
+                                                   (HYPERCALL_BUFFER(_buf))->dir = _dir;      \
+                                                } while (0)
+/*
  * Set the size of data to bounce. Useful when the size is not known
  * when the bounce buffer is declared.
  */
xen/arch/x86/Makefile +9 -5
index d4e507a..17a4830 100644
@@ -109,15 +109,19 @@ $(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o
 	$(NM) -pa --format=sysv $(@D)/.$(@F).0 \
 		| $(BASEDIR)/tools/symbols --sysv --sort >$(@D)/.$(@F).0.S
 	$(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).0.o
-	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o \
+	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o --build-id=sha1 \
 	    $(@D)/.$(@F).0.o -o $(@D)/.$(@F).1
 	$(NM) -pa --format=sysv $(@D)/.$(@F).1 \
 		| $(BASEDIR)/tools/symbols --sysv --sort --warn-dup >$(@D)/.$(@F).1.S
 	$(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).1.o
-	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o \
+	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o --build-id=sha1 \
 	    $(@D)/.$(@F).1.o -o $@
 	rm -f $(@D)/.$(@F).[0-9]*
 
+build_id.o: $(TARGET)-syms
+	$(OBJCOPY) --only-section=.note.gnu.build-id $< build_id.o
+
+
 EFI_LDFLAGS = $(patsubst -m%,-mi386pep,$(LDFLAGS)) --subsystem=10
 EFI_LDFLAGS += --image-base=$(1) --stack=0,0 --heap=0,0 --strip-debug
 EFI_LDFLAGS += --section-alignment=0x200000 --file-alignment=0x20
@@ -130,7 +134,7 @@ $(TARGET).efi: VIRT_BASE = 0x$(shell $(NM) efi/relocs-dummy.o | sed -n 's, A VIR
 $(TARGET).efi: ALT_BASE = 0x$(shell $(NM) efi/relocs-dummy.o | sed -n 's, A ALT_START$$,,p')
 # Don't use $(wildcard ...) here - at least make 3.80 expands this too early!
 $(TARGET).efi: guard = $(if $(shell echo efi/dis* | grep disabled),:)
-$(TARGET).efi: prelink-efi.o efi.lds efi/relocs-dummy.o $(BASEDIR)/common/symbols-dummy.o efi/mkreloc
+$(TARGET).efi: prelink-efi.o efi.lds efi/relocs-dummy.o $(BASEDIR)/common/symbols-dummy.o efi/mkreloc build_id.o
 	$(foreach base, $(VIRT_BASE) $(ALT_BASE), \
 	          $(guard) $(LD) $(call EFI_LDFLAGS,$(base)) -T efi.lds -N $< efi/relocs-dummy.o \
 	                $(BASEDIR)/common/symbols-dummy.o -o $(@D)/.$(@F).$(base).0 &&) :
@@ -145,8 +149,8 @@ $(TARGET).efi: prelink-efi.o efi.lds efi/relocs-dummy.o $(BASEDIR)/common/symbol
 	$(guard) $(NM) -pa --format=sysv $(@D)/.$(@F).$(VIRT_BASE).1 \
 		| $(guard) $(BASEDIR)/tools/symbols --sysv --sort >$(@D)/.$(@F).1s.S
 	$(guard) $(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).1r.o $(@D)/.$(@F).1s.o
-	$(guard) $(LD) $(call EFI_LDFLAGS,$(VIRT_BASE)) -T efi.lds -N $< \
-	                $(@D)/.$(@F).1r.o $(@D)/.$(@F).1s.o -o $@
+	$(guard) $(LD) $(call EFI_LDFLAGS,$(VIRT_BASE)) -T efi.lds --build-id=sha1 -N $< \
+	                $(@D)/.$(@F).1r.o $(@D)/.$(@F).1s.o build_id.o -o $@
 	if $(guard) false; then rm -f $@; echo 'EFI support disabled'; fi
 	rm -f $(@D)/.$(@F).[0-9]*
 
xen/arch/x86/xen.lds.S +6 -0
index 6553cff..c4aabc3 100644
@@ -67,6 +67,12 @@ SECTIONS
        *(.rodata.*)
   } :text
 
+  .note.gnu.build-id : {
+      __note_gnu_build_id_start = .;
+      *(.note.gnu.build-id)
+      __note_gnu_build_id_end = .;
+  } :text
+
   . = ALIGN(SMP_CACHE_BYTES);
   .data.read_mostly : {
        /* Exception table */
xen/common/kernel.c +29 -0
index d51a3ed..1574c63 100644
@@ -366,6 +366,35 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
             return -EFAULT;
         return 0;
     }
+    case XENVER_build_id:
+    {
+        xen_build_id_t build_id;
+        unsigned int sz;
+        int rc = 0;
+        char *p = NULL;
+
+        if ( deny )
+            return -EPERM;
+
+        if ( copy_from_guest(&build_id, arg, 1) )
+            return -EFAULT;
+
+        if ( build_id.len == 0 )
+            return -EINVAL;
+
+        rc = xen_build_id(&p, &sz);
+        if ( rc )
+            return rc;
+
+        if ( sz > build_id.len )
+            return -ENOMEM;
+
+        if ( copy_to_guest_offset(arg, offsetof(xen_build_id_t, buf),
+                                  deny ? xen_deny() : p, sz) )
+            return -EFAULT;
+
+        return sz;
+    }
     }
 
     return -ENOSYS;
xen/common/version.c +36 -0
index 786be4e..d556c35 100644
@@ -1,5 +1,9 @@
 #include <xen/compile.h>
 #include <xen/version.h>
+#include <xen/types.h>
+#include <xen/string.h>
+#include <xen/elf.h>
+#include <xen/errno.h>
 
 const char *xen_compile_date(void)
 {
@@ -60,3 +64,35 @@ const char *xen_deny(void)
 {
     return "<denied>";
 }
+#ifdef CONFIG_ARM
+int xen_build_id(char **p, unsigned int *len)
+{
+    return -ENODATA;
+}
+#else
+#define NT_GNU_BUILD_ID 3
+
+extern const Elf_Note __note_gnu_build_id_start;  /* Defined in linker script. */
+extern const char __note_gnu_build_id_end[];
+int xen_build_id(char **p, unsigned int *len)
+{
+    const Elf_Note *n = &__note_gnu_build_id_start;
+
+    /* Something is wrong. */
+    if ( __note_gnu_build_id_end <= (char *)&__note_gnu_build_id_start )
+        return -ENODATA;
+
+    /* Check if we really have a build-id. */
+    if ( NT_GNU_BUILD_ID != n->type )
+        return -ENODATA;
+
+    /* Sanity check, name should be "GNU" for ld-generated build-id. */
+    if ( strncmp(ELFNOTE_NAME(n), "GNU", n->namesz) != 0 )
+        return -ENODATA;
+
+    *len = n->descsz;
+    *p = ELFNOTE_DESC(n);
+
+    return 0;
+}
+#endif
xen/include/public/version.h +14 -1
index 44f26b0..adae298 100644
@@ -30,7 +30,8 @@
 
 #include "xen.h"
 
-/* NB. All ops return zero on success, except XENVER_{version,pagesize} */
+/* NB. All ops return zero on success, except
+ * XENVER_{version,pagesize, build_id} */
 
 /* arg == NULL; returns major:minor (16:16). */
 #define XENVER_version      0
@@ -83,6 +84,18 @@ typedef struct xen_feature_info xen_feature_info_t;
 #define XENVER_commandline 9
 typedef char xen_commandline_t[1024];
 
+/* arg = xen_build_id_t. Returns size in bytes or XEN_Exx. */
+#define XENVER_build_id 10
+struct xen_build_id {
+        uint32_t        len; /* IN: size of buf[]. */
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+        unsigned char   buf[];
+#elif defined(__GNUC__)
+        unsigned char   buf[1]; /* OUT: Variable length buffer with build_id. */
+#endif
+};
+typedef struct xen_build_id xen_build_id_t;
+
 #endif /* __XEN_PUBLIC_VERSION_H__ */
 
 /*
xen/include/xen/version.h +1 -0
index 2015c0b..466c977 100644
@@ -13,5 +13,6 @@ const char *xen_extra_version(void);
 const char *xen_changeset(void);
 const char *xen_banner(void);
 const char *xen_deny(void);
+int xen_build_id(char **p, unsigned int *len);
 
 #endif /* __XEN_VERSION_H__ */
xen/xsm/flask/policy/access_vectors +1 -1
index 273459f..35bdb42 100644
@@ -93,7 +93,7 @@ class xen2
     pmu_ctrl
 # PMU use (domains, including unprivileged ones, will be using this operation)
     pmu_use
-# XENVER_[compile_info|changeset|commandline|extraversion] usage.
+# XENVER_[compile_info|changeset|commandline|extraversion|buildid] usage.
    version_priv
 }
 
Signature · 1 line
2.1.0
#15 lore raw

Re: [PATCH v2 2/3] XENVER_build_id: Provide ld-embedded build-ids

Quoted 21 lines · Konrad Rzeszutek Wilk

From: Martin Pohlack <[email protected]>

The mechanism to get this is via the XENVER_build_id and we add a new subsequent sub-command to retrieve the binary build-id. The hypercall allows an arbitrary size (the buffer and len is provided to the hypervisor).

Note that one can also retrieve the value by 'readelf -h xen-syms'.

For EFI builds we re-use the same build-id that the xen-syms was built with.

Note that there are no changes to the XSM files (dummy.c and hooks.c) as the priviliged subops fall in the default case.

Since the new sub-ops provides the len parameter in the arguments to the hypercall we have to modify libxc to allow copying the arguments before the hypercall. We provide a new macro that modifies the bounce structure to change the direction.

snip

xen/arch/x86/Makefile $(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o

Quoted 5 lines
xen/arch/x86/Makefile +0 -0
index d4e507a..17a4830 100644
@@ -109,15 +109,19 @@ $(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o

The above invocation of ld also needs to pass "--build-id=sha1".
Otherwise, the first invocation of tools/symbols has __note_gnu_build_id_end == __note_gnu_build_id_start, which may cause the size of the symbol table to change later when there is actually a build id (presumably due to the way it is compressed?) ultimately resulting in incorrect values in the symbol table.

Quoted 14 lines
xen/arch/x86/Makefile +2 -2
  	$(NM) -pa --format=sysv $(@D)/.$(@F).0 \
  		| $(BASEDIR)/tools/symbols --sysv --sort >$(@D)/.$(@F).0.S
  	$(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).0.o
-	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o \
+	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o --build-id=sha1 \
  	    $(@D)/.$(@F).0.o -o $(@D)/.$(@F).1
  	$(NM) -pa --format=sysv $(@D)/.$(@F).1 \
  		| $(BASEDIR)/tools/symbols --sysv --sort --warn-dup >$(@D)/.$(@F).1.S
  	$(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).1.o
-	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o \
+	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o --build-id=sha1 \
  	    $(@D)/.$(@F).1.o -o $@
  	rm -f $(@D)/.$(@F).[0-9]*
 
Signature · 1 line
Ross Lagerwall
#16 lore raw

Re: [PATCH v2 2/3] XENVER_build_id: Provide ld-embedded build-ids

In reply to Konrad Rzeszutek Wilk

xen/arch/x86/Makefile $(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o · line 112

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 06.11.15 at 20:36, <[email protected]> wrote:
xen/arch/x86/Makefile +1 -1
@@ -109,15 +109,19 @@ $(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o
 	$(NM) -pa --format=sysv $(@D)/.$(@F).0 \
 		| $(BASEDIR)/tools/symbols --sysv --sort >$(@D)/.$(@F).0.S
 	$(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).0.o
-	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o \
+	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o --build-id=sha1 \

You continue to use option this unconditionally.

Jan

#17 lore raw

Re: [PATCH v2 2/3] XENVER_build_id: Provide ld-embedded build-ids

Quoted 11 lines · Jan Beulich

xen/arch/x86/Makefile $(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o · line 112

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 06.11.15 at 20:36, <[email protected]> wrote:
xen/arch/x86/Makefile +1 -1
@@ -109,15 +109,19 @@ $(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o
 	$(NM) -pa --format=sysv $(@D)/.$(@F).0 \
 		| $(BASEDIR)/tools/symbols --sysv --sort >$(@D)/.$(@F).0.S
 	$(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).0.o
-	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o \
+	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o --build-id=sha1 \

You continue to use option this unconditionally.

I presume you are suggesting that I should check that the $(LD) can use this right?

I've been building this using an ancient tool-chain:
GNU ld version 2.20.51.0.2-20.fc13 20091009

And even there it is OK.

Or are you thinking of a different LD altogether and checking for that?

Quoted 3 lines

Jan

#18 lore raw

Re: [PATCH v2 2/3] XENVER_build_id: Provide ld-embedded build-ids

Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 06.01.16 at 18:27, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich

xen/arch/x86/Makefile $(TARGET)-syms: prelink.o xen.lds

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 06.11.15 at 20:36, <[email protected]> wrote:
xen/arch/x86/Makefile +0 -0
@@ -109,15 +109,19 @@ $(TARGET)-syms: prelink.o xen.lds 

$(BASEDIR)/common/symbols-dummy.o

Quoted 7 lines

xen/arch/x86/Makefile $(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o · line 112

Quoted 5 lines
xen/arch/x86/Makefile +1 -1
 	$(NM) -pa --format=sysv $(@D)/.$(@F).0 \
 		| $(BASEDIR)/tools/symbols --sysv --sort >$(@D)/.$(@F).0.S
 	$(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).0.o
-	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o \
+	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o --build-id=sha1 \

You continue to use option this unconditionally.

Quoted 7 lines

I presume you are suggesting that I should check that the $(LD) can use this right?

I've been building this using an ancient tool-chain:
GNU ld version 2.20.51.0.2-20.fc13 20091009

And even there it is OK.

With us supporting gcc back to 4.1, binutils should be supported back to what was available at about that time, i.e. at least 2.17, whereas --build-id only got introduced in 2.18.

Jan

#19 lore raw

PATCH v2 3/3 libxl: info: Display build_id of the hypervisor.

In reply to Konrad Rzeszutek Wilk

If the hypervisor is built with we will display it.

---
v2: Include HAVE_*, use libxl_zalloc, s/rc/ret/

---
 tools/libxl/libxl.c         | 24 ++++++++++++++++++++++++
 tools/libxl/libxl.h         |  5 +++++
 tools/libxl/libxl_types.idl |  1 +
 tools/libxl/xl_cmdimpl.c    |  1 +
 4 files changed, 31 insertions(+)
tools/libxl/libxl.c +24 -0
index 854e957..f30f8c4 100644
@@ -5251,6 +5251,7 @@ libxl_numainfo *libxl_get_numainfo(libxl_ctx *ctx, int *nr)
 
 const libxl_version_info* libxl_get_version_info(libxl_ctx *ctx)
 {
+    GC_INIT(ctx);
     union {
         xen_extraversion_t xen_extra;
         xen_compile_info_t xen_cc;
@@ -5258,8 +5259,10 @@ const libxl_version_info* libxl_get_version_info(libxl_ctx *ctx)
         xen_capabilities_info_t xen_caps;
         xen_platform_parameters_t p_parms;
         xen_commandline_t xen_commandline;
+        xen_build_id_t build_id;
     } u;
     long xen_version;
+    int ret;
     libxl_version_info *info = &ctx->version_info;
 
     if (info->xen_version_extra != NULL)
@@ -5292,6 +5295,27 @@ const libxl_version_info* libxl_get_version_info(libxl_ctx *ctx)
     xc_version(ctx->xch, XENVER_commandline, &u.xen_commandline);
     info->commandline = strdup(u.xen_commandline);
 
+    u.build_id.len = sizeof(u) - sizeof(u.build_id);
+    ret = xc_version(ctx->xch, XENVER_build_id, &u.build_id);
+    switch ( ret ) {
+    case -EPERM:
+    case -ENODATA:
+    case 0:
+        info->build_id = strdup("");
+        break;
+    default:
+        if (ret > 0) {
+            unsigned int i;
+
+            info->build_id = libxl__zalloc(NOGC, (ret * 2) + 1);
+
+            for (i = 0; i < ret ; i++)
+                snprintf(&info->build_id[i * 2], 3, "%02hhx", u.build_id.buf[i]);
+        } else
+            LOGEV(ERROR, ret, "getting build_id");
+        break;
+    }
+    GC_FREE;
     return info;
 }
 
tools/libxl/libxl.h +5 -0
index 168fedd..3e2ebd1 100644
@@ -212,6 +212,11 @@
 #define LIBXL_HAVE_SOFT_RESET 1
 
 /*
+ * LIBXL_HAVE_BUILD_ID means that libxl_version_info has the extra
+ * field for the hypervisor build_id.
+ */
+#define LIBXL_HAVE_BUILD_ID 1
+/*
  * libxl ABI compatibility
  *
  * The only guarantee which libxl makes regarding ABI compatibility
tools/libxl/libxl_types.idl +1 -0
index 4d78f86..5b57824 100644
@@ -353,6 +353,7 @@ libxl_version_info = Struct("version_info", [
     ("virt_start",        uint64),
     ("pagesize",          integer),
     ("commandline",       string),
+    ("build_id",          string),
     ], dir=DIR_OUT)
 
 libxl_domain_create_info = Struct("domain_create_info",[
tools/libxl/xl_cmdimpl.c +1 -0
index 03442e1..287a356 100644
@@ -5544,6 +5544,7 @@ static void output_xeninfo(void)
     printf("cc_compile_by          : %s\n", info->compile_by);
     printf("cc_compile_domain      : %s\n", info->compile_domain);
     printf("cc_compile_date        : %s\n", info->compile_date);
+    printf("build_id               : %s\n", info->build_id);
 
     return;
 }
Signature · 1 line
2.1.0