Skip to content

Commit

Permalink
tls: rx: strp: fix determining record length in copy mode
Browse files Browse the repository at this point in the history
[ Upstream commit 8b0c0dc ]

We call tls_rx_msg_size(skb) before doing skb->len += chunk.
So the tls_rx_msg_size() code will see old skb->len, most
likely leading to an over-read.

Worst case we will over read an entire record, next iteration
will try to trim the skb but may end up turning frag len negative
or discarding the subsequent record (since we already told TCP
we've read it during previous read but now we'll trim it out of
the skb).

Fixes: 84c61fe ("tls: rx: do not use the standard strparser")
Tested-by: Shai Amiram <samiram@nvidia.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
kuba-moo authored and gregkh committed Jun 5, 2023
1 parent ecd9f6e commit c48b839
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions net/tls/tls_strp.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,28 @@ static int tls_strp_copyin(read_descriptor_t *desc, struct sk_buff *in_skb,
skb_frag_size(frag),
chunk));

sz = tls_rx_msg_size(strp, strp->anchor);
skb->len += chunk;
skb->data_len += chunk;
skb_frag_size_add(frag, chunk);

sz = tls_rx_msg_size(strp, skb);
if (sz < 0) {
desc->error = sz;
return 0;
}

/* We may have over-read, sz == 0 is guaranteed under-read */
if (sz > 0)
chunk = min_t(size_t, chunk, sz - skb->len);
if (unlikely(sz && sz < skb->len)) {
int over = skb->len - sz;

WARN_ON_ONCE(over > chunk);
skb->len -= over;
skb->data_len -= over;
skb_frag_size_add(frag, -over);

chunk -= over;
}

skb->len += chunk;
skb->data_len += chunk;
skb_frag_size_add(frag, chunk);
frag++;
len -= chunk;
offset += chunk;
Expand Down

0 comments on commit c48b839

Please sign in to comment.