Skip to contentSkip to conversation

geneve: gate GRO hint in geneve_gro_complete() on gs->gro_hint

PATCH Superseded Xiang Mei 2 participants 4 messages Jun 9 – Jun 13

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Xiang Mei

author
#0 lore raw

PATCH v2 1/2 geneve: gate GRO hint in geneve_gro_complete() on gs->gro_hint

geneve_gro_receive() reads the GRO hint through geneve_sk_gro_hint_off(), which honours it only when the socket enabled IFLA_GENEVE_GRO_HINT (gs->gro_hint). geneve_gro_complete() instead calls the low-level geneve_opt_gro_hint_off() and acts on the hint unconditionally.

On a tunnel without the hint, receive aggregates the frames as plain ETH_P_TEB while complete still honours an attacker-supplied hint option: it inflates gh_len by gro_hint->nested_hdr_len (u8) and redirects the dispatch type, so the inner gro_complete handler runs at nhoff + gh_len, an offset receive never pulled nor validated, reading out of bounds of the skb head:

  BUG: KASAN: slab-out-of-bounds in ipv6_gro_complete (net/ipv6/ip6_offload.c:196)
  Read of size 1 at addr ffff88800fe91980 by task exploit/153
   ipv6_gro_complete (net/ipv6/ip6_offload.c:196)
   geneve_gro_complete (drivers/net/geneve.c:965)
   udp_gro_complete (net/ipv4/udp_offload.c:940)
   inet_gro_complete (net/ipv4/af_inet.c:1621)
   __gro_flush (net/core/gro.c:306)

Gate the complete path on gs->gro_hint too via geneve_sk_gro_hint_off(), so both paths agree. Tunnels that enable the hint are unaffected.

Fixes fd0dd796576e ("geneve: use GRO hint option in the RX path")
Assisted-by Claude:claude-opus-4-8

---
v2: Add Kyle as "Reported-by"

 drivers/net/geneve.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/geneve.c +2 -2
