Skip to contentSkip to conversation

um: vector: Fix exception handling in vector_eth_configure()

PATCH In review Minjie Du 4 participants 5 messages Jul 6, 2023 – Aug 21, 2023

Subsystems (2)
lore
Share & tools
lore

Minjie Du

author
#0 lore raw

PATCH v4 1/1 um: vector: Fix exception handling in vector_eth_configure()

The resource cleanup was incomplete in the implementation of the function "vector_eth_configure".
Thus replace the jump target "out_undo_user_init" by "out_free_netdev". Delate the orphan function "out_undo_user_init"

PATCH v1-v3: Modify the patch format.

---
 arch/um/drivers/vector_kern.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
arch/um/drivers/vector_kern.c +1 -3
index 131b7cb29..7ae6ab8df 100644
@@ -1646,7 +1646,7 @@ static void vector_eth_configure(
 	err = register_netdevice(dev);
 	rtnl_unlock();
 	if (err)
-		goto out_undo_user_init;
+		goto out_free_netdev;
 
 	spin_lock(&vector_devices_lock);
 	list_add(&device->list, &vector_devices);
@@ -1654,8 +1654,6 @@ static void vector_eth_configure(
 
 	return;
 
-out_undo_user_init:
-	return;
 out_free_netdev:
 	free_netdev(dev);
 out_free_device:
Signature · 1 line
2.39.0
#1 lore raw
Quoted 2 lines

Thus replace the jump target
"out_undo_user_init" by "out_free_netdev".

Such text should be combined into a single line. (71 characters fit still into known wording constraints.)

Quoted 1 line

Delate the orphan function "out_undo_user_init"

Please avoid typos in such a sentence.

* How helpful is the attempt to mention a deletion?

* Would you eventually like to refer to a label instead of a “function”?

Regards,
Markus

#2 lore raw
In reply to Minjie Du
Quoted 2 lines

The resource cleanup was incomplete in the implementation of the function "vector_eth_configure".

…

Quoted 1 line

PATCH v1-v3: Modify the patch format.

…

Such a version description should usually be put into a comment area (patch changelog) after a marker line.

See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.4#n686

Would you like to add the tag “Fixes”?

Regards,
Markus

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

#3 lore raw
In reply to Minjie Du

----- Ursprüngliche Mail -----

Quoted 27 lines

The resource cleanup was incomplete in the implementation of the function "vector_eth_configure".
Thus replace the jump target "out_undo_user_init" by "out_free_netdev". Delate the orphan function "out_undo_user_init"

PATCH v1-v3: Modify the patch format.

---
arch/um/drivers/vector_kern.c | 4 +---

1 file changed, 1 insertion(+), 3 deletions(-)
arch/um/drivers/vector_kern.c +1 -1
index 131b7cb29..7ae6ab8df 100644
@@ -1646,7 +1646,7 @@ static void vector_eth_configure(
 	err = register_netdevice(dev);
 	rtnl_unlock();
 	if (err)
-		goto out_undo_user_init;
+		goto out_free_netdev;
 
 	spin_lock(&vector_devices_lock);
 	list_add(&device->list, &vector_devices);

arch/um/drivers/vector_kern.c static void vector_eth_configure( · line 1658

Quoted 5 lines
arch/um/drivers/vector_kern.c +0 -2
@@ -1654,8 +1654,6 @@ static void vector_eth_configure(
 
 	return;
 
-out_undo_user_init:
-	return;

I don't think this is correct.
vector_eth_configure() cannot communicate the failure since it is of type void. So, vector_remove() will run and will call unregister_netdev(). That can cause a double-free.

Thanks,
//richard

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

maintainer
#4 lore raw
Quoted 29 lines · Richard Weinberger

----- Ursprüngliche Mail -----

Quoted 28 lines

The resource cleanup was incomplete in the implementation of the function "vector_eth_configure".
Thus replace the jump target "out_undo_user_init" by "out_free_netdev". Delate the orphan function "out_undo_user_init"

PATCH v1-v3: Modify the patch format.

---
arch/um/drivers/vector_kern.c | 4 +---

1 file changed, 1 insertion(+), 3 deletions(-)
arch/um/drivers/vector_kern.c +1 -1
index 131b7cb29..7ae6ab8df 100644
@@ -1646,7 +1646,7 @@ static void vector_eth_configure(
 	err = register_netdevice(dev);
 	rtnl_unlock();
 	if (err)
-		goto out_undo_user_init;
+		goto out_free_netdev;
 
 	spin_lock(&vector_devices_lock);
 	list_add(&device->list, &vector_devices);
@@ -1654,8 +1654,6 @@ static void vector_eth_configure(
 
Quoted 8 lines

arch/um/drivers/vector_kern.c static void vector_eth_configure( · line 1658

Quoted 4 lines
arch/um/drivers/vector_kern.c +0 -2
 	return;
 
-out_undo_user_init:
-	return;

I don't think this is correct.
vector_eth_configure() cannot communicate the failure since it is of type void. So, vector_remove() will run and will call unregister_netdev(). That can cause a double-free.

vector_remove() will be called only once per device. It checks if the device is in the device list and if it is not - bails. If it is in the list it removes it from there and calls unregister_netdev() after that.

So, unless I am missing something, there is no harm here - unregister will not be called for a device that failed to register, because the list is updated only if the device has registered successfully.

However, on second read - if register fails, the current code leaks a *device which was alloc-ed in the beginning of configure. So even if we skip free_netdev, which invokes remove we still need to free that *device.

Quoted 4 lines

Thanks,
//richard

Signature · 3 lines
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/