From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.229.6 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796234772; b=OFXSpAhEKiylKiSbAfCAtOusJ9MN3GmcFuPDtTKR+FTcOqDpItXBWeDQvZ5poqM8/n54 Qa17/uqAXhHlzwAVfBVM9raK+JirQPnHaXfA8EKxv/UJmzkPJvCkW0a6nZHJ3HdbVyztT 6Jch5bHeM2hYdVqC3QIZZiI/PsgygMOvtuy2GHVMBnMsIpn2jtU83YJwdnxw6fpstPdBI AWFcrWJseHKfkouIBlyhrNfqWho2jepQM3eeVghg/G1ZSB5J0EAo3CR9hcONN0s2jJYtv X2xhyJLyRUJpGY73KZwsu+sFLFTDuoweWeTPh3ccxd1pEHk17k4N6RJUmDtQvVL1BFQ== 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:MIME-Version: Content-Transfer-Encoding; bh=L0oH+PwZfvo5rQNN+YJJF7CDnkzF+ir4oGHp5DKtiXc=; b=byBCKtwUFryJjuHIYI9eI4i2ReQlF/7bLluXPMMZgZnGF4JfYIr5IfluS6IyzwwA2bAs Dn27qPS4d2WPLBR79RrafKxgGqCWzDIbWItBcgVLwGK4sccceOZMRrxZWRvTpylX15G5b laprGuUYZcn7gcZ/7bN2dvaogk8ZySj7rIBJKeadMqAUd3qOLKOkcfrvQf7WXbPXaJBJQ Yerw1C6bheFV8+0JjUxIcEvb+kMzAWbAoUPEJD2ANEUisUns1U38Y1exDSJRF3GypX2CV b4P/d5aj5eVVUqKN+mgc9ZCr//y8DbCnh4PLjq/KsUBLV0A4SII0QYy9LVWIRTjP8gw== 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=NmDqQHgm; arc=none smtp.remote-ip=74.125.229.6 Received: from mail-dy2-f6.google.com (mail-dy2-f6.google.com [74.125.229.6]) (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 5DCD9606A692 for ; Wed, 2 Dec 2026 18:06:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5DCD9606A692 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=NmDqQHgm Received: by mail-dy2-f6.google.com with SMTP id 5a478bee46e88-33e48934fa8so2563629eec.0 for ; Wed, 02 Dec 2026 10:06:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796234766; x=1796839566; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=L0oH+PwZfvo5rQNN+YJJF7CDnkzF+ir4oGHp5DKtiXc=; b=NmDqQHgmuxlG9jeBYALd1Ur75Qs5NzILPDaNu3nT66NsvBSCz1m5U+2IGL/sxw3dap jk9uqFPiOQLP0dq3waaVMSCU2UgUZK2r4yGGdEvbLASio1p7mxCRxqQ9AJT25fMcNZWi TyIFhOi0WzoQ7n0APTIr7NhrCgbU83UNNn2k8tIl3Onj74Ztp39hw++orErRRiPtVnus /SZpZZ2Hqteya5jUbP7yvaw1lduVqn32ymqVooOaCPgkcSn78gbv31MLCXxMhMA/gHrS RQY7G7onO4VsfwQMxfw0vqslhnR0ff0IGB+3XylgnwSQNF6SkRCNU9eleD+bBQUHDyr5 i3hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796234766; x=1796839566; h=content-transfer-encoding:mime-version: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=L0oH+PwZfvo5rQNN+YJJF7CDnkzF+ir4oGHp5DKtiXc=; b=1osvqUCaLJNGFatSsqUcH/BfxYgx++P7BR6GsPYlkXHIA/+QebvZohM8wJHf+ZhiQl t4YAmZ7Zz8VIdj3cjW2bqUm5MyXoNEdPynVoPfNRHGqrNa+xhemu4Td5w2ne3s7fkBMs 7SiLeqfeKMgMSsCgMlXHGsIC8J0zrUGmSm+NMQja0/HcSQCba6UI1ZA7KpNKHYB7NHRP bUcatr46Id9FwYmmwfzw9eTttFL3eh8aMZ/yTMaczlVS56vt7i96wse0vnq1sqh1tzEC cRhnVjYy5CWlCE+1+xilXtGGBpaREGxLpd4JByCRXo/VXCJJcBKyBwO00utEIY1anehd Sb0g== X-Forwarded-Encrypted: i=1; AL+hErFssrVmc4w9E1jsDiIZGcN58EYT2cDRWXMA7b8qLrqLVcQOLdpPOS7bwfEr1Z0jVALLxl+mrzYVMrqv8rk=@vger.kernel.org X-Gm-Message-State: APuU4Z+5KFmBENIjPFEMxNHr76X9/x8mqOJvLi+PlimKzHHJZdcA5Rtz FtF+KlidksnGVrAtqbuisJkHDs8FRosjYa8SP7am2kwCg+jrl72ZTNrL X-Gm-Gg: AZFdTZcXXkXLO6aFDyZC+f5oT6U0vuxvgaopARbooBgg7pvjEIP81JgwbHh7hOZPR/Q 68mht8aDtvBnq5XJcwB4MpMGNE/353ER3DuFv+BZs2h1Ajg0J++DIry2+bgTPrVCghbWEV2XCwx euog+ADj96nM0NAJvLc0bJ6Bf5x1t0IDrqgWfSrmSkpvbrnQHOgi6GfGy5Z24pcNEx4yXRl/CSp nbBJmYKflqe4+fkEBpchKX5AZPKCgasoPaFJmN5O7F4FkCUaHR744i4btKQ3UWvCUAhobYBuINl y4jaMv3tU7zc40RUJvfUTbreZHt1DHbjsvvDELOmZU0iesasUhlVofAsXt7o/maVGREAdPYwHnT Msa09LnigWVYZ/A1SleRMfz67LgnrSa6UZP1qdVQEwsGyeriwe50FRr4ZNNExF3llHS9oEb/zfE 38UKHF70E0RPU2VFrS/6dRnWc63nIPf691F0aSCyHGfz3CvVJlRWXBMnx6nTZphJPPb/92MleeV pGyo8wKCeaGDsB9DUmS5Sp1/ig0roPCmNTpQgehTorh5r4c/E5/Nu6ZfIKrh3CH0hi0en2AzPbw r1LR8bIqStYUWP1inQwt0Yid+xYw+YozS6MdJ52JPlD3yZd36vTxwKq5 X-Received: by 2002:a05:7301:140b:b0:386:ca0e:430a with SMTP id 5a478bee46e88-386ca0e44c5mr26436043eec.24.1796234766340; Wed, 02 Dec 2026 10:06:06 -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.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 10:06:06 -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 1/2] vt: keyboard: take a tty reference in fn_hold() Date: Wed, 2 Dec 2026 18:05:55 +0000 Message-ID: <20261202180556.4149260-1-zhangjiayi1014@gmail.com> X-Mailer: git-send-email 2.53.0 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 fn_hold(), the handler of the Hold key, reads vc->port.tty without taking a reference and then calls start_tty() or stop_tty(), which take tty->flow.lock. When the last file of that console is closed at the same time, con_shutdown() clears vc->port.tty, the last reference is dropped and the tty_struct is freed from a work item, so fn_hold() can use a freed tty_struct. syzbot reports this on mainline. Its C reproducer binds Scroll Lock to K_HOLD, makes VT 63 the foreground console and presses Scroll Lock through uinput while other threads open and close /dev/tty63. On v7.3-rc4 with the syzbot config it triggered the report in 4 of 4 runs: BUG: KASAN: slab-use-after-free in _raw_spin_lock_irqsave+0x3a/0x60 Read of size 1 at addr ff110000295cc418 by task syz-executor175/5550 ... rt_spin_unlock+0x71/0x200 kernel/locking/spinlock_rt.c:84 fn_hold+0xaf/0xd0 drivers/tty/vt/keyboard.c:525 k_spec+0xf0/0x150 drivers/tty/vt/keyboard.c:648 kbd_keycode drivers/tty/vt/keyboard.c:1574 [inline] kbd_event+0xe0c/0x1a60 drivers/tty/vt/keyboard.c:1592 input_handle_events_default+0x119/0x1b0 drivers/input/input.c:2614 input_pass_values+0x74e/0x880 drivers/input/input.c:128 ... uinput_write+0xb26/0xff0 drivers/input/misc/uinput.c:682 Allocated by task 5549: alloc_tty_struct+0x96/0x8e0 drivers/tty/tty_io.c:3075 tty_init_dev.part.0+0x1e/0x500 drivers/tty/tty_io.c:1373 tty_open+0x963/0xe40 drivers/tty/tty_io.c:2093 Freed by task 3452: kfree+0x2b9/0x580 mm/slub.c:6801 process_one_work+0xabf/0x1e00 kernel/workqueue.c:3396 Last potentially related work creation: tty_kref_put+0x7e/0x90 drivers/tty/tty_io.c:1527 tty_open+0x94b/0xe40 drivers/tty/tty_io.c:2093 Commit e25d47a52693 ("vt: stabilize tty reference in kbd_keycode with tty_port_tty_get") made kbd_keycode() take a reference, but it drops the reference before the key handler runs, and fn_hold() reads vc->port.tty again. Take a reference in fn_hold() with tty_port_tty_get() as well. This patch alone does not close the report: the next patch is needed too. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: syzbot+098cefc0911c68db5dab@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=098cefc0911c68db5dab Cc: stable@vger.kernel.org Signed-off-by: Jiayi Zhang --- Tested in QEMU with the C reproducer and the kernel config of the syzbot report (PREEMPT_RT, KASAN), on commit efb44d93a620 (the commit of the report), 5 VMs per job, each running the reproducer for several minutes or until the first report: - without the series: 4 of 4 VMs report the use-after-free in fn_hold() (one VM did not boot) - with patch 1 only: 1 of 3 VMs reports the use-after-free in tty_port_tty_get() that patch 2 describes - with both patches: two jobs; none of the 7 VMs that ran the reproducer reports anything (3 VMs did not boot: a drm vblank timeout WARNING during boot, with panic_on_warn set) AI tools assisted with the analysis, the code and the changelog. drivers/tty/vt/keyboard.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c index 51d6d42..b0dc224 100644 --- a/drivers/tty/vt/keyboard.c +++ b/drivers/tty/vt/keyboard.c @@ -514,9 +514,13 @@ static void fn_show_ptregs(struct vc_data *vc) static void fn_hold(struct vc_data *vc) { - struct tty_struct *tty = vc->port.tty; + struct tty_struct *tty; - if (rep || !tty) + if (rep) + return; + + tty = tty_port_tty_get(&vc->port); + if (!tty) return; /* @@ -528,6 +532,8 @@ static void fn_hold(struct vc_data *vc) start_tty(tty); else stop_tty(tty); + + tty_kref_put(tty); } static void fn_num(struct vc_data *vc) -- 2.53.0