Skip to content

Commit

Permalink
apparmor: fix invalid reference on profile->disconnected
Browse files Browse the repository at this point in the history
[ Upstream commit 8884ba0 ]

profile->disconnected was storing an invalid reference to the
disconnected path. Fix it by duplicating the string using
aa_unpack_strdup and freeing accordingly.

Fixes: 72c8a76 ("apparmor: allow profiles to provide info to disconnected paths")
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
gegarcia authored and gregkh committed Nov 20, 2023
1 parent 74e5ce3 commit f997e1b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions security/apparmor/policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ void aa_free_profile(struct aa_profile *profile)

aa_put_ns(profile->ns);
kfree_sensitive(profile->rename);
kfree_sensitive(profile->disconnected);

free_attachment(&profile->attach);

Expand Down
5 changes: 3 additions & 2 deletions security/apparmor/policy_unpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)
const char *info = "failed to unpack profile";
size_t ns_len;
struct rhashtable_params params = { 0 };
char *key = NULL;
char *key = NULL, *disconnected = NULL;
struct aa_data *data;
int error = -EPROTO;
kernel_cap_t tmpcap;
Expand Down Expand Up @@ -870,7 +870,8 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)
}

/* disconnected attachment string is optional */
(void) aa_unpack_str(e, &profile->disconnected, "disconnected");
(void) aa_unpack_strdup(e, &disconnected, "disconnected");
profile->disconnected = disconnected;

/* per profile debug flags (complain, audit) */
if (!aa_unpack_nameX(e, AA_STRUCT, "flags")) {
Expand Down

0 comments on commit f997e1b

Please sign in to comment.