UPSTREAM: tls: extract context alloc/initialization out of tls_set_sw_offload
[ Upstream commit 615580cbc99af0da2d1c7226fab43a3d5003eb97 ] Simplify tls_set_sw_offload a bit. Bug: 326214245 Signed-off-by: Sabrina Dubroca <sd@queasysnail.net> Signed-off-by: David S. Miller <davem@davemloft.net> Stable-dep-of: aec7961916f3 ("tls: fix race between async notify and socket close") Signed-off-by: Sasha Levin <sashal@kernel.org> (cherry picked from commit d55eb0b495a9e4de1c61394087bb06f12d18b6bc) Signed-off-by: Lee Jones <joneslee@google.com> Change-Id: I97ae8c76bb91d49ca26ad9d92c7ce099a3f780ed
This commit is contained in:
parent
338203a817
commit
5cb88480ab
@ -2507,6 +2507,48 @@ void tls_update_rx_zc_capable(struct tls_context *tls_ctx)
|
|||||||
tls_ctx->prot_info.version != TLS_1_3_VERSION;
|
tls_ctx->prot_info.version != TLS_1_3_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct tls_sw_context_tx *init_ctx_tx(struct tls_context *ctx, struct sock *sk)
|
||||||
|
{
|
||||||
|
struct tls_sw_context_tx *sw_ctx_tx;
|
||||||
|
|
||||||
|
if (!ctx->priv_ctx_tx) {
|
||||||
|
sw_ctx_tx = kzalloc(sizeof(*sw_ctx_tx), GFP_KERNEL);
|
||||||
|
if (!sw_ctx_tx)
|
||||||
|
return NULL;
|
||||||
|
} else {
|
||||||
|
sw_ctx_tx = ctx->priv_ctx_tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
crypto_init_wait(&sw_ctx_tx->async_wait);
|
||||||
|
spin_lock_init(&sw_ctx_tx->encrypt_compl_lock);
|
||||||
|
INIT_LIST_HEAD(&sw_ctx_tx->tx_list);
|
||||||
|
INIT_DELAYED_WORK(&sw_ctx_tx->tx_work.work, tx_work_handler);
|
||||||
|
sw_ctx_tx->tx_work.sk = sk;
|
||||||
|
|
||||||
|
return sw_ctx_tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct tls_sw_context_rx *init_ctx_rx(struct tls_context *ctx)
|
||||||
|
{
|
||||||
|
struct tls_sw_context_rx *sw_ctx_rx;
|
||||||
|
|
||||||
|
if (!ctx->priv_ctx_rx) {
|
||||||
|
sw_ctx_rx = kzalloc(sizeof(*sw_ctx_rx), GFP_KERNEL);
|
||||||
|
if (!sw_ctx_rx)
|
||||||
|
return NULL;
|
||||||
|
} else {
|
||||||
|
sw_ctx_rx = ctx->priv_ctx_rx;
|
||||||
|
}
|
||||||
|
|
||||||
|
crypto_init_wait(&sw_ctx_rx->async_wait);
|
||||||
|
spin_lock_init(&sw_ctx_rx->decrypt_compl_lock);
|
||||||
|
init_waitqueue_head(&sw_ctx_rx->wq);
|
||||||
|
skb_queue_head_init(&sw_ctx_rx->rx_list);
|
||||||
|
skb_queue_head_init(&sw_ctx_rx->async_hold);
|
||||||
|
|
||||||
|
return sw_ctx_rx;
|
||||||
|
}
|
||||||
|
|
||||||
int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx)
|
int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx)
|
||||||
{
|
{
|
||||||
struct tls_context *tls_ctx = tls_get_ctx(sk);
|
struct tls_context *tls_ctx = tls_get_ctx(sk);
|
||||||
@ -2528,48 +2570,22 @@ int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tx) {
|
if (tx) {
|
||||||
if (!ctx->priv_ctx_tx) {
|
ctx->priv_ctx_tx = init_ctx_tx(ctx, sk);
|
||||||
sw_ctx_tx = kzalloc(sizeof(*sw_ctx_tx), GFP_KERNEL);
|
if (!ctx->priv_ctx_tx)
|
||||||
if (!sw_ctx_tx) {
|
return -ENOMEM;
|
||||||
rc = -ENOMEM;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
ctx->priv_ctx_tx = sw_ctx_tx;
|
|
||||||
} else {
|
|
||||||
sw_ctx_tx =
|
|
||||||
(struct tls_sw_context_tx *)ctx->priv_ctx_tx;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!ctx->priv_ctx_rx) {
|
|
||||||
sw_ctx_rx = kzalloc(sizeof(*sw_ctx_rx), GFP_KERNEL);
|
|
||||||
if (!sw_ctx_rx) {
|
|
||||||
rc = -ENOMEM;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
ctx->priv_ctx_rx = sw_ctx_rx;
|
|
||||||
} else {
|
|
||||||
sw_ctx_rx =
|
|
||||||
(struct tls_sw_context_rx *)ctx->priv_ctx_rx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tx) {
|
sw_ctx_tx = ctx->priv_ctx_tx;
|
||||||
crypto_init_wait(&sw_ctx_tx->async_wait);
|
|
||||||
spin_lock_init(&sw_ctx_tx->encrypt_compl_lock);
|
|
||||||
crypto_info = &ctx->crypto_send.info;
|
crypto_info = &ctx->crypto_send.info;
|
||||||
cctx = &ctx->tx;
|
cctx = &ctx->tx;
|
||||||
aead = &sw_ctx_tx->aead_send;
|
aead = &sw_ctx_tx->aead_send;
|
||||||
INIT_LIST_HEAD(&sw_ctx_tx->tx_list);
|
|
||||||
INIT_DELAYED_WORK(&sw_ctx_tx->tx_work.work, tx_work_handler);
|
|
||||||
sw_ctx_tx->tx_work.sk = sk;
|
|
||||||
} else {
|
} else {
|
||||||
crypto_init_wait(&sw_ctx_rx->async_wait);
|
ctx->priv_ctx_rx = init_ctx_rx(ctx);
|
||||||
spin_lock_init(&sw_ctx_rx->decrypt_compl_lock);
|
if (!ctx->priv_ctx_rx)
|
||||||
init_waitqueue_head(&sw_ctx_rx->wq);
|
return -ENOMEM;
|
||||||
|
|
||||||
|
sw_ctx_rx = ctx->priv_ctx_rx;
|
||||||
crypto_info = &ctx->crypto_recv.info;
|
crypto_info = &ctx->crypto_recv.info;
|
||||||
cctx = &ctx->rx;
|
cctx = &ctx->rx;
|
||||||
skb_queue_head_init(&sw_ctx_rx->rx_list);
|
|
||||||
skb_queue_head_init(&sw_ctx_rx->async_hold);
|
|
||||||
aead = &sw_ctx_rx->aead_recv;
|
aead = &sw_ctx_rx->aead_recv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user