2022-11-14 11:10:22

by Wei Yongjun

[permalink] [raw]
Subject: [PATCH] virtio-crypto: fix memory leak in virtio_crypto_alg_skcipher_close_session()

From: Wei Yongjun <[email protected]>

'vc_ctrl_req' is alloced in virtio_crypto_alg_skcipher_close_session(),
and should be freed in the invalid ctrl_status->status error handling
case. Otherwise there is a memory leak.

Fixes: 0756ad15b1fe ("virtio-crypto: use private buffer for control request")
Signed-off-by: Wei Yongjun <[email protected]>
---
drivers/crypto/virtio/virtio_crypto_skcipher_algs.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c b/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c
index e553ccadbcbc..e5876286828b 100644
--- a/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c
+++ b/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c
@@ -239,7 +239,8 @@ static int virtio_crypto_alg_skcipher_close_session(
pr_err("virtio_crypto: Close session failed status: %u, session_id: 0x%llx\n",
ctrl_status->status, destroy_session->session_id);

- return -EINVAL;
+ err = -EINVAL;
+ goto out;
}

err = 0;
--
2.34.1



2022-11-14 11:23:53

by Gonglei (Arei)

[permalink] [raw]
Subject: RE: [PATCH] virtio-crypto: fix memory leak in virtio_crypto_alg_skcipher_close_session()



> -----Original Message-----
> From: Wei Yongjun [mailto:[email protected]]
> Sent: Monday, November 14, 2022 7:08 PM
> To: Michael S. Tsirkin <[email protected]>; Jason Wang
> <[email protected]>; Gonglei (Arei) <[email protected]>;
> Herbert Xu <[email protected]>; David S. Miller
> <[email protected]>; zhenwei pi <[email protected]>
> Cc: weiyongjun (A) <[email protected]>;
> [email protected]; [email protected]
> Subject: [PATCH] virtio-crypto: fix memory leak in
> virtio_crypto_alg_skcipher_close_session()
>
> From: Wei Yongjun <[email protected]>
>
> 'vc_ctrl_req' is alloced in virtio_crypto_alg_skcipher_close_session(),
> and should be freed in the invalid ctrl_status->status error handling case.
> Otherwise there is a memory leak.
>
> Fixes: 0756ad15b1fe ("virtio-crypto: use private buffer for control request")
> Signed-off-by: Wei Yongjun <[email protected]>
> ---
> drivers/crypto/virtio/virtio_crypto_skcipher_algs.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c
> b/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c
> index e553ccadbcbc..e5876286828b 100644
> --- a/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c
> +++ b/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c
> @@ -239,7 +239,8 @@ static int virtio_crypto_alg_skcipher_close_session(
> pr_err("virtio_crypto: Close session failed status: %u, session_id:
> 0x%llx\n",
> ctrl_status->status, destroy_session->session_id);
>
> - return -EINVAL;
> + err = -EINVAL;
> + goto out;
> }
>
Good catch.

Reviewed-by: Gonglei <[email protected]>

Regards,
-Gonglei

> err = 0;
> --
> 2.34.1


2022-11-15 01:14:21

by zhenwei pi

[permalink] [raw]
Subject: Re: [PATCH] virtio-crypto: fix memory leak in virtio_crypto_alg_skcipher_close_session()

Looks good to me, thanks!

Acked-by: zhenwei pi<[email protected]>

On 11/14/22 19:07, Wei Yongjun wrote:
> From: Wei Yongjun <[email protected]>
>
> 'vc_ctrl_req' is alloced in virtio_crypto_alg_skcipher_close_session(),
> and should be freed in the invalid ctrl_status->status error handling
> case. Otherwise there is a memory leak.
>
> Fixes: 0756ad15b1fe ("virtio-crypto: use private buffer for control request")
> Signed-off-by: Wei Yongjun <[email protected]>
> ---
> drivers/crypto/virtio/virtio_crypto_skcipher_algs.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c b/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c
> index e553ccadbcbc..e5876286828b 100644
> --- a/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c
> +++ b/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c
> @@ -239,7 +239,8 @@ static int virtio_crypto_alg_skcipher_close_session(
> pr_err("virtio_crypto: Close session failed status: %u, session_id: 0x%llx\n",
> ctrl_status->status, destroy_session->session_id);
>
> - return -EINVAL;
> + err = -EINVAL;
> + goto out;
> }
>
> err = 0;

--
zhenwei pi

2022-11-15 06:31:22

by Jason Wang

[permalink] [raw]
Subject: Re: [PATCH] virtio-crypto: fix memory leak in virtio_crypto_alg_skcipher_close_session()

On Mon, Nov 14, 2022 at 7:26 PM Wei Yongjun <[email protected]> wrote:
>
> From: Wei Yongjun <[email protected]>
>
> 'vc_ctrl_req' is alloced in virtio_crypto_alg_skcipher_close_session(),
> and should be freed in the invalid ctrl_status->status error handling
> case. Otherwise there is a memory leak.
>
> Fixes: 0756ad15b1fe ("virtio-crypto: use private buffer for control request")
> Signed-off-by: Wei Yongjun <[email protected]>

Acked-by: Jason Wang <[email protected]>

Thanks

> ---
> drivers/crypto/virtio/virtio_crypto_skcipher_algs.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c b/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c
> index e553ccadbcbc..e5876286828b 100644
> --- a/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c
> +++ b/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c
> @@ -239,7 +239,8 @@ static int virtio_crypto_alg_skcipher_close_session(
> pr_err("virtio_crypto: Close session failed status: %u, session_id: 0x%llx\n",
> ctrl_status->status, destroy_session->session_id);
>
> - return -EINVAL;
> + err = -EINVAL;
> + goto out;
> }
>
> err = 0;
> --
> 2.34.1
>