diff mbox series

nfc: st21nfca: fix possible double free in st21nfca_im_recv_dep_res_cb()

Message ID 20220622065117.23210-1-hbh25y@gmail.com (mailing list archive)
State Rejected
Delegated to: Netdev Maintainers
Headers show
Series nfc: st21nfca: fix possible double free in st21nfca_im_recv_dep_res_cb() | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 9 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Hangyu Hua June 22, 2022, 6:51 a.m. UTC
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(-)

Comments

Paolo Abeni June 23, 2022, 9:42 a.m. UTC | #1
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
Hangyu Hua June 23, 2022, 10:47 a.m. UTC | #2
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
diff mbox series

Patch

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");