]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: Fix bpf_redirect to an ipip/ip6tnl dev
authorMartin KaFai Lau <kafai@fb.com>
Wed, 9 Nov 2016 23:36:33 +0000 (15:36 -0800)
committerDavid S. Miller <davem@davemloft.net>
Sun, 13 Nov 2016 04:38:07 +0000 (23:38 -0500)
commitf24348bd1556b13629f8f0917ab04517d18a4d57
treef6aee654871f3a3f3c471b811d66522e200454b1
parent0eaf5a138cf29f61751bd4d61fb83a5bc659789d
bpf: Fix bpf_redirect to an ipip/ip6tnl dev

If the bpf program calls bpf_redirect(dev, 0) and dev is
an ipip/ip6tnl, it currently includes the mac header.
e.g. If dev is ipip, the end result is IP-EthHdr-IP instead
of IP-IP.

The fix is to pull the mac header.  At ingress, skb_postpull_rcsum()
is not needed because the ethhdr should have been pulled once already
and then got pushed back just before calling the bpf_prog.
At egress, this patch calls skb_postpull_rcsum().

If bpf_redirect(dev, BPF_F_INGRESS) is called,
it also fails now because it calls dev_forward_skb() which
eventually calls eth_type_trans(skb, dev).  The eth_type_trans()
will set skb->type = PACKET_OTHERHOST because the mac address
does not match the redirecting dev->dev_addr.  The PACKET_OTHERHOST
will eventually cause the ip_rcv() errors out.  To fix this,
____dev_forward_skb() is added.

Joint work with Daniel Borkmann.

Fixes: c1fdbdd5d062 ("ip_tunnel: add collect_md mode to IPIP tunnel")
Fixes: 0b8b3a8de6df ("ip6_tunnel: add collect_md mode to IPv6 tunnels")
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@fb.com>
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/netdevice.h
net/core/dev.c
net/core/filter.c