Commit 145a0ef2 authored by John Johansen's avatar John Johansen

apparmor: fix blob compression when ns is forced on a policy load

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: 876dd866c084 ("apparmor: Initial implementation of raw policy blob compression")
Signed-off-by: default avatarJohn Johansen <john.johansen@canonical.com>
parent fe166a9f
...@@ -861,7 +861,7 @@ static struct aa_profile *update_to_newest_parent(struct aa_profile *new) ...@@ -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, ssize_t aa_replace_profiles(struct aa_ns *policy_ns, struct aa_label *label,
u32 mask, struct aa_loaddata *udata) 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_ns *ns = NULL;
struct aa_load_ent *ent, *tmp; struct aa_load_ent *ent, *tmp;
struct aa_loaddata *rawdata_ent; struct aa_loaddata *rawdata_ent;
...@@ -1048,6 +1048,7 @@ ssize_t aa_replace_profiles(struct aa_ns *policy_ns, struct aa_label *label, ...@@ -1048,6 +1048,7 @@ ssize_t aa_replace_profiles(struct aa_ns *policy_ns, struct aa_label *label,
out: out:
aa_put_ns(ns); aa_put_ns(ns);
aa_put_loaddata(udata); aa_put_loaddata(udata);
kfree(ns_name);
if (error) if (error)
return error; return error;
......
...@@ -944,11 +944,14 @@ static int verify_header(struct aa_ext *e, int required, const char **ns) ...@@ -944,11 +944,14 @@ static int verify_header(struct aa_ext *e, int required, const char **ns)
e, error); e, error);
return error; return error;
} }
if (*ns && strcmp(*ns, name)) if (*ns && strcmp(*ns, name)) {
audit_iface(NULL, NULL, NULL, "invalid ns change", e, audit_iface(NULL, NULL, NULL, "invalid ns change", e,
error); error);
else if (!*ns) } else if (!*ns) {
*ns = name; *ns = kstrdup(name, GFP_KERNEL);
if (!*ns)
return -ENOMEM;
}
} }
return 0; return 0;
......
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