]> git.itanic.dy.fi Git - linux-stable/commit
vlan: fix a use-after-free in vlan_device_event()
authorCong Wang <xiyou.wangcong@gmail.com>
Fri, 10 Nov 2017 00:43:13 +0000 (16:43 -0800)
committerBen Hutchings <ben@decadent.org.uk>
Mon, 1 Jan 2018 20:52:07 +0000 (20:52 +0000)
commit62350f3b6cf96d8a0f4f1eb352908e2bfa355739
tree42d3c56a5b8b226824c6a1ed754efcd221fefb2c
parentc6b9319fcd21883fdb3c366a176a24fe924571f2
vlan: fix a use-after-free in vlan_device_event()

commit 052d41c01b3a2e3371d66de569717353af489d63 upstream.

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 <fengguang.wu@intel.com>
Fixes: efc73f4bbc23 ("net: Fix memory leak - vlan_info struct")
Cc: Alexander Duyck <alexander.duyck@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Girish Moodalbail <girish.moodalbail@oracle.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Reviewed-by: Girish Moodalbail <girish.moodalbail@oracle.com>
Tested-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
[bwh: Backported to 3.16: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
net/8021q/vlan.c