diff options
author | Nicolas Dichtel | 2020-01-13 02:32:46 -0600 |
---|---|---|
committer | Greg Kroah-Hartman | 2020-02-05 08:43:49 -0600 |
commit | 011e94777d909f2551b0ade17bdad3672f979511 (patch) | |
tree | eade17ae19ff789a57bbc6ea11bddfdea89d2e8c | |
parent | 7a2c1d387f59f5917922bd1154978af7e9b453de (diff) | |
download | kernel-011e94777d909f2551b0ade17bdad3672f979511.tar.gz kernel-011e94777d909f2551b0ade17bdad3672f979511.tar.xz kernel-011e94777d909f2551b0ade17bdad3672f979511.zip |
vti[6]: fix packet tx through bpf_redirect()
[ Upstream commit 95224166a9032ff5d08fca633d37113078ce7d01 ]
With an ebpf program that redirects packets through a vti[6] interface,
the packets are dropped because no dst is attached.
This could also be reproduced with an AF_PACKET socket, with the following
python script (vti1 is an ip_vti interface):
import socket
send_s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, 0)
# scapy
# p = IP(src='10.100.0.2', dst='10.200.0.1')/ICMP(type='echo-request')
# raw(p)
req = b'E\x00\x00\x1c\x00\x01\x00\x00@\x01e\xb2\nd\x00\x02\n\xc8\x00\x01\x08\x00\xf7\xff\x00\x00\x00\x00'
send_s.sendto(req, ('vti1', 0x800, 0, 0))
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r-- | net/ipv4/ip_vti.c | 13 | ||||
-rw-r--r-- | net/ipv6/ip6_vti.c | 13 |
2 files changed, 22 insertions, 4 deletions
diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c index 960f4faaf294..f5e5fcd90859 100644 --- a/net/ipv4/ip_vti.c +++ b/net/ipv4/ip_vti.c | |||
@@ -208,8 +208,17 @@ static netdev_tx_t vti_xmit(struct sk_buff *skb, struct net_device *dev, | |||
208 | int mtu; | 208 | int mtu; |
209 | 209 | ||
210 | if (!dst) { | 210 | if (!dst) { |
211 | dev->stats.tx_carrier_errors++; | 211 | struct rtable *rt; |
212 | goto tx_error_icmp; | 212 | |
213 | fl->u.ip4.flowi4_oif = dev->ifindex; | ||
214 | fl->u.ip4.flowi4_flags |= FLOWI_FLAG_ANYSRC; | ||
215 | rt = __ip_route_output_key(dev_net(dev), &fl->u.ip4); | ||
216 | if (IS_ERR(rt)) { | ||
217 | dev->stats.tx_carrier_errors++; | ||
218 | goto tx_error_icmp; | ||
219 | } | ||
220 | dst = &rt->dst; | ||
221 | skb_dst_set(skb, dst); | ||
213 | } | 222 | } |
214 | 223 | ||
215 | dst_hold(dst); | 224 | dst_hold(dst); |
diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c index bfd39db3398a..67ff206b6d61 100644 --- a/net/ipv6/ip6_vti.c +++ b/net/ipv6/ip6_vti.c | |||
@@ -453,8 +453,17 @@ vti6_xmit(struct sk_buff *skb, struct net_device *dev, struct flowi *fl) | |||
453 | int err = -1; | 453 | int err = -1; |
454 | int mtu; | 454 | int mtu; |
455 | 455 | ||
456 | if (!dst) | 456 | if (!dst) { |
457 | goto tx_err_link_failure; | 457 | fl->u.ip6.flowi6_oif = dev->ifindex; |
458 | fl->u.ip6.flowi6_flags |= FLOWI_FLAG_ANYSRC; | ||
459 | dst = ip6_route_output(dev_net(dev), NULL, &fl->u.ip6); | ||
460 | if (dst->error) { | ||
461 | dst_release(dst); | ||
462 | dst = NULL; | ||
463 | goto tx_err_link_failure; | ||
464 | } | ||
465 | skb_dst_set(skb, dst); | ||
466 | } | ||
458 | 467 | ||
459 | dst_hold(dst); | 468 | dst_hold(dst); |
460 | dst = xfrm_lookup(t->net, dst, fl, NULL, 0); | 469 | dst = xfrm_lookup(t->net, dst, fl, NULL, 0); |