Commit 58af3d3d authored by Pavel Skripkin's avatar Pavel Skripkin Committed by David S. Miller

net: caif: fix memory leak in ldisc_open

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: default avatarPavel Skripkin <paskripkin@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 09427c19
...@@ -350,6 +350,7 @@ static int ldisc_open(struct tty_struct *tty) ...@@ -350,6 +350,7 @@ static int ldisc_open(struct tty_struct *tty)
rtnl_lock(); rtnl_lock();
result = register_netdevice(dev); result = register_netdevice(dev);
if (result) { if (result) {
tty_kref_put(tty);
rtnl_unlock(); rtnl_unlock();
free_netdev(dev); free_netdev(dev);
return -ENODEV; return -ENODEV;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment