]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
bonding: Fix bonding crash
authorMahesh Bandewar <maheshb@google.com>
Fri, 2 Sep 2016 05:18:34 +0000 (22:18 -0700)
committerWilly Tarreau <w@1wt.eu>
Fri, 10 Feb 2017 10:03:47 +0000 (11:03 +0100)
commit 24b27fc4cdf9e10c5e79e5923b6b7c2c5c95096c upstream.

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: Mahesh Bandewar <maheshb@google.com>
Acked-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Willy Tarreau <w@1wt.eu>
drivers/net/bonding/bond_main.c
include/linux/netdevice.h
net/core/dev.c

index c0ed7c802819318f482acd35b51cb96a6405c435..ce41616d9d1a7b925f2f5e54ddf77a193e729fe3 100644 (file)
@@ -1565,9 +1565,10 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
                           bond_dev->name, slave_dev->name);
        }
 
-       /* already enslaved */
-       if (slave_dev->flags & IFF_SLAVE) {
-               pr_debug("Error, Device was already enslaved\n");
+       /* already in-use? */
+       if (netdev_is_rx_handler_busy(slave_dev)) {
+               netdev_err(bond_dev,
+                          "Error: Device is in use and cannot be enslaved\n");
                return -EBUSY;
        }
 
index 4d2e0418ab5adb9352cd609fdd5999bcb1f99c62..45a618b58864693015a0105c6f7ec4e0309f0d87 100644 (file)
@@ -2223,6 +2223,7 @@ static inline void napi_free_frags(struct napi_struct *napi)
        napi->skb = NULL;
 }
 
+bool netdev_is_rx_handler_busy(struct net_device *dev);
 extern int netdev_rx_handler_register(struct net_device *dev,
                                      rx_handler_func_t *rx_handler,
                                      void *rx_handler_data);
index 1ccfc49683b37b484d133c7ab178c66588ca3ca3..408f6eea2fbf09aa0705e3306f066e115ebe3093 100644 (file)
@@ -3345,6 +3345,22 @@ out:
 }
 #endif
 
+/**
+ *     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
  *     @dev: device to register a handler for