diff mbox series

[net-next] hsr: fix refcnt leak of hsr slave interface

Message ID 20200305000254.8217-1-ap420073@gmail.com
State Accepted
Delegated to: David Miller
Headers show
Series [net-next] hsr: fix refcnt leak of hsr slave interface | expand

Commit Message

Taehee Yoo March 5, 2020, 12:02 a.m. UTC
In the commit e0a4b99773d3 ("hsr: use upper/lower device infrastructure"),
dev_get() was removed but dev_put() in the error path wasn't removed.
So, if creating hsr interface command is failed, the reference counter leak
of lower interface would occur.

Test commands:
    ip link add dummy0 type dummy
    ip link add ipvlan0 link dummy0 type ipvlan mode l2
    ip link add ipvlan1 link dummy0 type ipvlan mode l2
    ip link add hsr0 type hsr slave1 ipvlan0 slave2 ipvlan1
    ip link del ipvlan0

Result:
[  633.271992][ T1280] unregister_netdevice: waiting for ipvlan0 to become free. Usage count = -1

Fixes: e0a4b99773d3 ("hsr: use upper/lower device infrastructure")
Signed-off-by: Taehee Yoo <ap420073@gmail.com>
---

The commit e0a4b99773d3 ("hsr: use upper/lower device infrastructure")
is not merged into "net" yet.
So, the target branch is "net-next".

 net/hsr/hsr_slave.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

Comments

David Miller March 5, 2020, 8 p.m. UTC | #1
From: Taehee Yoo <ap420073@gmail.com>
Date: Thu,  5 Mar 2020 00:02:54 +0000

> In the commit e0a4b99773d3 ("hsr: use upper/lower device infrastructure"),
> dev_get() was removed but dev_put() in the error path wasn't removed.
> So, if creating hsr interface command is failed, the reference counter leak
> of lower interface would occur.
> 
> Test commands:
>     ip link add dummy0 type dummy
>     ip link add ipvlan0 link dummy0 type ipvlan mode l2
>     ip link add ipvlan1 link dummy0 type ipvlan mode l2
>     ip link add hsr0 type hsr slave1 ipvlan0 slave2 ipvlan1
>     ip link del ipvlan0
> 
> Result:
> [  633.271992][ T1280] unregister_netdevice: waiting for ipvlan0 to become free. Usage count = -1
> 
> Fixes: e0a4b99773d3 ("hsr: use upper/lower device infrastructure")
> Signed-off-by: Taehee Yoo <ap420073@gmail.com>

Applied.
diff mbox series

Patch

diff --git a/net/hsr/hsr_slave.c b/net/hsr/hsr_slave.c
index 123605cb5420..d3547e8c6d5b 100644
--- a/net/hsr/hsr_slave.c
+++ b/net/hsr/hsr_slave.c
@@ -108,7 +108,7 @@  static int hsr_portdev_setup(struct hsr_priv *hsr, struct net_device *dev,
 
 	res = dev_set_promiscuity(dev, 1);
 	if (res)
-		goto fail_promiscuity;
+		return res;
 
 	master = hsr_port_get_hsr(hsr, HSR_PT_MASTER);
 	hsr_dev = master->dev;
@@ -128,9 +128,6 @@  static int hsr_portdev_setup(struct hsr_priv *hsr, struct net_device *dev,
 	netdev_upper_dev_unlink(dev, hsr_dev);
 fail_upper_dev_link:
 	dev_set_promiscuity(dev, -1);
-fail_promiscuity:
-	dev_put(dev);
-
 	return res;
 }