Re: [PATCH 4.3 34/71] vrf: fix double free and memory corruption on register_netdevice failure
From: Ben Hutchings
Date: Mon Dec 14 2015 - 12:46:09 EST
On Sat, 2015-12-12 at 12:05 -0800, Greg Kroah-Hartman wrote:
> 4.3-stable review patch.ÂÂIf anyone has any objections, please let me
> know.
>
> ------------------
>
> From: Nikolay Aleksandrov <nikolay@xxxxxxxxxxxxxxxxxxx>
>
> [ Upstream commit 7f109f7cc37108cba7243bc832988525b0d85909 ]
[...]
> --- a/drivers/net/vrf.c
> +++ b/drivers/net/vrf.c
> @@ -581,7 +581,6 @@ static int vrf_newlink(struct net *src_n
> Â{
> Â struct net_vrf *vrf = netdev_priv(dev);
> Â struct net_vrf_dev *vrf_ptr;
> - int err;
> Â
> Â if (!data || !data[IFLA_VRF_TABLE])
> Â return -EINVAL;
> @@ -590,26 +589,16 @@ static int vrf_newlink(struct net *src_n
> Â
> Â dev->priv_flags |= IFF_VRF_MASTER;
> Â
> - err = -ENOMEM;
> Â vrf_ptr = kmalloc(sizeof(*dev->vrf_ptr), GFP_KERNEL);
> Â if (!vrf_ptr)
> - goto out_fail;
> + return -ENOMEM;
> Â
> Â vrf_ptr->ifindex = dev->ifindex;
> Â vrf_ptr->tb_id = vrf->tb_id;
> Â
> - err = register_netdevice(dev);
> - if (err < 0)
> - goto out_fail;
> -
> Â rcu_assign_pointer(dev->vrf_ptr, vrf_ptr);
> Â
> - return 0;
> -
> -out_fail:
> - kfree(vrf_ptr);
> - free_netdev(dev);
> - return err;
> + return register_netdev(dev);
> Â}
> Â
> Âstatic size_t vrf_nl_getsize(const struct net_device *dev)
This leaks *dev->vrf_ptr if register_netdevice() fails. Â(This bug does
not exist in the mainline version, as net_device::vrf_ptr no longer
exists there.)
Ben.
--
Ben Hutchings
Once a job is fouled up, anything done to improve it makes it worse.
Attachment:
signature.asc
Description: This is a digitally signed message part