Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp266828img; Mon, 18 Mar 2019 02:39:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqwD3EmQ8580ql8keXzlbPCvFtrFbA0JPmqShLOk6Z2mmt+K/JSdGvtKLa9MyDO0UhAIn5X8 X-Received: by 2002:a65:50c8:: with SMTP id s8mr16714314pgp.308.1552901951509; Mon, 18 Mar 2019 02:39:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552901951; cv=none; d=google.com; s=arc-20160816; b=wRvVQb4TTsnYqinWoDAyqxVxeTYE10KxxeoZN7IFnQWmJHZAnQ+D0+Ax15LYKxb5bQ +w1RkLcRuO1ClA6w1y83FYt4yUCmP+Xht3LbSa7djb/bAvsC18JF4VV/F7H1sQgDcw3r dwIAoicuD6jsBA2mEpYwkARuQ4DZLMVEJ9rl23e/RQvrasljxi3gY7xshBUDeld1sROC c/jkRazaZLl9lNTJcaRPt/5llsO2Em06/yPIYBfegjIK9FzinGlivnMHcNP2fSBQon33 xSH2MmjhOKuuxbxz6/uR+b/BDgB3pv+vWWWQXNlh82o6gDk1nYz7jp16WlhKRi1BDjeT FK/A== 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=QiDiiAIGB149Hmgy723a2gnw/iFWiHrbCGKP+hm0P/M=; b=MG37ekb5cC5W/GA4LAE9JbPDJ53xxuaoDb/K0l1FOXys3LUKZYNbyPltOhhx9tqzss txyCG0rDN6JHTpFQL5nl2LCtqFvLoFSvlzOSYqlbahshM9JoerYY6J2BfGQXgVR913Fn F/5vD4BGOPHwZCHmdwq6t2YlAh6ROB3alcjufd3d96ZFkj5iu4IWkehqRZyU0Fj+LRos isJWOqGN9mpsXzNAxz8fNTT4o+OohoB4a+3O2ud9/x8ZT7QQiI49IGjvTf8ICQMdJcH1 ggoty19AUGlk2Xojj532gwRIePwlzv6CcDattZPNUeh9HkMzZ9ckGRkZfxhVD3UCjg/2 Q3lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Chshkrws; 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 h127si8509614pgc.407.2019.03.18.02.38.56; Mon, 18 Mar 2019 02:39:11 -0700 (PDT) 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=Chshkrws; 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 S2387661AbfCRJg0 (ORCPT + 99 others); Mon, 18 Mar 2019 05:36:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:44728 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387628AbfCRJgY (ORCPT ); Mon, 18 Mar 2019 05:36:24 -0400 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 B00252075C; Mon, 18 Mar 2019 09:36:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552901784; bh=nE4breZ1fDAjkkvVa23aW/Jw+X7zhpcL+uiLMazSm9s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Chshkrwshv2/1hG+ew8998ekEKpDesnYE+icdxracDjSesSbPRyrjo2ZyijmhGk/f 9E0vJyFQjN4vXt9ygtj1zf1JIl/uR47UClPwohDFddFaQfHcimw8Zaw60q/sVjjTyI iBXwa2PuSBujSlrtYnLuB2FEtYn6cJcUOpVU2GhU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , "David S. Miller" Subject: [PATCH 4.9 13/31] vxlan: test dev->flags & IFF_UP before calling gro_cells_receive() Date: Mon, 18 Mar 2019 10:25:48 +0100 Message-Id: <20190318084210.932034496@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190318084210.397476003@linuxfoundation.org> References: <20190318084210.397476003@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 59cbf56fcd98ba2a715b6e97c4e43f773f956393 ] 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 Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/vxlan.c | 11 +++++++++++ 1 file changed, 11 insertions(+) --- a/drivers/net/vxlan.c +++ b/drivers/net/vxlan.c @@ -1380,6 +1380,14 @@ static int vxlan_rcv(struct sock *sk, st 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++; @@ -1387,6 +1395,9 @@ static int vxlan_rcv(struct sock *sk, st u64_stats_update_end(&stats->syncp); gro_cells_receive(&vxlan->gro_cells, skb); + + rcu_read_unlock(); + return 0; drop: