From: John Johansen <john.johansen@canonical.com>
To: Fedor Pchelkin <pchelkin@ispras.ru>
Cc: Paul Moore <paul@paul-moore.com>,
James Morris <jmorris@namei.org>,
"Serge E. Hallyn" <serge@hallyn.com>,
Georgia Garcia <georgia.garcia@canonical.com>,
apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org,
Alexey Khoroshilov <khoroshilov@ispras.ru>,
lvc-project@linuxtesting.org
Subject: Re: [PATCH] apparmor: free the allocated pdb objects
Date: Tue, 28 Nov 2023 06:29:38 -0800 [thread overview]
Message-ID: <f1675413-f6db-4d51-8b63-1fd6e6b4c871@canonical.com> (raw)
In-Reply-To: <20231127175904.156583-1-pchelkin@ispras.ru>
On 11/27/23 09:59, Fedor Pchelkin wrote:
> policy_db objects are allocated with kzalloc() inside aa_alloc_pdb() and
> are not cleared in the corresponding aa_free_pdb() function causing leak:
>
> unreferenced object 0xffff88801f0a1400 (size 192):
> comm "apparmor_parser", pid 1247, jiffies 4295122827 (age 2306.399s)
> hex dump (first 32 bytes):
> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
> backtrace:
> [<ffffffff81ddc612>] __kmem_cache_alloc_node+0x1e2/0x2d0
> [<ffffffff81c47c55>] kmalloc_trace+0x25/0xc0
> [<ffffffff83eb9a12>] aa_alloc_pdb+0x82/0x140
> [<ffffffff83ec4077>] unpack_pdb+0xc7/0x2700
> [<ffffffff83ec6b10>] unpack_profile+0x450/0x4960
> [<ffffffff83ecc129>] aa_unpack+0x309/0x15e0
> [<ffffffff83ebdb23>] aa_replace_profiles+0x213/0x33c0
> [<ffffffff83e8d341>] policy_update+0x261/0x370
> [<ffffffff83e8d66e>] profile_replace+0x20e/0x2a0
> [<ffffffff81eadfaf>] vfs_write+0x2af/0xe00
> [<ffffffff81eaf4c6>] ksys_write+0x126/0x250
> [<ffffffff890fa0b6>] do_syscall_64+0x46/0xf0
> [<ffffffff892000ea>] entry_SYSCALL_64_after_hwframe+0x6e/0x76
>
> Free the pdbs inside aa_free_pdb(). While at it, rename the variable
> representing an aa_policydb object to make the function more unified with
> aa_pdb_free_kref() and aa_alloc_pdb().
>
> Found by Linux Verification Center (linuxtesting.org).
>
> Fixes: 98b824ff8984 ("apparmor: refcount the pdb")
> Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
ouch, lgtm, I am going to pull this into my tree and throw some testing
on this asap
Acked-by: John Johansen <john.johansen@canonical.com>
> ---
> security/apparmor/policy.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c
> index ed4c9803c8fa..957654d253dd 100644
> --- a/security/apparmor/policy.c
> +++ b/security/apparmor/policy.c
> @@ -99,13 +99,14 @@ const char *const aa_profile_mode_names[] = {
> };
>
>
> -static void aa_free_pdb(struct aa_policydb *policy)
> +static void aa_free_pdb(struct aa_policydb *pdb)
> {
> - if (policy) {
> - aa_put_dfa(policy->dfa);
> - if (policy->perms)
> - kvfree(policy->perms);
> - aa_free_str_table(&policy->trans);
> + if (pdb) {
> + aa_put_dfa(pdb->dfa);
> + if (pdb->perms)
> + kvfree(pdb->perms);
> + aa_free_str_table(&pdb->trans);
> + kfree(pdb);
> }
> }
>
prev parent reply other threads:[~2023-11-28 14:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-27 17:59 [PATCH] apparmor: free the allocated pdb objects Fedor Pchelkin
2023-11-28 14:29 ` John Johansen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f1675413-f6db-4d51-8b63-1fd6e6b4c871@canonical.com \
--to=john.johansen@canonical.com \
--cc=apparmor@lists.ubuntu.com \
--cc=georgia.garcia@canonical.com \
--cc=jmorris@namei.org \
--cc=khoroshilov@ispras.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=lvc-project@linuxtesting.org \
--cc=paul@paul-moore.com \
--cc=pchelkin@ispras.ru \
--cc=serge@hallyn.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).