Skip to contentSkip to conversation

wifi: rtl8xxxu/rtlwifi: validate action frame size

PATCH In review Ping-Ke Shih 1 participant 5 messages Apr 14 – Apr 29

Subsystems (2)
lore
Share & tools
lore

Ping-Ke Shih

author maintainer
#0 lore raw

cover wifi: rtl8xxxu/rtlwifi: validate action frame size

As mentioned by Johannes [1], some where of rtl8xxxu and rtlwifi check fields of action frame without checking size. Refine the code to check size by IEEE80211_MIN_ACTION_SIZE() before using.

[1] https://lore.kernel.org/linux-wireless/[email protected]/

Ping-Ke Shih (3):
wifi: rtl8xxxu: validate action frame size before using in
rtl8xxxu_dump_action()
wifi: rtlwifi: validate action frame size in rtl_action_proc()
wifi: rtlwifi: validate action frame size before using in

    _rtl_pci_tx_isr()
 drivers/net/wireless/realtek/rtl8xxxu/core.c | 13 +++++++++++--
 drivers/net/wireless/realtek/rtlwifi/base.c  | 17 ++++++++++-------
 drivers/net/wireless/realtek/rtlwifi/pci.c   |  7 ++++---
 3 files changed, 25 insertions(+), 12 deletions(-)

base-commit: fa489a77e3267e05df95db96ba98e141ec07cbd9

Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH 1/3 wifi: rtl8xxxu: validate action frame size before using in rtl8xxxu_dump_action()

The rtl8xxxu_dump_action() is to print action frames when turning on debug mask. Validate the skb->len size to prevent potential broken in monitor mode injection.

Compile tested only.

---
 drivers/net/wireless/realtek/rtl8xxxu/core.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/net/wireless/realtek/rtl8xxxu/core.c +11 -2
index f20fade0c099..508137e4a87a 100644
@@ -5126,7 +5126,7 @@ static void rtl8xxxu_tx_complete(struct urb *urb)
 }
 
 static void rtl8xxxu_dump_action(struct device *dev,
-				 struct ieee80211_hdr *hdr)
+				 struct ieee80211_hdr *hdr, unsigned int skb_len)
 {
 	struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)hdr;
 	u16 cap, timeout;
