* [PATCH] net: farsync: Fix kmemleak when rmmods farsync
@ 2022-12-08 12:05 Li Zetao
2022-12-08 12:44 ` Jiri Pirko
2022-12-12 9:50 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Li Zetao @ 2022-12-08 12:05 UTC (permalink / raw)
To: kevin.curtis, davem, edumazet, kuba, pabeni
Cc: lizetao1, netdev, linux-kernel
There are two memory leaks reported by kmemleak:
unreferenced object 0xffff888114b20200 (size 128):
comm "modprobe", pid 4846, jiffies 4295146524 (age 401.345s)
hex dump (first 32 bytes):
e0 62 57 09 81 88 ff ff e0 62 57 09 81 88 ff ff .bW......bW.....
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace:
[<ffffffff815bcd82>] kmalloc_trace+0x22/0x60
[<ffffffff83d35c78>] __hw_addr_add_ex+0x198/0x6c0
[<ffffffff83d3989d>] dev_addr_init+0x13d/0x230
[<ffffffff83d1063d>] alloc_netdev_mqs+0x10d/0xe50
[<ffffffff82b4a06e>] alloc_hdlcdev+0x2e/0x80
[<ffffffffa016a741>] fst_add_one+0x601/0x10e0 [farsync]
...
unreferenced object 0xffff88810b85b000 (size 1024):
comm "modprobe", pid 4846, jiffies 4295146523 (age 401.346s)
hex dump (first 32 bytes):
00 00 b0 02 00 c9 ff ff 00 70 0a 00 00 c9 ff ff .........p......
00 00 00 f2 00 00 00 f3 0a 00 00 00 02 00 00 00 ................
backtrace:
[<ffffffff815bcd82>] kmalloc_trace+0x22/0x60
[<ffffffffa016a294>] fst_add_one+0x154/0x10e0 [farsync]
[<ffffffff82060e83>] local_pci_probe+0xd3/0x170
...
The root cause is traced to the netdev and fst_card_info are not freed
when removes one fst in fst_remove_one(), which may trigger oom if
repeated insmod and rmmod module.
Fix it by adding free_netdev() and kfree() in fst_remove_one(), just as
the operations on the error handling path in fst_add_one().
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
drivers/net/wan/farsync.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/net/wan/farsync.c b/drivers/net/wan/farsync.c
index 6a212c085435..5b01642ca44e 100644
--- a/drivers/net/wan/farsync.c
+++ b/drivers/net/wan/farsync.c
@@ -2545,6 +2545,7 @@ fst_remove_one(struct pci_dev *pdev)
struct net_device *dev = port_to_dev(&card->ports[i]);
unregister_hdlc_device(dev);
+ free_netdev(dev);
}
fst_disable_intr(card);
@@ -2564,6 +2565,7 @@ fst_remove_one(struct pci_dev *pdev)
card->tx_dma_handle_card);
}
fst_card_array[card->card_no] = NULL;
+ kfree(card);
}
static struct pci_driver fst_driver = {
--
2.31.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] net: farsync: Fix kmemleak when rmmods farsync
2022-12-08 12:05 [PATCH] net: farsync: Fix kmemleak when rmmods farsync Li Zetao
@ 2022-12-08 12:44 ` Jiri Pirko
2022-12-12 9:50 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Jiri Pirko @ 2022-12-08 12:44 UTC (permalink / raw)
To: Li Zetao
Cc: kevin.curtis, davem, edumazet, kuba, pabeni, netdev, linux-kernel
Thu, Dec 08, 2022 at 01:05:40PM CET, lizetao1@huawei.com wrote:
>There are two memory leaks reported by kmemleak:
>
> unreferenced object 0xffff888114b20200 (size 128):
> comm "modprobe", pid 4846, jiffies 4295146524 (age 401.345s)
> hex dump (first 32 bytes):
> e0 62 57 09 81 88 ff ff e0 62 57 09 81 88 ff ff .bW......bW.....
> 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
> backtrace:
> [<ffffffff815bcd82>] kmalloc_trace+0x22/0x60
> [<ffffffff83d35c78>] __hw_addr_add_ex+0x198/0x6c0
> [<ffffffff83d3989d>] dev_addr_init+0x13d/0x230
> [<ffffffff83d1063d>] alloc_netdev_mqs+0x10d/0xe50
> [<ffffffff82b4a06e>] alloc_hdlcdev+0x2e/0x80
> [<ffffffffa016a741>] fst_add_one+0x601/0x10e0 [farsync]
> ...
>
> unreferenced object 0xffff88810b85b000 (size 1024):
> comm "modprobe", pid 4846, jiffies 4295146523 (age 401.346s)
> hex dump (first 32 bytes):
> 00 00 b0 02 00 c9 ff ff 00 70 0a 00 00 c9 ff ff .........p......
> 00 00 00 f2 00 00 00 f3 0a 00 00 00 02 00 00 00 ................
> backtrace:
> [<ffffffff815bcd82>] kmalloc_trace+0x22/0x60
> [<ffffffffa016a294>] fst_add_one+0x154/0x10e0 [farsync]
> [<ffffffff82060e83>] local_pci_probe+0xd3/0x170
> ...
>
>The root cause is traced to the netdev and fst_card_info are not freed
>when removes one fst in fst_remove_one(), which may trigger oom if
>repeated insmod and rmmod module.
>
>Fix it by adding free_netdev() and kfree() in fst_remove_one(), just as
>the operations on the error handling path in fst_add_one().
>
>Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
>Signed-off-by: Li Zetao <lizetao1@huawei.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
On top, may be worth ordering the cleanup in fst_remove_one() to be
aligned with the order in fst_add_one() error path.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] net: farsync: Fix kmemleak when rmmods farsync
2022-12-08 12:05 [PATCH] net: farsync: Fix kmemleak when rmmods farsync Li Zetao
2022-12-08 12:44 ` Jiri Pirko
@ 2022-12-12 9:50 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-12-12 9:50 UTC (permalink / raw)
To: Li Zetao
Cc: kevin.curtis, davem, edumazet, kuba, pabeni, netdev, linux-kernel
Hello:
This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:
On Thu, 8 Dec 2022 20:05:40 +0800 you wrote:
> There are two memory leaks reported by kmemleak:
>
> unreferenced object 0xffff888114b20200 (size 128):
> comm "modprobe", pid 4846, jiffies 4295146524 (age 401.345s)
> hex dump (first 32 bytes):
> e0 62 57 09 81 88 ff ff e0 62 57 09 81 88 ff ff .bW......bW.....
> 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
> backtrace:
> [<ffffffff815bcd82>] kmalloc_trace+0x22/0x60
> [<ffffffff83d35c78>] __hw_addr_add_ex+0x198/0x6c0
> [<ffffffff83d3989d>] dev_addr_init+0x13d/0x230
> [<ffffffff83d1063d>] alloc_netdev_mqs+0x10d/0xe50
> [<ffffffff82b4a06e>] alloc_hdlcdev+0x2e/0x80
> [<ffffffffa016a741>] fst_add_one+0x601/0x10e0 [farsync]
> ...
>
> [...]
Here is the summary with links:
- net: farsync: Fix kmemleak when rmmods farsync
https://git.kernel.org/netdev/net/c/2f623aaf9f31
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-12-12 9:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-08 12:05 [PATCH] net: farsync: Fix kmemleak when rmmods farsync Li Zetao
2022-12-08 12:44 ` Jiri Pirko
2022-12-12 9:50 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox