From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.229.8 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796234772; b=KYj6dlvyYWkNL0C093dRFryJskJpqKgNNZA0jxiiy60LMcxiJ7YliVnzKsh3A47w00Fx D19GOX5yVe+/uqK3uZZvsMDuHWjBmhaZJlwx8dtGLDHXB9IOiINekzl5B+vt5fiEQkmCF dU1k1UO2BUyoxfIpnEX5zdBzwiDzVIU+Ko6RVNxfu/6lbCc3bmxY49Q6r1mVNXFJvzp1l LeAw1Qr3Dt0/wCCIxHGYG6j/rsslb/kyRmvTc9Vq/qeXgrJ/bCzK42VDgPqd7PPDSkdqf W7lHQMtXDAkKWQ7/xzfthJL0Jjyj1uzwRdMYkaU3gLB1A/W99DJwS4gGCHD61LtNmXA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796234772; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=fwiL/Xn6WbzU/AXegLqGEXZDEUAYuEYx4KkXb1l3sww=; b=uBfKTzcqiUOFxGLP4gYfNiOAMWfk6Kufx6qcEW5jPRkNinnv2H+HCRqltFX9+xvb21WT TNqxPj/RHZuyErrshRh5SKhihprMsXnKwz6BJcFa/uWlZAo+RphdiWTGLangPpSsLOS56 YVR4kBjgV15j8LEp2lu/xRpS5c29n8mqBSJVIJJGTiIuuvWdHyHBIWTtfWOaxn3gOsWua 9Qt9LtLZZbccWkVj/XEnZXEAZjY+s67GUKFL5QjZ7Fo265noH3XcTkqCCQbB+8gT5IR9h VkD8KrnC0mDLAo3tsoAgV/DVlekHd1C/5MsAyeukd5kXqzJfX0ose+TZ0DXYK9A3rLQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=k1f3SuP5; arc=none smtp.remote-ip=74.125.229.8 Received: from mail-dy2-f8.google.com (mail-dy2-f8.google.com [74.125.229.8]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8931E606A33D for ; Wed, 2 Dec 2026 18:06:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8931E606A33D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=k1f3SuP5 Received: by mail-dy2-f8.google.com with SMTP id 5a478bee46e88-3831d564bcfso4438750eec.1 for ; Wed, 02 Dec 2026 10:06:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796234771; x=1796839571; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=fwiL/Xn6WbzU/AXegLqGEXZDEUAYuEYx4KkXb1l3sww=; b=k1f3SuP5FPuEvtlkT5N+OXju3i+Nj1rALgUimdb3O1HG2UBz6ONHBqk7OAL8coCafs U1IFfZwUKZD+uHVLKpc5DBNdjpJOJVpHskYMQOqVhW9fZ6OznaoOleSq1cy93yvo5tfO Tu68/yO7Q+RE4XvOw1T3+heVaL9qzmVXH1FFfPaYkDsyFR7LbGctbBA5fLHdVbKFLVsH 3U8In/a6wyVlojiUAo+B7VrscTN3JqjmNU64/F0InXKA9NUvi/U5ajzxIc3EGiSRSFTG viVwMQTUEmdhR8nUDQRc7hGqJZiCLipdZfBJCuGo4ZyS4lBqmXEB7vBlTCHYblx2cPdb uZkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796234771; x=1796839571; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=fwiL/Xn6WbzU/AXegLqGEXZDEUAYuEYx4KkXb1l3sww=; b=CQuLzTS8e5mrG1mTitxNyhLzRYU+PKnHBK2YNY2tJE9V2J37FHtMdX8xHo4reyVsGo Ji48vM83xu2pZ9D33Y9dOJPs4Z2YngalWkvJjbb40FJyjSHnrbUpU4dEZJYVdWbxTUt8 6GA4taPRXvBkpXNPXYc/gXRugCbOzp4W+L9MvdTqRU6xUP2Z37yZjes3WL0PfzJbfiJh M3aumJ98LEQVgO5eQ92PxGjKR7D1ec71bqd7azJuSQxfrDzhRj1DMVH4gzeR4HEZBaGk belYS1bV3UE3j0JK5oTYZ6DTJkO8+Ihvg5GY+MWpWYWWU4ou4wPJe3hnegZayheOD4ro D1NA== X-Forwarded-Encrypted: i=1; AL+hErHSa+o8iu1WNHbAW54nefLx3vAdfabry1eUGy5GOjyJZi6bKSm0T6a34fh4Ha8MCV5EzXZoBD7ndca7rqU=@vger.kernel.org X-Gm-Message-State: APuU4Z+eqFxux76lipMLXco6O4E3lp1reGXvKJJZ3le0iIfDFyGOn6Mv YZZIq9pW7XaBQ6hgJpdh7pUifl/gC4z9oFs58gDL04aznoiWdEmvqadTHJLIthiGRq8= X-Gm-Gg: AZFdTZfq0lmG6l66RBWbn7a5wlB9O12rV8wDNjytcuR0Jp5e32rrukkJgqiX1rdC/bn YOqYVGlmdDFHzaYLnCu3MSDSeCpMwxqGkHtrruF2poU7xw7y53Popf03TP0DyN9Sex4vAZ2/JWy gLdIY7Kjb0o5pqSs13GLAkMVw9ootFppocsEhnfdDuQf+nySZfbUt4325cdMwdmLFlMB4vYCQR9 F3ddJ80t5Nvrq82OrwRTMR7ENPgvU7CCW+j7Zh1w476a7qyYFfrATsLS+yg9NoCt7DPiNbZvz0t MzApKcFrruHIl9eJmHDEIfE1Y1VL3zZGFqEf8eDe8QqIS0kq4x30LBlwTZQNzd+8e8ZnQAn4baX CWz9iHvwQb1dfthM3IUbwc1Vg3gDTLIrm5wQsFpdBKwFU4mEr82dME+Fax14RnvE5FaME8ewbM3 qshOEtP+GTHuWu+n08TBUsPQtbgBbNzS3rbJI1np4WJ8oA4pnPu366QBIm41en+zXQW9MAy9lRz xlWHv4rFMfUh6BLhBZ3Plp/kuYCBy/Jk/hY/oqwoPOUAytwKeRoXgovGlcI7ybxo9tHYSAUMNQ9 +/vve7n27RK7LgnK8fbDDBJBTfnaZLArY7cuiKzz72WPdMA8KBntpGRQ X-Received: by 2002:a05:7301:6187:10b0:386:a193:7eeb with SMTP id 5a478bee46e88-386a1938b8dmr36585748eec.30.1796234770506; Wed, 02 Dec 2026 10:06:10 -0800 (PST) Received: from jiayi-vm-sprl-server17.local ([155.69.195.24]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-385f68bc0adsm115475415eec.13.2026.12.02.10.06.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 10:06:10 -0800 (PST) From: Jiayi Zhang To: Greg Kroah-Hartman , Jiri Slaby Cc: Joshua Rogers , Wentao Guan , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+098cefc0911c68db5dab@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com Subject: [PATCH 2/2] vt: let the console port hold a reference to its tty Date: Wed, 2 Dec 2026 18:05:56 +0000 Message-ID: <20261202180556.4149260-2-zhangjiayi1014@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261202180556.4149260-1-zhangjiayi1014@gmail.com> References: <20261202180556.4149260-1-zhangjiayi1014@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The keyboard handler runs in atomic context and cannot take the console lock, so kbd_keycode() and fn_hold() get the tty of the console with tty_port_tty_get(), which reads vc->port.tty and takes a reference under vc->port.lock. con_install() and con_shutdown() set and clear vc->port.tty directly, under the console lock only, and the port holds no reference to the tty. A reader can therefore read the pointer before con_shutdown() clears it and take its reference only after release_tty() has dropped the last one and the tty has been freed. kbd_keycode() has had this window since commit e25d47a52693 ("vt: stabilize tty reference in kbd_keycode with tty_port_tty_get") made it use tty_port_tty_get(). With only the previous patch applied, the syzbot reproducer triggers it in fn_hold(): BUG: KASAN: slab-use-after-free in tty_port_tty_get+0x64/0xf0 Write of size 4 at addr ff11000030529000 by task syz-executor688/5536 ... tty_port_tty_get+0x64/0xf0 drivers/tty/tty_port.c:323 fn_hold drivers/tty/vt/keyboard.c:517 [inline] fn_hold+0x37/0xc0 drivers/tty/vt/keyboard.c:510 k_spec+0xf0/0x150 drivers/tty/vt/keyboard.c:654 kbd_keycode drivers/tty/vt/keyboard.c:1580 [inline] kbd_event+0xe0c/0x1a60 drivers/tty/vt/keyboard.c:1598 ... uinput_write+0xb26/0xff0 drivers/input/misc/uinput.c:682 Freed by task 1270: kfree+0x2b9/0x580 mm/slub.c:6801 process_one_work+0xabf/0x1e00 kernel/workqueue.c:3396 Last potentially related work creation: release_tty+0x4ce/0x5c0 drivers/tty/tty_io.c:1566 tty_release_struct+0xb7/0xe0 drivers/tty/tty_io.c:1665 tty_release+0xe3b/0x1480 drivers/tty/tty_io.c:1825 Use tty_port_tty_set() in con_install() and con_shutdown(), as tty_port_open() does for other drivers. vc->port.tty is then set and cleared under vc->port.lock, and the port holds a reference to the tty from install to shutdown. A reader that finds the tty in vc->port.tty takes its reference while the port's reference still keeps the tty alive. The reference is dropped in con_shutdown(), which release_tty() calls before it drops its own reference. Wentao Guan proposed the same change to con_install() and con_shutdown() in April; it received no reply. Fixes: e25d47a52693 ("vt: stabilize tty reference in kbd_keycode with tty_port_tty_get") Reported-by: syzbot+098cefc0911c68db5dab@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=098cefc0911c68db5dab Link: https://lore.kernel.org/all/20260410065546.2106592-1-guanwentao@uniontech.com/ Cc: stable@vger.kernel.org Signed-off-by: Jiayi Zhang --- Both patches are needed for the syzbot report; the test results are below the --- line of patch 1/2. With both patches applied, none of the 7 VMs that ran the reproducer reported anything. AI tools assisted with the analysis, the code and the changelog. drivers/tty/vt/vt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index 6a6eb8b..7cfb9d7 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -3875,7 +3875,7 @@ static int con_install(struct tty_driver *driver, struct tty_struct *tty) return ret; tty->driver_data = vc; - vc->port.tty = tty; + tty_port_tty_set(&vc->port, tty); tty_port_get(&vc->port); if (!tty->winsize.ws_row && !tty->winsize.ws_col) { @@ -3908,7 +3908,7 @@ static void con_shutdown(struct tty_struct *tty) BUG_ON(vc == NULL); guard(console_lock)(); - vc->port.tty = NULL; + tty_port_tty_set(&vc->port, NULL); } static void con_cleanup(struct tty_struct *tty) -- 2.53.0