From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8503A373C18; Tue, 17 Mar 2026 17:08:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773767295; cv=none; b=QyAmfLjbHmCCsvUHo6U4X79/kaIl1VU1Kk7yZujKSOIcJcnA0Y2gyzoMY802ZcE18O+MssTmqMl8bLq9I3gzzozZflhd6di3FUwVij3XTIvangF0v9ndOE6vxDahxlDKkCrdvsqs+eURx44eYGphfwohQegUuUi6U8xGIcG+TZ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773767295; c=relaxed/simple; bh=Bk2HK1iMyk5yO8TOenDKaEp1dT3Dve6oRp+S6LfvGhg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gP98R8hZk1M9R6YtrypgRmbd83jHlx5+i0Ecvdhzogb1idJFxpZVNuVJLmhxXd5ivUxh+cXxfWmuPCwlWFi1T34HF7ITsgFv7628+lBQ6ylUHT8r67BGcdTdBZsCcfnppFhI3pwmktKtTRvxgGcD8KEBR0FlwbZXMYlNgIu7+c8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=tCx+x2UF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="tCx+x2UF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2ABCC4CEF7; Tue, 17 Mar 2026 17:08:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1773767295; bh=Bk2HK1iMyk5yO8TOenDKaEp1dT3Dve6oRp+S6LfvGhg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tCx+x2UFGTnjy1cvCmXKjC88jBtQJfzf2X7R7E5y3ugXMijbGIcTfcSTL5NEmmg06 SfjXsj18u8qUVrUgAh+ZGjNkUEszCgX65amcKKz83rwNrOPM4pkvN/kRfK2Y0aGBeB D0y2Ow2+2mbGzbCDNoD6BYg+ms1CWAQ3f8dkzEXg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Shuangpeng Bai , Jiayuan Chen , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.18 056/333] serial: caif: hold tty->link reference in ldisc_open and ser_release Date: Tue, 17 Mar 2026 17:31:25 +0100 Message-ID: <20260317163001.447061776@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260317162959.345812316@linuxfoundation.org> References: <20260317162959.345812316@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Shuangpeng Bai [ Upstream commit 288598d80a068a0e9281de35bcb4ce495f189e2a ] 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 Reviewed-by: Jiayuan Chen Link: https://patch.msgid.link/20260306034006.3395740-1-shuangpeng.kernel@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- 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 b90890030751f..1873d8287bb9b 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.51.0