From nobody Tue Dec 19 00:48:42 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4SvJ3H3rZwz54MWL; Tue, 19 Dec 2023 00:48:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SvJ3G6c8Qz4rgt; Tue, 19 Dec 2023 00:48:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702946923; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=QDu5Hs7VybZ5K+PCHv5+3N8bFhOj8oibhlm2XU2phhY=; b=M3JHHdAWz/1jbXWjuRekA/qg+YEdrf83kwuxHioMWEYVPrR1Siq2e1e8DH5W59p474jERC SSagnTnsGOF8UdWTf1XPhBKTr0/I+rLygfTlwAbp4GkoP445PoYonNcZDBN7pi0xZ+4b01 Cvugz1/9XPSe20K1RZpALhvS9CzSe/LvdCs2fTbsxDsdelhxutTJ+IX4727S/ItpdZawbC O3vVjIVtGndUWdsMeaLlM4tLdcKaev5A/qXk/P+2GvA7if9fgVXbaGSdTf0bM6bnweQLvY 9rdg1zO1Z9fFhJNpdf4YPPXVrkFUM/FdsFLbQZ2jVwulYCfZnQK41y+G+VNvBQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1702946922; a=rsa-sha256; cv=none; b=bAObhyjD7cftuyPPP4XTBXTxQUvOAsJpBzy+W3H0OgAQ0nJqLvyQrNfR1aiv+rpWSl6Gtv HcFmIYmBzpps78staEBLGWTWsubBo0km1/9MT+bz/AAYOk5n20kqbxf18FTM9bRSLr1mhp UO0b6nBqoB4rrmOZkLwun3mTR4nFfSBpgpwuuQpsaN1I5XIBxxSjqOJENoPJrWpnWJh37M dNc3MHlU4VnqzKBjvSwCmuePUbussC1mIdEzufDbRhJiz2ki/cubxHFEDR00f3auSIL6Xk 3VzlmpEIEnExiRJIECSOZ/Xz5C8bBxUy+7tYQj9mSu9o8w+Itg77D7pIc8b5jg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702946922; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=QDu5Hs7VybZ5K+PCHv5+3N8bFhOj8oibhlm2XU2phhY=; b=cBZpzCRd7xuGZgGo2g6JoXDqOhLoufCifEMy1/WzxOXuCJBKEKqbCrs/nd5uSD/vmkuiJZ zi0+G9GQCJY4LiX6eirpGKdvukDYU62mgSbQhHBd1ms/WxbECRBXKy5njl6os/ewNN0b/p d0ZoFKSo3a19pyEWQ+tSFPmTJkd/YyVfaERKhOS9nTzroSWZN27qaT6Q/+DESQBoYs9AJx eaxRGW+2jLNqYcq3WH2JvhKAkvjzXwZZZ52Ko2OAaxPOQArPdXFcz15cx6rpxi29UCdERw t4YCjecOKJNQW6G4smOYoukq84JweI2wfqCKGJLmFLfacYm+GYQEgrypfNEVpA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4SvJ3G2dfLzjrc; Tue, 19 Dec 2023 00:48:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3BJ0mgQj041990; Tue, 19 Dec 2023 00:48:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BJ0mgXZ041987; Tue, 19 Dec 2023 00:48:42 GMT (envelope-from git) Date: Tue, 19 Dec 2023 00:48:42 GMT Message-Id: <202312190048.3BJ0mgXZ041987@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Robert Wing Subject: git: acd5638e268a - main - tty: delete knotes when TTY is revoked List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: acd5638e268a6706f6b7ad84947a8425e8d51ef7 Auto-Submitted: auto-generated The branch main has been updated by rew: URL: https://cgit.FreeBSD.org/src/commit/?id=acd5638e268a6706f6b7ad84947a8425e8d51ef7 commit acd5638e268a6706f6b7ad84947a8425e8d51ef7 Author: Robert Wing AuthorDate: 2023-12-19 00:40:46 +0000 Commit: Robert Wing CommitDate: 2023-12-19 00:40:46 +0000 tty: delete knotes when TTY is revoked Do not clear knotes from the TTY until it gets dealloc'ed, unless the TTY is being revoked, in that case delete the knotes when closed is called on the TTY. When knotes are cleared from a knlist, those knotes become detached from the knlist. And when an event is triggered on a detached knote there isn't an associated knlist and therefore no lock will be taken when the event is triggered. This becomes a problem when a detached knote is triggered on a TTY since the mutex for a TTY is also used as the lock for its knlists. This scenario ends up calling the TTY event handlers without the TTY lock being held and tripping on asserts in the event handlers. PR: 272151 Reviewed by: kib, markj Differential Revision: https://reviews.freebsd.org/D41605 --- sys/kern/tty.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sys/kern/tty.c b/sys/kern/tty.c index e051c66ab0c9..61a6beafa2c0 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -253,9 +253,6 @@ ttydev_leave(struct tty *tp) ttyoutq_free(&tp->t_outq); tp->t_outlow = 0; - knlist_clear(&tp->t_inpoll.si_note, 1); - knlist_clear(&tp->t_outpoll.si_note, 1); - if (!tty_gone(tp)) ttydevsw_close(tp); @@ -369,7 +366,7 @@ done: tp->t_flags &= ~TF_OPENCLOSE; static int ttydev_close(struct cdev *dev, int fflag, int devtype __unused, - struct thread *td __unused) + struct thread *td) { struct tty *tp = dev->si_drv1; @@ -392,8 +389,11 @@ ttydev_close(struct cdev *dev, int fflag, int devtype __unused, } /* If revoking, flush output now to avoid draining it later. */ - if (fflag & FREVOKE) + if ((fflag & FREVOKE) != 0) { tty_flush(tp, FWRITE); + knlist_delete(&tp->t_inpoll.si_note, td, 1); + knlist_delete(&tp->t_outpoll.si_note, td, 1); + } tp->t_flags &= ~TF_EXCLUDE; @@ -1120,6 +1120,8 @@ tty_dealloc(void *arg) ttyoutq_free(&tp->t_outq); seldrain(&tp->t_inpoll); seldrain(&tp->t_outpoll); + knlist_clear(&tp->t_inpoll.si_note, 0); + knlist_clear(&tp->t_outpoll.si_note, 0); knlist_destroy(&tp->t_inpoll.si_note); knlist_destroy(&tp->t_outpoll.si_note);