Skip to content

Commit a3aefbf

Browse files
Dan Carpenterdavem330
authored andcommitted
net: nfc: fix bounds checking bugs on "pipe"
This is similar to commit 674d9de ("NFC: Fix possible memory corruption when handling SHDLC I-Frame commands") and commit d7ee81a ("NFC: nci: Add some bounds checking in nci_hci_cmd_received()") which added range checks on "pipe". The "pipe" variable comes skb->data[0] in nfc_hci_msg_rx_work(). It's in the 0-255 range. We're using it as the array index into the hdev->pipes[] array which has NFC_HCI_MAX_PIPES (128) members. Fixes: 118278f ("NFC: hci: Add pipes table to reference them with a tuple {gate, host}") Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e25d5db commit a3aefbf

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

net/nfc/hci/core.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,20 @@ void nfc_hci_resp_received(struct nfc_hci_dev *hdev, u8 result,
181181
void nfc_hci_cmd_received(struct nfc_hci_dev *hdev, u8 pipe, u8 cmd,
182182
struct sk_buff *skb)
183183
{
184-
u8 gate = hdev->pipes[pipe].gate;
185184
u8 status = NFC_HCI_ANY_OK;
186185
struct hci_create_pipe_resp *create_info;
187186
struct hci_delete_pipe_noti *delete_info;
188187
struct hci_all_pipe_cleared_noti *cleared_info;
188+
u8 gate;
189189

190-
pr_debug("from gate %x pipe %x cmd %x\n", gate, pipe, cmd);
190+
pr_debug("from pipe %x cmd %x\n", pipe, cmd);
191+
192+
if (pipe >= NFC_HCI_MAX_PIPES) {
193+
status = NFC_HCI_ANY_E_NOK;
194+
goto exit;
195+
}
196+
197+
gate = hdev->pipes[pipe].gate;
191198

192199
switch (cmd) {
193200
case NFC_HCI_ADM_NOTIFY_PIPE_CREATED:
@@ -375,8 +382,14 @@ void nfc_hci_event_received(struct nfc_hci_dev *hdev, u8 pipe, u8 event,
375382
struct sk_buff *skb)
376383
{
377384
int r = 0;
378-
u8 gate = hdev->pipes[pipe].gate;
385+
u8 gate;
386+
387+
if (pipe >= NFC_HCI_MAX_PIPES) {
388+
pr_err("Discarded event %x to invalid pipe %x\n", event, pipe);
389+
goto exit;
390+
}
379391

392+
gate = hdev->pipes[pipe].gate;
380393
if (gate == NFC_HCI_INVALID_GATE) {
381394
pr_err("Discarded event %x to unopened pipe %x\n", event, pipe);
382395
goto exit;

0 commit comments

Comments
 (0)