Skip to contentSkip to conversation

wifi: aic: fix stack buffer overflow in aicbt_patch_info_unpack

RFC PATCH In review Tim Michals 2 participants 3 messages Aug 8 Networking drivers (wireless)

lore
Share & tools
lore
#0 lore raw

RFC PATCH v2 1/2 wifi: aic: fix stack buffer overflow in aicbt_patch_info_unpack

During hardware validation of the AIC8800D80 SDIO chipset on real silicon (Radxa Cubie A5E with Allwinner T527 SoC running Linux 7.1), unpacking the BT patch table (fw_patch_table_8800d80_u02.bin) caused a kernel stack protector panic:

  Kernel panic - not syncing: stack-protector: Kernel stack is corrupted
  in: aicbt_patch_trap_data_load+0xe4/0x110 [aic8800_bsp]

aicbt_patch_info_unpack() calculated copy length as:
patch_info->info_len * sizeof(uint32_t) * 2

When reading fw_patch_table_8800d80_u02.bin, info_len resulted in a memcpy size exceeding the remaining bounds of the stack-allocated struct struct aicbt_patch_info_t patch_info, overflowing by 4+ bytes.

Fix this by adding explicit bounds checking to memcpy in aicbt_patch_info_unpack(), capping copy_len to sizeof(struct aicbt_patch_info_t) - sizeof(patch_info->info_len).

---
 drivers/net/wireless/aic/aic8800_bsp/aic_bsp_driver.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/wireless/aic/aic8800_bsp/aic_bsp_driver.c +5 -1
index a1b2c3d..e4f5a6b 100644
@@ -1148,9 +1148,13 @@ int aicbt_patch_info_unpack(struct aicbt_patch_info_t *patch_info,
 		if (patch_info->info_len == 0)
 			return 0;
 
+		size_t copy_len = patch_info->info_len * sizeof(uint32_t) * 2;
+		size_t max_len = sizeof(struct aicbt_patch_info_t) - sizeof(patch_info->info_len);
+		if (copy_len > max_len)
+			copy_len = max_len;
 		memcpy(patch_info_array + sizeof(patch_info->info_len),
 		       head_t->data,
-		       patch_info->info_len * sizeof(uint32_t) * 2);
+		       copy_len);
 		AICWFDBG(LOGDEBUG, "%s adid_addrinf:%x addr_adid:%x \r\n", __func__,
 			 ((struct aicbt_patch_info_t *)patch_info_array)->adid_addrinf,
 			 ((struct aicbt_patch_info_t *)patch_info_array)->addr_adid);
Signature · 1 line
2.43.0
#1 lore raw

RFC PATCH v2 2/2 wifi: aic: update cfg80211 API compatibility for modern kernels

Fixes modern kernel API compilation differences in aic8800_fdrv:

1. netif_rx_ni was removed in Linux 5.18+. Provide compatibility macro
in rwnx_compat.h mapping to netif_rx.
2. cfg80211_probe_status parameter count was updated in Linux 6.0+.
Wrap cfg80211_probe_status invocation with LINUX_VERSION_CODE >= KERNEL_VERSION(6, 0, 0).
3. remain_on_channel callback signature in struct cfg80211_ops dropped rx_addr in Linux 6.5+. Wrap signature definition for Linux 6.5+.

---
 drivers/net/wireless/aic/aic8800_fdrv/rwnx_compat.h |  5 +++++
 drivers/net/wireless/aic/aic8800_fdrv/rwnx_main.c   | 20 ++++++++++++++++++++
 2 files changed, 25 insertions(+)
drivers/net/wireless/aic/aic8800_fdrv/rwnx_compat.h +6 -0
index b2c3d4e..f5e6d7c 100644
@@ -21,6 +21,11 @@
 #ifndef _RWNX_COMPAT_H_
 #define _RWNX_COMPAT_H_
 
+#include <linux/version.h>
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0)
+#ifndef netif_rx_ni
+#define netif_rx_ni netif_rx
+#endif
+#endif
 

/* CFG80211 */

drivers/net/wireless/aic/aic8800_fdrv/rwnx_main.c +20 -0
index c3d4e5f..a6b7c8d 100644
@@ -2824,12 +2824,22 @@ static void apm_probe_sta_work_process(struct work_struct *work)
 	if (found)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 0, 0)
+		cfg80211_probe_status(rwnx_vif->ndev, mac,
+				      (u64)rwnx_vif->sta_probe.probe_id,
+				      true, 0, false, GFP_ATOMIC);
+	else
+		cfg80211_probe_status(rwnx_vif->ndev, mac,
+				      (u64)rwnx_vif->sta_probe.probe_id,
+				      false, 0, false, GFP_ATOMIC);
+#else
 		cfg80211_probe_status(rwnx_vif->ndev, mac,
 				      (u64)rwnx_vif->sta_probe.probe_id, -1,
 				      true, 0, false, GFP_ATOMIC);
 	else
 		cfg80211_probe_status(rwnx_vif->ndev, mac,
 				      (u64)rwnx_vif->sta_probe.probe_id, -1,
 				      false, 0, false, GFP_ATOMIC);
+#endif
 	rwnx_vif->sta_probe.probe_id++;
 }
 
@@ -3463,6 +3473,16 @@ static int rwnx_cfg80211_remain_on_channel_(struct wiphy *wiphy,
 	return error;
 }
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0)
+static int rwnx_cfg80211_remain_on_channel(struct wiphy *wiphy,
+					   struct wireless_dev *wdev,
+					   struct ieee80211_channel *chan,
+					   unsigned int duration, u64 *cookie)
+{
+	return rwnx_cfg80211_remain_on_channel_(wiphy, wdev, chan,
+						duration, cookie, false);
+}
+#else
 static int rwnx_cfg80211_remain_on_channel(struct wiphy *wiphy,
 					   struct wireless_dev *wdev,
 					   struct ieee80211_channel *chan,
Signature · 1 line
2.43.0
maintainer
#2 lore raw
In reply to Tim Michals
Quoted 2 lines
 drivers/net/wireless/aic/aic8800_bsp/aic_bsp_driver.c | 6 +++++-

Please don't send patches upstream when the driver doesn't exist there.

johannes