]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
vti[6]: fix packet tx through bpf_redirect()
authorNicolas Dichtel <nicolas.dichtel@6wind.com>
Wed, 12 Feb 2020 18:07:00 +0000 (19:07 +0100)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Fri, 14 Feb 2020 12:44:21 +0000 (13:44 +0100)
BugLink: https://bugs.launchpad.net/bugs/1860969
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>
(cherry picked from commit 95224166a9032ff5d08fca633d37113078ce7d01)
Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
Acked-by: Kamal Mostafa <kamal@canonical.com>
Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
net/ipv4/ip_vti.c
net/ipv6/ip6_vti.c

index fb9f6d60c27cdf57cf677507b98eb8d3570bef50..79eef5db336a4e50dbdbedd02e4297c4aedcd80c 100644 (file)
@@ -187,8 +187,17 @@ static netdev_tx_t vti_xmit(struct sk_buff *skb, struct net_device *dev,
        int mtu;
 
        if (!dst) {
-               dev->stats.tx_carrier_errors++;
-               goto tx_error_icmp;
+               struct rtable *rt;
+
+               fl->u.ip4.flowi4_oif = dev->ifindex;
+               fl->u.ip4.flowi4_flags |= FLOWI_FLAG_ANYSRC;
+               rt = __ip_route_output_key(dev_net(dev), &fl->u.ip4);
+               if (IS_ERR(rt)) {
+                       dev->stats.tx_carrier_errors++;
+                       goto tx_error_icmp;
+               }
+               dst = &rt->dst;
+               skb_dst_set(skb, dst);
        }
 
        dst_hold(dst);
index 7ae98a24b31d14798c6a500525b3c1f75a740407..a45ca5ec30840d90b5979389cb7bcd3f7e4dc2ce 100644 (file)
@@ -449,8 +449,17 @@ vti6_xmit(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)
        int err = -1;
        int mtu;
 
-       if (!dst)
-               goto tx_err_link_failure;
+       if (!dst) {
+               fl->u.ip6.flowi6_oif = dev->ifindex;
+               fl->u.ip6.flowi6_flags |= FLOWI_FLAG_ANYSRC;
+               dst = ip6_route_output(dev_net(dev), NULL, &fl->u.ip6);
+               if (dst->error) {
+                       dst_release(dst);
+                       dst = NULL;
+                       goto tx_err_link_failure;
+               }
+               skb_dst_set(skb, dst);
+       }
 
        dst_hold(dst);
        dst = xfrm_lookup(t->net, dst, fl, NULL, 0);