Skip to content

Commit 12c7686

Browse files
Jakub Kicinskidavem330
authored andcommitted
net/tls: don't leak IV and record seq when offload fails
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 <[email protected]> Reviewed-by: Dirk van der Merwe <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 62ef81d commit 12c7686

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

net/tls/tls_device.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -941,8 +941,6 @@ void tls_device_offload_cleanup_rx(struct sock *sk)
941941
}
942942
out:
943943
up_read(&device_offload_lock);
944-
kfree(tls_ctx->rx.rec_seq);
945-
kfree(tls_ctx->rx.iv);
946944
tls_sw_release_resources_rx(sk);
947945
}
948946

net/tls/tls_main.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,8 @@ static void tls_sk_proto_close(struct sock *sk, long timeout)
293293
#endif
294294
}
295295

296-
if (ctx->rx_conf == TLS_SW) {
297-
kfree(ctx->rx.rec_seq);
298-
kfree(ctx->rx.iv);
296+
if (ctx->rx_conf == TLS_SW)
299297
tls_sw_free_resources_rx(sk);
300-
}
301298

302299
#ifdef CONFIG_TLS_DEVICE
303300
if (ctx->rx_conf == TLS_HW)

net/tls/tls_sw.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,6 +2078,9 @@ void tls_sw_release_resources_rx(struct sock *sk)
20782078
struct tls_context *tls_ctx = tls_get_ctx(sk);
20792079
struct tls_sw_context_rx *ctx = tls_sw_ctx_rx(tls_ctx);
20802080

2081+
kfree(tls_ctx->rx.rec_seq);
2082+
kfree(tls_ctx->rx.iv);
2083+
20812084
if (ctx->aead_recv) {
20822085
kfree_skb(ctx->recv_pkt);
20832086
ctx->recv_pkt = NULL;

0 commit comments

Comments
 (0)