Skip to content

Commit

Permalink
bonding: bond_slave_info_query() fix
Browse files Browse the repository at this point in the history
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 <dada1@cosmosbay.com>
Signed-off-by: Jay Vosburgh <fubar@us.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed May 1, 2009
1 parent 00b64f2 commit 689c96c
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions drivers/net/bonding/bond_main.c
Original file line number Diff line number Diff line change
@@ -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 -------------------------------*/

0 comments on commit 689c96c

Please sign in to comment.