From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796235995; b=gwKZuz6KhQ6l192z1lkLaiREYhnKl3L9t30HoZZPaU0RWhRzQv84uLvvHKs0BFF7d+LZ +mWQ3r3iwy38LIWpCiDTACMBkeCBXksd8tcSk1xnuYoWAjMw4whUnoL4Abrew1VQdR0bC MKS3R2dMadA7chJPnVTJQeHIjd05Sk4C4MpYkeoSxejtkbcvASp7EfDhGebbpwCKtpcD5 Kksn/Dy2x3vB/ftb97JXpjioY5y/U7x/F+O0kjwdipNR8aUkB+2YKyRlfQdjenBml7TDi bS4XzxHjz7aEJO7bsIy3/eFh1j91JqZPqJtyFBkSIwcm9mFqBtIHPrz0ZfR3QzNV3lA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796235995; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=P5Wfu9QZNXAiql7VzM0lIMrOQs6FpdilTw5QFhB4gC8=; b=dSSIsqU+XB8b7SVJiMGVqhRkyjw7QpEcohhZB1CDmVqsCpSp4TkJWj0g8exHxyYEhJAY aUnI09mELtpLIG0gU+CeD1S5XM/eygwBq8p3xUN6FPmP/B+GooMocFOXsD/HYM6lXpXAC j3QbkRJGgCy4CT1sUjVBko7/bip3I5mzSxNcCEfTgHsGfyXruS9Y5O11qvPQN/ek7P8tL Bmfk9fz16TeBMlO31pWtxcJrJ28gUGleR3nkRDAmONeqjq77LdQsNuSZFcFDRngQ+oDH7 3iMxw6jE4Fk8EgNgdN7Aj1bWdZQHea444CQwSt/P8d37hZBjBwU1Z8weNy4DNdctCmQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HwlGfdeK; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2EA9606A32C for ; Wed, 2 Dec 2026 18:26:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HwlGfdeK Received: by smtp.kernel.org (Postfix) with ESMTPSA id 769871F0089A; Wed, 2 Dec 2026 18:26:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796235994; bh=P5Wfu9QZNXAiql7VzM0lIMrOQs6FpdilTw5QFhB4gC8=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=HwlGfdeKc+J7P13cHvxIEI/doJFmlST/bZiL2xazclG0aReC0gn18xRco7gdlsA3W N+AYVd+sEoy3XXkBymjehFiUuTpjqtZmn3L4bqFm12IhBR8/6zUz121fWQo5d6o2hk fn+kQXFinAcuGh0zJjXGQeyNdg8SbxBKjKY5+7x//KTAfHEnv0+TyuRQw1pBmyVyId o/xbKDWMTR1Kchvac5wnyMbHzv/HHoZVpFCR55FvG7LCcRUpMuTkBkov4qhIkk4Ixj /h0MCBSBZAlB/7Dg2H3wgTS0k3fyYl4Y7UblGHN1J9RHCRELix2CEOxyyLmDSDcT9a Pqlgak3LvZCZw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] vt: drop console_lock before calling __do_SAK() in vc_SAK() Reply-To: sashiko-reviews@lists.linux.dev To: "Jiayi Zhang" Cc: linux-serial@vger.kernel.org In-Reply-To: <20261202181217.4160067-1-zhangjiayi1014@gmail.com> References: <20261202181217.4160067-1-zhangjiayi1014@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 18:26:34 +0000 X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] vt: premature tty_kref_put() in vc_SAK() before re-acquiring console_lock -- commit ae876e3ff5feb53c222ade62935a9819ac41e34c Author: Jiayi Zhang vt: drop console_lock before calling __do_SAK() in vc_SAK() This commit drops console_lock around __do_SAK() in vc_SAK() while holding a tty reference to avoid a lock ordering deadlock between console_lock and the tty buffer lock. > diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c > index ecefe4a666f26..62a52df1c2c15 100644 > --- a/drivers/tty/vt/vt_ioctl.c > +++ b/drivers/tty/vt/vt_ioctl.c > @@ -986,17 +986,25 @@ void vc_SAK(struct work_struct *work) > struct vc_data *vc; > struct tty_struct *tty; > =20 > - guard(console_lock)(); > + console_lock(); > vc =3D vc_con->d; > - if (!vc) > + if (!vc) { > + console_unlock(); > return; > + } > =20 > - /* FIXME: review tty ref counting */ > - tty =3D vc->port.tty; > + tty =3D tty_port_tty_get(&vc->port); > /* SAK should also work in all raw modes and reset them properly. */ > - if (tty) > + if (tty) { > + console_unlock(); > __do_SAK(tty); > - reset_vc(vc); > + tty_kref_put(tty); > + console_lock(); > + vc =3D vc_con->d; > + } > + if (vc) > + reset_vc(vc); > + console_unlock(); > } [Severity: Medium] Can calling tty_kref_put(tty) before re-acquiring console_lock() allow the console to be freed and reallocated before reset_vc() runs? If the process killed by __do_SAK() closes the tty before tty_kref_put(), dropping the reference outside console_lock() can trigger con_cleanup() and drop vc->port.kref to 1 while unlocked: kworker (vc_SAK) other tasks __do_SAK(tty) /* last user exits, closes tty */ tty_kref_put(tty) release_one_tty() con_cleanup() tty_port_put(&vc->port) vt_disallocate() kfree(vc) vt_setactivate() vc_allocate() INIT_WORK(&vc_con->SAK_work, ...) /* configures new vc_con->d */ console_lock() vc =3D vc_con->d reset_vc(vc) <-- clobbers newly allocated vc In addition to reset_vc() overwriting the new console's vt_mode and vt_pid, vc_allocate() calls INIT_WORK() on vc_con->SAK_work while vc_SAK() is still running, which corrupts the work item if fn_SAK() re-queued it. Putting the tty reference after console_unlock() at the end of vc_SAK() keeps vc->port.kref elevated across the entire unlocked window so vt_disallocate() still sees the console as in use. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202181217.4160= 067-1-zhangjiayi1014@gmail.com?part=3D1