]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
tls: drop unnecessary cipher_type checks in tls offload
authorSabrina Dubroca <sd@queasysnail.net>
Mon, 9 Oct 2023 20:50:42 +0000 (22:50 +0200)
committerDavid S. Miller <davem@davemloft.net>
Fri, 13 Oct 2023 10:26:09 +0000 (11:26 +0100)
We should never reach tls_device_reencrypt, tls_enc_record, or
tls_enc_skb with a cipher_type that can't be offloaded. Replace those
checks with a DEBUG_NET_WARN_ON_ONCE, and use cipher_desc instead of
hard-coding offloadable cipher types.

Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/tls/tls_device.c
net/tls/tls_device_fallback.c

index 8c94c926606ad5f2f3f32120aff8c5eefc08e474..fbd687a0c66f474a878f0dfe69dfafa82b3020c4 100644 (file)
@@ -891,14 +891,8 @@ tls_device_reencrypt(struct sock *sk, struct tls_context *tls_ctx)
        struct strp_msg *rxm;
        char *orig_buf, *buf;
 
-       switch (tls_ctx->crypto_recv.info.cipher_type) {
-       case TLS_CIPHER_AES_GCM_128:
-       case TLS_CIPHER_AES_GCM_256:
-               break;
-       default:
-               return -EINVAL;
-       }
        cipher_desc = get_cipher_desc(tls_ctx->crypto_recv.info.cipher_type);
+       DEBUG_NET_WARN_ON_ONCE(!cipher_desc || !cipher_desc->offloadable);
 
        rxm = strp_msg(tls_strp_msg(sw_ctx));
        orig_buf = kmalloc(rxm->full_len + TLS_HEADER_SIZE + cipher_desc->iv,
index b4a65f53d9c087909620973b4103d8f3932856ae..1d2b4d83ccab15d0816e1f208b2c679dcabdd0da 100644 (file)
@@ -62,14 +62,8 @@ static int tls_enc_record(struct aead_request *aead_req,
        u16 len;
        int rc;
 
-       switch (prot->cipher_type) {
-       case TLS_CIPHER_AES_GCM_128:
-       case TLS_CIPHER_AES_GCM_256:
-               break;
-       default:
-               return -EINVAL;
-       }
        cipher_desc = get_cipher_desc(prot->cipher_type);
+       DEBUG_NET_WARN_ON_ONCE(!cipher_desc || !cipher_desc->offloadable);
 
        buf_size = TLS_HEADER_SIZE + cipher_desc->iv;
        len = min_t(int, *in_len, buf_size);
@@ -338,14 +332,9 @@ static struct sk_buff *tls_enc_skb(struct tls_context *tls_ctx,
        if (!aead_req)
                return NULL;
 
-       switch (tls_ctx->crypto_send.info.cipher_type) {
-       case TLS_CIPHER_AES_GCM_128:
-       case TLS_CIPHER_AES_GCM_256:
-               break;
-       default:
-               goto free_req;
-       }
        cipher_desc = get_cipher_desc(tls_ctx->crypto_send.info.cipher_type);
+       DEBUG_NET_WARN_ON_ONCE(!cipher_desc || !cipher_desc->offloadable);
+
        buf_len = cipher_desc->salt + cipher_desc->iv + TLS_AAD_SPACE_SIZE +
                  sync_size + cipher_desc->tag;
        buf = kmalloc(buf_len, GFP_ATOMIC);