From patchwork Thu Feb 7 20:27:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 1038337 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="LLi90dsm"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43wVHP0Fvzz9sMl for ; Fri, 8 Feb 2019 07:27:45 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727452AbfBGU1n (ORCPT ); Thu, 7 Feb 2019 15:27:43 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:39618 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726758AbfBGU1m (ORCPT ); Thu, 7 Feb 2019 15:27:42 -0500 Received: by mail-pf1-f196.google.com with SMTP id f132so479413pfa.6 for ; Thu, 07 Feb 2019 12:27:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=22UHhvGLX0Ghmq0nkDruX3BNbgQ0f7OuV5FzpdNnbeg=; b=LLi90dsmuid3d2OSb8SwKOLwcz8qfH15dywgcQVbWI2xtbZJYdw3sVkdQYkwpnUKIA FCLy1f1dzngAu72HeV7VU3k9ewv77qrClJ2lBsM8hh6c/xPsbGxQgYsMh8LLeb4fdWz2 YBzBmBCbXJ09E9C04tO1RpG/4mHGc3BT6wWoWAk6CdIq3pWlQSUMNkdmp0VsI6Yfxksk Zv8hnVaO90SRK9Iq+aewkl/fkz9HEJ0dGDmb/i5Qgcs0HplrX1CyjM80XFiDkp0rfQ9Y 8UZep+SkiIRTdBM/00W4K0uxGFAusKTiMs3SMNlnuqqZaAt6sJody+kAVUVHIEK8sDHm VWyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=22UHhvGLX0Ghmq0nkDruX3BNbgQ0f7OuV5FzpdNnbeg=; b=W3zd2ExtzDiEMBNa1V99aPXa7shfWXXyIQbAPRUWBMWMquNutKn8ZY8Wd21dtPhUwK SwTNg1nMDg0spsTgT0EPBNM+B8xW7VtiQGKmuIYedcaxBWPKdbXPxoKXtCiGX6Mo78uq EAunbma9VjBH7J5LaA8wgVBO9n7EC8kSHmdDkDHlecNYQAu0DoVap2KEtPNJ/I72fi7N 7qA0KU9+vvcJMKqoWoHDcuLi/KWdlY+jRs1RcSUD+AUmf4AylrCfBZY9B3MWhSmeeDAS GbQ6hO0yGj0wEnEvuct4Xzul8eOvf9zFLSwEwSZMQH4kYNOb4c8K71Qlx9DqQqB1bAgP dVtA== X-Gm-Message-State: AHQUAub0NJNSNisqYHeryr6FE13lCZYJBxhXiidlCeH1hyu4dZFplt/e 8OgUYfNwWIjqc+Mm/zbuYkFd5A== X-Google-Smtp-Source: AHgI3IZhp0XNRT2lpwNf8t1ZfisX17dSKbWs5Gw7hBaMA2S9YZ3sBx9OESm4v4mXbC93xn4K/KgS9w== X-Received: by 2002:a62:c21c:: with SMTP id l28mr17925901pfg.74.1549571261397; Thu, 07 Feb 2019 12:27:41 -0800 (PST) Received: from localhost ([2620:15c:2c4:201:f5a:7eca:440a:3ead]) by smtp.gmail.com with ESMTPSA id e63sm7434563pfc.47.2019.02.07.12.27.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Feb 2019 12:27:40 -0800 (PST) From: Eric Dumazet To: "David S . Miller" Cc: netdev , Eric Dumazet , Eric Dumazet , Petr Machata , Ido Schimmel , Roopa Prabhu , Stefano Brivio Subject: [PATCH net] vxlan: test dev->flags & IFF_UP before calling netif_rx() Date: Thu, 7 Feb 2019 12:27:38 -0800 Message-Id: <20190207202738.155940-1-edumazet@google.com> X-Mailer: git-send-email 2.20.1.791.gb4d0f1c61a-goog MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org netif_rx() must be called under a strict contract. At device dismantle phase, core networking clears IFF_UP and flush_all_backlogs() is called after rcu grace period to make sure no incoming packet might be in a cpu backlog and still referencing the device. Most drivers call netif_rx() from their interrupt handler, and since the interrupts are disabled at device dismantle, netif_rx() does not have to check dev->flags & IFF_UP Virtual drivers do not have this guarantee, and must therefore make the check themselves. Otherwise we risk use-after-free and/or crashes. Note this patch also fixes a small issue that came with commit ce6502a8f957 ("vxlan: fix a use after free in vxlan_encap_bypass"), since the dev->stats.rx_dropped change was done on the wrong device. Fixes: d342894c5d2f ("vxlan: virtual extensible lan") Fixes: ce6502a8f957 ("vxlan: fix a use after free in vxlan_encap_bypass") Signed-off-by: Eric Dumazet Cc: Petr Machata Cc: Ido Schimmel Cc: Roopa Prabhu Cc: Stefano Brivio --- drivers/net/vxlan.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c index 5209ee9aac47846367d7f469a7e69d08c030087e..2aae11feff0c22c1b073a6a119fc6c311cbe1691 100644 --- a/drivers/net/vxlan.c +++ b/drivers/net/vxlan.c @@ -2219,7 +2219,7 @@ static void vxlan_encap_bypass(struct sk_buff *skb, struct vxlan_dev *src_vxlan, struct pcpu_sw_netstats *tx_stats, *rx_stats; union vxlan_addr loopback; union vxlan_addr *remote_ip = &dst_vxlan->default_dst.remote_ip; - struct net_device *dev = skb->dev; + struct net_device *dev; int len = skb->len; tx_stats = this_cpu_ptr(src_vxlan->dev->tstats); @@ -2239,9 +2239,15 @@ static void vxlan_encap_bypass(struct sk_buff *skb, struct vxlan_dev *src_vxlan, #endif } + rcu_read_lock(); + dev = skb->dev; + if (unlikely(!(dev->flags & IFF_UP))) { + kfree_skb(skb); + goto drop; + } + if (dst_vxlan->cfg.flags & VXLAN_F_LEARN) - vxlan_snoop(skb->dev, &loopback, eth_hdr(skb)->h_source, 0, - vni); + vxlan_snoop(dev, &loopback, eth_hdr(skb)->h_source, 0, vni); u64_stats_update_begin(&tx_stats->syncp); tx_stats->tx_packets++; @@ -2254,8 +2260,10 @@ static void vxlan_encap_bypass(struct sk_buff *skb, struct vxlan_dev *src_vxlan, rx_stats->rx_bytes += len; u64_stats_update_end(&rx_stats->syncp); } else { +drop: dev->stats.rx_dropped++; } + rcu_read_unlock(); } static int encap_bypass_if_local(struct sk_buff *skb, struct net_device *dev,