From patchwork Fri Jul 29 02:50:07 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Roskin X-Patchwork-Id: 1018862 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p6T2oGDW006596 for ; Fri, 29 Jul 2011 02:50:16 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932108Ab1G2CuM (ORCPT ); Thu, 28 Jul 2011 22:50:12 -0400 Received: from c60.cesmail.net ([216.154.195.49]:55581 "EHLO c60.cesmail.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756154Ab1G2CuL (ORCPT ); Thu, 28 Jul 2011 22:50:11 -0400 Received: from unknown (HELO smtprelay1.cesmail.net) ([192.168.1.111]) by c60.cesmail.net with ESMTP; 28 Jul 2011 22:50:10 -0400 Received: from mj.roinet.com (static-72-92-88-10.phlapa.fios.verizon.net [72.92.88.10]) by smtprelay1.cesmail.net (Postfix) with ESMTPSA id 9186F34C93; Thu, 28 Jul 2011 22:55:02 -0400 (EDT) Subject: [PATCH] lib80211: call try_module_get() in lib80211_get_crypto_ops() To: linux-wireless@vger.kernel.org, "John W. Linville" From: Pavel Roskin Date: Thu, 28 Jul 2011 22:50:07 -0400 Message-ID: <20110729025007.7889.19879.stgit@mj.roinet.com> User-Agent: StGit/0.15-111-g507b MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Fri, 29 Jul 2011 02:50:17 +0000 (UTC) Doing it by the caller is racy. Some callers neglected to do so. Fix callers not to call try_module_get() after lib80211_get_crypto_ops(). When ops is copied, move lib80211_crypt_delayed_deinit() after try_module_get() to avoid the risk that the module would be unloaded between those calls. Signed-off-by: Pavel Roskin --- drivers/net/wireless/hostap/hostap_ioctl.c | 5 ++--- drivers/net/wireless/ipw2x00/libipw_wx.c | 6 +++--- net/wireless/lib80211.c | 3 +++ 3 files changed, 8 insertions(+), 6 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/net/wireless/hostap/hostap_ioctl.c b/drivers/net/wireless/hostap/hostap_ioctl.c index 12de464..af0516c 100644 --- a/drivers/net/wireless/hostap/hostap_ioctl.c +++ b/drivers/net/wireless/hostap/hostap_ioctl.c @@ -166,7 +166,7 @@ static int prism2_ioctl_siwencode(struct net_device *dev, request_module("lib80211_crypt_wep"); new_crypt->ops = lib80211_get_crypto_ops("WEP"); } - if (new_crypt->ops && try_module_get(new_crypt->ops->owner)) + if (new_crypt->ops) new_crypt->priv = new_crypt->ops->init(i); if (!new_crypt->ops || !new_crypt->priv) { kfree(new_crypt); @@ -3293,8 +3293,6 @@ static int prism2_ioctl_siwencodeext(struct net_device *dev, if (*crypt == NULL || (*crypt)->ops != ops) { struct lib80211_crypt_data *new_crypt; - lib80211_crypt_delayed_deinit(&local->crypt_info, crypt); - new_crypt = kzalloc(sizeof(struct lib80211_crypt_data), GFP_KERNEL); if (new_crypt == NULL) { @@ -3310,6 +3308,7 @@ static int prism2_ioctl_siwencodeext(struct net_device *dev, goto done; } + lib80211_crypt_delayed_deinit(&local->crypt_info, crypt); *crypt = new_crypt; } diff --git a/drivers/net/wireless/ipw2x00/libipw_wx.c b/drivers/net/wireless/ipw2x00/libipw_wx.c index d7bd6cf0..04c4a60 100644 --- a/drivers/net/wireless/ipw2x00/libipw_wx.c +++ b/drivers/net/wireless/ipw2x00/libipw_wx.c @@ -395,7 +395,7 @@ int libipw_wx_set_encode(struct libipw_device *ieee, new_crypt->ops = lib80211_get_crypto_ops("WEP"); } - if (new_crypt->ops && try_module_get(new_crypt->ops->owner)) + if (new_crypt->ops) new_crypt->priv = new_crypt->ops->init(key); if (!new_crypt->ops || !new_crypt->priv) { @@ -629,8 +629,6 @@ int libipw_wx_set_encodeext(struct libipw_device *ieee, if (*crypt == NULL || (*crypt)->ops != ops) { struct lib80211_crypt_data *new_crypt; - lib80211_crypt_delayed_deinit(&ieee->crypt_info, crypt); - new_crypt = kzalloc(sizeof(*new_crypt), GFP_KERNEL); if (new_crypt == NULL) { ret = -ENOMEM; @@ -644,6 +642,8 @@ int libipw_wx_set_encodeext(struct libipw_device *ieee, ret = -EINVAL; goto done; } + + lib80211_crypt_delayed_deinit(&ieee->crypt_info, crypt); *crypt = new_crypt; } diff --git a/net/wireless/lib80211.c b/net/wireless/lib80211.c index a55c27b..123fa19 100644 --- a/net/wireless/lib80211.c +++ b/net/wireless/lib80211.c @@ -242,6 +242,7 @@ struct lib80211_crypto_ops *lib80211_get_crypto_ops(const char *name) { struct lib80211_crypto_alg *alg; unsigned long flags; + struct lib80211_crypto_ops *ret = NULL; spin_lock_irqsave(&lib80211_crypto_lock, flags); list_for_each_entry(alg, &lib80211_crypto_algs, list) { @@ -252,6 +253,8 @@ struct lib80211_crypto_ops *lib80211_get_crypto_ops(const char *name) return NULL; found: + if (try_module_get(alg->ops->owner)) + ret = alg->ops; spin_unlock_irqrestore(&lib80211_crypto_lock, flags); return alg->ops; }