diff mbox series

[-next] apparmor: Fix memleak in aa_simple_write_to_buffer()

Message ID 20220614090001.155107-1-xiujianfeng@huawei.com (mailing list archive)
State Handled Elsewhere
Headers show
Series [-next] apparmor: Fix memleak in aa_simple_write_to_buffer() | expand

Commit Message

Xiu Jianfeng June 14, 2022, 9 a.m. UTC
When copy_from_user failed, the memory is freed by kvfree. however the
management struct and data blob are allocated independently, so only
kvfree(data) cause a memleak issue here. Use aa_put_loaddata(data) to
fix this issue.

Fixes: a6a52579e52b5 ("apparmor: split load data into management struct and data blob")
Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
---
 security/apparmor/apparmorfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

John Johansen June 22, 2022, 7:49 p.m. UTC | #1
Sorry this feel through the cracks some how.

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

I will pull this into my tree and send it up with my next pull request.

On 6/14/22 02:00, Xiu Jianfeng wrote:
> When copy_from_user failed, the memory is freed by kvfree. however the
> management struct and data blob are allocated independently, so only
> kvfree(data) cause a memleak issue here. Use aa_put_loaddata(data) to
> fix this issue.
> 
> Fixes: a6a52579e52b5 ("apparmor: split load data into management struct and data blob")
> Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
> ---
>  security/apparmor/apparmorfs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c
> index 8b9c92f3ff95..0275a350dc23 100644
> --- a/security/apparmor/apparmorfs.c
> +++ b/security/apparmor/apparmorfs.c
> @@ -403,7 +403,7 @@ static struct aa_loaddata *aa_simple_write_to_buffer(const char __user *userbuf,
>  
>  	data->size = copy_size;
>  	if (copy_from_user(data->data, userbuf, copy_size)) {
> -		kvfree(data);
> +		aa_put_loaddata(data);
>  		return ERR_PTR(-EFAULT);
>  	}
>
diff mbox series

Patch

diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c
index 8b9c92f3ff95..0275a350dc23 100644
--- a/security/apparmor/apparmorfs.c
+++ b/security/apparmor/apparmorfs.c
@@ -403,7 +403,7 @@  static struct aa_loaddata *aa_simple_write_to_buffer(const char __user *userbuf,
 
 	data->size = copy_size;
 	if (copy_from_user(data->data, userbuf, copy_size)) {
-		kvfree(data);
+		aa_put_loaddata(data);
 		return ERR_PTR(-EFAULT);
 	}