From nobody Tue Feb 22 18:37:52 2022 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 D6EF719D09DB; Tue, 22 Feb 2022 18:37:52 +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 4K37Fr5fBCz3vg3; Tue, 22 Feb 2022 18:37:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645555072; 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=kdatJgeJIm1WmByUvMMXxOkfSgy9LrNH8wOvMxEO4pQ=; b=ud81mgM89tm8m2piyOYmT0VCkEJvsixvXS8IHgR9fBabpuRSxS1ednE7LnmDwhCvC2slF7 Xi4XDtsjdK/Tir2X2Hxcqo90Y9HT3ESpK1jeeIVVfHBLbOov2ktZo8qH0MulHYQQQmF6wz /ZyB38NxZx19RlG4CTi9NjTMWuCspGP3J7D8iXk8UKEk8/hO9FvoIyfUuIFALQqrgwXEsn jh6rEEjREiZ4YCMSUzEgS4NPrYcm2zaEx80CDsydlz6IcFeZrlfl5rx3FLCtfXxKOQMep0 hF30DZMrToHnjKEkovue5CAaTljjdwRx3RPxTs89EzDLgfA84OeaRkNj8z5hLg== 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 A1EC510FB; Tue, 22 Feb 2022 18:37:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 21MIbqw1018286; Tue, 22 Feb 2022 18:37:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21MIbqZH018285; Tue, 22 Feb 2022 18:37:52 GMT (envelope-from git) Date: Tue, 22 Feb 2022 18:37:52 GMT Message-Id: <202202221837.21MIbqZH018285@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: 0a2f49823402 - main - tty: fix a panic with INVARIANTS 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: 0a2f498234023008d9a3b13ad7fc8fd81d384bab Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645555072; 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=kdatJgeJIm1WmByUvMMXxOkfSgy9LrNH8wOvMxEO4pQ=; b=nxZsICKn9heROTJ9xr3EHHWTEFrrdmfQa7N/mNJbNqkOQD0crm/y+ogQZSuBcb3Nng+1S2 TIUWZigIfl0q4gMjqMYDA5frHJy2q+11tbF30Iz3obqDS2XgQ7ImlwXrTzkjMerGNvZy22 2HgMqTo1BU7ILZ32qTmJQ0EE146pgho9Aj732we1V3jB70PL7IINJ3IMBpnNC/xRGauDfF EyARwN0/6EE45HUr15YyIY6weiW+RC6pZMf2i6ZsMfALNyddMYHAOC2HkGE4n0SzB7vlgr jBGvd51k4evZtD13JRb0vQ7MQ58/SqZfpjmUlldUsfwfFUxrmrBdoFk9TlxJKg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1645555072; a=rsa-sha256; cv=none; b=oyWbY/m6ufPzkkbLaQ6/ncnCm9ylH7SYCaAJxVeeAP7j5E4LvG2expPM+T+7VpekXKhge9 k5FH6S+egKWyWINDviUUghN4ve/kQol5sS4UK8FRmiMhZBXoQ/T+vKbaIh3NnUVKg0d2o0 YrQcTYtfzXfGOebrru7g1Kv99kO0WsGNnYx3NU31gvU/3GOWQz9guj+Q3IHhVVszjohCph s4yYLTp4ioCnjzSv2aTmcJb4Zehp1YdtJdX+PaL1048o1P8Gc2cujOzh8uQG9Nfss31DWP EIBxDfCadrfnnu+fFv7XsnfhHnI0TBc2CygRi9PAt0ec7IHaq7ZAkXEylLE3lQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by rew: URL: https://cgit.FreeBSD.org/src/commit/?id=0a2f498234023008d9a3b13ad7fc8fd81d384bab commit 0a2f498234023008d9a3b13ad7fc8fd81d384bab Author: Robert Wing AuthorDate: 2022-02-22 18:22:18 +0000 Commit: Robert Wing CommitDate: 2022-02-22 18:37:13 +0000 tty: fix a panic with INVARIANTS watch'ing a tty triggers a refcount wraparound panic, take a reference on fp after fget_cap_locked() to fix. Reported by: Michael Jung Reviewed by: hselasky, mjg Fixes: f40dd6c8034b ("tty: switch ttyhook_register to use fget_cap_locked") Differential Revision: https://reviews.freebsd.org/D34335 --- sys/kern/tty.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sys/kern/tty.c b/sys/kern/tty.c index ebb32f698e88..9e6cd8d317cc 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -2083,6 +2083,8 @@ ttyhook_register(struct tty **rtp, struct proc *p, int fd, struct ttyhook *th, FILEDESC_SLOCK(fdp); error = fget_cap_locked(fdp, fd, cap_rights_init_one(&rights, CAP_TTYHOOK), &fp, NULL); + if (error == 0 && !fhold(fp)) + error = EBADF; FILEDESC_SUNLOCK(fdp); if (error != 0) return (error);