apparmor: fix a memleak in multi_transaction_new()
authorGaosheng Cui <cuigaosheng1@huawei.com>
Tue, 23 Aug 2022 01:15:03 +0000 (09:15 +0800)
committerJohn Johansen <john.johansen@canonical.com>
Mon, 3 Oct 2022 21:48:54 +0000 (14:48 -0700)
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: 1dea3b41e84c5 ("apparmor: speed up transactional queries")
Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
security/apparmor/apparmorfs.c

index d066ccc..7160e7a 100644 (file)
@@ -868,8 +868,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;
 }