All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tcp: Don't access TCP_SKB_CB before initializing it
@ 2019-03-11 18:41 Christoph Paasch
  2019-03-11 22:19 ` Eric Dumazet
  2019-03-11 22:37 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Christoph Paasch @ 2019-03-11 18:41 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Eric Dumazet

Since commit eeea10b83a13 ("tcp: add
tcp_v4_fill_cb()/tcp_v4_restore_cb()"), tcp_vX_fill_cb is only called
after tcp_filter(). That means, TCP_SKB_CB(skb)->end_seq still points to
the IP-part of the cb.

We thus should not mock with it, as this can trigger bugs (thanks
syzkaller):
[   12.349396] ==================================================================
[   12.350188] BUG: KASAN: slab-out-of-bounds in ip6_datagram_recv_specific_ctl+0x19b3/0x1a20
[   12.351035] Read of size 1 at addr ffff88006adbc208 by task test_ip6_datagr/1799

Setting end_seq is actually no more necessary in tcp_filter as it gets
initialized later on in tcp_vX_fill_cb.

Cc: Eric Dumazet <edumazet@google.com>
Fixes: eeea10b83a13 ("tcp: add tcp_v4_fill_cb()/tcp_v4_restore_cb()")
Signed-off-by: Christoph Paasch <cpaasch@apple.com>
---
 net/ipv4/tcp_ipv4.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 831d844a27ca..277d71239d75 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1734,15 +1734,8 @@ EXPORT_SYMBOL(tcp_add_backlog);
 int tcp_filter(struct sock *sk, struct sk_buff *skb)
 {
 	struct tcphdr *th = (struct tcphdr *)skb->data;
-	unsigned int eaten = skb->len;
-	int err;
 
-	err = sk_filter_trim_cap(sk, skb, th->doff * 4);
-	if (!err) {
-		eaten -= skb->len;
-		TCP_SKB_CB(skb)->end_seq -= eaten;
-	}
-	return err;
+	return sk_filter_trim_cap(sk, skb, th->doff * 4);
 }
 EXPORT_SYMBOL(tcp_filter);
 
-- 
2.16.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] tcp: Don't access TCP_SKB_CB before initializing it
  2019-03-11 18:41 [PATCH] tcp: Don't access TCP_SKB_CB before initializing it Christoph Paasch
@ 2019-03-11 22:19 ` Eric Dumazet
  2019-03-11 22:37 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2019-03-11 22:19 UTC (permalink / raw)
  To: Christoph Paasch, David Miller; +Cc: netdev, Eric Dumazet



On 03/11/2019 11:41 AM, Christoph Paasch wrote:
> Since commit eeea10b83a13 ("tcp: add
> tcp_v4_fill_cb()/tcp_v4_restore_cb()"), tcp_vX_fill_cb is only called
> after tcp_filter(). That means, TCP_SKB_CB(skb)->end_seq still points to
> the IP-part of the cb.
> 
> We thus should not mock with it, as this can trigger bugs (thanks
> syzkaller):
> [   12.349396] ==================================================================
> [   12.350188] BUG: KASAN: slab-out-of-bounds in ip6_datagram_recv_specific_ctl+0x19b3/0x1a20
> [   12.351035] Read of size 1 at addr ffff88006adbc208 by task test_ip6_datagr/1799
> 
> Setting end_seq is actually no more necessary in tcp_filter as it gets
> initialized later on in tcp_vX_fill_cb.
> 
> Cc: Eric Dumazet <edumazet@google.com>
> Fixes: eeea10b83a13 ("tcp: add tcp_v4_fill_cb()/tcp_v4_restore_cb()")
> Signed-off-by: Christoph Paasch <cpaasch@apple.com>
> ---
>  net/ipv4/tcp_ipv4.c | 9 +--------
>  1 file changed, 1 insertion(+), 8 deletions(-)

Good catch, thanks !

Signed-off-by: Eric Dumazet <edumazet@google.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tcp: Don't access TCP_SKB_CB before initializing it
  2019-03-11 18:41 [PATCH] tcp: Don't access TCP_SKB_CB before initializing it Christoph Paasch
  2019-03-11 22:19 ` Eric Dumazet
@ 2019-03-11 22:37 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2019-03-11 22:37 UTC (permalink / raw)
  To: cpaasch; +Cc: netdev, edumazet

From: Christoph Paasch <cpaasch@apple.com>
Date: Mon, 11 Mar 2019 11:41:05 -0700

> Since commit eeea10b83a13 ("tcp: add
> tcp_v4_fill_cb()/tcp_v4_restore_cb()"), tcp_vX_fill_cb is only called
> after tcp_filter(). That means, TCP_SKB_CB(skb)->end_seq still points to
> the IP-part of the cb.
> 
> We thus should not mock with it, as this can trigger bugs (thanks
> syzkaller):
> [   12.349396] ==================================================================
> [   12.350188] BUG: KASAN: slab-out-of-bounds in ip6_datagram_recv_specific_ctl+0x19b3/0x1a20
> [   12.351035] Read of size 1 at addr ffff88006adbc208 by task test_ip6_datagr/1799
> 
> Setting end_seq is actually no more necessary in tcp_filter as it gets
> initialized later on in tcp_vX_fill_cb.
> 
> Cc: Eric Dumazet <edumazet@google.com>
> Fixes: eeea10b83a13 ("tcp: add tcp_v4_fill_cb()/tcp_v4_restore_cb()")
> Signed-off-by: Christoph Paasch <cpaasch@apple.com>

Applied.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-03-11 22:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-11 18:41 [PATCH] tcp: Don't access TCP_SKB_CB before initializing it Christoph Paasch
2019-03-11 22:19 ` Eric Dumazet
2019-03-11 22:37 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.