{"id":810677,"url":"http://patchwork.ozlabs.org/api/patches/810677/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/patch/150471158528.3727.12324542627400287360.stgit@firesoul/","project":{"id":7,"url":"http://patchwork.ozlabs.org/api/projects/7/?format=json","name":"Linux network development","link_name":"netdev","list_id":"netdev.vger.kernel.org","list_email":"netdev@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<150471158528.3727.12324542627400287360.stgit@firesoul>","list_archive_url":null,"date":"2017-09-06T15:26:25","name":"[net-next] xdp: implement xdp_redirect_map for generic XDP","commit_ref":null,"pull_url":null,"state":"changes-requested","archived":true,"hash":"8566919dbeaebb3b2dae26ea58ec9cbc87b3efe0","submitter":{"id":13625,"url":"http://patchwork.ozlabs.org/api/people/13625/?format=json","name":"Jesper Dangaard Brouer","email":"brouer@redhat.com"},"delegate":{"id":34,"url":"http://patchwork.ozlabs.org/api/users/34/?format=json","username":"davem","first_name":"David","last_name":"Miller","email":"davem@davemloft.net"},"mbox":"http://patchwork.ozlabs.org/project/netdev/patch/150471158528.3727.12324542627400287360.stgit@firesoul/mbox/","series":[{"id":1836,"url":"http://patchwork.ozlabs.org/api/series/1836/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/list/?series=1836","date":"2017-09-06T15:26:25","name":"[net-next] xdp: implement xdp_redirect_map for generic XDP","version":1,"mbox":"http://patchwork.ozlabs.org/series/1836/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/810677/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/810677/checks/","tags":{},"related":[],"headers":{"Return-Path":"<netdev-owner@vger.kernel.org>","X-Original-To":"patchwork-incoming@ozlabs.org","Delivered-To":"patchwork-incoming@ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=netdev-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","ext-mx01.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx01.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=brouer@redhat.com"],"Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xnS9Y6TXGz9s03\n\tfor <patchwork-incoming@ozlabs.org>;\n\tThu,  7 Sep 2017 01:26:41 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S932864AbdIFP0j (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tWed, 6 Sep 2017 11:26:39 -0400","from mx1.redhat.com ([209.132.183.28]:52908 \"EHLO mx1.redhat.com\"\n\trhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S932263AbdIFP0h (ORCPT <rfc822;netdev@vger.kernel.org>);\n\tWed, 6 Sep 2017 11:26:37 -0400","from smtp.corp.redhat.com\n\t(int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id E686581E00;\n\tWed,  6 Sep 2017 15:26:36 +0000 (UTC)","from firesoul.localdomain (ovpn-200-42.brq.redhat.com\n\t[10.40.200.42])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id A39C18780D;\n\tWed,  6 Sep 2017 15:26:26 +0000 (UTC)","from [192.168.5.1] (localhost [IPv6:::1])\n\tby firesoul.localdomain (Postfix) with ESMTP id 5F4393073EC87;\n\tWed,  6 Sep 2017 17:26:25 +0200 (CEST)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com E686581E00","Subject":"[PATCH net-next] xdp: implement xdp_redirect_map for generic XDP","From":"Jesper Dangaard Brouer <brouer@redhat.com>","To":"netdev@vger.kernel.org, \"David S. Miller\" <davem@davemloft.net>","Cc":"John Fastabend <john.fastabend@gmail.com>,\n\tAndy Gospodarek <andy@greyhouse.net>,\n\tJesper Dangaard Brouer <brouer@redhat.com>","Date":"Wed, 06 Sep 2017 17:26:25 +0200","Message-ID":"<150471158528.3727.12324542627400287360.stgit@firesoul>","User-Agent":"StGit/0.17.1-dirty","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"7bit","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.15","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.25]);\n\tWed, 06 Sep 2017 15:26:37 +0000 (UTC)","Sender":"netdev-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<netdev.vger.kernel.org>","X-Mailing-List":"netdev@vger.kernel.org"},"content":"Using bpf_redirect_map is allowed for generic XDP programs, but the\nappropriate map lookup was never performed in xdp_do_generic_redirect().\n\nInstead the map-index is directly used as the ifindex.  For the\nxdp_redirect_map sample in SKB-mode '-S', this resulted in trying\nsending on ifindex 0 which isn't valid, resulting in getting SKB\npackets dropped.  Thus, the reported performance numbers are wrong in\ncommit 24251c264798 (\"samples/bpf: add option for native and skb mode\nfor redirect apps\") for the 'xdp_redirect_map -S' case.\n\nIt might seem innocent this was lacking, but it can actually crash the\nkernel.  The potential crash is caused by not consuming redirect_info->map.\nThe bpf_redirect_map helper will set this_cpu_ptr(&redirect_info)->map\npointer, which will survive even after unloading the xdp bpf_prog and\ndeallocating the devmap data-structure.  This leaves a dead map\npointer around.  The kernel will crash when loading the xdp_redirect\nsample (in native XDP mode) as it doesn't reset map (via bpf_redirect)\nand returns XDP_REDIRECT, which will cause it to dereference the map\npointer.\n\nFixes: 6103aa96ec07 (\"net: implement XDP_REDIRECT for xdp generic\")\nFixes: 24251c264798 (\"samples/bpf: add option for native and skb mode for redirect apps\")\nSigned-off-by: Jesper Dangaard Brouer <brouer@redhat.com>\n---\n net/core/filter.c |   29 +++++++++++++++++++++++++++++\n 1 file changed, 29 insertions(+)","diff":"diff --git a/net/core/filter.c b/net/core/filter.c\nindex 5912c738a7b2..6a4745bf2c9f 100644\n--- a/net/core/filter.c\n+++ b/net/core/filter.c\n@@ -2562,6 +2562,32 @@ int xdp_do_redirect(struct net_device *dev, struct xdp_buff *xdp,\n }\n EXPORT_SYMBOL_GPL(xdp_do_redirect);\n \n+static int xdp_do_generic_redirect_map(struct net_device *dev,\n+\t\t\t\t       struct sk_buff *skb,\n+\t\t\t\t       struct bpf_prog *xdp_prog)\n+{\n+\tstruct redirect_info *ri = this_cpu_ptr(&redirect_info);\n+\tstruct bpf_map *map = ri->map;\n+\tu32 index = ri->ifindex;\n+\tstruct net_device *fwd;\n+\tint err;\n+\n+\tri->ifindex = 0;\n+\tri->map = NULL;\n+\n+\tfwd = __dev_map_lookup_elem(map, index);\n+\tif (!fwd) {\n+\t\terr = -EINVAL;\n+\t\tgoto err;\n+\t}\n+\tskb->dev = fwd;\n+\t_trace_xdp_redirect_map(dev, xdp_prog, fwd, map, index);\n+\treturn 0;\n+err:\n+\t_trace_xdp_redirect_map_err(dev, xdp_prog, fwd, map, index, err);\n+\treturn err;\n+}\n+\n int xdp_do_generic_redirect(struct net_device *dev, struct sk_buff *skb,\n \t\t\t    struct bpf_prog *xdp_prog)\n {\n@@ -2571,6 +2597,9 @@ int xdp_do_generic_redirect(struct net_device *dev, struct sk_buff *skb,\n \tunsigned int len;\n \tint err = 0;\n \n+\tif (ri->map)\n+\t\treturn xdp_do_generic_redirect_map(dev, skb, xdp_prog);\n+\n \tfwd = dev_get_by_index_rcu(dev_net(dev), index);\n \tri->ifindex = 0;\n \tif (unlikely(!fwd)) {\n","prefixes":["net-next"]}