Skip to contentSkip to conversation

xsm: move the console read properly under xsm

PATCH In review Daniel P. Smith 2 participants 5 messages Feb 19 – Feb 27

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xsm: move the console read properly under xsm

The access control for domU to read the console should be controlled via XSM. By moving it under XSM, FLASK will now be able to work correctly with the domU console read capability that was introduced recently.

To enable console read under XSM, the legacy is_console field in struct domain was collapsed with the new input_allowed field in struct domain_console. Having two fields over console was redundant. By merging them together under the permissions field in struct domain_console, this allows better alignment with the existing fine grained access controls under FLASK.

---
 xen/arch/arm/vpl011.c                   |  2 +-
 xen/arch/x86/pv/shim.c                  |  2 +-
 xen/common/device-tree/dom0less-build.c |  2 +-
 xen/common/domain.c                     |  1 -
 xen/drivers/char/console.c              |  4 ++--
 xen/include/xen/sched.h                 |  8 ++++----
 xen/include/xsm/dummy.h                 | 17 ++++++++++++-----
 7 files changed, 21 insertions(+), 15 deletions(-)
xen/arch/arm/vpl011.c +1 -1
index d0d17c76b72c..1461c27afed0 100644
@@ -713,7 +713,7 @@ int domain_vpl011_init(struct domain *d, struct vpl011_init_info *info)
     }
     else
     {
-        d->console->input_allowed = true;
+        d->console->permissions = DOMAIN_CONSOLE_READ;
         vpl011->backend_in_domain = false;
 
         vpl011->backend.xen = xzalloc(struct vpl011_xen_backend);
xen/arch/x86/pv/shim.c +1 -1
index bd29c53a2d34..03990dfc0e01 100644
@@ -239,7 +239,7 @@ void __init pv_shim_setup_dom(struct domain *d, l4_pgentry_t *l4start,
      */
     d->max_pages = domain_tot_pages(d);
 
-    d->console->input_allowed = true;
+    d->console->permissions = DOMAIN_CONSOLE_READ;
 }
 
 static void write_start_info(struct domain *d)
xen/common/device-tree/dom0less-build.c +1 -1
index 840d14419da2..d144720fe195 100644
@@ -871,7 +871,7 @@ void __init create_domUs(void)
                   dt_node_name(node), rc);
 #endif /* CONFIG_HAS_LLC_COLORING */
 
-        ki.bd.d->is_console = true;
+        ki.bd.d->console->permissions = DOMAIN_CONSOLE_WRITE;
         dt_device_set_used_by(node, ki.bd.d->domain_id);
 
         rc = construct_domU(&ki, node);
