Skip to content

Commit 14c4be9

Browse files
kuba-moodavem330
authored andcommitted
tls: rx: strp: force mixed decrypted records into copy mode
If a record is partially decrypted we'll have to CoW it, anyway, so go into copy mode and allocate a writable skb right away. This will make subsequent fix simpler because we won't have to teach tls_strp_msg_make_copy() how to copy skbs while preserving decrypt status. 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 210620a commit 14c4be9

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

include/linux/skbuff.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,6 +1587,16 @@ static inline void skb_copy_hash(struct sk_buff *to, const struct sk_buff *from)
15871587
to->l4_hash = from->l4_hash;
15881588
};
15891589

1590+
static inline int skb_cmp_decrypted(const struct sk_buff *skb1,
1591+
const struct sk_buff *skb2)
1592+
{
1593+
#ifdef CONFIG_TLS_DEVICE
1594+
return skb2->decrypted - skb1->decrypted;
1595+
#else
1596+
return 0;
1597+
#endif
1598+
}
1599+
15901600
static inline void skb_copy_decrypted(struct sk_buff *to,
15911601
const struct sk_buff *from)
15921602
{

net/tls/tls_strp.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,22 +317,28 @@ static int tls_strp_read_copy(struct tls_strparser *strp, bool qshort)
317317
return 0;
318318
}
319319

320-
static bool tls_strp_check_no_dup(struct tls_strparser *strp)
320+
static bool tls_strp_check_queue_ok(struct tls_strparser *strp)
321321
{
322322
unsigned int len = strp->stm.offset + strp->stm.full_len;
323-
struct sk_buff *skb;
323+
struct sk_buff *first, *skb;
324324
u32 seq;
325325

326-
skb = skb_shinfo(strp->anchor)->frag_list;
327-
seq = TCP_SKB_CB(skb)->seq;
326+
first = skb_shinfo(strp->anchor)->frag_list;
327+
skb = first;
328+
seq = TCP_SKB_CB(first)->seq;
328329

330+
/* Make sure there's no duplicate data in the queue,
331+
* and the decrypted status matches.
332+
*/
329333
while (skb->len < len) {
330334
seq += skb->len;
331335
len -= skb->len;
332336
skb = skb->next;
333337

334338
if (TCP_SKB_CB(skb)->seq != seq)
335339
return false;
340+
if (skb_cmp_decrypted(first, skb))
341+
return false;
336342
}
337343

338344
return true;
@@ -413,7 +419,7 @@ static int tls_strp_read_sock(struct tls_strparser *strp)
413419
return tls_strp_read_copy(strp, true);
414420
}
415421

416-
if (!tls_strp_check_no_dup(strp))
422+
if (!tls_strp_check_queue_ok(strp))
417423
return tls_strp_read_copy(strp, false);
418424

419425
strp->msg_ready = 1;

0 commit comments

Comments
 (0)