selinux: convert range transition list to a hashtab
[safe/jmp/linux-2.6] / security / selinux / ss / mls.c
index c713af2..443ae73 100644 (file)
@@ -13,7 +13,7 @@
 /*
  * Updated: Hewlett-Packard <paul.moore@hp.com>
  *
- *      Added support to import/export the MLS label
+ *      Added support to import/export the MLS label from NetLabel
  *
  * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
  */
@@ -22,6 +22,7 @@
 #include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/errno.h>
+#include <net/netlabel.h>
 #include "sidtab.h"
 #include "mls.h"
 #include "policydb.h"
  * Return the length in bytes for the MLS fields of the
  * security context string representation of `context'.
  */
-int mls_compute_context_len(struct context * context)
+int mls_compute_context_len(struct context *context)
 {
-       int i, l, len, range;
+       int i, l, len, head, prev;
+       char *nm;
+       struct ebitmap *e;
        struct ebitmap_node *node;
 
        if (!selinux_mls_enabled)
@@ -41,31 +44,33 @@ int mls_compute_context_len(struct context * context)
 
        len = 1; /* for the beginning ":" */
        for (l = 0; l < 2; l++) {
-               range = 0;
-               len += strlen(policydb.p_sens_val_to_name[context->range.level[l].sens - 1]);
-
-               ebitmap_for_each_bit(&context->range.level[l].cat, node, i) {
-                       if (ebitmap_node_get_bit(node, i)) {
-                               if (range) {
-                                       range++;
-                                       continue;
-                               }
+               int index_sens = context->range.level[l].sens;
+               len += strlen(policydb.p_sens_val_to_name[index_sens - 1]);
 
-                               len += strlen(policydb.p_cat_val_to_name[i]) + 1;
-                               range++;
-                       } else {
-                               if (range > 1)
-                                       len += strlen(policydb.p_cat_val_to_name[i - 1]) + 1;
-                               range = 0;
+               /* categories */
+               head = -2;
+               prev = -2;
+               e = &context->range.level[l].cat;
+               ebitmap_for_each_positive_bit(e, node, i) {
+                       if (i - prev > 1) {
+                               /* one or more negative bits are skipped */
+                               if (head != prev) {
+                                       nm = policydb.p_cat_val_to_name[prev];
+                                       len += strlen(nm) + 1;
+                               }
+                               nm = policydb.p_cat_val_to_name[i];
+                               len += strlen(nm) + 1;
+                               head = i;
                        }
+                       prev = i;
+               }
+               if (prev != head) {
+                       nm = policydb.p_cat_val_to_name[prev];
+                       len += strlen(nm) + 1;
                }
-               /* Handle case where last category is the end of range */
-               if (range > 1)
-                       len += strlen(policydb.p_cat_val_to_name[i - 1]) + 1;
-
                if (l == 0) {
                        if (mls_level_eq(&context->range.level[0],
-                                        &context->range.level[1]))
+                                        &context->range.level[1]))
                                break;
                        else
                                len++;
@@ -81,10 +86,11 @@ int mls_compute_context_len(struct context * context)
  * Update `*scontext' to point to the end of the MLS fields.
  */
 void mls_sid_to_context(struct context *context,
-                        char **scontext)
+                       char **scontext)
 {
-       char *scontextp;
-       int i, l, range, wrote_sep;
+       char *scontextp, *nm;
+       int i, l, head, prev;
+       struct ebitmap *e;
        struct ebitmap_node *node;
 
        if (!selinux_mls_enabled)
@@ -96,61 +102,54 @@ void mls_sid_to_context(struct context *context,
        scontextp++;
 
        for (l = 0; l < 2; l++) {
-               range = 0;
-               wrote_sep = 0;
                strcpy(scontextp,
                       policydb.p_sens_val_to_name[context->range.level[l].sens - 1]);
-               scontextp += strlen(policydb.p_sens_val_to_name[context->range.level[l].sens - 1]);
+               scontextp += strlen(scontextp);
 
                /* categories */
-               ebitmap_for_each_bit(&context->range.level[l].cat, node, i) {
-                       if (ebitmap_node_get_bit(node, i)) {
-                               if (range) {
-                                       range++;
-                                       continue;
-                               }
-
-                               if (!wrote_sep) {
-                                       *scontextp++ = ':';
-                                       wrote_sep = 1;
-                               } else
-                                       *scontextp++ = ',';
-                               strcpy(scontextp, policydb.p_cat_val_to_name[i]);
-                               scontextp += strlen(policydb.p_cat_val_to_name[i]);
-                               range++;
-                       } else {
-                               if (range > 1) {
-                                       if (range > 2)
+               head = -2;
+               prev = -2;
+               e = &context->range.level[l].cat;
+               ebitmap_for_each_positive_bit(e, node, i) {
+                       if (i - prev > 1) {
+                               /* one or more negative bits are skipped */
+                               if (prev != head) {
+                                       if (prev - head > 1)
                                                *scontextp++ = '.';
                                        else
                                                *scontextp++ = ',';
-
-                                       strcpy(scontextp, policydb.p_cat_val_to_name[i - 1]);
-                                       scontextp += strlen(policydb.p_cat_val_to_name[i - 1]);
+                                       nm = policydb.p_cat_val_to_name[prev];
+                                       strcpy(scontextp, nm);
+                                       scontextp += strlen(nm);
                                }
-                               range = 0;
+                               if (prev < 0)
+                                       *scontextp++ = ':';
+                               else
+                                       *scontextp++ = ',';
+                               nm = policydb.p_cat_val_to_name[i];
+                               strcpy(scontextp, nm);
+                               scontextp += strlen(nm);
+                               head = i;
                        }
+                       prev = i;
                }
 
-               /* Handle case where last category is the end of range */
-               if (range > 1) {
-                       if (range > 2)
+               if (prev != head) {
+                       if (prev - head > 1)
                                *scontextp++ = '.';
                        else
                                *scontextp++ = ',';
-
-                       strcpy(scontextp, policydb.p_cat_val_to_name[i - 1]);
-                       scontextp += strlen(policydb.p_cat_val_to_name[i - 1]);
+                       nm = policydb.p_cat_val_to_name[prev];
+                       strcpy(scontextp, nm);
+                       scontextp += strlen(nm);
                }
 
                if (l == 0) {
                        if (mls_level_eq(&context->range.level[0],
-                                        &context->range.level[1]))
+                                        &context->range.level[1]))
                                break;
-                       else {
-                               *scontextp = '-';
-                               scontextp++;
-                       }
+                       else
+                               *scontextp++ = '-';
                }
        }
 
@@ -158,51 +157,55 @@ void mls_sid_to_context(struct context *context,
        return;
 }
 
+int mls_level_isvalid(struct policydb *p, struct mls_level *l)
+{
+       struct level_datum *levdatum;
+       struct ebitmap_node *node;
+       int i;
+
+       if (!l->sens || l->sens > p->p_levels.nprim)
+               return 0;
+       levdatum = hashtab_search(p->p_levels.table,
+                                 p->p_sens_val_to_name[l->sens - 1]);
+       if (!levdatum)
+               return 0;
+
+       ebitmap_for_each_positive_bit(&l->cat, node, i) {
+               if (i > p->p_cats.nprim)
+                       return 0;
+               if (!ebitmap_get_bit(&levdatum->level->cat, i)) {
+                       /*
+                        * Category may not be associated with
+                        * sensitivity.
+                        */
+                       return 0;
+               }
+       }
+
+       return 1;
+}
+
+int mls_range_isvalid(struct policydb *p, struct mls_range *r)
+{
+       return (mls_level_isvalid(p, &r->level[0]) &&
+               mls_level_isvalid(p, &r->level[1]) &&
+               mls_level_dom(&r->level[1], &r->level[0]));
+}
+
 /*
  * Return 1 if the MLS fields in the security context
  * structure `c' are valid.  Return 0 otherwise.
  */
 int mls_context_isvalid(struct policydb *p, struct context *c)
 {
-       struct level_datum *levdatum;
        struct user_datum *usrdatum;
-       struct ebitmap_node *node;
-       int i, l;
 
        if (!selinux_mls_enabled)
                return 1;
 
-       /*
-        * MLS range validity checks: high must dominate low, low level must
-        * be valid (category set <-> sensitivity check), and high level must
-        * be valid (category set <-> sensitivity check)
-        */
-       if (!mls_level_dom(&c->range.level[1], &c->range.level[0]))
-               /* High does not dominate low. */
+       if (!mls_range_isvalid(p, &c->range))
                return 0;
 
-       for (l = 0; l < 2; l++) {
-               if (!c->range.level[l].sens || c->range.level[l].sens > p->p_levels.nprim)
-                       return 0;
-               levdatum = hashtab_search(p->p_levels.table,
-                       p->p_sens_val_to_name[c->range.level[l].sens - 1]);
-               if (!levdatum)
-                       return 0;
-
-               ebitmap_for_each_bit(&c->range.level[l].cat, node, i) {
-                       if (ebitmap_node_get_bit(node, i)) {
-                               if (i > p->p_cats.nprim)
-                                       return 0;
-                               if (!ebitmap_get_bit(&levdatum->level->cat, i))
-                                       /*
-                                        * Category may not be associated with
-                                        * sensitivity in low level.
-                                        */
-                                       return 0;
-                       }
-               }
-       }
-
        if (c->role == OBJECT_R_VAL)
                return 1;
 
@@ -236,7 +239,8 @@ int mls_context_isvalid(struct policydb *p, struct context *c)
  * Policy read-lock must be held for sidtab lookup.
  *
  */
-int mls_context_to_sid(char oldc,
+int mls_context_to_sid(struct policydb *pol,
+                      char oldc,
                       char **scontext,
                       struct context *context,
                       struct sidtab *s,
@@ -269,7 +273,7 @@ int mls_context_to_sid(char oldc,
                if (!defcon)
                        goto out;
 
-               rc = mls_copy_context(context, defcon);
+               rc = mls_context_cpy(context, defcon);
                goto out;
        }
 
@@ -279,11 +283,11 @@ int mls_context_to_sid(char oldc,
                p++;
 
        delim = *p;
-       if (delim != 0)
-               *p++ = 0;
+       if (delim != '\0')
+               *p++ = '\0';
 
        for (l = 0; l < 2; l++) {
-               levdatum = hashtab_search(policydb.p_levels.table, scontextp);
+               levdatum = hashtab_search(pol->p_levels.table, scontextp);
                if (!levdatum) {
                        rc = -EINVAL;
                        goto out;
@@ -298,24 +302,25 @@ int mls_context_to_sid(char oldc,
                                while (*p && *p != ',' && *p != '-')
                                        p++;
                                delim = *p;
-                               if (delim != 0)
-                                       *p++ = 0;
+                               if (delim != '\0')
+                                       *p++ = '\0';
 
                                /* Separate into range if exists */
-                               if ((rngptr = strchr(scontextp, '.')) != NULL) {
+                               rngptr = strchr(scontextp, '.');
+                               if (rngptr != NULL) {
                                        /* Remove '.' */
-                                       *rngptr++ = 0;
+                                       *rngptr++ = '\0';
                                }
 
-                               catdatum = hashtab_search(policydb.p_cats.table,
-                                                         scontextp);
+                               catdatum = hashtab_search(pol->p_cats.table,
+                                                         scontextp);
                                if (!catdatum) {
                                        rc = -EINVAL;
                                        goto out;
                                }
 
                                rc = ebitmap_set_bit(&context->range.level[l].cat,
-                                                    catdatum->value - 1, 1);
+                                                    catdatum->value - 1, 1);
                                if (rc)
                                        goto out;
 
@@ -323,7 +328,7 @@ int mls_context_to_sid(char oldc,
                                if (rngptr) {
                                        int i;
 
-                                       rngdatum = hashtab_search(policydb.p_cats.table, rngptr);
+                                       rngdatum = hashtab_search(pol->p_cats.table, rngptr);
                                        if (!rngdatum) {
                                                rc = -EINVAL;
                                                goto out;
@@ -352,8 +357,8 @@ int mls_context_to_sid(char oldc,
                                p++;
 
                        delim = *p;
-                       if (delim != 0)
-                               *p++ = 0;
+                       if (delim != '\0')
+                               *p++ = '\0';
                } else
                        break;
        }
@@ -391,8 +396,8 @@ int mls_from_string(char *str, struct context *context, gfp_t gfp_mask)
        if (!tmpstr) {
                rc = -ENOMEM;
        } else {
-               rc = mls_context_to_sid(':', &tmpstr, context,
-                                       NULL, SECSID_NULL);
+               rc = mls_context_to_sid(&policydb, ':', &tmpstr, context,
+                                       NULL, SECSID_NULL);
                kfree(freestr);
        }
 
@@ -400,30 +405,10 @@ int mls_from_string(char *str, struct context *context, gfp_t gfp_mask)
 }
 
 /*
- * Copies the effective MLS range from `src' into `dst'.
- */
-static inline int mls_scopy_context(struct context *dst,
-                                    struct context *src)
-{
-       int l, rc = 0;
-
-       /* Copy the MLS range from the source context */
-       for (l = 0; l < 2; l++) {
-               dst->range.level[l].sens = src->range.level[0].sens;
-               rc = ebitmap_cpy(&dst->range.level[l].cat,
-                                &src->range.level[0].cat);
-               if (rc)
-                       break;
-       }
-
-       return rc;
-}
-
-/*
  * Copies the MLS range `range' into `context'.
  */
 static inline int mls_range_set(struct context *context,
-                                struct mls_range *range)
+                               struct mls_range *range)
 {
        int l, rc = 0;
 
@@ -440,7 +425,7 @@ static inline int mls_range_set(struct context *context,
 }
 
 int mls_setup_user_range(struct context *fromcon, struct user_datum *user,
-                         struct context *usercon)
+                        struct context *usercon)
 {
        if (selinux_mls_enabled) {
                struct mls_level *fromcon_sen = &(fromcon->range.level[0]);
@@ -452,13 +437,13 @@ int mls_setup_user_range(struct context *fromcon, struct user_datum *user,
                struct mls_level *usercon_clr = &(usercon->range.level[1]);
 
                /* Honor the user's default level if we can */
-               if (mls_level_between(user_def, fromcon_sen, fromcon_clr)) {
+               if (mls_level_between(user_def, fromcon_sen, fromcon_clr))
                        *usercon_sen = *user_def;
-               } else if (mls_level_between(fromcon_sen, user_def, user_clr)) {
+               else if (mls_level_between(fromcon_sen, user_def, user_clr))
                        *usercon_sen = *fromcon_sen;
-               } else if (mls_level_between(fromcon_clr, user_low, user_def)) {
+               else if (mls_level_between(fromcon_clr, user_low, user_def))
                        *usercon_sen = *user_low;
-               else
+               else
                        return -EINVAL;
 
                /* Lower the clearance of available contexts
@@ -466,11 +451,11 @@ int mls_setup_user_range(struct context *fromcon, struct user_datum *user,
                   that of the user's default clearance (but
                   only if the "fromcon" clearance dominates
                   the user's computed sensitivity level) */
-               if (mls_level_dom(user_clr, fromcon_clr)) {
+               if (mls_level_dom(user_clr, fromcon_clr))
                        *usercon_clr = *fromcon_clr;
-               } else if (mls_level_dom(fromcon_clr, user_clr)) {
+               else if (mls_level_dom(fromcon_clr, user_clr))
                        *usercon_clr = *user_clr;
-               else
+               else
                        return -EINVAL;
        }
 
@@ -504,18 +489,16 @@ int mls_convert_context(struct policydb *oldp,
                c->range.level[l].sens = levdatum->level->sens;
 
                ebitmap_init(&bitmap);
-               ebitmap_for_each_bit(&c->range.level[l].cat, node, i) {
-                       if (ebitmap_node_get_bit(node, i)) {
-                               int rc;
-
-                               catdatum = hashtab_search(newp->p_cats.table,
-                                               oldp->p_cat_val_to_name[i]);
-                               if (!catdatum)
-                                       return -EINVAL;
-                               rc = ebitmap_set_bit(&bitmap, catdatum->value - 1, 1);
-                               if (rc)
-                                       return rc;
-                       }
+               ebitmap_for_each_positive_bit(&c->range.level[l].cat, node, i) {
+                       int rc;
+
+                       catdatum = hashtab_search(newp->p_cats.table,
+                                                 oldp->p_cat_val_to_name[i]);
+                       if (!catdatum)
+                               return -EINVAL;
+                       rc = ebitmap_set_bit(&bitmap, catdatum->value - 1, 1);
+                       if (rc)
+                               return rc;
                }
                ebitmap_destroy(&c->range.level[l].cat);
                c->range.level[l].cat = bitmap;
@@ -530,7 +513,8 @@ int mls_compute_sid(struct context *scontext,
                    u32 specified,
                    struct context *newcontext)
 {
-       struct range_trans *rtr;
+       struct range_trans rtr;
+       struct mls_range *r;
 
        if (!selinux_mls_enabled)
                return 0;
@@ -538,185 +522,131 @@ int mls_compute_sid(struct context *scontext,
        switch (specified) {
        case AVTAB_TRANSITION:
                /* Look for a range transition rule. */
-               for (rtr = policydb.range_tr; rtr; rtr = rtr->next) {
-                       if (rtr->source_type == scontext->type &&
-                           rtr->target_type == tcontext->type &&
-                           rtr->target_class == tclass) {
-                               /* Set the range from the rule */
-                               return mls_range_set(newcontext,
-                                                    &rtr->target_range);
-                       }
-               }
+               rtr.source_type = scontext->type;
+               rtr.target_type = tcontext->type;
+               rtr.target_class = tclass;
+               r = hashtab_search(policydb.range_tr, &rtr);
+               if (r)
+                       return mls_range_set(newcontext, r);
                /* Fallthrough */
        case AVTAB_CHANGE:
-               if (tclass == SECCLASS_PROCESS)
+               if (tclass == policydb.process_class)
                        /* Use the process MLS attributes. */
-                       return mls_copy_context(newcontext, scontext);
+                       return mls_context_cpy(newcontext, scontext);
                else
                        /* Use the process effective MLS attributes. */
-                       return mls_scopy_context(newcontext, scontext);
+                       return mls_context_cpy_low(newcontext, scontext);
        case AVTAB_MEMBER:
-               /* Only polyinstantiate the MLS attributes if
-                  the type is being polyinstantiated */
-               if (newcontext->type != tcontext->type) {
-                       /* Use the process effective MLS attributes. */
-                       return mls_scopy_context(newcontext, scontext);
-               } else {
-                       /* Use the related object MLS attributes. */
-                       return mls_copy_context(newcontext, tcontext);
-               }
-       default:
-               return -EINVAL;
+               /* Use the process effective MLS attributes. */
+               return mls_context_cpy_low(newcontext, scontext);
+
+       /* fall through */
        }
        return -EINVAL;
 }
 
+#ifdef CONFIG_NETLABEL
 /**
- * mls_export_lvl - Export the MLS sensitivity levels
+ * mls_export_netlbl_lvl - Export the MLS sensitivity levels to NetLabel
  * @context: the security context
- * @low: the low sensitivity level
- * @high: the high sensitivity level
+ * @secattr: the NetLabel security attributes
  *
  * Description:
- * Given the security context copy the low MLS sensitivity level into lvl_low
- * and the high sensitivity level in lvl_high.  The MLS levels are only
- * exported if the pointers are not NULL, if they are NULL then that level is
- * not exported.
+ * Given the security context copy the low MLS sensitivity level into the
+ * NetLabel MLS sensitivity level field.
  *
  */
-void mls_export_lvl(const struct context *context, u32 *low, u32 *high)
+void mls_export_netlbl_lvl(struct context *context,
+                          struct netlbl_lsm_secattr *secattr)
 {
        if (!selinux_mls_enabled)
                return;
 
-       if (low != NULL)
-               *low = context->range.level[0].sens - 1;
-       if (high != NULL)
-               *high = context->range.level[1].sens - 1;
+       secattr->attr.mls.lvl = context->range.level[0].sens - 1;
+       secattr->flags |= NETLBL_SECATTR_MLS_LVL;
 }
 
 /**
- * mls_import_lvl - Import the MLS sensitivity levels
+ * mls_import_netlbl_lvl - Import the NetLabel MLS sensitivity levels
  * @context: the security context
- * @low: the low sensitivity level
- * @high: the high sensitivity level
+ * @secattr: the NetLabel security attributes
  *
  * Description:
- * Given the security context and the two sensitivty levels, set the MLS levels
- * in the context according the two given as parameters.  Returns zero on
- * success, negative values on failure.
+ * Given the security context and the NetLabel security attributes, copy the
+ * NetLabel MLS sensitivity level into the context.
  *
  */
-void mls_import_lvl(struct context *context, u32 low, u32 high)
+void mls_import_netlbl_lvl(struct context *context,
+                          struct netlbl_lsm_secattr *secattr)
 {
        if (!selinux_mls_enabled)
                return;
 
-       context->range.level[0].sens = low + 1;
-       context->range.level[1].sens = high + 1;
+       context->range.level[0].sens = secattr->attr.mls.lvl + 1;
+       context->range.level[1].sens = context->range.level[0].sens;
 }
 
 /**
- * mls_export_cat - Export the MLS categories
+ * mls_export_netlbl_cat - Export the MLS categories to NetLabel
  * @context: the security context
- * @low: the low category
- * @low_len: length of the cat_low bitmap in bytes
- * @high: the high category
- * @high_len: length of the cat_high bitmap in bytes
+ * @secattr: the NetLabel security attributes
  *
  * Description:
- * Given the security context export the low MLS category bitmap into cat_low
- * and the high category bitmap into cat_high.  The MLS categories are only
- * exported if the pointers are not NULL, if they are NULL then that level is
- * not exported.  The caller is responsibile for freeing the memory when
- * finished.  Returns zero on success, negative values on failure.
+ * Given the security context copy the low MLS categories into the NetLabel
+ * MLS category field.  Returns zero on success, negative values on failure.
  *
  */
-int mls_export_cat(const struct context *context,
-                  unsigned char **low,
-                  size_t *low_len,
-                  unsigned char **high,
-                  size_t *high_len)
+int mls_export_netlbl_cat(struct context *context,
+                         struct netlbl_lsm_secattr *secattr)
 {
-       int rc = -EPERM;
+       int rc;
 
        if (!selinux_mls_enabled)
                return 0;
 
-       if (low != NULL) {
-               rc = ebitmap_export(&context->range.level[0].cat,
-                                   low,
-                                   low_len);
-               if (rc != 0)
-                       goto export_cat_failure;
-       }
-       if (high != NULL) {
-               rc = ebitmap_export(&context->range.level[1].cat,
-                                   high,
-                                   high_len);
-               if (rc != 0)
-                       goto export_cat_failure;
-       }
-
-       return 0;
+       rc = ebitmap_netlbl_export(&context->range.level[0].cat,
+                                  &secattr->attr.mls.cat);
+       if (rc == 0 && secattr->attr.mls.cat != NULL)
+               secattr->flags |= NETLBL_SECATTR_MLS_CAT;
 
-export_cat_failure:
-       if (low != NULL)
-               kfree(*low);
-       if (high != NULL)
-               kfree(*high);
        return rc;
 }
 
 /**
- * mls_import_cat - Import the MLS categories
+ * mls_import_netlbl_cat - Import the MLS categories from NetLabel
  * @context: the security context
- * @low: the low category
- * @low_len: length of the cat_low bitmap in bytes
- * @high: the high category
- * @high_len: length of the cat_high bitmap in bytes
+ * @secattr: the NetLabel security attributes
  *
  * Description:
- * Given the security context and the two category bitmap strings import the
- * categories into the security context.  The MLS categories are only imported
- * if the pointers are not NULL, if they are NULL they are skipped.  Returns
- * zero on success, negative values on failure.
+ * Copy the NetLabel security attributes into the SELinux context; since the
+ * NetLabel security attribute only contains a single MLS category use it for
+ * both the low and high categories of the context.  Returns zero on success,
+ * negative values on failure.
  *
  */
-int mls_import_cat(struct context *context,
-                  const unsigned char *low,
-                  size_t low_len,
-                  const unsigned char *high,
-                  size_t high_len)
+int mls_import_netlbl_cat(struct context *context,
+                         struct netlbl_lsm_secattr *secattr)
 {
-       int rc = -EPERM;
+       int rc;
 
        if (!selinux_mls_enabled)
                return 0;
 
-       if (low != NULL) {
-               rc = ebitmap_import(low,
-                                   low_len,
-                                   &context->range.level[0].cat);
-               if (rc != 0)
-                       goto import_cat_failure;
-       }
-       if (high != NULL) {
-               if (high == low)
-                       rc = ebitmap_cpy(&context->range.level[1].cat,
-                                        &context->range.level[0].cat);
-               else
-                       rc = ebitmap_import(high,
-                                           high_len,
-                                           &context->range.level[1].cat);
-               if (rc != 0)
-                       goto import_cat_failure;
-       }
+       rc = ebitmap_netlbl_import(&context->range.level[0].cat,
+                                  secattr->attr.mls.cat);
+       if (rc != 0)
+               goto import_netlbl_cat_failure;
+
+       rc = ebitmap_cpy(&context->range.level[1].cat,
+                        &context->range.level[0].cat);
+       if (rc != 0)
+               goto import_netlbl_cat_failure;
 
        return 0;
 
-import_cat_failure:
+import_netlbl_cat_failure:
        ebitmap_destroy(&context->range.level[0].cat);
        ebitmap_destroy(&context->range.level[1].cat);
        return rc;
 }
+#endif /* CONFIG_NETLABEL */