Skip to contentSkip to conversation

netdevsim: fix unbalaced locking in nsim_create()

PATCH In review Taehee Yoo 3 participants 3 messages Jul 21, 2020

Subsystems (3)
lore
Share & tools
lore

Taehee Yoo

author
#0 lore raw

PATCH v2 1/1 netdevsim: fix unbalaced locking in nsim_create()

In the nsim_create(), rtnl_lock() is called before nsim_bpf_init(). If nsim_bpf_init() is failed, rtnl_unlock() should be called, but it isn't called.
So, unbalanced locking would occur.

Fixes e05b2d141fef ("netdevsim: move netdev creation/destruction to dev probe")

---

v1->v2:
- Change error path label name.

 drivers/net/netdevsim/netdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/netdevsim/netdev.c +2 -2
index 2908e0a0d6e1..23950e7a0f81 100644
@@ -302,7 +302,7 @@ nsim_create(struct nsim_dev *nsim_dev, struct nsim_dev_port *nsim_dev_port)
 	rtnl_lock();
 	err = nsim_bpf_init(ns);
 	if (err)
-		goto err_free_netdev;
+		goto err_rtnl_unlock;
 
 	nsim_ipsec_init(ns);
 
@@ -316,8 +316,8 @@ nsim_create(struct nsim_dev *nsim_dev, struct nsim_dev_port *nsim_dev_port)
 err_ipsec_teardown:
 	nsim_ipsec_teardown(ns);
 	nsim_bpf_uninit(ns);
+err_rtnl_unlock:
 	rtnl_unlock();
-err_free_netdev:
 	free_netdev(dev);
 	return ERR_PTR(err);
 }
Signature · 1 line
2.17.1
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · On Tue, 21 Jul 2020 14:51:50 +0000 Taehee Yoo wrote:

In the nsim_create(), rtnl_lock() is called before nsim_bpf_init(). If nsim_bpf_init() is failed, rtnl_unlock() should be called, but it isn't called.
So, unbalanced locking would occur.

Fixes e05b2d141fef ("netdevsim: move netdev creation/destruction to dev probe")

Thanks!

maintainer
#2 lore raw
In reply to Taehee Yoo

From: Taehee Yoo <[email protected]>
Date: Tue, 21 Jul 2020 14:51:50 +0000

Quoted 7 lines

In the nsim_create(), rtnl_lock() is called before nsim_bpf_init(). If nsim_bpf_init() is failed, rtnl_unlock() should be called, but it isn't called.
So, unbalanced locking would occur.

Fixes e05b2d141fef ("netdevsim: move netdev creation/destruction to dev probe")

Applied and queued up for -stable, thank you.