[PATCH v2] hw/virtio-crypto: enforce max akcipher key length

helei posted 1 patch 1 month, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260616123251.26446-2-lhestz@163.com
Maintainers: "Gonglei (Arei)" <arei.gonglei@huawei.com>, "Michael S. Tsirkin" <mst@redhat.com>
There is a newer version of this series
hw/virtio/virtio-crypto.c | 6 ++++++
1 file changed, 6 insertions(+)
[PATCH v2] hw/virtio-crypto: enforce max akcipher key length
Posted by helei 1 month, 1 week ago
enforce the global max_size boundary for akcipher session creation

Signed-off-by: helei <lhestz@163.com>
---
 hw/virtio/virtio-crypto.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
index 6fceb39681..79e2acb56c 100644
--- a/hw/virtio/virtio-crypto.c
+++ b/hw/virtio/virtio-crypto.c
@@ -216,6 +216,12 @@ virtio_crypto_create_asym_session(VirtIOCrypto *vcrypto,
         return -VIRTIO_CRYPTO_NOTSUPP;
     }
 
+    if (unlikely(keylen > vcrypto->conf.max_size)) {
+        error_report("virtio-crypto length of akcipher key is too large: %u",
+                     keylen);
+        return -VIRTIO_CRYPTO_ERR;
+    }
+
     if (keylen) {
         asym_info->key = g_malloc(keylen);
         if (iov_to_buf(iov, out_num, 0, asym_info->key, keylen) != keylen) {
-- 
2.43.0
Re: [PATCH v2] hw/virtio-crypto: enforce max akcipher key length
Posted by helei 1 month, 1 week ago

On 6/16/26 20:32, helei wrote:
> enforce the global max_size boundary for akcipher session creation
> 
> Signed-off-by: helei <lhestz@163.com>
> ---
>  hw/virtio/virtio-crypto.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
> index 6fceb39681..79e2acb56c 100644
> --- a/hw/virtio/virtio-crypto.c
> +++ b/hw/virtio/virtio-crypto.c
> @@ -216,6 +216,12 @@ virtio_crypto_create_asym_session(VirtIOCrypto *vcrypto,
>          return -VIRTIO_CRYPTO_NOTSUPP;
>      }
>  
> +    if (unlikely(keylen > vcrypto->conf.max_size)) {
> +        error_report("virtio-crypto length of akcipher key is too large: %u",
> +                     keylen);
> +        return -VIRTIO_CRYPTO_ERR;
> +    }
> +
>      if (keylen) {
>          asym_info->key = g_malloc(keylen);
>          if (iov_to_buf(iov, out_num, 0, asym_info->key, keylen) != keylen) {

sorry, i accidentally missed the cover letter, here is the changelog for
this version:
v2:
- dropped the hardcoded limit mirroring the linux kernel.
- enforced the global max_size boundary for akcipher session creation.