Skip to content

Commit

Permalink
apparmor: fix blob compression when ns is forced on a policy load
Browse files Browse the repository at this point in the history
When blob compression is turned on, if the policy namespace is forced
onto a policy load, the policy load will fail as the namespace name
being referenced is inside the compressed policy blob, resulting in
invalid or names that are too long. So duplicate the name before the
blob is compressed.

Fixes: 876dd86 ("apparmor: Initial implementation of raw policy blob compression")
Signed-off-by: John Johansen <john.johansen@canonical.com>
  • Loading branch information
John Johansen committed Apr 11, 2019
1 parent fe166a9 commit 145a0ef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion security/apparmor/policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ static struct aa_profile *update_to_newest_parent(struct aa_profile *new)
ssize_t aa_replace_profiles(struct aa_ns *policy_ns, struct aa_label *label,
u32 mask, struct aa_loaddata *udata)
{
const char *ns_name, *info = NULL;
const char *ns_name = NULL, *info = NULL;
struct aa_ns *ns = NULL;
struct aa_load_ent *ent, *tmp;
struct aa_loaddata *rawdata_ent;
Expand Down Expand Up @@ -1048,6 +1048,7 @@ ssize_t aa_replace_profiles(struct aa_ns *policy_ns, struct aa_label *label,
out:
aa_put_ns(ns);
aa_put_loaddata(udata);
kfree(ns_name);

if (error)
return error;
Expand Down
9 changes: 6 additions & 3 deletions security/apparmor/policy_unpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -944,11 +944,14 @@ static int verify_header(struct aa_ext *e, int required, const char **ns)
e, error);
return error;
}
if (*ns && strcmp(*ns, name))
if (*ns && strcmp(*ns, name)) {
audit_iface(NULL, NULL, NULL, "invalid ns change", e,
error);
else if (!*ns)
*ns = name;
} else if (!*ns) {
*ns = kstrdup(name, GFP_KERNEL);
if (!*ns)
return -ENOMEM;
}
}

return 0;
Expand Down

0 comments on commit 145a0ef

Please sign in to comment.