apparmor: fix invalid reference on profile->disconnected
authorGeorgia Garcia <georgia.garcia@canonical.com>
Mon, 21 Aug 2023 18:37:24 +0000 (15:37 -0300)
committerJohn Johansen <john.johansen@canonical.com>
Tue, 22 Aug 2023 19:16:54 +0000 (12:16 -0700)
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: 72c8a768641d ("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>
security/apparmor/policy.c
security/apparmor/policy_unpack.c

index 4817c1b30105324cb0c09d06a1728c20346be817..d7525f228c43233958d172da9a8adc740de40912 100644 (file)
@@ -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);
 
index d2d740bb5618f271368fe8d4b1aa6d9e55c346a9..8b2ad42c80ba070b4af8e155041265c45c736e6b 100644 (file)
@@ -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;
@@ -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")) {