Netdev List
 help / color / mirror / Atom feed
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>,
	 Peter Delevoryas <peter@pjd.dev>,
	Patrick Williams <patrick@stwcx.xyz>,
	netdev@vger.kernel.org,  Yuxiao Zhang <yuxiaozhang@google.com>
Subject: [PATCH net] net/ncsi: validate GMCMA address_count against packet length
Date: Tue, 24 Nov 2026 13:18:30 -0800	[thread overview]
Message-ID: <20261124211830.3298822-1-yuxiaozhang@google.com> (raw)

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 NC-SI payload length or the
received skb 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 or short skb 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.

Unshare the skb with skb_share_check() in ncsi_rcv_rsp() before handlers
can call pskb_may_pull(), use nrh->type instead of the potentially stale
hdr pointer for logging after nrh->handler(), ensure the fixed GMCMA
header is pulled before reading address_count, verify that both the NC-SI
payload length and the skb cover all address_count * ETH_ALEN bytes, and
re-fetch rsp after pskb_may_pull().

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 | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c
index 33921dc169e3..df915fdbbf27 100644
--- a/net/ncsi/ncsi-rsp.c
+++ b/net/ncsi/ncsi-rsp.c
@@ -1085,8 +1085,19 @@ 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 hdr_len, needed;
 	int i;
 
+	hdr_len = offsetof(struct ncsi_rsp_gmcma_pkt, addresses);
+	if (!pskb_may_pull(nr->rsp, hdr_len))
+		return -EINVAL;
+
+	rsp = (struct ncsi_rsp_gmcma_pkt *)skb_network_header(nr->rsp);
+	needed = hdr_len + (size_t)rsp->address_count * ETH_ALEN;
+	if (ntohs(rsp->rsp.common.length) < needed - sizeof(struct ncsi_pkt_hdr) ||
+	    !pskb_may_pull(nr->rsp, needed))
+		return -EINVAL;
+
 	rsp = (struct ncsi_rsp_gmcma_pkt *)skb_network_header(nr->rsp);
 	ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
 
@@ -1174,6 +1185,10 @@ int ncsi_rcv_rsp(struct sk_buff *skb, struct net_device *dev,
 		goto err_free_skb;
 	}
 
+	skb = skb_share_check(skb, GFP_ATOMIC);
+	if (!skb)
+		return -ENOMEM;
+
 	/* Check if it is AEN packet */
 	hdr = (struct ncsi_pkt_hdr *)skb_network_header(skb);
 	if (hdr->type == NCSI_PKT_AEN)
@@ -1243,7 +1258,7 @@ int ncsi_rcv_rsp(struct sk_buff *skb, struct net_device *dev,
 	if (ret)
 		netdev_err(ndp->ndev.dev,
 			   "NCSI: Handler for packet type 0x%x returned %d\n",
-			   hdr->type, ret);
+			   nrh->type, ret);
 
 out_netlink:
 	if (nr->flags == NCSI_REQ_FLAG_NETLINK_DRIVEN) {
@@ -1251,7 +1266,7 @@ int ncsi_rcv_rsp(struct sk_buff *skb, struct net_device *dev,
 		if (ret) {
 			netdev_err(ndp->ndev.dev,
 				   "NCSI: Netlink handler for packet type 0x%x returned %d\n",
-				   hdr->type, ret);
+				   nrh->type, ret);
 		}
 	}
 

base-commit: 4392bb809812ac79449cd0cf1f5e00469ee102d1
-- 
2.56.1.809.ga0b61035b5-goog


             reply	other threads:[~2026-11-24 21:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 21:18 Yuxiao Zhang [this message]
2026-11-24 21:22 ` [PATCH net] net/ncsi: validate GMCMA address_count against packet length netdev-bot+sinfo

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=20261124211830.3298822-1-yuxiaozhang@google.com \
    --to=yuxiaozhang@google.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=fercerpav@gmail.com \
    --cc=horms@kernel.org \
    --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