* [PATCH nf v2 0/2] ipvs: fix OOB write when NATing ICMPv6 errors quoting non-first fragments
@ 2026-11-17 13:40 Axel Mierczuk
2026-11-17 13:40 ` [PATCH nf v2 1/2] ipvs: avoid out-of-bounds write in ip_vs_nat_icmp_v6 Axel Mierczuk
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Axel Mierczuk @ 2026-11-17 13:40 UTC (permalink / raw)
To: ja, horms, pablo
Cc: fw, phil, dsahern, kuba, edumazet, pabeni, davem, netfilter-devel,
lvs-devel, coreteam, netdev, w, Axel Mierczuk
This series fixes a 16-byte OOB write past the verified skb area,
reachable through ICMPv6 errors that quote non-first fragments.
Following Julian's suggestion, it preserves ESP ICMPv6 handling.
Patch 1 includes the embedded IP header in ciph.len at both ICMPv6
call sites when parsing stops at a non-first fragment. It stands on
its own for stable.
Patch 2 makes ipv6_find_hdr() set *offset to the fragment payload
for non-first fragments when target < 0, rejecting a truncated
Fragment header, so every successful return updates *offset. It
drops the workaround from patch 1, which becomes dead code.
Changes since v1:
- Patch 1: rewrote the comment and commit message. Nothing blocks an
embedded ESP fragment on ciph.len; it continues because of
pp->dont_defrag and its lookup reads only the addresses. Name the
skb_ensure_writable() callers, handle_response_icmp() and
ip_vs_icmp_xmit_v6(), that size the writable area from ciph.len.
Code unchanged.
- Patch 2: return -EBADMSG when the Fragment header is truncated, so
*offset never exceeds skb->len (Sashiko, Julian). Add Fixes tag
(Julian). Drop the ciph.len workaround from patch 1 now that every
successful return writes *offset (Sashiko). Describe the
handle_response() effect, the nf_tables trace output change and the
SYNPROXY callers in the commit message.
v1: https://lore.kernel.org/netfilter-devel/20260925141155.17603-1-axel.mierczuk@1password.com/
Axel Mierczuk (2):
ipvs: avoid out-of-bounds write in ip_vs_nat_icmp_v6
ipv6: update *offset for non-first fragments in ipv6_find_hdr()
net/ipv6/exthdrs_core.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
base-commit: 734bef548a96e8774d6eef5dfa2026c6edc4e80b
--
2.50.1 (Apple Git-155)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH nf v2 1/2] ipvs: avoid out-of-bounds write in ip_vs_nat_icmp_v6
2026-11-17 13:40 [PATCH nf v2 0/2] ipvs: fix OOB write when NATing ICMPv6 errors quoting non-first fragments Axel Mierczuk
@ 2026-11-17 13:40 ` Axel Mierczuk
2026-11-17 13:40 ` [PATCH nf v2 2/2] ipv6: update *offset for non-first fragments in ipv6_find_hdr() Axel Mierczuk
2026-11-17 13:43 ` [PATCH nf v2 0/2] ipvs: fix OOB write when NATing ICMPv6 errors quoting non-first fragments netdev-bot+sinfo
2 siblings, 0 replies; 4+ messages in thread
From: Axel Mierczuk @ 2026-11-17 13:40 UTC (permalink / raw)
To: ja, horms, pablo
Cc: fw, phil, dsahern, kuba, edumazet, pabeni, davem, netfilter-devel,
lvs-devel, coreteam, netdev, w, Axel Mierczuk, stable
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 <ja@ssi.bg>
Signed-off-by: Axel Mierczuk <axel.mierczuk@1password.com>
---
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)
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH nf v2 2/2] ipv6: update *offset for non-first fragments in ipv6_find_hdr()
2026-11-17 13:40 [PATCH nf v2 0/2] ipvs: fix OOB write when NATing ICMPv6 errors quoting non-first fragments Axel Mierczuk
2026-11-17 13:40 ` [PATCH nf v2 1/2] ipvs: avoid out-of-bounds write in ip_vs_nat_icmp_v6 Axel Mierczuk
@ 2026-11-17 13:40 ` Axel Mierczuk
2026-11-17 13:43 ` [PATCH nf v2 0/2] ipvs: fix OOB write when NATing ICMPv6 errors quoting non-first fragments netdev-bot+sinfo
2 siblings, 0 replies; 4+ messages in thread
From: Axel Mierczuk @ 2026-11-17 13:40 UTC (permalink / raw)
To: ja, horms, pablo
Cc: fw, phil, dsahern, kuba, edumazet, pabeni, davem, netfilter-devel,
lvs-devel, coreteam, netdev, w, Axel Mierczuk
The non-first fragment early return is the only successful exit of
ipv6_find_hdr() that leaves *offset untouched, so a target < 0 caller
gets back the offset it started with, the network header, instead of
a position past the headers it asked to skip.
IPVS relies on the offset being advanced. ip_vs_fill_iph_skb_off()
stores it in iph->len, and handle_response() sizes
skb_ensure_writable() from it before rewriting the IPv6 source
address, so for a non-first ESP fragment matched through
ah_esp_conn_out_get() the copy-on-write check covered none of the
header. The ICMPv6 paths had the same problem with the embedded
header. The previous patch works around it there so that it can be
backported on its own.
For non-first fragments with target < 0, set *offset immediately
after the Fragment header, at the start of the fragment payload, and
return -EBADMSG when the Fragment header is truncated, as the other
exits already do for the header they skip. Callers must still account
for the nonzero fragment offset. A NEXTHDR_FRAGMENT search continues
to return the Fragment header's offset.
nf_tables stores the offset in pkt->thoff whatever the fragment
offset is, so nf_trace_fill_pkt_info() now dumps the network headers
up to the fragment payload for non-first fragments instead of an
empty network header and the IPv6 header as transport header.
SYNPROXY uses the offset without checking the fragment offset as
well and now reads the fragment payload instead of the IPv6 header;
the -EBADMSG check keeps the offset within the packet. The other
target < 0 users check the fragment offset first or only use the
returned protocol.
Drop the ciph.len workaround from the previous patch: every
successful return now writes *offset, so ciph.len can no longer equal
ciph.off.
Fixes: b777e0ce7437 ("[NETFILTER]: make ipv6_find_hdr() find transport protocol header")
Suggested-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Axel Mierczuk <axel.mierczuk@1password.com>
---
net/ipv6/exthdrs_core.c | 9 ++++++++-
net/netfilter/ipvs/ip_vs_core.c | 20 --------------------
2 files changed, 8 insertions(+), 21 deletions(-)
diff --git a/net/ipv6/exthdrs_core.c b/net/ipv6/exthdrs_core.c
index 4a9748338cf4..3112408ed2f3 100644
--- a/net/ipv6/exthdrs_core.c
+++ b/net/ipv6/exthdrs_core.c
@@ -179,7 +179,10 @@ EXPORT_SYMBOL_GPL(ipv6_find_tlv);
*
* Note that non-1st fragment is special case that "the protocol number
* of last header" is "next header" field in Fragment header. In this case,
- * *offset is meaningless and fragment offset is stored in *fragoff if fragoff
+ * for target < 0, *offset points immediately after the Fragment header,
+ * at the start of the fragment payload. Callers must still account for
+ * the nonzero fragment offset before interpreting the payload. The
+ * fragment offset is stored in *fragoff if fragoff
* isn't NULL.
*
* if flags is not NULL and it's a fragment, then the frag flag
@@ -259,8 +262,12 @@ int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
if (target < 0 &&
((!ipv6_ext_hdr(hp->nexthdr)) ||
hp->nexthdr == NEXTHDR_NONE)) {
+ if (skb->len - start <
+ sizeof(struct frag_hdr))
+ return -EBADMSG;
if (fragoff)
*fragoff = _frag_off;
+ *offset = start + sizeof(struct frag_hdr);
return hp->nexthdr;
}
if (!found)
diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
index d5da16ff9673..fd503f0efb57 100644
--- a/net/netfilter/ipvs/ip_vs_core.c
+++ b/net/netfilter/ipvs/ip_vs_core.c
@@ -1206,16 +1206,6 @@ 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;
@@ -2046,16 +2036,6 @@ 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)
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH nf v2 0/2] ipvs: fix OOB write when NATing ICMPv6 errors quoting non-first fragments
2026-11-17 13:40 [PATCH nf v2 0/2] ipvs: fix OOB write when NATing ICMPv6 errors quoting non-first fragments Axel Mierczuk
2026-11-17 13:40 ` [PATCH nf v2 1/2] ipvs: avoid out-of-bounds write in ip_vs_nat_icmp_v6 Axel Mierczuk
2026-11-17 13:40 ` [PATCH nf v2 2/2] ipv6: update *offset for non-first fragments in ipv6_find_hdr() Axel Mierczuk
@ 2026-11-17 13:43 ` netdev-bot+sinfo
2 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sinfo @ 2026-11-17 13:43 UTC (permalink / raw)
To: Axel Mierczuk
Cc: ja, horms, pablo, fw, phil, dsahern, kuba, edumazet, pabeni,
davem, netfilter-devel, lvs-devel, coreteam, netdev, w
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during
development, syzbot report, manual code inspection, LLM or static
analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical
(e.g. found by LLM and not proven at runtime). If it was triggered
please include the symptoms, like the stack trace or kernel messages.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
--
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-17 13:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 13:40 [PATCH nf v2 0/2] ipvs: fix OOB write when NATing ICMPv6 errors quoting non-first fragments Axel Mierczuk
2026-11-17 13:40 ` [PATCH nf v2 1/2] ipvs: avoid out-of-bounds write in ip_vs_nat_icmp_v6 Axel Mierczuk
2026-11-17 13:40 ` [PATCH nf v2 2/2] ipv6: update *offset for non-first fragments in ipv6_find_hdr() Axel Mierczuk
2026-11-17 13:43 ` [PATCH nf v2 0/2] ipvs: fix OOB write when NATing ICMPv6 errors quoting non-first fragments 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