diff mbox series

net: caif: fix memory leak in ldisc_open

Message ID 20210612145122.9354-1-paskripkin@gmail.com (mailing list archive)
State Accepted
Commit 58af3d3d54e87bfc1f936e16c04ade3369d34011
Delegated to: Netdev Maintainers
Headers show
Series net: caif: fix memory leak in ldisc_open | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Guessed tree name to be net-next
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cc_maintainers warning 3 maintainers not CCed: ducheng2@gmail.com luc.vanoostenryck@gmail.com jirislaby@kernel.org
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 7 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link

Commit Message

Pavel Skripkin June 12, 2021, 2:51 p.m. UTC
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(+)

Comments

patchwork-bot+netdevbpf@kernel.org June 14, 2021, 7:30 p.m. UTC | #1
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
diff mbox series

Patch

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;