Skip to contentSkip to conversation

mac80211: fix tx->skb NULL pointer dereference

PATCH Superseded Yoni Divinsky 2 participants 3 messages Jan 16, 2012 mac80211

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mac80211: fix tx->skb NULL pointer dereference

In function ieee80211_tx_h_encrypt the var info was initialized from tx->skb, since the fucntion is called after the function ieee80211_tx_h_fragment tx->skb is not valid anymore.

---
 net/mac80211/tx.c  |   10 +---------
 net/mac80211/wpa.c |   19 +++++++++++++++++++
 net/mac80211/wpa.h |    2 ++
 3 files changed, 22 insertions(+), 9 deletions(-)
net/mac80211/tx.c +1 -9
index edcd1c7..0a5558a 100644
@@ -1001,8 +1001,6 @@ ieee80211_tx_h_stats(struct ieee80211_tx_data *tx)
 static ieee80211_tx_result debug_noinline
 ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx)
 {
-	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
-
 	if (!tx->key)
 		return TX_CONTINUE;
 
@@ -1017,13 +1015,7 @@ ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx)
 	case WLAN_CIPHER_SUITE_AES_CMAC:
 		return ieee80211_crypto_aes_cmac_encrypt(tx);
 	default:
-		/* handle hw-only algorithm */
-		if (info->control.hw_key) {
-			ieee80211_tx_set_protected(tx);
-			return TX_CONTINUE;
-		}
-		break;
-
+		return ieee80211_crypto_default_encrypt(tx);
 	}
 
 	return TX_DROP;
net/mac80211/wpa.c +19 -0
index 93aab07..3fd65ec 100644
@@ -643,3 +643,22 @@ ieee80211_crypto_aes_cmac_decrypt(struct ieee80211_rx_data *rx)
 
 	return RX_CONTINUE;
 }
+
+ieee80211_tx_result
+ieee80211_crypto_default_encrypt(struct ieee80211_tx_data *tx)
+{
+	struct sk_buff *skb;
+	struct ieee80211_tx_info *info = NULL;
+
+	skb_queue_walk(&tx->skbs, skb) {
+		info  = IEEE80211_SKB_CB(skb);
+
+		/* handle hw-only algorithm */
+		if (info == NULL || !info->control.hw_key)
+			return TX_DROP;
+	}
+
+	ieee80211_tx_set_protected(tx);
+
+	return TX_CONTINUE;
+}
net/mac80211/wpa.h +2 -0
index baba060..9d6001a 100644
@@ -32,5 +32,7 @@ ieee80211_tx_result
 ieee80211_crypto_aes_cmac_encrypt(struct ieee80211_tx_data *tx);
 ieee80211_rx_result
 ieee80211_crypto_aes_cmac_decrypt(struct ieee80211_rx_data *rx);
+ieee80211_tx_result
+ieee80211_crypto_default_encrypt(struct ieee80211_tx_data *tx);
 
 #endif /* WPA_H */
Signature · 1 line
1.7.0.4
maintainer
#1 lore raw
Quoted 4 lines · Yoni Divinsky

In function ieee80211_tx_h_encrypt the var info was initialized from tx->skb, since the fucntion is called after the function ieee80211_tx_h_fragment tx->skb is not valid anymore.

Wow, that's quite a while ago, I guess nobody tests WAPI often? :-)

Quoted 11 lines
net/mac80211/tx.c +0 -2
@@ -1001,8 +1001,6 @@ ieee80211_tx_h_stats(struct ieee80211_tx_data *tx)
 static ieee80211_tx_result debug_noinline
 ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx)
 {
-	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
-
 	if (!tx->key)
 		return TX_CONTINUE;
 
@@ -1017,13 +1015,7 @@ ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx)
 	case WLAN_CIPHER_SUITE_AES_CMAC:

net/mac80211/tx.c ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx) · line 1018

Quoted 10 lines
net/mac80211/tx.c +1 -7
 		return ieee80211_crypto_aes_cmac_encrypt(tx);
 	default:
-		/* handle hw-only algorithm */
-		if (info->control.hw_key) {
-			ieee80211_tx_set_protected(tx);
-			return TX_CONTINUE;
-		}
-		break;
-
+		return ieee80211_crypto_default_encrypt(tx);

How about
ieee80211_require_hw_crypto() or something like that?

net/mac80211/wpa.c ieee80211_crypto_aes_cmac_decrypt(struct ieee80211_rx_data *rx) · line 658

Quoted 12 lines
net/mac80211/wpa.c +12 -0
+ieee80211_tx_result
+ieee80211_crypto_default_encrypt(struct ieee80211_tx_data *tx)
+{
+	struct sk_buff *skb;
+	struct ieee80211_tx_info *info = NULL;
+
+	skb_queue_walk(&tx->skbs, skb) {
+		info  = IEEE80211_SKB_CB(skb);
+
+		/* handle hw-only algorithm */
+		if (info == NULL || !info->control.hw_key)
+			return TX_DROP;

info == NULL can't happen

johannes

#2 lore raw
Quoted 7 lines · Johannes Berg
Quoted 4 lines · Yoni Divinsky

In function ieee80211_tx_h_encrypt the var info was initialized from tx->skb, since the fucntion is called after the function ieee80211_tx_h_fragment tx->skb is not valid anymore.

Wow, that's quite a while ago, I guess nobody tests WAPI often? :-)

Who said anything about WAPI ;-)

Quoted 10 lines
Quoted 10 lines
(quoted diff) +0 -0
@@ -1001,8 +1001,6 @@ ieee80211_tx_h_stats(struct ieee80211_tx_data *tx)

 static ieee80211_tx_result debug_noinline ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx)
 {
-     struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); -
      if (!tx->key)
              return TX_CONTINUE;

Quoted 15 lines
Quoted 4 lines
(quoted diff) +0 -0
@@ -1017,13 +1015,7 @@ ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx)

      case WLAN_CIPHER_SUITE_AES_CMAC:
              return ieee80211_crypto_aes_cmac_encrypt(tx); default:

Quoted 8 lines

-             /* handle hw-only algorithm */
-             if (info->control.hw_key) {
-                     ieee80211_tx_set_protected(tx);
-                     return TX_CONTINUE;
-             }
-             break;
-
+             return ieee80211_crypto_default_encrypt(tx);

How about
ieee80211_require_hw_crypto() or something like that?

To be consistent with the other encryptions I think it would be better to use something like: ieee80211_crypto_hw_encrypt(tx)

Quoted 15 lines

net/mac80211/wpa.c ieee80211_crypto_aes_cmac_decrypt(struct ieee80211_rx_data *rx) · line 658

Quoted 13 lines
net/mac80211/wpa.c +12 -0
+ieee80211_tx_result
+ieee80211_crypto_default_encrypt(struct ieee80211_tx_data *tx)
+{
+     struct sk_buff *skb;
+     struct ieee80211_tx_info *info = NULL;
+
+     skb_queue_walk(&tx->skbs, skb) {
+             info  = IEEE80211_SKB_CB(skb);
+
+             /* handle hw-only algorithm */
+             if (info == NULL || !info->control.hw_key)
+                     return TX_DROP;

info == NULL can't happen

I agree,

thanks,
Yoni

Quoted 3 lines

johannes