Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp268896img; Mon, 18 Mar 2019 02:42:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqyS/R0uAxuZ+fjVulbY50Mp+7SifTqrbPjpgKhmdctiIxgRxOO4Av6uNLPSVdtU2Ak51fog X-Received: by 2002:a62:6f06:: with SMTP id k6mr18010692pfc.257.1552902168347; Mon, 18 Mar 2019 02:42:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552902168; cv=none; d=google.com; s=arc-20160816; b=yuF3xbEYTdrk/2ifcNyt4fpFsDhR9EAwWE0/PX0BnrhZp8vSOWLzh3BKN6UWxmzUl+ KOMdiwz9Y6xbM1sSDD3uVSuJFmm4SmjyeTQJ5dy77ic4Du5NENhkOp3/Bh3D39cXukSG iOIryg1Oc1AKQDnEdPK0Opzv+ETBCfgCJAlllDQ8XPM0NxWpYyLqtA8r2vPnnp0AXjOb BQrcnyi3PakTJeG9HRnS6s3WbYJZFuXgmsYJZ8IthZn29BUemqqkg8zcM70oza3W0IMz LvpN6dhSy3A0Ax1ppW/Tck6sh7zScO/quTtGjgGBBzZWJVPcMAY87XT4UWtFHmcT0uDk dTng== 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=eZ7n+HmLc00PAnVebeAI/yKNMYL1lILJftXeP4cJogk=; b=vl+WeNMtgb7Bk1Q9s2Dtfv0ACYyyWqqN4Gde3cSRN0ZAdBcwKRLL1ms/RN3K0T74Xc i+wSy29jToWXpd+Usukw12OYxTj2W0ziyom3SDu+8WFdjEb9xhUdy6PjsPXdFy2wWe3k u5nkOeqqVKoxxAAx6mJab6R55/wmN3SibrZ/KGFmNknt8MlOMkWIaLfk6pjgtNQRsYjR H63wS8wIkFqVJWeUfjnGD3wDdTCq3H7yCycHKEUKrP8vYid0jV9Wy6GTEWa5jIewwlVZ 9sOzTQo49wREmqxCLA32xbAQW0sQGp7j/qPoiKMp8IRu/681PevjVLqqSWIvHO+yJbgw nUyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VSBBO+ie; 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 o7si8683388pgh.273.2019.03.18.02.42.33; Mon, 18 Mar 2019 02:42:48 -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=VSBBO+ie; 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 S1729040AbfCRJew (ORCPT + 99 others); Mon, 18 Mar 2019 05:34:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:43192 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729050AbfCRJeq (ORCPT ); Mon, 18 Mar 2019 05:34:46 -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 7F59F214AF; Mon, 18 Mar 2019 09:34:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552901686; bh=livFhjSBHX6LsRYL/yz2GNpBcPfCGfx6Uu3tAb3Y79g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VSBBO+ie8GOPRns0sQhj/aK3DeUuJXM0KGs9J/vdonGVH+OYR6zb2a0+Lvg1uWxrv S6OaMZOe+AkHJ92F8R7X0mm2gl7dml629G2DyDVStomPKhWn13hjZKd2MsmKPM5d9D AT+b7JcKpVCr03eRa6KIIdwzZA8d6+64zXVi1+EE= 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.14 18/34] vxlan: test dev->flags & IFF_UP before calling gro_cells_receive() Date: Mon, 18 Mar 2019 10:25:42 +0100 Message-Id: <20190318084147.211002820@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190318084144.657740413@linuxfoundation.org> References: <20190318084144.657740413@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.14-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 @@ -1468,6 +1468,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++; @@ -1475,6 +1483,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: