Re: [syzbot] [serial?] KASAN: slab-use-after-free Read in tty_write_room (2)

From: Hillf Danton
Date: Tue Mar 12 2024 - 07:20:49 EST


On Mon, 11 Mar 2024 07:34:21 -0700
> syzbot has found a reproducer for the following issue on:
>
> HEAD commit: e8f897f4afef Linux 6.8
> git tree: upstream
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=11f338d1180000

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

--- x/drivers/net/caif/caif_serial.c
+++ y/drivers/net/caif/caif_serial.c
@@ -306,8 +306,11 @@ static void ser_release(struct work_stru
if (!list_empty(&list)) {
rtnl_lock();
list_for_each_entry_safe(ser, tmp, &list, node) {
+ struct tty_struct *tty = ser->tty;
+
dev_close(ser->dev);
unregister_netdevice(ser->dev);
+ tty_kref_put(tty);
debugfs_deinit(ser);
}
rtnl_unlock();
@@ -369,8 +372,6 @@ static void ldisc_close(struct tty_struc
{
struct ser_device *ser = tty->disc_data;

- tty_kref_put(ser->tty);
-
spin_lock(&ser_lock);
list_move(&ser->node, &ser_release_list);
spin_unlock(&ser_lock);
--