Netdev List
 help / color / mirror / Atom feed
* [PATCH net] net/ncsi: validate GMCMA address_count against packet length
@ 2026-11-24 21:18 Yuxiao Zhang
  2026-11-24 21:22 ` netdev-bot+sinfo
  0 siblings, 1 reply; 2+ messages in thread
From: Yuxiao Zhang @ 2026-11-24 21:18 UTC (permalink / raw)
  To: Samuel Mendoza-Jonas, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn
  Cc: Paul Fertser, Simon Horman, Peter Delevoryas, Patrick Williams,
	netdev, Yuxiao Zhang

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


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

end of thread, other threads:[~2026-11-24 21:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 21:18 [PATCH net] net/ncsi: validate GMCMA address_count against packet length Yuxiao Zhang
2026-11-24 21:22 ` netdev-bot+sinfo

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