Skip to content

Commit

Permalink
net/tls: don't leak IV and record seq when offload fails
Browse files Browse the repository at this point in the history
[ Upstream commit 12c7686 ]

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: 4799ac8 ("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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Jakub Kicinski authored and Greg Kroah-Hartman committed May 2, 2019
1 parent 2adb990 commit bcf0c1f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 0 additions & 2 deletions net/tls/tls_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -921,8 +921,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);
}

Expand Down
5 changes: 1 addition & 4 deletions net/tls/tls_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,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)
Expand Down
3 changes: 3 additions & 0 deletions net/tls/tls_sw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,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;
Expand Down

0 comments on commit bcf0c1f

Please sign in to comment.