Software kTLS receive parses and decrypts TLS records on the CPU, assuming queued fragments are readable struct pages. If TLS_RX is configured on a socket with unreadable net_iov data in its receive queue (or receiving from a devmem RX queue), tls_strp either anchors unreadable skbs for CPU decryption or triggers warnings and advances skb lengths over uninitialized memory when skb_copy_bits() fails. Reject unreadable skbs in tls_strp queue validation and abort stream parsing cleanly with -EFAULT if unreadable fragments are encountered. This issue was found by code inspection while developing per-socket devmem RX and reproduced and verified with the accompanying devmem.py selftests. Fixes: 65249feb6b3d ("net: add support for skbs with unreadable frags") Assisted-by: LLM Signed-off-by: Octavian Purdila --- net/tls/tls_strp.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/net/tls/tls_strp.c b/net/tls/tls_strp.c index 53d3256d0114a..a9e49384a1692 100644 --- a/net/tls/tls_strp.c +++ b/net/tls/tls_strp.c @@ -45,6 +45,11 @@ tls_strp_skb_copy(struct tls_strparser *strp, struct sk_buff *in_skb, struct sk_buff *skb; int i, err; + if (unlikely(!skb_frags_readable(in_skb))) { + tls_strp_abort_strp(strp, -EFAULT); + return NULL; + } + skb = alloc_skb_with_frags(0, len, TLS_PAGE_ORDER, &err, strp->sk->sk_allocation); if (!skb) @@ -53,9 +58,13 @@ tls_strp_skb_copy(struct tls_strparser *strp, struct sk_buff *in_skb, for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; - WARN_ON_ONCE(skb_copy_bits(in_skb, offset, + if (unlikely(skb_copy_bits(in_skb, offset, skb_frag_address(frag), - skb_frag_size(frag))); + skb_frag_size(frag)))) { + kfree_skb(skb); + tls_strp_abort_strp(strp, -EFAULT); + return NULL; + } offset += skb_frag_size(frag); } @@ -349,6 +358,12 @@ static int tls_strp_copyin(read_descriptor_t *desc, struct sk_buff *in_skb, if (strp->msg_ready) return 0; + if (unlikely(!skb_frags_readable(in_skb))) { + tls_strp_abort_strp(strp, -EFAULT); + desc->error = -EFAULT; + return 0; + } + skb = strp->anchor; if (!skb->len) skb_copy_decrypted(skb, in_skb); @@ -438,6 +453,8 @@ static bool tls_strp_check_queue_ok(struct tls_strparser *strp, u32 seq; first = skb_shinfo(strp->anchor)->frag_list; + if (unlikely(!skb_frags_readable(first))) + return false; skb = first; seq = TCP_SKB_CB(first)->seq; @@ -449,6 +466,9 @@ static bool tls_strp_check_queue_ok(struct tls_strparser *strp, remaining -= skb->len; skb = skb->next; + if (unlikely(!skb_frags_readable(skb))) + return false; + if (TCP_SKB_CB(skb)->seq != seq) return false; if (skb_cmp_decrypted(first, skb)) -- 2.56.1.915.g69d5ec7298-goog