staging: rtl8723bs: fix stale recv_frame free in recv_func_posthandle()
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.
--- drivers/staging/rtl8723bs/core/rtw_recv.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/rtl8723bs/core/rtw_recv.c +1 -2
@@ -2139,7 +2139,6 @@ static int recv_func_prehandle(struct adapter *padapter, union recv_frame *rframstatic 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)
Quoted 14 lines · Yuho Choi
recv_func_posthandle()saved the originalrecv_framepointer before callingrecvframe_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_frameon the failure path instead of the saved pre-defrag pointer.
Quoted 7 lines
Fixes 554c0a3abf21 ("staging: Add rtl8723bs sdio wifi driver")Co-developed-by Myeonghun Pak <[email protected]>Signed-off-by Myeonghun Pak <[email protected]>Co-developed-by Ijae Kim <[email protected]>Signed-off-by Ijae Kim <[email protected]>Co-developed-by Taegyu Kim <[email protected]>Signed-off-by Taegyu Kim <[email protected]>
Same. Are you, folks, doing some AI/static analyser tool?
Quoted 1 line
Signed-off-by Yuho Choi <[email protected]>
Signature · 2 lines
With Best Regards, Andy Shevchenko
Greg Kroah-Hartman
maintainerQuoted 7 lines · Yuho Choi
recv_func_posthandle()saved the originalrecv_framepointer before callingrecvframe_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_frameon 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
Quoted 10 lines · Yuho Choi
recv_func_posthandle()saved the originalrecv_framepointer before callingrecvframe_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_frameon the failure path instead of the saved pre-defrag pointer.Fixes 554c0a3abf21 ("staging: Add rtl8723bs sdio wifi driver")