All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nfc: st21nfca: fix possible double free in st21nfca_im_recv_dep_res_cb()
@ 2022-06-22  6:51 Hangyu Hua
  2022-06-23  9:42 ` Paolo Abeni
  0 siblings, 1 reply; 3+ messages in thread
From: Hangyu Hua @ 2022-06-22  6:51 UTC (permalink / raw)
  To: krzysztof.kozlowski, sameo, christophe.ricard
  Cc: netdev, linux-kernel, Hangyu Hua

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.

Fixes: 1892bf844ea0 ("NFC: st21nfca: Adding P2P support to st21nfca in Initiator & Target mode")
Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
---
 drivers/nfc/st21nfca/dep.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/nfc/st21nfca/dep.c b/drivers/nfc/st21nfca/dep.c
index 1ec651e31064..07ac5688011c 100644
--- a/drivers/nfc/st21nfca/dep.c
+++ b/drivers/nfc/st21nfca/dep.c
@@ -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");
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] nfc: st21nfca: fix possible double free in st21nfca_im_recv_dep_res_cb()
  2022-06-22  6:51 [PATCH] nfc: st21nfca: fix possible double free in st21nfca_im_recv_dep_res_cb() Hangyu Hua
@ 2022-06-23  9:42 ` Paolo Abeni
  2022-06-23 10:47   ` Hangyu Hua
  0 siblings, 1 reply; 3+ messages in thread
From: Paolo Abeni @ 2022-06-23  9:42 UTC (permalink / raw)
  To: Hangyu Hua, krzysztof.kozlowski, sameo, christophe.ricard
  Cc: netdev, linux-kernel

On Wed, 2022-06-22 at 14:51 +0800, Hangyu Hua wrote:
> 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.
> 
> Fixes: 1892bf844ea0 ("NFC: st21nfca: Adding P2P support to st21nfca in Initiator & Target mode")
> Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
> ---
>  drivers/nfc/st21nfca/dep.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/nfc/st21nfca/dep.c b/drivers/nfc/st21nfca/dep.c
> index 1ec651e31064..07ac5688011c 100644
> --- a/drivers/nfc/st21nfca/dep.c
> +++ b/drivers/nfc/st21nfca/dep.c
> @@ -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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] nfc: st21nfca: fix possible double free in st21nfca_im_recv_dep_res_cb()
  2022-06-23  9:42 ` Paolo Abeni
@ 2022-06-23 10:47   ` Hangyu Hua
  0 siblings, 0 replies; 3+ messages in thread
From: Hangyu Hua @ 2022-06-23 10:47 UTC (permalink / raw)
  To: Paolo Abeni, krzysztof.kozlowski, sameo, christophe.ricard
  Cc: netdev, linux-kernel

On 2022/6/23 17:42, Paolo Abeni wrote:
> On Wed, 2022-06-22 at 14:51 +0800, Hangyu Hua wrote:
>> 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.
>>
>> Fixes: 1892bf844ea0 ("NFC: st21nfca: Adding P2P support to st21nfca in Initiator & Target mode")
>> Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
>> ---
>>   drivers/nfc/st21nfca/dep.c | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/nfc/st21nfca/dep.c b/drivers/nfc/st21nfca/dep.c
>> index 1ec651e31064..07ac5688011c 100644
>> --- a/drivers/nfc/st21nfca/dep.c
>> +++ b/drivers/nfc/st21nfca/dep.c
>> @@ -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
> 

My fault. I messed up two switch statements. I will be more careful next 
time.

hangyu



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-23 10:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-22  6:51 [PATCH] nfc: st21nfca: fix possible double free in st21nfca_im_recv_dep_res_cb() Hangyu Hua
2022-06-23  9:42 ` Paolo Abeni
2022-06-23 10:47   ` Hangyu Hua

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.