Skip to contentSkip to conversation

mac80211: don't allow registering the same rate control twice

PATCH New Johannes Berg 1 participant 1 message Oct 28, 2007 mac80211

lore
Share & tools
lore

Johannes Berg

author maintainer
#0 lore raw

PATCH 1/1 mac80211: don't allow registering the same rate control twice

Previously, mac80211 would allow registering the same rate control algorithm twice. This is a programming error in the registration and should not happen; additionally the second version could never be selected. Disallow this and warn about it.

---
There could be potential for data corruption here when one algorithm is registered twice depending on how the algorithm code is written (it might only expect to be registered once), so I think this should be applied for 2.6.24.

 net/mac80211/ieee80211_rate.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
net/mac80211/ieee80211_rate.c +10 -1
@@ -28,13 +28,22 @@ int ieee80211_rate_control_register(stru
 	if (!ops->name)
 		return -EINVAL;
 
+	mutex_lock(&rate_ctrl_mutex);
+	list_for_each_entry(alg, &rate_ctrl_algs, list) {
+		if (!strcmp(alg->ops->name, ops->name)) {
+			/* don't register an algorithm twice */
+			WARN_ON(1);
+			return -EALREADY;
+		}
+	}
+
 	alg = kzalloc(sizeof(*alg), GFP_KERNEL);
 	if (alg == NULL) {
+		mutex_unlock(&rate_ctrl_mutex);
 		return -ENOMEM;
 	}
 	alg->ops = ops;
 
-	mutex_lock(&rate_ctrl_mutex);
 	list_add_tail(&alg->list, &rate_ctrl_algs);
 	mutex_unlock(&rate_ctrl_mutex);