xen/common/domain.c +0 -1
index 2e46207d2db0..331c048e2f72 100644
@@ -999,7 +999,6 @@ struct domain *domain_create(domid_t domid,
         goto fail;
 
     spin_lock_init(&d->console->lock);
-    d->console->input_allowed = is_hardware_domain(d);
 
     /*
      * This assertion helps static analysis tools infer that config cannot be
xen/drivers/char/console.c +2 -2
index bcd6d261491b..909e0fdb8c08 100644
@@ -554,7 +554,7 @@ struct domain *console_get_domain(void)
     if ( !d )
         return NULL;
 
-    if ( d->console->input_allowed )
+    if ( !xsm_console_io(XSM_OTHER, d, CONSOLEIO_read) )
         return d;
 
     rcu_unlock_domain(d);
@@ -595,7 +595,7 @@ static void console_switch_input(void)
         d = rcu_lock_domain_by_id(domid);
         if ( d )
         {
-            if ( !d->console->input_allowed )
+            if ( xsm_console_io(XSM_OTHER, d, CONSOLEIO_read) )
             {
                 rcu_unlock_domain(d);
                 continue;
xen/include/xen/sched.h +4 -4
index 40a35fc15c65..3713664aaea5 100644
@@ -377,8 +377,10 @@ struct evtchn_port_ops;
 
 /* Domain console settings. */
 struct domain_console {
-    /* Permission to take ownership of the physical console input. */
-    bool input_allowed;
+    /* XSM: permission to use HYPERCALL_console_io hypercall */
+#define DOMAIN_CONSOLE_READ  (1u << 0)
+#define DOMAIN_CONSOLE_WRITE (1u << 1)
+    unsigned int permissions;
 
     /* hvm_print_line() and guest_console_write() logging. */
     unsigned int idx;
@@ -528,8 +530,6 @@ struct domain
     bool             auto_node_affinity;
     /* Is this guest fully privileged (aka dom0)? */
     bool             is_privileged;
-    /* XSM: permission to use HYPERCALL_console_io hypercall */
-    bool             is_console;
     /* Is this guest being debugged by dom0? */
     bool             debugger_attached;
     /*
xen/include/xsm/dummy.h +12 -5
index b8fd7aeedd9e..129823b8d37b 100644
@@ -269,12 +269,19 @@ static XSM_INLINE int cf_check xsm_console_io(
     XSM_DEFAULT_ARG struct domain *d, int cmd)
 {
     XSM_ASSERT_ACTION(XSM_OTHER);
-    if ( d->is_console )
-        return xsm_default_action(XSM_HOOK, d, NULL);
-#ifdef CONFIG_VERBOSE_DEBUG
-    if ( cmd == CONSOLEIO_write )
-        return xsm_default_action(XSM_HOOK, d, NULL);
+    switch ( cmd )
+    {
+    case CONSOLEIO_read:
+        if ( d->console->permissions & DOMAIN_CONSOLE_READ )
+            return xsm_default_action(XSM_HOOK, d, NULL);
+        break;
+    case CONSOLEIO_write:
+#ifndef CONFIG_VERBOSE_DEBUG
+        if ( d->console->permissions & DOMAIN_CONSOLE_WRITE )
 #endif
+		return xsm_default_action(XSM_HOOK, d, NULL);
+        break;
+    }
     return xsm_default_action(XSM_PRIV, d, NULL);
 }
 
Signature · 1 line
2.39.5
#1 lore raw
Quoted 12 lines · Daniel P. Smith
xen/drivers/char/console.c +1 -1
@@ -554,7 +554,7 @@ struct domain *console_get_domain(void)
     if ( !d )
         return NULL;
 
-    if ( d->console->input_allowed )
+    if ( !xsm_console_io(XSM_OTHER, d, CONSOLEIO_read) )
         return d;
 
     rcu_unlock_domain(d);

xen/drivers/char/console.c static void console_switch_input(void) · line 601

Quoted 8 lines
xen/drivers/char/console.c +1 -1
@@ -595,7 +595,7 @@ static void console_switch_input(void)
         d = rcu_lock_domain_by_id(domid);
         if ( d )
         {
-            if ( !d->console->input_allowed )
+            if ( xsm_console_io(XSM_OTHER, d, CONSOLEIO_read) )
             {
                 rcu_unlock_domain(d);
                 continue;

At least the latter of these two can be called from an IRQ handler, and can be called with IRQs off. Flask's avc_audit() looks to be using a spinlock, which isn't IRQ-safe. (There may be other lock involved; I merely went as far as I needed to to find the first one.) IOW I fear you can't call xsm_console_io() from here.

Jan

#2 lore raw
Quoted 11 lines · Jan Beulich
Quoted 10 lines · Daniel P. Smith
xen/drivers/char/console.c +1 -1
@@ -554,7 +554,7 @@ struct domain *console_get_domain(void)
      if ( !d )
          return NULL;
 
-    if ( d->console->input_allowed )
+    if ( !xsm_console_io(XSM_OTHER, d, CONSOLEIO_read) )
          return d;
 
Quoted 16 lines

xen/drivers/char/console.c static void console_switch_input(void) · line 601

Quoted 10 lines
xen/drivers/char/console.c +1 -1
      rcu_unlock_domain(d);
@@ -595,7 +595,7 @@ static void console_switch_input(void)
          d = rcu_lock_domain_by_id(domid);
          if ( d )
          {
-            if ( !d->console->input_allowed )
+            if ( xsm_console_io(XSM_OTHER, d, CONSOLEIO_read) )
              {
                  rcu_unlock_domain(d);
                  continue;

At least the latter of these two can be called from an IRQ handler, and can be called with IRQs off. Flask's avc_audit() looks to be using a spinlock, which isn't IRQ-safe. (There may be other lock involved; I merely went as far as I needed to to find the first one.) IOW I fear you can't call xsm_console_io() from here.

Apologies that I didn't consider the IRQ context. With that said, we can't be wiring non-XSM access control paths that circumvent FLASK's ability to control domain access to a resource.

v/r,
dps

#3 lore raw
Quoted 29 lines · Daniel P. Smith
Quoted 11 lines · Jan Beulich
Quoted 10 lines · Daniel P. Smith
xen/drivers/char/console.c +1 -1
@@ -554,7 +554,7 @@ struct domain *console_get_domain(void)
      if ( !d )
          return NULL;
 
-    if ( d->console->input_allowed )
+    if ( !xsm_console_io(XSM_OTHER, d, CONSOLEIO_read) )
          return d;
 
Quoted 16 lines

xen/drivers/char/console.c static void console_switch_input(void) · line 601

Quoted 10 lines
xen/drivers/char/console.c +1 -1
      rcu_unlock_domain(d);
@@ -595,7 +595,7 @@ static void console_switch_input(void)
          d = rcu_lock_domain_by_id(domid);
          if ( d )
          {
-            if ( !d->console->input_allowed )
+            if ( xsm_console_io(XSM_OTHER, d, CONSOLEIO_read) )
              {
                  rcu_unlock_domain(d);
                  continue;

At least the latter of these two can be called from an IRQ handler, and can be called with IRQs off. Flask's avc_audit() looks to be using a spinlock, which isn't IRQ-safe. (There may be other lock involved; I merely went as far as I needed to to find the first one.) IOW I fear you can't call xsm_console_io() from here.

Quoted 3 lines

Apologies that I didn't consider the IRQ context. With that said, we can't be wiring non-XSM access control paths that circumvent FLASK's ability to control domain access to a resource.

I feel like I can interpret this last sentence in different ways. Are you suggesting that this effort needs to be dropped, and the situation needs leaving as is? If so, aren't there options to move at least a little closer to what is wanted?

Jan

#4 lore raw
Quoted 30 lines · Jan Beulich
Quoted 29 lines · Daniel P. Smith
Quoted 27 lines · Jan Beulich
Quoted 12 lines · Daniel P. Smith
xen/drivers/char/console.c +1 -1
@@ -554,7 +554,7 @@ struct domain *console_get_domain(void)
       if ( !d )
           return NULL;
 
-    if ( d->console->input_allowed )
+    if ( !xsm_console_io(XSM_OTHER, d, CONSOLEIO_read) )
           return d;
 
       rcu_unlock_domain(d);

xen/drivers/char/console.c static void console_switch_input(void) · line 601

Quoted 8 lines
xen/drivers/char/console.c +1 -1
@@ -595,7 +595,7 @@ static void console_switch_input(void)
           d = rcu_lock_domain_by_id(domid);
           if ( d )
           {
-            if ( !d->console->input_allowed )
+            if ( xsm_console_io(XSM_OTHER, d, CONSOLEIO_read) )
               {
                   rcu_unlock_domain(d);
                   continue;

At least the latter of these two can be called from an IRQ handler, and can be called with IRQs off. Flask's avc_audit() looks to be using a spinlock, which isn't IRQ-safe. (There may be other lock involved; I merely went as far as I needed to to find the first one.) IOW I fear you can't call xsm_console_io() from here.

Quoted 8 lines
Quoted 3 lines

Apologies that I didn't consider the IRQ context. With that said, we can't be wiring non-XSM access control paths that circumvent FLASK's ability to control domain access to a resource.

I feel like I can interpret this last sentence in different ways. Are you suggesting that this effort needs to be dropped, and the situation needs leaving as is? If so, aren't there options to move at least a little closer to what is wanted?

What I am saying is it needs to be controlled via XSM, so a means to enable that needs to be determined.

V/r,
dps