Skip to contentSkip to conversation

(revised) Updating a policy on a running system

PATCH New Stefan Berger 1 participant 1 message Apr 25, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 (revised) Updating a policy on a running system

This is a revised version of the previously posted patch that adds functionality to allow a policy to be updated on a running system and domains to be relabeled. The updating of a policy is happening in several steps: relabeling the domains, testing whether the system would be in a valid state after the relabeling (according to the policy), committing the changes if state is determined to be valid.

I have followed Keir's suggestion of building a 2nd linked list parallel to the domain list. That 2nd list holds security information related to the running domains. Each entry is pointed to by its domain structure. The list is protected by its own read/write-lock. I have moved nearly all ACM-related code that was traversing the domain list previously to traverse this list instead and not hold onto the domain list lock.

---
 xen-unstable.hg/xen/acm/acm_chinesewall_hooks.c             |  158 ++-
 xen-unstable.hg/xen/acm/acm_core.c                          |   24 
 xen-unstable.hg/xen/acm/acm_null_hooks.c                    |   10 
 xen-unstable.hg/xen/acm/acm_policy.c                        |  532 +++++++++++-
 xen-unstable.hg/xen/acm/acm_simple_type_enforcement_hooks.c |  147 ++-
 xen-unstable.hg/xen/common/acm_ops.c                        |   36 
 xen-unstable.hg/xen/include/acm/acm_core.h                  |   60 +
 xen-unstable.hg/xen/include/acm/acm_hooks.h                 |   51 -
 xen-unstable.hg/xen/include/public/acm.h                    |   13 
 xen-unstable.hg/xen/include/public/acm_ops.h                |   56 +
 10 files changed, 923 insertions(+), 164 deletions(-)
