wifi: rtw88: allow key removal when the CAM table is full
PATCH 1/1 wifi: rtw88: allow key removal when the CAM table is full
rtw_ops_set_key() looks for a free CAM entry before checking the command. When all pairwise entries are in use, DISABLE_KEY returns -ENOSPC without clearing the existing entry.
Move the allocation and bounds check into SET_KEY. DISABLE_KEY uses the existing key->hw_key_idx.
--- drivers/net/wireless/realtek/rtw88/mac80211.c | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/net/wireless/realtek/rtw88/mac80211.c +12 -12
@@ -598,20 +598,20 @@ static int rtw_ops_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,rtw_leave_lps_deep (rtwdev); -if (key->flags &IEEE80211_KEY_FLAG_PAIRWISE ) { - hw_key_idx =rtw_sec_get_free_cam (sec); - }else { -/* multiple interfaces? */ - hw_key_idx = key->keyidx; - } - -if (hw_key_idx >= sec->total_cam_num) { - ret = -ENOSPC ; - goto out; - } -switch (cmd) {case SET_KEY : +if (key->flags &IEEE80211_KEY_FLAG_PAIRWISE ) { + hw_key_idx =rtw_sec_get_free_cam (sec); + }else { +/* multiple interfaces? */ + hw_key_idx = key->keyidx; + } + +if (hw_key_idx >= sec->total_cam_num) { + ret = -ENOSPC ; + goto out; + } +/* need sw generated IV */ key->flags |=IEEE80211_KEY_FLAG_GENERATE_IV ; key->hw_key_idx = hw_key_idx;
Quoted 11 lines · Hungyu Lin
rtw_ops_set_key()looks for a free CAM entry before checking the command. When all pairwise entries are in use,DISABLE_KEYreturns-ENOSPCwithout clearing the existing entry.Move the allocation and bounds check into
SET_KEY.DISABLE_KEYuses the existingkey->hw_key_idx.Fixes 10d58823cb44 ("wifi: rtw88: fix out-of-bounds CAM write when key table is full")Signed-off-by Hungyu Lin <[email protected]>---
Looking good to me.
Best regards,
Luka Gejak
Quoted 3 lines · Hungyu Lin
rtw_ops_set_key()looks for a free CAM entry before checking the command. When all pairwise entries are in use,DISABLE_KEYreturns-ENOSPCwithout clearing the existing entry.
Is this the actual case you met?
Quoted 5 lines
Move the allocation and bounds check into
SET_KEY.DISABLE_KEYuses the existingkey->hw_key_idx.Fixes 10d58823cb44 ("wifi: rtw88: fix out-of-bounds CAM write when key table is full")
Should it be ?
Quoted 1 line
Signed-off-by Hungyu Lin <[email protected]>
Then,
Hi Ping-Ke,
Quoted 10 lines · Ping-Ke Shih
Quoted 5 lines · Hungyu Lin
rtw_ops_set_key()looks for a free CAM entry before checking the
command. When all pairwise entries are in use,DISABLE_KEYreturns-ENOSPCwithout clearing the existing entry.Is this the actual case you met?
From my investigation it seems reachable.
As far as I undersrand, it needs all 28 pairwise entries (4-31) in use at once, so AP mode with 28 secured stations (31 mac_ids are left after the AP vif), or IBSS/TDLS with as many peers. Not reachable as a plain client. Once it is hit its pairwise DISABLE_KEY fails, mac80211 frees the key anyway after logging "failed to remove key", the cam_map bit is never cleared, and the table stays full until the driver is reloaded.
I think it can be tested with two clients by temporarily setting sec.total_cam_num = 6.
Quoted 10 lines
Quoted 6 lines
Move the allocation and bounds check into
SET_KEY.DISABLE_KEYuses
the existingkey->hw_key_idx.Fixes 10d58823cb44 ("wifi: rtw88: fix out-of-bounds CAM write when key table is full")Should it be ?
Fixes e3037485c68e ("rtw88: new Realtek 802.11ac driver")
I think 10d58823cb44 is the right tag. In e3037485c68e the check was
if (hw_key_idx > sec->total_cam_num) {and rtw_sec_get_free_cam() returns at most RTW_MAX_SEC_CAM_NUM (32), which equals total_cam_num, so the check never fired and DISABLE_KEY always reached rtw_sec_clear_cam(). The bug there was the out-of-bounds SET_KEY, which 10d58823cb44 fixed. DISABLE_KEY only started failing once the check became ">=". This patch also does not apply without 10d58823cb44, since its context has the ">=". Since 10d58823cb44 is tagged for stable, I think this one should carry
Cc: [email protected] too.
Best regards,
Luka Gejak
Ping-Ke Shih
maintainerQuoted 8 lines · Luka Gejak
Hi Ping-Ke,
Quoted 4 lines · Ping-Ke Shih
Quoted 1 line · Hungyu Lin
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
rtw_ops_set_key()looks for a free CAM entry before checking the
command. When all pairwise entries are in use,DISABLE_KEYreturns-ENOSPCwithout clearing the existing entry.Is this the actual case you met?
From my investigation it seems reachable.
I knew. I just want to know if people encountered the problem, or found and fixed this by reviewing.
Quoted 25 lines
As far as I undersrand, it needs all 28 pairwise entries (4-31) in use at once, so AP mode with 28 secured stations (31
mac_idsare left after the AP vif), or IBSS/TDLS with as many peers. Not reachable as a plain client. Once it is hit its pairwiseDISABLE_KEYfails, mac80211 frees the key anyway after logging "failed to remove key", thecam_mapbit is never cleared, and the table stays full until the driver is reloaded.I think it can be tested with two clients by temporarily setting sec.total_cam_num = 6.
Quoted 10 lines
Quoted 6 lines
Move the allocation and bounds check into
SET_KEY.DISABLE_KEYuses
the existingkey->hw_key_idx.Fixes 10d58823cb44 ("wifi: rtw88: fix out-of-bounds CAM write when key table is full")Should it be ?
Fixes e3037485c68e ("rtw88: new Realtek 802.11ac driver")I think
10d58823cb44is the right tag. Ine3037485c68ethe check was
Quoted 8 lines
if (hw_key_idx > sec->total_cam_num) {and
rtw_sec_get_free_cam()returns at mostRTW_MAX_SEC_CAM_NUM(32), which equalstotal_cam_num, so the check never fired andDISABLE_KEYalways reachedrtw_sec_clear_cam(). The bug there was the out-of-boundsSET_KEY, which10d58823cb44fixed.DISABLE_KEYonly started failing once the check became ">=". This patch also does not apply without10d58823cb44, since its context has the ">=".
I feel the initial commit e3037485c68e containing two bugs. One is missing to check proper boundary, and the other is this one.
Without e3037485c68e, it will out-of-bounds SET_KEY, and then it is possible to DISABLE_KEY fail (at wrong boundary), no?
Ping-Ke
Quoted 2 lines
I knew. I just want to know if people encountered the problem, or found and fixed this by reviewing.
Found by code inspection. I don't have rtw88 hardware.
Thanks,
Hungyu
A message that is not in the archive (sent off-list or not yet received): CANQ=N_C3+gpQ3O=SXYpRCGTh_MC1y4TEfnxF90SWgUVF_wYPUA@mail.gmail.com
Quoted 1 line
I can help in testing if you want. Since i do have rtw88 hardware available with me.
Thanks, that would help.
Best regards,
Hungyu
Hi Shagor,
Quoted 2 lines
I can help in testing if you want. Since i do have rtw88 hardware available with me.
Have you had a chance to test this patch?
Thanks,
Hungyu
Imtiyaz Parvez
Tested-byHi Hungyu,
Quoted 1 line
Have you had a chance to test this patch?
Yes, sorry for the delay. I tested it on my laptop.
Hardware: RTL8822CE 802.11ac | kernel version: 7.2.11-arch1-1
I built only the rtw88 modules from the v7.2.11 source tree with this patch applied, and loaded them.
I used it for around 2 hours with normal browsing, suspend/resume and reconnecting. No new warnings or errors in dmesg.
Thanks,
Imtiyaz
Ping-Ke Shih
maintainerQuoted 6 lines · Imtiyaz Parvez
Hi Hungyu,
Quoted 1 line
Have you had a chance to test this patch?
Yes, sorry for the delay. I tested it on my laptop.
Quoted 7 lines
Hardware: RTL8822CE 802.11ac | kernel version: 7.2.11-arch1-1
I built only the rtw88 modules from the v7.2.11 source tree with this patch applied, and loaded them.
I used it for around 2 hours with normal browsing, suspend/resume and reconnecting. No new warnings or errors in dmesg.
To hit the problem this patch fixes, we need 28 pairwise entries as Luka's mention [1]. I think it is not easy to prepare so many stations devices.
Anyway. As your result, it proves that this patch is okay for normal use.
[1] https://lore.kernel.org/linux-wireless/[email protected]/
Imtiyaz Parvez
Tested-byHi Hungyu,
Quoted 1 line
Have you had a chance to test this patch?
Yes, sorry for the delay. I tested it on my laptop.
Hardware: RTL8822CE 802.11ac | kernel version: 7.2.11-arch1-1
I built only the rtw88 modules from the v7.2.11 source tree with this patch applied, and loaded them.
I used it for around 2 hours with normal browsing, suspend/resume and reconnecting. No new warnings or errors in dmesg.
Thanks,
Imtiyaz
Ping-Ke Shih
maintainerQuoted 7 lines · Hungyu Lin
rtw_ops_set_key()looks for a free CAM entry before checking the command. When all pairwise entries are in use,DISABLE_KEYreturns-ENOSPCwithout clearing the existing entry.Move the allocation and bounds check into
SET_KEY.DISABLE_KEYuses the existingkey->hw_key_idx.
Quoted 6 lines
Fixes 10d58823cb44 ("wifi: rtw88: fix out-of-bounds CAM write when key table is full")Signed-off-by Hungyu Lin <[email protected]>Reviewed-by Luka Gejak <[email protected]>Acked-by Ping-Ke Shih <[email protected]>Tested-by Imtiyaz Parvez <[email protected]>Tested-by Imtiyaz Parvez <[email protected]>
1 patch(es) applied to rtw-next branch of rtw.git, thanks.
b60ee9891e40 wifi: rtw88: allow key removal when the CAM table is full