From nobody Thu Oct 10 20:46:23 2024 X-Original-To: dev-commits-src-all@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 4XPhcb6sCQz5Yc8q; Thu, 10 Oct 2024 20:46:23 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XPhcb4d7Sz4Yt5; Thu, 10 Oct 2024 20:46:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728593183; 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=8X1y6kYFNm26DePnA0MQ85AWdrpcoi3vTO927RC9Tyc=; b=svpBBHJ0zEAIRQtkYo1ns2RomhK9R95eGXR+k+GLi85+MdvA6fubYOcy4B0/lYa2Jv3bPs KtaXNbeWf+PnOob0Eh3y+3COL0FjjWztTrd0qKM7niwaHzl7x1CmhtbVhCfP5IcrEm8ifL NIdO6x6ZTu74Ktkmwi2XubgcbWDOea5WETQ0/aHp03MHuclSWQFG+S6QVD11wvPnrxAabD ZuX6RZfjjIjV5TevMZlgnfpiuGeEFu3zyUx9Ym24ae2LuMFDPKxU0YwLg4WdpjHo6CIHNk lYUx67gtizDNQJhclGw/oIQ1WnDjhjkufMqv8Rot57L5DB5vYsNf2av/iIikJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728593183; 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=8X1y6kYFNm26DePnA0MQ85AWdrpcoi3vTO927RC9Tyc=; b=tQP8FLS5e4i9RIoHcn6YKnbXM8j87DZ1uUAeSt5Xjck6nuFttdelBKbrE0cRsrULdbKDmK g0fHCa3qxJpLhxsBrMzsUySeDJG75URuVHubMrhjYZ9lFzTbGK7JFT4KE3VShPyeOO/Ebq sMTObnHLEqkYwaLk6wdbbh6LglcNeoYiuJD0tu5FuTURZEh72QANv3VG8A4Tz9QnJXpr4k T1osPq1D6CnB/1zbdbkYKjW58rwi7b/XLgZOFe1KoUfqVd7XvqZsZY7kBFKP+d4vVt1fAe YCDml+V3fi+7NQwNWoxNEkAZKmVfdMn2t4IiNDAH8jnmwXR6lthYJ/GAmDII5Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728593183; a=rsa-sha256; cv=none; b=niyEplU4j8FbJUzo2nBoySTIyezBjo6Sqx6DuT8EN2SuGUzjJ1HeIcMpJXB7Ow5rW7bYE4 78yFBafF519c3kXlKgLGiAfaLDlu3G8IG6Ubks520YPScvgf3fuByLJ3aJQjnrE7tivvIQ Bv5ric9r4X96cEP73rXKKwVYk4W3egjd2lh8JYSndUS6zymasjSNJKwWyhCNJ2ilSJk6Zh srvidVeWlfwEsgxFF9qRCThNnxwPgAVWxqz5y0HAGsZ67Ks3lU4FDZKX4FzC9JFUTScaEs v7fCRelXSSCH4TP3nUMDv6z9ZStZLvGiF4vZD/7xaBMbstZVsdbP09ouubt8bg== 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 4XPhcb3xBLz1Chv; Thu, 10 Oct 2024 20:46:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49AKkNL0038609; Thu, 10 Oct 2024 20:46:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49AKkNoi038606; Thu, 10 Oct 2024 20:46:23 GMT (envelope-from git) Date: Thu, 10 Oct 2024 20:46:23 GMT Message-Id: <202410102046.49AKkNoi038606@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 3e19aac2e84a - stable/13 - tty: delete knotes when TTY is revoked List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 3e19aac2e84a93d1f8ae6e227e0e1ff6e1356594 Auto-Submitted: auto-generated The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=3e19aac2e84a93d1f8ae6e227e0e1ff6e1356594 commit 3e19aac2e84a93d1f8ae6e227e0e1ff6e1356594 Author: Robert Wing AuthorDate: 2023-12-19 00:40:46 +0000 Commit: Mark Johnston CommitDate: 2024-10-10 20:44:14 +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 (cherry picked from commit acd5638e268a6706f6b7ad84947a8425e8d51ef7) --- 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 8ed59fd166fa..42862ffb8a45 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -254,9 +254,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); @@ -370,7 +367,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; @@ -393,8 +390,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; @@ -1121,6 +1121,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);