From nobody Fri Feb 11 13:58:01 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 9762419B04B4; Fri, 11 Feb 2022 13:58:02 +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 4JwFZ206llz3sgm; Fri, 11 Feb 2022 13:58:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644587882; 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=+HuadkEu0URr7EaK3Yq+Hs39aZtftuospxX/Q5XcKLM=; b=EH30MNhvc8LcXOs/COyimshGV9ycabwQ6vO+KPM1HTOtC7l2c285+oToFhCrq+ERvUjTdx 5CQiu/EfuapTLs6RDie9E2Nzl6AVbjEG0Ro/gGu/uz4hM12zQkmblEvcEciLHS6ZWyRiZY y3tH4pPmm55iAxBUzzuQ4nK23/9vhcGJm1hZ5Rjce4cNEXuY9XA9a8ErsuK2VTqNCPbUNi rGIThvZOuyU7xSwKJljrUMMoyjFnQNqmllC509quKbrpTh3J5HmGOh0PzRR0uCRSf7HhZq CMIYHxD5l+j7RRFX0QmxMhHSzPlhsE+Vi6HBLq4HuZLj1jpIMUB/IAsKxxrxkA== 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 8E20F154C5; Fri, 11 Feb 2022 13:58:01 +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 21BDw11O093083; Fri, 11 Feb 2022 13:58:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21BDw1cY093082; Fri, 11 Feb 2022 13:58:01 GMT (envelope-from git) Date: Fri, 11 Feb 2022 13:58:01 GMT Message-Id: <202202111358.21BDw1cY093082@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mateusz Guzik Subject: git: f40dd6c8034b - main - tty: switch ttyhook_register to use fget_cap_locked 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: mjg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f40dd6c8034be8c3c6db3d98bdc944a70c1248ad Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644587882; 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=+HuadkEu0URr7EaK3Yq+Hs39aZtftuospxX/Q5XcKLM=; b=S3Vy7cK69K2buFwQjv8ZzIhs50RaYM1wEALozsLIXlNVhcb84iFmMvbbjEuemMb8KpAh/j fAEDEu02vZGrkb5OiRlBPoT0+7jfE/z0+CoWPYI5S0SqhqT6SulqWC8rgr8g5Y3+5R6RpS DVM5wfnxD5TPVe03JYrzKQ9WGBuaD0NNjiDslXeAnSauHb2vqyuyEaQzUIrWvoKbS3tsNC ecletbCyTrPKpPL8iiY/QTgVk/A2HoPlu524BvYnkkQAmbtOch/h8xwIuSeX0j0OC2i1MH uvdCvQT/pxZ3DlgADUYnyq7ysI8zMFAeTDKjSD5gvs5kwzU7/RJmp6/Jv5axIg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1644587882; a=rsa-sha256; cv=none; b=DcJelIlPXBO8VpSQkI3b4Ows+grRHX3mshU8WENkPuiiRWO13AcrXFZDHsD2KotGd0PMLG boqAIj5EU+5IGJG7MAc7zdzqFGYuekoS7HOCYAIO6ICkB6Y6n68tw20cJZtazmirqLueuM m4xaMxpgacGRFhEBEvgY613Y1NFs8fdBtLqJ+NdQOCokwqUg/2ZrByQXsHeTf5+v8yt+9e Bcv5/8/7oalBfhaVOG+sO6rO09TfmmKulqAzJe7+odMqhFD1kXdQekX//A1eENbvisrr80 0BnB3DV0WS31Ef3sBpgvyQSS/HmD7QMdR2eaQbeLZfWLY5XZf4DSPs16KM4KNg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=f40dd6c8034be8c3c6db3d98bdc944a70c1248ad commit f40dd6c8034be8c3c6db3d98bdc944a70c1248ad Author: Mateusz Guzik AuthorDate: 2022-02-11 12:00:25 +0000 Commit: Mateusz Guzik CommitDate: 2022-02-11 12:13:27 +0000 tty: switch ttyhook_register to use fget_cap_locked It is still wrong-ish as fget* funcs don't expect to operate on abitrary file descriptor tables, but this at least moves it out of the way of an upcoming change while being bug-compatible. --- sys/kern/tty.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sys/kern/tty.c b/sys/kern/tty.c index 8dfe5e93780f..ebb32f698e88 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -2074,9 +2074,16 @@ ttyhook_register(struct tty **rtp, struct proc *p, int fd, struct ttyhook *th, int error, ref; /* Validate the file descriptor. */ + /* + * XXX this code inspects a file descriptor from a different process, + * but there is no dedicated routine to do it in fd code, making the + * ordeal highly questionable. + */ fdp = p->p_fd; - error = fget_unlocked(fdp, fd, cap_rights_init_one(&rights, CAP_TTYHOOK), - &fp); + FILEDESC_SLOCK(fdp); + error = fget_cap_locked(fdp, fd, cap_rights_init_one(&rights, CAP_TTYHOOK), + &fp, NULL); + FILEDESC_SUNLOCK(fdp); if (error != 0) return (error); if (fp->f_ops == &badfileops) {