Commit ea6836dd authored by nikolay@redhat.com's avatar nikolay@redhat.com Committed by David S. Miller

bonding: fix set mode race conditions

Changing the mode without any locking can result in multiple races (e.g.
upping a bond, enslaving/releasing). Depending on which race is hit the
impact can vary from incosistent bond state to kernel crash.
Use RTNL to synchronize the mode setting with the dangerous races.
Signed-off-by: default avatarNikolay Aleksandrov <nikolay@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ff0102ee
...@@ -316,6 +316,9 @@ static ssize_t bonding_store_mode(struct device *d, ...@@ -316,6 +316,9 @@ static ssize_t bonding_store_mode(struct device *d,
int new_value, ret = count; int new_value, ret = count;
struct bonding *bond = to_bond(d); struct bonding *bond = to_bond(d);
if (!rtnl_trylock())
return restart_syscall();
if (bond->dev->flags & IFF_UP) { if (bond->dev->flags & IFF_UP) {
pr_err("unable to update mode of %s because interface is up.\n", pr_err("unable to update mode of %s because interface is up.\n",
bond->dev->name); bond->dev->name);
...@@ -352,6 +355,7 @@ static ssize_t bonding_store_mode(struct device *d, ...@@ -352,6 +355,7 @@ static ssize_t bonding_store_mode(struct device *d,
bond->dev->name, bond_mode_tbl[new_value].modename, bond->dev->name, bond_mode_tbl[new_value].modename,
new_value); new_value);
out: out:
rtnl_unlock();
return ret; return ret;
} }
static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
......
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