]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net/tls: don't leak IV and record seq when offload fails
authorJakub Kicinski <jakub.kicinski@netronome.com>
Fri, 19 Apr 2019 23:52:19 +0000 (16:52 -0700)
committerDavid S. Miller <davem@davemloft.net>
Sun, 21 Apr 2019 03:36:51 +0000 (20:36 -0700)
When device refuses the offload in tls_set_device_offload_rx()
it calls tls_sw_free_resources_rx() to clean up software context
state.

Unfortunately, tls_sw_free_resources_rx() does not free all
the state tls_set_sw_offload() allocated - it leaks IV and
sequence number buffers.  All other code paths which lead to
tls_sw_release_resources_rx() (which tls_sw_free_resources_rx()
calls) free those right before the call.

Avoid the leak by moving freeing of iv and rec_seq into
tls_sw_release_resources_rx().

Fixes: 81b6ef1732a9 ("tls: Add rx inline crypto offload")
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Dirk van der Merwe <dirk.vandermerwe@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/tls/tls_device.c
net/tls/tls_main.c
net/tls/tls_sw.c

index 1b5f55cac613d1416a64bbc900418c8cc1a9267a..cc0256939eb63e2afef7dddb33f57583d1387cc3 100644 (file)
@@ -941,8 +941,6 @@ void tls_device_offload_cleanup_rx(struct sock *sk)
        }
 out:
        up_read(&device_offload_lock);
-       kfree(tls_ctx->rx.rec_seq);
-       kfree(tls_ctx->rx.iv);
        tls_sw_release_resources_rx(sk);
 }
 
index 9547cea0ce3b078b4ca79fec7b24232b046b74c6..478603f43964d557146ae141ba45d4b0cae538fd 100644 (file)
@@ -293,11 +293,8 @@ static void tls_sk_proto_close(struct sock *sk, long timeout)
 #endif
        }
 
-       if (ctx->rx_conf == TLS_SW) {
-               kfree(ctx->rx.rec_seq);
-               kfree(ctx->rx.iv);
+       if (ctx->rx_conf == TLS_SW)
                tls_sw_free_resources_rx(sk);
-       }
 
 #ifdef CONFIG_TLS_DEVICE
        if (ctx->rx_conf == TLS_HW)
index b50ced862f6f9a9f9d959950dcee4adbdd59cb6e..29d6af43dd249dd72c175ac7401a308ef6193c2c 100644 (file)
@@ -2078,6 +2078,9 @@ void tls_sw_release_resources_rx(struct sock *sk)
        struct tls_context *tls_ctx = tls_get_ctx(sk);
        struct tls_sw_context_rx *ctx = tls_sw_ctx_rx(tls_ctx);
 
+       kfree(tls_ctx->rx.rec_seq);
+       kfree(tls_ctx->rx.iv);
+
        if (ctx->aead_recv) {
                kfree_skb(ctx->recv_pkt);
                ctx->recv_pkt = NULL;