From nobody Thu Feb 03 14:47:06 2022 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 C454919A0CDE; Thu, 3 Feb 2022 14:47:06 +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 4JqM2L4tcrz3L3Z; Thu, 3 Feb 2022 14:47:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643899626; 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=FdNTq046FIW6b17BLNw6h1PzWx8ffqY/H1KN2w452dI=; b=cfhS8+NBWC0oGPo0BXNVuMzFldFSBzechTaZvylzONHvkPkv56TfKHHZ6Zbo8vsqy3iQBa t282/moAJ20seZMDVyQ2titL3Rj0Nnvynci//3LEILwkB48pDA2MDQHMEnAjBhgAuGX0DG +IdUQ/f4R672smL7ppDVTr/AoIMRKNz/1XTOpzmwLYSzjacuI1v86ipJH4zI7WpMzSlPKU zqyf+kQVh1a2fIU2ce5DI7uSAE1BKkIfEnDsBEluqv6OE7vkkPu22gC5Fg7Br9bNc0L0OG MT8PDgqwWE7Xmdt03iJl1RptODaCOYTRuGp7I1op8fXXiqVQ6CAw8J01axyEFw== 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 8478D19A65; Thu, 3 Feb 2022 14:47:06 +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 213El6AO050286; Thu, 3 Feb 2022 14:47:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 213El61Y050285; Thu, 3 Feb 2022 14:47:06 GMT (envelope-from git) Date: Thu, 3 Feb 2022 14:47:06 GMT Message-Id: <202202031447.213El61Y050285@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: b84ed4e7f626 - main - filemon: Reject FILEMON_SET_FD commands when the fd is a kqueue 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: 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/main X-Git-Reftype: branch X-Git-Commit: b84ed4e7f626de5475cf26bae6d7ff15ec9f9675 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643899626; 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=FdNTq046FIW6b17BLNw6h1PzWx8ffqY/H1KN2w452dI=; b=hDF3kJ7shYPhaHQfrqYKjWbWNK/RR08IlkvPEyiCCDpfKyp8scIKBbhkydkBlBMmDVjXuW 2orvVqpyvAEOBdlXff57ltz1gi/uiC8mogOqzZywEiBKAzFeMhKb7rclQtd88mD/4iDGpR S1gQG1LbHXE8TFIhoWmzeirNCsIZrxxSqcS3MpFLZ3LNkqv9IOnfuMJ1ozW5hUR8KcvGVG dLJ6/KkjwrMJL7zykpe1xQ3iOdtl/iUjIMeegaUvXtutdYPcSjcXrj2XujbOkr7HiG+rTX eltuDfsL+CzZZwKZL6KtNmqZuCSQb7G5EP5BdxlMyUVlhkWRe2d5WFe2Ji1uPA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1643899626; a=rsa-sha256; cv=none; b=HGBvu6pCVRjEu6uK/FzaIx7uXAosHKN9rzoX47/spY+9LEKNSeeSXsFt75E5GtFStehjbw Q4B8/7h06mrquima7EI5vAruZ8rKxRouminEN04upu9EBhiZuln1m3lf1Lo+N42PF4wBgZ iiDWw98ENEsg1wINubJ8vSb+sBoNAVDBe7W85I7OSRCY3AVocFJ/U17Y/zDhieDS5GDD2q zWHaYXlWJnmO8hK1KZobjNqhpCEdrhwTloouv1ckd4UQGkvlsC6cQZzCsTYRzp0d8te0Gf GxwN0d2sfn3EdjcyAEULwhfY+P3nw2fKj8XRYUuEfJ9PPP0gA64LpHZqBLAKlA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=b84ed4e7f626de5475cf26bae6d7ff15ec9f9675 commit b84ed4e7f626de5475cf26bae6d7ff15ec9f9675 Author: Mark Johnston AuthorDate: 2022-02-03 14:41:17 +0000 Commit: Mark Johnston CommitDate: 2022-02-03 14:41:53 +0000 filemon: Reject FILEMON_SET_FD commands when the fd is a kqueue When FILEMON_SET_FD is used, the filemon handle effectively wraps the passed file. In particular, the handle may be inherited by a child process, or transferred over a unix domain socket, so we must verify that the backing file permits this. Reported by: syzbot+36e6be9e02735fe66ca8@syzkaller.appspotmail.com Reviewed by: emaste MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D34128 --- sys/dev/filemon/filemon.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/sys/dev/filemon/filemon.c b/sys/dev/filemon/filemon.c index cd48c68d8b04..4c3a23a53042 100644 --- a/sys/dev/filemon/filemon.c +++ b/sys/dev/filemon/filemon.c @@ -359,9 +359,10 @@ static int filemon_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag __unused, struct thread *td) { - int error = 0; struct filemon *filemon; + struct file *fp; struct proc *p; + int error; if ((error = devfs_get_cdevpriv((void **) &filemon)) != 0) return (error); @@ -376,12 +377,21 @@ filemon_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag __unused, break; } - error = fget_write(td, *(int *)data, - &cap_pwrite_rights, - &filemon->fp); - if (error == 0) + error = fget_write(td, *(int *)data, &cap_pwrite_rights, &fp); + if (error == 0) { + /* + * The filemon handle may be passed to another process, + * so the underlying file handle must support this. + */ + if ((fp->f_ops->fo_flags & DFLAG_PASSABLE) == 0) { + fdrop(fp, curthread); + error = EINVAL; + break; + } + filemon->fp = fp; /* Write the file header. */ filemon_write_header(filemon); + } break; /* Set the monitored process ID. */