@@ -5134,8 +5134,14 @@ static void rtl8xxxu_dump_action(struct device *dev,
 	if (!(rtl8xxxu_debug & RTL8XXXU_DEBUG_ACTION))
 		return;
 
+	if (skb_len < IEEE80211_MIN_ACTION_SIZE(action_code))
+		return;
+
 	switch (mgmt->u.action.action_code) {
 	case WLAN_ACTION_ADDBA_RESP:
+		if (skb_len < IEEE80211_MIN_ACTION_SIZE(addba_resp))
+			break;
+
 		cap = le16_to_cpu(mgmt->u.action.addba_resp.capab);
 		timeout = le16_to_cpu(mgmt->u.action.addba_resp.timeout);
 		dev_info(dev, "WLAN_ACTION_ADDBA_RESP: "
@@ -5148,6 +5154,9 @@ static void rtl8xxxu_dump_action(struct device *dev,
 			 le16_to_cpu(mgmt->u.action.addba_resp.status));
 		break;
 	case WLAN_ACTION_ADDBA_REQ:
+		if (skb_len < IEEE80211_MIN_ACTION_SIZE(addba_req))
+			break;
+
 		cap = le16_to_cpu(mgmt->u.action.addba_req.capab);
 		timeout = le16_to_cpu(mgmt->u.action.addba_req.timeout);
 		dev_info(dev, "WLAN_ACTION_ADDBA_REQ: "
@@ -5437,7 +5446,7 @@ static void rtl8xxxu_tx(struct ieee80211_hw *hw,
 	}
 
 	if (ieee80211_is_action(hdr->frame_control))
-		rtl8xxxu_dump_action(dev, hdr);
+		rtl8xxxu_dump_action(dev, hdr, skb->len);
 
 	tx_info->rate_driver_data[0] = hw;
 
Signature · 1 line
2.25.1
author maintainer
#3 lore raw

PATCH 2/3 wifi: rtlwifi: validate action frame size in rtl_action_proc()

In reply to Ping-Ke Shih

Since action frames might be malformed from RX or injected TX, validate the size before using.

More, use struct ieee80211_mgmt to access fields of action frames instead of counting barely.

Tested with ping on RTL8723BE. The add BA request action frames of TX/RX can be handled properly.

---
 drivers/net/wireless/realtek/rtlwifi/base.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
drivers/net/wireless/realtek/rtlwifi/base.c +10 -7
index aad377864e73..9e98c01bb90e 100644
@@ -1369,18 +1369,19 @@ bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
 	struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
 	struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
 	struct rtl_priv *rtlpriv = rtl_priv(hw);
+	struct ieee80211_mgmt *mgmt;
 	__le16 fc = rtl_get_fc(skb);
-	u8 *act = (u8 *)(((u8 *)skb->data + MAC80211_3ADDR_LEN));
-	u8 category;
 
 	if (!ieee80211_is_action(fc))
 		return true;
 
-	category = *act;
-	act++;
-	switch (category) {
+	mgmt = (void *)skb->data;
+	if (skb->len < IEEE80211_MIN_ACTION_SIZE(action_code))
+		return true;
+
+	switch (mgmt->u.action.category) {
 	case ACT_CAT_BA:
-		switch (*act) {
+		switch (mgmt->u.action.action_code) {
 		case ACT_ADDBAREQ:
 			if (mac->act_scanning)
 				return false;
@@ -1394,9 +1395,11 @@ bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
 				struct ieee80211_sta *sta = NULL;
 				struct rtl_sta_info *sta_entry = NULL;
 				struct rtl_tid_data *tid_data;
-				struct ieee80211_mgmt *mgmt = (void *)skb->data;
 				u16 capab = 0, tid = 0;
 
+				if (skb->len < IEEE80211_MIN_ACTION_SIZE(addba_req))
+					return true;
+
 				rcu_read_lock();
 				sta = rtl_find_sta(hw, hdr->addr3);
 				if (sta == NULL) {
Signature · 1 line
2.25.1
author maintainer
#4 lore raw

PATCH 3/3 wifi: rtlwifi: validate action frame size before using in _rtl_pci_tx_isr()

In reply to Ping-Ke Shih

Since TX action frames might be malformed, validate the size before using.

Tested on RTL8723BE.

---
 drivers/net/wireless/realtek/rtlwifi/pci.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/wireless/realtek/rtlwifi/pci.c +4 -3
index 9cc0a871ea3c..73018a0498b4 100644
@@ -505,9 +505,10 @@ static void _rtl_pci_tx_isr(struct ieee80211_hw *hw, int prio)
 			}
 		}
 		if (ieee80211_is_action(fc)) {
-			struct ieee80211_mgmt *action_frame =
-				(struct ieee80211_mgmt *)skb->data;
-			if (action_frame->u.action.action_code ==
+			struct ieee80211_mgmt *action_frame = (void *)skb->data;
+
+			if (skb->len >= IEEE80211_MIN_ACTION_SIZE(action_code) &&
+			    action_frame->u.action.action_code ==
 			    WLAN_HT_ACTION_SMPS) {
 				dev_kfree_skb(skb);
 				goto tx_status_ok;
Signature · 1 line
2.25.1
author maintainer
#2 lore raw

Re: [PATCH rtw-next 1/3] wifi: rtl8xxxu: validate action frame size before using in rtl8xxxu_dump_action()

In reply to Ping-Ke Shih
Quoted 7 lines · Ping-Ke Shih

The rtl8xxxu_dump_action() is to print action frames when turning on debug mask. Validate the skb->len size to prevent potential broken in monitor mode injection.

Compile tested only.

3 patch(es) applied to rtw-next branch of rtw.git, thanks.

26769329c40a wifi: rtl8xxxu: validate action frame size before using in rtl8xxxu_dump_action() c9f10419c38e wifi: rtlwifi: validate action frame size in rtl_action_proc() 043f09bb78dd wifi: rtlwifi: validate action frame size before using in _rtl_pci_tx_isr()

---
https://github.com/pkshih/rtw.git