Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3458506rwb; Tue, 16 Aug 2022 03:30:42 -0700 (PDT) X-Google-Smtp-Source: AA6agR6GjhwEXeJhBqoibTqAKmW/VvImcgSJY4U9ahSz2Tcmlkk34a+zxuxwSfv2pmjXoT7v94sB X-Received: by 2002:a17:907:e88:b0:730:8e7d:2281 with SMTP id ho8-20020a1709070e8800b007308e7d2281mr14041324ejc.20.1660645842024; Tue, 16 Aug 2022 03:30:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660645842; cv=none; d=google.com; s=arc-20160816; b=BDnf5XS4a4p1jFTA9ZTs6qPO5uaMWaBq4T04bNS0dyoyn2FafQ4QTVp5T92QYAjpw8 7AbCgdUARXtE81wRcFQa6fldA4PDJ9Si332KofSqgZmSZDRHGNlUVZ0eEWwbDvXp6n1Q 0BnuNehZGXnmbXMiKdQ9txEcyWykZsQARjcdXWNZCcpRnrsPkRPJe2jlOws6UU2mcN2B xzR6w72Nk+5JNq7bYqMZ+AAZB+KRPYdMkOwQS3Z51Xz394urSjZ96CFjpR/r84+ZBWBa WU9R+WfTl0x3Ya+OjDAFq1tgwNbjfcX11bF1zk/SLkm8Ejpu0N7yb4CMZ7UnzCbD1Ys7 TILw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=7skN0UP09SJ9rnKzqbbB2khIgmY4l+xZtn5PKywGrO0=; b=QDRXzP+2pPb+y652H+t7pkmV63jFwbWHP/vwo88BVusscVn/O6EFFamgIgP1Gk9W1F 1v4OYOkcGnHPk9PYGrvZEeadkDQ+Nl/9biGrNTCRNaTWmiVKaJcjxmUYAZmTqS3i/Ihk zx3/UzSHp2QBBQ3ilWyJmDEm2nzUzr2uIOuwDgBK3w4ZCc18Cdir/JArrKJBVM2ulG7p ULV55fZ3nj5SAyz1lGM18hFj8hm2WxHTFfdBRnMC4anQtxj+H9hFxfkr78iSqudw9es5 8MR3S870FYEd5SxphY3x61UPUQCeskW6Q2ufsq0kMFlyeKmofrRGJpHEnTnOs6qVy2zP zI/A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga33-20020a1709070c2100b00732f83eb741si10382501ejc.985.2022.08.16.03.30.17; Tue, 16 Aug 2022 03:30:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234432AbiHPK2A convert rfc822-to-8bit (ORCPT + 99 others); Tue, 16 Aug 2022 06:28:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234451AbiHPK11 (ORCPT ); Tue, 16 Aug 2022 06:27:27 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3F5A4C605; Tue, 16 Aug 2022 02:15:47 -0700 (PDT) Received: from kwepemi500011.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4M6QQd51zkz1M8yg; Tue, 16 Aug 2022 17:12:25 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by kwepemi500011.china.huawei.com (7.221.188.124) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 16 Aug 2022 17:15:44 +0800 Received: from dggpemm500006.china.huawei.com ([7.185.36.236]) by dggpemm500006.china.huawei.com ([7.185.36.236]) with mapi id 15.01.2375.024; Tue, 16 Aug 2022 17:15:44 +0800 From: "Gonglei (Arei)" To: "Michael S. Tsirkin" , Lei He CC: "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 Thread-Topic: [PATCH] crypto-virtio: fix memory-leak Thread-Index: AQHYsUY0nKlBM3YWoEWBnWo9iL/j1q2wr84AgACNxNA= Date: Tue, 16 Aug 2022 09:15:44 +0000 Message-ID: <0a675c21c1dc4e699d542c2f4f92f729@huawei.com> References: <20220816075916.23651-1-helei.sig11@bytedance.com> <20220816044118-mutt-send-email-mst@kernel.org> In-Reply-To: <20220816044118-mutt-send-email-mst@kernel.org> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.174.149.11] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org > -----Original Message----- > From: Michael S. Tsirkin [mailto:mst@redhat.com] > Sent: Tuesday, August 16, 2022 4:43 PM > To: Lei He > Cc: Gonglei (Arei) ; > 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 Regards, -Gonglei > On Tue, Aug 16, 2022 at 03:59:16PM +0800, Lei He wrote: > > From: lei he > > > > 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 > > 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 > > > 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