Skip to content

Commit

Permalink
apparmor: fix a memleak in multi_transaction_new()
Browse files Browse the repository at this point in the history
[ Upstream commit c73275c ]

In multi_transaction_new(), the variable t is not freed or passed out
on the failure of copy_from_user(t->data, buf, size), which could lead
to a memleak.

Fix this bug by adding a put_multi_transaction(t) in the error path.

Fixes: 1dea3b4 ("apparmor: speed up transactional queries")
Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
gscui authored and gregkh committed Dec 31, 2022
1 parent 09f30f3 commit 775a37f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion security/apparmor/apparmorfs.c
Expand Up @@ -867,8 +867,10 @@ static struct multi_transaction *multi_transaction_new(struct file *file,
if (!t)
return ERR_PTR(-ENOMEM);
kref_init(&t->count);
if (copy_from_user(t->data, buf, size))
if (copy_from_user(t->data, buf, size)) {
put_multi_transaction(t);
return ERR_PTR(-EFAULT);
}

return t;
}
Expand Down

0 comments on commit 775a37f

Please sign in to comment.