Skip to content

Commit

Permalink
Don't try to change aa label if we are already apparmor-confined
Browse files Browse the repository at this point in the history
Closes #1459

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
  • Loading branch information
hallyn authored and stgraber committed Jan 4, 2016
1 parent 642e2c5 commit 9bfdc0a
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions src/lxc/lsm/apparmor.c
Expand Up @@ -127,12 +127,31 @@ static char *apparmor_process_label_get(pid_t pid)
return buf;
}

static int apparmor_am_unconfined(void)
/*
* Probably makes sense to reorganize these to only read
* the label once
*/
static bool apparmor_am_unconfined(void)
{
char *p = apparmor_process_label_get(getpid());
int ret = 0;
bool ret = false;
if (!p || strcmp(p, "unconfined") == 0)
ret = 1;
ret = true;
free(p);
return ret;
}

/* aa stacking is not yet supported */
static bool aa_stacking_supported(void) {
return false;
}

/* are we in a confined container? */
static bool in_aa_confined_container(void) {
char *p = apparmor_process_label_get(getpid());
bool ret = false;
if (p && strcmp(p, "/usr/bin/lxc-start") != 0)
ret = true;
free(p);
return ret;
}
Expand Down Expand Up @@ -163,6 +182,19 @@ static int apparmor_process_label_set(const char *inlabel, struct lxc_conf *conf
return 0;
}

/*
* If we are already confined and no profile was requested,
* then default to unchanged
*/
if (in_aa_confined_container() && !aa_stacking_supported()) {
if (label) {
ERROR("already apparmor confined, but new label requested.");
return -1;
}
INFO("Already apparmor-confined");
return 0;
}

if (!label) {
if (use_default)
label = AA_DEF_PROFILE;
Expand Down

0 comments on commit 9bfdc0a

Please sign in to comment.