linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] NFC fixes for 4.19-final
@ 2018-09-17 13:51 Greg Kroah-Hartman
  2018-09-17 13:51 ` [PATCH 1/2] NFC: Fix possible memory corruption when handling SHDLC I-Frame commands Greg Kroah-Hartman
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2018-09-17 13:51 UTC (permalink / raw)
  To: sameo, davem, netdev
  Cc: allen.pais, keescook, surenb, linux-wireless, linux-kernel,
	Greg Kroah-Hartman

For some reason, these two NFC patches fell through the cracks.  It
looks like sometimes NFC patches go through the wireless tree, and
other times, through the networking tree directly.

I don't care which way they go, but they should get merged through some
way, or, I can take them in my device tree, but that feels a bit odd to
me.

thanks,

greg k-h

Suren Baghdasaryan (2):
  NFC: Fix possible memory corruption when handling SHDLC I-Frame
    commands
  NFC: Fix the number of pipes

 include/net/nfc/hci.h |  2 +-
 net/nfc/hci/core.c    | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

-- 
2.19.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] NFC: Fix possible memory corruption when handling SHDLC I-Frame commands
  2018-09-17 13:51 [PATCH 0/2] NFC fixes for 4.19-final Greg Kroah-Hartman
@ 2018-09-17 13:51 ` Greg Kroah-Hartman
  2018-09-17 13:51 ` [PATCH 2/2] NFC: Fix the number of pipes Greg Kroah-Hartman
  2018-09-19  2:54 ` [PATCH 0/2] NFC fixes for 4.19-final David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2018-09-17 13:51 UTC (permalink / raw)
  To: sameo, davem, netdev
  Cc: allen.pais, keescook, surenb, linux-wireless, linux-kernel,
	stable, Greg Kroah-Hartman

From: Suren Baghdasaryan <surenb@google.com>

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>
---
 net/nfc/hci/core.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/net/nfc/hci/core.c b/net/nfc/hci/core.c
index ac8030c4bcf8..19cb2e473ea6 100644
--- a/net/nfc/hci/core.c
+++ b/net/nfc/hci/core.c
@@ -209,6 +209,11 @@ void nfc_hci_cmd_received(struct nfc_hci_dev *hdev, u8 pipe, u8 cmd,
 		}
 		create_info = (struct hci_create_pipe_resp *)skb->data;
 
+		if (create_info->pipe >= NFC_HCI_MAX_PIPES) {
+			status = NFC_HCI_ANY_E_NOK;
+			goto exit;
+		}
+
 		/* Save the new created pipe and bind with local gate,
 		 * the description for skb->data[3] is destination gate id
 		 * 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,
 		}
 		delete_info = (struct hci_delete_pipe_noti *)skb->data;
 
+		if (delete_info->pipe >= NFC_HCI_MAX_PIPES) {
+			status = NFC_HCI_ANY_E_NOK;
+			goto exit;
+		}
+
 		hdev->pipes[delete_info->pipe].gate = NFC_HCI_INVALID_GATE;
 		hdev->pipes[delete_info->pipe].dest_host = NFC_HCI_INVALID_HOST;
 		break;
-- 
2.19.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] NFC: Fix the number of pipes
  2018-09-17 13:51 [PATCH 0/2] NFC fixes for 4.19-final Greg Kroah-Hartman
  2018-09-17 13:51 ` [PATCH 1/2] NFC: Fix possible memory corruption when handling SHDLC I-Frame commands Greg Kroah-Hartman
@ 2018-09-17 13:51 ` Greg Kroah-Hartman
  2018-09-19  2:54 ` [PATCH 0/2] NFC fixes for 4.19-final David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2018-09-17 13:51 UTC (permalink / raw)
  To: sameo, davem, netdev
  Cc: allen.pais, keescook, surenb, linux-wireless, linux-kernel,
	stable, Greg Kroah-Hartman

From: Suren Baghdasaryan <surenb@google.com>

According to ETSI TS 102 622 specification chapter 4.4 pipe identifier
is 7 bits long which allows for 128 unique pipe IDs. Because
NFC_HCI_MAX_PIPES is used as the number of pipes supported and not
as the max pipe ID, its value should be 128 instead of 127.

nfc_hci_recv_from_llc extracts pipe ID from packet header using
NFC_HCI_FRAGMENT(0x7F) mask which allows for pipe ID value of 127.
Same happens when NCI_HCP_MSG_GET_PIPE() is being used. With
pipes array having only 127 elements and pipe ID of 127 the OOB memory
access will result.

Cc: Samuel Ortiz <sameo@linux.intel.com>
Cc: Allen Pais <allen.pais@oracle.com>
Cc: "David S. Miller" <davem@davemloft.net>
Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 include/net/nfc/hci.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/net/nfc/hci.h b/include/net/nfc/hci.h
index 316694dafa5b..008f466d1da7 100644
--- a/include/net/nfc/hci.h
+++ b/include/net/nfc/hci.h
@@ -87,7 +87,7 @@ struct nfc_hci_pipe {
  * According to specification 102 622 chapter 4.4 Pipes,
  * the pipe identifier is 7 bits long.
  */
-#define NFC_HCI_MAX_PIPES		127
+#define NFC_HCI_MAX_PIPES		128
 struct nfc_hci_init_data {
 	u8 gate_count;
 	struct nfc_hci_gate gates[NFC_HCI_MAX_CUSTOM_GATES];
-- 
2.19.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] NFC fixes for 4.19-final
  2018-09-17 13:51 [PATCH 0/2] NFC fixes for 4.19-final Greg Kroah-Hartman
  2018-09-17 13:51 ` [PATCH 1/2] NFC: Fix possible memory corruption when handling SHDLC I-Frame commands Greg Kroah-Hartman
  2018-09-17 13:51 ` [PATCH 2/2] NFC: Fix the number of pipes Greg Kroah-Hartman
@ 2018-09-19  2:54 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2018-09-19  2:54 UTC (permalink / raw)
  To: gregkh
  Cc: sameo, netdev, allen.pais, keescook, surenb, linux-wireless,
	linux-kernel

From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date: Mon, 17 Sep 2018 15:51:39 +0200

> For some reason, these two NFC patches fell through the cracks.  It
> looks like sometimes NFC patches go through the wireless tree, and
> other times, through the networking tree directly.
> 
> I don't care which way they go, but they should get merged through some
> way, or, I can take them in my device tree, but that feels a bit odd to
> me.

I'll take these directly, thanks Greg.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-09-19  2:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-17 13:51 [PATCH 0/2] NFC fixes for 4.19-final Greg Kroah-Hartman
2018-09-17 13:51 ` [PATCH 1/2] NFC: Fix possible memory corruption when handling SHDLC I-Frame commands Greg Kroah-Hartman
2018-09-17 13:51 ` [PATCH 2/2] NFC: Fix the number of pipes Greg Kroah-Hartman
2018-09-19  2:54 ` [PATCH 0/2] NFC fixes for 4.19-final David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).