Skip to contentSkip to conversation

Isolating ACM's architecture-dependent parts

RFC PATCH In review Stefan Berger 3 participants 8 messages Sep 13, 2006 – Sep 26, 2006

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 Isolating ACM's architecture-dependent parts

This is a modification of Tristan's previously posted patch. I have tried to isolate architecture-dependent parts into functions that are kept in architecture-specific include files. For example, the code that deals with starting up ACM on the x86 architecture has been moved to include/asm-x86/acm.h. There the policy is tried to be picked from the multiboot structure.
If other architectures can recycle some of the x86-specific code, such as for example the multiboot-related code, then I guess this could be moved to shared code areas.
The easiest way to support ACM is to call acm_init(NULL,0); from within the setup function if for some reason the machine cannot be started with a policy.

(patch based on previously posted patch by Tristan on 9/5/6)

xen-unstable.hg/xen/acm/acm_core.c +36 -61
Index: root/xen-unstable.hg/xen/acm/acm_core.c
===================================================================
@@ -100,9 +100,11 @@ acm_dump_policy_reference(u8 *buf, u32 b
     struct acm_policy_reference_buffer *pr_buf = (struct acm_policy_reference_buffer *)buf;
     int ret = sizeof(struct acm_policy_reference_buffer) + strlen(acm_bin_pol.policy_reference_name) + 1;
 
+    ret = (ret + 7) & ~7;
     if (buf_size < ret)
         return -EINVAL;
 
+    memset(buf, 0, ret);
     pr_buf->len = htonl(strlen(acm_bin_pol.policy_reference_name) + 1); /* including stringend '\0' */
     strcpy((char *)(buf + sizeof(struct acm_policy_reference_buffer)),
            acm_bin_pol.policy_reference_name);
@@ -187,85 +189,58 @@ acm_init_binary_policy(u32 policy_code)
     return ret;
 }
 
+int
+acm_is_policy(char *buf, unsigned long len)
+{
+    struct acm_policy_buffer *pol;
+
+    if (buf == NULL || len < sizeof(struct acm_policy_buffer))
+        return 0;
+
+    pol = (struct acm_policy_buffer *)buf;
+    return ntohl(pol->magic) == ACM_MAGIC;
+}
+
+
 static int
-acm_setup(unsigned int *initrdidx,
-          const multiboot_info_t *mbi,
-          unsigned long initial_images_start)
+acm_setup(char *policy_start,
+          unsigned long policy_len)
 {
-    int i;
-    module_t *mod = (module_t *)__va(mbi->mods_addr);
     int rc = ACM_OK;
+    struct acm_policy_buffer *pol;
+
+    if (policy_start == NULL || policy_len < sizeof(struct acm_policy_buffer))
+        return rc;
 
-    if (mbi->mods_count > 1)
-        *initrdidx = 1;
+    pol = (struct acm_policy_buffer *)policy_start;
+    if (ntohl(pol->magic) != ACM_MAGIC)
+        return rc;
 
-    /*
-     * Try all modules and see whichever could be the binary policy.
-     * Adjust the initrdidx if module[1] is the binary policy.
-     */
-    for (i = mbi->mods_count-1; i >= 1; i--)
+    rc = do_acm_set_policy((void *)policy_start, (u32)policy_len);
+    if (rc == ACM_OK)
+    {
+        printkd("Policy len  0x%lx, start at %p.\n",policy_len,policy_start);
+    }
+    else
     {
-        struct acm_policy_buffer *pol;
-        char *_policy_start;
-        unsigned long _policy_len;
-#if defined(__i386__)
-        _policy_start = (char *)(initial_images_start + (mod[i].mod_start-mod[0].mod_start));
-#elif defined(__x86_64__)
-        _policy_start = __va(initial_images_start + (mod[i].mod_start-mod[0].mod_start));
-#else
-#error Architecture unsupported by sHype
-#endif
-        _policy_len   = mod[i].mod_end - mod[i].mod_start;
-        if (_policy_len < sizeof(struct acm_policy_buffer))
-            continue; /* not a policy */
-
-        pol = (struct acm_policy_buffer *)_policy_start;
-        if (ntohl(pol->magic) == ACM_MAGIC)
-        {
-            rc = do_acm_set_policy((void *)_policy_start,
-                                   (u32)_policy_len);
-            if (rc == ACM_OK)
-            {
-                printkd("Policy len  0x%lx, start at %p.\n",_policy_len,_policy_start);
-                if (i == 1)
-                {
-                    if (mbi->mods_count > 2)
-                    {
-                        *initrdidx = 2;
-                    }
-                    else {
-                        *initrdidx = 0;
-                    }
-                }
-                else
-                {
-                    *initrdidx = 1;
-                }
-                break;
-            }
-            else
-            {
-                printk("Invalid policy. %d.th module line.\n", i+1);
-                /* load default policy later */
-                acm_active_security_policy = ACM_POLICY_UNDEFINED;
-            }
-        } /* end if a binary policy definition, i.e., (ntohl(pol->magic) == ACM_MAGIC ) */
+        printk("Invalid policy.\n");
+        /* load default policy later */
+        acm_active_security_policy = ACM_POLICY_UNDEFINED;
     }
     return rc;
 }
 
 
 int
-acm_init(unsigned int *initrdidx,
-         const multiboot_info_t *mbi,
-         unsigned long initial_images_start)
+acm_init(char *policy_start,
+         unsigned long policy_len)
 {
     int ret = ACM_OK;
 
     acm_set_endian();
 
     /* first try to load the boot policy (uses its own locks) */
-    acm_setup(initrdidx, mbi, initial_images_start);
+    acm_setup(policy_start, policy_len);
 
     if (acm_active_security_policy != ACM_POLICY_UNDEFINED)
     {
xen-unstable.hg/xen/arch/x86/setup.c +2 -1
Index: root/xen-unstable.hg/xen/arch/x86/setup.c
===================================================================
@@ -25,6 +25,7 @@
 #include <asm/desc.h>
 #include <asm/shadow.h>
 #include <asm/e820.h>
+#include <asm/acm.h>
 #include <acm/acm_hooks.h>
 
 extern void dmi_scan_machine(void);
@@ -560,7 +561,7 @@ void __init __start_xen(multiboot_info_t
         watchdog_enable();
 
     /* initialize access control security module */
-    acm_init(&initrdidx, mbi, initial_images_start);
+    acm_x86_init(mbi, &initrdidx, initial_images_start);
 
     /* Create initial domain 0. */
     dom0 = domain_create(0);
xen-unstable.hg/xen/include/acm/acm_hooks.h +5 -9
Index: root/xen-unstable.hg/xen/include/acm/acm_hooks.h
===================================================================
@@ -25,7 +25,6 @@
 #include <xen/lib.h>
 #include <xen/delay.h>
 #include <xen/sched.h>
-#include <xen/multiboot.h>
 #include <public/acm.h>
 #include <acm/acm_core.h>
 #include <public/domctl.h>
@@ -143,15 +142,10 @@ static inline int acm_pre_grant_map_ref(
 { return 0; }
 static inline int acm_pre_grant_setup(domid_t id) 
 { return 0; }
-static inline int acm_init(unsigned int *initrdidx,
-                           const multiboot_info_t *mbi,
-                           unsigned long start)
-{ return 0; }
 static inline void acm_post_domain0_create(domid_t domid) 
 { return; }
 static inline int acm_sharing(ssidref_t ssidref1, ssidref_t ssidref2)
 { return 0; }
-
 #else
 
 static inline int acm_pre_domain_create(void *subject_ssid, ssidref_t ssidref)
@@ -369,9 +363,11 @@ static inline int acm_sharing(ssidref_t 
         return ACM_ACCESS_PERMITTED;
 }
 
-extern int acm_init(unsigned int *initrdidx,
-                    const multiboot_info_t *mbi,
-                    unsigned long start);
+
+extern int acm_init(char *policy_start, unsigned long policy_len);
+
+/* Return true iff buffer has an acm policy magic number.  */
+extern int acm_is_policy(char *buf, unsigned long len);
 
 #endif
 
xen-unstable.hg/xen/acm/Makefile +2 -0
Index: root/xen-unstable.hg/xen/acm/Makefile
===================================================================
@@ -3,3 +3,5 @@ obj-y += acm_policy.o
 obj-y += acm_simple_type_enforcement_hooks.o
 obj-y += acm_chinesewall_hooks.o
 obj-y += acm_null_hooks.o
+obj-$(x86_32) += acm_multiboot.o
+obj-$(x86_64) += acm_multiboot.o
xen-unstable.hg/xen/acm/acm_multiboot.c new file +2 -0
Index: root/xen-unstable.hg/xen/acm/acm_multiboot.c
===================================================================
@@ -0,0 +1,2 @@
+#include <acm/acm_hooks.h>
+
xen-unstable.hg/xen/include/asm-x86/acm.h new file +91 -0

91 lines not on this page · raw message

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

#1 lore raw

xen-unstable.hg/xen/acm/Makefile obj-y += acm_policy.o · line 7

Quoted 11 lines · Stefan Berger

Index: root/xen-unstable.hg/xen/acm/Makefile
===================================================================

xen-unstable.hg/xen/acm/Makefile +2 -0
@@ -3,3 +3,5 @@ obj-y += acm_policy.o
 obj-y += acm_simple_type_enforcement_hooks.o
 obj-y += acm_chinesewall_hooks.o
 obj-y += acm_null_hooks.o
+obj-$(x86_32) += acm_multiboot.o
+obj-$(x86_64) += acm_multiboot.o 

config/x86_* defines CONFIG_X86, so that would be better to use here.

Quoted 87 lines

Index: root/xen-unstable.hg/xen/include/asm-x86/acm.h
===================================================================

xen-unstable.hg/xen/include/asm-x86/acm.h new file +32 -0
@@ -0,0 +1,91 @@
+#ifndef _XEN_ASM_ACM_H
+#define _XEN_ASM_ACM_H
+
+#include <xen/multiboot.h>
+#include <acm/acm_hooks.h>
+
+#ifdef ACM_SECURITY
+
+/* Fetch acm policy module from multiboot modules.  */
+static inline void
+extract_acm_policy(multiboot_info_t *mbi,
+                   unsigned int *initrdidx,
+                   unsigned long initial_images_start,
+                   char **_policy_start, unsigned long *_policy_len)
+{
+    int i;
+    module_t *mod = (module_t *)__va(mbi->mods_addr);
+
+    if ( mbi->mods_count > 1 )
+        *initrdidx = 1;
+
+    /*
+     * Try all modules and see whichever could be the binary policy.
+     * Adjust the initrdidx if module[1] is the binary policy.
+     */
+    for ( i = mbi->mods_count-1; i >= 1; i-- )
+    {
+        unsigned long start;
+        char *policy_start;
+        unsigned long policy_len;
+
+        start = initial_images_start +

(mod[i].mod_start-mod[0].mod_start);

xen-unstable.hg/xen/include/asm-x86/acm.h new file +49 -0
+#if defined(__i386__)
+        policy_start = (char *)start;
+#elif defined(__x86_64__)
+        policy_start = __va(start);
+#endif
+        policy_len   = mod[i].mod_end - mod[i].mod_start;
+        if ( acm_is_policy(policy_start, policy_len) )
+        {
+            printf("Policy len  0x%lx, start at %p - module %d.\n",
+                   policy_len, policy_start, i);
+            *_policy_start = policy_start;
+            *_policy_len = policy_len;
+            if ( i == 1 )
+            {
+                if (mbi->mods_count > 2)
+                    *initrdidx = 2;
+                else
+                    *initrdidx = 0;
+            }
+            else
+                *initrdidx = 1;
+            break;
+        }
+    }
+}
+
+static inline
+int acm_x86_init(multiboot_info_t *mbi,
+                 unsigned int *initrdidx,
+                 unsigned long initial_images_start)
+{
+    char *_policy_start = NULL;
+    unsigned long _policy_len = 0;
+    /* Extract policy from multiboot.  */
+    extract_acm_policy(mbi,
+                       initrdidx,
+                       initial_images_start,
+                       &_policy_start, &_policy_len);
+
+    /*
+     * Initialize access control security module no matter whether
+     * a policy has been found or not.
+     */
+    return acm_init(_policy_start, _policy_len);
+}
+
+#else
+
+static inline

xen-unstable.hg/xen/include/asm-x86/acm.h line 91

Quoted 10 lines
xen-unstable.hg/xen/include/asm-x86/acm.h new file +10 -0
+int acm_x86_init(multiboot_info_t *mbi,
+                 unsigned int *initrdidx,
+                 unsigned long initial_images_start)
+{
+    return 0;
+}
+
+#endif
+
+#endif

These are way too big to be static inlines. Make them regular functions please.

Other than that, this patch seems great.

Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center
#2 lore raw

[email protected] wrote on 09/13/2006 10:51:29 AM:

Quoted 16 lines

xen-unstable.hg/xen/include/asm-x86/acm.h line 91

Quoted 12 lines
xen-unstable.hg/xen/include/asm-x86/acm.h new file +12 -0
+
+static inline
+int acm_x86_init(multiboot_info_t *mbi,
+                 unsigned int *initrdidx,
+                 unsigned long initial_images_start)
+{
+    return 0;
+}
+
+#endif
+
+#endif

These are way too big to be static inlines. Make them regular functions please.

Quoted 1 line

Other than that, this patch seems great.

Don't want to have that checked in so far, though.

What about the multiboot code. Do you think PPC will be able to also use this part? Not that I would move it, it's more out of curiosity.

Stefan

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

#3 lore raw
Quoted 6 lines · Stefan Berger

[email protected] wrote on 09/13/2006 10:51:29 AM:

Quoted 2 lines

Other than that, this patch seems great.

Don't want to have that checked in so far, though.

Why not?

BTW, I missed this first time:

xen-unstable.hg/xen/acm/acm_multiboot.c line 1

Quoted 4 lines
xen-unstable.hg/xen/acm/acm_multiboot.c new file +1 -0
@@ -0,0 +1,2 @@
+#include <acm/acm_hooks.h>

That is where the (non-inline) ACM/multiboot functions should live; not in a header file.

Quoted 2 lines

What about the multiboot code. Do you think PPC will be able to also use this part? Not that I would move it, it's more out of curiosity.

Well, that ifdef will need changing. Why must it exist at all, is it some weirdness of Xen/x86-64?

Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center
#4 lore raw

[email protected] wrote on 09/13/2006 11:00:16 AM:

Quoted 3 lines

That is where the (non-inline) ACM/multiboot functions should live; not in a header file.

I could move them there but that would include the architecture-dependent #ifdef's.

Quoted 6 lines
Quoted 3 lines

What about the multiboot code. Do you think PPC will be able to also use this part? Not that I would move it, it's more out of curiosity.

Well, that ifdef will need changing. Why must it exist at all, is it some weirdness of Xen/x86-64?

Yes, on x86-64 we need that. It would be possible to define MACROs for x86-64 and i386 so the code could look the same. It will be necessary to do either that for ia64 and ppc as well, or we just leave the #ifdef's in the ACM code. Either way is fine by me. From what I could find, there's at least grub available for ia64, so chances that ia64 can also use the multiboot code are high.

Stefan

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

#5 lore raw
Quoted 10 lines · Stefan Berger

[email protected] wrote on 09/13/2006 11:00:16 AM:

Quoted 2 lines

That is where the (non-inline) ACM/multiboot functions should live; not in a header file.

I could move them there but that would include the architecture-dependent #ifdef's.

Quoted 3 lines
Quoted 2 lines

What about the multiboot code. Do you think PPC will be able to also use this part? Not that I would move it, it's more out of curiosity.

Quoted 7 lines
Quoted 2 lines

Well, that ifdef will need changing. Why must it exist at all, is it some weirdness of Xen/x86-64?

Yes, on x86-64 we need that. It would be possible to define MACROs for x86-64 and i386 so the code could look the same. It will be necessary to do either that for ia64 and ppc as well, or we just leave the #ifdef's in the ACM code.

Hi,

sorry for the late reply, I am just back from holidays.

It seems you patch has not yet been merged. Is there any reason ? I'd like to see it in the repository, it will help me to enable ACM on ia64.

Quoted 3 lines

Either way is fine by me. From what I could find, there's at least grub available for ia64, so chances that ia64 can also use the multiboot code are high.

Yes I am porting grub to ia64. I am not sure it could use multiboot as is because multiboot is not 64 bits ready.

Tristan.

#6 lore raw

Tristan Gingold <[email protected]> wrote on 09/26/2006 07:54:27 AM:

Quoted 3 lines · Stefan Berger
Quoted 2 lines

[email protected] wrote on 09/13/2006 11:00:16 AM:

Quoted 1 line

That is where the (non-inline) ACM/multiboot functions should live;

not

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

in a header file.

I could move them there but that would include the

architecture-dependent

Quoted 3 lines
Quoted 3 lines

#ifdef's.

Quoted 1 line
Quoted 1 line

What about the multiboot code. Do you think PPC will be able to

also

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

use this part? Not that I would move it, it's more out of

curiosity.

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

Well, that ifdef will need changing. Why must it exist at all, is it some weirdness of Xen/x86-64?

Yes, on x86-64 we need that. It would be possible to define MACROs for x86-64 and i386 so the code could look the same. It will be necessary

to

Quoted 1 line
Quoted 1 line

do either that for ia64 and ppc as well, or we just leave the #ifdef's

in

Quoted 7 lines
Quoted 1 line

the ACM code.

Hi,

sorry for the late reply, I am just back from holidays.

It seems you patch has not yet been merged. Is there any reason ? I'd like to see it in the repository, it will help me to enable ACM on

ia64.

Quoted 1 line

We wanted to wait for the 3.0.3 close and submit them soon after that.

Quoted 4 lines
Quoted 3 lines

Either way is fine by me. From what I could find, there's at least grub available for ia64, so chances that ia64 can also use the multiboot code are high.

Yes I am porting grub to ia64. I am not sure it could use multiboot as

is

:-)

Stefan

Quoted 1 line

because multiboot is not 64 bits ready.

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

#7 lore raw
Quoted 1 line · Stefan Berger

Tristan Gingold <[email protected]> wrote on 09/26/2006 07:54:27

[...]

Quoted 9 lines
Quoted 6 lines

Hi,

sorry for the late reply, I am just back from holidays.

It seems you patch has not yet been merged. Is there any reason ? I'd like to see it in the repository, it will help me to enable ACM on

ia64.

We wanted to wait for the 3.0.3 close and submit them soon after that.

Sound reasonnable.
Thanks.

Tristan.