Skip to content

Commit 288598d

Browse files
Shuangpeng Baikuba-moo
authored andcommitted
serial: caif: hold tty->link reference in ldisc_open and ser_release
A reproducer triggers a KASAN slab-use-after-free in pty_write_room() when caif_serial's TX path calls tty_write_room(). The faulting access is on tty->link->port. Hold an extra kref on tty->link for the lifetime of the caif_serial line discipline: get it in ldisc_open() and drop it in ser_release(), and also drop it on the ldisc_open() error path. With this change applied, the reproducer no longer triggers the UAF in my testing. Link: https://gist.github.com/shuangpengbai/c898debad6bdf170a84be7e6b3d8707f Link: https://lore.kernel.org/netdev/[email protected] Fixes: e31d5a0 ("caif: tty's are kref objects so take a reference") Signed-off-by: Shuangpeng Bai <[email protected]> Reviewed-by: Jiayuan Chen <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 87d1268 commit 288598d

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

drivers/net/caif/caif_serial.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ static void ser_release(struct work_struct *work)
297297
dev_close(ser->dev);
298298
unregister_netdevice(ser->dev);
299299
debugfs_deinit(ser);
300+
tty_kref_put(tty->link);
300301
tty_kref_put(tty);
301302
}
302303
rtnl_unlock();
@@ -331,6 +332,7 @@ static int ldisc_open(struct tty_struct *tty)
331332

332333
ser = netdev_priv(dev);
333334
ser->tty = tty_kref_get(tty);
335+
tty_kref_get(tty->link);
334336
ser->dev = dev;
335337
debugfs_init(ser, tty);
336338
tty->receive_room = 4096;
@@ -339,6 +341,7 @@ static int ldisc_open(struct tty_struct *tty)
339341
rtnl_lock();
340342
result = register_netdevice(dev);
341343
if (result) {
344+
tty_kref_put(tty->link);
342345
tty_kref_put(tty);
343346
rtnl_unlock();
344347
free_netdev(dev);

0 commit comments

Comments
 (0)