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 5527A265620; Mon, 23 Mar 2026 15:05:22 +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=1774278322; cv=none; b=blD9LqK+TQC/Y92619syLn86ZutWonBsCz8WAVZP8sMPoloz0N9tFffgIYXsxlvr+vIhKHarcjxEPg/15XQRsJnw7bpohCBoSulqC1jFYnYTS9TCbEig6cTj4RtzbVwRju7pYakA0TG3v9AIcmgGdlj3JLitAfkPnbNcwSD6u7U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774278322; c=relaxed/simple; bh=AgdZz/516yz1e+imFD4jgpinYqZ6GOceJ10YQEzIDkk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TNsHP8cYskKsJSGyQt9dk/R8ZKSPHCbJzZb9Ip79wBrp05C19rZPtyPGu40VrV76V94z9SS1/v/JVIbiRLXOd/Do0rLdhEw72s3eaJ23GNZE1n5dmeWCbPoEzrE33x1Tq/fLeZOhb/HyMn9xN3n+KDGUO3m5pbPYcOqLNDXEF6U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=tbvLiO2z; 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="tbvLiO2z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CDE0AC4CEF7; Mon, 23 Mar 2026 15:05:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1774278322; bh=AgdZz/516yz1e+imFD4jgpinYqZ6GOceJ10YQEzIDkk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tbvLiO2zd/cuWRkzvCYVmcM6nkN95XtMFvhwYOyOtgBKyCSDF9oVOi1+xB8VKrF3Y l7Fq5GIWY9k7xgRf6avzf0d5nTBXJkocCgnSZagnWAw2r1jv82KMZ2BB5jo2nWsomb u6zB7Y0SBXaCXx6ICl4x21J3Hi+glPUPibYC0DWI= 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.6 234/567] serial: caif: hold tty->link reference in ldisc_open and ser_release Date: Mon, 23 Mar 2026 14:42:34 +0100 Message-ID: <20260323134539.626822615@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260323134533.749096647@linuxfoundation.org> References: <20260323134533.749096647@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.6-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 699ed0ff461e8..6799dbf80f484 100644 --- a/drivers/net/caif/caif_serial.c +++ b/drivers/net/caif/caif_serial.c @@ -311,6 +311,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(); @@ -345,6 +346,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 = N_TTY_BUF_SIZE; @@ -353,6 +355,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