apparmor: fix a memleak in multi_transaction_new()

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: 1dea3b41e8 ("apparmor: speed up transactional queries")
Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
This commit is contained in:
Gaosheng Cui 2022-08-23 09:15:03 +08:00 committed by John Johansen
parent 3cc40a443a
commit c73275cf68
1 changed files with 3 additions and 1 deletions

View File

@ -868,8 +868,10 @@ static struct multi_transaction *multi_transaction_new(struct file *file,
if (!t) if (!t)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
kref_init(&t->count); 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 ERR_PTR(-EFAULT);
}
return t; return t;
} }