Commit 24b27fc4 authored by Mahesh Bandewar's avatar Mahesh Bandewar Committed by David S. Miller

bonding: Fix bonding crash

Following few steps will crash kernel -

  (a) Create bonding master
      > modprobe bonding miimon=50
  (b) Create macvlan bridge on eth2
      > ip link add link eth2 dev mvl0 address aa:0:0:0:0:01 \
	   type macvlan
  (c) Now try adding eth2 into the bond
      > echo +eth2 > /sys/class/net/bond0/bonding/slaves
      <crash>

Bonding does lots of things before checking if the device enslaved is
busy or not.

In this case when the notifier call-chain sends notifications, the
bond_netdev_event() assumes that the rx_handler /rx_handler_data is
registered while the bond_enslave() hasn't progressed far enough to
register rx_handler for the new slave.

This patch adds a rx_handler check that can be performed right at the
beginning of the enslave code to avoid getting into this situation.
Signed-off-by: default avatarMahesh Bandewar <maheshb@google.com>
Acked-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 312565a0
...@@ -1341,9 +1341,10 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) ...@@ -1341,9 +1341,10 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
slave_dev->name); slave_dev->name);
} }
/* already enslaved */ /* already in-use? */
if (slave_dev->flags & IFF_SLAVE) { if (netdev_is_rx_handler_busy(slave_dev)) {
netdev_dbg(bond_dev, "Error: Device was already enslaved\n"); netdev_err(bond_dev,
"Error: Device is in use and cannot be enslaved\n");
return -EBUSY; return -EBUSY;
} }
......
...@@ -3267,6 +3267,7 @@ static inline void napi_free_frags(struct napi_struct *napi) ...@@ -3267,6 +3267,7 @@ static inline void napi_free_frags(struct napi_struct *napi)
napi->skb = NULL; napi->skb = NULL;
} }
bool netdev_is_rx_handler_busy(struct net_device *dev);
int netdev_rx_handler_register(struct net_device *dev, int netdev_rx_handler_register(struct net_device *dev,
rx_handler_func_t *rx_handler, rx_handler_func_t *rx_handler,
void *rx_handler_data); void *rx_handler_data);
......
...@@ -3974,6 +3974,22 @@ sch_handle_ingress(struct sk_buff *skb, struct packet_type **pt_prev, int *ret, ...@@ -3974,6 +3974,22 @@ sch_handle_ingress(struct sk_buff *skb, struct packet_type **pt_prev, int *ret,
return skb; return skb;
} }
/**
* netdev_is_rx_handler_busy - check if receive handler is registered
* @dev: device to check
*
* Check if a receive handler is already registered for a given device.
* Return true if there one.
*
* The caller must hold the rtnl_mutex.
*/
bool netdev_is_rx_handler_busy(struct net_device *dev)
{
ASSERT_RTNL();
return dev && rtnl_dereference(dev->rx_handler);
}
EXPORT_SYMBOL_GPL(netdev_is_rx_handler_busy);
/** /**
* netdev_rx_handler_register - register receive handler * netdev_rx_handler_register - register receive handler
* @dev: device to register a handler for * @dev: device to register a handler for
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment