]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net: caif: fix memory leak in ldisc_open
authorPavel Skripkin <paskripkin@gmail.com>
Sat, 12 Jun 2021 14:51:22 +0000 (17:51 +0300)
committerDavid S. Miller <davem@davemloft.net>
Mon, 14 Jun 2021 19:28:16 +0000 (12:28 -0700)
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>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/caif/caif_serial.c

index d17482395a4dace2cfa319a675be463849be3366..4ffbfd534f1820f9ce60b95ef58c287d318a859c 100644 (file)
@@ -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;