Skip to contentSkip to conversation

bonding: add rtnl lock for bonding_store_xmit_hash

PATCH In review Ding Tianhong 2 participants 3 messages Aug 28, 2013 – Aug 30, 2013

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

PATCH 3/5 bonding: add rtnl lock for bonding_store_xmit_hash

The bonding_store_xmit_hash() call bond_set_mode_ops() to set bond xmit_policy, the xmit_policy is used in xmit path for xor mode, so any changes may occur problem without protection, add rtnl lock is fit here.

---
 drivers/net/bonding/bond_sysfs.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/bonding/bond_sysfs.c +4 -0
index 0f539de..deb1d8e 100644
@@ -382,6 +382,9 @@ static ssize_t bonding_store_xmit_hash(struct device *d,
 	int new_value, ret = count;
 	struct bonding *bond = to_bond(d);
 
+	if (!rtnl_trylock())
+		return restart_syscall();
+
 	new_value = bond_parse_parm(buf, xmit_hashtype_tbl);
 	if (new_value < 0)  {
 		pr_err("%s: Ignoring invalid xmit hash policy value %.*s.\n",
@@ -396,6 +399,7 @@ static ssize_t bonding_store_xmit_hash(struct device *d,
 			xmit_hashtype_tbl[new_value].modename, new_value);
 	}
 
+	rtnl_unlock();
 	return ret;
 }
 static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR,
Signature · 1 line
1.8.2.1
#1 lore raw
Quoted 6 lines · Ding Tianhong

The bonding_store_xmit_hash() call bond_set_mode_ops() to set bond xmit_policy, the xmit_policy is used in xmit path for xor mode, so any changes may occur problem without protection, add rtnl lock is fit here.

---

I don't think we need any locking there, nothing bad can happen.

#2 lore raw
Quoted 11 lines · Nikolay Aleksandrov
Quoted 6 lines · Ding Tianhong

The bonding_store_xmit_hash() call bond_set_mode_ops() to set bond xmit_policy, the xmit_policy is used in xmit path for xor mode, so any changes may occur problem without protection, add rtnl lock is fit here.

---

I don't think we need any locking there, nothing bad can happen.

But I think bond->xmit_hash_policy need protect if write it, as the bond_3ad_xmit may use it, or did I miss something? :)