bonding: bond_slave_info_query() fix
Subsystems (3)
PATCH 1/1 bonding: bond_slave_info_query() fix
bond_slave_info_query() should keep a read lock while accessing slave info, or risk accessing stale data and corruption.
drivers/net/bonding/bond_main.c +8 -14
@@ -2213,33 +2213,27 @@ static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *in {struct bonding *bond =netdev_priv (bond_dev);struct slave *slave; -int i, found =0 ; +int i, ret = -ENODEV ; -if (info->slave_id <0 ) { +if (info->slave_id <0 )return -ENODEV ; - }read_lock (&bond->lock);bond_for_each_slave (bond, slave, i) {if (i == (int )info->slave_id) { - found =1 ; + ret =0 ; +strcpy (info->slave_name, slave->dev->name); + info->link = slave->link; + info->state = slave->state; + info->link_failure_count = slave->link_failure_count;break ; } }read_unlock (&bond->lock); -if (found) { -strcpy (info->slave_name, slave->dev->name); - info->link = slave->link; - info->state = slave->state; - info->link_failure_count = slave->link_failure_count; - }else { -return -ENODEV ; - } - -return 0 ; +return ret; }/*-------------------------------- Monitoring -------------------------------*/
Quoted 10 lines · Thu, Apr 23, 2009 at 01:24:07PM CEST, [email protected] wrote:
bond_slave_info_query()should keep a read lock while accessing slave info, or risk accessing stale data and corruption.Signed-off-by Eric Dumazet <[email protected]>drivers/net/bonding/bond_main.c +0
-0
drivers/net/bonding/bond_main.c static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *in · line 2219
Quoted 9 lines
drivers/net/bonding/bond_main.c +2
-2@@ -2213,33 +2213,27 @@ static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *in {struct bonding *bond =netdev_priv (bond_dev);struct slave *slave; -int i, found =0 ; +int i, ret = -ENODEV ; -if (info->slave_id <0 ) { +if (info->slave_id <0 )return -ENODEV ;
You can return ret; here since -ENODEV is there, but I don't know if it isn't against policy. Patch looks good anyway.
Quoted 36 lines
drivers/net/bonding/bond_main.c +6
-13- }read_lock (&bond->lock);bond_for_each_slave (bond, slave, i) {if (i == (int )info->slave_id) { - found =1 ; + ret =0 ; +strcpy (info->slave_name, slave->dev->name); + info->link = slave->link; + info->state = slave->state; + info->link_failure_count = slave->link_failure_count;break ; } }read_unlock (&bond->lock); -if (found) { -strcpy (info->slave_name, slave->dev->name); - info->link = slave->link; - info->state = slave->state; - info->link_failure_count = slave->link_failure_count; - }else { -return -ENODEV ; - } - -return 0 ; +return ret; }/*-------------------------------- Monitoring -------------------------------*/ --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 17 lines · Jiri Pirko
Quoted 16 lines · Thu, Apr 23, 2009 at 01:24:07PM CEST, [email protected] wrote:
bond_slave_info_query()should keep a read lock while accessing slave info, or risk accessing stale data and corruption.Signed-off-by Eric Dumazet <[email protected]>drivers/net/bonding/bond_main.c +1
-1@@ -2213,33 +2213,27 @@ static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *in {struct bonding *bond =netdev_priv (bond_dev);struct slave *slave; -int i, found =0 ; +int i, ret = -ENODEV ;
Quoted 7 lines
drivers/net/bonding/bond_main.c static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *in · line 2219
Quoted 3 lines
drivers/net/bonding/bond_main.c +1
-1-if (info->slave_id <0 ) { +if (info->slave_id <0 )return -ENODEV ;You can return ret; here since
-ENODEVis there, but I don't know if it isn't against policy. Patch looks good anyway.
Yes, we can just delete this extra test, since requested slave_id wont be found anyway if negative.
Thanks
[PATCH] bonding: bond_slave_info_query() fix
bond_slave_info_query() should keep a read lock while accessing slave info, or risk accessing stale data and corruption.
drivers/net/bonding/bond_main.c +7 -16
@@ -2213,33 +2213,24 @@ static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *in {struct bonding *bond =netdev_priv (bond_dev);struct slave *slave; -int i, found =0 ; - -if (info->slave_id <0 ) { -return -ENODEV ; - } +int i, res = -ENODEV ;read_lock (&bond->lock);bond_for_each_slave (bond, slave, i) {if (i == (int )info->slave_id) { - found =1 ; + res =0 ; +strcpy (info->slave_name, slave->dev->name); + info->link = slave->link; + info->state = slave->state; + info->link_failure_count = slave->link_failure_count;break ; } }read_unlock (&bond->lock); -if (found) { -strcpy (info->slave_name, slave->dev->name); - info->link = slave->link; - info->state = slave->state; - info->link_failure_count = slave->link_failure_count; - }else { -return -ENODEV ; - } - -return 0 ; +return res; }/*-------------------------------- Monitoring -------------------------------*/
Quoted 29 lines · Eric Dumazet
Quoted 17 lines · Jiri Pirko
Quoted 16 lines · Thu, Apr 23, 2009 at 01:24:07PM CEST, [email protected] wrote:
bond_slave_info_query()should keep a read lock while accessing slave info, or risk accessing stale data and corruption.Signed-off-by Eric Dumazet <[email protected]>drivers/net/bonding/bond_main.c +1
-1@@ -2213,33 +2213,27 @@ static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *in {struct bonding *bond =netdev_priv (bond_dev);struct slave *slave; -int i, found =0 ; +int i, ret = -ENODEV ;Quoted 7 lines
drivers/net/bonding/bond_main.c static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *in · line 2219
Quoted 3 lines
drivers/net/bonding/bond_main.c +1
-1-if (info->slave_id <0 ) { +if (info->slave_id <0 )return -ENODEV ;You can return ret; here since
-ENODEVis there, but I don't know if it isn't against policy. Patch looks good anyway.Yes, we can just delete this extra test, since requested
slave_idwont be found anyway if negative.
Quoted 6 lines
Thanks
[PATCH] bonding:
bond_slave_info_query()fix
bond_slave_info_query()should keep a read lock while accessing slave info, or risk accessing stale data and corruption.
I don't think that's actually true, since changes to the data
being referenced are (should be) protected by RTNL, and bond_slave_info_query runs via ioctl, and is holding RTNL.
Nevertheless, the patch does make the function cleaner, so I
have no objections.
-J
Quoted 49 lines
Signed-off-by Eric Dumazet <[email protected]>drivers/net/bonding/bond_main.c +7
-17@@ -2213,33 +2213,24 @@ static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *in {struct bonding *bond =netdev_priv (bond_dev);struct slave *slave; -int i, found =0 ; - -if (info->slave_id <0 ) { -return -ENODEV ; - } +int i, res = -ENODEV ;read_lock (&bond->lock);bond_for_each_slave (bond, slave, i) {if (i == (int )info->slave_id) { - found =1 ; + res =0 ; +strcpy (info->slave_name, slave->dev->name); + info->link = slave->link; + info->state = slave->state; + info->link_failure_count = slave->link_failure_count;break ; } }read_unlock (&bond->lock); -if (found) { -strcpy (info->slave_name, slave->dev->name); - info->link = slave->link; - info->state = slave->state; - info->link_failure_count = slave->link_failure_count; - }else { -return -ENODEV ; - } - -return 0 ; +return res; }/*-------------------------------- Monitoring -------------------------------*/ --
Quoted 3 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
---
-Jay Vosburgh, IBM Linux Technology Center, [email protected]
David Miller
maintainerFrom: Jay Vosburgh <[email protected]>
Date: Thu, 23 Apr 2009 07:51:36 -0700
Quoted 5 lines
Eric Dumazet <[email protected]> wrote:
Signed-off-by Jay Vosburgh <[email protected]>Quoted 1 line
Signed-off-by Eric Dumazet <[email protected]>
Aha, I'll apply this updated version instead, ignore my other email.
From: Eric Dumazet <[email protected]>
Date: Thu, 23 Apr 2009 13:24:07 +0200
Quoted 4 lines
bond_slave_info_query()should keep a read lock while accessing slave info, or risk accessing stale data and corruption.Signed-off-by Eric Dumazet <[email protected]>
Applied, thanks Eric.