Netdev List
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: yun.zhou@windriver.com
Cc: 'Simon Horman' <horms@kernel.org>,
	david+nfc@ixit.cz, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com, bongsu.jeon@samsung.com,
	oe-linux-nfc@lists.linux.dev, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] nfc: nci: fix use of uninitialized memory in CORE_INIT_RSP parsing
Date: Thu, 21 May 2026 15:58:17 +0100	[thread overview]
Message-ID: <20260521145817.1990235-1-horms@kernel.org> (raw)
In-Reply-To: <20260519013042.3459906-1-yun.zhou@windriver.com>

From: 'Simon Horman' <horms@kernel.org>

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
Full review at: https://sashiko.dev
---
nfc: nci: fix use of uninitialized memory in CORE_INIT_RSP parsing

This commit adds skb length checks to nci_core_init_rsp_packet_v1() and
nci_core_init_rsp_packet_v2() before parsing the CORE_INIT_RSP packet to
prevent reads of uninitialized memory.

> diff --git a/net/nfc/nci/rsp.c b/net/nfc/nci/rsp.c
> index 9eeb862825c5f..36e49fb7d8941 100644
> --- a/net/nfc/nci/rsp.c
> +++ b/net/nfc/nci/rsp.c
> @@ -50,6 +50,9 @@ static u8 nci_core_init_rsp_packet_v1(struct nci_dev *ndev,
>  	const struct nci_core_init_rsp_1 *rsp_1 = (void *)skb->data;
>  	const struct nci_core_init_rsp_2 *rsp_2;
>  
> +	if (skb->len < sizeof(*rsp_1))
> +		return NCI_STATUS_SYNTAX_ERROR;
> +

Does this length check break the handling of valid NCI error responses?

If the device returns an error status, the response payload might only
contain the 1-byte status field. By requiring the full sizeof(*rsp_1)
before checking the status, will this return NCI_STATUS_SYNTAX_ERROR
instead of propagating the actual error code from the device?

>  	pr_debug("status 0x%x\n", rsp_1->status);
>  
>  	if (rsp_1->status != NCI_STATUS_OK)

[ ... ]

> @@ -87,15 +94,21 @@ static u8 nci_core_init_rsp_packet_v2(struct nci_dev *ndev,
>  				      const struct sk_buff *skb)
>  {
>  	const struct nci_core_init_rsp_nci_ver2 *rsp = (void *)skb->data;
> -	const u8 *supported_rf_interface = rsp->supported_rf_interfaces;
> +	const u8 *supported_rf_interface;
> +	const u8 *skb_end = skb->data + skb->len;
>  	u8 rf_interface_idx = 0;
>  	u8 rf_extension_cnt = 0;
>  
> +	if (skb->len < sizeof(*rsp))
> +		return NCI_STATUS_SYNTAX_ERROR;
> +

Could the same issue occur here for v2 responses?

If a command fails and the response payload only includes the status
field, checking for the full sizeof(*rsp) will drop the error response
and obscure the true failure reason.

>  	pr_debug("status %x\n", rsp->status);
>  
>  	if (rsp->status != NCI_STATUS_OK)
>  		return rsp->status;

      reply	other threads:[~2026-05-21 14:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-19  1:30 [PATCH] nfc: nci: fix use of uninitialized memory in CORE_INIT_RSP parsing Yun Zhou
2026-05-21 14:58 ` Simon Horman [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260521145817.1990235-1-horms@kernel.org \
    --to=horms@kernel.org \
    --cc=bongsu.jeon@samsung.com \
    --cc=davem@davemloft.net \
    --cc=david+nfc@ixit.cz \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=oe-linux-nfc@lists.linux.dev \
    --cc=pabeni@redhat.com \
    --cc=yun.zhou@windriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox