Skip to content

Commit cf6d43e

Browse files
qsndavem330
authored andcommitted
tls: fix sw_ctx leak
During setsockopt(SOL_TCP, TLS_TX), if initialization of the software context fails in tls_set_sw_offload(), we leak sw_ctx. We also don't reassign ctx->priv_ctx to NULL, so we can't even do another attempt to set it up on the same socket, as it will fail with -EEXIST. Fixes: 3c4d755 ('tls: kernel TLS support') Signed-off-by: Sabrina Dubroca <sd@queasysnail.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 6ab6dd9 commit cf6d43e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

net/tls/tls_sw.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -681,18 +681,17 @@ int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx)
681681
}
682682
default:
683683
rc = -EINVAL;
684-
goto out;
684+
goto free_priv;
685685
}
686686

687687
ctx->prepend_size = TLS_HEADER_SIZE + nonce_size;
688688
ctx->tag_size = tag_size;
689689
ctx->overhead_size = ctx->prepend_size + ctx->tag_size;
690690
ctx->iv_size = iv_size;
691-
ctx->iv = kmalloc(iv_size + TLS_CIPHER_AES_GCM_128_SALT_SIZE,
692-
GFP_KERNEL);
691+
ctx->iv = kmalloc(iv_size + TLS_CIPHER_AES_GCM_128_SALT_SIZE, GFP_KERNEL);
693692
if (!ctx->iv) {
694693
rc = -ENOMEM;
695-
goto out;
694+
goto free_priv;
696695
}
697696
memcpy(ctx->iv, gcm_128_info->salt, TLS_CIPHER_AES_GCM_128_SALT_SIZE);
698697
memcpy(ctx->iv + TLS_CIPHER_AES_GCM_128_SALT_SIZE, iv, iv_size);
@@ -740,7 +739,7 @@ int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx)
740739

741740
rc = crypto_aead_setauthsize(sw_ctx->aead_send, ctx->tag_size);
742741
if (!rc)
743-
goto out;
742+
return 0;
744743

745744
free_aead:
746745
crypto_free_aead(sw_ctx->aead_send);
@@ -751,6 +750,9 @@ int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx)
751750
free_iv:
752751
kfree(ctx->iv);
753752
ctx->iv = NULL;
753+
free_priv:
754+
kfree(ctx->priv_ctx);
755+
ctx->priv_ctx = NULL;
754756
out:
755757
return rc;
756758
}

0 commit comments

Comments
 (0)