From patchwork Mon Feb 10 16:59:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kelsey Skunberg X-Patchwork-Id: 1235895 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48GXFV6S4Lz9sRN; Tue, 11 Feb 2020 03:59:42 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1j1CPK-0000YP-Mz; Mon, 10 Feb 2020 16:59:38 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1j1CPI-0000Xp-0f for kernel-team@lists.ubuntu.com; Mon, 10 Feb 2020 16:59:36 +0000 Received: from mail-il1-f200.google.com ([209.85.166.200]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1j1CPH-00085O-KW for kernel-team@lists.ubuntu.com; Mon, 10 Feb 2020 16:59:35 +0000 Received: by mail-il1-f200.google.com with SMTP id z12so7118291ilh.17 for ; Mon, 10 Feb 2020 08:59:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RCfXzKCKa/bNp+yzNTETxrRArrWBuD5l92z8jn03Tdo=; b=UCvlqVre2+jromMJac7xFt3JsarHk19F+/sx7MiAm9/Ik8rDWX2Jd/y6c4me9pU0mJ M1t0zihafZ+0qbtmY1UEFXAXgEPZQ12cmYXChPEXTGiAkyk6l4NhY7WkisH/EfFSQpPb YaYXR9yBdoWjLxp3oy5uKQ/W2uh5JiGo1MWwIbKG1JUWVVoxB/vgQ5TI29aSj4283OUM l0D0cpKNxANIx33VvNSPN+kRR8QY3C7ShVyuYB4VfW5ZppPmQTKq3PsPQw8TXUZe+NMX 2D+bzUY2RVnNAgapPb4gaKJ382ZPNV721AaXkDx58wvtCh3S16b5AFVKx2cccJdnD+wI DJmw== X-Gm-Message-State: APjAAAWACezYSt6vcCbvE0lXNsA28WUWH4PafFR6bqFwDoNGknHpP5Lj hKEc+PuYV2AM3JLb7kTXvimH3ijtq7dOJ4TtRt82eydmOD0IPUmJkd11Et9q1UmU7zkWIlCqgoU EokSyDJ/4NYSbta/0mXbKpM+UD9Dz2eXGpmTHQC9UVA== X-Received: by 2002:a6b:600f:: with SMTP id r15mr9608682iog.54.1581353974474; Mon, 10 Feb 2020 08:59:34 -0800 (PST) X-Google-Smtp-Source: APXvYqwdrLn0opVLW0dtIRx9T+CqipV2Ot45vLlmg4z89MEjxstW98/aGKJTxhRoMO4Mfr2QtP5roA== X-Received: by 2002:a6b:600f:: with SMTP id r15mr9608668iog.54.1581353974265; Mon, 10 Feb 2020 08:59:34 -0800 (PST) Received: from localhost.localdomain (c-73-243-191-173.hsd1.co.comcast.net. [73.243.191.173]) by smtp.gmail.com with ESMTPSA id v18sm215486ilm.85.2020.02.10.08.59.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2020 08:59:34 -0800 (PST) From: Kelsey Skunberg To: kernel-team@lists.ubuntu.com Subject: [SRU][F/E/B/X][PATCH 1/2] vti[6]: fix packet tx through bpf_redirect() Date: Mon, 10 Feb 2020 09:59:16 -0700 Message-Id: <20200210165917.23193-2-kelsey.skunberg@canonical.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200210165917.23193-1-kelsey.skunberg@canonical.com> References: <20200210165917.23193-1-kelsey.skunberg@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Nicolas Dichtel 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 Signed-off-by: Steffen Klassert (cherry picked from commit 95224166a9032ff5d08fca633d37113078ce7d01) Signed-off-by: Kelsey Skunberg --- net/ipv4/ip_vti.c | 13 +++++++++++-- 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 cfb025606793..8064e5750b65 100644 --- a/net/ipv4/ip_vti.c +++ b/net/ipv4/ip_vti.c @@ -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); diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c index 4aa31ccd8a33..f11916120ef3 100644 --- a/net/ipv6/ip6_vti.c +++ b/net/ipv6/ip6_vti.c @@ -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); From patchwork Mon Feb 10 16:59:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kelsey Skunberg X-Patchwork-Id: 1235896 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48GXFW2btHz9sRQ; Tue, 11 Feb 2020 03:59:43 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1j1CPL-0000Yh-2q; Mon, 10 Feb 2020 16:59:39 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1j1CPI-0000Xv-ON for kernel-team@lists.ubuntu.com; Mon, 10 Feb 2020 16:59:36 +0000 Received: from mail-il1-f198.google.com ([209.85.166.198]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1j1CPI-00085U-Bj for kernel-team@lists.ubuntu.com; Mon, 10 Feb 2020 16:59:36 +0000 Received: by mail-il1-f198.google.com with SMTP id z12so7118315ilh.17 for ; Mon, 10 Feb 2020 08:59:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eHmBIvtY+Ozj7/6HU3Cc3JBEzCZE12ZE2Gk+ZD9K+KE=; b=PhRHTupq43WCW0ddrisIX87T1EZLmnOJBI1Up79B4rDb10CQaKZKTq23I7nfSJ8Rfq M5dVaOCjoeff65nulDDzCrAvLsbeKONNZBgpB5bKvs9QLj4HqJM8JbnIE5EKDGcV5ttB MB9RmRoCQOKV9Q3G6CvpJGqUNXBfjHhdwU6H4DHuHBVaNGZ3G0ng/lqQ9OvstC3/vPfK 96S89+4aV3LYPgGv19uJW7/73978KY5jbDVAxWEIzCRL21kOWVplZtuuFQ/Xd+w+DVOl Z9+y5ls/4ZfxaPySoqdKlQlZBIWqzAyGf74/ez2XMR9UdCua/IXsH1u1w3sJPskP4iz/ BRUg== X-Gm-Message-State: APjAAAXCZQmRV2de0lVG+2A80o0AnggBYbAQyrDbVN8a8jUkTGLfWRD0 3RVKnbn1cbh4zF+wpAESt1Qy3i5r9oE11K+wJVJoYK357FxttyI0/gT4ydC9XTPAnyir1/ISF/W 1UIgjOeFAceLM/vScplpYkz1oiynhXwhi2Ld4iOjBfQ== X-Received: by 2002:a02:c85b:: with SMTP id r27mr10635520jao.57.1581353975182; Mon, 10 Feb 2020 08:59:35 -0800 (PST) X-Google-Smtp-Source: APXvYqxft0w+v5RbE6eTyia5eLuUYKM1o1Hv+7EieSViZDRfakKvDYHQ11XbcQ2DRqUWOFizzM4frQ== X-Received: by 2002:a02:c85b:: with SMTP id r27mr10635504jao.57.1581353974820; Mon, 10 Feb 2020 08:59:34 -0800 (PST) Received: from localhost.localdomain (c-73-243-191-173.hsd1.co.comcast.net. [73.243.191.173]) by smtp.gmail.com with ESMTPSA id v18sm215486ilm.85.2020.02.10.08.59.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2020 08:59:34 -0800 (PST) From: Kelsey Skunberg To: kernel-team@lists.ubuntu.com Subject: [SRU][F/E/B/X][PATCH 2/2] xfrm interface: fix packet tx through bpf_redirect() Date: Mon, 10 Feb 2020 09:59:17 -0700 Message-Id: <20200210165917.23193-3-kelsey.skunberg@canonical.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200210165917.23193-1-kelsey.skunberg@canonical.com> References: <20200210165917.23193-1-kelsey.skunberg@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Nicolas Dichtel BugLink: https://bugs.launchpad.net/bugs/1860969 With an ebpf program that redirects packets through a xfrm interface, packets are dropped because no dst is attached to skb. This could also be reproduced with an AF_PACKET socket, with the following python script (xfrm1 is a xfrm 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, ('xfrm1', 0x800, 0, 0)) It was also not possible to send an ip packet through an AF_PACKET socket because a LL header was expected. Let's remove those LL header constraints. Signed-off-by: Nicolas Dichtel Signed-off-by: Steffen Klassert (cherry picked from commit f042365dbffea98fb8148c98c700402e8d099f02) Signed-off-by: Kelsey Skunberg --- net/xfrm/xfrm_interface.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/net/xfrm/xfrm_interface.c b/net/xfrm/xfrm_interface.c index 2ab4859df55a..6809b96714e5 100644 --- a/net/xfrm/xfrm_interface.c +++ b/net/xfrm/xfrm_interface.c @@ -268,9 +268,6 @@ xfrmi_xmit2(struct sk_buff *skb, struct net_device *dev, struct flowi *fl) int err = -1; int mtu; - if (!dst) - goto tx_err_link_failure; - dst_hold(dst); dst = xfrm_lookup_with_ifid(xi->net, dst, fl, NULL, 0, xi->p.if_id); if (IS_ERR(dst)) { @@ -343,6 +340,7 @@ static netdev_tx_t xfrmi_xmit(struct sk_buff *skb, struct net_device *dev) { struct xfrm_if *xi = netdev_priv(dev); struct net_device_stats *stats = &xi->dev->stats; + struct dst_entry *dst = skb_dst(skb); struct flowi fl; int ret; @@ -352,10 +350,33 @@ static netdev_tx_t xfrmi_xmit(struct sk_buff *skb, struct net_device *dev) case htons(ETH_P_IPV6): xfrm_decode_session(skb, &fl, AF_INET6); memset(IP6CB(skb), 0, sizeof(*IP6CB(skb))); + 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); + stats->tx_carrier_errors++; + goto tx_err; + } + skb_dst_set(skb, dst); + } break; case htons(ETH_P_IP): xfrm_decode_session(skb, &fl, AF_INET); memset(IPCB(skb), 0, sizeof(*IPCB(skb))); + if (!dst) { + 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)) { + stats->tx_carrier_errors++; + goto tx_err; + } + skb_dst_set(skb, &rt->dst); + } break; default: goto tx_err; @@ -563,12 +584,9 @@ static void xfrmi_dev_setup(struct net_device *dev) { dev->netdev_ops = &xfrmi_netdev_ops; dev->type = ARPHRD_NONE; - dev->hard_header_len = ETH_HLEN; - dev->min_header_len = ETH_HLEN; dev->mtu = ETH_DATA_LEN; dev->min_mtu = ETH_MIN_MTU; - dev->max_mtu = ETH_DATA_LEN; - dev->addr_len = ETH_ALEN; + dev->max_mtu = IP_MAX_MTU; dev->flags = IFF_NOARP; dev->needs_free_netdev = true; dev->priv_destructor = xfrmi_dev_free;