Skip to content

Commit 8b0c0dc

Browse files
kuba-moodavem330
authored andcommitted
tls: rx: strp: fix determining record length in copy mode
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 <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 14c4be9 commit 8b0c0dc

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

net/tls/tls_strp.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,19 +210,28 @@ static int tls_strp_copyin(read_descriptor_t *desc, struct sk_buff *in_skb,
210210
skb_frag_size(frag),
211211
chunk));
212212

213-
sz = tls_rx_msg_size(strp, strp->anchor);
213+
skb->len += chunk;
214+
skb->data_len += chunk;
215+
skb_frag_size_add(frag, chunk);
216+
217+
sz = tls_rx_msg_size(strp, skb);
214218
if (sz < 0) {
215219
desc->error = sz;
216220
return 0;
217221
}
218222

219223
/* We may have over-read, sz == 0 is guaranteed under-read */
220-
if (sz > 0)
221-
chunk = min_t(size_t, chunk, sz - skb->len);
224+
if (unlikely(sz && sz < skb->len)) {
225+
int over = skb->len - sz;
226+
227+
WARN_ON_ONCE(over > chunk);
228+
skb->len -= over;
229+
skb->data_len -= over;
230+
skb_frag_size_add(frag, -over);
231+
232+
chunk -= over;
233+
}
222234

223-
skb->len += chunk;
224-
skb->data_len += chunk;
225-
skb_frag_size_add(frag, chunk);
226235
frag++;
227236
len -= chunk;
228237
offset += chunk;

0 commit comments

Comments
 (0)