geneve: don't announce options that are not geneve options
Subsystems (3)
PATCH 1/1 geneve: don't announce options that are not geneve options
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.
--- drivers/net/geneve.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
drivers/net/geneve.c +15 -4
@@ -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 ;
Signature · 1 line
2.39.5
[email protected]
AI reviewThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- 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.
Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.