diff options
author | Eric Dumazet <edumazet@google.com> | 2016-11-10 16:12:35 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-11-13 12:30:02 -0500 |
commit | ac6e780070e30e4c35bd395acfe9191e6268bdd3 (patch) | |
tree | ee4ad258481549b15aa79cccf97b47c5ff3954e1 /net/ipv4 | |
parent | 969447f226b451c453ddc83cac6144eaeac6f2e3 (diff) |
tcp: take care of truncations done by sk_filter()
With syzkaller help, Marco Grassi found a bug in TCP stack,
crashing in tcp_collapse()
Root cause is that sk_filter() can truncate the incoming skb,
but TCP stack was not really expecting this to happen.
It probably was expecting a simple DROP or ACCEPT behavior.
We first need to make sure no part of TCP header could be removed.
Then we need to adjust TCP_SKB_CB(skb)->end_seq
Many thanks to syzkaller team and Marco for giving us a reproducer.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: Marco Grassi <marco.gra@gmail.com>
Reported-by: Vladis Dronov <vdronov@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r-- | net/ipv4/tcp_ipv4.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 61b7be303eec..2259114c7242 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c | |||
@@ -1564,6 +1564,21 @@ bool tcp_add_backlog(struct sock *sk, struct sk_buff *skb) | |||
1564 | } | 1564 | } |
1565 | EXPORT_SYMBOL(tcp_add_backlog); | 1565 | EXPORT_SYMBOL(tcp_add_backlog); |
1566 | 1566 | ||
1567 | int tcp_filter(struct sock *sk, struct sk_buff *skb) | ||
1568 | { | ||
1569 | struct tcphdr *th = (struct tcphdr *)skb->data; | ||
1570 | unsigned int eaten = skb->len; | ||
1571 | int err; | ||
1572 | |||
1573 | err = sk_filter_trim_cap(sk, skb, th->doff * 4); | ||
1574 | if (!err) { | ||
1575 | eaten -= skb->len; | ||
1576 | TCP_SKB_CB(skb)->end_seq -= eaten; | ||
1577 | } | ||
1578 | return err; | ||
1579 | } | ||
1580 | EXPORT_SYMBOL(tcp_filter); | ||
1581 | |||
1567 | /* | 1582 | /* |
1568 | * From tcp_input.c | 1583 | * From tcp_input.c |
1569 | */ | 1584 | */ |
@@ -1676,8 +1691,10 @@ process: | |||
1676 | 1691 | ||
1677 | nf_reset(skb); | 1692 | nf_reset(skb); |
1678 | 1693 | ||
1679 | if (sk_filter(sk, skb)) | 1694 | if (tcp_filter(sk, skb)) |
1680 | goto discard_and_relse; | 1695 | goto discard_and_relse; |
1696 | th = (const struct tcphdr *)skb->data; | ||
1697 | iph = ip_hdr(skb); | ||
1681 | 1698 | ||
1682 | skb->dev = NULL; | 1699 | skb->dev = NULL; |
1683 | 1700 | ||