diff mbox

bonding: disallow enslaving a bond to itself

Message ID 20140226172013.GA18145@midget.suse.cz
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Jiri Bohac Feb. 26, 2014, 5:20 p.m. UTC
Enslaving a bond to itself leads to an endless loop and hangs the kernel.

Signed-off-by: Jiri Bohac <jbohac@suse.cz>

Comments

Ding Tianhong Feb. 27, 2014, 1:30 a.m. UTC | #1
On 2014/2/27 1:20, Jiri Bohac wrote:
> Enslaving a bond to itself leads to an endless loop and hangs the kernel.
> 

Yes, I met the same problem.

Tested-by: Ding Tianhong <dingtianhong@huawei.com>

> Signed-off-by: Jiri Bohac <jbohac@suse.cz>
> 
> diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
> index 1c6104d..8f028ac 100644
> --- a/drivers/net/bonding/bond_main.c
> +++ b/drivers/net/bonding/bond_main.c
> @@ -1193,6 +1193,11 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
>  		return -EBUSY;
>  	}
>  
> +	if (bond_dev == slave_dev) {
> +		pr_err("%s: cannot enslave bond to itself.\n", bond_dev->name);
> +		return -EPERM;
> +	}
> +
>  	/* vlan challenged mutual exclusion */
>  	/* no need to lock since we're protected by rtnl_lock */
>  	if (slave_dev->features & NETIF_F_VLAN_CHALLENGED) {
> 


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller Feb. 27, 2014, 3:37 a.m. UTC | #2
From: Jiri Bohac <jbohac@suse.cz>
Date: Wed, 26 Feb 2014 18:20:13 +0100

> Enslaving a bond to itself leads to an endless loop and hangs the kernel.
> 
> Signed-off-by: Jiri Bohac <jbohac@suse.cz>

Applied, thank you.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 1c6104d..8f028ac 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1193,6 +1193,11 @@  int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
 		return -EBUSY;
 	}
 
+	if (bond_dev == slave_dev) {
+		pr_err("%s: cannot enslave bond to itself.\n", bond_dev->name);
+		return -EPERM;
+	}
+
 	/* vlan challenged mutual exclusion */
 	/* no need to lock since we're protected by rtnl_lock */
 	if (slave_dev->features & NETIF_F_VLAN_CHALLENGED) {