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 68B24309DB5; Mon, 13 Apr 2026 16:22:53 +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=1776097373; cv=none; b=Poyq/eeqT+F4fXu+Uhjto8fnFGwT6XcUkm/xAQHKcJc/9L+hDPQfG6NcBtLCAfZI0O3SZp3wkXBo1kPgIpCIiUM6VkFOOtvVCInsSUjNtuyRzrWCHW+mX5BLAHW8EGiInScm8IFQVlBoEhUFphuj8o0mR3CG3MMGhAbt4NoiG+8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776097373; c=relaxed/simple; bh=nJ4mpWscwlWfpX0AZ4kXaLNaVLx2SeM5CcB79AmCoeU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=swA94ehojmt1iicEpgiJ5j7P+N0bKEPTXvT+nITW8TG1JmZ/gVRAe4Vq1dTzpv2l/HJ492cXl66Mg/YbofhOKhvPm5n4tYShf8IL0THxlatgwDy+kec87v0Z+nIwkRodW4xgneXJhgUQpSXV4nimsvwU6HahJj/p0eLSCLRTW3Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=OlIetKsR; 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="OlIetKsR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8C77C2BCAF; Mon, 13 Apr 2026 16:22:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1776097373; bh=nJ4mpWscwlWfpX0AZ4kXaLNaVLx2SeM5CcB79AmCoeU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OlIetKsR4Z52wt/DtZ03GLKyJ43OrvrBBg+F0c/6vmMJUsKmHSY0qwsVsw/Iuyh7Y SQS/dvj2xb6cdjFwlzMeAkJp9y4M7pFZsrud4enwD2kSpIf7rr10pxLsoLuqZ9DYNL K+BtfIb6hF2gwA9qscIyLhFtWSw3w8AjkEIna3Ow= 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 5.15 111/570] serial: caif: hold tty->link reference in ldisc_open and ser_release Date: Mon, 13 Apr 2026 17:54:02 +0200 Message-ID: <20260413155834.602203418@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260413155830.386096114@linuxfoundation.org> References: <20260413155830.386096114@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-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 90b4820486990..32f396a8ff34f 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