Commit 709bba29 authored by John Johansen's avatar John Johansen Committed by Tim Gardner

Revert "UBUNTU: SAUCE: apparmor: Fix: label merge handling of marking unconfined and stale"

BugLink: http://bugs.launchpad.net/bugs/1379535

This reverts commit 919e68433341077eec6b72c268447e2883f5c0b8.
Signed-off-by: default avatarTim Gardner <tim.gardner@canonical.com>
parent e23c92ae
...@@ -358,6 +358,7 @@ bool aa_label_remove(struct aa_labelset *ls, struct aa_label *l) ...@@ -358,6 +358,7 @@ bool aa_label_remove(struct aa_labelset *ls, struct aa_label *l)
return res; return res;
} }
#if 0
/* don't use when using ptr comparisons because nodes should never be /* don't use when using ptr comparisons because nodes should never be
* the same * the same
*/ */
...@@ -385,9 +386,10 @@ static bool __aa_label_replace(struct aa_labelset *ls, struct aa_label *old, ...@@ -385,9 +386,10 @@ static bool __aa_label_replace(struct aa_labelset *ls, struct aa_label *old,
return false; return false;
} }
#endif
static struct aa_label *__aa_label_insert(struct aa_labelset *ls, static struct aa_label *__aa_label_insert(struct aa_labelset *ls,
struct aa_label *l, bool replace); struct aa_label *l);
static struct aa_label *__aa_label_remove_and_insert(struct aa_labelset *ls, static struct aa_label *__aa_label_remove_and_insert(struct aa_labelset *ls,
struct aa_label *remove, struct aa_label *remove,
...@@ -401,7 +403,7 @@ static struct aa_label *__aa_label_remove_and_insert(struct aa_labelset *ls, ...@@ -401,7 +403,7 @@ static struct aa_label *__aa_label_remove_and_insert(struct aa_labelset *ls,
AA_BUG(insert->flags & FLAG_IN_TREE); AA_BUG(insert->flags & FLAG_IN_TREE);
__aa_label_remove(ls, remove); __aa_label_remove(ls, remove);
return __aa_label_insert(ls, insert, false); return __aa_label_insert(ls, insert);
} }
struct aa_label *aa_label_remove_and_insert(struct aa_labelset *ls, struct aa_label *aa_label_remove_and_insert(struct aa_labelset *ls,
...@@ -436,7 +438,7 @@ bool aa_label_replace(struct aa_labelset *ls, struct aa_label *old, ...@@ -436,7 +438,7 @@ bool aa_label_replace(struct aa_labelset *ls, struct aa_label *old,
write_lock_irqsave(&ls->lock, flags); write_lock_irqsave(&ls->lock, flags);
if (!(old->flags & FLAG_IN_TREE)) if (!(old->flags & FLAG_IN_TREE))
l = __aa_label_insert(ls, new, false); l = __aa_label_insert(ls, new);
else else
l = __aa_label_remove_and_insert(ls, old, new); l = __aa_label_remove_and_insert(ls, old, new);
res = (l == new); res = (l == new);
...@@ -649,7 +651,7 @@ struct aa_label *aa_label_find(struct aa_labelset *ls, struct aa_label *l) ...@@ -649,7 +651,7 @@ struct aa_label *aa_label_find(struct aa_labelset *ls, struct aa_label *l)
* __aa_label_insert - attempt to insert @l into a label set * __aa_label_insert - attempt to insert @l into a label set
* @ls: set of labels to insert @l into (NOT NULL) * @ls: set of labels to insert @l into (NOT NULL)
* @l: new label to insert (NOT NULL) * @l: new label to insert (NOT NULL)
* @replace: whether this insertion should replace an existing entry if present *
* Requires: @ls->lock * Requires: @ls->lock
* caller to hold a valid ref on l * caller to hold a valid ref on l
* *
...@@ -657,7 +659,7 @@ struct aa_label *aa_label_find(struct aa_labelset *ls, struct aa_label *l) ...@@ -657,7 +659,7 @@ struct aa_label *aa_label_find(struct aa_labelset *ls, struct aa_label *l)
* else ref counted equivalent label that is already in the set. * else ref counted equivalent label that is already in the set.
*/ */
static struct aa_label *__aa_label_insert(struct aa_labelset *ls, static struct aa_label *__aa_label_insert(struct aa_labelset *ls,
struct aa_label *l, bool replace) struct aa_label *l)
{ {
struct rb_node **new, *parent = NULL; struct rb_node **new, *parent = NULL;
...@@ -675,10 +677,7 @@ static struct aa_label *__aa_label_insert(struct aa_labelset *ls, ...@@ -675,10 +677,7 @@ static struct aa_label *__aa_label_insert(struct aa_labelset *ls,
parent = *new; parent = *new;
if (result == 0) { if (result == 0) {
labelsetstats_inc(ls, existing); labelsetstats_inc(ls, existing);
if (!replace)
return this; return this;
__aa_label_replace(ls, this, l);
return l;
} else if (result < 0) } else if (result < 0)
new = &((*new)->rb_left); new = &((*new)->rb_left);
else /* (result > 0) */ else /* (result > 0) */
...@@ -724,7 +723,7 @@ struct aa_label *aa_label_insert(struct aa_labelset *ls, struct aa_label *l) ...@@ -724,7 +723,7 @@ struct aa_label *aa_label_insert(struct aa_labelset *ls, struct aa_label *l)
} }
write_lock_irqsave(&ls->lock, flags); write_lock_irqsave(&ls->lock, flags);
label = aa_get_label(__aa_label_insert(ls, l, false)); label = aa_get_label(__aa_label_insert(ls, l));
write_unlock_irqrestore(&ls->lock, flags); write_unlock_irqrestore(&ls->lock, flags);
return label; return label;
...@@ -894,7 +893,7 @@ static int aa_sort_and_merge_profiles(int n, struct aa_profile **ps) ...@@ -894,7 +893,7 @@ static int aa_sort_and_merge_profiles(int n, struct aa_profile **ps)
} }
/** /**
* __label_merge_insert - create a new label by merging @a and @b * __label_merge - create a new label by merging @a and @b
* @l: preallocated label to merge into (NOT NULL) * @l: preallocated label to merge into (NOT NULL)
* @a: label to merge with @b (NOT NULL) * @a: label to merge with @b (NOT NULL)
* @b: label to merge with @a (NOT NULL) * @b: label to merge with @a (NOT NULL)
...@@ -908,15 +907,12 @@ static int aa_sort_and_merge_profiles(int n, struct aa_profile **ps) ...@@ -908,15 +907,12 @@ static int aa_sort_and_merge_profiles(int n, struct aa_profile **ps)
* Must be used within labelset write lock to avoid racing with * Must be used within labelset write lock to avoid racing with
* label invalidation. * label invalidation.
*/ */
static struct aa_label *__label_merge_insert(struct aa_labelset *ls, static struct aa_label *__label_merge(struct aa_label *l, struct aa_label *a,
struct aa_label *l,
struct aa_label *a,
struct aa_label *b) struct aa_label *b)
{ {
struct aa_profile *next; struct aa_profile *next;
struct label_it i; struct label_it i;
int k = 0, invcount = 0; int k = 0, invcount = 0;
bool stale = false;
AA_BUG(!a); AA_BUG(!a);
AA_BUG(a->size < 0); AA_BUG(a->size < 0);
...@@ -935,7 +931,6 @@ static struct aa_label *__label_merge_insert(struct aa_labelset *ls, ...@@ -935,7 +931,6 @@ static struct aa_label *__label_merge_insert(struct aa_labelset *ls,
l->ent[k]->label.replacedby) l->ent[k]->label.replacedby)
invcount++; invcount++;
k++; k++;
stale = true;
} else } else
l->ent[k++] = aa_get_profile(next); l->ent[k++] = aa_get_profile(next);
} }
...@@ -945,17 +940,17 @@ static struct aa_label *__label_merge_insert(struct aa_labelset *ls, ...@@ -945,17 +940,17 @@ static struct aa_label *__label_merge_insert(struct aa_labelset *ls,
if (invcount) { if (invcount) {
l->size -= aa_sort_and_merge_profiles(l->size, &l->ent[0]); l->size -= aa_sort_and_merge_profiles(l->size, &l->ent[0]);
} else if (!stale) { if (label_profiles_unconfined(l))
/* merge could be same as a || b, note: it is not possible l->flags |= FLAG_UNCONFINED;
* for l->size == a->size == b->size unless a == b */ } else {
/* merge is same as at least one of the labels */
if (k == a->size) if (k == a->size)
return aa_get_label(a); return aa_get_label(a);
else if (k == b->size) else if (k == b->size)
return aa_get_label(b); return aa_get_label(b);
l->flags |= a->flags & b->flags & FLAG_UNCONFINED;
} }
if (label_profiles_unconfined(l))
l->flags |= FLAG_UNCONFINED;
__aa_label_insert(ls, l, true);
return aa_get_label(l); return aa_get_label(l);
} }
...@@ -1089,7 +1084,7 @@ struct aa_label *aa_label_merge(struct aa_label *a, struct aa_label *b, ...@@ -1089,7 +1084,7 @@ struct aa_label *aa_label_merge(struct aa_label *a, struct aa_label *b,
*/ */
if (!label) { if (!label) {
struct aa_label *new; struct aa_label *new, *l;
a = aa_get_newest_label(a); a = aa_get_newest_label(a);
b = aa_get_newest_label(b); b = aa_get_newest_label(b);
...@@ -1102,14 +1097,17 @@ struct aa_label *aa_label_merge(struct aa_label *a, struct aa_label *b, ...@@ -1102,14 +1097,17 @@ struct aa_label *aa_label_merge(struct aa_label *a, struct aa_label *b,
return NULL; return NULL;
write_lock_irqsave(&ls->lock, flags); write_lock_irqsave(&ls->lock, flags);
label = __label_merge_insert(ls, new, a, b); l = __label_merge(new, a, b);
write_unlock_irqrestore(&ls->lock, flags); if (l != new) {
if (label != new) {
/* new may not be fully setup so no put_label */ /* new may not be fully setup so no put_label */
aa_label_free(new); aa_label_free(new);
new = NULL; new = NULL;
} }
if (!(l->flags & FLAG_IN_TREE))
label = aa_get_label(__aa_label_insert(ls, l));
write_unlock_irqrestore(&ls->lock, flags);
aa_put_label(new); aa_put_label(new);
aa_put_label(l);
aa_put_label(a); aa_put_label(a);
aa_put_label(b); aa_put_label(b);
} }
...@@ -1144,7 +1142,7 @@ struct aa_label *aa_label_vec_merge(struct aa_profile **vec, int len, ...@@ -1144,7 +1142,7 @@ struct aa_label *aa_label_vec_merge(struct aa_profile **vec, int len,
write_lock_irqsave(&ls->lock, flags); write_lock_irqsave(&ls->lock, flags);
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
new->ent[i] = aa_get_profile(vec[i]); new->ent[i] = aa_get_profile(vec[i]);
label = __aa_label_insert(ls, new, false); label = __aa_label_insert(ls, new);
if (label != new) { if (label != new) {
aa_get_label(label); aa_get_label(label);
/* not fully constructed don't put */ /* not fully constructed don't put */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment