lei he 1bedcf22c0 virtio-crypto: fix memory-leak
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>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Gonglei <arei.gonglei@huawei.com>
Message-Id: <20220919075158.3625-1-helei.sig11@bytedance.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2022-09-27 18:30:48 -04:00
..
2022-09-03 13:23:11 -07:00
2022-08-04 12:12:54 -07:00
2022-08-04 19:30:35 -07:00
2022-09-27 18:30:48 -04:00
2022-08-06 16:38:17 -07:00
2022-09-22 11:10:11 -07:00
2022-09-23 13:18:26 +10:00
2022-08-31 09:54:14 -07:00
2022-08-05 10:07:23 -07:00
2022-09-03 13:09:46 -07:00
2022-08-18 17:37:22 +02:00
2022-08-26 11:05:54 -07:00
2022-08-04 19:41:09 -07:00
2022-08-06 10:25:16 -07:00
2022-09-02 15:03:12 -07:00
2022-08-05 14:13:45 -07:00
2022-09-09 15:03:08 -04:00
2022-08-04 12:12:54 -07:00
2022-09-23 15:28:51 -07:00
2022-09-02 10:35:51 -07:00
2022-08-04 12:12:54 -07:00
2022-08-04 12:12:54 -07:00
2022-09-08 12:56:20 -04:00
2022-08-05 10:02:33 -07:00
2022-08-09 00:56:41 +02:00
2022-09-24 17:35:42 -07:00
2022-09-08 13:13:47 -04:00
2022-08-13 13:41:48 -07:00
2022-08-27 15:07:58 +02:00
2022-09-22 15:43:18 +02:00
2022-09-09 07:44:33 -04:00
2022-08-12 09:50:34 -07:00
2022-09-12 18:33:55 -04:00
2022-08-08 15:04:04 -07:00
2022-09-23 08:31:24 -07:00
2022-08-04 12:01:42 -07:00