public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net v5] serial: caif: hold tty->link reference in ldisc_open and ser_release
@ 2026-03-06  3:40 Shuangpeng Bai
  2026-03-07  3:57 ` Jiayuan Chen
  2026-03-10  2:00 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Shuangpeng Bai @ 2026-03-06  3:40 UTC (permalink / raw)
  To: netdev
  Cc: kuba, davem, edumazet, pabeni, linux-kernel, andrew+netdev,
	gregkh, horms, jirislaby, shaojijie, jiayuan.chen, alan,
	Shuangpeng Bai

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/20260301220525.1546355-1-shuangpeng.kernel@gmail.com
Fixes: e31d5a05948e ("caif: tty's are kref objects so take a reference")
Signed-off-by: Shuangpeng Bai <shuangpeng.kernel@gmail.com>
---
Changes since v4:
  - Fixes: reference e31d5a05948e ("caif: tty's are kref objects so take a reference")

 drivers/net/caif/caif_serial.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/caif/caif_serial.c b/drivers/net/caif/caif_serial.c
index b90890030751..1873d8287bb9 100644
--- a/drivers/net/caif/caif_serial.c
+++ b/drivers/net/caif/caif_serial.c
@@ -297,6 +297,7 @@ static void ser_release(struct work_struct *work)
 			dev_close(ser->dev);
 			unregister_netdevice(ser->dev);
 			debugfs_deinit(ser);
+			tty_kref_put(tty->link);
 			tty_kref_put(tty);
 		}
 		rtnl_unlock();
@@ -331,6 +332,7 @@ static int ldisc_open(struct tty_struct *tty)
 
 	ser = netdev_priv(dev);
 	ser->tty = tty_kref_get(tty);
+	tty_kref_get(tty->link);
 	ser->dev = dev;
 	debugfs_init(ser, tty);
 	tty->receive_room = 4096;
@@ -339,6 +341,7 @@ static int ldisc_open(struct tty_struct *tty)
 	rtnl_lock();
 	result = register_netdevice(dev);
 	if (result) {
+		tty_kref_put(tty->link);
 		tty_kref_put(tty);
 		rtnl_unlock();
 		free_netdev(dev);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net v5] serial: caif: hold tty->link reference in ldisc_open and ser_release
  2026-03-06  3:40 [PATCH net v5] serial: caif: hold tty->link reference in ldisc_open and ser_release Shuangpeng Bai
@ 2026-03-07  3:57 ` Jiayuan Chen
  2026-03-10  2:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Jiayuan Chen @ 2026-03-07  3:57 UTC (permalink / raw)
  To: Shuangpeng Bai
  Cc: netdev, kuba, davem, edumazet, pabeni, linux-kernel,
	andrew+netdev, gregkh, horms, jirislaby, shaojijie, jiayuan.chen,
	alan

On Thu, Mar 05, 2026 at 10:40:06PM +0800, Shuangpeng Bai wrote:
> 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/20260301220525.1546355-1-shuangpeng.kernel@gmail.com
> Fixes: e31d5a05948e ("caif: tty's are kref objects so take a reference")
> Signed-off-by: Shuangpeng Bai <shuangpeng.kernel@gmail.com>

From a design perspective, ideally tty_kref_get()/tty_kref_put() should
automatically get/put tty->link as well when it exists, so that any holder
of a tty reference implicitly keeps the peer alive.

But that would be too invasive a change to the tty core.

As-is, this patch is sufficient to fix the problem.

Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net v5] serial: caif: hold tty->link reference in ldisc_open and ser_release
  2026-03-06  3:40 [PATCH net v5] serial: caif: hold tty->link reference in ldisc_open and ser_release Shuangpeng Bai
  2026-03-07  3:57 ` Jiayuan Chen
@ 2026-03-10  2:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-03-10  2:00 UTC (permalink / raw)
  To: Shuangpeng Bai
  Cc: netdev, kuba, davem, edumazet, pabeni, linux-kernel,
	andrew+netdev, gregkh, horms, jirislaby, shaojijie, jiayuan.chen,
	alan

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Thu,  5 Mar 2026 22:40:06 -0500 you wrote:
> 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.
> 
> [...]

Here is the summary with links:
  - [net,v5] serial: caif: hold tty->link reference in ldisc_open and ser_release
    https://git.kernel.org/netdev/net/c/288598d80a06

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-03-10  2:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-06  3:40 [PATCH net v5] serial: caif: hold tty->link reference in ldisc_open and ser_release Shuangpeng Bai
2026-03-07  3:57 ` Jiayuan Chen
2026-03-10  2:00 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox