Skip to content

Commit d7ee81a

Browse files
Dan Carpenterdavem330
authored andcommitted
NFC: nci: Add some bounds checking in nci_hci_cmd_received()
This is similar to commit 674d9de ("NFC: Fix possible memory corruption when handling SHDLC I-Frame commands"). I'm not totally sure, but I think that commit description may have overstated the danger. I was under the impression that this data came from the firmware? If you can't trust your networking firmware, then you're already in trouble. Anyway, these days we add bounds checking where ever we can and we call it kernel hardening. Better safe than sorry. Fixes: 11f54f2 ("NFC: nci: Add HCI over NCI protocol support") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7f46774 commit d7ee81a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

net/nfc/nci/hci.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,10 @@ static void nci_hci_cmd_received(struct nci_dev *ndev, u8 pipe,
312312
create_info = (struct nci_hci_create_pipe_resp *)skb->data;
313313
dest_gate = create_info->dest_gate;
314314
new_pipe = create_info->pipe;
315+
if (new_pipe >= NCI_HCI_MAX_PIPES) {
316+
status = NCI_HCI_ANY_E_NOK;
317+
goto exit;
318+
}
315319

316320
/* Save the new created pipe and bind with local gate,
317321
* the description for skb->data[3] is destination gate id
@@ -336,6 +340,10 @@ static void nci_hci_cmd_received(struct nci_dev *ndev, u8 pipe,
336340
goto exit;
337341
}
338342
delete_info = (struct nci_hci_delete_pipe_noti *)skb->data;
343+
if (delete_info->pipe >= NCI_HCI_MAX_PIPES) {
344+
status = NCI_HCI_ANY_E_NOK;
345+
goto exit;
346+
}
339347

340348
ndev->hci_dev->pipes[delete_info->pipe].gate =
341349
NCI_HCI_INVALID_GATE;

0 commit comments

Comments
 (0)