Subject: Re: [Patch net-next] vxlan: do not use vxlan_net before checking event type

From: Daniel Borkmann <[email-masked]>
Date: Fri, 17 Jan 2014 09:39:46 +0100

On 01/17/2014 05:28 AM, Fan Du wrote:
> Hi, Cong
>
> On 2014年01月17日 12:20, Cong Wang wrote:
>> When cloning a netns, loopback device will be registered
>> and therefore an event will be notified. Of course
>> vxlan doesn't care about it, therefore should check if it
>> is NETDEV_UNREGISTER before getting the vxlan_net struct.
>> Otherwise, vxlan_net is probably not initialized yet at
>> this point.
>
> I'm bit new to vxlan, but in vxlan_init_module
>
> register_pernet_device is called before register_netdevice_notifier.
> By my understanding once register_pernet_device is called,
> then subsequent vxlan_notifier_block callback see a valid vxlan_net_id.
> I mean execute vxlan_notifier_block callback indicates a valid vxlan_net_id,
> or I miss somewhere else.

That was also my understanding, but apparently I missed that.
Very sorry. Then, it would have been enough to just provide this:

diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index a2dee80..d6ec71f 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -2681,10 +2681,12 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
  				unsigned long event, void *ptr)
  {
  	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
-	struct vxlan_net *vn = net_generic(dev_net(dev), vxlan_net_id);
+	struct vxlan_net *vn;

-	if (event == NETDEV_UNREGISTER)
+	if (event == NETDEV_UNREGISTER) {
+		vn = net_generic(dev_net(dev), vxlan_net_id);
  		vxlan_handle_lowerdev_unregister(vn, dev);
+	}

  	return NOTIFY_DONE;
  }