staging: rtl8723bs: fix null pointer deref in rtw_check_bcn_info
Subsystems (2)
PATCH 1/1 staging: rtl8723bs: fix null pointer deref in rtw_check_bcn_info
From: Luka Gejak <[email protected]>
When parsing beacon or probe response frames, if the ap does not provide a valid ssid ie, rtw_get_ie() returns NULL. The code then blindly performs a memcpy() using the returned NULL pointer (p + 2), resulting in a kernel oops or kernel panic due to a NULL pointer dereference.
Fix this by moving the memcpy() inside the if (p) block so it is only executed when a valid ssid ie is actually found.
--- drivers/staging/rtl8723bs/core/rtw_wlan_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8723bs/core/rtw_wlan_util.c +1 -1
@@ -1204,8 +1204,8 @@ int rtw_check_bcn_info(struct adapter *Adapter, u8 *pframe, u32 packet_len) ssid_len = *(p +1 );if (ssid_len >NDIS_802_11_LENGTH_SSID ) ssid_len =0 ; +memcpy (bssid->ssid.ssid, (p +2 ), ssid_len); } -memcpy (bssid->ssid.ssid, (p +2 ), ssid_len); bssid->ssid.ssid_length = ssid_len; if (memcmp(bssid->ssid.ssid, cur_network->network.ssid.ssid, 32) ||
Signature · 1 line
2.53.0
Quoted 22 lines · On Tue, Apr 14, 2026 at 10:55:20PM +0200, [email protected] wrote:
From: Luka Gejak <[email protected]>
When parsing beacon or probe response frames, if the ap does not provide a valid ssid ie,
rtw_get_ie()returns NULL. The code then blindly performs amemcpy()using the returned NULL pointer (p + 2), resulting in a kernel oops or kernel panic due to a NULL pointer dereference.Fix this by moving the
memcpy()inside the if (p) block so it is only executed when a valid ssid ie is actually found.Fixes 370730894bec ("Staging: rtl8723bs: rtw_wlan_util: Add size check of SSID IE")Signed-off-by Luka Gejak <[email protected]>--- drivers/staging/rtl8723bs/core/rtw_wlan_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/staging/rtl8723bs/core/rtw_wlan_util.c +0
-0
drivers/staging/rtl8723bs/core/rtw_wlan_util.c int rtw_check_bcn_info(struct adapter *Adapter, u8 *pframe, u32 packet_len) · line 1208
Quoted 6 lines
drivers/staging/rtl8723bs/core/rtw_wlan_util.c +1
-1@@ -1204,8 +1204,8 @@ int rtw_check_bcn_info(struct adapter *Adapter, u8 *pframe, u32 packet_len) ssid_len = *(p +1 );if (ssid_len >NDIS_802_11_LENGTH_SSID ) ssid_len =0 ; +memcpy (bssid->ssid.ssid, (p +2 ), ssid_len); } -memcpy (bssid->ssid.ssid, (p +2 ), ssid_len);
This isn't a bug. Doing an memcpy() of zero bytes is a no-op.
I think there might be an issue in user space where some of these functions functions are marked as not accepting NULL pointers. It leads to weirdness because the compiler starts making assumptions based on that and, for example, strips away all the subsequent NULL checks. But in the kernel it's fine.
Still this change does make the code more readable. Please, could you send the patch again with a commit message that explains that it is not a bugfix, only a cleanup and remove the Fixes tag.
regards,
dan carpenter