From: Dickson Wu <dick…@certik.com>
When an SRH segment names a local address on a VRF slave,
ip6_rt_get_dev_rcu() uses the VRF master as the route device while
ip6_rt_init_dst() sets its input handler to ip6_input().
ipv6_srh_rcv() recognizes local delivery only from IFF_LOOPBACK, so it
calls dst_input(), which re-enters the routing header receiver for each
remaining segment. ipv6_rpl_srh_rcv() has the same path.
On systems allowing unprivileged user namespaces, an unprivileged user
can create this setup and send a 127-segment SRH, overflowing the
kernel stack and panicking the host. An SRv6-enabled VRF slave can
receive the packet from a peer as well.
Take the existing iterative path when the route's input handler is
ip6_input(), while retaining the loopback test. Local addresses outside
a VRF already take this path, because ip6_rt_get_dev_rcu() gives their
routes the loopback device; VRF-local routes get the VRF master instead
and miss it. This applies the existing hop-limit check to VRF-local
segments in both receivers. Before decrementing Hop Limit, invalidate a
CHECKSUM_COMPLETE receive checksum so the transport layer recomputes it
from the changed packet.
A reproducer is available on request.
Fixes: 1ababeba4a21 ("ipv6: implement dataplane support for rthdr type 4 (Segment Routing Header)")
Fixes: 8610c7c6e3bd ("net: ipv6: add support for rpl sr exthdr")
Signed-off-by: Dickson Wu <dick…@certik.com>
---
Tested on net e9d78fc6741a in KVM, as an unprivileged user in a user
namespace:
- 127-segment SRH to a local address on a VRF slave, sent locally and
over veth, and a 127-segment RPL type 3 packet: the base kernel hits
the IRQ stack guard page and panics, the patched kernel survives.
- one-segment SRH and RPL type 3 packets with CHECKSUM_COMPLETE (tc ct
action): UDP receives them with no checksum errors.
- tools/testing/selftests/net/srv6_*.sh: same results before and after
(11 pass, srv6_encap_lookup_l3vpn_test.sh skips; the rpfilter match
was not available in the guest).
- W=1 build, checkpatch --strict clean.
A two-segment RPL packet shows UDP checksum errors with and without
this patch; I haven't looked into that one.
This conflicts with net-next 47f89dfc930b ("seg6: update skb checksum
when ipv6_srh_rcv() decrements the Hop Limit"). The resolution is to
keep its update_csum_diff4() in ipv6_srh_rcv() and drop the
CHECKSUM_NONE lines there; the RPL hunk is unaffected.
This was found and the fix prepared with AI coding tools (OpenAI Codex
agents, with review by Claude). I went over the analysis and the patch
before signing off.
net/ipv6/exthdrs.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c
index ccc549de3c8a..2e0d247366d2 100644
--- a/net/ipv6/exthdrs.c
+++ b/net/ipv6/exthdrs.c
@@ -459,7 +459,8 @@ static int ipv6_srh_rcv(struct sk_buff *skb, struct inet6_dev *idev)
return -1;
}
- if (skb_dst_dev(skb)->flags & IFF_LOOPBACK) {
+ if ((skb_dst_dev(skb)->flags & IFF_LOOPBACK) ||
+ skb_dst(skb)->input == ip6_input) {
if (ipv6_hdr(skb)->hop_limit <= 1) {
__IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS);
icmpv6_send(skb, ICMPV6_TIME_EXCEED,
@@ -467,6 +468,8 @@ static int ipv6_srh_rcv(struct sk_buff *skb, struct inet6_dev *idev)
kfree_skb_reason(skb, SKB_DROP_REASON_IP_TTL_EXCEEDED);
return -1;
}
+ if (skb->ip_summed == CHECKSUM_COMPLETE)
+ skb->ip_summed = CHECKSUM_NONE;
ipv6_hdr(skb)->hop_limit--;
skb_pull(skb, skb_transport_offset(skb));
@@ -618,7 +621,8 @@ static int ipv6_rpl_srh_rcv(struct sk_buff *skb, struct inet6_dev *idev)
return -1;
}
- if (skb_dst_dev(skb)->flags & IFF_LOOPBACK) {
+ if ((skb_dst_dev(skb)->flags & IFF_LOOPBACK) ||
+ skb_dst(skb)->input == ip6_input) {
if (ipv6_hdr(skb)->hop_limit <= 1) {
__IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS);
icmpv6_send(skb, ICMPV6_TIME_EXCEED,
@@ -626,6 +630,8 @@ static int ipv6_rpl_srh_rcv(struct sk_buff *skb, struct inet6_dev *idev)
kfree_skb_reason(skb, SKB_DROP_REASON_IP_TTL_EXCEEDED);
return -1;
}
+ if (skb->ip_summed == CHECKSUM_COMPLETE)
+ skb->ip_summed = CHECKSUM_NONE;
ipv6_hdr(skb)->hop_limit--;
skb_pull(skb, sizeof(struct ipv6hdr));
--
2.43.0