bonding: fix two race conditions in bond_store_updelay/downdelay
Subsystems (3)
PATCH 1/1 bonding: fix two race conditions in bond_store_updelay/downdelay
This patch fixes two race conditions between bond_store_updelay/downdelay and bond_store_miimon which could lead to division by zero as miimon can be set to 0 while either updelay/downdelay are being set and thus miss the zero check in the beginning, the zero div happens because updelay/downdelay are stored as new_value / bond->params.miimon. Use rtnl to synchronize with miimon setting.
--- drivers/net/bonding/bond_sysfs.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/bonding/bond_sysfs.c +6 -0
@@ -701,6 +701,8 @@ static ssize_t bonding_store_downdelay(struct device *d,int new_value, ret = count;struct bonding *bond =to_bond (d); +if (!rtnl_trylock ()) +return restart_syscall ();if (!(bond->params.miimon)) {pr_err ("%s: Unable to set down delay as MII monitoring is disabled\n" , bond->dev->name);
@@ -734,6 +736,7 @@ static ssize_t bonding_store_downdelay(struct device *d, } out: +rtnl_unlock ();return ret; } static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR,
@@ -756,6 +759,8 @@ static ssize_t bonding_store_updelay(struct device *d,int new_value, ret = count;struct bonding *bond =to_bond (d); +if (!rtnl_trylock ()) +return restart_syscall ();if (!(bond->params.miimon)) {pr_err ("%s: Unable to set up delay as MII monitoring is disabled\n" , bond->dev->name);
@@ -789,6 +794,7 @@ static ssize_t bonding_store_updelay(struct device *d, } out: +rtnl_unlock ();return ret; } static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR,
Signature · 1 line
1.8.1.4
Quoted 7 lines · Nikolay Aleksandrov
This patch fixes two race conditions between bond_store_updelay/downdelay and
bond_store_miimonwhich could lead to division by zero as miimon can be set to 0 while either updelay/downdelay are being set and thus miss the zero check in the beginning, the zero div happens because updelay/downdelay are stored asnew_value/bond->params.miimon. Use rtnl to synchronize with miimon setting.
Quoted 5 lines
CC Jay Vosburgh <[email protected]>CC Andy Gospodarek <[email protected]>CC Veaceslav Falico <[email protected]>Signed-off-by Nikolay Aleksandrov <[email protected]>---
A little addition: these can also race with anything that sets miimon to 0, currently beside store_miimon only store_arp_interval does that. But that is also fixed because store_arp_interval uses rtnl.
Cheers,
Nik
Quoted 6 lines · Nikolay Aleksandrov
This patch fixes two race conditions between bond_store_updelay/downdelay and
bond_store_miimonwhich could lead to division by zero as miimon can be set to 0 while either updelay/downdelay are being set and thus miss the zero check in the beginning, the zero div happens because updelay/downdelay are stored asnew_value/bond->params.miimon. Use rtnl to synchronize with miimon setting.
It seems a bit heavy duty to take rtnl for this.
Using ACCESS_ONCE() in bonding_store_updelay()/bonding_store_downdelay() should be enough ?
int miimon = ACCESS_ONCE(bond->params.miimon);
Quoted 13 lines · Eric Dumazet
Quoted 6 lines · Nikolay Aleksandrov
This patch fixes two race conditions between bond_store_updelay/downdelay and
bond_store_miimonwhich could lead to division by zero as miimon can be set to 0 while either updelay/downdelay are being set and thus miss the zero check in the beginning, the zero div happens because updelay/downdelay are stored asnew_value/bond->params.miimon. Use rtnl to synchronize with miimon setting.It seems a bit heavy duty to take rtnl for this.
Using
ACCESS_ONCE()in bonding_store_updelay()/bonding_store_downdelay() should be enough ?
Quoted 9 lines
int miimon =
ACCESS_ONCE(bond->params.miimon);--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Eric,
I thought about this version too, but downdelay/updelay can be changed in other places (e.g., store_miimon) and the resulting downdelay/updelay value might not be the right one.
Correct me if I'm wrong, but this is what I have in mind (miimon = 100, updelay = 200):
set miimon to 300 and concurrently set updelay to 400, we might endup leaving updelay to 400 because the old value of miimon is used in the calculation in store_updelay even though when changing miimon updelay/downdelay get adjusted, they might get adjusted by store_updelay/downdelay to a wrong value afterwards.
Nik
Quoted 9 lines · Nikolay Aleksandrov
I thought about this version too, but downdelay/updelay can be changed in other places (e.g.,
store_miimon) and the resulting downdelay/updelay value might not be the right one.
Correct me if I'm wrong, but this is what I have in mind (miimon = 100, updelay = 200):
set miimon to 300 and concurrently set updelay to 400, we might endup leaving updelay to 400 because the old value of miimon is used in the calculation instore_updelayeven though when changing miimon updelay/downdelay get adjusted, they might get adjusted by store_updelay/downdelay to a wrong value afterwards.
OK then ;)
Quoted 34 lines · Nikolay Aleksandrov
Quoted 13 lines · Eric Dumazet
Quoted 6 lines · Nikolay Aleksandrov
This patch fixes two race conditions between bond_store_updelay/downdelay and
bond_store_miimonwhich could lead to division by zero as miimon can be set to 0 while either updelay/downdelay are being set and thus miss the zero check in the beginning, the zero div happens because updelay/downdelay are stored asnew_value/bond->params.miimon. Use rtnl to synchronize with miimon setting.It seems a bit heavy duty to take rtnl for this.
Using
ACCESS_ONCE()in bonding_store_updelay()/bonding_store_downdelay() should be enough ?Quoted 9 lines
int miimon =
ACCESS_ONCE(bond->params.miimon);--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.htmlHi Eric,
I thought about this version too, but downdelay/updelay can be changed in other places (e.g.,store_miimon) and the resulting downdelay/updelay value might not be the right one.
Correct me if I'm wrong, but this is what I have in mind (miimon = 100, updelay = 200):
set miimon to 300 and concurrently set updelay to 400, we might endup leaving updelay to 400 because the old value of miimon is used in the calculation instore_updelayeven though when changing miimon updelay/downdelay get adjusted, they might get adjusted by store_updelay/downdelay to a wrong value afterwards.
Quoted 3 lines
Nik
agree, set miimon and set updelay may conflict.
Quoted 8 lines
--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 11 lines · Nikolay Aleksandrov
This patch fixes two race conditions between bond_store_updelay/downdelay and
bond_store_miimonwhich could lead to division by zero as miimon can be set to 0 while either updelay/downdelay are being set and thus miss the zero check in the beginning, the zero div happens because updelay/downdelay are stored asnew_value/bond->params.miimon. Use rtnl to synchronize with miimon setting.CC Jay Vosburgh <[email protected]>CC Andy Gospodarek <[email protected]>CC Veaceslav Falico <[email protected]>Signed-off-by Nikolay Aleksandrov <[email protected]>
Nice, thanks! :)
Quoted 45 lines
---
drivers/net/bonding/bond_sysfs.c| 6 ++++++1 file changed, 6 insertions(+)drivers/net/bonding/bond_sysfs.c +2
-0@@ -701,6 +701,8 @@ static ssize_t bonding_store_downdelay(struct device *d,int new_value, ret = count;struct bonding *bond =to_bond (d); +if (!rtnl_trylock ()) +return restart_syscall ();if (!(bond->params.miimon)) {pr_err ("%s: Unable to set down delay as MII monitoring is disabled\n" , bond->dev->name);@@ -734,6 +736,7 @@ static ssize_t bonding_store_downdelay(struct device *d, }out:
drivers/net/bonding/bond_sysfs.c +1
-0+rtnl_unlock ();return ret; }static DEVICE_ATTR(downdelay,
S_IRUGO|S_IWUSR,drivers/net/bonding/bond_sysfs.c +2
-0@@ -756,6 +759,8 @@ static ssize_t bonding_store_updelay(struct device *d,int new_value, ret = count;struct bonding *bond =to_bond (d); +if (!rtnl_trylock ()) +return restart_syscall ();if (!(bond->params.miimon)) {pr_err ("%s: Unable to set up delay as MII monitoring is disabled\n" , bond->dev->name);@@ -789,6 +794,7 @@ static ssize_t bonding_store_updelay(struct device *d, }out:
drivers/net/bonding/bond_sysfs.c +1
-0+rtnl_unlock ();return ret; }static DEVICE_ATTR(updelay,
S_IRUGO|S_IWUSR,Signature · 1 line
1.8.1.4
David Miller
maintainerFrom: Nikolay Aleksandrov <[email protected]>
Date: Wed, 13 Nov 2013 17:07:46 +0100
Quoted 11 lines
This patch fixes two race conditions between bond_store_updelay/downdelay and
bond_store_miimonwhich could lead to division by zero as miimon can be set to 0 while either updelay/downdelay are being set and thus miss the zero check in the beginning, the zero div happens because updelay/downdelay are stored asnew_value/bond->params.miimon. Use rtnl to synchronize with miimon setting.CC Jay Vosburgh <[email protected]>CC Andy Gospodarek <[email protected]>CC Veaceslav Falico <[email protected]>Signed-off-by Nikolay Aleksandrov <[email protected]>
Applied and queued up for -stable, thanks.