Skip to contentSkip to conversation

wireguard: device: provide sane limits for mtu setting

PATCH In review Eric Dumazet 4 participants 5 messages Feb 14, 2020

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

PATCH 1/1 wireguard: device: provide sane limits for mtu setting

If wireguard device mtu is set to zero, a divide by zero crash happens in calculate_skb_padding().

This patch provides dev->min_mtu and dev->max_mtu bounds.

Fixes e7096c131e51 ("net: WireGuard secure network tunnel")
Cc Jason A. Donenfeld <[email protected]>
---
 drivers/net/wireguard/device.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/wireguard/device.c +5 -0
index 43db442b1373073eaf5e805cfe6cfee15875437a..c02b84cca122d92ee8a81c5efdcf67aada2554d6 100644
@@ -271,9 +271,14 @@ static void wg_setup(struct net_device *dev)
 	dev->features |= WG_NETDEV_FEATURES;
 	dev->hw_features |= WG_NETDEV_FEATURES;
 	dev->hw_enc_features |= WG_NETDEV_FEATURES;
+
 	dev->mtu = ETH_DATA_LEN - MESSAGE_MINIMUM_LENGTH -
 		   sizeof(struct udphdr) -
 		   max(sizeof(struct ipv6hdr), sizeof(struct iphdr));
+	dev->min_mtu = MESSAGE_PADDING_MULTIPLE;
+	dev->max_mtu = ETH_MAX_MTU - MESSAGE_MINIMUM_LENGTH -
+		       sizeof(struct udphdr) -
+		       max(sizeof(struct ipv6hdr), sizeof(struct iphdr));
 
 	SET_NETDEV_DEVTYPE(dev, &device_type);
 
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
#1 lore raw

I'm just curious, under what circumstances would people set mtu to zero?

Quoted 23 lines · Eric Dumazet

If wireguard device mtu is set to zero, a divide by zero crash happens in calculate_skb_padding().

This patch provides dev->min_mtu and dev->max_mtu bounds.

Fixes e7096c131e51 ("net: WireGuard secure network tunnel")
Cc Jason A. Donenfeld <[email protected]>
---
  drivers/net/wireguard/device.c | 5 +++++
  1 file changed, 5 insertions(+)
drivers/net/wireguard/device.c +1 -0
index 43db442b1373073eaf5e805cfe6cfee15875437a..c02b84cca122d92ee8a81c5efdcf67aada2554d6 100644
@@ -271,9 +271,14 @@ static void wg_setup(struct net_device *dev)
  	dev->features |= WG_NETDEV_FEATURES;
  	dev->hw_features |= WG_NETDEV_FEATURES;
  	dev->hw_enc_features |= WG_NETDEV_FEATURES;
+

drivers/net/wireguard/device.c static void wg_setup(struct net_device *dev) · line 284

Quoted 10 lines
drivers/net/wireguard/device.c +4 -0
  	dev->mtu = ETH_DATA_LEN - MESSAGE_MINIMUM_LENGTH -
  		   sizeof(struct udphdr) -
  		   max(sizeof(struct ipv6hdr), sizeof(struct iphdr));
+	dev->min_mtu = MESSAGE_PADDING_MULTIPLE;
+	dev->max_mtu = ETH_MAX_MTU - MESSAGE_MINIMUM_LENGTH -
+		       sizeof(struct udphdr) -
+		       max(sizeof(struct ipv6hdr), sizeof(struct iphdr));
 
  	SET_NETDEV_DEVTYPE(dev, &device_type);
 

_______________________________________________
WireGuard mailing list
[email protected]
https://lists.zx2c4.com/mailman/listinfo/wireguard

#2 lore raw

Hello,

from https://github.com/google/syzkaller/blob/master/docs/syzbot.md

"syzbot system continuously fuzzes main Linux kernel branches and automatically reports found bugs to kernel mailing lists."

As I understand it, fuzzing is applying changes to inputs to see what breaks and, in this case, fix it.

It doesn't make sense to set an MTU to 0 so why allow the program to crash on setting the MTU to zero instead of giving back a useful error or preventing the crash in other ways.

Providing dev->min_mtu and dev->max_mtu bounds is a nice thing to do.

Samir

Quoted 44 lines · Quan Zhou

I'm just curious, under what circumstances would people set mtu to zero?

Quoted 10 lines · Eric Dumazet

If wireguard device mtu is set to zero, a divide by zero crash happens in calculate_skb_padding().

This patch provides dev->min_mtu and dev->max_mtu bounds.

Fixes e7096c131e51 ("net: WireGuard secure network tunnel")
Cc Jason A. Donenfeld <[email protected]>

Review

Quoted 5 lines
---
  drivers/net/wireguard/device.c | 5 +++++
  1 file changed, 5 insertions(+)
(quoted diff) +0 -0

b/drivers/net/wireguard/device.c

Quoted 1 line

index

43db442b1373073eaf5e805cfe6cfee15875437a..c02b84cca122d92ee8a81c5efdcf67aada2554d6 100644

