Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02F01C43381 for ; Sun, 10 Mar 2019 17:36:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B8F77206DF for ; Sun, 10 Mar 2019 17:36:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bmdpvVuB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726732AbfCJRgq (ORCPT ); Sun, 10 Mar 2019 13:36:46 -0400 Received: from mail-it1-f201.google.com ([209.85.166.201]:37721 "EHLO mail-it1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726668AbfCJRgp (ORCPT ); Sun, 10 Mar 2019 13:36:45 -0400 Received: by mail-it1-f201.google.com with SMTP id q141so3046739itc.2 for ; Sun, 10 Mar 2019 10:36:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=pjzCuURrUb/D6J0FcvBXOwkQ7oSE4qm4L3yw6w7BORc=; b=bmdpvVuBX93c6fPTD/UNRjTWT/O8vztyhjMEdU4nGiK83gbwaIIHFYY56sO396ihKG u1U82vMHeLc1iAKL/Z4FoXL4Uy2xjkp2XAkBdl37zYs/Sht4mvnuUGWsDhGohqBq64RG T9zBkz2pgRMx1GphTDI9FkifVR12ZC3PYMo3RNL+5K9YPFj5EnYWTOFlYeSCkKaT3NeU UduGF5CYoAELaSYsoevG5yWszbwwFTWs3U4SY8EdO7acrhPhEmFqBxg2ZZsDNKXqOpdx uAw+F4sjt1qf3uNKXY70GJ/m08o1DLdsxcmdDOOL6tcLEPKBoZAohGzzhAgYucJrJaPX vZVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=pjzCuURrUb/D6J0FcvBXOwkQ7oSE4qm4L3yw6w7BORc=; b=f7RL/XcIzWa06jIXZYsjvO1JCWKUzzIEryfGZqbPulp4q4RLCVYd3VNc5vjXA607dd iMJQ+IvNmP9bPgj0cikmAltoSQFHoDFKB04cWjb1k9aaH+anZGkVa8cIejHLnI1gFWEt t7aBYR1R/XuMNcJ5/bfYZvleyOS3h9UV1m5n8GfIYeJkQpgbzy3Sbos3wa82bmPnneP1 LqFa+xCXAjQj6cAaE/8HGZQ1cm/f/9RzqxAyiaFejDOwUg4KujDrJLSmqnPOTEDxLoZg RXu7qhIsUNIebkpXX9DCXXBkE4OKpNhgJiqP7jW/J/LMOw+O6ITvkM+olukFyskdfVnf z1og== X-Gm-Message-State: APjAAAVRzjfrUEr0U8qIPHWSg1V1eh1UqjSHBJK9jx8++OokdCj7nuuy oqv3Wi/YhSoSzYIJOXjrLl8u6b+6KR/tMA== X-Google-Smtp-Source: APXvYqyJNq4tvnsBlB4L0V7rmGD4Gd3EFx269KCCOx7Uvf7+GHS1Ksz8Ap8YgEcwtVbDRB38UDylmNiD+yej4g== X-Received: by 2002:a24:1c0c:: with SMTP id c12mr17914061itc.19.1552239404789; Sun, 10 Mar 2019 10:36:44 -0700 (PDT) Date: Sun, 10 Mar 2019 10:36:40 -0700 Message-Id: <20190310173640.54607-1-edumazet@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.21.0.360.g471c308f928-goog Subject: [PATCH net] vxlan: test dev->flags & IFF_UP before calling gro_cells_receive() From: Eric Dumazet To: "David S . Miller" Cc: netdev , Eric Dumazet , Eric Dumazet Content-Type: text/plain; charset="UTF-8" Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Same reasons than the ones explained in commit 4179cb5a4c92 ("vxlan: test dev->flags & IFF_UP before calling netif_rx()") netif_rx() or gro_cells_receive() 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. A similar protocol is used for gro_cells infrastructure, as gro_cells_destroy() will be called only after a full rcu grace period is observed after IFF_UP has been cleared. 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. Fixes: d342894c5d2f ("vxlan: virtual extensible lan") Signed-off-by: Eric Dumazet --- drivers/net/vxlan.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c index a3c46d78d216bf088545d7550170545c1771ab79..3d716790ebee4fc0bb3975c1720025688a109bbb 100644 --- a/drivers/net/vxlan.c +++ b/drivers/net/vxlan.c @@ -1731,6 +1731,14 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) goto drop; } + rcu_read_lock(); + + if (unlikely(!(vxlan->dev->flags & IFF_UP))) { + rcu_read_unlock(); + atomic_long_inc(&vxlan->dev->rx_dropped); + goto drop; + } + stats = this_cpu_ptr(vxlan->dev->tstats); u64_stats_update_begin(&stats->syncp); stats->rx_packets++; @@ -1738,6 +1746,9 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) u64_stats_update_end(&stats->syncp); gro_cells_receive(&vxlan->gro_cells, skb); + + rcu_read_unlock(); + return 0; drop: -- 2.21.0.360.g471c308f928-goog