Netdev List
 help / color / mirror / Atom feed
* [PATCH] nfc: nci: validate CORE_CONN_CREATE response length before reading fields
@ 2026-09-07  6:28 Aamir Ahmed
  2026-09-11 12:27 ` Simon Horman
  0 siblings, 1 reply; 2+ messages in thread
From: Aamir Ahmed @ 2026-09-07  6:28 UTC (permalink / raw)
  To: David Heidelberg, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: Simon Horman, Christophe Ricard, Samuel Ortiz, oe-linux-nfc,
	netdev, linux-kernel, stable, Aamir Ahmed

nci_core_conn_create_rsp_packet() casts skb->data to struct
nci_core_conn_create_rsp and accesses its conn_id,
max_ctrl_pkt_payload_len, and credits_cnt fields (offsets 1-3) when
the status byte is NCI_STATUS_OK.  However, the NCI transport layer
(nci_valid_size) only guarantees that the payload contains at least
one byte.  A malformed response with plen=1 and status=0 passes this
check, and the handler then reads three bytes past the valid payload,
using uninitialised slab data to populate the connection info that is
later used for NFC data exchange.

This can be triggered from userspace via the virtual_ncidev interface
by injecting a short CORE_CONN_CREATE_RSP frame.

Add a length check for the full response structure before accessing
any field beyond the status byte.

Fixes: 736bb9577407 ("NFC: nci: Support logical connections management")
Cc: stable@vger.kernel.org
Signed-off-by: Aamir Ahmed <elb12345@hotmail.co.uk>
---
 net/nfc/nci/rsp.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/nfc/nci/rsp.c b/net/nfc/nci/rsp.c
index b0ab4f5acbce..72b748f0be9f 100644
--- a/net/nfc/nci/rsp.c
+++ b/net/nfc/nci/rsp.c
@@ -312,6 +312,10 @@ static void nci_core_conn_create_rsp_packet(struct nci_dev *ndev,
 	pr_debug("status 0x%x\n", status);
 
 	if (status == NCI_STATUS_OK) {
+		if (skb->len < sizeof(*rsp)) {
+			status = NCI_STATUS_SYNTAX_ERROR;
+			goto exit;
+		}
 		rsp = (struct nci_core_conn_create_rsp *)skb->data;
 
 		conn_info = devm_kzalloc(&ndev->nfc_dev->dev,
-- 
2.43.0


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

* Re: [PATCH] nfc: nci: validate CORE_CONN_CREATE response length before reading fields
  2026-09-07  6:28 [PATCH] nfc: nci: validate CORE_CONN_CREATE response length before reading fields Aamir Ahmed
@ 2026-09-11 12:27 ` Simon Horman
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Horman @ 2026-09-11 12:27 UTC (permalink / raw)
  To: Aamir Ahmed
  Cc: David Heidelberg, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Christophe Ricard, Samuel Ortiz, oe-linux-nfc,
	netdev, linux-kernel, stable

On Mon, Sep 07, 2026 at 06:28:55AM +0000, Aamir Ahmed wrote:
> nci_core_conn_create_rsp_packet() casts skb->data to struct
> nci_core_conn_create_rsp and accesses its conn_id,
> max_ctrl_pkt_payload_len, and credits_cnt fields (offsets 1-3) when
> the status byte is NCI_STATUS_OK.  However, the NCI transport layer
> (nci_valid_size) only guarantees that the payload contains at least
> one byte.  A malformed response with plen=1 and status=0 passes this
> check, and the handler then reads three bytes past the valid payload,
> using uninitialised slab data to populate the connection info that is
> later used for NFC data exchange.
> 
> This can be triggered from userspace via the virtual_ncidev interface
> by injecting a short CORE_CONN_CREATE_RSP frame.
> 
> Add a length check for the full response structure before accessing
> any field beyond the status byte.
> 
> Fixes: 736bb9577407 ("NFC: nci: Support logical connections management")
> Cc: stable@vger.kernel.org
> Signed-off-by: Aamir Ahmed <elb12345@hotmail.co.uk>

This patch looks good to me but as noted collectively by Greg and Paolo
elsewhere:
1. Please include an Assisted-by tag
2. Please keep the number of patches in-flight to 15 or less

When you repost feel free to include:

Reviewed-by: Simon Horman <horms@kernel.org>

-- 
pw-bot: changes-requested

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

end of thread, other threads:[~2026-09-11 12:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-07  6:28 [PATCH] nfc: nci: validate CORE_CONN_CREATE response length before reading fields Aamir Ahmed
2026-09-11 12:27 ` Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox