nfc: st21nfca: fix possible double free in st21nfca_im_recv_dep_res_cb()
Subsystems (3)
PATCH 1/1 nfc: st21nfca: fix possible double free in st21nfca_im_recv_dep_res_cb()
nfc_tm_data_received will free skb internally when it fails. There is no need to free skb in st21nfca_im_recv_dep_res_cb again.
Fix this by setting skb to NULL when nfc_tm_data_received fails.
--- drivers/nfc/st21nfca/dep.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nfc/st21nfca/dep.c +2 -1
@@ -594,7 +594,8 @@ static void st21nfca_im_recv_dep_res_cb(void *context, struct sk_buff *skb,ST21NFCA_NFC_DEP_PFB_PNI (dep_res->pfb +1 ); size++;skb_pull (skb, size); -nfc_tm_data_received (info->hdev->ndev, skb); +if (nfc_tm_data_received (info->hdev->ndev, skb)) + skb =NULL ;break ;case ST21NFCA_NFC_DEP_PFB_SUPERVISOR_PDU :pr_err ("Received a SUPERVISOR PDU\n" );
Signature · 1 line
2.25.1
Paolo Abeni
maintainerQuoted 16 lines · Hangyu Hua
nfc_tm_data_receivedwill free skb internally when it fails. There is no need to free skb inst21nfca_im_recv_dep_res_cbagain.Fix this by setting skb to NULL when
nfc_tm_data_receivedfails.Fixes 1892bf844ea0 ("NFC: st21nfca: Adding P2P support to st21nfca in Initiator & Target mode")Signed-off-by Hangyu Hua <[email protected]>--- drivers/nfc/st21nfca/dep.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/nfc/st21nfca/dep.c +0
-0
drivers/nfc/st21nfca/dep.c static void st21nfca_im_recv_dep_res_cb(void *context, struct sk_buff *skb, · line 598
Quoted 6 lines
drivers/nfc/st21nfca/dep.c +2
-1@@ -594,7 +594,8 @@ static void st21nfca_im_recv_dep_res_cb(void *context, struct sk_buff *skb,ST21NFCA_NFC_DEP_PFB_PNI (dep_res->pfb +1 ); size++;skb_pull (skb, size); -nfc_tm_data_received (info->hdev->ndev, skb); +if (nfc_tm_data_received (info->hdev->ndev, skb)) + skb =NULL ;
Note that 'skb' not used (nor freed) by this function after this point:
the next 'break' statement refears to the inner switch, and land to the execution flow to the 'return' statement a few lines below. kfree_skb(skb) is never reached.
Paolo
Quoted 29 lines · Paolo Abeni
Quoted 16 lines · Hangyu Hua
nfc_tm_data_receivedwill free skb internally when it fails. There is no need to free skb inst21nfca_im_recv_dep_res_cbagain.Fix this by setting skb to NULL when
nfc_tm_data_receivedfails.Fixes 1892bf844ea0 ("NFC: st21nfca: Adding P2P support to st21nfca in Initiator & Target mode")Signed-off-by Hangyu Hua <[email protected]>--- drivers/nfc/st21nfca/dep.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/nfc/st21nfca/dep.c +0
-0drivers/nfc/st21nfca/dep.c static void st21nfca_im_recv_dep_res_cb(void *context, struct sk_buff *skb, · line 598
Quoted 6 lines
drivers/nfc/st21nfca/dep.c +2
-1@@ -594,7 +594,8 @@ static void st21nfca_im_recv_dep_res_cb(void *context, struct sk_buff *skb,ST21NFCA_NFC_DEP_PFB_PNI (dep_res->pfb +1 ); size++;skb_pull (skb, size); -nfc_tm_data_received (info->hdev->ndev, skb); +if (nfc_tm_data_received (info->hdev->ndev, skb)) + skb =NULL ;Note that 'skb' not used (nor freed) by this function after this point:
the next 'break' statement refears to the inner switch, and land to the execution flow to the 'return' statement a few lines below.kfree_skb(skb)is never reached.
Quoted 2 lines
Paolo
My fault. I messed up two switch statements. I will be more careful next time.
hangyu