Skip to contentSkip to conversation

staging: rtl8723bs: fix stale recv_frame free in recv_func_posthandle()

PATCH In review Yuho Choi 4 participants 4 messages Apr 20 Staging

lore
Share & tools
lore

Yuho Choi

author
#0 lore raw

PATCH 1/1 staging: rtl8723bs: fix stale recv_frame free in recv_func_posthandle()

recv_func_posthandle() saved the original recv_frame pointer before calling recvframe_chk_defrag().

On the last-fragment reassembly path, recvframe_chk_defrag() may return the first fragment as the new frame while freeing the original last-fragment frame when draining the defrag queue.

If process_recv_indicatepkts() then fails, recv_func_posthandle() frees the saved pre-defrag pointer again, which can result in a stale pointer free.

Free the current recv_frame on the failure path instead of the saved pre-defrag pointer.

Fixes 554c0a3abf21 ("staging: Add rtl8723bs sdio wifi driver")
---
 drivers/staging/rtl8723bs/core/rtw_recv.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/rtl8723bs/core/rtw_recv.c +1 -2
index 337671b1211f0..a404b6fc97723 100644
@@ -2139,7 +2139,6 @@ static int recv_func_prehandle(struct adapter *padapter, union recv_frame *rfram
 static int recv_func_posthandle(struct adapter *padapter, union recv_frame *prframe)
 {
 	int ret = _SUCCESS;
-	union recv_frame *orig_prframe = prframe;
 	struct recv_priv *precvpriv = &padapter->recvpriv;
 	struct __queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
 
@@ -2163,7 +2162,7 @@ static int recv_func_posthandle(struct adapter *padapter, union recv_frame *prfr
 
 	ret = process_recv_indicatepkts(padapter, prframe);
 	if (ret != _SUCCESS) {
-		rtw_free_recvframe(orig_prframe, pfree_recv_queue);/* free this recv_frame */
+		rtw_free_recvframe(prframe, pfree_recv_queue);/* free this recv_frame */
 		goto _recv_data_drop;
 	}
 
Signature · 1 line
2.50.1 (Apple Git-155)
#1 lore raw
Quoted 14 lines · Yuho Choi

recv_func_posthandle() saved the original recv_frame pointer before calling recvframe_chk_defrag().

On the last-fragment reassembly path, recvframe_chk_defrag() may return the first fragment as the new frame while freeing the original last-fragment frame when draining the defrag queue.

If process_recv_indicatepkts() then fails, recv_func_posthandle() frees the saved pre-defrag pointer again, which can result in a stale pointer free.

Free the current recv_frame on the failure path instead of the saved pre-defrag pointer.

Quoted 7 lines
Fixes 554c0a3abf21 ("staging: Add rtl8723bs sdio wifi driver")

Same. Are you, folks, doing some AI/static analyser tool?

Quoted 1 line
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
In reply to Yuho Choi
Quoted 7 lines · Yuho Choi

recv_func_posthandle() saved the original recv_frame pointer before calling recvframe_chk_defrag().

On the last-fragment reassembly path, recvframe_chk_defrag() may return the first fragment as the new frame while freeing the original last-fragment frame when draining the defrag queue.

Quoted 6 lines

If process_recv_indicatepkts() then fails, recv_func_posthandle() frees the saved pre-defrag pointer again, which can result in a stale pointer free.

Free the current recv_frame on the failure path instead of the saved pre-defrag pointer.

Can you cause this to happen in any way? Given the age of this code, and the crazy paths here, I'm loath to change this without lots of testing with a real device, have you done so?

thanks,

greg k-h

#3 lore raw
In reply to Yuho Choi
Quoted 10 lines · Yuho Choi

recv_func_posthandle() saved the original recv_frame pointer before calling recvframe_chk_defrag().

On the last-fragment reassembly path, recvframe_chk_defrag() may return the first fragment as the new frame while freeing the original last-fragment frame when draining the defrag queue.

If process_recv_indicatepkts() then fails, recv_func_posthandle() frees the saved pre-defrag pointer again, which can result in a stale pointer free.

You seem to be saying that process_recv_indicatepkts() frees orig_prframe. And, sure, that's true. But then it returns NULL and we goto _recv_data_drop so we don't hit this path.

This seems like a false positive.

regards,
dan carpenter

Quoted 5 lines

Free the current recv_frame on the failure path instead of the saved pre-defrag pointer.

Fixes 554c0a3abf21 ("staging: Add rtl8723bs sdio wifi driver")