diff mbox series

apparmor: fix a memleak in multi_transaction_new()

Message ID 20220823011503.2757088-1-cuigaosheng1@huawei.com (mailing list archive)
State Handled Elsewhere
Headers show
Series apparmor: fix a memleak in multi_transaction_new() | expand

Commit Message

Gaosheng Cui Aug. 23, 2022, 1:15 a.m. UTC
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>
---
 security/apparmor/apparmorfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

John Johansen Aug. 24, 2022, 5:10 p.m. UTC | #1
On 8/22/22 18:15, Gaosheng Cui wrote:
> 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>

yep, thanks. I will pull this into apparmor-next

Acked-by: John Johansen <john.johansen@canonical.com>

> ---
>   security/apparmor/apparmorfs.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c
> index d066ccc219e2..7160e7aa58b9 100644
> --- a/security/apparmor/apparmorfs.c
> +++ b/security/apparmor/apparmorfs.c
> @@ -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;
>   }
diff mbox series

Patch

diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c
index d066ccc219e2..7160e7aa58b9 100644
--- a/security/apparmor/apparmorfs.c
+++ b/security/apparmor/apparmorfs.c
@@ -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;
 }