Skip to contentSkip to conversation

ovpn: reset MAC header before passing skb up

PATCH In review Qingfang Deng 2 participants 4 messages Apr 27 – Apr 28

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ovpn: reset MAC header before passing skb up

After decapsulating a packet, the skb->mac_header still points to the outer transport header. Call skb_reset_mac_header() in ovpn_netdev_write() to ensure the MAC header points to the beginning of the inner IP packet.

Fixes 8534731dbf2d ("ovpn: implement packet processing")
---
 drivers/net/ovpn/io.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ovpn/io.c +1 -0
index db43a1f8a07a..d92bb87be2b2 100644
@@ -85,6 +85,7 @@ static void ovpn_netdev_write(struct ovpn_peer *peer, struct sk_buff *skb)
 	skb_scrub_packet(skb, true);
 
 	/* network header reset in ovpn_decrypt_post() */
+	skb_reset_mac_header(skb);
 	skb_reset_transport_header(skb);
 	skb_reset_inner_headers(skb);
 
Signature · 1 line
2.43.0
#1 lore raw

Hi Qingfang,

thanks for the patch!

Quoted 4 lines · Qingfang Deng

After decapsulating a packet, the skb->mac_header still points to the outer transport header. Call skb_reset_mac_header() in ovpn_netdev_write() to ensure the MAC header points to the beginning of the inner IP packet.

May you elaborate on what this is exactly fixing? Did you encounter a bug triggered by this missing line?

I am asking because I wonder what is "expected" as MAC header for a packet not having one at all (packets delivered to the ovpn interface are L3 only, as per the interface type itself).

Thanks!

Regards,

Quoted 20 lines
Fixes 8534731dbf2d ("ovpn: implement packet processing")
---
  drivers/net/ovpn/io.c | 1 +
  1 file changed, 1 insertion(+)
drivers/net/ovpn/io.c +1 -0
index db43a1f8a07a..d92bb87be2b2 100644
@@ -85,6 +85,7 @@ static void ovpn_netdev_write(struct ovpn_peer *peer, struct sk_buff *skb)
  	skb_scrub_packet(skb, true);
 
  	/* network header reset in ovpn_decrypt_post() */
+	skb_reset_mac_header(skb);
  	skb_reset_transport_header(skb);
  	skb_reset_inner_headers(skb);
 
Signature · 1 line
Antonio Quartulli
#2 lore raw

Hi,

Quoted 10 lines · Antonio Quartulli

Hi Qingfang,

thanks for the patch!

Quoted 4 lines · Qingfang Deng

After decapsulating a packet, the skb->mac_header still points to the outer transport header. Call skb_reset_mac_header() in ovpn_netdev_write() to ensure the MAC header points to the beginning of the inner IP packet.

Quoted 4 lines

May you elaborate on what this is exactly fixing? Did you encounter a bug triggered by this missing line?

I am asking because I wonder what is "expected" as MAC header for a packet not having one at all (packets delivered to the ovpn interface are L3 only, as per the interface type itself).

For L3-only devices, the net core expects skb->mac_header == skb->network_header.

For example, in __netif_receive_skb_core(), skb_reset_mac_len() sets skb->mac_len to (skb->network_header - skb->mac_header). If skb->mac_header still has a stale value, this will incorrectly assign a non-zero value to skb->mac_len.

Also, if generic XDP or SOCK_PACKET is used, either will do skb_push(skb, skb->data - skb_mac_header(skb));

Quoted 13 lines

Thanks!

Regards,

Quoted 8 lines
Fixes 8534731dbf2d ("ovpn: implement packet processing")

---
  drivers/net/ovpn/io.c | 1 +

  1 file changed, 1 insertion(+)
Quoted 12 lines

drivers/net/ovpn/io.c static void ovpn_netdev_write(struct ovpn_peer · line 90

Quoted 11 lines
drivers/net/ovpn/io.c +1 -0
index db43a1f8a07a..d92bb87be2b2 100644
@@ -85,6 +85,7 @@ static void ovpn_netdev_write(struct ovpn_peer 
 *peer, struct sk_buff *skb)
       skb_scrub_packet(skb, true);
         /* network header reset in ovpn_decrypt_post() */
+    skb_reset_mac_header(skb);
       skb_reset_transport_header(skb);
       skb_reset_inner_headers(skb);

+Cc: netdev

Regards,

Qingfang

#3 lore raw

Hi,

Quoted 18 lines · Qingfang Deng

Hi,

Quoted 10 lines · Antonio Quartulli

Hi Qingfang,

thanks for the patch!

Quoted 4 lines · Qingfang Deng

After decapsulating a packet, the skb->mac_header still points to the outer transport header. Call skb_reset_mac_header() in ovpn_netdev_write() to ensure the MAC header points to the beginning of the inner IP packet.

Quoted 4 lines

May you elaborate on what this is exactly fixing? Did you encounter a bug triggered by this missing line?

I am asking because I wonder what is "expected" as MAC header for a packet not having one at all (packets delivered to the ovpn interface are L3 only, as per the interface type itself).

Quoted 8 lines

For L3-only devices, the net core expects skb->mac_header == skb-

Quoted 1 line

network_header.

For example, in __netif_receive_skb_core(), skb_reset_mac_len() sets skb->mac_len to (skb->network_header - skb->mac_header). If skb->mac_header still has a stale value, this will incorrectly assign a non-zero value to skb->mac_len.

Also, if generic XDP or SOCK_PACKET is used, either will do
  skb_push(skb, skb->data - skb_mac_header(skb));

Thanks a lot! This makes sense!

I'm applying the patch to my tree.

Regards,

Signature · 1 line
Antonio Quartulli