Skip to contentSkip to conversation

vlan: fix potential race in vlan_cleanup_module vs vlan_ioctl_handler

PATCH Applied Pavel Emelyanov 3 participants 3 messages Dec 11, 2007

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

PATCH 1/1 vlan: fix potential race in vlan_cleanup_module vs vlan_ioctl_handler

The vlan module cleanup function starts with

	vlan_netlink_fini();
	vlan_ioctl_set(NULL);

The first call removes all the vlan devices and the second one closes the vlan ioctl.

AFAIS there's a tiny race window between these two calls - after rtnl unregistered all the vlans, but the ioctl handler isn't set to NULL yet, user can manage to call this ioctl and create one vlan device, and that this function will later BUG_ON seeing non-emply hashes.

I think, that we must first close the vlan ioctl and only after this remove all the vlans with the vlan_netlink_fini() call.

---

net/8021q/vlan.c +1 -1
index 5b18315..4add9bd 100644
@@ -124,8 +124,8 @@ static void __exit vlan_cleanup_module(void)
 {
 	int i;
 
-	vlan_netlink_fini();
 	vlan_ioctl_set(NULL);
+	vlan_netlink_fini();
 
 	/* Un-register us from receiving netdevice events */
 	unregister_netdevice_notifier(&vlan_notifier_block);
#1 lore raw
Quoted 10 lines · Pavel Emelyanov

The vlan module cleanup function starts with

	vlan_netlink_fini();
	vlan_ioctl_set(NULL);

The first call removes all the vlan devices and the second one closes the vlan ioctl.

AFAIS there's a tiny race window between these two
calls - after rtnl unregistered all the vlans, but the ioctl handler isn't set to NULL yet, user can manage to call this ioctl and create one vlan device, and that this function will later BUG_ON seeing non-emply hashes.

Indeed, I can't see anything preventing this.

Quoted 3 lines

I think, that we must first close the vlan ioctl and only after this remove all the vlans with the vlan_netlink_fini() call.

That looks correct, thanks Pavel. Dave, please apply.

maintainer Applied
#2 lore raw

From: Patrick McHardy <[email protected]>
Date: Tue, 11 Dec 2007 11:38:38 +0100

Quoted 8 lines
Quoted 6 lines · Pavel Emelyanov

AFAIS there's a tiny race window between these two calls - after rtnl unregistered all the vlans, but the ioctl handler isn't set to NULL yet, user can manage to call this ioctl and create one vlan device, and that this function will later BUG_ON seeing non-emply hashes.

Quoted 7 lines

Indeed, I can't see anything preventing this.

Quoted 3 lines

I think, that we must first close the vlan ioctl and only after this remove all the vlans with the vlan_netlink_fini() call.

That looks correct, thanks Pavel. Dave, please apply.

Applied to net-2.6, thanks!