Skip to contentSkip to conversation

hw/virtio-crypto: enforce max akcipher key length

PATCH RESEND New helei 1 participant 2 messages Jun 25

lore
Share & tools
lore

helei

author
#0 lore raw

v2 cover hw/virtio-crypto: enforce max akcipher key length

The virtio-crypto spec does not dictate a maximum length limit for asymmetric cipher (akcipher) keys. We added a hard limit which mirrors the linux kernels's internal limit for akcipher keys (see keyctl framework and the add_key syscall).
Maybe we should update the virtio-spec and add a max_akcipher_key_len field for virtio crypto devices.

v2:
- dropped the hardcoded limit mirroring the linux kernel.
- enforced the global max_size boundary specifically for akcipher session creation

helei (1):
hw/virtio-crypto: enforce max akcipher key length

 hw/virtio/virtio-crypto.c | 6 ++++++
 1 file changed, 6 insertions(+)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH RESEND v2 1/1 hw/virtio-crypto: enforce max akcipher key length

enforce the global max_size boundary for akcipher session creation

---
 hw/virtio/virtio-crypto.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/virtio/virtio-crypto.c +6 -0
index 6fceb39681..79e2acb56c 100644
@@ -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) {
Signature · 1 line
2.43.0