All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Gonglei (Arei)" <arei.gonglei@huawei.com>
To: "Michael S. Tsirkin" <mst@redhat.com>,
	Lei He <helei.sig11@bytedance.com>
Cc: "herbert@gondor.apana.org.au" <herbert@gondor.apana.org.au>,
	"virtualization@lists.linux-foundation.org" 
	<virtualization@lists.linux-foundation.org>,
	"linux-crypto@vger.kernel.org" <linux-crypto@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"pizhenwei@bytedance.com" <pizhenwei@bytedance.com>
Subject: RE: [PATCH] crypto-virtio: fix memory-leak
Date: Tue, 16 Aug 2022 09:15:44 +0000	[thread overview]
Message-ID: <0a675c21c1dc4e699d542c2f4f92f729@huawei.com> (raw)
In-Reply-To: <20220816044118-mutt-send-email-mst@kernel.org>



> -----Original Message-----
> From: Michael S. Tsirkin [mailto:mst@redhat.com]
> Sent: Tuesday, August 16, 2022 4:43 PM
> To: Lei He <helei.sig11@bytedance.com>
> Cc: Gonglei (Arei) <arei.gonglei@huawei.com>;
> herbert@gondor.apana.org.au; virtualization@lists.linux-foundation.org;
> linux-crypto@vger.kernel.org; linux-kernel@vger.kernel.org;
> pizhenwei@bytedance.com
> Subject: Re: [PATCH] crypto-virtio: fix memory-leak
> 

Pls 's/crypto-virtio/virtio-crypto' in order to keep consistency.

Reviewed-by: Gonglei <arei.gonglei@huawei.com>

Regards,
-Gonglei

