From: Henry Martin <bsdhenrymartin@gmail.com>
To: Andrew Lunn <andrew+netdev@lunn.ch>,
Pieter Jansen van Vuuren <pieter.jansenvanvuuren@netronome.com>,
"David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Eric Dumazet <edumazet@kernel.org>
Cc: netdev@vger.kernel.org, Henry Martin <bsdhenrymartin@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH net] geneve: don't announce options that are not geneve options
Date: Fri, 27 Nov 2026 14:47:06 +0800 [thread overview]
Message-ID: <20261127064706.2920854-1-bsdhenrymartin@gmail.com> (raw)
geneve_build_header() announces info->options_len in the wire header
unconditionally, but only copies the option bytes when the tunnel
metadata carries the geneve option flag. With metadata of another
tunnel type (vxlan, erspan), set for example by a tc tunnel_key action,
the announced option space is never written: the packet goes out with
whatever bytes __skb_push() left in the skb headroom, and the peer can
read 4 or 12 stale kernel bytes per packet, repeatedly.
Only announce and emit options that are actually geneve options. Other
metadata is dropped from the wire header instead of being replaced by
stale headroom bytes: the option space sizing and the GRO hint offset
now both follow the same condition as the copy.
This issue was discovered by Tencent CodeBuddy Security.
Cc: stable@vger.kernel.org
Fixes: 256c87c17c53 ("net: check tunnel option type in tunnel flags")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
drivers/net/geneve.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c
index 0ab729f055ea0..dd1734b82af59 100644
--- a/drivers/net/geneve.c
+++ b/drivers/net/geneve.c
@@ -1231,7 +1231,7 @@ static void geneve_build_header(struct genevehdr *geneveh,
__be16 inner_proto)
{
geneveh->ver = GENEVE_VER;
- geneveh->opt_len = info->options_len / 4;
+ geneveh->opt_len = 0;
geneveh->oam = test_bit(IP_TUNNEL_OAM_BIT, info->key.tun_flags);
geneveh->critical = test_bit(IP_TUNNEL_CRIT_OPT_BIT,
info->key.tun_flags);
@@ -1240,8 +1240,15 @@ static void geneve_build_header(struct genevehdr *geneveh,
geneveh->proto_type = inner_proto;
geneveh->rsvd2 = 0;
- if (test_bit(IP_TUNNEL_GENEVE_OPT_BIT, info->key.tun_flags))
+ /* Only announce and copy options that are actually geneve
+ * options. Metadata of another tunnel type (vxlan, erspan)
+ * must not go on the wire: there is nothing to copy it from,
+ * and the option space would carry stale headroom bytes.
+ */
+ if (test_bit(IP_TUNNEL_GENEVE_OPT_BIT, info->key.tun_flags)) {
+ geneveh->opt_len = info->options_len / 4;
ip_tunnel_info_opts_get(geneveh->options, info);
+ }
}
static int geneve_build_gro_hint_opt(const struct geneve_dev *geneve,
@@ -1336,7 +1343,10 @@ static int geneve_build_skb(struct dst_entry *dst, struct sk_buff *skb,
skb_reset_mac_header(skb);
skb_scrub_packet(skb, xnet);
- opt_size = info->options_len + cb->gro_hint_len;
+ if (test_bit(IP_TUNNEL_GENEVE_OPT_BIT, info->key.tun_flags))
+ opt_size = info->options_len + cb->gro_hint_len;
+ else
+ opt_size = cb->gro_hint_len;
min_headroom = LL_RESERVED_SPACE(dst->dev) + dst->header_len +
GENEVE_BASE_HLEN + opt_size + ip_hdr_len;
err = skb_cow_head(skb, min_headroom);
@@ -1353,7 +1363,8 @@ static int geneve_build_skb(struct dst_entry *dst, struct sk_buff *skb,
geneve_build_header(gnvh, info, inner_proto);
if (cb->gro_hint_len)
- geneve_put_gro_hint_opt(gnvh, info->options_len, &cb->gro_hint);
+ geneve_put_gro_hint_opt(gnvh, opt_size - cb->gro_hint_len,
+ &cb->gro_hint);
udp_tunnel_set_inner_protocol(skb, double_encap, inner_proto);
return 0;
--
2.39.5
next reply other threads:[~2026-11-27 6:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 6:47 Henry Martin [this message]
2026-11-27 6:53 ` [PATCH net] geneve: don't announce options that are not geneve options netdev-bot+sinfo
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=20261127064706.2920854-1-bsdhenrymartin@gmail.com \
--to=bsdhenrymartin@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pieter.jansenvanvuuren@netronome.com \
--cc=stable@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox