Skip to contentSkip to conversation

Invalid assignment to gate in st21nfca_get_iso14443_3_uid

PATCH In review Nicolas Iooss 2 participants 4 messages Feb 28, 2015 – Mar 16, 2015 NFC

lore
Share & tools
lore
#0 lore raw

Hello,

While compiling Linux with -Wunused-but-set-parameter, gcc reported a warning in st21nfca_get_iso14443_3_uid function, about "gate" being set but not used [1]. By looking at the code, it is clear that "gate = uid_skb->data;" does nothing useful. The function is only called once, by st21nfca_hci_target_from_gate [2], which uses the content of the uid array which is NOT initialized by st21nfca_get_iso14443_3_uid as the source of a memcpy [3].

My understanding of the code is that "gate = uid_skb->data;" in st21nfca_get_iso14443_3_uid should be changed to "memcpy(gate, uid_skb->data, uid_skb->len);".

I'm new to the NFC subsystem so I can be wrong, in which case please tell me what I missed in my analysis. Please Cc me when replying as I am not subscribed to the mailing lists.

Thanks,

Nicolas

[1]
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/nfc/st21nfca/st21nfca.c?id=v4.0-rc1#n575
[2]
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/nfc/st21nfca/st21nfca.c?id=v4.0-rc1#n646
[3]
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/nfc/st21nfca/st21nfca.c?id=v4.0-rc1#n682

#1 lore raw

PATCH 1/1 NFC: st21nfca: fix st21nfca_get_iso14443_3_uid data copy

st21nfca_get_iso14443_3_uid() does not correctly copy the uid from uid_skb->data to its gate parameter. "gate = uid_skb->data;" only puts a pointer to uid_skb->data to the local variable gate. This means that in st21nfca_hci_target_from_gate() the content of "u8 uid[NFC_NFCID1_MAXSIZE]" local variable is never initialized before being used in memcpy(target->nfcid1, uid, len).

Fix this by replacing the local variable assignment with a memcpy.

This was found by compiling Linux with "gcc -Wunused-but-set-parameter".

---

As I did not get any reply from https://lkml.org/lkml/2015/2/28/25 and got confirmation by other people that this may be a real bug, I am now sending a patch to fix it.

 drivers/nfc/st21nfca/st21nfca.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nfc/st21nfca/st21nfca.c +1 -1
index 24d3d240d5f4..ff70d2838b29 100644
@@ -588,7 +588,7 @@ static int st21nfca_get_iso14443_3_uid(struct nfc_hci_dev *hdev, u8 *gate,
 		goto exit;
 	}
 
-	gate = uid_skb->data;
+	memcpy(gate, uid_skb->data, uid_skb->len);
 	*len = uid_skb->len;
 exit:
 	kfree_skb(uid_skb);
Signature · 1 line
2.3.1
#2 lore raw

Re: [PATCH] NFC: st21nfca: fix st21nfca_get_iso14443_3_uid data copy

Hello,
I have not received any comments about this patch so I'm sending it again. Could you please review it?

Nicolas

Quoted 35 lines · Nicolas Iooss

st21nfca_get_iso14443_3_uid() does not correctly copy the uid from uid_skb->data to its gate parameter. "gate = uid_skb->data;" only puts a pointer to uid_skb->data to the local variable gate. This means that in st21nfca_hci_target_from_gate() the content of "u8 uid[NFC_NFCID1_MAXSIZE]" local variable is never initialized before being used in memcpy(target->nfcid1, uid, len).

Fix this by replacing the local variable assignment with a memcpy.

This was found by compiling Linux with "gcc -Wunused-but-set-parameter".

---

As I did not get any reply from https://lkml.org/lkml/2015/2/28/25 and got confirmation by other people that this may be a real bug, I am now sending a patch to fix it.

 drivers/nfc/st21nfca/st21nfca.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nfc/st21nfca/st21nfca.c +1 -1
index 24d3d240d5f4..ff70d2838b29 100644
@@ -588,7 +588,7 @@ static int st21nfca_get_iso14443_3_uid(struct nfc_hci_dev *hdev, u8 *gate,
 		goto exit;
 	}
 
-	gate = uid_skb->data;
+	memcpy(gate, uid_skb->data, uid_skb->len);
 	*len = uid_skb->len;
 exit:
 	kfree_skb(uid_skb);
#3 lore raw

Re: [PATCH] NFC: st21nfca: fix st21nfca_get_iso14443_3_uid data copy

Hi Nicolas,

Sorry for the late reply.

I am planning to include your patch with a Acked-by in a future patch serie.

Thanks a lot
Best Regards
Christophe

Quoted 42 lines · Nicolas Iooss

Hello,
I have not received any comments about this patch so I'm sending it again. Could you please review it?

Nicolas

Quoted 35 lines · Nicolas Iooss

st21nfca_get_iso14443_3_uid() does not correctly copy the uid from uid_skb->data to its gate parameter. "gate = uid_skb->data;" only puts a pointer to uid_skb->data to the local variable gate. This means that in st21nfca_hci_target_from_gate() the content of "u8 uid[NFC_NFCID1_MAXSIZE]" local variable is never initialized before being used in memcpy(target->nfcid1, uid, len).

Fix this by replacing the local variable assignment with a memcpy.

This was found by compiling Linux with "gcc -Wunused-but-set-parameter".

---

As I did not get any reply from https://lkml.org/lkml/2015/2/28/25 and got confirmation by other people that this may be a real bug, I am now sending a patch to fix it.

  drivers/nfc/st21nfca/st21nfca.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nfc/st21nfca/st21nfca.c +1 -1
index 24d3d240d5f4..ff70d2838b29 100644
@@ -588,7 +588,7 @@ static int st21nfca_get_iso14443_3_uid(struct nfc_hci_dev *hdev, u8 *gate,
  		goto exit;
  	}
 
-	gate = uid_skb->data;
+	memcpy(gate, uid_skb->data, uid_skb->len);
  	*len = uid_skb->len;
  exit:
  	kfree_skb(uid_skb);