index 715180c3a1b3..d0dc5d6c46df 100644
@@ -948,13 +948,13 @@ static int geneve_gro_complete(struct sock *sk, struct sk_buff *skb,
 	struct genevehdr *gh;
 	struct packet_offload *ptype;
 	__be16 type;
-	int gh_len;
+	unsigned int gh_len;
 	int err = -ENOSYS;
 
 	gh = (struct genevehdr *)(skb->data + nhoff);
 	gh_len = geneve_hlen(gh);
 	type = gh->proto_type;
-	geneve_opt_gro_hint_off(gh, &type, &gh_len);
+	geneve_sk_gro_hint_off(sk, gh, &type, &gh_len);
 
 	/* since skb->encapsulation is set, eth_gro_complete() sets the inner mac header */
 	if (likely(type == htons(ETH_P_TEB)))
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v2 2/2 geneve: validate inner network offset in geneve_gro_complete()

Even with both paths gated on gs->gro_hint, geneve_gro_complete() re-derives the inner dispatch type and length from the packet and the current gs->gro_hint, independently of geneve_gro_receive(). The two can disagree if gs->gro_hint flips under a concurrent geneve_quiesce()/ geneve_unquiesce() (sk_user_data is NULL across a synchronize_net()), or if the re-read option bytes differ from the ones receive parsed.

geneve_gro_receive() already records the inner network header position in NAPI_GRO_CB()->inner_network_offset. Have geneve_gro_complete() check the offset it is about to dispatch at against that value, adding ETH_HLEN in the ETH_P_TEB case where eth_gro_complete() steps over the inner MAC header, and bail out on mismatch instead of trusting the re-derivation.

Fixes fd0dd796576e ("geneve: use GRO hint option in the RX path")
Assisted-by Claude:claude-opus-4-8

---
v2: Add patch for race condition found by Sashiko

 drivers/net/geneve.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/net/geneve.c +13 -0
index d0dc5d6c46df..028740e97740 100644
@@ -956,6 +956,19 @@ static int geneve_gro_complete(struct sock *sk, struct sk_buff *skb,
 	type = gh->proto_type;
 	geneve_sk_gro_hint_off(sk, gh, &type, &gh_len);
 
+	/* Bail out if our inner network offset disagrees with gro_receive().
+	 * ETH_P_TEB adds ETH_HLEN for the inner MAC header.
+	 */
+	if (skb->encapsulation) {
+		unsigned int inner_nh = nhoff + gh_len;
+
+		if (type == htons(ETH_P_TEB))
+			inner_nh += ETH_HLEN;
+
+		if (unlikely(inner_nh != NAPI_GRO_CB(skb)->inner_network_offset))
+			return -EINVAL;
+	}
+
 	/* since skb->encapsulation is set, eth_gro_complete() sets the inner mac header */
 	if (likely(type == htons(ETH_P_TEB)))
 		return eth_gro_complete(skb, nhoff + gh_len);
Signature · 1 line
2.43.0
maintainer
#2 lore raw

Re: [PATCH net v2 2/2] geneve: validate inner network offset in geneve_gro_complete()

Quoted 28 lines · Xiang Mei

Even with both paths gated on gs->gro_hint, geneve_gro_complete() re-derives the inner dispatch type and length from the packet and the current gs->gro_hint, independently of geneve_gro_receive(). The two can disagree if gs->gro_hint flips under a concurrent geneve_quiesce()/ geneve_unquiesce() (sk_user_data is NULL across a synchronize_net()), or if the re-read option bytes differ from the ones receive parsed.

geneve_gro_receive() already records the inner network header position in NAPI_GRO_CB()->inner_network_offset. Have geneve_gro_complete() check the offset it is about to dispatch at against that value, adding ETH_HLEN in the ETH_P_TEB case where eth_gro_complete() steps over the inner MAC header, and bail out on mismatch instead of trusting the re-derivation.

Fixes fd0dd796576e ("geneve: use GRO hint option in the RX path")
Assisted-by Claude:claude-opus-4-8

---
v2: Add patch for race condition found by Sashiko

 drivers/net/geneve.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/net/geneve.c +0 -0
index d0dc5d6c46df..028740e97740 100644

drivers/net/geneve.c static int geneve_gro_complete(struct sock *sk, struct sk_buff *skb, · line 962

Quoted 7 lines
drivers/net/geneve.c +4 -0
@@ -956,6 +956,19 @@ static int geneve_gro_complete(struct sock *sk, struct sk_buff *skb,
 	type = gh->proto_type;
 	geneve_sk_gro_hint_off(sk, gh, &type, &gh_len);
 
+	/* Bail out if our inner network offset disagrees with gro_receive().
+	 * ETH_P_TEB adds ETH_HLEN for the inner MAC header.
+	 */
+	if (skb->encapsulation) {

I think the disagreement could happen even in the opposite direction, i.e. gro_receives does not see hints available, but gro_complete does.

drivers/net/geneve.c static int geneve_gro_complete(struct sock *sk, struct sk_buff *skb, · line 966

Quoted 4 lines
drivers/net/geneve.c +4 -0
+		unsigned int inner_nh = nhoff + gh_len;
+
+		if (type == htons(ETH_P_TEB))
+			inner_nh += ETH_HLEN;

This does not work in when the innermost headers carry a vlan tag.

/P

author
#3 lore raw

Re: [PATCH net v2 2/2] geneve: validate inner network offset in geneve_gro_complete()

Quoted 40 lines · Paolo Abeni
Quoted 28 lines · Xiang Mei

Even with both paths gated on gs->gro_hint, geneve_gro_complete() re-derives the inner dispatch type and length from the packet and the current gs->gro_hint, independently of geneve_gro_receive(). The two can disagree if gs->gro_hint flips under a concurrent geneve_quiesce()/ geneve_unquiesce() (sk_user_data is NULL across a synchronize_net()), or if the re-read option bytes differ from the ones receive parsed.

geneve_gro_receive() already records the inner network header position in NAPI_GRO_CB()->inner_network_offset. Have geneve_gro_complete() check the offset it is about to dispatch at against that value, adding ETH_HLEN in the ETH_P_TEB case where eth_gro_complete() steps over the inner MAC header, and bail out on mismatch instead of trusting the re-derivation.

Fixes fd0dd796576e ("geneve: use GRO hint option in the RX path")
Assisted-by Claude:claude-opus-4-8

---
v2: Add patch for race condition found by Sashiko

 drivers/net/geneve.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/net/geneve.c +0 -0
index d0dc5d6c46df..028740e97740 100644

drivers/net/geneve.c static int geneve_gro_complete(struct sock *sk, struct sk_buff *skb, · line 962

Quoted 7 lines
drivers/net/geneve.c +4 -0
@@ -956,6 +956,19 @@ static int geneve_gro_complete(struct sock *sk, struct sk_buff *skb,
 	type = gh->proto_type;
 	geneve_sk_gro_hint_off(sk, gh, &type, &gh_len);
 
+	/* Bail out if our inner network offset disagrees with gro_receive().
+	 * ETH_P_TEB adds ETH_HLEN for the inner MAC header.
+	 */
+	if (skb->encapsulation) {

I think the disagreement could happen even in the opposite direction, i.e. gro_receives does not see hints available, but gro_complete does.

Quoted 6 lines

drivers/net/geneve.c static int geneve_gro_complete(struct sock *sk, struct sk_buff *skb, · line 966

Quoted 4 lines
drivers/net/geneve.c +4 -0
+		unsigned int inner_nh = nhoff + gh_len;
+
+		if (type == htons(ETH_P_TEB))
+			inner_nh += ETH_HLEN;

This does not work in when the innermost headers carry a vlan tag.

Yes, you're right. the check is wrong.

inner_network_offset is the inner L3 offset recorded by gro_receive. For a tagged inner frame eth_gro_receive hands off to vlan_gro_receive, which pulls the VLAN tag before the inner ip*_gro_receive records it, so it ends up at nhoff + gh_len + ETH_HLEN + n*VLAN_HLEN. We only add ETH_HLEN, so '!=' drops a valid frame.

Do you think a lower bound works?

For example:

	if (skb->encapsulation) {
		unsigned int inner_nh = nhoff + gh_len;

		if (type == htons(ETH_P_TEB))
			inner_nh += ETH_HLEN;

		if (unlikely(inner_nh > NAPI_GRO_CB(skb)->inner_network_offset))
			return -EINVAL;
	}

A VLAN tag only pushes inner_network_offset later, so a valid packet has inner_nh <= inner_network_offset and passes. The opposite direction you mentioned (receive does not see the hint, complete does) inflates gh_len in complete, so inner_nh goes past inner_network_offset and is rejected.

The only case this does not reject is the reverse (receive uses the hint, complete does not), where inner_nh lands before inner_network_offset. That is in bounds and only reachable across a concurrent geneve_changelink() quiesce/unquiesce, so not attacker reachable. If you want that too, we need to record the offset gro_receive used in napi_gro_cb and compare by '=='.

Xiang

Quoted 3 lines

/P