Skip to contentSkip to conversation

bonding: fix race condition in bonding_store_slaves_active

PATCH Superseded Nikolay Aleksandrov 3 participants 5 messages Nov 24, 2012 – Nov 29, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bonding: fix race condition in bonding_store_slaves_active

Race between bonding_store_slaves_active() and slave manipulation functions The bond_for_each_slave use in bonding_store_slaves_active() is not protected by any synchronization mechanism. NULL pointer dereference is easy to reach. Fixed by acquiring the bond->lock for the slave walk.

---
 drivers/net/bonding/bond_sysfs.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/bonding/bond_sysfs.c +2 -0
index ef8d2a0..ba4f95b 100644
@@ -1582,6 +1582,7 @@ static ssize_t bonding_store_slaves_active(struct device *d,
 		goto out;
 	}
 
+	read_lock(&bond->lock);
 	bond_for_each_slave(bond, slave, i) {
 		if (!bond_is_active_slave(slave)) {
 			if (new_value)
@@ -1590,6 +1591,7 @@ static ssize_t bonding_store_slaves_active(struct device *d,
 				slave->inactive = 1;
 		}
 	}
+	read_unlock(&bond->lock);
 out:
 	return ret;
 }
Signature · 1 line
1.7.11.7
maintainer
#1 lore raw

Some bonding developer reviews would be appreciated.

#2 lore raw

PATCH v2 1/1 bonding: fix race condition in bonding_store_slaves_active

In reply to Nikolay Aleksandrov

Race between bonding_store_slaves_active() and slave manipulation functions. The bond_for_each_slave use in bonding_store_slaves_active() is not protected by any synchronization mechanism.
NULL pointer dereference is easy to reach.
Fixed by acquiring the bond->lock for the slave walk.

v2: Make description text < 75 columns

---
 drivers/net/bonding/bond_sysfs.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/bonding/bond_sysfs.c +2 -0
index ef8d2a0..ba4f95b 100644
@@ -1582,6 +1582,7 @@ static ssize_t bonding_store_slaves_active(struct device *d,
 		goto out;
 	}
 
+	read_lock(&bond->lock);
 	bond_for_each_slave(bond, slave, i) {
 		if (!bond_is_active_slave(slave)) {
 			if (new_value)
@@ -1590,6 +1591,7 @@ static ssize_t bonding_store_slaves_active(struct device *d,
 				slave->inactive = 1;
 		}
 	}
+	read_unlock(&bond->lock);
 out:
 	return ret;
 }
Signature · 1 line
1.7.11.7
#3 lore raw
Quoted 9 lines · Nikolay Aleksandrov

Race between bonding_store_slaves_active() and slave manipulation functions. The bond_for_each_slave use in bonding_store_slaves_active() is not protected by any synchronization mechanism.
NULL pointer dereference is easy to reach.
Fixed by acquiring the bond->lock for the slave walk.

v2: Make description text < 75 columns

Quoted 27 lines

---
drivers/net/bonding/bond_sysfs.c | 2 ++

1 file changed, 2 insertions(+)
drivers/net/bonding/bond_sysfs.c +2 -0
index ef8d2a0..ba4f95b 100644
@@ -1582,6 +1582,7 @@ static ssize_t bonding_store_slaves_active(struct device *d,
 		goto out;
 	}
 
+	read_lock(&bond->lock);
 	bond_for_each_slave(bond, slave, i) {
 		if (!bond_is_active_slave(slave)) {
 			if (new_value)
@@ -1590,6 +1591,7 @@ static ssize_t bonding_store_slaves_active(struct device *d,
 				slave->inactive = 1;
 		}
 	}
+	read_unlock(&bond->lock);

out:

	return ret;
}
Signature · 1 line
1.7.11.7
maintainer Applied
#4 lore raw

From: Jay Vosburgh <[email protected]>
Date: Thu, 29 Nov 2012 09:37:56 -0800

Quoted 8 lines
Quoted 6 lines · Nikolay Aleksandrov

Race between bonding_store_slaves_active() and slave manipulation functions. The bond_for_each_slave use in bonding_store_slaves_active() is not protected by any synchronization mechanism.
NULL pointer dereference is easy to reach.
Fixed by acquiring the bond->lock for the slave walk.

Quoted 5 lines
Quoted 3 lines

v2: Make description text < 75 columns

Applied.