From: Simon Horman <horms@kernel.org>
To: Samuel Page <sam@bynar.io>
Cc: David Heidelberg <david@ixit.cz>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
oe-linux-nfc@lists.linux.dev, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH net v2] nfc: nci: fix uninit-value in nci_core_init_rsp_packet()
Date: Fri, 26 Jun 2026 14:12:19 +0100 [thread overview]
Message-ID: <20260626131219.GD1286967@horms.kernel.org> (raw)
In-Reply-To: <20260624224455.999374-1-sam@bynar.io>
On Wed, Jun 24, 2026 at 11:44:55PM +0100, Samuel Page wrote:
> The CORE_INIT_RSP handlers walk the response using length fields taken
> from the packet itself, without checking they stay within skb->len:
>
> - v1 computes
> rsp_2 = skb->data + 6 + rsp_1->num_supported_rf_interfaces;
> from the on-wire (unclamped) interface count and then dereferences
> rsp_2, and memcpy()s the advertised interfaces - both can run past the
> received data;
> - v2 walks supported_rf_interfaces[], advancing the cursor by an
> in-packet rf_extension_cnt with no bound.
>
> A short CORE_INIT_RSP therefore makes the parser read past the packet
> (into the uninitialised tail of the RX skb); the values are stored into
> struct nci_dev and consumed while bringing the device up:
>
> BUG: KMSAN: uninit-value in nci_dev_up+0x10f3/0x1720
> nci_dev_up+0x10f3/0x1720
> nfc_dev_up+0x187/0x380
> nfc_genl_dev_up+0xdc/0x1a0
> genl_rcv_msg+0x5d4/0x9e0
> netlink_rcv_skb+0x28f/0x530
> Uninit was stored to memory at:
> nci_rsp_packet+0x68f/0x2310
> nci_rx_work+0x25f/0x5d0
> Uninit was created at:
> __alloc_skb+0x540/0xd40
> virtual_ncidev_write+0x65/0x210
>
> Validate the response length before parsing or storing the
> variable-length parts, rejecting truncated responses with
> NCI_STATUS_SYNTAX_ERROR. In v1 the check is done before
> num_supported_rf_interfaces is stored into ndev, so a truncated response
> cannot leave ndev->num_supported_rf_interfaces holding the unclamped
> on-wire count, which nci_init_complete_req() would otherwise use as a
> bound for the fixed-size supported_rf_interfaces[] array.
>
> Fixes: 6a2968aaf50c ("NFC: basic NCI protocol implementation")
> Fixes: bcd684aace34 ("net/nfc/nci: Support NCI 2.x initial sequence")
> Cc: stable@vger.kernel.org
> Tested-by: syzbot@syzkaller.appspotmail.com
> Assisted-by: Bynario AI
> Signed-off-by: Samuel Page <sam@bynar.io>
> ---
> v2: validate the response length before storing num_supported_rf_interfaces
> into @ndev. In v1 the unclamped on-wire count was stored first and the
> length check returned early on a truncated response, leaving
> ndev->num_supported_rf_interfaces > NCI_MAX_SUPPORTED_RF_INTERFACES; a
> subsequent CORE_INIT completion then walked it in nci_init_complete_req(),
> which the syzbot CI run on v1 flagged as a UBSAN array-index-out-of-bounds.
> https://ci.syzbot.org/series/2a9a8657-37a3-4dce-8cb5-2035027791dd
> v1: https://lore.kernel.org/all/20260623222402.175798-1-sam@bynar.io
Reviewed-by: Simon Horman <horms@kernel.org>
prev parent reply other threads:[~2026-06-26 13:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-24 22:44 [PATCH net v2] nfc: nci: fix uninit-value in nci_core_init_rsp_packet() Samuel Page
2026-06-26 13:12 ` 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=20260626131219.GD1286967@horms.kernel.org \
--to=horms@kernel.org \
--cc=davem@davemloft.net \
--cc=david@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=sam@bynar.io \
--cc=stable@vger.kernel.org \
/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