Skip to content

Commit 674d9de

Browse files
surenbaghdasaryandavem330
authored andcommitted
NFC: Fix possible memory corruption when handling SHDLC I-Frame commands
When handling SHDLC I-Frame commands "pipe" field used for indexing into an array should be checked before usage. If left unchecked it might access memory outside of the array of size NFC_HCI_MAX_PIPES(127). Malformed NFC HCI frames could be injected by a malicious NFC device communicating with the device being attacked (remote attack vector), or even by an attacker with physical access to the I2C bus such that they could influence the data transfers on that bus (local attack vector). skb->data is controlled by the attacker and has only been sanitized in the most trivial ways (CRC check), therefore we can consider the create_info struct and all of its members to tainted. 'create_info->pipe' with max value of 255 (uint8) is used to take an offset of the hdev->pipes array of 127 elements which can lead to OOB write. Cc: Samuel Ortiz <sameo@linux.intel.com> Cc: Allen Pais <allen.pais@oracle.com> Cc: "David S. Miller" <davem@davemloft.net> Suggested-by: Kevin Deus <kdeus@google.com> Signed-off-by: Suren Baghdasaryan <surenb@google.com> Acked-by: Kees Cook <keescook@chromium.org> Cc: stable <stable@vger.kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0a286af commit 674d9de

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

net/nfc/hci/core.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ void nfc_hci_cmd_received(struct nfc_hci_dev *hdev, u8 pipe, u8 cmd,
209209
}
210210
create_info = (struct hci_create_pipe_resp *)skb->data;
211211

212+
if (create_info->pipe >= NFC_HCI_MAX_PIPES) {
213+
status = NFC_HCI_ANY_E_NOK;
214+
goto exit;
215+
}
216+
212217
/* Save the new created pipe and bind with local gate,
213218
* the description for skb->data[3] is destination gate id
214219
* but since we received this cmd from host controller, we
@@ -232,6 +237,11 @@ void nfc_hci_cmd_received(struct nfc_hci_dev *hdev, u8 pipe, u8 cmd,
232237
}
233238
delete_info = (struct hci_delete_pipe_noti *)skb->data;
234239

240+
if (delete_info->pipe >= NFC_HCI_MAX_PIPES) {
241+
status = NFC_HCI_ANY_E_NOK;
242+
goto exit;
243+
}
244+
235245
hdev->pipes[delete_info->pipe].gate = NFC_HCI_INVALID_GATE;
236246
hdev->pipes[delete_info->pipe].dest_host = NFC_HCI_INVALID_HOST;
237247
break;

0 commit comments

Comments
 (0)