When an ICMPv6 error embeds a non-first fragment, ipv6_find_hdr() returns at the Fragment header without updating *offset, so ip_vs_fill_iph_skb_icmp() leaves ciph.len equal to ciph.off, the start of the embedded IPv6 header. ip_vs_out_icmp_v6() and ip_vs_in_icmp_v6() pass embedded non-first TCP, UDP and SCTP fragments through before any lookup. AH and ESP set pp->dont_defrag, so their fragments continue. Their lookups read only the addresses and never use ciph.len, but handle_response_icmp() and ip_vs_icmp_xmit_v6() size skb_ensure_writable() from ciph.len, which then covers nothing of the embedded header. ip_vs_nat_icmp_v6() rewrites the embedded destination or source address, 16 bytes located 8 or 24 bytes past the end of the validated area. Include the embedded IPv6 header in ciph.len at both call sites when ipv6_find_hdr() stopped at a non-first fragment. Only the size of the writable check changes; the AH and ESP lookups do not use ciph.len. This fix does not depend on patch 2. Stable kernels without commit 342e24a339b9 ("ipvs: do not mangle ICMP replies for non-first fragments") also need that commit to handle incoming ICMPv6 errors quoting non-first ESP fragments. Fixes: 63dca2c0b0e7 ("ipvs: Fix faulty IPv6 extension header handling in IPVS") Cc: stable@vger.kernel.org Suggested-by: Julian Anastasov Signed-off-by: Axel Mierczuk --- net/netfilter/ipvs/ip_vs_core.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c index fd503f0efb57..d5da16ff9673 100644 --- a/net/netfilter/ipvs/ip_vs_core.c +++ b/net/netfilter/ipvs/ip_vs_core.c @@ -1206,6 +1206,16 @@ static int ip_vs_out_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb, true, &ciph)) return NF_ACCEPT; /* The packet looks wrong, ignore */ + /* ipv6_find_hdr() stops at the Fragment header of a non-first + * fragment and leaves ciph.len == ciph.off. Only AH and ESP + * (pp->dont_defrag) pass the fragoffs check below and their + * lookup reads only the addresses, but handle_response_icmp() + * sizes skb_ensure_writable() from ciph.len before + * ip_vs_nat_icmp_v6() rewrites the embedded header. Include it. + */ + if (ciph.len == ciph.off) + ciph.len += sizeof(struct ipv6hdr); + pp = ip_vs_proto_get(ciph.protocol); if (!pp) return NF_ACCEPT; @@ -2036,6 +2046,16 @@ static int ip_vs_in_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb, if (!ip_vs_fill_iph_skb_icmp(AF_INET6, skb, offset, true, &ciph)) return NF_ACCEPT; + /* ipv6_find_hdr() stops at the Fragment header of a non-first + * fragment and leaves ciph.len == ciph.off. Only AH and ESP + * (pp->dont_defrag) pass the fragoffs check below and their + * lookup reads only the addresses, but ip_vs_icmp_xmit_v6() + * sizes skb_ensure_writable() from ciph.len before + * ip_vs_nat_icmp_v6() rewrites the embedded header. Include it. + */ + if (ciph.len == ciph.off) + ciph.len += sizeof(struct ipv6hdr); + pd = ip_vs_proto_data_get(ipvs, ciph.protocol); if (!pd) return NF_ACCEPT; -- 2.50.1 (Apple Git-155)