> On Tue, Aug 16, 2022 at 03:59:16PM +0800, Lei He wrote:
> > From: lei he <helei.sig11@bytedance.com>
> >
> > Fix memory-leak for virtio-crypto akcipher request, this problem is
> > introduced by 59ca6c93387d3(virtio-crypto: implement RSA algorithm).
> > The leak can be reproduced and tested with the following script inside
> > virtual machine:
> >
> > #!/bin/bash
> >
> > LOOP_TIMES=10000
> >
> > # required module: pkcs8_key_parser, virtio_crypto modprobe
> > pkcs8_key_parser # if CONFIG_PKCS8_PRIVATE_KEY_PARSER=m modprobe
> > virtio_crypto # if CONFIG_CRYPTO_DEV_VIRTIO=m rm -rf /tmp/data dd
> > if=/dev/random of=/tmp/data count=1 bs=230
> >
> > # generate private key and self-signed cert openssl req -nodes -x509
> > -newkey rsa:2048 -keyout key.pem \
> > 		-outform der -out cert.der  \
> > 		-subj
> "/C=CN/ST=GD/L=SZ/O=vihoo/OU=dev/CN=always.com/emailAddress=yy@
> always.com"
> > # convert private key from pem to der
> > openssl pkcs8 -in key.pem -topk8 -nocrypt -outform DER -out key.der
> >
> > # add key
> > PRIV_KEY_ID=`cat key.der | keyctl padd asymmetric test_priv_key @s`
> > echo "priv key id = "$PRIV_KEY_ID PUB_KEY_ID=`cat cert.der | keyctl
> > padd asymmetric test_pub_key @s` echo "pub key id = "$PUB_KEY_ID
> >
> > # query key
> > keyctl pkey_query $PRIV_KEY_ID 0
> > keyctl pkey_query $PUB_KEY_ID 0
> >
> > # here we only run pkey_encrypt becasuse it is the fastest interface
> > function bench_pub() {
> > 	keyctl pkey_encrypt $PUB_KEY_ID 0 /tmp/data
> enc=pkcs1 >/tmp/enc.pub }
> >
> > # do bench_pub in loop to obtain the memory leak for (( i = 0; i <
> > ${LOOP_TIMES}; ++i )); do
> > 	bench_pub
> > done
> >
> > Signed-off-by: lei he <helei.sig11@bytedance.com>
> 
> trash below pls drop.
> 
> 
> > # Please enter the commit message for your changes. Lines starting #
> > with '#' will be kept; you may remove them yourself if you want to.
> > # An empty message aborts the commit.
> > #
> > # Date:      Tue Aug 16 11:53:30 2022 +0800
> > #
> > # On branch master
> > # Your branch is ahead of 'origin/master' by 1 commit.
> > #   (use "git push" to publish your local commits)
> > #
> > # Changes to be committed:
> > #	modified:   drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> > #
> > # Untracked files:
> > #	cert.der
> > #	key.der
> > #	key.pem
> > #
> >
> > # Please enter the commit message for your changes. Lines starting #
> > with '#' will be kept; you may remove them yourself if you want to.
> > # An empty message aborts the commit.
> > #
> > # Date:      Tue Aug 16 11:53:30 2022 +0800
> > #
> > # On branch master
> > # Your branch is ahead of 'origin/master' by 1 commit.
> > #   (use "git push" to publish your local commits)
> > #
> > # Changes to be committed:
> > #	modified:   drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> > #
> > # Untracked files:
> > #	cert.der
> > #	key.der
> > #	key.pem
> > #
> >
> > # Please enter the commit message for your changes. Lines starting #
> > with '#' will be kept; you may remove them yourself if you want to.
> > # An empty message aborts the commit.
> > #
> > # Date:      Tue Aug 16 11:53:30 2022 +0800
> > #
> > # On branch master
> > # Your branch is ahead of 'origin/master' by 1 commit.
> > #   (use "git push" to publish your local commits)
> > #
> > # Changes to be committed:
> > #	modified:   drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> > #
> > # Untracked files:
> > #	cert.der
> > #	key.der
> > #	key.pem
> > #
> > ---
> 
> with commit log fixed:
> 
> Acked-by: Michael S. Tsirkin <mst@redhat.com>
> 
> >  drivers/crypto/virtio/virtio_crypto_akcipher_algs.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> > b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> > index 2a60d0525cde..168195672e2e 100644
> > --- a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> > +++ b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> > @@ -56,6 +56,10 @@ static void virtio_crypto_akcipher_finalize_req(
> >  	struct virtio_crypto_akcipher_request *vc_akcipher_req,
> >  	struct akcipher_request *req, int err)  {
> > +	kfree(vc_akcipher_req->src_buf);
> > +	kfree(vc_akcipher_req->dst_buf);
> > +	vc_akcipher_req->src_buf = NULL;
> > +	vc_akcipher_req->dst_buf = NULL;
> >  	virtcrypto_clear_request(&vc_akcipher_req->base);
> >
> >
> > crypto_finalize_akcipher_request(vc_akcipher_req->base.dataq->engine,
> > req, err);
> > --
> > 2.20.1


WARNING: multiple messages have this Message-ID (diff)
From: "Gonglei \(Arei\) via Virtualization" <virtualization@lists.linux-foundation.org>
To: "Michael S. Tsirkin" <mst@redhat.com>,
	Lei He <helei.sig11@bytedance.com>
Cc: "linux-crypto@vger.kernel.org" <linux-crypto@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"herbert@gondor.apana.org.au" <herbert@gondor.apana.org.au>,
	"pizhenwei@bytedance.com" <pizhenwei@bytedance.com>,
	"virtualization@lists.linux-foundation.org"
	<virtualization@lists.linux-foundation.org>
Subject: RE: [PATCH] crypto-virtio: fix memory-leak
Date: Tue, 16 Aug 2022 09:15:44 +0000	[thread overview]
Message-ID: <0a675c21c1dc4e699d542c2f4f92f729@huawei.com> (raw)
In-Reply-To: <20220816044118-mutt-send-email-mst@kernel.org>



> -----Original Message-----
> From: Michael S. Tsirkin [mailto:mst@redhat.com]
> Sent: Tuesday, August 16, 2022 4:43 PM
> To: Lei He <helei.sig11@bytedance.com>
> Cc: Gonglei (Arei) <arei.gonglei@huawei.com>;
> herbert@gondor.apana.org.au; virtualization@lists.linux-foundation.org;
> linux-crypto@vger.kernel.org; linux-kernel@vger.kernel.org;
> pizhenwei@bytedance.com
> Subject: Re: [PATCH] crypto-virtio: fix memory-leak
> 

Pls 's/crypto-virtio/virtio-crypto' in order to keep consistency.

Reviewed-by: Gonglei <arei.gonglei@huawei.com>

Regards,
-Gonglei

> On Tue, Aug 16, 2022 at 03:59:16PM +0800, Lei He wrote:
> > From: lei he <helei.sig11@bytedance.com>
> >
> > Fix memory-leak for virtio-crypto akcipher request, this problem is
> > introduced by 59ca6c93387d3(virtio-crypto: implement RSA algorithm).
> > The leak can be reproduced and tested with the following script inside
> > virtual machine:
> >
> > #!/bin/bash
> >
> > LOOP_TIMES=10000
> >
> > # required module: pkcs8_key_parser, virtio_crypto modprobe
> > pkcs8_key_parser # if CONFIG_PKCS8_PRIVATE_KEY_PARSER=m modprobe
> > virtio_crypto # if CONFIG_CRYPTO_DEV_VIRTIO=m rm -rf /tmp/data dd
> > if=/dev/random of=/tmp/data count=1 bs=230
> >
> > # generate private key and self-signed cert openssl req -nodes -x509
> > -newkey rsa:2048 -keyout key.pem \
> > 		-outform der -out cert.der  \
> > 		-subj
> "/C=CN/ST=GD/L=SZ/O=vihoo/OU=dev/CN=always.com/emailAddress=yy@
> always.com"
> > # convert private key from pem to der
> > openssl pkcs8 -in key.pem -topk8 -nocrypt -outform DER -out key.der
> >
> > # add key
> > PRIV_KEY_ID=`cat key.der | keyctl padd asymmetric test_priv_key @s`
> > echo "priv key id = "$PRIV_KEY_ID PUB_KEY_ID=`cat cert.der | keyctl
> > padd asymmetric test_pub_key @s` echo "pub key id = "$PUB_KEY_ID
> >
> > # query key
> > keyctl pkey_query $PRIV_KEY_ID 0
> > keyctl pkey_query $PUB_KEY_ID 0
> >
> > # here we only run pkey_encrypt becasuse it is the fastest interface
> > function bench_pub() {
> > 	keyctl pkey_encrypt $PUB_KEY_ID 0 /tmp/data
> enc=pkcs1 >/tmp/enc.pub }
> >
> > # do bench_pub in loop to obtain the memory leak for (( i = 0; i <
> > ${LOOP_TIMES}; ++i )); do
> > 	bench_pub
> > done
> >
> > Signed-off-by: lei he <helei.sig11@bytedance.com>
> 
> trash below pls drop.
> 
> 
> > # Please enter the commit message for your changes. Lines starting #
> > with '#' will be kept; you may remove them yourself if you want to.
> > # An empty message aborts the commit.
> > #
> > # Date:      Tue Aug 16 11:53:30 2022 +0800
> > #
> > # On branch master
> > # Your branch is ahead of 'origin/master' by 1 commit.
> > #   (use "git push" to publish your local commits)
> > #
> > # Changes to be committed:
> > #	modified:   drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> > #
> > # Untracked files:
> > #	cert.der
> > #	key.der
> > #	key.pem
> > #
> >
> > # Please enter the commit message for your changes. Lines starting #
> > with '#' will be kept; you may remove them yourself if you want to.
> > # An empty message aborts the commit.
> > #
> > # Date:      Tue Aug 16 11:53:30 2022 +0800
> > #
> > # On branch master
> > # Your branch is ahead of 'origin/master' by 1 commit.
> > #   (use "git push" to publish your local commits)
> > #
> > # Changes to be committed:
> > #	modified:   drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> > #
> > # Untracked files:
> > #	cert.der
> > #	key.der
> > #	key.pem
> > #
> >
> > # Please enter the commit message for your changes. Lines starting #
> > with '#' will be kept; you may remove them yourself if you want to.
> > # An empty message aborts the commit.
> > #
> > # Date:      Tue Aug 16 11:53:30 2022 +0800
> > #
> > # On branch master
> > # Your branch is ahead of 'origin/master' by 1 commit.
> > #   (use "git push" to publish your local commits)
> > #
> > # Changes to be committed:
> > #	modified:   drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> > #
> > # Untracked files:
> > #	cert.der
> > #	key.der
> > #	key.pem
> > #
> > ---
> 
> with commit log fixed:
> 
> Acked-by: Michael S. Tsirkin <mst@redhat.com>
> 
> >  drivers/crypto/virtio/virtio_crypto_akcipher_algs.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> > b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> > index 2a60d0525cde..168195672e2e 100644
> > --- a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> > +++ b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> > @@ -56,6 +56,10 @@ static void virtio_crypto_akcipher_finalize_req(
> >  	struct virtio_crypto_akcipher_request *vc_akcipher_req,
> >  	struct akcipher_request *req, int err)  {
> > +	kfree(vc_akcipher_req->src_buf);
> > +	kfree(vc_akcipher_req->dst_buf);
> > +	vc_akcipher_req->src_buf = NULL;
> > +	vc_akcipher_req->dst_buf = NULL;
> >  	virtcrypto_clear_request(&vc_akcipher_req->base);
> >
> >
> > crypto_finalize_akcipher_request(vc_akcipher_req->base.dataq->engine,
> > req, err);
> > --
> > 2.20.1

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

  reply	other threads:[~2022-08-16 10:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-16  7:59 [PATCH] crypto-virtio: fix memory-leak Lei He
2022-08-16  8:43 ` Michael S. Tsirkin
2022-08-16  8:43   ` Michael S. Tsirkin
2022-08-16  9:15   ` Gonglei (Arei) [this message]
2022-08-16  9:15     ` Gonglei (Arei) via Virtualization

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=0a675c21c1dc4e699d542c2f4f92f729@huawei.com \
    --to=arei.gonglei@huawei.com \
    --cc=helei.sig11@bytedance.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=pizhenwei@bytedance.com \
    --cc=virtualization@lists.linux-foundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.