Skip to content

Commit 3463e51

Browse files
keesdavem330
authored andcommitted
net/tls: Remove VLA usage on nonce
It looks like the prior VLA removal, commit b16520f ("net/tls: Remove VLA usage"), and a new VLA addition, commit c46234e ("tls: RX path for ktls"), passed in the night. This removes the newly added VLA, which happens to have its bounds based on the same max value. Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 27a2628 commit 3463e51

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

net/tls/tls_sw.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ static int tls_read_size(struct strparser *strp, struct sk_buff *skb)
941941
{
942942
struct tls_context *tls_ctx = tls_get_ctx(strp->sk);
943943
struct tls_sw_context_rx *ctx = tls_sw_ctx_rx(tls_ctx);
944-
char header[tls_ctx->rx.prepend_size];
944+
char header[TLS_HEADER_SIZE + MAX_IV_SIZE];
945945
struct strp_msg *rxm = strp_msg(skb);
946946
size_t cipher_overhead;
947947
size_t data_len = 0;
@@ -951,6 +951,12 @@ static int tls_read_size(struct strparser *strp, struct sk_buff *skb)
951951
if (rxm->offset + tls_ctx->rx.prepend_size > skb->len)
952952
return 0;
953953

954+
/* Sanity-check size of on-stack buffer. */
955+
if (WARN_ON(tls_ctx->rx.prepend_size > sizeof(header))) {
956+
ret = -EINVAL;
957+
goto read_failure;
958+
}
959+
954960
/* Linearize header to local buffer */
955961
ret = skb_copy_bits(skb, rxm->offset, header, tls_ctx->rx.prepend_size);
956962

@@ -1108,7 +1114,7 @@ int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx)
11081114
}
11091115

11101116
/* Sanity-check the IV size for stack allocations. */
1111-
if (iv_size > MAX_IV_SIZE) {
1117+
if (iv_size > MAX_IV_SIZE || nonce_size > MAX_IV_SIZE) {
11121118
rc = -EINVAL;
11131119
goto free_priv;
11141120
}

0 commit comments

Comments
 (0)