From: David Miller Subject: Re: [Patch net] vlan: fix a use-after-free in vlan_device_event() Date: Sat, 11 Nov 2017 19:36:07 +0900 (KST) Message-ID: <20171111.193607.2008376633029594348.davem@davemloft.net> References: <20171110004313.20662-1-xiyou.wangcong@gmail.com> Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Cc: netdev@vger.kernel.org, fengguang.wu@intel.com, alexander.duyck@gmail.com, torvalds@linux-foundation.org, girish.moodalbail@oracle.com To: xiyou.wangcong@gmail.com Return-path: Received: from shards.monkeyblade.net ([184.105.139.130]:46588 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751413AbdKKKgK (ORCPT ); Sat, 11 Nov 2017 05:36:10 -0500 In-Reply-To: <20171110004313.20662-1-xiyou.wangcong@gmail.com> Sender: netdev-owner@vger.kernel.org List-ID: From: Cong Wang Date: Thu, 9 Nov 2017 16:43:13 -0800 > After refcnt reaches zero, vlan_vid_del() could free > dev->vlan_info via RCU: > > RCU_INIT_POINTER(dev->vlan_info, NULL); > call_rcu(&vlan_info->rcu, vlan_info_rcu_free); > > However, the pointer 'grp' still points to that memory > since it is set before vlan_vid_del(): > > vlan_info = rtnl_dereference(dev->vlan_info); > if (!vlan_info) > goto out; > grp = &vlan_info->grp; > > Depends on when that RCU callback is scheduled, we could > trigger a use-after-free in vlan_group_for_each_dev() > right following this vlan_vid_del(). > > Fix it by moving vlan_vid_del() before setting grp. This > is also symmetric to the vlan_vid_add() we call in > vlan_device_event(). > > Reported-by: Fengguang Wu > Fixes: efc73f4bbc23 ("net: Fix memory leak - vlan_info struct") > Cc: Alexander Duyck > Cc: Linus Torvalds > Cc: Girish Moodalbail > Signed-off-by: Cong Wang Applied and queued up for -stable, thanks Cong!