From: Esteban Alba <estebancalba@gmail.com>
To: u-boot@lists.u-boot-project.org
Cc: Ramon Fried <rfried.dev@gmail.com>,
Jerome Forissier <jerome.forissier@arm.com>,
Tom Rini <trini@konsulko.com>
Subject: [PATCH] net: net6: validate IPv6 payload and UDP length on receive
Date: Fri, 07 Aug 2026 21:09:53 -0500 [thread overview]
Message-ID: <20260807-net6-len-validation-v1-1-edff271cbf2c@gmail.com> (raw)
net_ip6_handler() checks the received length only against IP6_HDR_SIZE
and then uses two length fields from the packet without checking them.
The checksum is computed over payload_len, but the length passed to the
UDP handler comes from udp_len. A sender can keep payload_len correct so
the checksum still validates and set udp_len larger than the frame. A
handler that trusts that length then reads or writes past the receive
buffer. The DHCPv6 client copies the declared number of bytes and can be
made to write past the packet buffer from a single link-local ADVERTISE.
The IPv4 path already reconciles these lengths in
net_process_received_packet(). Do the same here: reject a payload_len
that exceeds the received length and trim len to it, then reject a
udp_len smaller than the UDP header or larger than the payload before
calling the handler.
Fixes: 1feb697830ce ("net: ipv6: Add implementation of main IPv6 functions")
Signed-off-by: Esteban Alba <estebancalba@gmail.com>
Cc: Jerome Forissier <jerome.forissier@arm.com>
Cc: Tom Rini <trini@konsulko.com>
---
net/net6.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/net/net6.c b/net/net6.c
index 4cff98df15..af2f484fad 100644
--- a/net/net6.c
+++ b/net/net6.c
@@ -392,6 +392,11 @@ int net_ip6_handler(struct ethernet_hdr *et, struct ip6_hdr *ip6, int len)
if (ip6->version != 6)
return -EINVAL;
+ /* Trim to the length declared in the header, as the IPv4 path does */
+ if (len < IP6_HDR_SIZE + ntohs(ip6->payload_len))
+ return -EINVAL;
+ len = IP6_HDR_SIZE + ntohs(ip6->payload_len);
+
switch (ip6->nexthdr) {
case PROT_ICMPV6:
icmp = (struct icmp6hdr *)(((uchar *)ip6) + IP6_HDR_SIZE);
@@ -433,6 +438,10 @@ int net_ip6_handler(struct ethernet_hdr *et, struct ip6_hdr *ip6, int len)
if (csum != udp->udp_xsum)
return -EINVAL;
+ if (ntohs(udp->udp_len) < UDP_HDR_SIZE ||
+ ntohs(udp->udp_len) > len - IP6_HDR_SIZE)
+ return -EINVAL;
+
/* IP header OK. Pass the packet to the current handler. */
net_get_udp_handler()((uchar *)ip6 + IP6_HDR_SIZE +
UDP_HDR_SIZE,
---
base-commit: ece349ade2973e220f524ce59e59711cc919263f
change-id: 20260807-net6-len-validation-cd71efd96a7f
Best regards,
--
Esteban Alba <estebancalba@gmail.com>
WARNING: multiple messages have this Message-ID (diff)
From: Esteban Alba via B4 Relay <devnull+estebancalba.gmail.com@kernel.org>
To: u-boot@lists.u-boot-project.org
Cc: Ramon Fried <rfried.dev@gmail.com>,
Jerome Forissier <jerome.forissier@arm.com>,
Tom Rini <trini@konsulko.com>
Subject: [PATCH] net: net6: validate IPv6 payload and UDP length on receive
Date: Fri, 07 Aug 2026 21:09:53 -0500 [thread overview]
Message-ID: <20260807-net6-len-validation-v1-1-edff271cbf2c@gmail.com> (raw)
From: Esteban Alba <estebancalba@gmail.com>
net_ip6_handler() checks the received length only against IP6_HDR_SIZE
and then uses two length fields from the packet without checking them.
The checksum is computed over payload_len, but the length passed to the
UDP handler comes from udp_len. A sender can keep payload_len correct so
the checksum still validates and set udp_len larger than the frame. A
handler that trusts that length then reads or writes past the receive
buffer. The DHCPv6 client copies the declared number of bytes and can be
made to write past the packet buffer from a single link-local ADVERTISE.
The IPv4 path already reconciles these lengths in
net_process_received_packet(). Do the same here: reject a payload_len
that exceeds the received length and trim len to it, then reject a
udp_len smaller than the UDP header or larger than the payload before
calling the handler.
Fixes: 1feb697830ce ("net: ipv6: Add implementation of main IPv6 functions")
Signed-off-by: Esteban Alba <estebancalba@gmail.com>
Cc: Jerome Forissier <jerome.forissier@arm.com>
Cc: Tom Rini <trini@konsulko.com>
---
net/net6.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/net/net6.c b/net/net6.c
index 4cff98df15..af2f484fad 100644
--- a/net/net6.c
+++ b/net/net6.c
@@ -392,6 +392,11 @@ int net_ip6_handler(struct ethernet_hdr *et, struct ip6_hdr *ip6, int len)
if (ip6->version != 6)
return -EINVAL;
+ /* Trim to the length declared in the header, as the IPv4 path does */
+ if (len < IP6_HDR_SIZE + ntohs(ip6->payload_len))
+ return -EINVAL;
+ len = IP6_HDR_SIZE + ntohs(ip6->payload_len);
+
switch (ip6->nexthdr) {
case PROT_ICMPV6:
icmp = (struct icmp6hdr *)(((uchar *)ip6) + IP6_HDR_SIZE);
@@ -433,6 +438,10 @@ int net_ip6_handler(struct ethernet_hdr *et, struct ip6_hdr *ip6, int len)
if (csum != udp->udp_xsum)
return -EINVAL;
+ if (ntohs(udp->udp_len) < UDP_HDR_SIZE ||
+ ntohs(udp->udp_len) > len - IP6_HDR_SIZE)
+ return -EINVAL;
+
/* IP header OK. Pass the packet to the current handler. */
net_get_udp_handler()((uchar *)ip6 + IP6_HDR_SIZE +
UDP_HDR_SIZE,
---
base-commit: ece349ade2973e220f524ce59e59711cc919263f
change-id: 20260807-net6-len-validation-cd71efd96a7f
Best regards,
--
Esteban Alba <estebancalba@gmail.com>
next reply other threads:[~2026-08-08 2:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-08 2:09 Esteban Alba [this message]
2026-08-08 2:09 ` [PATCH] net: net6: validate IPv6 payload and UDP length on receive Esteban Alba via B4 Relay
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=20260807-net6-len-validation-v1-1-edff271cbf2c@gmail.com \
--to=estebancalba@gmail.com \
--cc=jerome.forissier@arm.com \
--cc=rfried.dev@gmail.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.u-boot-project.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.