From: Tom Lendacky <thomas.lendacky@amd.com>
To: Dinghao Liu <dinghao.liu@zju.edu.cn>
Cc: John Allen <john.allen@amd.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] crypto: ccp - fix memleak in ccp_init_dm_workarea
Date: Sat, 25 Nov 2023 09:10:09 -0600 [thread overview]
Message-ID: <3f033585-91c6-1d70-be1e-f083fc855aed@amd.com> (raw)
In-Reply-To: <20231123070337.11600-1-dinghao.liu@zju.edu.cn>
On 11/23/23 01:03, Dinghao Liu wrote:
> When dma_map_single() fails, we should free wa->address to
> prevent potential memleak.
You should expand on this a bit more. The ccp_dm_free() function is
normally called to free that memory, but many of the call spots don't
expect to have to call ccp_dm_free() on an error return from
ccp_init_dm_workarea(). Because of that, the memory is freed in
ccp_init_dm_workarea().
So a more detailed commit message about why this change is needed should
be provided.
>
> Fixes: 63b945091a07 ("crypto: ccp - CCP device driver and interface support")
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> ---
> drivers/crypto/ccp/ccp-ops.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/crypto/ccp/ccp-ops.c b/drivers/crypto/ccp/ccp-ops.c
> index aa4e1a500691..45552ae6347e 100644
> --- a/drivers/crypto/ccp/ccp-ops.c
> +++ b/drivers/crypto/ccp/ccp-ops.c
> @@ -179,8 +179,10 @@ static int ccp_init_dm_workarea(struct ccp_dm_workarea *wa,
>
> wa->dma.address = dma_map_single(wa->dev, wa->address, len,
> dir);
> - if (dma_mapping_error(wa->dev, wa->dma.address))
> + if (dma_mapping_error(wa->dev, wa->dma.address)) {
> + kfree(wa->address);
If future changes should result in ccp_dm_free() being called on an error
returned from ccp_init_dm_workarea(), you should add:
wa->address = NULL;
Thanks,
Tom
> return -ENOMEM;
> + }
>
> wa->dma.length = len;
> }
next prev parent reply other threads:[~2023-11-25 15:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-23 7:03 [PATCH] crypto: ccp - fix memleak in ccp_init_dm_workarea Dinghao Liu
2023-11-25 15:10 ` Tom Lendacky [this message]
2023-11-27 1:45 ` dinghao.liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3f033585-91c6-1d70-be1e-f083fc855aed@amd.com \
--to=thomas.lendacky@amd.com \
--cc=davem@davemloft.net \
--cc=dinghao.liu@zju.edu.cn \
--cc=herbert@gondor.apana.org.au \
--cc=john.allen@amd.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox