From: Yuxiao Zhang <yuxiaozhang@google.com>
To: Samuel Mendoza-Jonas <sam@mendozajonas.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Willem de Bruijn <willemb@google.com>
Cc: Paul Fertser <fercerpav@gmail.com>,
Simon Horman <horms@kernel.org>, Joel Stanley <joel@jms.id.au>,
Peter Delevoryas <peter@pjd.dev>,
Patrick Williams <patrick@stwcx.xyz>,
netdev@vger.kernel.org, Yuxiao Zhang <yuxiaozhang@google.com>
Subject: [PATCH net v2 2/2] net/ncsi: validate GMCMA address_count against packet length
Date: Tue, 1 Dec 2026 19:36:09 -0800 [thread overview]
Message-ID: <20261202033609.1934503-3-yuxiaozhang@google.com> (raw)
In-Reply-To: <20261202033609.1934503-1-yuxiaozhang@google.com>
ncsi_rsp_handler_gmcma() iterates up to rsp->address_count (a u8 field
from the network packet, up to 255) over rsp->addresses[] and logs each
6-byte entry without verifying that the validated NC-SI payload actually
holds the fixed GMCMA response header and all advertised MAC addresses.
A malformed or malicious NC-SI Get MC MAC Address response with a small
payload (e.g. length = 8 in a 46-byte Ethernet-padded frame) and a large
address_count (up to 0xff, indexing up to 1530 bytes past addresses[])
triggers a slab out-of-bounds read and leaks adjacent kernel heap memory
into dmesg via netdev_info(), or reads trailing Ethernet padding as
provisioned MAC addresses.
Now that ncsi_validate_rsp_pkt() guarantees the skb linear head covers
the common header, 4-byte-aligned payload, and checksum, validate that
the NC-SI payload length covers both the fixed GMCMA header fields and
all address_count * ETH_ALEN bytes before indexing rsp->addresses[].
Discovered via automated LLM-assisted code scanning and verified by
manual code inspection. Not observed in production, but reproduced at
runtime on netdev/net with ARCH=um + KASAN by delivering a 46-byte
NCSI_PKT_RSP_GMCMA skb (length=8, checksum=0, address_count=0xff) to
ncsi_rcv_rsp():
BUG: KASAN: slab-out-of-bounds in ncsi_rsp_handler_gmcma+0x212/0x573
Read of size 1 at addr 00000000624d6683 by task kunit_try_catch/30
The buggy address belongs to the object at 00000000624d63c0
which belongs to the cache skbuff_small_head of size 704
The buggy address is located 3 bytes to the right of
allocated 704-byte region [00000000624d63c0, 00000000624d6680)
With this series applied, the same KUnit + KASAN run rejects malformed
GMCMA frames with -EINVAL without triggering KASAN and continues to
parse valid linear and shared non-linear GMCMA responses.
Fixes: b8291cf3d118 ("net/ncsi: Add NC-SI 1.2 Get MC MAC Address command")
Signed-off-by: Yuxiao Zhang <yuxiaozhang@google.com>
---
net/ncsi/ncsi-rsp.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c
index e917cefd408b..23f2715baa8e 100644
--- a/net/ncsi/ncsi-rsp.c
+++ b/net/ncsi/ncsi-rsp.c
@@ -1111,9 +1111,17 @@ static int ncsi_rsp_handler_gmcma(struct ncsi_request *nr)
struct sockaddr_storage *saddr = &ndp->pending_mac;
struct net_device *ndev = ndp->ndev.dev;
struct ncsi_rsp_gmcma_pkt *rsp;
+ size_t min_payload, payload;
int i;
+ min_payload = offsetof(struct ncsi_rsp_gmcma_pkt, addresses) -
+ sizeof(struct ncsi_pkt_hdr);
rsp = (struct ncsi_rsp_gmcma_pkt *)skb_network_header(nr->rsp);
+ payload = ntohs(rsp->rsp.common.length);
+ if (payload < min_payload ||
+ payload - min_payload < (size_t)rsp->address_count * ETH_ALEN)
+ return -EINVAL;
+
ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
netdev_info(ndev, "NCSI: Received %d provisioned MAC addresses\n",
--
2.56.1.839.g22a8290db9-goog
prev parent reply other threads:[~2026-12-02 3:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 3:36 [PATCH net v2 0/2] net/ncsi: validate response packet and GMCMA lengths Yuxiao Zhang
2026-12-02 3:36 ` [PATCH net v2 1/2] net/ncsi: validate response packet lengths against skb Yuxiao Zhang
2026-12-02 3:36 ` Yuxiao Zhang [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=20261202033609.1934503-3-yuxiaozhang@google.com \
--to=yuxiaozhang@google.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=fercerpav@gmail.com \
--cc=horms@kernel.org \
--cc=joel@jms.id.au \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=patrick@stwcx.xyz \
--cc=peter@pjd.dev \
--cc=sam@mendozajonas.com \
--cc=willemb@google.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