xen-unstable.hg/xen/include/acm/acm_hooks.h +30 -21
Index: root/xen-unstable.hg/xen/include/acm/acm_hooks.h
===================================================================
@@ -91,8 +91,10 @@ struct acm_operations {
     int  (*init_domain_ssid)           (void **ssid, ssidref_t ssidref);
     void (*free_domain_ssid)           (void *ssid);
     int  (*dump_binary_policy)         (u8 *buffer, u32 buf_size);
-    int  (*set_binary_policy)          (u8 *buffer, u32 buf_size,
-                                        int is_bootpolicy);
+    int  (*test_binary_policy)         (u8 *buffer, u32 buf_size,
+                                        int is_bootpolicy,
+                                        struct acm_sized_buffer *);
+    int  (*set_binary_policy)          (u8 *buffer, u32 buf_size);
     int  (*dump_statistics)            (u8 *buffer, u16 buf_size);
     int  (*dump_ssid_types)            (ssidref_t ssidref, u8 *buffer, u16 buf_size);
     /* domain management control hooks (can be NULL) */
@@ -228,23 +230,35 @@ static inline int acm_pre_grant_setup(do
 }
 
 
+static inline void acm_domain_destroy(struct domain *d)
+{
+    void *ssid = d->ssid;
+    if (ssid != NULL) {
+        if (acm_primary_ops->domain_destroy != NULL)
+            acm_primary_ops->domain_destroy(ssid, d);
+        if (acm_secondary_ops->domain_destroy != NULL)
+            acm_secondary_ops->domain_destroy(ssid, d);
+        /* free security ssid for the destroyed domain (also if null policy */
+        acm_free_domain_ssid((struct acm_ssid_domain *)(ssid));
+    }
+}
+
+
 static inline int acm_domain_create(struct domain *d, ssidref_t ssidref)
 {
     void *subject_ssid = current->domain->ssid;
     domid_t domid = d->domain_id;
-    int rc;
+    int rc = 0;
 
+    read_lock(&acm_bin_pol_rwlock);
     /*
        To be called when a domain is created; returns '0' if the
        domain is allowed to be created, != '0' if not.
      */
-    rc = acm_init_domain_ssid_new(d, ssidref);
-    if (rc != ACM_OK)
-        return rc;
 
     if ((acm_primary_ops->domain_create != NULL) &&
         acm_primary_ops->domain_create(subject_ssid, ssidref, domid)) {
-        return ACM_ACCESS_DENIED;
+        rc = ACM_ACCESS_DENIED;
     } else if ((acm_secondary_ops->domain_create != NULL) &&
                 acm_secondary_ops->domain_create(subject_ssid, ssidref,
                                                  domid)) {
@@ -252,24 +266,19 @@ static inline int acm_domain_create(stru
         if (acm_primary_ops->domain_destroy != NULL)
             acm_primary_ops->domain_destroy(d->ssid, d);
         acm_free_domain_ssid(d->ssid);
-        return ACM_ACCESS_DENIED;
+        rc = ACM_ACCESS_DENIED;
     }
 
-    return 0;
-}
-
+    if (rc == 0) {
+        rc = acm_init_domain_ssid_new(d, ssidref);
 
-static inline void acm_domain_destroy(struct domain *d)
-{
-    void *ssid = d->ssid;
-    if (ssid != NULL) {
-        if (acm_primary_ops->domain_destroy != NULL)
-            acm_primary_ops->domain_destroy(ssid, d);
-        if (acm_secondary_ops->domain_destroy != NULL)
-            acm_secondary_ops->domain_destroy(ssid, d);
-        /* free security ssid for the destroyed domain (also if null policy */
-        acm_free_domain_ssid((struct acm_ssid_domain *)(ssid));
+        if (rc != ACM_OK) {
+            acm_domain_destroy(d);
+        }
     }
+
+    read_unlock(&acm_bin_pol_rwlock);
+    return rc;
 }
 
 
xen-unstable.hg/xen/acm/acm_chinesewall_hooks.c +112 -46

228 lines not on this page · raw message

xen-unstable.hg/xen/acm/acm_core.c +20 -4
Index: root/xen-unstable.hg/xen/acm/acm_core.c
===================================================================
@@ -62,10 +62,14 @@ struct acm_binary_policy acm_bin_pol;
 /* acm binary policy lock */
 DEFINE_RWLOCK(acm_bin_pol_rwlock);
 
-/* ACM's only accepted policy name */
+/* ACM's only accepted policy name during boot */
 char polname[80];
 char *acm_accepted_boot_policy_name = NULL;
 
+/* a lits of all chained ssid structures */
+LIST_HEAD(ssid_list);
+DEFINE_RWLOCK(ssid_list_rwlock);
+
 static void __init set_dom0_ssidref(const char *val)
 {
     /* expected format:
@@ -77,7 +81,7 @@ static void __init set_dom0_ssidref(cons
     int i;
     int dom0_ssidref = simple_strtoull(val, &c, 0);
 
-    if (!strncmp(&c[0],":sHype:", 7)) {
+    if (!strncmp(&c[0],":ACM:", 5)) {
         lo = dom0_ssidref & 0xffff;
         if (lo < ACM_MAX_NUM_TYPES && lo >= 1)
             dom0_chwall_ssidref = lo;
@@ -249,7 +253,8 @@ acm_setup(char *policy_start,
         return rc;
 
     rc = do_acm_set_policy((void *)policy_start, (u32)policy_len,
-                           is_bootpolicy);
+                           is_bootpolicy,
+                           NULL, NULL, NULL);
     if (rc == ACM_OK)
     {
         printkd("Policy len  0x%lx, start at %p.\n",policy_len,policy_start);
@@ -337,9 +342,10 @@ int acm_init_domain_ssid_new(struct doma
         return ACM_INIT_SSID_ERROR;
     }
 
+    INIT_LIST_HEAD(&ssid->node);
     ssid->datatype       = ACM_DATATYPE_domain;
     ssid->subject        = subj;
-    ssid->domainid      = subj->domain_id;
+    ssid->domainid       = subj->domain_id;
     ssid->primary_ssid   = NULL;
     ssid->secondary_ssid = NULL;
 
@@ -367,6 +373,11 @@ int acm_init_domain_ssid_new(struct doma
         acm_free_domain_ssid(ssid);
         return ACM_INIT_SSID_ERROR;
     }
+
+    write_lock(&ssid_list_rwlock);
+    list_add(&ssid->node, &ssid_list);
+    write_unlock(&ssid_list_rwlock);
+
     printkd("%s: assigned domain %x the ssidref=%x.\n",
            __func__, subj->domain_id, ssid->ssidref);
     return ACM_OK;
@@ -387,6 +398,11 @@ acm_free_domain_ssid(struct acm_ssid_dom
     if (acm_secondary_ops->free_domain_ssid != NULL)
         acm_secondary_ops->free_domain_ssid(ssid->secondary_ssid);
     ssid->secondary_ssid = NULL;
+
+    write_lock(&ssid_list_rwlock);
+    list_del(&ssid->node);
+    write_unlock(&ssid_list_rwlock);
+
     xfree(ssid);
     printkd("%s: Freed individual domain ssid (domain=%02x).\n",
             __func__, id);
xen-unstable.hg/xen/acm/acm_null_hooks.c +9 -1
Index: root/xen-unstable.hg/xen/acm/acm_null_hooks.c
===================================================================
@@ -33,7 +33,14 @@ null_dump_binary_policy(u8 *buf, u32 buf
 }
 
 static int
-null_set_binary_policy(u8 *buf, u32 buf_size, int is_bootpolicy)
+null_test_binary_policy(u8 *buf, u32 buf_size, int is_bootpolicy,
+                        struct acm_sized_buffer *errors)
+{
+    return ACM_OK;
+}
+
+static int
+null_set_binary_policy(u8 *buf, u32 buf_size)
 { 
     return ACM_OK;
 }
@@ -58,6 +65,7 @@ struct acm_operations acm_null_ops = {
     .init_domain_ssid = null_init_domain_ssid,
     .free_domain_ssid = null_free_domain_ssid,
     .dump_binary_policy = null_dump_binary_policy,
+    .test_binary_policy = null_test_binary_policy,
     .set_binary_policy = null_set_binary_policy,
     .dump_statistics = null_dump_stats,
     .dump_ssid_types = null_dump_ssid_types,
xen-unstable.hg/xen/acm/acm_policy.c +495 -37

604 lines not on this page · raw message

xen-unstable.hg/xen/acm/acm_simple_type_enforcement_hooks.c +104 -43

253 lines not on this page · raw message

xen-unstable.hg/xen/common/acm_ops.c +36 -0
Index: root/xen-unstable.hg/xen/common/acm_ops.c
===================================================================
@@ -216,6 +216,42 @@ ret_t do_acm_op(int cmd, XEN_GUEST_HANDL
         break;
     }
 
+    case ACMOP_chgpolicy: {
+        struct acm_change_policy chgpolicy;
+
+        if (copy_from_guest(&chgpolicy, arg, 1) != 0)
+            return -EFAULT;
+        if (chgpolicy.interface_version != ACM_INTERFACE_VERSION)
+            return -EACCES;
+
+        rc = acm_change_policy(&chgpolicy);
+
+        if (rc == 0) {
+            if (copy_to_guest(arg, &chgpolicy, 1) != 0) {
+                rc = -EFAULT;
+            }
+        }
+        break;
+    }
+
+    case ACMOP_relabeldoms: {
+        struct acm_relabel_doms relabeldoms;
+
+        if (copy_from_guest(&relabeldoms, arg, 1) != 0)
+            return -EFAULT;
+        if (relabeldoms.interface_version != ACM_INTERFACE_VERSION)
+            return -EACCES;
+
+        rc = acm_relabel_domains(&relabeldoms);
+
+        if (rc == 0) {
+            if (copy_to_guest(arg, &relabeldoms, 1) != 0) {
+                rc = -EFAULT;
+            }
+        }
+        break;
+    }
+
     default:
         rc = -ENOSYS;
         break;
xen-unstable.hg/xen/include/acm/acm_core.h +11 -6
Index: root/xen-unstable.hg/xen/include/acm/acm_core.h
===================================================================
@@ -20,9 +20,11 @@
 #define _ACM_CORE_H
 
 #include <xen/spinlock.h>
+#include <xen/list.h>
 #include <public/acm.h>
 #include <xen/acm_policy.h>
 #include <public/acm_ops.h>
+#include <acm/acm_endian.h>
 
 /* Xen-internal representation of the binary policy */
 struct acm_binary_policy {
@@ -58,6 +60,7 @@ extern struct chwall_binary_policy chwal
 extern struct ste_binary_policy ste_bin_pol;
 /* use the lock when reading / changing binary policy ! */
 extern rwlock_t acm_bin_pol_rwlock;
+extern rwlock_t ssid_list_rwlock;
 
 /* subject and object type definitions */
 #define ACM_DATATYPE_domain 1
@@ -80,12 +83,14 @@ struct acm_ste_cache_line {
 
 /* general definition of a subject security id */
 struct acm_ssid_domain {
-    int datatype; /* type of subject (e.g., partition): ACM_DATATYPE_* */
-    ssidref_t ssidref;   /* combined security reference */
-    void *primary_ssid;   /* primary policy ssid part (e.g. chinese wall) */
-    void *secondary_ssid;    /* secondary policy ssid part (e.g. type enforcement) */
-    struct domain *subject;     /* backpointer to subject structure */
-    domid_t domainid;   /* replicate id */
+    struct list_head node; /* all are chained together */
+    int datatype;          /* type of subject (e.g., partition): ACM_DATATYPE_* */
+    ssidref_t ssidref;     /* combined security reference */
+    ssidref_t old_ssidref; /* holds previous value of ssidref during relabeling */
+    void *primary_ssid;    /* primary policy ssid part (e.g. chinese wall) */
+    void *secondary_ssid;  /* secondary policy ssid part (e.g. type enforcement) */
+    struct domain *subject;/* backpointer to subject structure */
+    domid_t domainid;      /* replicate id */
 };
 
 

/* chinese wall ssid type */
@@ -118,19 +123,53 @@ struct ste_ssid {
((POLICY) == acm_bin_pol.primary_policy_code) ? \
((ssid)->primary_ssid) : ((ssid)->secondary_ssid)

+#define ACM_INVALID_SSIDREF (0xffffffff)
+
+struct acm_sized_buffer
+{

+    uint32_t *array;
+    uint num_items;
+    uint position;

+};
+
+static inline int acm_array_append_tuple(struct acm_sized_buffer *buf,
+ uint32_t a, uint32_t b)
+{
+ uint i;
+ if (buf == NULL)
+ return 0;
+
+ i = buf->position;
+
+ if ((i + 2) > buf->num_items)
+ return 0;
+

+    buf->array[i]   = cpu_to_be32(a);
+    buf->array[i+1] = cpu_to_be32(b);
+    buf->position += 2;
+    return 1;

+}
+
+
/* protos */
int acm_init_domain_ssid(domid_t id, ssidref_t ssidref);
int acm_init_domain_ssid_new(struct domain *, ssidref_t ssidref); void acm_free_domain_ssid(struct acm_ssid_domain *ssid);
int acm_init_binary_policy(u32 policy_code);
int acm_set_policy(XEN_GUEST_HANDLE(void) buf, u32 buf_size);
-int do_acm_set_policy(void *buf, u32 buf_size, int is_bootpolicy); +int do_acm_set_policy(void *buf, u32 buf_size, int is_bootpolicy,
+ struct acm_sized_buffer *, struct acm_sized_buffer *,
+ struct acm_sized_buffer *);
int acm_get_policy(XEN_GUEST_HANDLE(void) buf, u32 buf_size);
int acm_dump_statistics(XEN_GUEST_HANDLE(void) buf, u16 buf_size); int acm_get_ssid(ssidref_t ssidref, XEN_GUEST_HANDLE(void) buf, u16 buf_size); int acm_get_decision(ssidref_t ssidref1, ssidref_t ssidref2, u32 hook); int acm_set_policy_reference(u8 * buf, u32 buf_size);
int acm_dump_policy_reference(u8 *buf, u32 buf_size);
+int acm_change_policy(struct acm_change_policy *);
+int acm_relabel_domains(struct acm_relabel_doms *);
+int do_chwall_init_state_curr(struct acm_sized_buffer *);
+int do_ste_init_state_curr(struct acm_sized_buffer *);

/* variables */
@@ -138,6 +177,13 @@ extern ssidref_t dom0_chwall_ssidref;
extern ssidref_t dom0_ste_ssidref;
#define ACM_MAX_NUM_TYPES (256)

+/* traversing the list of ssids */
+extern struct list_head ssid_list;
+#define for_each_acmssid( N ) \
+ for ( N = (struct acm_ssid_domain *)ssid_list.next; \

+         N != (struct acm_ssid_domain *)&ssid_list;      \
+         N =  (struct acm_ssid_domain *)N->node.next     )

+
#endif

/*

xen-unstable.hg/xen/include/public/acm.h +13 -0
Index: root/xen-unstable.hg/xen/include/public/acm.h
===================================================================
@@ -56,6 +56,19 @@
 #define ACM_ACCESS_DENIED           -111
 #define ACM_NULL_POINTER_ERROR      -200
 
+/*
+   Error codes reported in when trying to test for a new policy
+   These error codes are reported in an array of tuples where
+   each error code is followed by a parameter describing the error
+   more closely, such as a domain id.
+*/
+#define ACM_EVTCHN_SHARING_VIOLATION       0x100
+#define ACM_GNTTAB_SHARING_VIOLATION       0x101
+#define ACM_DOMAIN_LOOKUP                  0x102
+#define ACM_CHWALL_CONFLICT                0x103
+#define ACM_SSIDREF_IN_USE                 0x104
+
+
 /* primary policy in lower 4 bits */
 #define ACM_NULL_POLICY 0
 #define ACM_CHINESE_WALL_POLICY 1
xen-unstable.hg/xen/include/public/acm_ops.h +51 -5

92 lines not on this page · raw message

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