net: lapbether: fix issue of dev reference count leakage in lapbeth_device_event()
authorZhengchao Shao <shaozhengchao@huawei.com>
Thu, 3 Nov 2022 09:05:37 +0000 (17:05 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 25 Nov 2022 16:36:45 +0000 (17:36 +0100)
[ Upstream commit 531705a765493655472c993627106e19f7e5a6d2 ]

When following tests are performed, it will cause dev reference counting
leakage.
a)ip link add bond2 type bond mode balance-rr
b)ip link set bond2 up
c)ifenslave -f bond2 rose1
d)ip link del bond2

When new bond device is created, the default type of the bond device is
ether. And the bond device is up, lapbeth_device_event() receives the
message and creates a new lapbeth device. In this case, the reference
count value of dev is hold once. But after "ifenslave -f bond2 rose1"
command is executed, the type of the bond device is changed to rose. When
the bond device is unregistered, lapbeth_device_event() will not put the
dev reference count.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/wan/lapbether.c

index 3ec922bed2d841ae65301d898ebbf87a0bf7475e..6233805fc032c40b50db7d59eb2d6795e23d11a5 100644 (file)
@@ -406,7 +406,7 @@ static int lapbeth_device_event(struct notifier_block *this,
        if (dev_net(dev) != &init_net)
                return NOTIFY_DONE;
 
-       if (!dev_is_ethdev(dev))
+       if (!dev_is_ethdev(dev) && !lapbeth_get_x25_dev(dev))
                return NOTIFY_DONE;
 
        switch (event) {