Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1503739

Re: [PATCH net-next 4/6] net: use core MTU range checking in core net infra

From Jiri Benc <jbenc@redhat.com>
Newsgroups linux.kernel
Subject Re: [PATCH net-next 4/6] net: use core MTU range checking in core net infra
Date 2016-10-19 16:50 +0200
Message-ID <su0lP-2yX-7@gated-at.bofh.it> (permalink)
References <stOXn-2Tk-9@gated-at.bofh.it> <stOXn-2Tk-19@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Tue, 18 Oct 2016 22:33:31 -0400, Jarod Wilson wrote:
> --- a/drivers/net/vxlan.c
> +++ b/drivers/net/vxlan.c
> @@ -2367,43 +2367,31 @@ static void vxlan_set_multicast_list(struct net_device *dev)
>  {
>  }
>  
> -static int __vxlan_change_mtu(struct net_device *dev,
> -			      struct net_device *lowerdev,
> -			      struct vxlan_rdst *dst, int new_mtu, bool strict)
> +static int vxlan_change_mtu(struct net_device *dev, int new_mtu)
>  {
> -	int max_mtu = IP_MAX_MTU;
> -
> -	if (lowerdev)
> -		max_mtu = lowerdev->mtu;
> +	struct vxlan_dev *vxlan = netdev_priv(dev);
> +	struct vxlan_rdst *dst = &vxlan->default_dst;
> +	struct net_device *lowerdev = __dev_get_by_index(vxlan->net,
> +							 dst->remote_ifindex);
> +	bool use_ipv6 = false;
>  
>  	if (dst->remote_ip.sa.sa_family == AF_INET6)
> -		max_mtu -= VXLAN6_HEADROOM;
> -	else
> -		max_mtu -= VXLAN_HEADROOM;
> -
> -	if (new_mtu < 68)
> -		return -EINVAL;
> +		use_ipv6 = true;
>  
> -	if (new_mtu > max_mtu) {
> -		if (strict)
> +	/* We re-check this, because users *could* alter the mtu of the
> +	 * lower device after we've initialized dev->max_mtu.
> +	 */
> +	if (lowerdev) {
> +		dev->max_mtu = lowerdev->mtu -
> +			       (use_ipv6 ? VXLAN6_HEADROOM : VXLAN_HEADROOM);
> +		if (new_mtu > dev->max_mtu)
>  			return -EINVAL;
> -
> -		new_mtu = max_mtu;
>  	}
>  
>  	dev->mtu = new_mtu;
>  	return 0;
>  }

Sorry for the silly question, how does the min_mtu and max_mtu stuff
works? I noticed your patches but haven't looked in depth into them.

When the ndo_change_mtu callback is defined, is the dev->min_mtu and
dev->max_mtu checked first and if the desired mtu is not within range,
ndo_change_mtu is not called?

Or does ndo_change_mtu override the checks?

In either case, the code does not look correct. In the first case,
increasing of lowerdev MTU wouldn't allow increasing of vxlan MTU
without deleting and recreating the vxlan interface. In the second
case, you're missing check against the min_mtu.

>  
> -static int vxlan_change_mtu(struct net_device *dev, int new_mtu)
> -{
> -	struct vxlan_dev *vxlan = netdev_priv(dev);
> -	struct vxlan_rdst *dst = &vxlan->default_dst;
> -	struct net_device *lowerdev = __dev_get_by_index(vxlan->net,
> -							 dst->remote_ifindex);
> -	return __vxlan_change_mtu(dev, lowerdev, dst, new_mtu, true);
> -}
> -
>  static int vxlan_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb)
>  {
>  	struct vxlan_dev *vxlan = netdev_priv(dev);
> @@ -2795,6 +2783,10 @@ static int vxlan_dev_configure(struct net *src_net, struct net_device *dev,
>  		vxlan_ether_setup(dev);
>  	}
>  
> +	/* MTU range: 68 - 65535 */
> +	dev->min_mtu = 68;
> +	dev->max_mtu = IP_MAX_MTU;
> +
>  	vxlan->net = src_net;
>  
>  	dst->remote_vni = conf->vni;
> @@ -2837,8 +2829,11 @@ static int vxlan_dev_configure(struct net *src_net, struct net_device *dev,
>  		}
>  #endif
>  
> -		if (!conf->mtu)
> -			dev->mtu = lowerdev->mtu - (use_ipv6 ? VXLAN6_HEADROOM : VXLAN_HEADROOM);
> +		if (!conf->mtu) {
> +			dev->mtu = lowerdev->mtu -
> +				   (use_ipv6 ? VXLAN6_HEADROOM : VXLAN_HEADROOM);
> +			dev->max_mtu = dev->mtu;
> +		}
>  
>  		needed_headroom = lowerdev->hard_header_len;
>  	} else if (vxlan_addr_multicast(&dst->remote_ip)) {
> @@ -2847,9 +2842,14 @@ static int vxlan_dev_configure(struct net *src_net, struct net_device *dev,
>  	}
>  
>  	if (conf->mtu) {
> -		err = __vxlan_change_mtu(dev, lowerdev, dst, conf->mtu, false);
> -		if (err)
> -			return err;
> +		if (lowerdev)
> +			dev->max_mtu = lowerdev->mtu;
> +		dev->max_mtu -= (use_ipv6 ? VXLAN6_HEADROOM : VXLAN_HEADROOM);
> +
> +		dev->mtu = conf->mtu;
> +
> +		if (conf->mtu > dev->max_mtu)
> +			dev->mtu = dev->max_mtu;
>  	}

You removed the check for min_mtu but it's needed here. The conf->mtu
value comes from the user space and can be anything.

>  
>  	if (use_ipv6 || conf->flags & VXLAN_F_COLLECT_METADATA)

 Jiri

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH net-next 4/6] net: use core MTU range checking in core net infra Jarod Wilson <jarod@redhat.com> - 2016-10-19 04:40 +0200
  Re: [PATCH net-next 4/6] net: use core MTU range checking in core  net infra Sabrina Dubroca <sd@queasysnail.net> - 2016-10-19 16:20 +0200
    Re: [PATCH net-next 4/6] net: use core MTU range checking in core  net infra Jarod Wilson <jarod@redhat.com> - 2016-10-19 16:50 +0200
      Re: [PATCH net-next 4/6] net: use core MTU range checking in core  net infra Sabrina Dubroca <sd@queasysnail.net> - 2016-10-19 17:30 +0200
        Re: [PATCH net-next 4/6] net: use core MTU range checking in core  net infra Jarod Wilson <jarod@redhat.com> - 2016-10-19 17:50 +0200
  Re: [PATCH net-next 4/6] net: use core MTU range checking in core  net infra Jiri Benc <jbenc@redhat.com> - 2016-10-19 16:50 +0200
    Re: [PATCH net-next 4/6] net: use core MTU range checking in core  net infra Jarod Wilson <jarod@redhat.com> - 2016-10-19 17:00 +0200

csiph-web