Skip to content

Commit

Permalink
bridge: fix use-after-free in br_cleanup_bridges()
Browse files Browse the repository at this point in the history
Unregistering a bridge device may cause virtual devices stacked on the
bridge, like vlan or macvlan devices, to be unregistered as well.
br_cleanup_bridges() uses for_each_netdev_safe() to iterate over all
devices during cleanup. This is not enough however, if one of the
additionally unregistered devices is next in the list to the bridge
device, it will get freed as well and the iteration continues on
the freed element.

Restart iteration after each bridge device removal from the beginning to
fix this, similar to what rtnl_link_unregister() does.

Signed-off-by: Patrick McHardy <kaber@trash.net>
Acked-by: Stephen Hemminger <shemminger@vyatta.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Patrick McHardy authored and David S. Miller committed Jul 3, 2008
1 parent 374e7b5 commit ab1b204
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions net/bridge/br_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,16 @@ int br_del_if(struct net_bridge *br, struct net_device *dev)

void __exit br_cleanup_bridges(void)
{
struct net_device *dev, *nxt;
struct net_device *dev;

rtnl_lock();
for_each_netdev_safe(&init_net, dev, nxt)
if (dev->priv_flags & IFF_EBRIDGE)
restart:
for_each_netdev(&init_net, dev) {
if (dev->priv_flags & IFF_EBRIDGE) {
del_br(dev->priv);
goto restart;
}
}
rtnl_unlock();

}

0 comments on commit ab1b204

Please sign in to comment.