ipv6: fix Route Information option length validation
Subsystems (4)
PATCH v2 1/1 ipv6: fix Route Information option length validation
rt6_route_rcv() validates the Route Information option (RFC 4191) length against the prefix length, but both checks are off by one.
rinfo->length is the ND option length in units of 8 octets and it *includes* the 8-byte option header, so an option carrying N bytes of prefix has length == 1 + N/8. RFC 4191 section 2.3 requires length 3 when Prefix Length is greater than 64, and 2 or 3 when it is greater than 0. The code accepts length >= 2 and length >= 1 respectively.
ipv6_addr_prefix() then copies prefix_len/8 bytes out of rinfo->prefix, so a Router Advertisement with (prefix_len=128, length=2) or (prefix_len=64, length=1) makes the kernel read up to 8 bytes past the end of the option. Those bytes end up in the prefix of the route that gets installed, so they are visible to userspace:
# RA with a Route Information option (prefix_len=128, length=2)
# followed by a source link-layer address option, 01 01 de ad be ef ca fe
$ ip -6 route show
2001:db8:dead:beef:101:dead:beef:cafe via fe80::1234 dev veth0 proto ra
^^^^^^^^^^^^^^^^^^ the next option, read out of boundsWhen the Route Information option is the last one in the packet, those eight bytes come from the skb tail room instead.
Reject the option lengths RFC 4191 does not allow.
---
v2:
- drop the stray blank line in the tag block; no code change
v1: https://lore.kernel.org/netdev/[email protected]/
net/ipv6/route.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/ipv6/route.c +4 -4
@@ -988,13 +988,13 @@ int rt6_route_rcv(struct net_device *dev, u8 *opt, int len, }else if (rinfo->prefix_len >128 ) {return -EINVAL ; }else if (rinfo->prefix_len >64 ) { -if (rinfo->length <2 ) { +/* RFC 4191: Length MUST be 3 when Prefix Length > 64 */ +if (rinfo->length <3 )return -EINVAL ; - } }else if (rinfo->prefix_len >0 ) { -if (rinfo->length <1 ) { +/* RFC 4191: Length MUST be 2 or 3 when Prefix Length > 0 */ +if (rinfo->length <2 )return -EINVAL ; - } } pref = rinfo->route_pref;
--
2.51.0
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Thu, 30 Jul 2026 11:52:32 +0800 you wrote:
rt6_route_rcv()validates the Route Information option (RFC 4191) length against the prefix length, but both checks are off by one.
rinfo->lengthis the ND option length in units of 8 octets and it *includes* the 8-byte option header, so an option carrying N bytes of prefix has length == 1 + N/8. RFC 4191 section 2.3 requires length 3 when Prefix Length is greater than 64, and 2 or 3 when it is greater than 0. The code accepts length >= 2 and length >= 1 respectively.[...]
Here is the summary with links:
- [net,v2] ipv6: fix Route Information option length validation
https://git.kernel.org/netdev/net/c/d1ad8fb2ac6a
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html