Skip to contentSkip to conversation

wifi: rtw89: mcc: prevent shift wrapping in rtw89_core_mlsr_switch()

PATCH Superseded Dan Carpenter 2 participants 4 messages May 27, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wifi: rtw89: mcc: prevent shift wrapping in rtw89_core_mlsr_switch()

The "link_id" value comes from the user via debugfs. If it's larger than BITS_PER_LONG then that would result in shift wrapping and potentially an out of bounds access later. Fortunately, only root can write to debugfs files so the security impact is minimal.

Fixes 9dd85e739ce0 ("wifi: rtw89: debug: add mlo_mode dbgfs")

---

---
 drivers/net/wireless/realtek/rtw89/core.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/wireless/realtek/rtw89/core.c +3 -0
index 49447668cbf3..7e5f87700941 100644
@@ -5239,6 +5239,9 @@ int rtw89_core_mlsr_switch(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif,
 	if (unlikely(!ieee80211_vif_is_mld(vif)))
 		return -EOPNOTSUPP;
 
+	if (unlikely(link_id >= BITS_PER_LONG))
+		return -EINVAL;
+
 	if (unlikely(!(usable_links & BIT(link_id)))) {
 		rtw89_warn(rtwdev, "%s: link id %u is not usable\n", __func__,
 			   link_id);
Signature · 1 line
2.47.2
#1 lore raw
Quoted 5 lines · Dan Carpenter

The "link_id" value comes from the user via debugfs. If it's larger than BITS_PER_LONG then that would result in shift wrapping and potentially an out of bounds access later. Fortunately, only root can write to debugfs files so the security impact is minimal.

Thank you for catching this problem.

drivers/net/wireless/realtek/rtw89/core.c int rtw89_core_mlsr_switch(struct rtw89_dev *rtwdev, struct · line 5245

Quoted 11 lines

[...]

drivers/net/wireless/realtek/rtw89/core.c +3 -0
@@ -5239,6 +5239,9 @@ int rtw89_core_mlsr_switch(struct rtw89_dev *rtwdev, struct
 rtw89_vif *rtwvif,
        if (unlikely(!ieee80211_vif_is_mld(vif)))
                return -EOPNOTSUPP;
 
+       if (unlikely(link_id >= BITS_PER_LONG))
+               return -EINVAL;
+

Since I think this problem only comes from dbgfs path, would you like to just add a check in debug.c ?

For example,
(based on 0 <= valid link id < IEEE80211_MLD_MAX_NUM_LINKS < BITS_PER_LONG)

rtw89_debug_priv_mlo_mode_set(...)

{
        ...
        switch (mlo_mode) {
        case RTW89_MLO_MODE_MLSR:
               if (argv >= IEEE80211_MLD_MAX_NUM_LINKS)
                       return -EINVAL;
                ...
Quoted 5 lines
drivers/net/wireless/realtek/rtw89/core.c +0 -0
        if (unlikely(!(usable_links & BIT(link_id)))) {
                rtw89_warn(rtwdev, "%s: link id %u is not usable\n", __func__,
                           link_id);

--
2.47.2

#2 lore raw
Quoted 26 lines · Zong-Zhe Yang
Quoted 5 lines · Dan Carpenter

The "link_id" value comes from the user via debugfs. If it's larger than BITS_PER_LONG then that would result in shift wrapping and potentially an out of bounds access later. Fortunately, only root can write to debugfs files so the security impact is minimal.

Thank you for catching this problem.

drivers/net/wireless/realtek/rtw89/core.c int rtw89_core_mlsr_switch(struct rtw89_dev *rtwdev, struct · line 5245

Quoted 11 lines

[...]

drivers/net/wireless/realtek/rtw89/core.c +3 -0
@@ -5239,6 +5239,9 @@ int rtw89_core_mlsr_switch(struct rtw89_dev *rtwdev, struct
 rtw89_vif *rtwvif,
        if (unlikely(!ieee80211_vif_is_mld(vif)))
                return -EOPNOTSUPP;
 
+       if (unlikely(link_id >= BITS_PER_LONG))
+               return -EINVAL;
+

Since I think this problem only comes from dbgfs path, would you like to just add a check in debug.c ?

For example,
(based on 0 <= valid link id < IEEE80211_MLD_MAX_NUM_LINKS < BITS_PER_LONG)

Quoted 9 lines

rtw89_debug_priv_mlo_mode_set(...)

{
        ...
        switch (mlo_mode) {
        case RTW89_MLO_MODE_MLSR:
               if (argv >= IEEE80211_MLD_MAX_NUM_LINKS)
                       return -EINVAL;
                ...

I'd prefer to add the check in one place instead of all the callers. We could check IEEE80211_MLD_MAX_NUM_LINKS instead of bits per long if that's more readable?

regards,
dan carpenter

#3 lore raw
Quoted 41 lines · Dan Carpenter
Quoted 5 lines · Zong-Zhe Yang
Quoted 4 lines · Dan Carpenter

The "link_id" value comes from the user via debugfs. If it's larger
than BITS_PER_LONG then that would result in shift wrapping and
potentially an out of bounds access later. Fortunately, only root can write to debugfs files

so the security impact is minimal.

Quoted 12 lines
Quoted 1 line

Thank you for catching this problem.

Quoted 8 lines

[...]

drivers/net/wireless/realtek/rtw89/core.c +0 -0
@@ -5239,6 +5239,9 @@ int rtw89_core_mlsr_switch(struct rtw89_dev
 *rtwdev, struct rtw89_vif *rtwvif,
        if (unlikely(!ieee80211_vif_is_mld(vif)))
                return -EOPNOTSUPP;
 
Quoted 5 lines

drivers/net/wireless/realtek/rtw89/core.c int rtw89_core_mlsr_switch(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif, · line 5244

Quoted 3 lines
drivers/net/wireless/realtek/rtw89/core.c +3 -0
+       if (unlikely(link_id >= BITS_PER_LONG))
+               return -EINVAL;
+

Since I think this problem only comes from dbgfs path, would you like to just add a check in

debug.c ?

Quoted 5 lines

For example,
(based on 0 <= valid link id < IEEE80211_MLD_MAX_NUM_LINKS < BITS_PER_LONG)

Quoted 9 lines

rtw89_debug_priv_mlo_mode_set(...)

{
        ...
        switch (mlo_mode) {
        case RTW89_MLO_MODE_MLSR:
               if (argv >= IEEE80211_MLD_MAX_NUM_LINKS)
                       return -EINVAL;
                ...
Quoted 1 line

I'd prefer to add the check in one place instead of all the callers.

Understandable.

Quoted 2 lines

We could check IEEE80211_MLD_MAX_NUM_LINKS instead of bits per long if that's more readable?

Sound good to me.