All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: caif: fix memory leak in ldisc_open
@ 2021-06-12 14:51 Pavel Skripkin
  2021-06-14 19:30 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Pavel Skripkin @ 2021-06-12 14:51 UTC (permalink / raw)
  To: davem, kuba, gregkh
  Cc: netdev, linux-kernel, Pavel Skripkin, syzbot+f303e045423e617d2cad

Syzbot reported memory leak in tty_init_dev().
The problem was in unputted tty in ldisc_open()

static int ldisc_open(struct tty_struct *tty)
{
...
	ser->tty = tty_kref_get(tty);
...
	result = register_netdevice(dev);
	if (result) {
		rtnl_unlock();
		free_netdev(dev);
		return -ENODEV;
	}
...
}

Ser pointer is netdev private_data, so after free_netdev()
this pointer goes away with unputted tty reference. So, fix
it by adding tty_kref_put() before freeing netdev.

Reported-and-tested-by: syzbot+f303e045423e617d2cad@syzkaller.appspotmail.com
Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
---
 drivers/net/caif/caif_serial.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/caif/caif_serial.c b/drivers/net/caif/caif_serial.c
index d17482395a4d..4ffbfd534f18 100644
--- a/drivers/net/caif/caif_serial.c
+++ b/drivers/net/caif/caif_serial.c
@@ -350,6 +350,7 @@ static int ldisc_open(struct tty_struct *tty)
 	rtnl_lock();
 	result = register_netdevice(dev);
 	if (result) {
+		tty_kref_put(tty);
 		rtnl_unlock();
 		free_netdev(dev);
 		return -ENODEV;
-- 
2.32.0


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

* Re: [PATCH] net: caif: fix memory leak in ldisc_open
  2021-06-12 14:51 [PATCH] net: caif: fix memory leak in ldisc_open Pavel Skripkin
@ 2021-06-14 19:30 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-06-14 19:30 UTC (permalink / raw)
  To: Pavel Skripkin
  Cc: davem, kuba, gregkh, netdev, linux-kernel, syzbot+f303e045423e617d2cad

Hello:

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

On Sat, 12 Jun 2021 17:51:22 +0300 you wrote:
> Syzbot reported memory leak in tty_init_dev().
> The problem was in unputted tty in ldisc_open()
> 
> static int ldisc_open(struct tty_struct *tty)
> {
> ...
> 	ser->tty = tty_kref_get(tty);
> ...
> 	result = register_netdevice(dev);
> 	if (result) {
> 		rtnl_unlock();
> 		free_netdev(dev);
> 		return -ENODEV;
> 	}
> ...
> }
> 
> [...]

Here is the summary with links:
  - net: caif: fix memory leak in ldisc_open
    https://git.kernel.org/netdev/net/c/58af3d3d54e8

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-06-14 19:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-12 14:51 [PATCH] net: caif: fix memory leak in ldisc_open Pavel Skripkin
2021-06-14 19:30 ` 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.