Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp549627imp; Thu, 21 Feb 2019 06:40:08 -0800 (PST) X-Google-Smtp-Source: AHgI3IZ+jaGOXtrA3vP+QhzEb8RCtjHQYkvGSxulNc0zAsBLUoqSmpAX07Ebfp+AAMpYgkqy3g+8 X-Received: by 2002:a62:190e:: with SMTP id 14mr40516940pfz.70.1550760008303; Thu, 21 Feb 2019 06:40:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550760008; cv=none; d=google.com; s=arc-20160816; b=rOPCUd06R0svEVo6XTxkeR9yvli0v3YwShSSzDkkn59+aezGFDUgD8p+o8qN2djKjT I+4DIuauQs0LNsw9uKoqoXUNNiK9bgBLeQ8lpv4MzZjmu5AqEE6uwP8Kb0XTJZ5lW0gG r8fGWnnDJCQuSs/CeLEG0MW7VWfNi65HwxvNUuMo2vjQcBz5aJems8LHdFxXd5A9EAjS Q/jw03UGjxK2PNksOe4Jg5iTB0HeVSqt+eMhIBvG2Qjcx/RZZtdM1EkL1lu+sIoG3thh cIB24GiVcpr7nbYsEaRR7RTetoPJFyE4X2xl7dp1NBVYrjn4Zdk+OuhK9Eyb7In7gJVQ 8n0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=F7PyoBdPtnMqvbjPzu7SvoCowXWGS3wy9k4Z9yxe3uc=; b=MWLyAJlnJlkGx+jnN5VEzwxpU6qqLuT2nncrYt03P+8F8bezbAkvWSMxL9ivHQn47J 1NRD3rxja09mKdyPGGsjPhbD9cLXyigfo1Ps+yHaRLyKc13GoJ4Y2I2e9AuN6CUVo6sg 8ar5aGIRHZFaw04ZBfl/G4klQ3qqsJm3rCn/TB6GiJXpX76w0x2H1Ipo7LikVWncSSiY ometD/QdQMBwTB+ZxZwX0rVLQ2Jyz5iXwJjVBDHu+wt2JFYvhFZyf5oDU99DHkGJ6dGH vC0vfBOWy2cE/Dk8IXPY4ThGE3HK/RAFA6Db4IgvNZDvKiq7UETFVsDqv15rNwXotl3v KhwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lvCL3T+5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i12si17667982pgq.466.2019.02.21.06.39.52; Thu, 21 Feb 2019 06:40:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lvCL3T+5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728736AbfBUOin (ORCPT + 99 others); Thu, 21 Feb 2019 09:38:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:60502 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728726AbfBUOil (ORCPT ); Thu, 21 Feb 2019 09:38:41 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B6A1320838; Thu, 21 Feb 2019 14:38:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550759920; bh=ZhwsqaejxMh7z08mgr9RHI2muieFhaPI+kWgJLeqOaw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lvCL3T+53Ifo3HzN2fXU3/kNTx9MTljRyCdLM9NQzOGN0t8CAtcZD4eLzVFWVkxnu i+dFhWvaSLSdT8xNZ5wY/6TO2AdsB2QXG9QxHAkxYwIWmziCZojjNTta5gzhl62/ov K3px+HGgDEoHRa6VRf2gfQJPlTUjRiRw85QneMag= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Petr Machata , Ido Schimmel , Roopa Prabhu , Stefano Brivio , "David S. Miller" Subject: [PATCH 4.9 14/20] vxlan: test dev->flags & IFF_UP before calling netif_rx() Date: Thu, 21 Feb 2019 15:35:52 +0100 Message-Id: <20190221125243.778253549@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190221125242.153179182@linuxfoundation.org> References: <20190221125242.153179182@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet [ Upstream commit 4179cb5a4c924cd233eaadd081882425bc98f44e ] 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 Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/vxlan.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) --- a/drivers/net/vxlan.c +++ b/drivers/net/vxlan.c @@ -1911,7 +1911,7 @@ static void vxlan_encap_bypass(struct sk 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); @@ -1931,8 +1931,15 @@ static void vxlan_encap_bypass(struct sk #endif } + rcu_read_lock(); + dev = skb->dev; + if (unlikely(!(dev->flags & IFF_UP))) { + kfree_skb(skb); + goto drop; + } + if (dst_vxlan->flags & VXLAN_F_LEARN) - vxlan_snoop(skb->dev, &loopback, eth_hdr(skb)->h_source); + vxlan_snoop(dev, &loopback, eth_hdr(skb)->h_source); u64_stats_update_begin(&tx_stats->syncp); tx_stats->tx_packets++; @@ -1945,8 +1952,10 @@ static void vxlan_encap_bypass(struct sk rx_stats->rx_bytes += len; u64_stats_update_end(&rx_stats->syncp); } else { +drop: dev->stats.rx_dropped++; } + rcu_read_unlock(); } static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,