All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drivers: net: fix memory leak in peak_usb_create_dev
@ 2021-04-01 13:27 Pavel Skripkin
  2021-04-01 23:00 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Pavel Skripkin @ 2021-04-01 13:27 UTC (permalink / raw)
  To: wg, mkl, davem, kuba, mailhol.vincent
  Cc: linux-can, netdev, linux-kernel, Pavel Skripkin,
	syzbot+91adee8d9ebb9193d22d

syzbot reported memory leak in peak_usb.
The problem was in case of failure after calling
->dev_init()[2] in peak_usb_create_dev()[1]. The data
allocated int dev_init() wasn't freed, so simple
->dev_free() call fix this problem.

backtrace:
    [<0000000079d6542a>] kmalloc include/linux/slab.h:552 [inline]
    [<0000000079d6542a>] kzalloc include/linux/slab.h:682 [inline]
    [<0000000079d6542a>] pcan_usb_fd_init+0x156/0x210 drivers/net/can/usb/peak_usb/pcan_usb_fd.c:868   [2]
    [<00000000c09f9057>] peak_usb_create_dev drivers/net/can/usb/peak_usb/pcan_usb_core.c:851 [inline] [1]
    [<00000000c09f9057>] peak_usb_probe+0x389/0x490 drivers/net/can/usb/peak_usb/pcan_usb_core.c:949

Reported-by: syzbot+91adee8d9ebb9193d22d@syzkaller.appspotmail.com
Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
---
 drivers/net/can/usb/peak_usb/pcan_usb_core.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
index 573b11559d73..28e916a04047 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
@@ -857,7 +857,7 @@ static int peak_usb_create_dev(const struct peak_usb_adapter *peak_usb_adapter,
 	if (dev->adapter->dev_set_bus) {
 		err = dev->adapter->dev_set_bus(dev, 0);
 		if (err)
-			goto lbl_unregister_candev;
+			goto adap_dev_free;
 	}
 
 	/* get device number early */
@@ -869,6 +869,10 @@ static int peak_usb_create_dev(const struct peak_usb_adapter *peak_usb_adapter,
 
 	return 0;
 
+adap_dev_free:
+	if (dev->adapter->dev_free)
+		dev->adapter->dev_free(dev);
+
 lbl_unregister_candev:
 	unregister_candev(netdev);
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drivers: net: fix memory leak in peak_usb_create_dev
  2021-04-01 13:27 [PATCH] drivers: net: fix memory leak in peak_usb_create_dev Pavel Skripkin
@ 2021-04-01 23:00 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-04-01 23:00 UTC (permalink / raw)
  To: Pavel Skripkin
  Cc: wg, mkl, davem, kuba, mailhol.vincent, linux-can, netdev,
	linux-kernel, syzbot+91adee8d9ebb9193d22d

Hello:

This patch was applied to netdev/net.git (refs/heads/master):

On Thu,  1 Apr 2021 16:27:52 +0300 you wrote:
> syzbot reported memory leak in peak_usb.
> The problem was in case of failure after calling
> ->dev_init()[2] in peak_usb_create_dev()[1]. The data
> allocated int dev_init() wasn't freed, so simple
> ->dev_free() call fix this problem.
> 
> backtrace:
>     [<0000000079d6542a>] kmalloc include/linux/slab.h:552 [inline]
>     [<0000000079d6542a>] kzalloc include/linux/slab.h:682 [inline]
>     [<0000000079d6542a>] pcan_usb_fd_init+0x156/0x210 drivers/net/can/usb/peak_usb/pcan_usb_fd.c:868   [2]
>     [<00000000c09f9057>] peak_usb_create_dev drivers/net/can/usb/peak_usb/pcan_usb_core.c:851 [inline] [1]
>     [<00000000c09f9057>] peak_usb_probe+0x389/0x490 drivers/net/can/usb/peak_usb/pcan_usb_core.c:949
> 
> [...]

Here is the summary with links:
  - drivers: net: fix memory leak in peak_usb_create_dev
    https://git.kernel.org/netdev/net/c/a0b96b4a6274

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] 2+ messages in thread

end of thread, other threads:[~2021-04-01 23:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-01 13:27 [PATCH] drivers: net: fix memory leak in peak_usb_create_dev Pavel Skripkin
2021-04-01 23:00 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.