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 6E5283EE1CC; Tue, 17 Mar 2026 16:42:40 +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=1773765760; cv=none; b=tCuLxR8l/HlnHLMguuRdwPphqcJhHnFl9c7TooNbegUNjBZDF6o+4++PAHbrI7/n+jwWcBGooUBMt37AR+HSInYXZZXSUUuYaVADDiRjcIZt7H43fo1018B0kZczKmTmCENOLaRQAUYH90kRD05rwqP8+jCkuKbZ+YdRZhx+Mm4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773765760; c=relaxed/simple; bh=oV07dfO3x2SR3EBAKAZ5U5LyPu8U0asA4u9OSNgneQM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X8CM4Vr6StJtVhRavUxf1PHQK7ELlDOU+azf+axLpM27Pt/o1sungtxFSIw1QHaQpnNp+cpco6y5lQIaeUBIUgWwA8+5gGzAJn0c6oRVOgSqOCn63JokK3/R4brYLBo28ncGQlmw4PDEJ80HCkPVcNMrD5bXUpaszwYUusV/4I0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=xkYAntVY; 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="xkYAntVY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6B33C2BC86; Tue, 17 Mar 2026 16:42:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1773765760; bh=oV07dfO3x2SR3EBAKAZ5U5LyPu8U0asA4u9OSNgneQM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xkYAntVYP+zEx0vrlxx4r457WR1Ytc3yOWvT7T/QIUwuE3Dl9JhK1Bb+wnXDi/TJN c3MhzLhQ9kk9JRjI25nTLBycZA1NxGYELrQhKM68Rb84MBgatNc7pAECCBldYJyOiR nmfnu5F9eY/fvgL0yUTRbancfQ2UXPGP8NinmQLI= 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.19 061/378] serial: caif: hold tty->link reference in ldisc_open and ser_release Date: Tue, 17 Mar 2026 17:30:18 +0100 Message-ID: <20260317163009.236720185@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260317163006.959177102@linuxfoundation.org> References: <20260317163006.959177102@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.19-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