[PATCH v6] staging: rtl8723bs: fix heap buffer overflow in cfg80211_rtw_add_key()

From: Feng Ning

Date: Mon Apr 27 2026 - 07:18:45 EST


The cfg80211 framework allows userspace to specify a key sequence
counter (NL80211_KEY_SEQ) of up to 16 bytes via NL80211_CMD_NEW_KEY
netlink messages, but ieee_param.crypt.seq is a fixed 8-byte buffer.
When cfg80211_rtw_add_key() copies the sequence counter via memcpy()
without checking seq_len, a heap buffer overflow of up to 8 bytes
occurs, overwriting bytes following seq within the same ieee_param
structure (key_len and the trailing key[] flexible array).

Cap the copy length at the buffer size using min_t().

Reviewed-by: Luka Gejak <luka.gejak@xxxxxxxxx>
Fixes: 554c0a3abf21 ("staging: Add rtl8723bs sdio wifi driver")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Feng Ning <feng@xxxxxxxxx>
---
Changes v5 -> v6:
- Restore the changelog that was lost in v5 (per Greg KH feedback)
- Add Cc: stable@xxxxxxxxxxxxxxx (user-reachable heap overflow)
- Tighten wording about which fields are clobbered (avoid implying
a specific layout when padding may exist)
- No code changes from v5; v4..v6 are byte-identical at the code
level, so Luka Gejak's Reviewed-by from v4 is carried over

Changes v4 -> v5:
- Rebase onto staging-next (line numbers and surrounding hashes
refreshed; the hunk itself is unchanged)
- No code changes from v4

Changes v3 -> v4:
- Resend as plain text without PGP signature and public-key
attachment (per Luka Gejak feedback)
- No code changes from v3

Changes v2 -> v3:
- Move the changelog below the cut line (per gregkh patch-bot)
- No code changes from v2

Changes v1 -> v2:
- Reformat as a proper kernel patch with Fixes: tag and
Signed-off-by; address comments from the initial submission
- No code changes from v1

drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
index 7cb0c6f22..4fba53c2d 100644
--- a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
+++ b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
@@ -883,8 +883,11 @@ static int cfg80211_rtw_add_key(struct wiphy *wiphy, struct net_device *ndev,

param->u.crypt.idx = key_index;

- if (params->seq_len && params->seq)
- memcpy(param->u.crypt.seq, (u8 *)params->seq, params->seq_len);
+ if (params->seq_len && params->seq) {
+ size_t seq_copy = min_t(size_t, params->seq_len,
+ sizeof(param->u.crypt.seq));
+ memcpy(param->u.crypt.seq, (u8 *)params->seq, seq_copy);
+ }

if (params->key_len && params->key) {
param->u.crypt.key_len = params->key_len;
--
2.43.0