Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp548200imp; Thu, 21 Feb 2019 06:38:36 -0800 (PST) X-Google-Smtp-Source: AHgI3IZs/cY4bOei9UgPXvsY2gUPgIa8adoIyU6zyKmRgae9YAyP6EmD9lkX/+6B7SnPkSe4B7xb X-Received: by 2002:a63:2b03:: with SMTP id r3mr33615299pgr.1.1550759916712; Thu, 21 Feb 2019 06:38:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550759916; cv=none; d=google.com; s=arc-20160816; b=AbZxoko15TyXqBU+tXWa8/vjdqCgvPVhg+SyJu1z403o27hsNVNEE/suHJKnNvKD5Y x4ThdPJ8Vr+YgesYdsZ9RvfrTLu6uXiuNJCY3CJQCdaMYg1pVdiIp4h2UxBKRYe0V47H Ad/RiiN7e4wlK0pUbDjc6EGloZZ3zgc+YpPS1kPhWdMjg0h8KViTh/I8BEeEcjLSdlFl +XrJulMUOCBLwKt835uQNk5Fbz1/FCkzwdlDNclWwMbacx4DKHKIvbCw/+CeJwfpwedW 6NgV/+x8kdcLbGDsayHB/V2xTcLalc7inPj9U3HQWpNPG1c3ulbT4z7QWB1+rjf89OfC TKQw== 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=vpiZY6ROBEqcZkHuRHd50O9B8RCEi+lDgGSTBHF/gUQ=; b=xOfOYzpaI2t8Nbf8N0iAW9/zbMX7xkw5JMi8yKs0UfVEG09LxQaroytZCh43Rvpmng NrVEEPkXJ0r1kkIGrZ0aBlk5w8PpsXNDBFSIo0KnAnw+HBj5OQhFfZRbIY2u4NwhkFEM OxTeSc3UFI0CmbdBXaxz9BknGTX3M1sLQnG0yve1IYmkOwfc4VjKbuMaHn/WD3qVnh66 yXiGrVJMEQJAluC4o+2u+Hw9Eo0A3KGrtvn6pFfwDtZB7v+CaodRuHHOY955stAN5lgy zm7vkkQzVNy7HaYYZMJ4r9apr5vjapTFMk4r4F61ET0lAWnvZHQcB2CiIQ98LNA2Y1KV g7Sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=K7W1Lz1f; 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 y15si21055306pgf.321.2019.02.21.06.38.21; Thu, 21 Feb 2019 06:38:36 -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=K7W1Lz1f; 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 S1728390AbfBUOh0 (ORCPT + 99 others); Thu, 21 Feb 2019 09:37:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:58624 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728356AbfBUOhZ (ORCPT ); Thu, 21 Feb 2019 09:37:25 -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 4E2302085A; Thu, 21 Feb 2019 14:37:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550759844; bh=QQ5R2pIoxrA19gUXJMZM7SLzk//he0yyApi/ldr3pnU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K7W1Lz1fGXS+tC7kD2Fy6yQZ6LpV9LjJeLwrHl/s0401o6feE6tOgPYfi+WgcsUk1 LuS6SlYEB6clW4CZu95G9RXQ57Eq8txT6huJCoBzOA0ZyQbJhIhm/s++r7onYoN/cS MXQ3q2wjKlks7dieNS0z8kqdyAoAGGAuPJS9Q4gE= 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.4 10/20] vxlan: test dev->flags & IFF_UP before calling netif_rx() Date: Thu, 21 Feb 2019 15:35:40 +0100 Message-Id: <20190221141947.068191226@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190221141946.772985220@linuxfoundation.org> References: <20190221141946.772985220@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.4-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 @@ -1881,7 +1881,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); @@ -1901,8 +1901,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++; @@ -1915,8 +1922,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,