Skip to content

Commit 3f92a64

Browse files
committed
tcp: allow tls to decrypt directly from the tcp rcv queue
Expose TCP rx queue accessor and cleanup, so that TLS can decrypt directly from the TCP queue. The expectation is that the caller can access the skb returned from tcp_recv_skb() and up to inq bytes worth of data (some of which may be in ->next skbs) and then call tcp_read_done() when data has been consumed. The socket lock must be held continuously across those two operations. Signed-off-by: Jakub Kicinski <[email protected]>
1 parent d4e5db6 commit 3f92a64

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

include/net/tcp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,8 @@ void tcp_get_info(struct sock *, struct tcp_info *);
673673
int tcp_read_sock(struct sock *sk, read_descriptor_t *desc,
674674
sk_read_actor_t recv_actor);
675675
int tcp_read_skb(struct sock *sk, skb_read_actor_t recv_actor);
676+
struct sk_buff *tcp_recv_skb(struct sock *sk, u32 seq, u32 *off);
677+
void tcp_read_done(struct sock *sk, size_t len);
676678

677679
void tcp_initialize_rcv_mss(struct sock *sk);
678680

net/ipv4/tcp.c

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1635,7 +1635,7 @@ static void tcp_eat_recv_skb(struct sock *sk, struct sk_buff *skb)
16351635
__kfree_skb(skb);
16361636
}
16371637

1638-
static struct sk_buff *tcp_recv_skb(struct sock *sk, u32 seq, u32 *off)
1638+
struct sk_buff *tcp_recv_skb(struct sock *sk, u32 seq, u32 *off)
16391639
{
16401640
struct sk_buff *skb;
16411641
u32 offset;
@@ -1658,6 +1658,7 @@ static struct sk_buff *tcp_recv_skb(struct sock *sk, u32 seq, u32 *off)
16581658
}
16591659
return NULL;
16601660
}
1661+
EXPORT_SYMBOL(tcp_recv_skb);
16611662

16621663
/*
16631664
* This routine provides an alternative to tcp_recvmsg() for routines
@@ -1788,6 +1789,45 @@ int tcp_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
17881789
}
17891790
EXPORT_SYMBOL(tcp_read_skb);
17901791

1792+
void tcp_read_done(struct sock *sk, size_t len)
1793+
{
1794+
struct tcp_sock *tp = tcp_sk(sk);
1795+
u32 seq = tp->copied_seq;
1796+
struct sk_buff *skb;
1797+
size_t left;
1798+
u32 offset;
1799+
1800+
if (sk->sk_state == TCP_LISTEN)
1801+
return;
1802+
1803+
left = len;
1804+
while (left && (skb = tcp_recv_skb(sk, seq, &offset)) != NULL) {
1805+
int used;
1806+
1807+
used = min_t(size_t, skb->len - offset, left);
1808+
seq += used;
1809+
left -= used;
1810+
1811+
if (skb->len > offset + used)
1812+
break;
1813+
1814+
if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) {
1815+
tcp_eat_recv_skb(sk, skb);
1816+
++seq;
1817+
break;
1818+
}
1819+
tcp_eat_recv_skb(sk, skb);
1820+
}
1821+
WRITE_ONCE(tp->copied_seq, seq);
1822+
1823+
tcp_rcv_space_adjust(sk);
1824+
1825+
/* Clean up data we have read: This will do ACK frames. */
1826+
if (left != len)
1827+
tcp_cleanup_rbuf(sk, len - left);
1828+
}
1829+
EXPORT_SYMBOL(tcp_read_done);
1830+
17911831
int tcp_peek_len(struct socket *sock)
17921832
{
17931833
return tcp_inq(sock->sk);

0 commit comments

Comments
 (0)