Quoted 7 lines
drivers/net/wireguard/device.c +1 -0
@@ -271,9 +271,14 @@ static void wg_setup(struct net_device *dev)
  	dev->features |= WG_NETDEV_FEATURES;
  	dev->hw_features |= WG_NETDEV_FEATURES;
  	dev->hw_enc_features |= WG_NETDEV_FEATURES;
+

drivers/net/wireguard/device.c static void wg_setup(struct net_device *dev) · line 284

Quoted 10 lines
drivers/net/wireguard/device.c +4 -0
  	dev->mtu = ETH_DATA_LEN - MESSAGE_MINIMUM_LENGTH -
  		   sizeof(struct udphdr) -
  		   max(sizeof(struct ipv6hdr), sizeof(struct iphdr));
+	dev->min_mtu = MESSAGE_PADDING_MULTIPLE;
+	dev->max_mtu = ETH_MAX_MTU - MESSAGE_MINIMUM_LENGTH -
+		       sizeof(struct udphdr) -
+		       max(sizeof(struct ipv6hdr), sizeof(struct iphdr));
 
  	SET_NETDEV_DEVTYPE(dev, &device_type);
 

_______________________________________________
WireGuard mailing list
[email protected]
https://lists.zx2c4.com/mailman/listinfo/wireguard

Signature · 8 lines
Samir Nassar
[email protected]

Sent from my mobile device. Please excuse my brevity.
_______________________________________________
WireGuard mailing list
[email protected]
https://lists.zx2c4.com/mailman/listinfo/wireguard
#3 lore raw

Hi Samir,

I didn't realize this. You convinced me on this one. Thanks!

Quoted 8 lines · Samir Nassar

Hello,

from https://github.com/google/syzkaller/blob/master/docs/syzbot.md

"syzbot system continuously fuzzes main Linux kernel branches and automatically reports found bugs to kernel mailing lists."

As I understand it, fuzzing is applying changes to inputs to see what breaks and, in this case, fix it.

Quoted 51 lines

It doesn't make sense to set an MTU to 0 so why allow the program to crash on setting the MTU to zero instead of giving back a useful error or preventing the crash in other ways.

Providing dev->min_mtu and dev->max_mtu bounds is a nice thing to do.

Samir

Quoted 44 lines · Quan Zhou

I'm just curious, under what circumstances would people set mtu to zero?

Quoted 10 lines · Eric Dumazet

If wireguard device mtu is set to zero, a divide by zero crash happens in calculate_skb_padding().

This patch provides dev->min_mtu and dev->max_mtu bounds.

Fixes e7096c131e51 ("net: WireGuard secure network tunnel")
Cc Jason A. Donenfeld <[email protected]>

Review

Quoted 5 lines
---
   drivers/net/wireguard/device.c | 5 +++++
   1 file changed, 5 insertions(+)
(quoted diff) +0 -0

b/drivers/net/wireguard/device.c

Quoted 1 line

index

43db442b1373073eaf5e805cfe6cfee15875437a..c02b84cca122d92ee8a81c5efdcf67aada2554d6 100644

Quoted 7 lines
drivers/net/wireguard/device.c +1 -0
@@ -271,9 +271,14 @@ static void wg_setup(struct net_device *dev)
   	dev->features |= WG_NETDEV_FEATURES;
   	dev->hw_features |= WG_NETDEV_FEATURES;
   	dev->hw_enc_features |= WG_NETDEV_FEATURES;
+

drivers/net/wireguard/device.c static void wg_setup(struct net_device *dev) · line 284

Quoted 10 lines
drivers/net/wireguard/device.c +4 -0
   	dev->mtu = ETH_DATA_LEN - MESSAGE_MINIMUM_LENGTH -
   		   sizeof(struct udphdr) -
   		   max(sizeof(struct ipv6hdr), sizeof(struct iphdr));
+	dev->min_mtu = MESSAGE_PADDING_MULTIPLE;
+	dev->max_mtu = ETH_MAX_MTU - MESSAGE_MINIMUM_LENGTH -
+		       sizeof(struct udphdr) -
+		       max(sizeof(struct ipv6hdr), sizeof(struct iphdr));
 
   	SET_NETDEV_DEVTYPE(dev, &device_type);
 

_______________________________________________
WireGuard mailing list
[email protected]
https://lists.zx2c4.com/mailman/listinfo/wireguard

_______________________________________________
WireGuard mailing list
[email protected]
https://lists.zx2c4.com/mailman/listinfo/wireguard

#4 lore raw
In reply to Eric Dumazet

Hi Eric,

Quoted 4 lines · Eric Dumazet

If wireguard device mtu is set to zero, a divide by zero crash happens in calculate_skb_padding().

This patch provides dev->min_mtu and dev->max_mtu bounds.

Thanks for the patch. However, I solved this slightly differently yesterday afternoon already:
https://git.zx2c4.com/wireguard-linux/commit/?h=stable&id=06e79ab0d545a20dec1b179fa26841eb0afb1f07
. I've got some additional testing of this to do this afternoon, and then I'll submit it to the list.

Jason